Skip to content

Commit 2a56595

Browse files
committed
Include some more safety around the project-specific dependency files.
1 parent 825357c commit 2a56595

4 files changed

Lines changed: 47 additions & 13 deletions

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
} from '@microsoft/package-deps-hash';
1212
import {
1313
Path,
14-
InternalError
14+
InternalError,
15+
FileSystem
1516
} from '@microsoft/node-core-library';
1617

1718
import { RushConfiguration } from '../api/RushConfiguration';
@@ -146,6 +147,14 @@ export class PackageChangeAnalyzer {
146147
this._rushConfiguration.rushJsonFolder,
147148
dependencyManifestFilePath
148149
).replace(/\\/g, '/');
150+
151+
if (!FileSystem.exists(dependencyManifestFilePath)) {
152+
throw new Error(
153+
`A project dependency file (${relativeDependencyManifestFilePath}) is missing. You may need to run ` +
154+
'"rush unlink" and "rush link".'
155+
);
156+
}
157+
149158
projects.push(project);
150159
projectDependencyManifestPaths.push(relativeDependencyManifestFilePath);
151160
}

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// See LICENSE in the project root for license information.
33

44
import * as path from 'path';
5+
import { FileSystem } from '@microsoft/node-core-library';
56

67
import { RushConfiguration } from '../api/RushConfiguration';
78
import { Utilities } from '../utilities/Utilities';
8-
import { FileSystem } from '@microsoft/node-core-library';
9+
import { PnpmProjectDependencyManifest } from './pnpm/PnpmProjectDependencyManifest';
910

1011
/**
1112
* This class implements the logic for "rush unlink"
@@ -18,31 +19,45 @@ export class UnlinkManager {
1819
}
1920

2021
/**
21-
* Delete flag file and all the existing node_modules
22-
* symlinks
22+
* Delete flag file and all the existing node_modules symlinks and all
23+
* project/.rush/temp/project-dependencies.json files
24+
*
25+
* Returns true if anything was deleted.
2326
*/
2427
public unlink(): boolean {
2528
this._deleteFlagFile();
26-
return this._deleteSymlinks();
29+
return this._deleteProjectFiles();
2730
}
2831

2932
/**
30-
* Delete all the node_modules symlinks of configured Rush
31-
* projects
33+
* Delete:
34+
* - all the node_modules symlinks of configured Rush projects
35+
* - all of the project/.rush/temp/project-dependencies.json files of configured Rush projects
36+
*
37+
* Returns true if anything was deleted
3238
* */
33-
private _deleteSymlinks(): boolean {
34-
let didDeleteSymlinks: boolean = false;
39+
private _deleteProjectFiles(): boolean {
40+
let didDeleteAnything: boolean = false;
3541

3642
for (const rushProject of this._rushConfiguration.projects) {
3743
const localModuleFolder: string = path.join(rushProject.projectFolder, 'node_modules');
3844
if (FileSystem.exists(localModuleFolder)) {
39-
console.log('Purging ' + localModuleFolder);
45+
console.log(`Purging ${localModuleFolder}`);
4046
Utilities.dangerouslyDeletePath(localModuleFolder);
41-
didDeleteSymlinks = true;
47+
didDeleteAnything = true;
48+
}
49+
50+
const projectDependencyManifestFilePath: string = PnpmProjectDependencyManifest.getFilePathForProject(
51+
rushProject
52+
);
53+
if (FileSystem.exists(projectDependencyManifestFilePath)) {
54+
console.log(`Deleting ${projectDependencyManifestFilePath}`);
55+
FileSystem.deleteFile(projectDependencyManifestFilePath);
56+
didDeleteAnything = true;
4257
}
4358
}
4459

45-
return didDeleteSymlinks;
60+
return didDeleteAnything;
4661
}
4762

4863
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ export class PnpmLinkManager extends BaseLinkManager {
286286

287287
if (!this._rushConfiguration.pnpmOptions.disablePerProjectDependencyManifest) {
288288
pnpmProjectDependencyManifest.save();
289+
} else {
290+
pnpmProjectDependencyManifest.deleteIfExists();
289291
}
290292

291293
// Also symlink the ".bin" folder

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import * as path from 'path';
55
import {
66
JsonFile,
7-
InternalError
7+
InternalError,
8+
FileSystem
89
} from '@microsoft/node-core-library';
910

1011
import {
@@ -78,6 +79,13 @@ export class PnpmProjectDependencyManifest {
7879
);
7980
}
8081

82+
/**
83+
* If the project/.rush/temp/project-dependencies.json file exists, delete it. Otherwise, do nothing.
84+
*/
85+
public deleteIfExists(): void {
86+
FileSystem.deleteFile(this._projectDependencyManifestFilename, { throwIfNotExists: false });
87+
}
88+
8189
private _addDependencyInternal(
8290
name: string,
8391
version: string

0 commit comments

Comments
 (0)