forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnlinkManager.ts
More file actions
70 lines (60 loc) · 2.27 KB
/
UnlinkManager.ts
File metadata and controls
70 lines (60 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as path from 'path';
import { FileSystem } from '@rushstack/node-core-library';
import { RushConfiguration } from '../api/RushConfiguration';
import { Utilities } from '../utilities/Utilities';
import { PnpmProjectDependencyManifest } from './pnpm/PnpmProjectDependencyManifest';
/**
* This class implements the logic for "rush unlink"
*/
export class UnlinkManager {
private _rushConfiguration: RushConfiguration;
public constructor(rushConfiguration: RushConfiguration) {
this._rushConfiguration = rushConfiguration;
}
/**
* Delete flag file and all the existing node_modules symlinks and all
* project/.rush/temp/shrinkwrap-deps.json files
*
* Returns true if anything was deleted.
*/
public unlink(): boolean {
this._deleteFlagFile();
return this._deleteProjectFiles();
}
/**
* Delete:
* - all the node_modules symlinks of configured Rush projects
* - all of the project/.rush/temp/shrinkwrap-deps.json files of configured Rush projects
*
* Returns true if anything was deleted
* */
private _deleteProjectFiles(): boolean {
let didDeleteAnything: boolean = false;
for (const rushProject of this._rushConfiguration.projects) {
const localModuleFolder: string = path.join(rushProject.projectFolder, 'node_modules');
if (FileSystem.exists(localModuleFolder)) {
console.log(`Purging ${localModuleFolder}`);
Utilities.dangerouslyDeletePath(localModuleFolder);
didDeleteAnything = true;
}
const projectDependencyManifestFilePath: string = PnpmProjectDependencyManifest.getFilePathForProject(
rushProject
);
if (FileSystem.exists(projectDependencyManifestFilePath)) {
console.log(`Deleting ${projectDependencyManifestFilePath}`);
FileSystem.deleteFile(projectDependencyManifestFilePath);
didDeleteAnything = true;
}
}
return didDeleteAnything;
}
/**
* Delete the flag file if it exists; this will ensure that
* a full "rush link" is required next time
*/
private _deleteFlagFile(): void {
Utilities.deleteFile(this._rushConfiguration.rushLinkJsonFilename);
}
}