Skip to content

Commit 18bba57

Browse files
committed
Track per-project dependencies file in package-deps instead of global shrinkwrap.
1 parent 8cc2598 commit 18bba57

2 files changed

Lines changed: 56 additions & 17 deletions

File tree

‎apps/rush-lib/src/logic/PackageChangeAnalyzer.ts‎

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ import * as colors from 'colors';
66

77
import {
88
getPackageDeps,
9+
gitHashFiles,
910
IPackageDeps
1011
} from '@microsoft/package-deps-hash';
11-
import { Path } from '@microsoft/node-core-library';
12+
import {
13+
Path,
14+
InternalError
15+
} from '@microsoft/node-core-library';
1216

1317
import { RushConfiguration } from '../api/RushConfiguration';
1418
import { Git } from './Git';
19+
import { PnpmProjectDependencyManifest } from './pnpm/PnpmProjectDependencyManifest';
20+
import { RushConfigurationProject } from '../api/RushConfigurationProject';
1521

1622
export class PackageChangeAnalyzer {
1723
// Allow this function to be overwritten during unit tests
@@ -125,19 +131,48 @@ export class PackageChangeAnalyzer {
125131
// });
126132
// }
127133

128-
// Determine the current variant from the link JSON.
129-
const variant: string | undefined = this._rushConfiguration.currentInstalledVariant;
130-
131-
// Add the shrinkwrap file to every project's dependencies
132-
const shrinkwrapFile: string = path.relative(
133-
this._rushConfiguration.rushJsonFolder,
134-
this._rushConfiguration.getCommittedShrinkwrapFilename(variant)
135-
).replace(/\\/g, '/');
134+
if (this._rushConfiguration.packageManager === 'pnpm') {
135+
const projects: RushConfigurationProject[] = [];
136+
const projectDependencyManifestPaths: string[] = [];
137+
138+
for (const project of this._rushConfiguration.projects) {
139+
const dependencyManifestFilePath: string = PnpmProjectDependencyManifest.getFilePathForProject(project);
140+
const relativeDependencyManifestFilePath: string = path.relative(
141+
this._rushConfiguration.rushJsonFolder,
142+
dependencyManifestFilePath
143+
).replace(/\\/g, '/');
144+
projects.push(project);
145+
projectDependencyManifestPaths.push(relativeDependencyManifestFilePath);
146+
}
136147

137-
for (const project of this._rushConfiguration.projects) {
138-
const shrinkwrapHash: string | undefined = noProjectHashes[shrinkwrapFile];
139-
if (shrinkwrapHash) {
140-
projectHashDeps.get(project.packageName)!.files[shrinkwrapFile] = shrinkwrapHash;
148+
const hashes: Map<string, string> = gitHashFiles(
149+
projectDependencyManifestPaths,
150+
this._rushConfiguration.rushJsonFolder
151+
);
152+
for (let i: number = 0; i < projects.length; i++) {
153+
const project: RushConfigurationProject = projects[i];
154+
const projectDependencyManifestPath: string = projectDependencyManifestPaths[i];
155+
if (!hashes.has(projectDependencyManifestPath)) {
156+
throw new InternalError(`Expected to get a hash for ${projectDependencyManifestPath}`);
157+
}
158+
const hash: string = hashes.get(projectDependencyManifestPath)!;
159+
projectHashDeps.get(project.packageName)!.files[projectDependencyManifestPath] = hash;
160+
}
161+
} else {
162+
// Determine the current variant from the link JSON.
163+
const variant: string | undefined = this._rushConfiguration.currentInstalledVariant;
164+
165+
// Add the shrinkwrap file to every project's dependencies
166+
const shrinkwrapFile: string = path.relative(
167+
this._rushConfiguration.rushJsonFolder,
168+
this._rushConfiguration.getCommittedShrinkwrapFilename(variant)
169+
).replace(/\\/g, '/');
170+
171+
for (const project of this._rushConfiguration.projects) {
172+
const shrinkwrapHash: string | undefined = noProjectHashes[shrinkwrapFile];
173+
if (shrinkwrapHash) {
174+
projectHashDeps.get(project.packageName)!.files[shrinkwrapFile] = shrinkwrapHash;
175+
}
141176
}
142177
}
143178

‎apps/rush-lib/src/logic/pnpm/PnpmProjectDependencyManifest.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ export class PnpmProjectDependencyManifest {
2929

3030
private _projectDependencyManifestFile: Map<string, string>;
3131

32+
public static getFilePathForProject(project: RushConfigurationProject): string {
33+
return path.join(
34+
project.projectRushTempFolder,
35+
RushConstants.projectDependencyManifestFilename
36+
);
37+
}
38+
3239
public constructor(options: IPnpmProjectDependencyManifestOptions) {
3340
this._pnpmShrinkwrapFile = options.pnpmShrinkwrapFile;
3441
this._project = options.project;
35-
this._projectDependencyManifestFilename = path.join(
36-
this._project.projectRushTempFolder,
37-
RushConstants.projectDependencyManifestFilename
38-
);
42+
this._projectDependencyManifestFilename = PnpmProjectDependencyManifest.getFilePathForProject(this._project);
3943

4044
this._projectDependencyManifestFile = new Map<string, string>();
4145
}

0 commit comments

Comments
 (0)