@rushstack/rush-sdk 5.131.0 → 5.131.2

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.
Files changed (37) hide show
  1. package/dist/rush-lib.d.ts +4 -119
  2. package/dist/tsdoc-metadata.json +1 -1
  3. package/lib/api/RushConfiguration.d.ts +1 -1
  4. package/lib/index.d.ts +1 -1
  5. package/lib-shim/index.js +1995 -119
  6. package/lib-shim/index.js.map +1 -1
  7. package/lib-shim/loader.js +299 -174
  8. package/lib-shim/loader.js.map +1 -1
  9. package/package.json +5 -4
  10. package/lib/logic/LookupByPath.d.ts +0 -120
  11. package/lib/logic/LookupByPath.js +0 -1
  12. package/lib-commonjs/generate-stubs.d.ts +0 -2
  13. package/lib-commonjs/generate-stubs.d.ts.map +0 -1
  14. package/lib-commonjs/generate-stubs.js +0 -84
  15. package/lib-commonjs/generate-stubs.js.map +0 -1
  16. package/lib-commonjs/helpers.d.ts +0 -21
  17. package/lib-commonjs/helpers.d.ts.map +0 -1
  18. package/lib-commonjs/helpers.js +0 -83
  19. package/lib-commonjs/helpers.js.map +0 -1
  20. package/lib-commonjs/index.d.ts +0 -5
  21. package/lib-commonjs/index.d.ts.map +0 -1
  22. package/lib-commonjs/index.js +0 -207
  23. package/lib-commonjs/index.js.map +0 -1
  24. package/lib-commonjs/loader.d.ts +0 -86
  25. package/lib-commonjs/loader.d.ts.map +0 -1
  26. package/lib-commonjs/loader.js +0 -192
  27. package/lib-commonjs/loader.js.map +0 -1
  28. package/lib-esnext/generate-stubs.js +0 -57
  29. package/lib-esnext/generate-stubs.js.map +0 -1
  30. package/lib-esnext/helpers.js +0 -54
  31. package/lib-esnext/helpers.js.map +0 -1
  32. package/lib-esnext/index.js +0 -180
  33. package/lib-esnext/index.js.map +0 -1
  34. package/lib-esnext/loader.js +0 -165
  35. package/lib-esnext/loader.js.map +0 -1
  36. package/lib-shim/commons.js +0 -2200
  37. package/lib-shim/commons.js.map +0 -1
@@ -1,86 +0,0 @@
1
- /// <reference types="node" />
2
- /**
3
- * Type of {@link ISdkCallbackEvent.logMessage}
4
- * @public
5
- */
6
- export interface IProgressBarCallbackLogMessage {
7
- /**
8
- * A status message to print in the log window, or `undefined` if there are
9
- * no further messages. This string may contain newlines.
10
- */
11
- text: string;
12
- /**
13
- * The type of message. More message types may be added in the future.
14
- */
15
- kind: 'info' | 'debug';
16
- }
17
- /**
18
- * Event options for {@link ILoadSdkAsyncOptions.onNotifyEvent}
19
- * @public
20
- */
21
- export interface ISdkCallbackEvent {
22
- /**
23
- * Allows the caller to display log information about the operation.
24
- */
25
- logMessage: IProgressBarCallbackLogMessage | undefined;
26
- /**
27
- * Allows the caller to display a progress bar for long-running operations.
28
- *
29
- * @remarks
30
- * If a long-running operation is required, then `progressPercent` will
31
- * start at 0.0 and count upwards and finish at 100.0 if the operation completes
32
- * successfully. If the long-running operation has not yet started, or
33
- * is not required, then the value will be `undefined`.
34
- */
35
- progressPercent: number | undefined;
36
- }
37
- /**
38
- * Type of {@link ILoadSdkAsyncOptions.onNotifyEvent}
39
- * @public
40
- */
41
- export type SdkNotifyEventCallback = (sdkEvent: ISdkCallbackEvent) => void;
42
- /**
43
- * Options for {@link RushSdkLoader.loadAsync}
44
- * @public
45
- */
46
- export interface ILoadSdkAsyncOptions {
47
- /**
48
- * The folder to start from when searching for the Rush workspace configuration.
49
- * If this folder does not contain a `rush.json` file, then each parent folder
50
- * will be searched. If `rush.json` is not found, then the SDK fails to load.
51
- */
52
- rushJsonSearchFolder?: string;
53
- /**
54
- * A cancellation token that the caller can use to prematurely abort the operation.
55
- */
56
- abortSignal?: AbortSignal;
57
- /**
58
- * Allows the caller to monitor the progress of the operation.
59
- */
60
- onNotifyEvent?: SdkNotifyEventCallback;
61
- }
62
- /**
63
- * Exposes operations that control how the `@microsoft/rush-lib` engine is
64
- * located and loaded.
65
- * @public
66
- */
67
- export declare class RushSdkLoader {
68
- /**
69
- * Throws an "AbortError" exception if abortSignal.aborted is true.
70
- */
71
- private static _checkForCancel;
72
- /**
73
- * Returns true if the Rush engine has already been loaded.
74
- */
75
- static get isLoaded(): boolean;
76
- /**
77
- * Manually load the Rush engine based on rush.json found for `rushJsonSearchFolder`.
78
- * Throws an exception if {@link RushSdkLoader.isLoaded} is already `true`.
79
- *
80
- * @remarks
81
- * This API supports an callback that can be used display a progress bar,
82
- * log of operations, and allow the operation to be canceled prematurely.
83
- */
84
- static loadAsync(options?: ILoadSdkAsyncOptions): Promise<void>;
85
- }
86
- //# sourceMappingURL=loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAqBA;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,UAAU,EAAE,8BAA8B,GAAG,SAAS,CAAC;IAEvD;;;;;;;;OAQG;IACH,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAE3E;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;OAEG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAC;CACxC;AAED;;;;GAIG;AACH,qBAAa,aAAa;IACxB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAwB9B;;OAEG;IACH,WAAkB,QAAQ,IAAI,OAAO,CAEpC;IAED;;;;;;;OAOG;WACiB,SAAS,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAkJ7E"}
@@ -1,192 +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 __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
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAE7B,oEAAqF;AAErF,uCAMmB;AA4EnB;;;;GAIG;AACH,MAAa,aAAa;IACxB;;OAEG;IACK,MAAM,CAAC,eAAe,CAC5B,WAAwB,EACxB,aAAiD,EACjD,eAAmC;QAEnC,IAAI,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAA,EAAE,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC;gBACZ,UAAU,EAAE;oBACV,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,4BAA4B;iBACnC;gBACD,eAAe;aAChB,CAAC,CAAC;QACL,CAAC;QAED,MAAM,KAAK,GAAU,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC7D,KAAK,CAAC,IAAI,GAAG,YAAY,CAAC;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,QAAQ;QACxB,OAAO,oBAAU,CAAC,aAAa,KAAK,SAAS,CAAC;IAChD,CAA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I,EAAE,OAAO;gCACb,IAAI,EAAE,mBAAmB,uBAAa,8CAA8C;6BACrF;4BACD,eAAe;yBAChB,CAAC,CAAC;oBACL,CAAC;oBAED,oBAAU,CAAC,aAAa,GAAG,IAAA,uCAA6B,EAAC,0BAA0B,CAAC,CAAC;oBAErF,eAAe,GAAG,GAAG,CAAC;gBACxB,CAAC;gBAAC,OAAO,EAAE,EAAE,CAAC;oBACZ,sCAAsC;oBACtC,OAAO,CAAC,KAAK,CAAC,GAAG,8BAA8B,EAAE,CAAC,CAAC;oBACnD,MAAM,IAAI,KAAK,CAAC,OAAO,uBAAa,yBAAyB,CAAC,CAAC;gBACjE,CAAC;YACH,CAAC;YAED,IAAI,oBAAU,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;gBAC3C,gEAAgE;gBAChE,MAAM,CAAC,4CAA4C,GAAG,oBAAU,CAAC,aAAa,CAAC;gBAC/E,IAAI,aAAa,EAAE,CAAC;oBAClB,aAAa,CAAC;wBACZ,UAAU,EAAE;4BACV,IAAI,EAAE,OAAO;4BACb,IAAI,EAAE,UAAU,uBAAa,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;AA7LD,sCA6LC","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"]}
@@ -1,57 +0,0 @@
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 { FileSystem, Import, Path } from '@rushstack/node-core-library';
5
- function generateLibFilesRecursively(options) {
6
- for (const folderItem of FileSystem.readFolderItems(options.parentSourcePath)) {
7
- const sourcePath = path.join(options.parentSourcePath, folderItem.name);
8
- const targetPath = path.join(options.parentTargetPath, folderItem.name);
9
- if (folderItem.isDirectory()) {
10
- // create destination folder
11
- FileSystem.ensureEmptyFolder(targetPath);
12
- generateLibFilesRecursively({
13
- parentSourcePath: sourcePath,
14
- parentTargetPath: targetPath,
15
- parentSrcImportPathWithSlash: options.parentSrcImportPathWithSlash + folderItem.name + '/',
16
- libShimIndexPath: options.libShimIndexPath
17
- });
18
- }
19
- else {
20
- if (folderItem.name.endsWith('.d.ts')) {
21
- FileSystem.copyFile({
22
- sourcePath: sourcePath,
23
- destinationPath: targetPath
24
- });
25
- }
26
- else if (folderItem.name.endsWith('.js')) {
27
- const srcImportPath = options.parentSrcImportPathWithSlash + path.parse(folderItem.name).name;
28
- const shimPath = path.relative(options.parentTargetPath, options.libShimIndexPath);
29
- const shimPathLiteral = JSON.stringify(Path.convertToSlashes(shimPath));
30
- const srcImportPathLiteral = JSON.stringify(srcImportPath);
31
- FileSystem.writeFile(targetPath,
32
- // Example:
33
- // module.exports = require("../../../lib-shim/index")._rushSdk_loadInternalModule("logic/policy/GitEmailPolicy");
34
- `module.exports = require(${shimPathLiteral})._rushSdk_loadInternalModule(${srcImportPathLiteral});`);
35
- }
36
- }
37
- }
38
- }
39
- // Entry point invoked by "runScript" action from config/heft.json
40
- export async function runAsync() {
41
- const rushLibFolder = Import.resolvePackage({
42
- baseFolderPath: __dirname,
43
- packageName: '@microsoft/rush-lib'
44
- });
45
- const stubsTargetPath = path.resolve(__dirname, '../lib');
46
- // eslint-disable-next-line no-console
47
- console.log('generate-stubs: Generating stub files under: ' + stubsTargetPath);
48
- generateLibFilesRecursively({
49
- parentSourcePath: path.join(rushLibFolder, 'lib'),
50
- parentTargetPath: stubsTargetPath,
51
- parentSrcImportPathWithSlash: '',
52
- libShimIndexPath: path.join(__dirname, '../lib-shim/index')
53
- });
54
- // eslint-disable-next-line no-console
55
- console.log('generate-stubs: Completed successfully.');
56
- }
57
- //# sourceMappingURL=generate-stubs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-stubs.js","sourceRoot":"","sources":["../src/generate-stubs.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAExE,SAAS,2BAA2B,CAAC,OAKpC;IACC,KAAK,MAAM,UAAU,IAAI,UAAU,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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c,CAAC;QAClD,cAAc,EAAE,SAAS;QACzB,WAAW,EAAE,qBAAqB;KACnC,CAAC,CAAC;IAEH,MAAM,eAAe,GAAW,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAClE,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,+CAA+C,GAAG,eAAe,CAAC,CAAC;IAC/E,2BAA2B,CAAC;QAC1B,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC,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","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"]}
@@ -1,54 +0,0 @@
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 { Import, FileSystem } from '@rushstack/node-core-library';
5
- export const RUSH_LIB_NAME = '@microsoft/rush-lib';
6
- export const RUSH_LIB_PATH_ENV_VAR_NAME = '_RUSH_LIB_PATH';
7
- export const sdkContext = {
8
- rushLibModule: undefined
9
- };
10
- /**
11
- * Find the rush.json location and return the path, or undefined if a rush.json can't be found.
12
- *
13
- * @privateRemarks
14
- * Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`.
15
- */
16
- export function tryFindRushJsonLocation(startingFolder) {
17
- let currentFolder = startingFolder;
18
- // Look upwards at parent folders until we find a folder containing rush.json
19
- for (let i = 0; i < 10; ++i) {
20
- const rushJsonFilename = path.join(currentFolder, 'rush.json');
21
- if (FileSystem.exists(rushJsonFilename)) {
22
- return rushJsonFilename;
23
- }
24
- const parentFolder = path.dirname(currentFolder);
25
- if (parentFolder === currentFolder) {
26
- break;
27
- }
28
- currentFolder = parentFolder;
29
- }
30
- return undefined;
31
- }
32
- export function _require(moduleName) {
33
- if (typeof __non_webpack_require__ === 'function') {
34
- // If this library has been bundled with Webpack, we need to call the real `require` function
35
- // that doesn't get turned into a `__webpack_require__` statement.
36
- // `__non_webpack_require__` is a Webpack macro that gets turned into a `require` statement
37
- // during bundling.
38
- return __non_webpack_require__(moduleName);
39
- }
40
- else {
41
- return require(moduleName);
42
- }
43
- }
44
- /**
45
- * Require `@microsoft/rush-lib` under the specified folder path.
46
- */
47
- export function requireRushLibUnderFolderPath(folderPath) {
48
- const rushLibModulePath = Import.resolveModule({
49
- modulePath: RUSH_LIB_NAME,
50
- baseFolderPath: folderPath
51
- });
52
- return _require(rushLibModulePath);
53
- }
54
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAGlE,MAAM,CAAC,MAAM,aAAa,GAA0B,qBAAqB,CAAC;AAC1E,MAAM,CAAC,MAAM,0BAA0B,GAAmD,gBAAgB,CAAC;AAQ3G,MAAM,CAAC,MAAM,UAAU,GAAgB;IACrC,aAAa,EAAE,SAAS;CACzB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,cAAsB;IAC5D,IAAI,aAAa,GAAW,cAAc,CAAC;IAE3C,6EAA6E;IAC7E,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QACpC,MAAM,gBAAgB,GAAW,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;QAEvE,IAAI,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACxC,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,YAAY,GAAW,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACzD,IAAI,YAAY,KAAK,aAAa,EAAE,CAAC;YACnC,MAAM;QACR,CAAC;QAED,aAAa,GAAG,YAAY,CAAC;IAC/B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,QAAQ,CAAU,UAAkB;IAClD,IAAI,OAAO,uBAAuB,KAAK,UAAU,EAAE,CAAC;QAClD,6FAA6F;QAC7F,kEAAkE;QAClE,2FAA2F;QAC3F,mBAAmB;QACnB,OAAO,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAAC,UAAkB;IAC9D,MAAM,iBAAiB,GAAW,MAAM,CAAC,aAAa,CAAC;QACrD,UAAU,EAAE,aAAa;QACzB,cAAc,EAAE,UAAU;KAC3B,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AACrC,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 * as path from 'path';\nimport { Import, FileSystem } from '@rushstack/node-core-library';\nimport type { EnvironmentVariableNames } from '@microsoft/rush-lib';\n\nexport const RUSH_LIB_NAME: '@microsoft/rush-lib' = '@microsoft/rush-lib';\nexport const RUSH_LIB_PATH_ENV_VAR_NAME: typeof EnvironmentVariableNames._RUSH_LIB_PATH = '_RUSH_LIB_PATH';\n\nexport type RushLibModuleType = Record<string, unknown>;\n\nexport interface ISdkContext {\n rushLibModule: RushLibModuleType | undefined;\n}\n\nexport const sdkContext: ISdkContext = {\n rushLibModule: undefined\n};\n\n/**\n * Find the rush.json location and return the path, or undefined if a rush.json can't be found.\n *\n * @privateRemarks\n * Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`.\n */\nexport function tryFindRushJsonLocation(startingFolder: string): string | undefined {\n let currentFolder: string = startingFolder;\n\n // Look upwards at parent folders until we find a folder containing rush.json\n for (let i: number = 0; i < 10; ++i) {\n const rushJsonFilename: string = path.join(currentFolder, 'rush.json');\n\n if (FileSystem.exists(rushJsonFilename)) {\n return rushJsonFilename;\n }\n\n const parentFolder: string = path.dirname(currentFolder);\n if (parentFolder === currentFolder) {\n break;\n }\n\n currentFolder = parentFolder;\n }\n\n return undefined;\n}\n\nexport function _require<TResult>(moduleName: string): TResult {\n if (typeof __non_webpack_require__ === 'function') {\n // If this library has been bundled with Webpack, we need to call the real `require` function\n // that doesn't get turned into a `__webpack_require__` statement.\n // `__non_webpack_require__` is a Webpack macro that gets turned into a `require` statement\n // during bundling.\n return __non_webpack_require__(moduleName);\n } else {\n return require(moduleName);\n }\n}\n\n/**\n * Require `@microsoft/rush-lib` under the specified folder path.\n */\nexport function requireRushLibUnderFolderPath(folderPath: string): RushLibModuleType {\n const rushLibModulePath: string = Import.resolveModule({\n modulePath: RUSH_LIB_NAME,\n baseFolderPath: folderPath\n });\n\n return _require(rushLibModulePath);\n}\n"]}
@@ -1,180 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
- // See LICENSE in the project root for license information.
3
- var _a;
4
- import * as path from 'path';
5
- import { JsonFile, PackageJsonLookup, Executable } from '@rushstack/node-core-library';
6
- import { Terminal, ConsoleTerminalProvider } from '@rushstack/terminal';
7
- import { RushGlobalFolder } from '@microsoft/rush-lib/lib-esnext/api/RushGlobalFolder';
8
- import { RUSH_LIB_NAME, RUSH_LIB_PATH_ENV_VAR_NAME, _require, requireRushLibUnderFolderPath, tryFindRushJsonLocation, sdkContext } from './helpers';
9
- const verboseEnabled = typeof process !== 'undefined' &&
10
- (process.env.RUSH_SDK_DEBUG === '1' || process.env._RUSH_SDK_DEBUG === '1');
11
- const terminal = new Terminal(new ConsoleTerminalProvider({
12
- verboseEnabled
13
- }));
14
- let errorMessage = '';
15
- // SCENARIO 1: Rush's PluginManager has initialized "rush-sdk" with Rush's own instance of rush-lib.
16
- // The Rush host process will assign "global.___rush___rushLibModule" before loading the plugin.
17
- if (sdkContext.rushLibModule === undefined) {
18
- sdkContext.rushLibModule =
19
- global.___rush___rushLibModule ||
20
- global.___rush___rushLibModuleFromEnvironment ||
21
- global.___rush___rushLibModuleFromRushGlobalFolder ||
22
- global.___rush___rushLibModuleFromInstallAndRunRush;
23
- }
24
- // SCENARIO 2: The project importing "rush-sdk" has installed its own instance of "rush-lib"
25
- // as a package.json dependency. For example, this is used by the Jest tests for Rush plugins.
26
- if (sdkContext.rushLibModule === undefined) {
27
- const importingPath = (_a = module === null || module === void 0 ? void 0 : module.parent) === null || _a === void 0 ? void 0 : _a.filename;
28
- if (importingPath) {
29
- const callerPackageFolder = PackageJsonLookup.instance.tryGetPackageFolderFor(importingPath);
30
- if (callerPackageFolder !== undefined) {
31
- const callerPackageJson = _require(path.join(callerPackageFolder, 'package.json'));
32
- // Does the caller properly declare a dependency on rush-lib?
33
- if ((callerPackageJson.dependencies && callerPackageJson.dependencies[RUSH_LIB_NAME] !== undefined) ||
34
- (callerPackageJson.devDependencies &&
35
- callerPackageJson.devDependencies[RUSH_LIB_NAME] !== undefined) ||
36
- (callerPackageJson.peerDependencies &&
37
- callerPackageJson.peerDependencies[RUSH_LIB_NAME] !== undefined)) {
38
- // Try to resolve rush-lib from the caller's folder
39
- terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from caller package`);
40
- try {
41
- sdkContext.rushLibModule = requireRushLibUnderFolderPath(callerPackageFolder);
42
- }
43
- catch (error) {
44
- // If we fail to resolve it, ignore the error
45
- terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from caller package`);
46
- }
47
- // If two different libraries invoke `rush-sdk`, and one of them provides "rush-lib"
48
- // then the first version to be loaded wins. We do not support side-by-side instances of "rush-lib".
49
- if (sdkContext.rushLibModule !== undefined) {
50
- // to track which scenario is active and how it got initialized.
51
- global.___rush___rushLibModule = sdkContext.rushLibModule;
52
- terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from caller`);
53
- }
54
- }
55
- }
56
- }
57
- }
58
- // SCENARIO 3: A tool or script has been invoked as a child process by an instance of "rush-lib" and can use the
59
- // version that invoked it. In this case, use process.env._RUSH_LIB_PATH to find "rush-lib".
60
- if (sdkContext.rushLibModule === undefined) {
61
- const rushLibPath = process.env[RUSH_LIB_PATH_ENV_VAR_NAME];
62
- if (rushLibPath) {
63
- terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME} from caller package`);
64
- try {
65
- sdkContext.rushLibModule = _require(rushLibPath);
66
- }
67
- catch (error) {
68
- // Log this as a warning, since it is unexpected to define an incorrect value of the variable.
69
- terminal.writeWarningLine(`Failed to load ${RUSH_LIB_NAME} via process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`);
70
- }
71
- if (sdkContext.rushLibModule !== undefined) {
72
- // to track which scenario is active and how it got initialized.
73
- global.___rush___rushLibModuleFromEnvironment = sdkContext.rushLibModule;
74
- terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`);
75
- }
76
- }
77
- }
78
- // SCENARIO 4: A standalone tool or script depends on "rush-sdk", and is meant to be used inside a monorepo folder.
79
- // In this case, we can first load the rush-lib version in rush global folder. If the expected version is not installed,
80
- // using install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.
81
- if (sdkContext.rushLibModule === undefined) {
82
- try {
83
- const rushJsonPath = tryFindRushJsonLocation(process.cwd());
84
- if (!rushJsonPath) {
85
- throw new Error('Unable to find rush.json in the current folder or its parent folders.\n' +
86
- 'This tool is meant to be invoked from a working directory inside a Rush repository.');
87
- }
88
- const monorepoRoot = path.dirname(rushJsonPath);
89
- const rushJson = JsonFile.load(rushJsonPath);
90
- const { rushVersion } = rushJson;
91
- try {
92
- terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from rush global folder`);
93
- const rushGlobalFolder = new RushGlobalFolder();
94
- // The path needs to keep align with the logic inside RushVersionSelector
95
- const expectedGlobalRushInstalledFolder = `${rushGlobalFolder.nodeSpecificPath}/rush-${rushVersion}`;
96
- terminal.writeVerboseLine(`The expected global rush installed folder is "${expectedGlobalRushInstalledFolder}"`);
97
- sdkContext.rushLibModule = requireRushLibUnderFolderPath(expectedGlobalRushInstalledFolder);
98
- }
99
- catch (e) {
100
- terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from rush global folder: ${e.message}`);
101
- }
102
- if (sdkContext.rushLibModule !== undefined) {
103
- // to track which scenario is active and how it got initialized.
104
- global.___rush___rushLibModuleFromRushGlobalFolder = sdkContext.rushLibModule;
105
- terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed from rush global folder`);
106
- }
107
- else {
108
- const installRunNodeModuleFolder = `${monorepoRoot}/common/temp/install-run/@microsoft+rush@${rushVersion}`;
109
- try {
110
- // First, try to load the version of "rush-lib" that was installed by install-run-rush.js
111
- terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`);
112
- sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
113
- }
114
- catch (e1) {
115
- let installAndRunRushStderrContent = '';
116
- try {
117
- const installAndRunRushJSPath = `${monorepoRoot}/common/scripts/install-run-rush.js`;
118
- terminal.writeLine('The Rush engine has not been installed yet. Invoking install-run-rush.js...');
119
- const installAndRunRushProcess = Executable.spawnSync('node', [installAndRunRushJSPath, '--help'], {
120
- stdio: 'pipe'
121
- });
122
- installAndRunRushStderrContent = installAndRunRushProcess.stderr;
123
- if (installAndRunRushProcess.status !== 0) {
124
- throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);
125
- }
126
- // Retry to load "rush-lib" after install-run-rush run
127
- terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`);
128
- sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
129
- }
130
- catch (e2) {
131
- // eslint-disable-next-line no-console
132
- console.error(`${installAndRunRushStderrContent}`);
133
- throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);
134
- }
135
- }
136
- if (sdkContext.rushLibModule !== undefined) {
137
- // to track which scenario is active and how it got initialized.
138
- global.___rush___rushLibModuleFromInstallAndRunRush = sdkContext.rushLibModule;
139
- terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed by install-run-rush`);
140
- }
141
- }
142
- }
143
- catch (e) {
144
- // no-catch
145
- errorMessage = e.message;
146
- }
147
- }
148
- if (sdkContext.rushLibModule === undefined) {
149
- // This error indicates that a project is trying to import "@rushstack/rush-sdk", but the Rush engine
150
- // instance cannot be found. If you are writing Jest tests for a Rush plugin, add "@microsoft/rush-lib"
151
- // to the devDependencies for your project.
152
- // eslint-disable-next-line no-console
153
- console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:
154
- ${errorMessage}
155
- `);
156
- process.exit(1);
157
- }
158
- // Based on TypeScript's __exportStar()
159
- for (const property in sdkContext.rushLibModule) {
160
- if (property !== 'default' && !exports.hasOwnProperty(property)) {
161
- const rushLibModuleForClosure = sdkContext.rushLibModule;
162
- // Based on TypeScript's __createBinding()
163
- Object.defineProperty(exports, property, {
164
- enumerable: true,
165
- get: function () {
166
- return rushLibModuleForClosure[property];
167
- }
168
- });
169
- }
170
- }
171
- /**
172
- * Used by the .js stubs for path-based imports of `@microsoft/rush-lib` internal APIs.
173
- */
174
- export function _rushSdk_loadInternalModule(srcImportPath) {
175
- if (!exports._RushInternals) {
176
- throw new Error(`Rush version ${exports.Rush.version} does not support internal API imports via rush-sdk`);
177
- }
178
- return exports._RushInternals.loadModule(srcImportPath);
179
- }
180
- //# sourceMappingURL=index.js.map