@rushstack/package-extractor 0.9.9 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +39 -0
- package/CHANGELOG.md +13 -1
- package/dist/scripts/create-links.js +69206 -20310
- package/dist/scripts/create-links.js.map +1 -1
- package/lib/PackageExtractor.d.ts.map +1 -1
- package/lib/PackageExtractor.js +17 -28
- package/lib/PackageExtractor.js.map +1 -1
- package/lib/PathConstants.d.ts +3 -2
- package/lib/PathConstants.d.ts.map +1 -1
- package/lib/PathConstants.js +4 -3
- package/lib/PathConstants.js.map +1 -1
- package/lib/Utils.d.ts +8 -0
- package/lib/Utils.d.ts.map +1 -1
- package/lib/Utils.js +32 -1
- package/lib/Utils.js.map +1 -1
- package/lib/scripts/createLinks/cli/CreateLinksCommandLineParser.d.ts +8 -0
- package/lib/scripts/createLinks/cli/CreateLinksCommandLineParser.d.ts.map +1 -0
- package/lib/scripts/createLinks/cli/CreateLinksCommandLineParser.js +36 -0
- package/lib/scripts/createLinks/cli/CreateLinksCommandLineParser.js.map +1 -0
- package/lib/scripts/createLinks/cli/actions/CreateLinksAction.d.ts +10 -0
- package/lib/scripts/createLinks/cli/actions/CreateLinksAction.d.ts.map +1 -0
- package/lib/scripts/createLinks/cli/actions/CreateLinksAction.js +91 -0
- package/lib/scripts/createLinks/cli/actions/CreateLinksAction.js.map +1 -0
- package/lib/scripts/createLinks/cli/actions/RemoveLinksAction.d.ts +10 -0
- package/lib/scripts/createLinks/cli/actions/RemoveLinksAction.d.ts.map +1 -0
- package/lib/scripts/createLinks/cli/actions/RemoveLinksAction.js +38 -0
- package/lib/scripts/createLinks/cli/actions/RemoveLinksAction.js.map +1 -0
- package/lib/scripts/createLinks/start.d.ts +2 -0
- package/lib/scripts/createLinks/start.d.ts.map +1 -0
- package/lib/scripts/createLinks/start.js +10 -0
- package/lib/scripts/createLinks/start.js.map +1 -0
- package/lib/scripts/createLinks/utilities/CreateLinksUtilities.d.ts +3 -0
- package/lib/scripts/createLinks/utilities/CreateLinksUtilities.d.ts.map +1 -0
- package/lib/scripts/createLinks/utilities/CreateLinksUtilities.js +15 -0
- package/lib/scripts/createLinks/utilities/CreateLinksUtilities.js.map +1 -0
- package/lib/scripts/createLinks/utilities/constants.d.ts +34 -0
- package/lib/scripts/createLinks/utilities/constants.d.ts.map +1 -0
- package/lib/scripts/createLinks/utilities/constants.js +43 -0
- package/lib/scripts/createLinks/utilities/constants.js.map +1 -0
- package/package.json +7 -6
- package/lib/scripts/create-links.d.ts +0 -2
- package/lib/scripts/create-links.d.ts.map +0 -1
- package/lib/scripts/create-links.js +0 -119
- package/lib/scripts/create-links.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateLinksAction.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/createLinks/cli/actions/CreateLinksAction.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAiC,MAAM,4BAA4B,CAAC;AAqE9F,qBAAa,iBAAkB,SAAQ,iBAAiB;IACtD,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,sBAAsB,CAA2B;IACzD,OAAO,CAAC,kBAAkB,CAA2B;gBAElC,QAAQ,EAAE,SAAS;cAoBtB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAsB3C"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CreateLinksAction = void 0;
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
11
|
+
const ts_command_line_1 = require("@rushstack/ts-command-line");
|
|
12
|
+
const Utils_1 = require("../../../../Utils");
|
|
13
|
+
const CreateLinksUtilities_1 = require("../../utilities/CreateLinksUtilities");
|
|
14
|
+
const constants_1 = require("../../utilities/constants");
|
|
15
|
+
const RemoveLinksAction_1 = require("./RemoveLinksAction");
|
|
16
|
+
async function createLinksAsync(terminal, targetRootFolder, extractorMetadataObject) {
|
|
17
|
+
await node_core_library_1.Async.forEachAsync(extractorMetadataObject.links, async (linkInfo) => {
|
|
18
|
+
// Link to the relative path for symlinks
|
|
19
|
+
const newLinkPath = node_path_1.default.join(targetRootFolder, linkInfo.linkPath);
|
|
20
|
+
const linkTargetPath = node_path_1.default.join(targetRootFolder, linkInfo.targetPath);
|
|
21
|
+
// Make sure the containing folder exists
|
|
22
|
+
await node_core_library_1.FileSystem.ensureFolderAsync(node_path_1.default.dirname(newLinkPath));
|
|
23
|
+
// NOTE: This logic is based on NpmLinkManager._createSymlink()
|
|
24
|
+
if (linkInfo.kind === 'folderLink') {
|
|
25
|
+
terminal.writeVerboseLine(`Creating linked folder at path "${newLinkPath}"`);
|
|
26
|
+
await node_core_library_1.FileSystem.createSymbolicLinkJunctionAsync({ newLinkPath, linkTargetPath });
|
|
27
|
+
}
|
|
28
|
+
else if (linkInfo.kind === 'fileLink') {
|
|
29
|
+
// Use hardlinks for Windows and symlinks for other platforms since creating a symbolic link
|
|
30
|
+
// requires administrator permission on Windows. This may cause unexpected behaviour for consumers
|
|
31
|
+
// of the hardlinked files. If this becomes an issue, we may need to revisit this.
|
|
32
|
+
terminal.writeVerboseLine(`Creating linked file at path "${newLinkPath}"`);
|
|
33
|
+
if (process.platform === 'win32') {
|
|
34
|
+
await node_core_library_1.FileSystem.createHardLinkAsync({ newLinkPath, linkTargetPath });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
await node_core_library_1.FileSystem.createSymbolicLinkFileAsync({ newLinkPath, linkTargetPath });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}, { concurrency: constants_1.MAX_CONCURRENCY });
|
|
41
|
+
}
|
|
42
|
+
async function realizeFilesAsync(terminal, targetRootFolder, extractorMetadataObject) {
|
|
43
|
+
await node_core_library_1.Async.forEachAsync(extractorMetadataObject.files, async (relativeFilePath) => {
|
|
44
|
+
const filePath = `${targetRootFolder}/${relativeFilePath}`;
|
|
45
|
+
const realFilePath = await node_core_library_1.FileSystem.getRealPathAsync(filePath);
|
|
46
|
+
if (!node_core_library_1.Path.isEqual(realFilePath, filePath)) {
|
|
47
|
+
// Delete the existing symlink and create a hardlink to the real file, since creating hardlinks
|
|
48
|
+
// is less overhead than copying the file.
|
|
49
|
+
terminal.writeVerboseLine(`Realizing file at path "${filePath}"`);
|
|
50
|
+
await node_core_library_1.FileSystem.deleteFileAsync(filePath);
|
|
51
|
+
await node_core_library_1.FileSystem.createHardLinkAsync({ newLinkPath: filePath, linkTargetPath: realFilePath });
|
|
52
|
+
}
|
|
53
|
+
}, { concurrency: constants_1.MAX_CONCURRENCY });
|
|
54
|
+
}
|
|
55
|
+
class CreateLinksAction extends ts_command_line_1.CommandLineAction {
|
|
56
|
+
constructor(terminal) {
|
|
57
|
+
super({
|
|
58
|
+
actionName: 'create',
|
|
59
|
+
summary: 'Create symlinks for extraction',
|
|
60
|
+
documentation: 'This action creates symlinks for the extraction process.'
|
|
61
|
+
});
|
|
62
|
+
this._terminal = terminal;
|
|
63
|
+
this._realizeFilesParameter = this.defineFlagParameter({
|
|
64
|
+
parameterLongName: constants_1.REALIZE_FILES_PARAMETER_NAME,
|
|
65
|
+
description: 'Realize files instead of creating symlinks'
|
|
66
|
+
});
|
|
67
|
+
this._linkBinsParameter = this.defineFlagParameter({
|
|
68
|
+
parameterLongName: constants_1.LINK_BINS_PARAMETER_NAME,
|
|
69
|
+
description: 'Create the .bin files for extracted packages'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async onExecute() {
|
|
73
|
+
const extractorMetadataObject = await (0, CreateLinksUtilities_1.getExtractorMetadataAsync)();
|
|
74
|
+
const realizeFiles = this._realizeFilesParameter.value;
|
|
75
|
+
const linkBins = this._linkBinsParameter.value;
|
|
76
|
+
this._terminal.writeLine(`Creating links for extraction at path "${constants_1.TARGET_ROOT_FOLDER}"`);
|
|
77
|
+
await (0, RemoveLinksAction_1.removeLinksAsync)(this._terminal, constants_1.TARGET_ROOT_FOLDER, extractorMetadataObject);
|
|
78
|
+
await createLinksAsync(this._terminal, constants_1.TARGET_ROOT_FOLDER, extractorMetadataObject);
|
|
79
|
+
if (realizeFiles) {
|
|
80
|
+
this._terminal.writeLine(`Realizing files for extraction at path "${constants_1.TARGET_ROOT_FOLDER}"`);
|
|
81
|
+
await realizeFilesAsync(this._terminal, constants_1.TARGET_ROOT_FOLDER, extractorMetadataObject);
|
|
82
|
+
}
|
|
83
|
+
if (linkBins) {
|
|
84
|
+
this._terminal.writeLine(`Linking bins for extraction at path "${constants_1.TARGET_ROOT_FOLDER}"`);
|
|
85
|
+
const extractedProjectFolderPaths = extractorMetadataObject.projects.map((project) => node_path_1.default.join(constants_1.TARGET_ROOT_FOLDER, project.path));
|
|
86
|
+
await (0, Utils_1.makeBinLinksAsync)(this._terminal, extractedProjectFolderPaths);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.CreateLinksAction = CreateLinksAction;
|
|
91
|
+
//# sourceMappingURL=CreateLinksAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateLinksAction.js","sourceRoot":"","sources":["../../../../../src/scripts/createLinks/cli/actions/CreateLinksAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,0DAA6B;AAC7B,oEAAuE;AAEvE,gEAA8F;AAE9F,6CAAsD;AACtD,+EAAiF;AACjF,yDAKmC;AACnC,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IAES,KAAK,CAAC,SAAS;QACvB,MAAM,uBAAuB,GAA2B,MAAM,IAAA,gDAAyB,GAAE,CAAC;QAC1F,MAAM,YAAY,GAAY,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC;QAChE,MAAM,QAAQ,GAAY,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;QAExD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,0CAA0C,8BAAkB,GAAG,CAAC,CAAC;QAC1F,MAAM,IAAA,oCAAgB,EAAC,IAAI,CAAC,SAAS,EAAE,8BAAkB,EAAE,uBAAuB,CAAC,CAAC;QACpF,MAAM,gBAAgB,CAAC,IAAI,CAAC,SAAS,EAAE,8BAAkB,EAAE,uBAAuB,CAAC,CAAC;QAEpF,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,2CAA2C,8BAAkB,GAAG,CAAC,CAAC;YAC3F,MAAM,iBAAiB,CAAC,IAAI,CAAC,SAAS,EAAE,8BAAkB,EAAE,uBAAuB,CAAC,CAAC;QACvF,CAAC;QAED,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,wCAAwC,8BAAkB,GAAG,CAAC,CAAC;YACxF,MAAM,2BAA2B,GAAa,uBAAuB,CAAC,QAAQ,CAAC,GAAG,CAChF,CAAC,OAAyB,EAAE,EAAE,CAAC,mBAAI,CAAC,IAAI,CAAC,8BAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,CAC3E,CAAC;YACF,MAAM,IAAA,yBAAiB,EAAC,IAAI,CAAC,SAAS,EAAE,2BAA2B,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;CACF;AA/CD,8CA+CC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport path from 'node:path';\nimport { Async, FileSystem, Path } from '@rushstack/node-core-library';\nimport type { ITerminal } from '@rushstack/terminal';\nimport { CommandLineAction, type CommandLineFlagParameter } from '@rushstack/ts-command-line';\nimport type { IExtractorMetadataJson, IProjectInfoJson } from '../../../../PackageExtractor';\nimport { makeBinLinksAsync } from '../../../../Utils';\nimport { getExtractorMetadataAsync } from '../../utilities/CreateLinksUtilities';\nimport {\n TARGET_ROOT_FOLDER,\n REALIZE_FILES_PARAMETER_NAME,\n LINK_BINS_PARAMETER_NAME,\n MAX_CONCURRENCY\n} from '../../utilities/constants';\nimport { removeLinksAsync } from './RemoveLinksAction';\n\nasync function createLinksAsync(\n terminal: ITerminal,\n targetRootFolder: string,\n extractorMetadataObject: IExtractorMetadataJson\n): Promise<void> {\n await Async.forEachAsync(\n extractorMetadataObject.links,\n async (linkInfo) => {\n // Link to the relative path for symlinks\n const newLinkPath: string = path.join(targetRootFolder, linkInfo.linkPath);\n const linkTargetPath: string = path.join(targetRootFolder, linkInfo.targetPath);\n\n // Make sure the containing folder exists\n await FileSystem.ensureFolderAsync(path.dirname(newLinkPath));\n\n // NOTE: This logic is based on NpmLinkManager._createSymlink()\n if (linkInfo.kind === 'folderLink') {\n terminal.writeVerboseLine(`Creating linked folder at path \"${newLinkPath}\"`);\n await FileSystem.createSymbolicLinkJunctionAsync({ newLinkPath, linkTargetPath });\n } else if (linkInfo.kind === 'fileLink') {\n // Use hardlinks for Windows and symlinks for other platforms since creating a symbolic link\n // requires administrator permission on Windows. This may cause unexpected behaviour for consumers\n // of the hardlinked files. If this becomes an issue, we may need to revisit this.\n terminal.writeVerboseLine(`Creating linked file at path \"${newLinkPath}\"`);\n if (process.platform === 'win32') {\n await FileSystem.createHardLinkAsync({ newLinkPath, linkTargetPath });\n } else {\n await FileSystem.createSymbolicLinkFileAsync({ newLinkPath, linkTargetPath });\n }\n }\n },\n { concurrency: MAX_CONCURRENCY }\n );\n}\n\nasync function realizeFilesAsync(\n terminal: ITerminal,\n targetRootFolder: string,\n extractorMetadataObject: IExtractorMetadataJson\n): Promise<void> {\n await Async.forEachAsync(\n extractorMetadataObject.files,\n async (relativeFilePath) => {\n const filePath: string = `${targetRootFolder}/${relativeFilePath}`;\n const realFilePath: string = await FileSystem.getRealPathAsync(filePath);\n if (!Path.isEqual(realFilePath, filePath)) {\n // Delete the existing symlink and create a hardlink to the real file, since creating hardlinks\n // is less overhead than copying the file.\n terminal.writeVerboseLine(`Realizing file at path \"${filePath}\"`);\n await FileSystem.deleteFileAsync(filePath);\n await FileSystem.createHardLinkAsync({ newLinkPath: filePath, linkTargetPath: realFilePath });\n }\n },\n { concurrency: MAX_CONCURRENCY }\n );\n}\n\nexport class CreateLinksAction extends CommandLineAction {\n private _terminal: ITerminal;\n private _realizeFilesParameter: CommandLineFlagParameter;\n private _linkBinsParameter: CommandLineFlagParameter;\n\n public constructor(terminal: ITerminal) {\n super({\n actionName: 'create',\n summary: 'Create symlinks for extraction',\n documentation: 'This action creates symlinks for the extraction process.'\n });\n\n this._terminal = terminal;\n\n this._realizeFilesParameter = this.defineFlagParameter({\n parameterLongName: REALIZE_FILES_PARAMETER_NAME,\n description: 'Realize files instead of creating symlinks'\n });\n\n this._linkBinsParameter = this.defineFlagParameter({\n parameterLongName: LINK_BINS_PARAMETER_NAME,\n description: 'Create the .bin files for extracted packages'\n });\n }\n\n protected async onExecute(): Promise<void> {\n const extractorMetadataObject: IExtractorMetadataJson = await getExtractorMetadataAsync();\n const realizeFiles: boolean = this._realizeFilesParameter.value;\n const linkBins: boolean = this._linkBinsParameter.value;\n\n this._terminal.writeLine(`Creating links for extraction at path \"${TARGET_ROOT_FOLDER}\"`);\n await removeLinksAsync(this._terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);\n await createLinksAsync(this._terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);\n\n if (realizeFiles) {\n this._terminal.writeLine(`Realizing files for extraction at path \"${TARGET_ROOT_FOLDER}\"`);\n await realizeFilesAsync(this._terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);\n }\n\n if (linkBins) {\n this._terminal.writeLine(`Linking bins for extraction at path \"${TARGET_ROOT_FOLDER}\"`);\n const extractedProjectFolderPaths: string[] = extractorMetadataObject.projects.map(\n (project: IProjectInfoJson) => path.join(TARGET_ROOT_FOLDER, project.path)\n );\n await makeBinLinksAsync(this._terminal, extractedProjectFolderPaths);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ITerminal } from '@rushstack/terminal';
|
|
2
|
+
import { CommandLineAction } from '@rushstack/ts-command-line';
|
|
3
|
+
import type { IExtractorMetadataJson } from '../../../../PackageExtractor';
|
|
4
|
+
export declare function removeLinksAsync(terminal: ITerminal, targetRootFolder: string, extractorMetadataObject: IExtractorMetadataJson): Promise<void>;
|
|
5
|
+
export declare class RemoveLinksAction extends CommandLineAction {
|
|
6
|
+
private _terminal;
|
|
7
|
+
constructor(terminal: ITerminal);
|
|
8
|
+
protected onExecute(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=RemoveLinksAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoveLinksAction.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/createLinks/cli/actions/RemoveLinksAction.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAI3E,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,SAAS,EACnB,gBAAgB,EAAE,MAAM,EACxB,uBAAuB,EAAE,sBAAsB,GAC9C,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,qBAAa,iBAAkB,SAAQ,iBAAiB;IACtD,OAAO,CAAC,SAAS,CAAY;gBAEV,QAAQ,EAAE,SAAS;cAUtB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAM3C"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.RemoveLinksAction = exports.removeLinksAsync = void 0;
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
11
|
+
const ts_command_line_1 = require("@rushstack/ts-command-line");
|
|
12
|
+
const CreateLinksUtilities_1 = require("../../utilities/CreateLinksUtilities");
|
|
13
|
+
const constants_1 = require("../../utilities/constants");
|
|
14
|
+
async function removeLinksAsync(terminal, targetRootFolder, extractorMetadataObject) {
|
|
15
|
+
await node_core_library_1.Async.forEachAsync(extractorMetadataObject.links, async ({ linkPath }) => {
|
|
16
|
+
const newLinkPath = node_path_1.default.join(targetRootFolder, linkPath);
|
|
17
|
+
terminal.writeVerboseLine(`Removing link at path "${newLinkPath}"`);
|
|
18
|
+
await node_core_library_1.FileSystem.deleteFileAsync(newLinkPath, { throwIfNotExists: false });
|
|
19
|
+
}, { concurrency: constants_1.MAX_CONCURRENCY });
|
|
20
|
+
}
|
|
21
|
+
exports.removeLinksAsync = removeLinksAsync;
|
|
22
|
+
class RemoveLinksAction extends ts_command_line_1.CommandLineAction {
|
|
23
|
+
constructor(terminal) {
|
|
24
|
+
super({
|
|
25
|
+
actionName: 'remove',
|
|
26
|
+
summary: 'Remove symlinks created by the "create" action',
|
|
27
|
+
documentation: 'This action removes the symlinks created by the "create" action.'
|
|
28
|
+
});
|
|
29
|
+
this._terminal = terminal;
|
|
30
|
+
}
|
|
31
|
+
async onExecute() {
|
|
32
|
+
const extractorMetadataObject = await (0, CreateLinksUtilities_1.getExtractorMetadataAsync)();
|
|
33
|
+
this._terminal.writeLine(`Removing links for extraction at path "${constants_1.TARGET_ROOT_FOLDER}"`);
|
|
34
|
+
await removeLinksAsync(this._terminal, constants_1.TARGET_ROOT_FOLDER, extractorMetadataObject);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.RemoveLinksAction = RemoveLinksAction;
|
|
38
|
+
//# sourceMappingURL=RemoveLinksAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoveLinksAction.js","sourceRoot":"","sources":["../../../../../src/scripts/createLinks/cli/actions/RemoveLinksAction.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,0DAA6B;AAC7B,oEAAiE;AAEjE,gEAA+D;AAE/D,+EAAiF;AACjF,yDAAgF;AAEzE,KAAK,UAAU,gBAAgB,CACpC,QAAmB,EACnB,gBAAwB,EACxB,uBAA+C;IAE/C,MAAM,yBAAK,CAAC,YAAY,CACtB,uBAAuB,CAAC,KAAK,EAC7B,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;QACrB,MAAM,WAAW,GAAW,mBAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAClE,QAAQ,CAAC,gBAAgB,CAAC,0BAA0B,WAAW,GAAG,CAAC,CAAC;QACpE,MAAM,8BAAU,CAAC,eAAe,CAAC,WAAW,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7E,CAAC,EACD,EAAE,WAAW,EAAE,2BAAe,EAAE,CACjC,CAAC;AACJ,CAAC;AAdD,4CAcC;AAED,MAAa,iBAAkB,SAAQ,mCAAiB;IAGtD,YAAmB,QAAmB;QACpC,KAAK,CAAC;YACJ,UAAU,EAAE,QAAQ;YACpB,OAAO,EAAE,gDAAgD;YACzD,aAAa,EAAE,kEAAkE;SAClF,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAES,KAAK,CAAC,SAAS;QACvB,MAAM,uBAAuB,GAA2B,MAAM,IAAA,gDAAyB,GAAE,CAAC;QAE1F,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,0CAA0C,8BAAkB,GAAG,CAAC,CAAC;QAC1F,MAAM,gBAAgB,CAAC,IAAI,CAAC,SAAS,EAAE,8BAAkB,EAAE,uBAAuB,CAAC,CAAC;IACtF,CAAC;CACF;AAnBD,8CAmBC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport path from 'node:path';\nimport { Async, FileSystem } from '@rushstack/node-core-library';\nimport type { ITerminal } from '@rushstack/terminal';\nimport { CommandLineAction } from '@rushstack/ts-command-line';\nimport type { IExtractorMetadataJson } from '../../../../PackageExtractor';\nimport { getExtractorMetadataAsync } from '../../utilities/CreateLinksUtilities';\nimport { TARGET_ROOT_FOLDER, MAX_CONCURRENCY } from '../../utilities/constants';\n\nexport async function removeLinksAsync(\n terminal: ITerminal,\n targetRootFolder: string,\n extractorMetadataObject: IExtractorMetadataJson\n): Promise<void> {\n await Async.forEachAsync(\n extractorMetadataObject.links,\n async ({ linkPath }) => {\n const newLinkPath: string = path.join(targetRootFolder, linkPath);\n terminal.writeVerboseLine(`Removing link at path \"${newLinkPath}\"`);\n await FileSystem.deleteFileAsync(newLinkPath, { throwIfNotExists: false });\n },\n { concurrency: MAX_CONCURRENCY }\n );\n}\n\nexport class RemoveLinksAction extends CommandLineAction {\n private _terminal: ITerminal;\n\n public constructor(terminal: ITerminal) {\n super({\n actionName: 'remove',\n summary: 'Remove symlinks created by the \"create\" action',\n documentation: 'This action removes the symlinks created by the \"create\" action.'\n });\n\n this._terminal = terminal;\n }\n\n protected async onExecute(): Promise<void> {\n const extractorMetadataObject: IExtractorMetadataJson = await getExtractorMetadataAsync();\n\n this._terminal.writeLine(`Removing links for extraction at path \"${TARGET_ROOT_FOLDER}\"`);\n await removeLinksAsync(this._terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../src/scripts/createLinks/start.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const terminal_1 = require("@rushstack/terminal");
|
|
6
|
+
const CreateLinksCommandLineParser_1 = require("./cli/CreateLinksCommandLineParser");
|
|
7
|
+
const terminal = new terminal_1.Terminal(new terminal_1.ConsoleTerminalProvider({ verboseEnabled: true }));
|
|
8
|
+
const parser = new CreateLinksCommandLineParser_1.CreateLinksCommandLineParser(terminal);
|
|
9
|
+
parser.executeAsync().catch(terminal.writeErrorLine);
|
|
10
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/scripts/createLinks/start.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,kDAAwE;AAExE,qFAAkF;AAElF,MAAM,QAAQ,GAAa,IAAI,mBAAQ,CAAC,IAAI,kCAAuB,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAE/F,MAAM,MAAM,GAAiC,IAAI,2DAA4B,CAAC,QAAQ,CAAC,CAAC;AACxF,MAAM,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { Terminal, ConsoleTerminalProvider } from '@rushstack/terminal';\n\nimport { CreateLinksCommandLineParser } from './cli/CreateLinksCommandLineParser';\n\nconst terminal: Terminal = new Terminal(new ConsoleTerminalProvider({ verboseEnabled: true }));\n\nconst parser: CreateLinksCommandLineParser = new CreateLinksCommandLineParser(terminal);\nparser.executeAsync().catch(terminal.writeErrorLine);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateLinksUtilities.d.ts","sourceRoot":"","sources":["../../../../src/scripts/createLinks/utilities/CreateLinksUtilities.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAGxE,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAKjF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getExtractorMetadataAsync = void 0;
|
|
6
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
7
|
+
const PathConstants_1 = require("../../../PathConstants");
|
|
8
|
+
async function getExtractorMetadataAsync() {
|
|
9
|
+
const extractorMetadataPath = `${__dirname}/${PathConstants_1.EXTRACTOR_METADATA_FILENAME}`;
|
|
10
|
+
const extractorMetadataJson = await node_core_library_1.FileSystem.readFileAsync(extractorMetadataPath);
|
|
11
|
+
const extractorMetadataObject = JSON.parse(extractorMetadataJson);
|
|
12
|
+
return extractorMetadataObject;
|
|
13
|
+
}
|
|
14
|
+
exports.getExtractorMetadataAsync = getExtractorMetadataAsync;
|
|
15
|
+
//# sourceMappingURL=CreateLinksUtilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateLinksUtilities.js","sourceRoot":"","sources":["../../../../src/scripts/createLinks/utilities/CreateLinksUtilities.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAA0D;AAE1D,0DAAqE;AAE9D,KAAK,UAAU,yBAAyB;IAC7C,MAAM,qBAAqB,GAAW,GAAG,SAAS,IAAI,2CAA2B,EAAE,CAAC;IACpF,MAAM,qBAAqB,GAAW,MAAM,8BAAU,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;IAC5F,MAAM,uBAAuB,GAA2B,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC1F,OAAO,uBAAuB,CAAC;AACjC,CAAC;AALD,8DAKC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { FileSystem } from '@rushstack/node-core-library';\nimport type { IExtractorMetadataJson } from '../../../PackageExtractor';\nimport { EXTRACTOR_METADATA_FILENAME } from '../../../PathConstants';\n\nexport async function getExtractorMetadataAsync(): Promise<IExtractorMetadataJson> {\n const extractorMetadataPath: string = `${__dirname}/${EXTRACTOR_METADATA_FILENAME}`;\n const extractorMetadataJson: string = await FileSystem.readFileAsync(extractorMetadataPath);\n const extractorMetadataObject: IExtractorMetadataJson = JSON.parse(extractorMetadataJson);\n return extractorMetadataObject;\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TARGET_ROOT_SCRIPT_RELATIVE_PATH_TEMPLATE_STRING as TargetRootScriptRelativePathTemplateString } from '../../../PackageExtractor';
|
|
2
|
+
/**
|
|
3
|
+
* The maximum number of concurrent operations to perform.
|
|
4
|
+
*/
|
|
5
|
+
export declare const MAX_CONCURRENCY: number;
|
|
6
|
+
/**
|
|
7
|
+
* The name of the action to create symlinks.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CREATE_ACTION_NAME: 'create';
|
|
10
|
+
/**
|
|
11
|
+
* The name of the action to remove symlinks.
|
|
12
|
+
*/
|
|
13
|
+
export declare const REMOVE_ACTION_NAME: 'remove';
|
|
14
|
+
/**
|
|
15
|
+
* The name of the parameter to realize files when creating symlinks.
|
|
16
|
+
*/
|
|
17
|
+
export declare const REALIZE_FILES_PARAMETER_NAME: '--realize-files';
|
|
18
|
+
/**
|
|
19
|
+
* The name of the parameter to link bins when creating symlinks.
|
|
20
|
+
*/
|
|
21
|
+
export declare const LINK_BINS_PARAMETER_NAME: '--link-bins';
|
|
22
|
+
/**
|
|
23
|
+
* The name of the parameter to link packages when creating symlinks. The actual value of this
|
|
24
|
+
* export is modified after bundling the script to ensure that the extracted version of the script
|
|
25
|
+
* contains the relative path from the extraction target folder to the script. Generally, this
|
|
26
|
+
* value should not be used directly, but rather the `TARGET_ROOT_FOLDER` export should be used
|
|
27
|
+
* instead.
|
|
28
|
+
*/
|
|
29
|
+
export declare const TARGET_ROOT_SCRIPT_RELATIVE_PATH: typeof TargetRootScriptRelativePathTemplateString;
|
|
30
|
+
/**
|
|
31
|
+
* The path to the root folder where symlinks are created.
|
|
32
|
+
*/
|
|
33
|
+
export declare const TARGET_ROOT_FOLDER: string;
|
|
34
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/scripts/createLinks/utilities/constants.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gDAAgD,IAAI,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AAEhJ;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAA6B,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAmB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAmB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,4BAA4B,EAAE,iBAAqC,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,aAA6B,CAAC;AAErE;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,EAAE,OAAO,0CAChB,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAkE,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.TARGET_ROOT_FOLDER = exports.TARGET_ROOT_SCRIPT_RELATIVE_PATH = exports.LINK_BINS_PARAMETER_NAME = exports.REALIZE_FILES_PARAMETER_NAME = exports.REMOVE_ACTION_NAME = exports.CREATE_ACTION_NAME = exports.MAX_CONCURRENCY = void 0;
|
|
9
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
/**
|
|
12
|
+
* The maximum number of concurrent operations to perform.
|
|
13
|
+
*/
|
|
14
|
+
exports.MAX_CONCURRENCY = node_os_1.default.cpus().length * 2;
|
|
15
|
+
/**
|
|
16
|
+
* The name of the action to create symlinks.
|
|
17
|
+
*/
|
|
18
|
+
exports.CREATE_ACTION_NAME = 'create';
|
|
19
|
+
/**
|
|
20
|
+
* The name of the action to remove symlinks.
|
|
21
|
+
*/
|
|
22
|
+
exports.REMOVE_ACTION_NAME = 'remove';
|
|
23
|
+
/**
|
|
24
|
+
* The name of the parameter to realize files when creating symlinks.
|
|
25
|
+
*/
|
|
26
|
+
exports.REALIZE_FILES_PARAMETER_NAME = '--realize-files';
|
|
27
|
+
/**
|
|
28
|
+
* The name of the parameter to link bins when creating symlinks.
|
|
29
|
+
*/
|
|
30
|
+
exports.LINK_BINS_PARAMETER_NAME = '--link-bins';
|
|
31
|
+
/**
|
|
32
|
+
* The name of the parameter to link packages when creating symlinks. The actual value of this
|
|
33
|
+
* export is modified after bundling the script to ensure that the extracted version of the script
|
|
34
|
+
* contains the relative path from the extraction target folder to the script. Generally, this
|
|
35
|
+
* value should not be used directly, but rather the `TARGET_ROOT_FOLDER` export should be used
|
|
36
|
+
* instead.
|
|
37
|
+
*/
|
|
38
|
+
exports.TARGET_ROOT_SCRIPT_RELATIVE_PATH = '{TARGET_ROOT_SCRIPT_RELATIVE_PATH}';
|
|
39
|
+
/**
|
|
40
|
+
* The path to the root folder where symlinks are created.
|
|
41
|
+
*/
|
|
42
|
+
exports.TARGET_ROOT_FOLDER = node_path_1.default.resolve(__dirname, exports.TARGET_ROOT_SCRIPT_RELATIVE_PATH);
|
|
43
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/scripts/createLinks/utilities/constants.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,sDAAyB;AACzB,0DAA6B;AAG7B;;GAEG;AACU,QAAA,eAAe,GAAW,iBAAE,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAE5D;;GAEG;AACU,QAAA,kBAAkB,GAAa,QAAQ,CAAC;AAErD;;GAEG;AACU,QAAA,kBAAkB,GAAa,QAAQ,CAAC;AAErD;;GAEG;AACU,QAAA,4BAA4B,GAAsB,iBAAiB,CAAC;AAEjF;;GAEG;AACU,QAAA,wBAAwB,GAAkB,aAAa,CAAC;AAErE;;;;;;GAMG;AACU,QAAA,gCAAgC,GAC3C,oCAAoC,CAAC;AAEvC;;GAEG;AACU,QAAA,kBAAkB,GAAW,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,wCAAgC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport os from 'node:os';\nimport path from 'node:path';\nimport type { TARGET_ROOT_SCRIPT_RELATIVE_PATH_TEMPLATE_STRING as TargetRootScriptRelativePathTemplateString } from '../../../PackageExtractor';\n\n/**\n * The maximum number of concurrent operations to perform.\n */\nexport const MAX_CONCURRENCY: number = os.cpus().length * 2;\n\n/**\n * The name of the action to create symlinks.\n */\nexport const CREATE_ACTION_NAME: 'create' = 'create';\n\n/**\n * The name of the action to remove symlinks.\n */\nexport const REMOVE_ACTION_NAME: 'remove' = 'remove';\n\n/**\n * The name of the parameter to realize files when creating symlinks.\n */\nexport const REALIZE_FILES_PARAMETER_NAME: '--realize-files' = '--realize-files';\n\n/**\n * The name of the parameter to link bins when creating symlinks.\n */\nexport const LINK_BINS_PARAMETER_NAME: '--link-bins' = '--link-bins';\n\n/**\n * The name of the parameter to link packages when creating symlinks. The actual value of this\n * export is modified after bundling the script to ensure that the extracted version of the script\n * contains the relative path from the extraction target folder to the script. Generally, this\n * value should not be used directly, but rather the `TARGET_ROOT_FOLDER` export should be used\n * instead.\n */\nexport const TARGET_ROOT_SCRIPT_RELATIVE_PATH: typeof TargetRootScriptRelativePathTemplateString =\n '{TARGET_ROOT_SCRIPT_RELATIVE_PATH}';\n\n/**\n * The path to the root folder where symlinks are created.\n */\nexport const TARGET_ROOT_FOLDER: string = path.resolve(__dirname, TARGET_ROOT_SCRIPT_RELATIVE_PATH);\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/package-extractor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "A library for bundling selected files and dependencies into a deployable package.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "dist/package-extractor.d.ts",
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
"minimatch": "~3.0.3",
|
|
18
18
|
"npm-packlist": "~2.1.2",
|
|
19
19
|
"semver": "~7.5.4",
|
|
20
|
-
"@rushstack/node-core-library": "5.
|
|
21
|
-
"@rushstack/
|
|
20
|
+
"@rushstack/node-core-library": "5.10.0",
|
|
21
|
+
"@rushstack/ts-command-line": "4.23.1",
|
|
22
|
+
"@rushstack/terminal": "0.14.3"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@types/glob": "7.1.1",
|
|
@@ -28,9 +29,9 @@
|
|
|
28
29
|
"webpack": "~5.95.0",
|
|
29
30
|
"@types/semver": "7.5.0",
|
|
30
31
|
"local-node-rig": "1.0.0",
|
|
31
|
-
"@rushstack/heft
|
|
32
|
-
"@rushstack/heft": "0.
|
|
33
|
-
"@rushstack/webpack-preserve-dynamic-require-plugin": "0.11.
|
|
32
|
+
"@rushstack/heft": "0.68.7",
|
|
33
|
+
"@rushstack/heft-webpack5-plugin": "0.11.5",
|
|
34
|
+
"@rushstack/webpack-preserve-dynamic-require-plugin": "0.11.74"
|
|
34
35
|
},
|
|
35
36
|
"scripts": {
|
|
36
37
|
"build": "heft build --clean",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-links.d.ts","sourceRoot":"","sources":["../../src/scripts/create-links.ts"],"names":[],"mappings":""}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
-
// See LICENSE in the project root for license information.
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
// THIS SCRIPT IS GENERATED BY THE "rush deploy" COMMAND.
|
|
9
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
-
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
13
|
-
const terminal_1 = require("@rushstack/terminal");
|
|
14
|
-
const MAX_CONCURRENCY = node_os_1.default.cpus().length * 2;
|
|
15
|
-
const CREATE_ACTION_NAME = 'create';
|
|
16
|
-
const REMOVE_ACTION_NAME = 'remove';
|
|
17
|
-
const REALIZE_FILES_OPTION_NAME = '--realize-files';
|
|
18
|
-
const TARGET_ROOT_SCRIPT_RELATIVE_PATH = '{TARGET_ROOT_SCRIPT_RELATIVE_PATH}';
|
|
19
|
-
const TARGET_ROOT_FOLDER = node_path_1.default.resolve(__dirname, TARGET_ROOT_SCRIPT_RELATIVE_PATH);
|
|
20
|
-
async function removeLinksAsync(terminal, targetRootFolder, extractorMetadataObject) {
|
|
21
|
-
await node_core_library_1.Async.forEachAsync(extractorMetadataObject.links, async ({ linkPath }) => {
|
|
22
|
-
const newLinkPath = `${targetRootFolder}/${linkPath}`;
|
|
23
|
-
terminal.writeVerboseLine(`Removing link at path "${newLinkPath}"`);
|
|
24
|
-
await node_core_library_1.FileSystem.deleteFileAsync(newLinkPath, { throwIfNotExists: false });
|
|
25
|
-
}, { concurrency: MAX_CONCURRENCY });
|
|
26
|
-
}
|
|
27
|
-
async function createLinksAsync(terminal, targetRootFolder, extractorMetadataObject) {
|
|
28
|
-
await node_core_library_1.Async.forEachAsync(extractorMetadataObject.links, async (linkInfo) => {
|
|
29
|
-
// Link to the relative path for symlinks
|
|
30
|
-
const newLinkPath = `${targetRootFolder}/${linkInfo.linkPath}`;
|
|
31
|
-
const linkTargetPath = `${targetRootFolder}/${linkInfo.targetPath}`;
|
|
32
|
-
// Make sure the containing folder exists
|
|
33
|
-
await node_core_library_1.FileSystem.ensureFolderAsync(node_path_1.default.dirname(newLinkPath));
|
|
34
|
-
// NOTE: This logic is based on NpmLinkManager._createSymlink()
|
|
35
|
-
if (linkInfo.kind === 'folderLink') {
|
|
36
|
-
terminal.writeVerboseLine(`Creating linked folder at path "${newLinkPath}"`);
|
|
37
|
-
await node_core_library_1.FileSystem.createSymbolicLinkJunctionAsync({ newLinkPath, linkTargetPath });
|
|
38
|
-
}
|
|
39
|
-
else if (linkInfo.kind === 'fileLink') {
|
|
40
|
-
// Use hardlinks for Windows and symlinks for other platforms since creating a symbolic link
|
|
41
|
-
// requires administrator permission on Windows. This may cause unexpected behaviour for consumers
|
|
42
|
-
// of the hardlinked files. If this becomes an issue, we may need to revisit this.
|
|
43
|
-
terminal.writeVerboseLine(`Creating linked file at path "${newLinkPath}"`);
|
|
44
|
-
if (process.platform === 'win32') {
|
|
45
|
-
await node_core_library_1.FileSystem.createHardLinkAsync({ newLinkPath, linkTargetPath });
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
await node_core_library_1.FileSystem.createSymbolicLinkFileAsync({ newLinkPath, linkTargetPath });
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}, { concurrency: MAX_CONCURRENCY });
|
|
52
|
-
}
|
|
53
|
-
async function realizeFilesAsync(terminal, targetRootFolder, extractorMetadataObject) {
|
|
54
|
-
await node_core_library_1.Async.forEachAsync(extractorMetadataObject.files, async (relativeFilePath) => {
|
|
55
|
-
const filePath = `${targetRootFolder}/${relativeFilePath}`;
|
|
56
|
-
const realFilePath = await node_core_library_1.FileSystem.getRealPathAsync(filePath);
|
|
57
|
-
if (!node_core_library_1.Path.isEqual(realFilePath, filePath)) {
|
|
58
|
-
await node_core_library_1.FileSystem.deleteFileAsync(filePath);
|
|
59
|
-
// Hard links seem to cause build failures on Mac, so for all other operating
|
|
60
|
-
// systems we copy files.
|
|
61
|
-
terminal.writeVerboseLine(`Realizing file at path "${filePath}"`);
|
|
62
|
-
if (process.platform === 'win32') {
|
|
63
|
-
await node_core_library_1.FileSystem.createHardLinkAsync({ newLinkPath: filePath, linkTargetPath: realFilePath });
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
await node_core_library_1.FileSystem.copyFileAsync({ sourcePath: realFilePath, destinationPath: filePath });
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}, { concurrency: MAX_CONCURRENCY });
|
|
70
|
-
}
|
|
71
|
-
function showUsage(terminal) {
|
|
72
|
-
terminal.writeLine('Usage:');
|
|
73
|
-
terminal.writeLine(` node create-links.js ${CREATE_ACTION_NAME} [${REALIZE_FILES_OPTION_NAME}]`);
|
|
74
|
-
terminal.writeLine(` node create-links.js ${REMOVE_ACTION_NAME}`);
|
|
75
|
-
terminal.writeLine('');
|
|
76
|
-
terminal.writeLine('Creates or removes the symlinks for the output folder created by "rush deploy".');
|
|
77
|
-
terminal.writeLine('The link information is read from "extractor-metadata.json" in the same folder.');
|
|
78
|
-
}
|
|
79
|
-
async function runAsync(terminal) {
|
|
80
|
-
// Example: [ "node.exe", "create-links.js", ""create" ]
|
|
81
|
-
const args = process.argv.slice(2);
|
|
82
|
-
if ((args[0] !== CREATE_ACTION_NAME && args[0] !== REMOVE_ACTION_NAME) ||
|
|
83
|
-
(args[0] === CREATE_ACTION_NAME && args[1] && args[1] !== REALIZE_FILES_OPTION_NAME) ||
|
|
84
|
-
(args[0] === REMOVE_ACTION_NAME && args[1])) {
|
|
85
|
-
showUsage(terminal);
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
const extractorMetadataPath = `${__dirname}/extractor-metadata.json`;
|
|
89
|
-
if (!node_fs_1.default.existsSync(extractorMetadataPath)) {
|
|
90
|
-
throw new Error('Input file not found: ' + extractorMetadataPath);
|
|
91
|
-
}
|
|
92
|
-
const extractorMetadataJson = node_fs_1.default.readFileSync(extractorMetadataPath).toString();
|
|
93
|
-
const extractorMetadataObject = JSON.parse(extractorMetadataJson);
|
|
94
|
-
if (args[0] === 'create') {
|
|
95
|
-
const realizeFiles = args[1] === '--realize-files';
|
|
96
|
-
terminal.writeLine(`Creating links for extraction at path "${TARGET_ROOT_FOLDER}"`);
|
|
97
|
-
await removeLinksAsync(terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);
|
|
98
|
-
await createLinksAsync(terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);
|
|
99
|
-
if (realizeFiles) {
|
|
100
|
-
await realizeFilesAsync(terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else if (args[0] === 'remove') {
|
|
104
|
-
terminal.writeLine(`Removing links for extraction at path "${TARGET_ROOT_FOLDER}"`);
|
|
105
|
-
await removeLinksAsync(terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);
|
|
106
|
-
}
|
|
107
|
-
terminal.writeLine('The operation completed successfully.');
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
process.exitCode = 1;
|
|
111
|
-
const terminal = new terminal_1.Terminal(new terminal_1.ConsoleTerminalProvider());
|
|
112
|
-
runAsync(terminal)
|
|
113
|
-
.then((result) => {
|
|
114
|
-
process.exitCode = result ? 0 : 1;
|
|
115
|
-
})
|
|
116
|
-
.catch((error) => {
|
|
117
|
-
terminal.writeErrorLine('ERROR: ' + error);
|
|
118
|
-
});
|
|
119
|
-
//# sourceMappingURL=create-links.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-links.js","sourceRoot":"","sources":["../../src/scripts/create-links.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;AAE3D,yDAAyD;AAEzD,sDAAyB;AACzB,sDAAyB;AACzB,0DAA6B;AAC7B,oEAAuE;AACvE,kDAAwE;AAMxE,MAAM,eAAe,GAAW,iBAAE,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AACrD,MAAM,kBAAkB,GAAa,QAAQ,CAAC;AAC9C,MAAM,kBAAkB,GAAa,QAAQ,CAAC;AAC9C,MAAM,yBAAyB,GAAsB,iBAAiB,CAAC;AAEvE,MAAM,gCAAgC,GACpC,oCAAoC,CAAC;AACvC,MAAM,kBAAkB,GAAW,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,gCAAgC,CAAC,CAAC;AAE7F,KAAK,UAAU,gBAAgB,CAC7B,QAAkB,EAClB,gBAAwB,EACxB,uBAA+C;IAE/C,MAAM,yBAAK,CAAC,YAAY,CACtB,uBAAuB,CAAC,KAAK,EAC7B,KAAK,EAAE,EAAE,Q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,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n// THIS SCRIPT IS GENERATED BY THE \"rush deploy\" COMMAND.\n\nimport os from 'node:os';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { Async, FileSystem, Path } from '@rushstack/node-core-library';\nimport { Terminal, ConsoleTerminalProvider } from '@rushstack/terminal';\nimport type {\n TARGET_ROOT_SCRIPT_RELATIVE_PATH_TEMPLATE_STRING as TargetRootScriptRelativePathTemplateString,\n IExtractorMetadataJson\n} from '../PackageExtractor';\n\nconst MAX_CONCURRENCY: number = os.cpus().length * 2;\nconst CREATE_ACTION_NAME: 'create' = 'create';\nconst REMOVE_ACTION_NAME: 'remove' = 'remove';\nconst REALIZE_FILES_OPTION_NAME: '--realize-files' = '--realize-files';\n\nconst TARGET_ROOT_SCRIPT_RELATIVE_PATH: typeof TargetRootScriptRelativePathTemplateString =\n '{TARGET_ROOT_SCRIPT_RELATIVE_PATH}';\nconst TARGET_ROOT_FOLDER: string = path.resolve(__dirname, TARGET_ROOT_SCRIPT_RELATIVE_PATH);\n\nasync function removeLinksAsync(\n terminal: Terminal,\n targetRootFolder: string,\n extractorMetadataObject: IExtractorMetadataJson\n): Promise<void> {\n await Async.forEachAsync(\n extractorMetadataObject.links,\n async ({ linkPath }) => {\n const newLinkPath: string = `${targetRootFolder}/${linkPath}`;\n terminal.writeVerboseLine(`Removing link at path \"${newLinkPath}\"`);\n await FileSystem.deleteFileAsync(newLinkPath, { throwIfNotExists: false });\n },\n { concurrency: MAX_CONCURRENCY }\n );\n}\n\nasync function createLinksAsync(\n terminal: Terminal,\n targetRootFolder: string,\n extractorMetadataObject: IExtractorMetadataJson\n): Promise<void> {\n await Async.forEachAsync(\n extractorMetadataObject.links,\n async (linkInfo) => {\n // Link to the relative path for symlinks\n const newLinkPath: string = `${targetRootFolder}/${linkInfo.linkPath}`;\n const linkTargetPath: string = `${targetRootFolder}/${linkInfo.targetPath}`;\n\n // Make sure the containing folder exists\n await FileSystem.ensureFolderAsync(path.dirname(newLinkPath));\n\n // NOTE: This logic is based on NpmLinkManager._createSymlink()\n if (linkInfo.kind === 'folderLink') {\n terminal.writeVerboseLine(`Creating linked folder at path \"${newLinkPath}\"`);\n await FileSystem.createSymbolicLinkJunctionAsync({ newLinkPath, linkTargetPath });\n } else if (linkInfo.kind === 'fileLink') {\n // Use hardlinks for Windows and symlinks for other platforms since creating a symbolic link\n // requires administrator permission on Windows. This may cause unexpected behaviour for consumers\n // of the hardlinked files. If this becomes an issue, we may need to revisit this.\n terminal.writeVerboseLine(`Creating linked file at path \"${newLinkPath}\"`);\n if (process.platform === 'win32') {\n await FileSystem.createHardLinkAsync({ newLinkPath, linkTargetPath });\n } else {\n await FileSystem.createSymbolicLinkFileAsync({ newLinkPath, linkTargetPath });\n }\n }\n },\n { concurrency: MAX_CONCURRENCY }\n );\n}\n\nasync function realizeFilesAsync(\n terminal: Terminal,\n targetRootFolder: string,\n extractorMetadataObject: IExtractorMetadataJson\n): Promise<void> {\n await Async.forEachAsync(\n extractorMetadataObject.files,\n async (relativeFilePath) => {\n const filePath: string = `${targetRootFolder}/${relativeFilePath}`;\n const realFilePath: string = await FileSystem.getRealPathAsync(filePath);\n if (!Path.isEqual(realFilePath, filePath)) {\n await FileSystem.deleteFileAsync(filePath);\n\n // Hard links seem to cause build failures on Mac, so for all other operating\n // systems we copy files.\n terminal.writeVerboseLine(`Realizing file at path \"${filePath}\"`);\n if (process.platform === 'win32') {\n await FileSystem.createHardLinkAsync({ newLinkPath: filePath, linkTargetPath: realFilePath });\n } else {\n await FileSystem.copyFileAsync({ sourcePath: realFilePath, destinationPath: filePath });\n }\n }\n },\n { concurrency: MAX_CONCURRENCY }\n );\n}\n\nfunction showUsage(terminal: Terminal): void {\n terminal.writeLine('Usage:');\n terminal.writeLine(` node create-links.js ${CREATE_ACTION_NAME} [${REALIZE_FILES_OPTION_NAME}]`);\n terminal.writeLine(` node create-links.js ${REMOVE_ACTION_NAME}`);\n terminal.writeLine('');\n terminal.writeLine('Creates or removes the symlinks for the output folder created by \"rush deploy\".');\n terminal.writeLine('The link information is read from \"extractor-metadata.json\" in the same folder.');\n}\n\nasync function runAsync(terminal: Terminal): Promise<boolean> {\n // Example: [ \"node.exe\", \"create-links.js\", \"\"create\" ]\n const args: string[] = process.argv.slice(2);\n if (\n (args[0] !== CREATE_ACTION_NAME && args[0] !== REMOVE_ACTION_NAME) ||\n (args[0] === CREATE_ACTION_NAME && args[1] && args[1] !== REALIZE_FILES_OPTION_NAME) ||\n (args[0] === REMOVE_ACTION_NAME && args[1])\n ) {\n showUsage(terminal);\n return false;\n }\n\n const extractorMetadataPath: string = `${__dirname}/extractor-metadata.json`;\n if (!fs.existsSync(extractorMetadataPath)) {\n throw new Error('Input file not found: ' + extractorMetadataPath);\n }\n\n const extractorMetadataJson: string = fs.readFileSync(extractorMetadataPath).toString();\n const extractorMetadataObject: IExtractorMetadataJson = JSON.parse(extractorMetadataJson);\n\n if (args[0] === 'create') {\n const realizeFiles: boolean = args[1] === '--realize-files';\n terminal.writeLine(`Creating links for extraction at path \"${TARGET_ROOT_FOLDER}\"`);\n await removeLinksAsync(terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);\n await createLinksAsync(terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);\n if (realizeFiles) {\n await realizeFilesAsync(terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);\n }\n } else if (args[0] === 'remove') {\n terminal.writeLine(`Removing links for extraction at path \"${TARGET_ROOT_FOLDER}\"`);\n await removeLinksAsync(terminal, TARGET_ROOT_FOLDER, extractorMetadataObject);\n }\n\n terminal.writeLine('The operation completed successfully.');\n return true;\n}\n\nprocess.exitCode = 1;\nconst terminal: Terminal = new Terminal(new ConsoleTerminalProvider());\nrunAsync(terminal)\n .then((result) => {\n process.exitCode = result ? 0 : 1;\n })\n .catch((error) => {\n terminal.writeErrorLine('ERROR: ' + error);\n });\n"]}
|