@rushstack/rush-sdk 5.61.3 → 5.62.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,11 +10,15 @@ The **@rushstack/rush-sdk** package acts as a lightweight proxy for accessing th
10
10
 
11
11
  2. When authoring unit tests for a Rush plugin, developers should add **@microsoft/rush-lib** to their **package.json** `devDependencies`. In this context, **@rushstack/rush-sdk** will resolve to that instance for testing purposes.
12
12
 
13
- 3. **(Not implemented yet)** For scripts and tools that are designed to be used in a Rush monorepo, in the future **@rushstack/rush-sdk** will automatically invoke **install-run-rush.js** and load the local installation. This ensures that tools load a compatible version of the Rush engine for the given branch. Once this is implemented, **@rushstack/rush-sdk** can replace **@microsoft/rush-lib** entirely as the official API interface, with the latter serving as the underlying implementation.
13
+ 3. For scripts and tools that are designed to be used in a Rush monorepo, in the future **@rushstack/rush-sdk** will automatically invoke **install-run-rush.js** and load the local installation. This ensures that tools load a compatible version of the Rush engine for the given branch. Once this is implemented, **@rushstack/rush-sdk** can replace **@microsoft/rush-lib** entirely as the official API interface, with the latter serving as the underlying implementation.
14
14
 
15
15
 
16
16
  The **@rushstack/rush-sdk** API declarations are identical to the corresponding version of **@microsoft/rush-lib**.
17
17
 
18
+ ## Debugging
19
+
20
+ Verbose logging can be turn on by set environment variable `RUSH_SDK_DEBUG` to `1`
21
+
18
22
 
19
23
  ## Links
20
24
 
@@ -791,7 +791,7 @@ declare interface ILocalBuildCacheJson extends IBaseBuildCacheJson {
791
791
 
792
792
  declare interface ILockStepVersionJson extends IVersionPolicyJson {
793
793
  version: string;
794
- nextBump: string;
794
+ nextBump?: string;
795
795
  mainProject?: string;
796
796
  }
797
797
 
@@ -1151,7 +1151,7 @@ export declare class LockStepVersionPolicy extends VersionPolicy {
1151
1151
  /**
1152
1152
  * The type of bump for next bump.
1153
1153
  */
1154
- get nextBump(): BumpType;
1154
+ get nextBump(): BumpType | undefined;
1155
1155
  /**
1156
1156
  * The main project for the version policy.
1157
1157
  *
@@ -1707,6 +1707,9 @@ export declare class RushConfiguration {
1707
1707
  static loadFromDefaultLocation(options?: ITryFindRushJsonLocationOptions): RushConfiguration;
1708
1708
  /**
1709
1709
  * Find the rush.json location and return the path, or undefined if a rush.json can't be found.
1710
+ *
1711
+ * @privateRemarks
1712
+ * Keep this in sync with `findRushJsonLocation` in `rush-sdk/src/index.ts`.
1710
1713
  */
1711
1714
  static tryFindRushJsonLocation(options?: ITryFindRushJsonLocationOptions): string | undefined;
1712
1715
  /**
@@ -2715,7 +2718,7 @@ export declare class VersionPolicyConfiguration {
2715
2718
  * @param versionPolicyName - version policy name
2716
2719
  * @param newVersion - new version
2717
2720
  */
2718
- update(versionPolicyName: string, newVersion: string): void;
2721
+ update(versionPolicyName: string, newVersion: string, shouldCommit?: boolean): void;
2719
2722
  private _loadFile;
2720
2723
  private _saveFile;
2721
2724
  }
package/lib/index.js CHANGED
@@ -25,9 +25,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  const path = __importStar(require("path"));
26
26
  const node_core_library_1 = require("@rushstack/node-core-library");
27
27
  const RUSH_LIB_NAME = '@microsoft/rush-lib';
28
+ const verboseEnabled = typeof process !== 'undefined' && process.env.RUSH_SDK_DEBUG === '1';
29
+ const terminal = new node_core_library_1.Terminal(new node_core_library_1.ConsoleTerminalProvider({
30
+ verboseEnabled
31
+ }));
28
32
  // SCENARIO 1: Rush's PluginManager has initialized "rush-sdk" with Rush's own instance of rush-lib.
29
33
  // The Rush host process will assign "global.___rush___rushLibModule" before loading the plugin.
30
- let rushLibModule = global.___rush___rushLibModule;
34
+ let rushLibModule = global.___rush___rushLibModule || global.___rush___rushLibModuleFromInstallAndRunRush;
35
+ let errorMessage = '';
31
36
  // SCENARIO 2: The project importing "rush-sdk" has installed its own instance of "rush-lib"
32
37
  // as a package.json dependency. For example, this is used by the Jest tests for Rush plugins.
33
38
  if (rushLibModule === undefined) {
@@ -43,22 +48,20 @@ if (rushLibModule === undefined) {
43
48
  (callerPackageJson.peerDependencies &&
44
49
  callerPackageJson.peerDependencies[RUSH_LIB_NAME] !== undefined)) {
45
50
  // Try to resolve rush-lib from the caller's folder
51
+ terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from caller package`);
46
52
  try {
47
- const rushLibModulePath = node_core_library_1.Import.resolveModule({
48
- modulePath: RUSH_LIB_NAME,
49
- baseFolderPath: callerPackageFolder
50
- });
51
- rushLibModule = require(rushLibModulePath);
53
+ rushLibModule = requireRushLibUnderFolderPath(callerPackageFolder);
52
54
  }
53
55
  catch (error) {
54
56
  // If we fail to resolve it, ignore the error
57
+ terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from caller package`);
55
58
  }
56
59
  // If two different libraries invoke `rush-sdk`, and one of them provides "rush-lib"
57
60
  // then the first version to be loaded wins. We do not support side-by-side instances of "rush-lib".
58
61
  if (rushLibModule !== undefined) {
59
- // TODO: When we implement Scenario 3, we should also add some diagnostic state
60
62
  // to track which scenario is active and how it got initialized.
61
63
  global.___rush___rushLibModule = rushLibModule;
64
+ terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from caller`);
62
65
  }
63
66
  }
64
67
  }
@@ -66,13 +69,62 @@ if (rushLibModule === undefined) {
66
69
  }
67
70
  // SCENARIO 3: A tool or script depends on "rush-sdk", and is meant to be used inside a monorepo folder.
68
71
  // In this case, we can use install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.
69
- //
70
- // NOT IMPLEMENTED YET
72
+ if (rushLibModule === undefined) {
73
+ try {
74
+ const rushJsonPath = tryFindRushJsonLocation(process.cwd());
75
+ if (!rushJsonPath) {
76
+ throw new Error('Unable to find rush.json in the current folder or its parent folders.\n' +
77
+ 'This tool is meant to be invoked from a working directory inside a Rush repository.');
78
+ }
79
+ const monorepoRoot = path.dirname(rushJsonPath);
80
+ const rushJson = node_core_library_1.JsonFile.load(rushJsonPath);
81
+ const { rushVersion } = rushJson;
82
+ const installRunNodeModuleFolder = path.join(monorepoRoot, `common/temp/install-run/@microsoft+rush@${rushVersion}`);
83
+ try {
84
+ // First, try to load the version of "rush-lib" that was installed by install-run-rush.js
85
+ terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`);
86
+ rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
87
+ }
88
+ catch (e) {
89
+ let installAndRunRushStderrContent = '';
90
+ try {
91
+ const installAndRunRushJSPath = path.join(monorepoRoot, 'common/scripts/install-run-rush.js');
92
+ terminal.writeLine('The Rush engine has not been installed yet. Invoking install-run-rush.js...');
93
+ const installAndRuhRushProcess = node_core_library_1.Executable.spawnSync('node', [installAndRunRushJSPath, '--help'], {
94
+ stdio: 'pipe'
95
+ });
96
+ installAndRunRushStderrContent = installAndRuhRushProcess.stderr;
97
+ if (installAndRuhRushProcess.status !== 0) {
98
+ throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);
99
+ }
100
+ // Retry to load "rush-lib" after install-run-rush run
101
+ terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`);
102
+ rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
103
+ }
104
+ catch (e) {
105
+ console.error(`${installAndRunRushStderrContent}`);
106
+ throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);
107
+ }
108
+ }
109
+ if (rushLibModule !== undefined) {
110
+ // to track which scenario is active and how it got initialized.
111
+ global.___rush___rushLibModuleFromInstallAndRunRush = rushLibModule;
112
+ terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed by install-run-rush`);
113
+ }
114
+ }
115
+ catch (e) {
116
+ // no-catch
117
+ errorMessage = e.message;
118
+ }
119
+ }
71
120
  if (rushLibModule === undefined) {
72
121
  // This error indicates that a project is trying to import "@rushstack/rush-sdk", but the Rush engine
73
122
  // instance cannot be found. If you are writing Jest tests for a Rush plugin, add "@microsoft/rush-lib"
74
123
  // to the devDependencies for your project.
75
- throw new Error('The "@rushstack/rush-sdk" package context has not been initialized.');
124
+ console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:
125
+ ${errorMessage}
126
+ `);
127
+ process.exit(1);
76
128
  }
77
129
  // Based on TypeScript's __exportStar()
78
130
  for (const property in rushLibModule) {
@@ -87,4 +139,36 @@ for (const property in rushLibModule) {
87
139
  });
88
140
  }
89
141
  }
142
+ /**
143
+ * Require `@microsoft/rush-lib` under the specified folder path.
144
+ */
145
+ function requireRushLibUnderFolderPath(folderPath) {
146
+ const rushLibModulePath = node_core_library_1.Import.resolveModule({
147
+ modulePath: RUSH_LIB_NAME,
148
+ baseFolderPath: folderPath
149
+ });
150
+ return require(rushLibModulePath);
151
+ }
152
+ /**
153
+ * Find the rush.json location and return the path, or undefined if a rush.json can't be found.
154
+ *
155
+ * @privateRemarks
156
+ * Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`.
157
+ */
158
+ function tryFindRushJsonLocation(startingFolder) {
159
+ let currentFolder = startingFolder;
160
+ // Look upwards at parent folders until we find a folder containing rush.json
161
+ for (let i = 0; i < 10; ++i) {
162
+ const rushJsonFilename = path.join(currentFolder, 'rush.json');
163
+ if (node_core_library_1.FileSystem.exists(rushJsonFilename)) {
164
+ return rushJsonFilename;
165
+ }
166
+ const parentFolder = path.dirname(currentFolder);
167
+ if (parentFolder === currentFolder) {
168
+ break;
169
+ }
170
+ currentFolder = parentFolder;
171
+ }
172
+ return undefined;
173
+ }
90
174
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,oEAAuF;AAEvF,MAAM,aAAa,GAAW,qBAAqB,CAAC;AAQpD,qGAAqG;AACrG,gGAAgG;AAChG,IAAI,aAAa,GAAkC,MAAM,CAAC,uBAAuB,CAAC;AAElF,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B;AACtB,IAAI,aAAa,KAAK,SAAS,EAAE;IAC/B,qGAAqG;IACrG,wGAAwG;IACxG,2CAA2C;IAC3C,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;CACxF;AAED,uCAAuC;AACvC,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE;IACpC,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;QAC/D,MAAM,uBAAuB,GAAsB,aAAa,CAAC;QAEjE,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;KACJ;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 { Import, IPackageJson, PackageJsonLookup } from '@rushstack/node-core-library';\n\nconst RUSH_LIB_NAME: string = '@microsoft/rush-lib';\n\ntype RushLibModuleType = Record<string, unknown>;\ndeclare const global: NodeJS.Global &\n typeof globalThis & {\n ___rush___rushLibModule?: RushLibModuleType;\n };\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.\nlet rushLibModule: RushLibModuleType | undefined = global.___rush___rushLibModule;\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 (rushLibModule === undefined) {\n const importingPath: string | undefined = module?.parent?.filename;\n if (importingPath !== undefined) {\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 try {\n const rushLibModulePath: string = Import.resolveModule({\n modulePath: RUSH_LIB_NAME,\n baseFolderPath: callerPackageFolder\n });\n\n rushLibModule = require(rushLibModulePath);\n } catch (error) {\n // If we fail to resolve it, ignore the error\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 (rushLibModule !== undefined) {\n // TODO: When we implement Scenario 3, we should also add some diagnostic state\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModule = rushLibModule;\n }\n }\n }\n }\n}\n\n// SCENARIO 3: A tool or script depends on \"rush-sdk\", and is meant to be used inside a monorepo folder.\n// In this case, we can use install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.\n//\n// NOT IMPLEMENTED YET\nif (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 throw new Error('The \"@rushstack/rush-sdk\" package context has not been initialized.');\n}\n\n// Based on TypeScript's __exportStar()\nfor (const property in rushLibModule) {\n if (property !== 'default' && !exports.hasOwnProperty(property)) {\n const rushLibModuleForClosure: RushLibModuleType = 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"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA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uCAAuC;AACvC,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE;IACpC,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;QAC/D,MAAM,uBAAuB,GAAsB,aAAa,CAAC;QAEjE,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;KACJ;CACF;AAED;;GAEG;AACH,SAAS,6BAA6B,CAAC,UAAkB;IACvD,MAAM,iBAAiB,GAAW,0BAAM,CAAC,aAAa,CAAC;QACrD,UAAU,EAAE,aAAa;QACzB,cAAc,EAAE,UAAU;KAC3B,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACpC,CAAC;AAED;;;;;GAKG;AACH,SAAS,uBAAuB,CAAC,cAAsB;IACrD,IAAI,aAAa,GAAW,cAAc,CAAC;IAE3C,6EAA6E;IAC7E,KAAK,IAAI,CAAC,GAAW,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE;QACnC,MAAM,gBAAgB,GAAW,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;QAEvE,IAAI,8BAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;YACvC,OAAO,gBAAgB,CAAC;SACzB;QAED,MAAM,YAAY,GAAW,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACzD,IAAI,YAAY,KAAK,aAAa,EAAE;YAClC,MAAM;SACP;QAED,aAAa,GAAG,YAAY,CAAC;KAC9B;IAED,OAAO,SAAS,CAAC;AACnB,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 {\n JsonFile,\n JsonObject,\n Import,\n IPackageJson,\n PackageJsonLookup,\n Executable,\n FileSystem,\n Terminal,\n ConsoleTerminalProvider\n} from '@rushstack/node-core-library';\nimport type { SpawnSyncReturns } from 'child_process';\n\nconst RUSH_LIB_NAME: string = '@microsoft/rush-lib';\n\nconst verboseEnabled: boolean = typeof process !== 'undefined' && process.env.RUSH_SDK_DEBUG === '1';\nconst terminal: Terminal = new Terminal(\n new ConsoleTerminalProvider({\n verboseEnabled\n })\n);\n\ntype RushLibModuleType = Record<string, unknown>;\ndeclare const global: NodeJS.Global &\n typeof globalThis & {\n ___rush___rushLibModule?: RushLibModuleType;\n ___rush___rushLibModuleFromInstallAndRunRush?: RushLibModuleType;\n };\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.\nlet rushLibModule: RushLibModuleType | undefined =\n global.___rush___rushLibModule || global.___rush___rushLibModuleFromInstallAndRunRush;\nlet errorMessage: string = '';\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 (rushLibModule === undefined) {\n const importingPath: string | undefined = module?.parent?.filename;\n if (importingPath !== undefined) {\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 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 (rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModule = rushLibModule;\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from caller`);\n }\n }\n }\n }\n}\n\n// SCENARIO 3: A tool or script depends on \"rush-sdk\", and is meant to be used inside a monorepo folder.\n// In this case, we can use install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.\nif (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 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 terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`);\n rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\n } catch (e) {\n let installAndRunRushStderrContent: string = '';\n try {\n const installAndRunRushJSPath: string = path.join(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 installAndRuhRushProcess: SpawnSyncReturns<string> = Executable.spawnSync(\n 'node',\n [installAndRunRushJSPath, '--help'],\n {\n stdio: 'pipe'\n }\n );\n\n installAndRunRushStderrContent = installAndRuhRushProcess.stderr;\n if (installAndRuhRushProcess.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(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`);\n rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\n } catch (e) {\n console.error(`${installAndRunRushStderrContent}`);\n throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);\n }\n }\n\n if (rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModuleFromInstallAndRunRush = rushLibModule;\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed by install-run-rush`);\n }\n } catch (e) {\n // no-catch\n errorMessage = (e as Error).message;\n }\n}\n\nif (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 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 rushLibModule) {\n if (property !== 'default' && !exports.hasOwnProperty(property)) {\n const rushLibModuleForClosure: RushLibModuleType = 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 * Require `@microsoft/rush-lib` under the specified folder path.\n */\nfunction 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\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 */\nfunction 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/rush-sdk",
3
- "version": "5.61.3",
3
+ "version": "5.62.1",
4
4
  "description": "An API for interacting with the Rush engine",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,7 @@
17
17
  "tapable": "2.2.1"
18
18
  },
19
19
  "devDependencies": {
20
- "@microsoft/rush-lib": "5.61.3",
20
+ "@microsoft/rush-lib": "5.62.1",
21
21
  "@rushstack/eslint-config": "2.5.1",
22
22
  "@rushstack/heft": "0.44.2",
23
23
  "@rushstack/heft-node-rig": "1.7.1",