@rushstack/rush-sdk 5.129.5 → 5.129.7
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/dist/rush-lib.d.ts +8 -2
- package/{lib-shim → dist}/tsdoc-metadata.json +1 -1
- package/lib/api/CommonVersionsConfiguration.d.ts +3 -2
- package/lib/api/RushConfiguration.d.ts +6 -0
- package/lib-commonjs/generate-stubs.d.ts +2 -0
- package/lib-commonjs/generate-stubs.d.ts.map +1 -0
- package/lib-commonjs/generate-stubs.js +84 -0
- package/lib-commonjs/generate-stubs.js.map +1 -0
- package/lib-commonjs/index.d.ts.map +1 -0
- package/lib-commonjs/index.js +207 -0
- package/lib-commonjs/index.js.map +1 -0
- package/lib-commonjs/loader.js +192 -0
- package/lib-commonjs/loader.js.map +1 -0
- package/lib-esnext/generate-stubs.js +57 -0
- package/lib-esnext/generate-stubs.js.map +1 -0
- package/lib-esnext/helpers.js +54 -0
- package/lib-esnext/helpers.js.map +1 -0
- package/lib-esnext/index.js +180 -0
- package/lib-esnext/index.js.map +1 -0
- package/lib-esnext/loader.js +165 -0
- package/lib-esnext/loader.js.map +1 -0
- package/lib-shim/commons.js +2192 -0
- package/lib-shim/commons.js.map +1 -0
- package/lib-shim/index.js +298 -184
- package/lib-shim/index.js.map +1 -1
- package/lib-shim/loader.js +228 -191
- package/lib-shim/loader.js.map +1 -1
- package/package.json +22 -9
- package/lib-shim/index.d.ts.map +0 -1
- /package/{lib-shim → lib-commonjs}/helpers.d.ts +0 -0
- /package/{lib-shim → lib-commonjs}/helpers.d.ts.map +0 -0
- /package/{lib-shim → lib-commonjs}/helpers.js +0 -0
- /package/{lib-shim → lib-commonjs}/helpers.js.map +0 -0
- /package/{lib-shim → lib-commonjs}/index.d.ts +0 -0
- /package/{lib-shim → lib-commonjs}/loader.d.ts +0 -0
- /package/{lib-shim → lib-commonjs}/loader.d.ts.map +0 -0
package/dist/rush-lib.d.ts
CHANGED
|
@@ -302,7 +302,7 @@ export declare class CommonVersionsConfiguration {
|
|
|
302
302
|
* If true, then consistent version specifiers for dependencies will be enforced.
|
|
303
303
|
* I.e. "rush check" is run before some commands.
|
|
304
304
|
*/
|
|
305
|
-
readonly ensureConsistentVersions: boolean
|
|
305
|
+
readonly ensureConsistentVersions: boolean;
|
|
306
306
|
/**
|
|
307
307
|
* A table that specifies a "preferred version" for a given NPM package. This feature is typically used
|
|
308
308
|
* to hold back an indirect dependency to a specific older version, or to reduce duplication of indirect dependencies.
|
|
@@ -336,7 +336,7 @@ export declare class CommonVersionsConfiguration {
|
|
|
336
336
|
* Loads the common-versions.json data from the specified file path.
|
|
337
337
|
* If the file has not been created yet, then an empty object is returned.
|
|
338
338
|
*/
|
|
339
|
-
static loadFromFile(jsonFilename: string): CommonVersionsConfiguration;
|
|
339
|
+
static loadFromFile(jsonFilename: string, rushConfiguration?: RushConfiguration): CommonVersionsConfiguration;
|
|
340
340
|
private static _deserializeTable;
|
|
341
341
|
private static _serializeTable;
|
|
342
342
|
/**
|
|
@@ -3733,6 +3733,12 @@ export declare class RushConfiguration {
|
|
|
3733
3733
|
* to disable Rush's warning.
|
|
3734
3734
|
*/
|
|
3735
3735
|
readonly suppressNodeLtsWarning: boolean;
|
|
3736
|
+
/**
|
|
3737
|
+
* The raw value of `ensureConsistentVersions` from the `rush.json` file.
|
|
3738
|
+
*
|
|
3739
|
+
* @internal
|
|
3740
|
+
*/
|
|
3741
|
+
readonly _ensureConsistentVersionsJsonValue: boolean | undefined;
|
|
3736
3742
|
/**
|
|
3737
3743
|
* If true, then consistent version specifiers for dependencies will be enforced.
|
|
3738
3744
|
* I.e. "rush check" is run before some commands.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RushConfiguration } from './RushConfiguration';
|
|
1
2
|
/**
|
|
2
3
|
* Part of the ICommonVersionsJson structure.
|
|
3
4
|
*/
|
|
@@ -45,7 +46,7 @@ export declare class CommonVersionsConfiguration {
|
|
|
45
46
|
* If true, then consistent version specifiers for dependencies will be enforced.
|
|
46
47
|
* I.e. "rush check" is run before some commands.
|
|
47
48
|
*/
|
|
48
|
-
readonly ensureConsistentVersions: boolean
|
|
49
|
+
readonly ensureConsistentVersions: boolean;
|
|
49
50
|
/**
|
|
50
51
|
* A table that specifies a "preferred version" for a given NPM package. This feature is typically used
|
|
51
52
|
* to hold back an indirect dependency to a specific older version, or to reduce duplication of indirect dependencies.
|
|
@@ -79,7 +80,7 @@ export declare class CommonVersionsConfiguration {
|
|
|
79
80
|
* Loads the common-versions.json data from the specified file path.
|
|
80
81
|
* If the file has not been created yet, then an empty object is returned.
|
|
81
82
|
*/
|
|
82
|
-
static loadFromFile(jsonFilename: string): CommonVersionsConfiguration;
|
|
83
|
+
static loadFromFile(jsonFilename: string, rushConfiguration?: RushConfiguration): CommonVersionsConfiguration;
|
|
83
84
|
private static _deserializeTable;
|
|
84
85
|
private static _serializeTable;
|
|
85
86
|
/**
|
|
@@ -356,6 +356,12 @@ export declare class RushConfiguration {
|
|
|
356
356
|
* to disable Rush's warning.
|
|
357
357
|
*/
|
|
358
358
|
readonly suppressNodeLtsWarning: boolean;
|
|
359
|
+
/**
|
|
360
|
+
* The raw value of `ensureConsistentVersions` from the `rush.json` file.
|
|
361
|
+
*
|
|
362
|
+
* @internal
|
|
363
|
+
*/
|
|
364
|
+
readonly _ensureConsistentVersionsJsonValue: boolean | undefined;
|
|
359
365
|
/**
|
|
360
366
|
* If true, then consistent version specifiers for dependencies will be enforced.
|
|
361
367
|
* I.e. "rush check" is run before some commands.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-stubs.d.ts","sourceRoot":"","sources":["../src/generate-stubs.ts"],"names":[],"mappings":"AAkDA,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAiB9C"}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.runAsync = void 0;
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
31
|
+
function generateLibFilesRecursively(options) {
|
|
32
|
+
for (const folderItem of node_core_library_1.FileSystem.readFolderItems(options.parentSourcePath)) {
|
|
33
|
+
const sourcePath = path.join(options.parentSourcePath, folderItem.name);
|
|
34
|
+
const targetPath = path.join(options.parentTargetPath, folderItem.name);
|
|
35
|
+
if (folderItem.isDirectory()) {
|
|
36
|
+
// create destination folder
|
|
37
|
+
node_core_library_1.FileSystem.ensureEmptyFolder(targetPath);
|
|
38
|
+
generateLibFilesRecursively({
|
|
39
|
+
parentSourcePath: sourcePath,
|
|
40
|
+
parentTargetPath: targetPath,
|
|
41
|
+
parentSrcImportPathWithSlash: options.parentSrcImportPathWithSlash + folderItem.name + '/',
|
|
42
|
+
libShimIndexPath: options.libShimIndexPath
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (folderItem.name.endsWith('.d.ts')) {
|
|
47
|
+
node_core_library_1.FileSystem.copyFile({
|
|
48
|
+
sourcePath: sourcePath,
|
|
49
|
+
destinationPath: targetPath
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else if (folderItem.name.endsWith('.js')) {
|
|
53
|
+
const srcImportPath = options.parentSrcImportPathWithSlash + path.parse(folderItem.name).name;
|
|
54
|
+
const shimPath = path.relative(options.parentTargetPath, options.libShimIndexPath);
|
|
55
|
+
const shimPathLiteral = JSON.stringify(node_core_library_1.Path.convertToSlashes(shimPath));
|
|
56
|
+
const srcImportPathLiteral = JSON.stringify(srcImportPath);
|
|
57
|
+
node_core_library_1.FileSystem.writeFile(targetPath,
|
|
58
|
+
// Example:
|
|
59
|
+
// module.exports = require("../../../lib-shim/index")._rushSdk_loadInternalModule("logic/policy/GitEmailPolicy");
|
|
60
|
+
`module.exports = require(${shimPathLiteral})._rushSdk_loadInternalModule(${srcImportPathLiteral});`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Entry point invoked by "runScript" action from config/heft.json
|
|
66
|
+
async function runAsync() {
|
|
67
|
+
const rushLibFolder = node_core_library_1.Import.resolvePackage({
|
|
68
|
+
baseFolderPath: __dirname,
|
|
69
|
+
packageName: '@microsoft/rush-lib'
|
|
70
|
+
});
|
|
71
|
+
const stubsTargetPath = path.resolve(__dirname, '../lib');
|
|
72
|
+
// eslint-disable-next-line no-console
|
|
73
|
+
console.log('generate-stubs: Generating stub files under: ' + stubsTargetPath);
|
|
74
|
+
generateLibFilesRecursively({
|
|
75
|
+
parentSourcePath: path.join(rushLibFolder, 'lib'),
|
|
76
|
+
parentTargetPath: stubsTargetPath,
|
|
77
|
+
parentSrcImportPathWithSlash: '',
|
|
78
|
+
libShimIndexPath: path.join(__dirname, '../lib-shim/index')
|
|
79
|
+
});
|
|
80
|
+
// eslint-disable-next-line no-console
|
|
81
|
+
console.log('generate-stubs: Completed successfully.');
|
|
82
|
+
}
|
|
83
|
+
exports.runAsync = runAsync;
|
|
84
|
+
//# sourceMappingURL=generate-stubs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-stubs.js","sourceRoot":"","sources":["../src/generate-stubs.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAE7B,oEAAwE;AAExE,SAAS,2BAA2B,CAAC,OAKpC;IACC,KAAK,MAAM,UAAU,IAAI,8BAAU,CAAC,eAAe,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC9E,MAAM,UAAU,GAAW,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QAChF,MAAM,UAAU,GAAW,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QAEhF,IAAI,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC;YAC7B,4BAA4B;YAC5B,8BAAU,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;YACzC,2BAA2B,CAAC;gBAC1B,gBAAgB,EAAE,UAAU;gBAC5B,gBAAgB,EAAE,UAAU;gBAC5B,4BAA4B,EAAE,OAAO,CAAC,4BAA4B,GAAG,UAAU,CAAC,IAAI,GAAG,GAAG;gBAC1F,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;aAC3C,CAAC,CAAC;QACL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C,aAAa,EAAE,KAAK,CAAC;QACjD,gBAAgB,EAAE,eAAe;QACjC,4BAA4B,EAAE,EAAE;QAChC,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC;KAC5D,CAAC,CAAC;IACH,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;AACzD,CAAC;AAjBD,4BAiBC","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 * as path from 'path';\n\nimport { FileSystem, Import, Path } from '@rushstack/node-core-library';\n\nfunction generateLibFilesRecursively(options: {\n parentSourcePath: string;\n parentTargetPath: string;\n parentSrcImportPathWithSlash: string;\n libShimIndexPath: string;\n}): void {\n for (const folderItem of FileSystem.readFolderItems(options.parentSourcePath)) {\n const sourcePath: string = path.join(options.parentSourcePath, folderItem.name);\n const targetPath: string = path.join(options.parentTargetPath, folderItem.name);\n\n if (folderItem.isDirectory()) {\n // create destination folder\n FileSystem.ensureEmptyFolder(targetPath);\n generateLibFilesRecursively({\n parentSourcePath: sourcePath,\n parentTargetPath: targetPath,\n parentSrcImportPathWithSlash: options.parentSrcImportPathWithSlash + folderItem.name + '/',\n libShimIndexPath: options.libShimIndexPath\n });\n } else {\n if (folderItem.name.endsWith('.d.ts')) {\n FileSystem.copyFile({\n sourcePath: sourcePath,\n destinationPath: targetPath\n });\n } else if (folderItem.name.endsWith('.js')) {\n const srcImportPath: string = options.parentSrcImportPathWithSlash + path.parse(folderItem.name).name;\n const shimPath: string = path.relative(options.parentTargetPath, options.libShimIndexPath);\n const shimPathLiteral: string = JSON.stringify(Path.convertToSlashes(shimPath));\n const srcImportPathLiteral: string = JSON.stringify(srcImportPath);\n\n FileSystem.writeFile(\n targetPath,\n // Example:\n // module.exports = require(\"../../../lib-shim/index\")._rushSdk_loadInternalModule(\"logic/policy/GitEmailPolicy\");\n `module.exports = require(${shimPathLiteral})._rushSdk_loadInternalModule(${srcImportPathLiteral});`\n );\n }\n }\n }\n}\n\n// Entry point invoked by \"runScript\" action from config/heft.json\nexport async function runAsync(): Promise<void> {\n const rushLibFolder: string = Import.resolvePackage({\n baseFolderPath: __dirname,\n packageName: '@microsoft/rush-lib'\n });\n\n const stubsTargetPath: string = path.resolve(__dirname, '../lib');\n // eslint-disable-next-line no-console\n console.log('generate-stubs: Generating stub files under: ' + stubsTargetPath);\n generateLibFilesRecursively({\n parentSourcePath: path.join(rushLibFolder, 'lib'),\n parentTargetPath: stubsTargetPath,\n parentSrcImportPathWithSlash: '',\n libShimIndexPath: path.join(__dirname, '../lib-shim/index')\n });\n // eslint-disable-next-line no-console\n console.log('generate-stubs: Completed successfully.');\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoOA;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAO1E"}
|
|
@@ -0,0 +1,207 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var _a;
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports._rushSdk_loadInternalModule = void 0;
|
|
30
|
+
const path = __importStar(require("path"));
|
|
31
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
32
|
+
const terminal_1 = require("@rushstack/terminal");
|
|
33
|
+
const RushGlobalFolder_1 = require("@microsoft/rush-lib/lib-esnext/api/RushGlobalFolder");
|
|
34
|
+
const helpers_1 = require("./helpers");
|
|
35
|
+
const verboseEnabled = typeof process !== 'undefined' &&
|
|
36
|
+
(process.env.RUSH_SDK_DEBUG === '1' || process.env._RUSH_SDK_DEBUG === '1');
|
|
37
|
+
const terminal = new terminal_1.Terminal(new terminal_1.ConsoleTerminalProvider({
|
|
38
|
+
verboseEnabled
|
|
39
|
+
}));
|
|
40
|
+
let errorMessage = '';
|
|
41
|
+
// SCENARIO 1: Rush's PluginManager has initialized "rush-sdk" with Rush's own instance of rush-lib.
|
|
42
|
+
// The Rush host process will assign "global.___rush___rushLibModule" before loading the plugin.
|
|
43
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
44
|
+
helpers_1.sdkContext.rushLibModule =
|
|
45
|
+
global.___rush___rushLibModule ||
|
|
46
|
+
global.___rush___rushLibModuleFromEnvironment ||
|
|
47
|
+
global.___rush___rushLibModuleFromRushGlobalFolder ||
|
|
48
|
+
global.___rush___rushLibModuleFromInstallAndRunRush;
|
|
49
|
+
}
|
|
50
|
+
// SCENARIO 2: The project importing "rush-sdk" has installed its own instance of "rush-lib"
|
|
51
|
+
// as a package.json dependency. For example, this is used by the Jest tests for Rush plugins.
|
|
52
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
53
|
+
const importingPath = (_a = module === null || module === void 0 ? void 0 : module.parent) === null || _a === void 0 ? void 0 : _a.filename;
|
|
54
|
+
if (importingPath) {
|
|
55
|
+
const callerPackageFolder = node_core_library_1.PackageJsonLookup.instance.tryGetPackageFolderFor(importingPath);
|
|
56
|
+
if (callerPackageFolder !== undefined) {
|
|
57
|
+
const callerPackageJson = (0, helpers_1._require)(path.join(callerPackageFolder, 'package.json'));
|
|
58
|
+
// Does the caller properly declare a dependency on rush-lib?
|
|
59
|
+
if ((callerPackageJson.dependencies && callerPackageJson.dependencies[helpers_1.RUSH_LIB_NAME] !== undefined) ||
|
|
60
|
+
(callerPackageJson.devDependencies &&
|
|
61
|
+
callerPackageJson.devDependencies[helpers_1.RUSH_LIB_NAME] !== undefined) ||
|
|
62
|
+
(callerPackageJson.peerDependencies &&
|
|
63
|
+
callerPackageJson.peerDependencies[helpers_1.RUSH_LIB_NAME] !== undefined)) {
|
|
64
|
+
// Try to resolve rush-lib from the caller's folder
|
|
65
|
+
terminal.writeVerboseLine(`Try to load ${helpers_1.RUSH_LIB_NAME} from caller package`);
|
|
66
|
+
try {
|
|
67
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(callerPackageFolder);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// If we fail to resolve it, ignore the error
|
|
71
|
+
terminal.writeVerboseLine(`Failed to load ${helpers_1.RUSH_LIB_NAME} from caller package`);
|
|
72
|
+
}
|
|
73
|
+
// If two different libraries invoke `rush-sdk`, and one of them provides "rush-lib"
|
|
74
|
+
// then the first version to be loaded wins. We do not support side-by-side instances of "rush-lib".
|
|
75
|
+
if (helpers_1.sdkContext.rushLibModule !== undefined) {
|
|
76
|
+
// to track which scenario is active and how it got initialized.
|
|
77
|
+
global.___rush___rushLibModule = helpers_1.sdkContext.rushLibModule;
|
|
78
|
+
terminal.writeVerboseLine(`Loaded ${helpers_1.RUSH_LIB_NAME} from caller`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// SCENARIO 3: A tool or script has been invoked as a child process by an instance of "rush-lib" and can use the
|
|
85
|
+
// version that invoked it. In this case, use process.env._RUSH_LIB_PATH to find "rush-lib".
|
|
86
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
87
|
+
const rushLibPath = process.env[helpers_1.RUSH_LIB_PATH_ENV_VAR_NAME];
|
|
88
|
+
if (rushLibPath) {
|
|
89
|
+
terminal.writeVerboseLine(`Try to load ${helpers_1.RUSH_LIB_NAME} from process.env.${helpers_1.RUSH_LIB_PATH_ENV_VAR_NAME} from caller package`);
|
|
90
|
+
try {
|
|
91
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1._require)(rushLibPath);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
// Log this as a warning, since it is unexpected to define an incorrect value of the variable.
|
|
95
|
+
terminal.writeWarningLine(`Failed to load ${helpers_1.RUSH_LIB_NAME} via process.env.${helpers_1.RUSH_LIB_PATH_ENV_VAR_NAME}`);
|
|
96
|
+
}
|
|
97
|
+
if (helpers_1.sdkContext.rushLibModule !== undefined) {
|
|
98
|
+
// to track which scenario is active and how it got initialized.
|
|
99
|
+
global.___rush___rushLibModuleFromEnvironment = helpers_1.sdkContext.rushLibModule;
|
|
100
|
+
terminal.writeVerboseLine(`Loaded ${helpers_1.RUSH_LIB_NAME} from process.env.${helpers_1.RUSH_LIB_PATH_ENV_VAR_NAME}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// SCENARIO 4: A standalone tool or script depends on "rush-sdk", and is meant to be used inside a monorepo folder.
|
|
105
|
+
// In this case, we can first load the rush-lib version in rush global folder. If the expected version is not installed,
|
|
106
|
+
// using install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.
|
|
107
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
108
|
+
try {
|
|
109
|
+
const rushJsonPath = (0, helpers_1.tryFindRushJsonLocation)(process.cwd());
|
|
110
|
+
if (!rushJsonPath) {
|
|
111
|
+
throw new Error('Unable to find rush.json in the current folder or its parent folders.\n' +
|
|
112
|
+
'This tool is meant to be invoked from a working directory inside a Rush repository.');
|
|
113
|
+
}
|
|
114
|
+
const monorepoRoot = path.dirname(rushJsonPath);
|
|
115
|
+
const rushJson = node_core_library_1.JsonFile.load(rushJsonPath);
|
|
116
|
+
const { rushVersion } = rushJson;
|
|
117
|
+
try {
|
|
118
|
+
terminal.writeVerboseLine(`Try to load ${helpers_1.RUSH_LIB_NAME} from rush global folder`);
|
|
119
|
+
const rushGlobalFolder = new RushGlobalFolder_1.RushGlobalFolder();
|
|
120
|
+
// The path needs to keep align with the logic inside RushVersionSelector
|
|
121
|
+
const expectedGlobalRushInstalledFolder = `${rushGlobalFolder.nodeSpecificPath}/rush-${rushVersion}`;
|
|
122
|
+
terminal.writeVerboseLine(`The expected global rush installed folder is "${expectedGlobalRushInstalledFolder}"`);
|
|
123
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(expectedGlobalRushInstalledFolder);
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
terminal.writeVerboseLine(`Failed to load ${helpers_1.RUSH_LIB_NAME} from rush global folder: ${e.message}`);
|
|
127
|
+
}
|
|
128
|
+
if (helpers_1.sdkContext.rushLibModule !== undefined) {
|
|
129
|
+
// to track which scenario is active and how it got initialized.
|
|
130
|
+
global.___rush___rushLibModuleFromRushGlobalFolder = helpers_1.sdkContext.rushLibModule;
|
|
131
|
+
terminal.writeVerboseLine(`Loaded ${helpers_1.RUSH_LIB_NAME} installed from rush global folder`);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
const installRunNodeModuleFolder = `${monorepoRoot}/common/temp/install-run/@microsoft+rush@${rushVersion}`;
|
|
135
|
+
try {
|
|
136
|
+
// First, try to load the version of "rush-lib" that was installed by install-run-rush.js
|
|
137
|
+
terminal.writeVerboseLine(`Trying to load ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush`);
|
|
138
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(installRunNodeModuleFolder);
|
|
139
|
+
}
|
|
140
|
+
catch (e1) {
|
|
141
|
+
let installAndRunRushStderrContent = '';
|
|
142
|
+
try {
|
|
143
|
+
const installAndRunRushJSPath = `${monorepoRoot}/common/scripts/install-run-rush.js`;
|
|
144
|
+
terminal.writeLine('The Rush engine has not been installed yet. Invoking install-run-rush.js...');
|
|
145
|
+
const installAndRunRushProcess = node_core_library_1.Executable.spawnSync('node', [installAndRunRushJSPath, '--help'], {
|
|
146
|
+
stdio: 'pipe'
|
|
147
|
+
});
|
|
148
|
+
installAndRunRushStderrContent = installAndRunRushProcess.stderr;
|
|
149
|
+
if (installAndRunRushProcess.status !== 0) {
|
|
150
|
+
throw new Error(`The ${helpers_1.RUSH_LIB_NAME} package failed to install`);
|
|
151
|
+
}
|
|
152
|
+
// Retry to load "rush-lib" after install-run-rush run
|
|
153
|
+
terminal.writeVerboseLine(`Trying to load ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush a second time`);
|
|
154
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(installRunNodeModuleFolder);
|
|
155
|
+
}
|
|
156
|
+
catch (e2) {
|
|
157
|
+
// eslint-disable-next-line no-console
|
|
158
|
+
console.error(`${installAndRunRushStderrContent}`);
|
|
159
|
+
throw new Error(`The ${helpers_1.RUSH_LIB_NAME} package failed to load`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (helpers_1.sdkContext.rushLibModule !== undefined) {
|
|
163
|
+
// to track which scenario is active and how it got initialized.
|
|
164
|
+
global.___rush___rushLibModuleFromInstallAndRunRush = helpers_1.sdkContext.rushLibModule;
|
|
165
|
+
terminal.writeVerboseLine(`Loaded ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
// no-catch
|
|
171
|
+
errorMessage = e.message;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
175
|
+
// This error indicates that a project is trying to import "@rushstack/rush-sdk", but the Rush engine
|
|
176
|
+
// instance cannot be found. If you are writing Jest tests for a Rush plugin, add "@microsoft/rush-lib"
|
|
177
|
+
// to the devDependencies for your project.
|
|
178
|
+
// eslint-disable-next-line no-console
|
|
179
|
+
console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:
|
|
180
|
+
${errorMessage}
|
|
181
|
+
`);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
// Based on TypeScript's __exportStar()
|
|
185
|
+
for (const property in helpers_1.sdkContext.rushLibModule) {
|
|
186
|
+
if (property !== 'default' && !exports.hasOwnProperty(property)) {
|
|
187
|
+
const rushLibModuleForClosure = helpers_1.sdkContext.rushLibModule;
|
|
188
|
+
// Based on TypeScript's __createBinding()
|
|
189
|
+
Object.defineProperty(exports, property, {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
get: function () {
|
|
192
|
+
return rushLibModuleForClosure[property];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Used by the .js stubs for path-based imports of `@microsoft/rush-lib` internal APIs.
|
|
199
|
+
*/
|
|
200
|
+
function _rushSdk_loadInternalModule(srcImportPath) {
|
|
201
|
+
if (!exports._RushInternals) {
|
|
202
|
+
throw new Error(`Rush version ${exports.Rush.version} does not support internal API imports via rush-sdk`);
|
|
203
|
+
}
|
|
204
|
+
return exports._RushInternals.loadModule(srcImportPath);
|
|
205
|
+
}
|
|
206
|
+
exports._rushSdk_loadInternalModule = _rushSdk_loadInternalModule;
|
|
207
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,oEAMsC;AACtC,kDAAwE;AACxE,0FAAuF;AAEvF,uCAQmB;AAEnB,MAAM,cAAc,GAClB,OAAO,OAAO,KAAK,WAAW;IAC9B,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,GAAG,CAAC,CAAC;AAC9E,MAAM,QAAQ,GAAa,IAAI,mBAAQ,CACrC,IAAI,kCAAuB,CAAC;IAC1B,cAAc;CACf,CAAC,CACH,CAAC;AASF,IAAI,YAAY,GAAW,EAAE,CAAC;AAE9B,qGAAqG;AACrG,gGAAgG;AAChG,IAAI,oBAAU,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;IAC3C,oBAAU,CAAC,aAAa;QACtB,MAAM,CAAC,uBAAuB;YAC9B,MAAM,CAAC,sCAAsC;YAC7C,MAAM,CAAC,2CAA2C;YAClD,MAAM,CAAC,4CAA4C,CAAC;AACxD,CAAC;AAED,6FAA6F;AAC7F,+FAA+F;AAC/F,IAAI,oBAAU,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;IAC3C,MAAM,aAAa,GAA8B,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,0CAAE,QAAQ,CAAC;IAC1E,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,mBAAmB,GACvB,qCAAiB,CAAC,QAAQ,CAAC,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QAAQ,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChE,MAAM,uBAAuB,GAAsB,oBAAU,CAAC,aAAa,CAAC;QAE5E,0CAA0C;QAC1C,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE;YACvC,UAAU,EAAE,IAAI;YAChB,GAAG,EAAE;gBACH,OAAO,uBAAuB,CAAC,QAAQ,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,2BAA2B,CAAC,aAAqB;IAC/D,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,gBAAgB,OAAO,CAAC,IAAI,CAAC,OAAO,qDAAqD,CAC1F,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAC1D,CAAC;AAPD,kEAOC","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 * as path from 'path';\nimport {\n JsonFile,\n type JsonObject,\n type IPackageJson,\n PackageJsonLookup,\n Executable\n} from '@rushstack/node-core-library';\nimport { Terminal, ConsoleTerminalProvider } from '@rushstack/terminal';\nimport { RushGlobalFolder } from '@microsoft/rush-lib/lib-esnext/api/RushGlobalFolder';\nimport type { SpawnSyncReturns } from 'child_process';\nimport {\n RUSH_LIB_NAME,\n RUSH_LIB_PATH_ENV_VAR_NAME,\n type RushLibModuleType,\n _require,\n requireRushLibUnderFolderPath,\n tryFindRushJsonLocation,\n sdkContext\n} from './helpers';\n\nconst verboseEnabled: boolean =\n typeof process !== 'undefined' &&\n (process.env.RUSH_SDK_DEBUG === '1' || process.env._RUSH_SDK_DEBUG === '1');\nconst terminal: Terminal = new Terminal(\n new ConsoleTerminalProvider({\n verboseEnabled\n })\n);\n\ndeclare const global: typeof globalThis & {\n ___rush___rushLibModule?: RushLibModuleType;\n ___rush___rushLibModuleFromEnvironment?: RushLibModuleType;\n ___rush___rushLibModuleFromRushGlobalFolder?: RushLibModuleType;\n ___rush___rushLibModuleFromInstallAndRunRush?: RushLibModuleType;\n};\n\nlet errorMessage: string = '';\n\n// SCENARIO 1: Rush's PluginManager has initialized \"rush-sdk\" with Rush's own instance of rush-lib.\n// The Rush host process will assign \"global.___rush___rushLibModule\" before loading the plugin.\nif (sdkContext.rushLibModule === undefined) {\n sdkContext.rushLibModule =\n global.___rush___rushLibModule ||\n global.___rush___rushLibModuleFromEnvironment ||\n global.___rush___rushLibModuleFromRushGlobalFolder ||\n global.___rush___rushLibModuleFromInstallAndRunRush;\n}\n\n// SCENARIO 2: The project importing \"rush-sdk\" has installed its own instance of \"rush-lib\"\n// as a package.json dependency. For example, this is used by the Jest tests for Rush plugins.\nif (sdkContext.rushLibModule === undefined) {\n const importingPath: string | null | undefined = module?.parent?.filename;\n if (importingPath) {\n const callerPackageFolder: string | undefined =\n PackageJsonLookup.instance.tryGetPackageFolderFor(importingPath);\n\n if (callerPackageFolder !== undefined) {\n const callerPackageJson: IPackageJson = _require(path.join(callerPackageFolder, 'package.json'));\n\n // Does the caller properly declare a dependency on rush-lib?\n if (\n (callerPackageJson.dependencies && callerPackageJson.dependencies[RUSH_LIB_NAME] !== undefined) ||\n (callerPackageJson.devDependencies &&\n callerPackageJson.devDependencies[RUSH_LIB_NAME] !== undefined) ||\n (callerPackageJson.peerDependencies &&\n callerPackageJson.peerDependencies[RUSH_LIB_NAME] !== undefined)\n ) {\n // Try to resolve rush-lib from the caller's folder\n terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from caller package`);\n try {\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(callerPackageFolder);\n } catch (error) {\n // If we fail to resolve it, ignore the error\n terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from caller package`);\n }\n\n // If two different libraries invoke `rush-sdk`, and one of them provides \"rush-lib\"\n // then the first version to be loaded wins. We do not support side-by-side instances of \"rush-lib\".\n if (sdkContext.rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModule = sdkContext.rushLibModule;\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from caller`);\n }\n }\n }\n }\n}\n\n// SCENARIO 3: A tool or script has been invoked as a child process by an instance of \"rush-lib\" and can use the\n// version that invoked it. In this case, use process.env._RUSH_LIB_PATH to find \"rush-lib\".\nif (sdkContext.rushLibModule === undefined) {\n const rushLibPath: string | undefined = process.env[RUSH_LIB_PATH_ENV_VAR_NAME];\n if (rushLibPath) {\n terminal.writeVerboseLine(\n `Try to load ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME} from caller package`\n );\n try {\n sdkContext.rushLibModule = _require(rushLibPath);\n } catch (error) {\n // Log this as a warning, since it is unexpected to define an incorrect value of the variable.\n terminal.writeWarningLine(\n `Failed to load ${RUSH_LIB_NAME} via process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`\n );\n }\n\n if (sdkContext.rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModuleFromEnvironment = sdkContext.rushLibModule;\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`);\n }\n }\n}\n\n// SCENARIO 4: A standalone tool or script depends on \"rush-sdk\", and is meant to be used inside a monorepo folder.\n// In this case, we can first load the rush-lib version in rush global folder. If the expected version is not installed,\n// using install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.\nif (sdkContext.rushLibModule === undefined) {\n try {\n const rushJsonPath: string | undefined = tryFindRushJsonLocation(process.cwd());\n if (!rushJsonPath) {\n throw new Error(\n 'Unable to find rush.json in the current folder or its parent folders.\\n' +\n 'This tool is meant to be invoked from a working directory inside a Rush repository.'\n );\n }\n const monorepoRoot: string = path.dirname(rushJsonPath);\n\n const rushJson: JsonObject = JsonFile.load(rushJsonPath);\n const { rushVersion } = rushJson;\n\n try {\n terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from rush global folder`);\n const rushGlobalFolder: RushGlobalFolder = new RushGlobalFolder();\n // The path needs to keep align with the logic inside RushVersionSelector\n const expectedGlobalRushInstalledFolder: string = `${rushGlobalFolder.nodeSpecificPath}/rush-${rushVersion}`;\n terminal.writeVerboseLine(\n `The expected global rush installed folder is \"${expectedGlobalRushInstalledFolder}\"`\n );\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(expectedGlobalRushInstalledFolder);\n } catch (e) {\n terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from rush global folder: ${e.message}`);\n }\n\n if (sdkContext.rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModuleFromRushGlobalFolder = sdkContext.rushLibModule;\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed from rush global folder`);\n } else {\n const installRunNodeModuleFolder: string = `${monorepoRoot}/common/temp/install-run/@microsoft+rush@${rushVersion}`;\n\n try {\n // First, try to load the version of \"rush-lib\" that was installed by install-run-rush.js\n terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`);\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\n } catch (e1) {\n let installAndRunRushStderrContent: string = '';\n try {\n const installAndRunRushJSPath: string = `${monorepoRoot}/common/scripts/install-run-rush.js`;\n\n terminal.writeLine('The Rush engine has not been installed yet. Invoking install-run-rush.js...');\n\n const installAndRunRushProcess: SpawnSyncReturns<string> = Executable.spawnSync(\n 'node',\n [installAndRunRushJSPath, '--help'],\n {\n stdio: 'pipe'\n }\n );\n\n installAndRunRushStderrContent = installAndRunRushProcess.stderr;\n if (installAndRunRushProcess.status !== 0) {\n throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);\n }\n\n // Retry to load \"rush-lib\" after install-run-rush run\n terminal.writeVerboseLine(\n `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`\n );\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\n } catch (e2) {\n // eslint-disable-next-line no-console\n console.error(`${installAndRunRushStderrContent}`);\n throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);\n }\n }\n\n if (sdkContext.rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModuleFromInstallAndRunRush = sdkContext.rushLibModule;\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed by install-run-rush`);\n }\n }\n } catch (e) {\n // no-catch\n errorMessage = (e as Error).message;\n }\n}\n\nif (sdkContext.rushLibModule === undefined) {\n // This error indicates that a project is trying to import \"@rushstack/rush-sdk\", but the Rush engine\n // instance cannot be found. If you are writing Jest tests for a Rush plugin, add \"@microsoft/rush-lib\"\n // to the devDependencies for your project.\n // eslint-disable-next-line no-console\n console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:\n${errorMessage}\n`);\n process.exit(1);\n}\n\n// Based on TypeScript's __exportStar()\nfor (const property in sdkContext.rushLibModule) {\n if (property !== 'default' && !exports.hasOwnProperty(property)) {\n const rushLibModuleForClosure: RushLibModuleType = sdkContext.rushLibModule;\n\n // Based on TypeScript's __createBinding()\n Object.defineProperty(exports, property, {\n enumerable: true,\n get: function () {\n return rushLibModuleForClosure[property];\n }\n });\n }\n}\n\n/**\n * Used by the .js stubs for path-based imports of `@microsoft/rush-lib` internal APIs.\n */\nexport function _rushSdk_loadInternalModule(srcImportPath: string): unknown {\n if (!exports._RushInternals) {\n throw new Error(\n `Rush version ${exports.Rush.version} does not support internal API imports via rush-sdk`\n );\n }\n return exports._RushInternals.loadModule(srcImportPath);\n}\n"]}
|
|
@@ -0,0 +1,192 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.RushSdkLoader = void 0;
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
31
|
+
const helpers_1 = require("./helpers");
|
|
32
|
+
/**
|
|
33
|
+
* Exposes operations that control how the `@microsoft/rush-lib` engine is
|
|
34
|
+
* located and loaded.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
class RushSdkLoader {
|
|
38
|
+
/**
|
|
39
|
+
* Throws an "AbortError" exception if abortSignal.aborted is true.
|
|
40
|
+
*/
|
|
41
|
+
static _checkForCancel(abortSignal, onNotifyEvent, progressPercent) {
|
|
42
|
+
if (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (onNotifyEvent) {
|
|
46
|
+
onNotifyEvent({
|
|
47
|
+
logMessage: {
|
|
48
|
+
kind: 'info',
|
|
49
|
+
text: `The operation was canceled`
|
|
50
|
+
},
|
|
51
|
+
progressPercent
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const error = new Error('The operation was canceled');
|
|
55
|
+
error.name = 'AbortError';
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns true if the Rush engine has already been loaded.
|
|
60
|
+
*/
|
|
61
|
+
static get isLoaded() {
|
|
62
|
+
return helpers_1.sdkContext.rushLibModule !== undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Manually load the Rush engine based on rush.json found for `rushJsonSearchFolder`.
|
|
66
|
+
* Throws an exception if {@link RushSdkLoader.isLoaded} is already `true`.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* This API supports an callback that can be used display a progress bar,
|
|
70
|
+
* log of operations, and allow the operation to be canceled prematurely.
|
|
71
|
+
*/
|
|
72
|
+
static async loadAsync(options) {
|
|
73
|
+
// SCENARIO 5: The rush-lib engine is loaded manually using rushSdkLoader.loadAsync().
|
|
74
|
+
var _a, _b;
|
|
75
|
+
if (!options) {
|
|
76
|
+
options = {};
|
|
77
|
+
}
|
|
78
|
+
if (RushSdkLoader.isLoaded) {
|
|
79
|
+
throw new Error('RushSdkLoader.loadAsync() failed because the Rush engine has already been loaded');
|
|
80
|
+
}
|
|
81
|
+
const onNotifyEvent = options.onNotifyEvent;
|
|
82
|
+
let progressPercent = undefined;
|
|
83
|
+
const abortSignal = options.abortSignal;
|
|
84
|
+
try {
|
|
85
|
+
const rushJsonSearchFolder = (_a = options.rushJsonSearchFolder) !== null && _a !== void 0 ? _a : process.cwd();
|
|
86
|
+
if (onNotifyEvent) {
|
|
87
|
+
onNotifyEvent({
|
|
88
|
+
logMessage: {
|
|
89
|
+
kind: 'debug',
|
|
90
|
+
text: `Searching for rush.json starting from: ` + rushJsonSearchFolder
|
|
91
|
+
},
|
|
92
|
+
progressPercent
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const rushJsonPath = (0, helpers_1.tryFindRushJsonLocation)(rushJsonSearchFolder);
|
|
96
|
+
if (!rushJsonPath) {
|
|
97
|
+
throw new Error('Unable to find rush.json in the specified folder or its parent folders:\n' +
|
|
98
|
+
`${rushJsonSearchFolder}\n`);
|
|
99
|
+
}
|
|
100
|
+
const monorepoRoot = path.dirname(rushJsonPath);
|
|
101
|
+
const rushJson = await node_core_library_1.JsonFile.loadAsync(rushJsonPath);
|
|
102
|
+
const { rushVersion } = rushJson;
|
|
103
|
+
const installRunNodeModuleFolder = path.join(monorepoRoot, `common/temp/install-run/@microsoft+rush@${rushVersion}`);
|
|
104
|
+
try {
|
|
105
|
+
// First, try to load the version of "rush-lib" that was installed by install-run-rush.js
|
|
106
|
+
if (onNotifyEvent) {
|
|
107
|
+
onNotifyEvent({
|
|
108
|
+
logMessage: {
|
|
109
|
+
kind: 'info',
|
|
110
|
+
text: `Trying to load ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush`
|
|
111
|
+
},
|
|
112
|
+
progressPercent
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(installRunNodeModuleFolder);
|
|
116
|
+
}
|
|
117
|
+
catch (e1) {
|
|
118
|
+
let installAndRunRushStderrContent = '';
|
|
119
|
+
try {
|
|
120
|
+
const installAndRunRushJSPath = path.join(monorepoRoot, 'common/scripts/install-run-rush.js');
|
|
121
|
+
if (onNotifyEvent) {
|
|
122
|
+
onNotifyEvent({
|
|
123
|
+
logMessage: {
|
|
124
|
+
kind: 'info',
|
|
125
|
+
text: 'The Rush engine has not been installed yet. Invoking install-run-rush.js...'
|
|
126
|
+
},
|
|
127
|
+
progressPercent
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// Start the installation
|
|
131
|
+
progressPercent = 0;
|
|
132
|
+
const installAndRunRushProcess = node_core_library_1.Executable.spawnSync('node', [installAndRunRushJSPath, '--help'], {
|
|
133
|
+
stdio: 'pipe'
|
|
134
|
+
});
|
|
135
|
+
installAndRunRushStderrContent = installAndRunRushProcess.stderr;
|
|
136
|
+
if (installAndRunRushProcess.status !== 0) {
|
|
137
|
+
throw new Error(`The ${helpers_1.RUSH_LIB_NAME} package failed to install`);
|
|
138
|
+
}
|
|
139
|
+
if (abortSignal) {
|
|
140
|
+
RushSdkLoader._checkForCancel(abortSignal, onNotifyEvent, progressPercent);
|
|
141
|
+
}
|
|
142
|
+
// TODO: Implement incremental progress updates
|
|
143
|
+
progressPercent = 90;
|
|
144
|
+
// Retry to load "rush-lib" after install-run-rush run
|
|
145
|
+
if (onNotifyEvent) {
|
|
146
|
+
onNotifyEvent({
|
|
147
|
+
logMessage: {
|
|
148
|
+
kind: 'debug',
|
|
149
|
+
text: `Trying to load ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush a second time`
|
|
150
|
+
},
|
|
151
|
+
progressPercent
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(installRunNodeModuleFolder);
|
|
155
|
+
progressPercent = 100;
|
|
156
|
+
}
|
|
157
|
+
catch (e2) {
|
|
158
|
+
// eslint-disable-next-line no-console
|
|
159
|
+
console.error(`${installAndRunRushStderrContent}`);
|
|
160
|
+
throw new Error(`The ${helpers_1.RUSH_LIB_NAME} package failed to load`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (helpers_1.sdkContext.rushLibModule !== undefined) {
|
|
164
|
+
// to track which scenario is active and how it got initialized.
|
|
165
|
+
global.___rush___rushLibModuleFromInstallAndRunRush = helpers_1.sdkContext.rushLibModule;
|
|
166
|
+
if (onNotifyEvent) {
|
|
167
|
+
onNotifyEvent({
|
|
168
|
+
logMessage: {
|
|
169
|
+
kind: 'debug',
|
|
170
|
+
text: `Loaded ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush`
|
|
171
|
+
},
|
|
172
|
+
progressPercent
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
if (onNotifyEvent) {
|
|
179
|
+
onNotifyEvent({
|
|
180
|
+
logMessage: {
|
|
181
|
+
kind: 'info',
|
|
182
|
+
text: 'The operation failed: ' + ((_b = e.message) !== null && _b !== void 0 ? _b : 'An unknown error occurred')
|
|
183
|
+
},
|
|
184
|
+
progressPercent
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.RushSdkLoader = RushSdkLoader;
|
|
192
|
+
//# sourceMappingURL=loader.js.map
|