@rushstack/rush-sdk 5.129.6 → 5.130.0
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 +23 -6
- package/{lib-shim → dist}/tsdoc-metadata.json +1 -1
- package/lib/api/CommonVersionsConfiguration.d.ts +3 -2
- package/lib/api/ExperimentsConfiguration.d.ts +7 -0
- package/lib/api/RushConfiguration.d.ts +6 -0
- package/lib/logic/RushConstants.d.ts +8 -0
- package/lib/logic/operations/AsyncOperationQueue.d.ts +3 -17
- package/lib/logic/operations/OperationExecutionRecord.d.ts +1 -0
- package/lib/logic/operations/OperationStatus.d.ts +5 -4
- package/lib/utilities/RushAlerts.d.ts +22 -0
- package/lib/utilities/RushAlerts.js +1 -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 +2200 -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
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { JsonFile, Executable } from '@rushstack/node-core-library';
|
|
5
|
+
import { tryFindRushJsonLocation, RUSH_LIB_NAME, requireRushLibUnderFolderPath, sdkContext } from './helpers';
|
|
6
|
+
/**
|
|
7
|
+
* Exposes operations that control how the `@microsoft/rush-lib` engine is
|
|
8
|
+
* located and loaded.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export class RushSdkLoader {
|
|
12
|
+
/**
|
|
13
|
+
* Throws an "AbortError" exception if abortSignal.aborted is true.
|
|
14
|
+
*/
|
|
15
|
+
static _checkForCancel(abortSignal, onNotifyEvent, progressPercent) {
|
|
16
|
+
if (!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (onNotifyEvent) {
|
|
20
|
+
onNotifyEvent({
|
|
21
|
+
logMessage: {
|
|
22
|
+
kind: 'info',
|
|
23
|
+
text: `The operation was canceled`
|
|
24
|
+
},
|
|
25
|
+
progressPercent
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const error = new Error('The operation was canceled');
|
|
29
|
+
error.name = 'AbortError';
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns true if the Rush engine has already been loaded.
|
|
34
|
+
*/
|
|
35
|
+
static get isLoaded() {
|
|
36
|
+
return sdkContext.rushLibModule !== undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Manually load the Rush engine based on rush.json found for `rushJsonSearchFolder`.
|
|
40
|
+
* Throws an exception if {@link RushSdkLoader.isLoaded} is already `true`.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* This API supports an callback that can be used display a progress bar,
|
|
44
|
+
* log of operations, and allow the operation to be canceled prematurely.
|
|
45
|
+
*/
|
|
46
|
+
static async loadAsync(options) {
|
|
47
|
+
// SCENARIO 5: The rush-lib engine is loaded manually using rushSdkLoader.loadAsync().
|
|
48
|
+
var _a, _b;
|
|
49
|
+
if (!options) {
|
|
50
|
+
options = {};
|
|
51
|
+
}
|
|
52
|
+
if (RushSdkLoader.isLoaded) {
|
|
53
|
+
throw new Error('RushSdkLoader.loadAsync() failed because the Rush engine has already been loaded');
|
|
54
|
+
}
|
|
55
|
+
const onNotifyEvent = options.onNotifyEvent;
|
|
56
|
+
let progressPercent = undefined;
|
|
57
|
+
const abortSignal = options.abortSignal;
|
|
58
|
+
try {
|
|
59
|
+
const rushJsonSearchFolder = (_a = options.rushJsonSearchFolder) !== null && _a !== void 0 ? _a : process.cwd();
|
|
60
|
+
if (onNotifyEvent) {
|
|
61
|
+
onNotifyEvent({
|
|
62
|
+
logMessage: {
|
|
63
|
+
kind: 'debug',
|
|
64
|
+
text: `Searching for rush.json starting from: ` + rushJsonSearchFolder
|
|
65
|
+
},
|
|
66
|
+
progressPercent
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const rushJsonPath = tryFindRushJsonLocation(rushJsonSearchFolder);
|
|
70
|
+
if (!rushJsonPath) {
|
|
71
|
+
throw new Error('Unable to find rush.json in the specified folder or its parent folders:\n' +
|
|
72
|
+
`${rushJsonSearchFolder}\n`);
|
|
73
|
+
}
|
|
74
|
+
const monorepoRoot = path.dirname(rushJsonPath);
|
|
75
|
+
const rushJson = await JsonFile.loadAsync(rushJsonPath);
|
|
76
|
+
const { rushVersion } = rushJson;
|
|
77
|
+
const installRunNodeModuleFolder = path.join(monorepoRoot, `common/temp/install-run/@microsoft+rush@${rushVersion}`);
|
|
78
|
+
try {
|
|
79
|
+
// First, try to load the version of "rush-lib" that was installed by install-run-rush.js
|
|
80
|
+
if (onNotifyEvent) {
|
|
81
|
+
onNotifyEvent({
|
|
82
|
+
logMessage: {
|
|
83
|
+
kind: 'info',
|
|
84
|
+
text: `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`
|
|
85
|
+
},
|
|
86
|
+
progressPercent
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
|
|
90
|
+
}
|
|
91
|
+
catch (e1) {
|
|
92
|
+
let installAndRunRushStderrContent = '';
|
|
93
|
+
try {
|
|
94
|
+
const installAndRunRushJSPath = path.join(monorepoRoot, 'common/scripts/install-run-rush.js');
|
|
95
|
+
if (onNotifyEvent) {
|
|
96
|
+
onNotifyEvent({
|
|
97
|
+
logMessage: {
|
|
98
|
+
kind: 'info',
|
|
99
|
+
text: 'The Rush engine has not been installed yet. Invoking install-run-rush.js...'
|
|
100
|
+
},
|
|
101
|
+
progressPercent
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// Start the installation
|
|
105
|
+
progressPercent = 0;
|
|
106
|
+
const installAndRunRushProcess = Executable.spawnSync('node', [installAndRunRushJSPath, '--help'], {
|
|
107
|
+
stdio: 'pipe'
|
|
108
|
+
});
|
|
109
|
+
installAndRunRushStderrContent = installAndRunRushProcess.stderr;
|
|
110
|
+
if (installAndRunRushProcess.status !== 0) {
|
|
111
|
+
throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);
|
|
112
|
+
}
|
|
113
|
+
if (abortSignal) {
|
|
114
|
+
RushSdkLoader._checkForCancel(abortSignal, onNotifyEvent, progressPercent);
|
|
115
|
+
}
|
|
116
|
+
// TODO: Implement incremental progress updates
|
|
117
|
+
progressPercent = 90;
|
|
118
|
+
// Retry to load "rush-lib" after install-run-rush run
|
|
119
|
+
if (onNotifyEvent) {
|
|
120
|
+
onNotifyEvent({
|
|
121
|
+
logMessage: {
|
|
122
|
+
kind: 'debug',
|
|
123
|
+
text: `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`
|
|
124
|
+
},
|
|
125
|
+
progressPercent
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
|
|
129
|
+
progressPercent = 100;
|
|
130
|
+
}
|
|
131
|
+
catch (e2) {
|
|
132
|
+
// eslint-disable-next-line no-console
|
|
133
|
+
console.error(`${installAndRunRushStderrContent}`);
|
|
134
|
+
throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (sdkContext.rushLibModule !== undefined) {
|
|
138
|
+
// to track which scenario is active and how it got initialized.
|
|
139
|
+
global.___rush___rushLibModuleFromInstallAndRunRush = sdkContext.rushLibModule;
|
|
140
|
+
if (onNotifyEvent) {
|
|
141
|
+
onNotifyEvent({
|
|
142
|
+
logMessage: {
|
|
143
|
+
kind: 'debug',
|
|
144
|
+
text: `Loaded ${RUSH_LIB_NAME} installed by install-run-rush`
|
|
145
|
+
},
|
|
146
|
+
progressPercent
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
if (onNotifyEvent) {
|
|
153
|
+
onNotifyEvent({
|
|
154
|
+
logMessage: {
|
|
155
|
+
kind: 'info',
|
|
156
|
+
text: 'The operation failed: ' + ((_b = e.message) !== null && _b !== void 0 ? _b : 'An unknown error occurred')
|
|
157
|
+
},
|
|
158
|
+
progressPercent
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
throw e;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
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AC;oBACnD,MAAM,IAAI,KAAK,CAAC,OAAO,aAAa,yBAAyB,CAAC,CAAC;gBACjE,CAAC;YACH,CAAC;YAED,IAAI,UAAU,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;gBAC3C,gEAAgE;gBAChE,MAAM,CAAC,4CAA4C,GAAG,UAAU,CAAC,aAAa,CAAC;gBAC/E,IAAI,aAAa,EAAE,CAAC;oBAClB,aAAa,CAAC;wBACZ,UAAU,EAAE;4BACV,IAAI,EAAE,OAAO;4BACb,IAAI,EAAE,UAAU,aAAa,gCAAgC;yBAC9D;wBACD,eAAe;qBAChB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,aAAa,EAAE,CAAC;gBAClB,aAAa,CAAC;oBACZ,UAAU,EAAE;wBACV,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,wBAAwB,GAAG,CAAC,MAAA,CAAC,CAAC,OAAO,mCAAI,2BAA2B,CAAC;qBAC5E;oBACD,eAAe;iBAChB,CAAC,CAAC;YACL,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF","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 type { SpawnSyncReturns } from 'child_process';\nimport { JsonFile, type JsonObject, Executable } from '@rushstack/node-core-library';\n\nimport {\n tryFindRushJsonLocation,\n RUSH_LIB_NAME,\n type RushLibModuleType,\n requireRushLibUnderFolderPath,\n sdkContext\n} from './helpers';\n\ndeclare const global: typeof globalThis & {\n ___rush___rushLibModule?: RushLibModuleType;\n ___rush___rushLibModuleFromEnvironment?: RushLibModuleType;\n ___rush___rushLibModuleFromInstallAndRunRush?: RushLibModuleType;\n};\n\n/**\n * Type of {@link ISdkCallbackEvent.logMessage}\n * @public\n */\nexport interface IProgressBarCallbackLogMessage {\n /**\n * A status message to print in the log window, or `undefined` if there are\n * no further messages. This string may contain newlines.\n */\n text: string;\n\n /**\n * The type of message. More message types may be added in the future.\n */\n kind: 'info' | 'debug';\n}\n\n/**\n * Event options for {@link ILoadSdkAsyncOptions.onNotifyEvent}\n * @public\n */\nexport interface ISdkCallbackEvent {\n /**\n * Allows the caller to display log information about the operation.\n */\n logMessage: IProgressBarCallbackLogMessage | undefined;\n\n /**\n * Allows the caller to display a progress bar for long-running operations.\n *\n * @remarks\n * If a long-running operation is required, then `progressPercent` will\n * start at 0.0 and count upwards and finish at 100.0 if the operation completes\n * successfully. If the long-running operation has not yet started, or\n * is not required, then the value will be `undefined`.\n */\n progressPercent: number | undefined;\n}\n\n/**\n * Type of {@link ILoadSdkAsyncOptions.onNotifyEvent}\n * @public\n */\nexport type SdkNotifyEventCallback = (sdkEvent: ISdkCallbackEvent) => void;\n\n/**\n * Options for {@link RushSdkLoader.loadAsync}\n * @public\n */\nexport interface ILoadSdkAsyncOptions {\n /**\n * The folder to start from when searching for the Rush workspace configuration.\n * If this folder does not contain a `rush.json` file, then each parent folder\n * will be searched. If `rush.json` is not found, then the SDK fails to load.\n */\n rushJsonSearchFolder?: string;\n\n /**\n * A cancellation token that the caller can use to prematurely abort the operation.\n */\n abortSignal?: AbortSignal;\n\n /**\n * Allows the caller to monitor the progress of the operation.\n */\n onNotifyEvent?: SdkNotifyEventCallback;\n}\n\n/**\n * Exposes operations that control how the `@microsoft/rush-lib` engine is\n * located and loaded.\n * @public\n */\nexport class RushSdkLoader {\n /**\n * Throws an \"AbortError\" exception if abortSignal.aborted is true.\n */\n private static _checkForCancel(\n abortSignal: AbortSignal,\n onNotifyEvent: SdkNotifyEventCallback | undefined,\n progressPercent: number | undefined\n ): void {\n if (!abortSignal?.aborted) {\n return;\n }\n\n if (onNotifyEvent) {\n onNotifyEvent({\n logMessage: {\n kind: 'info',\n text: `The operation was canceled`\n },\n progressPercent\n });\n }\n\n const error: Error = new Error('The operation was canceled');\n error.name = 'AbortError';\n throw error;\n }\n\n /**\n * Returns true if the Rush engine has already been loaded.\n */\n public static get isLoaded(): boolean {\n return sdkContext.rushLibModule !== undefined;\n }\n\n /**\n * Manually load the Rush engine based on rush.json found for `rushJsonSearchFolder`.\n * Throws an exception if {@link RushSdkLoader.isLoaded} is already `true`.\n *\n * @remarks\n * This API supports an callback that can be used display a progress bar,\n * log of operations, and allow the operation to be canceled prematurely.\n */\n public static async loadAsync(options?: ILoadSdkAsyncOptions): Promise<void> {\n // SCENARIO 5: The rush-lib engine is loaded manually using rushSdkLoader.loadAsync().\n\n if (!options) {\n options = {};\n }\n\n if (RushSdkLoader.isLoaded) {\n throw new Error('RushSdkLoader.loadAsync() failed because the Rush engine has already been loaded');\n }\n\n const onNotifyEvent: SdkNotifyEventCallback | undefined = options.onNotifyEvent;\n let progressPercent: number | undefined = undefined;\n\n const abortSignal: AbortSignal | undefined = options.abortSignal;\n\n try {\n const rushJsonSearchFolder: string = options.rushJsonSearchFolder ?? process.cwd();\n\n if (onNotifyEvent) {\n onNotifyEvent({\n logMessage: {\n kind: 'debug',\n text: `Searching for rush.json starting from: ` + rushJsonSearchFolder\n },\n progressPercent\n });\n }\n\n const rushJsonPath: string | undefined = tryFindRushJsonLocation(rushJsonSearchFolder);\n if (!rushJsonPath) {\n throw new Error(\n 'Unable to find rush.json in the specified folder or its parent folders:\\n' +\n `${rushJsonSearchFolder}\\n`\n );\n }\n const monorepoRoot: string = path.dirname(rushJsonPath);\n\n const rushJson: JsonObject = await JsonFile.loadAsync(rushJsonPath);\n const { rushVersion } = rushJson;\n\n const installRunNodeModuleFolder: string = path.join(\n monorepoRoot,\n `common/temp/install-run/@microsoft+rush@${rushVersion}`\n );\n\n try {\n // First, try to load the version of \"rush-lib\" that was installed by install-run-rush.js\n if (onNotifyEvent) {\n onNotifyEvent({\n logMessage: {\n kind: 'info',\n text: `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`\n },\n progressPercent\n });\n }\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\n } catch (e1) {\n let installAndRunRushStderrContent: string = '';\n try {\n const installAndRunRushJSPath: string = path.join(\n monorepoRoot,\n 'common/scripts/install-run-rush.js'\n );\n\n if (onNotifyEvent) {\n onNotifyEvent({\n logMessage: {\n kind: 'info',\n text: 'The Rush engine has not been installed yet. Invoking install-run-rush.js...'\n },\n progressPercent\n });\n }\n\n // Start the installation\n progressPercent = 0;\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 if (abortSignal) {\n RushSdkLoader._checkForCancel(abortSignal, onNotifyEvent, progressPercent);\n }\n\n // TODO: Implement incremental progress updates\n progressPercent = 90;\n\n // Retry to load \"rush-lib\" after install-run-rush run\n if (onNotifyEvent) {\n onNotifyEvent({\n logMessage: {\n kind: 'debug',\n text: `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`\n },\n progressPercent\n });\n }\n\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\n\n progressPercent = 100;\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 if (onNotifyEvent) {\n onNotifyEvent({\n logMessage: {\n kind: 'debug',\n text: `Loaded ${RUSH_LIB_NAME} installed by install-run-rush`\n },\n progressPercent\n });\n }\n }\n } catch (e) {\n if (onNotifyEvent) {\n onNotifyEvent({\n logMessage: {\n kind: 'info',\n text: 'The operation failed: ' + (e.message ?? 'An unknown error occurred')\n },\n progressPercent\n });\n }\n throw e;\n }\n }\n}\n"]}
|