@rushstack/rush-sdk 5.61.4 → 5.62.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.
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
  /**
@@ -2436,6 +2439,11 @@ export declare class RushConstants {
2436
2439
  * Build cache configuration file.
2437
2440
  */
2438
2441
  static readonly buildCacheFilename: string;
2442
+ /**
2443
+ * Build cache version number, incremented when the logic to create cache entries changes.
2444
+ * Changing this ensures that cache entries generated by an old version will no longer register as a cache hit.
2445
+ */
2446
+ static readonly buildCacheVersion: number;
2439
2447
  /**
2440
2448
  * Per-project configuration filename.
2441
2449
  */
@@ -2715,7 +2723,7 @@ export declare class VersionPolicyConfiguration {
2715
2723
  * @param versionPolicyName - version policy name
2716
2724
  * @param newVersion - new version
2717
2725
  */
2718
- update(versionPolicyName: string, newVersion: string): void;
2726
+ update(versionPolicyName: string, newVersion: string, shouldCommit?: boolean): void;
2719
2727
  private _loadFile;
2720
2728
  private _saveFile;
2721
2729
  }
package/lib/index.js CHANGED
@@ -25,17 +25,34 @@ 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
+ }));
32
+ 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
+ }
28
44
  // SCENARIO 1: Rush's PluginManager has initialized "rush-sdk" with Rush's own instance of rush-lib.
29
45
  // The Rush host process will assign "global.___rush___rushLibModule" before loading the plugin.
30
- let rushLibModule = global.___rush___rushLibModule;
46
+ let rushLibModule = global.___rush___rushLibModule || global.___rush___rushLibModuleFromInstallAndRunRush;
47
+ let errorMessage = '';
31
48
  // SCENARIO 2: The project importing "rush-sdk" has installed its own instance of "rush-lib"
32
49
  // as a package.json dependency. For example, this is used by the Jest tests for Rush plugins.
33
50
  if (rushLibModule === undefined) {
34
51
  const importingPath = (_a = module === null || module === void 0 ? void 0 : module.parent) === null || _a === void 0 ? void 0 : _a.filename;
35
- if (importingPath !== undefined) {
52
+ if (importingPath) {
36
53
  const callerPackageFolder = node_core_library_1.PackageJsonLookup.instance.tryGetPackageFolderFor(importingPath);
37
54
  if (callerPackageFolder !== undefined) {
38
- const callerPackageJson = require(path.join(callerPackageFolder, 'package.json'));
55
+ const callerPackageJson = _require(path.join(callerPackageFolder, 'package.json'));
39
56
  // Does the caller properly declare a dependency on rush-lib?
40
57
  if ((callerPackageJson.dependencies && callerPackageJson.dependencies[RUSH_LIB_NAME] !== undefined) ||
41
58
  (callerPackageJson.devDependencies &&
@@ -43,22 +60,20 @@ if (rushLibModule === undefined) {
43
60
  (callerPackageJson.peerDependencies &&
44
61
  callerPackageJson.peerDependencies[RUSH_LIB_NAME] !== undefined)) {
45
62
  // Try to resolve rush-lib from the caller's folder
63
+ terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from caller package`);
46
64
  try {
47
- const rushLibModulePath = node_core_library_1.Import.resolveModule({
48
- modulePath: RUSH_LIB_NAME,
49
- baseFolderPath: callerPackageFolder
50
- });
51
- rushLibModule = require(rushLibModulePath);
65
+ rushLibModule = requireRushLibUnderFolderPath(callerPackageFolder);
52
66
  }
53
67
  catch (error) {
54
68
  // If we fail to resolve it, ignore the error
69
+ terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from caller package`);
55
70
  }
56
71
  // If two different libraries invoke `rush-sdk`, and one of them provides "rush-lib"
57
72
  // then the first version to be loaded wins. We do not support side-by-side instances of "rush-lib".
58
73
  if (rushLibModule !== undefined) {
59
- // TODO: When we implement Scenario 3, we should also add some diagnostic state
60
74
  // to track which scenario is active and how it got initialized.
61
75
  global.___rush___rushLibModule = rushLibModule;
76
+ terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from caller`);
62
77
  }
63
78
  }
64
79
  }
@@ -66,13 +81,62 @@ if (rushLibModule === undefined) {
66
81
  }
67
82
  // SCENARIO 3: A tool or script depends on "rush-sdk", and is meant to be used inside a monorepo folder.
68
83
  // 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
84
+ if (rushLibModule === undefined) {
85
+ try {
86
+ const rushJsonPath = tryFindRushJsonLocation(process.cwd());
87
+ if (!rushJsonPath) {
88
+ throw new Error('Unable to find rush.json in the current folder or its parent folders.\n' +
89
+ 'This tool is meant to be invoked from a working directory inside a Rush repository.');
90
+ }
91
+ const monorepoRoot = path.dirname(rushJsonPath);
92
+ const rushJson = node_core_library_1.JsonFile.load(rushJsonPath);
93
+ const { rushVersion } = rushJson;
94
+ const installRunNodeModuleFolder = path.join(monorepoRoot, `common/temp/install-run/@microsoft+rush@${rushVersion}`);
95
+ try {
96
+ // First, try to load the version of "rush-lib" that was installed by install-run-rush.js
97
+ terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`);
98
+ rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
99
+ }
100
+ catch (e) {
101
+ let installAndRunRushStderrContent = '';
102
+ try {
103
+ const installAndRunRushJSPath = path.join(monorepoRoot, 'common/scripts/install-run-rush.js');
104
+ terminal.writeLine('The Rush engine has not been installed yet. Invoking install-run-rush.js...');
105
+ const installAndRuhRushProcess = node_core_library_1.Executable.spawnSync('node', [installAndRunRushJSPath, '--help'], {
106
+ stdio: 'pipe'
107
+ });
108
+ installAndRunRushStderrContent = installAndRuhRushProcess.stderr;
109
+ if (installAndRuhRushProcess.status !== 0) {
110
+ throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);
111
+ }
112
+ // Retry to load "rush-lib" after install-run-rush run
113
+ terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`);
114
+ rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
115
+ }
116
+ catch (e) {
117
+ console.error(`${installAndRunRushStderrContent}`);
118
+ throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);
119
+ }
120
+ }
121
+ if (rushLibModule !== undefined) {
122
+ // to track which scenario is active and how it got initialized.
123
+ global.___rush___rushLibModuleFromInstallAndRunRush = rushLibModule;
124
+ terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed by install-run-rush`);
125
+ }
126
+ }
127
+ catch (e) {
128
+ // no-catch
129
+ errorMessage = e.message;
130
+ }
131
+ }
71
132
  if (rushLibModule === undefined) {
72
133
  // This error indicates that a project is trying to import "@rushstack/rush-sdk", but the Rush engine
73
134
  // instance cannot be found. If you are writing Jest tests for a Rush plugin, add "@microsoft/rush-lib"
74
135
  // to the devDependencies for your project.
75
- throw new Error('The "@rushstack/rush-sdk" package context has not been initialized.');
136
+ console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:
137
+ ${errorMessage}
138
+ `);
139
+ process.exit(1);
76
140
  }
77
141
  // Based on TypeScript's __exportStar()
78
142
  for (const property in rushLibModule) {
@@ -87,4 +151,36 @@ for (const property in rushLibModule) {
87
151
  });
88
152
  }
89
153
  }
154
+ /**
155
+ * Require `@microsoft/rush-lib` under the specified folder path.
156
+ */
157
+ function requireRushLibUnderFolderPath(folderPath) {
158
+ const rushLibModulePath = node_core_library_1.Import.resolveModule({
159
+ modulePath: RUSH_LIB_NAME,
160
+ baseFolderPath: folderPath
161
+ });
162
+ return _require(rushLibModulePath);
163
+ }
164
+ /**
165
+ * Find the rush.json location and return the path, or undefined if a rush.json can't be found.
166
+ *
167
+ * @privateRemarks
168
+ * Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`.
169
+ */
170
+ function tryFindRushJsonLocation(startingFolder) {
171
+ let currentFolder = startingFolder;
172
+ // Look upwards at parent folders until we find a folder containing rush.json
173
+ for (let i = 0; i < 10; ++i) {
174
+ const rushJsonFilename = path.join(currentFolder, 'rush.json');
175
+ if (node_core_library_1.FileSystem.exists(rushJsonFilename)) {
176
+ return rushJsonFilename;
177
+ }
178
+ const parentFolder = path.dirname(currentFolder);
179
+ if (parentFolder === currentFolder) {
180
+ break;
181
+ }
182
+ currentFolder = parentFolder;
183
+ }
184
+ return undefined;
185
+ }
90
186
  //# 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,6FAA6F;AAC7F,+FAA+F;AAC/F,IAAI,aAAa,KAAK,SAAS,EAAE;IAC/B,MAAM,aAAa,GAAuB,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,0CAAE,QAAQ,CAAC;IACnE,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,MAAM,mBAAmB,GACvB,qCAAiB,CAAC,QAAQ,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC;QAEnE,IAAI,mBAAmB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uB,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,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,oEAUsC;AAGtC,MAAM,aAAa,GAAW,qBAAqB,CAAC;AAEpD,MAAM,cAAc,GAAY,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,GAAG,CAAC;AACrG,MAAM,QAAQ,GAAa,IAAI,4BAAQ,CACrC,IAAI,2CAAuB,CAAC;IAC1B,cAA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AI,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,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AACrC,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\nfunction _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// 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 | 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 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(\n `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`\n );\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/lib/index.mjs ADDED
@@ -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
+ var _a;
4
+ import * as path from 'path';
5
+ import { JsonFile, Import, PackageJsonLookup, Executable, FileSystem, Terminal, ConsoleTerminalProvider } from '@rushstack/node-core-library';
6
+ const RUSH_LIB_NAME = '@microsoft/rush-lib';
7
+ const verboseEnabled = typeof process !== 'undefined' && process.env.RUSH_SDK_DEBUG === '1';
8
+ const terminal = new Terminal(new ConsoleTerminalProvider({
9
+ verboseEnabled
10
+ }));
11
+ function _require(moduleName) {
12
+ if (typeof __non_webpack_require__ === 'function') {
13
+ // If this library has been bundled with Webpack, we need to call the real `require` function
14
+ // that doesn't get turned into a `__webpack_require__` statement.
15
+ // `__non_webpack_require__` is a Webpack macro that gets turned into a `require` statement
16
+ // during bundling.
17
+ return __non_webpack_require__(moduleName);
18
+ }
19
+ else {
20
+ return require(moduleName);
21
+ }
22
+ }
23
+ // SCENARIO 1: Rush's PluginManager has initialized "rush-sdk" with Rush's own instance of rush-lib.
24
+ // The Rush host process will assign "global.___rush___rushLibModule" before loading the plugin.
25
+ let rushLibModule = global.___rush___rushLibModule || global.___rush___rushLibModuleFromInstallAndRunRush;
26
+ let errorMessage = '';
27
+ // SCENARIO 2: The project importing "rush-sdk" has installed its own instance of "rush-lib"
28
+ // as a package.json dependency. For example, this is used by the Jest tests for Rush plugins.
29
+ if (rushLibModule === undefined) {
30
+ const importingPath = (_a = module === null || module === void 0 ? void 0 : module.parent) === null || _a === void 0 ? void 0 : _a.filename;
31
+ if (importingPath) {
32
+ const callerPackageFolder = PackageJsonLookup.instance.tryGetPackageFolderFor(importingPath);
33
+ if (callerPackageFolder !== undefined) {
34
+ const callerPackageJson = _require(path.join(callerPackageFolder, 'package.json'));
35
+ // Does the caller properly declare a dependency on rush-lib?
36
+ if ((callerPackageJson.dependencies && callerPackageJson.dependencies[RUSH_LIB_NAME] !== undefined) ||
37
+ (callerPackageJson.devDependencies &&
38
+ callerPackageJson.devDependencies[RUSH_LIB_NAME] !== undefined) ||
39
+ (callerPackageJson.peerDependencies &&
40
+ callerPackageJson.peerDependencies[RUSH_LIB_NAME] !== undefined)) {
41
+ // Try to resolve rush-lib from the caller's folder
42
+ terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from caller package`);
43
+ try {
44
+ rushLibModule = requireRushLibUnderFolderPath(callerPackageFolder);
45
+ }
46
+ catch (error) {
47
+ // If we fail to resolve it, ignore the error
48
+ terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from caller package`);
49
+ }
50
+ // If two different libraries invoke `rush-sdk`, and one of them provides "rush-lib"
51
+ // then the first version to be loaded wins. We do not support side-by-side instances of "rush-lib".
52
+ if (rushLibModule !== undefined) {
53
+ // to track which scenario is active and how it got initialized.
54
+ global.___rush___rushLibModule = rushLibModule;
55
+ terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from caller`);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ // SCENARIO 3: A tool or script depends on "rush-sdk", and is meant to be used inside a monorepo folder.
62
+ // In this case, we can use install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.
63
+ if (rushLibModule === undefined) {
64
+ try {
65
+ const rushJsonPath = tryFindRushJsonLocation(process.cwd());
66
+ if (!rushJsonPath) {
67
+ throw new Error('Unable to find rush.json in the current folder or its parent folders.\n' +
68
+ 'This tool is meant to be invoked from a working directory inside a Rush repository.');
69
+ }
70
+ const monorepoRoot = path.dirname(rushJsonPath);
71
+ const rushJson = JsonFile.load(rushJsonPath);
72
+ const { rushVersion } = rushJson;
73
+ const installRunNodeModuleFolder = path.join(monorepoRoot, `common/temp/install-run/@microsoft+rush@${rushVersion}`);
74
+ try {
75
+ // First, try to load the version of "rush-lib" that was installed by install-run-rush.js
76
+ terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`);
77
+ rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
78
+ }
79
+ catch (e) {
80
+ let installAndRunRushStderrContent = '';
81
+ try {
82
+ const installAndRunRushJSPath = path.join(monorepoRoot, 'common/scripts/install-run-rush.js');
83
+ terminal.writeLine('The Rush engine has not been installed yet. Invoking install-run-rush.js...');
84
+ const installAndRuhRushProcess = Executable.spawnSync('node', [installAndRunRushJSPath, '--help'], {
85
+ stdio: 'pipe'
86
+ });
87
+ installAndRunRushStderrContent = installAndRuhRushProcess.stderr;
88
+ if (installAndRuhRushProcess.status !== 0) {
89
+ throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);
90
+ }
91
+ // Retry to load "rush-lib" after install-run-rush run
92
+ terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`);
93
+ rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
94
+ }
95
+ catch (e) {
96
+ console.error(`${installAndRunRushStderrContent}`);
97
+ throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);
98
+ }
99
+ }
100
+ if (rushLibModule !== undefined) {
101
+ // to track which scenario is active and how it got initialized.
102
+ global.___rush___rushLibModuleFromInstallAndRunRush = rushLibModule;
103
+ terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed by install-run-rush`);
104
+ }
105
+ }
106
+ catch (e) {
107
+ // no-catch
108
+ errorMessage = e.message;
109
+ }
110
+ }
111
+ if (rushLibModule === undefined) {
112
+ // This error indicates that a project is trying to import "@rushstack/rush-sdk", but the Rush engine
113
+ // instance cannot be found. If you are writing Jest tests for a Rush plugin, add "@microsoft/rush-lib"
114
+ // to the devDependencies for your project.
115
+ console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:
116
+ ${errorMessage}
117
+ `);
118
+ process.exit(1);
119
+ }
120
+ // Based on TypeScript's __exportStar()
121
+ for (const property in rushLibModule) {
122
+ if (property !== 'default' && !exports.hasOwnProperty(property)) {
123
+ const rushLibModuleForClosure = rushLibModule;
124
+ // Based on TypeScript's __createBinding()
125
+ Object.defineProperty(exports, property, {
126
+ enumerable: true,
127
+ get: function () {
128
+ return rushLibModuleForClosure[property];
129
+ }
130
+ });
131
+ }
132
+ }
133
+ /**
134
+ * Require `@microsoft/rush-lib` under the specified folder path.
135
+ */
136
+ function requireRushLibUnderFolderPath(folderPath) {
137
+ const rushLibModulePath = Import.resolveModule({
138
+ modulePath: RUSH_LIB_NAME,
139
+ baseFolderPath: folderPath
140
+ });
141
+ return _require(rushLibModulePath);
142
+ }
143
+ /**
144
+ * Find the rush.json location and return the path, or undefined if a rush.json can't be found.
145
+ *
146
+ * @privateRemarks
147
+ * Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`.
148
+ */
149
+ function tryFindRushJsonLocation(startingFolder) {
150
+ let currentFolder = startingFolder;
151
+ // Look upwards at parent folders until we find a folder containing rush.json
152
+ for (let i = 0; i < 10; ++i) {
153
+ const rushJsonFilename = path.join(currentFolder, 'rush.json');
154
+ if (FileSystem.exists(rushJsonFilename)) {
155
+ return rushJsonFilename;
156
+ }
157
+ const parentFolder = path.dirname(currentFolder);
158
+ if (parentFolder === currentFolder) {
159
+ break;
160
+ }
161
+ currentFolder = parentFolder;
162
+ }
163
+ return undefined;
164
+ }
165
+ //# 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,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,QAAQ,EAER,MAAM,EAEN,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,QAAQ,EACR,uBAAuB,EACxB,MAAM,8BAA8B,CAAC;AAGtC,MAAM,aAAa,GAAW,qBAAqB,CAAC;AAEpD,MAAM,cAAc,GAAY,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,GAAG,CAAC;AACrG,MAAM,QAAQ,GAAa,IAAI,QAAQ,CACrC,IAAI,uBAAuB,CAAC;IAC1B,cAAc;CACf,CAAC,CACH,CAAC;AASF,SAAS,QAAQ,CAAU,UAAkB;IAC3C,IAAI,OAAO,uBAAuB,KAAK,UAAU,EAAE;QACjD,6FAA6F;QAC7F,kEAAkE;QAClE,2FAA2F;QAC3F,mBAAmB;QACnB,OAAO,uBAAuB,CAAC,UAAU,CAAC,CAAC;KAC5C;SAAM;QACL,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;KAC5B;AACH,CAAC;AAED,qGAAqG;AACrG,gGAAgG;AAChG,IAAI,aAAa,GACf,MAAM,CAAC,uBAAuB,IAAI,MAAM,CAAC,4CAA4C,CAAC;AACxF,IAAI,YAAY,GAAW,EAAE,CAAC;AAE9B,6FAA6F;AAC7F,+FAA+F;AAC/F,IAAI,aAAa,KAAK,SAAS,EAAE;IAC/B,MAAM,aAAa,GAA8B,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,0CAAE,QAAQ,CAAC;IAC1E,IAAI,aAAa,EAAE;QACjB,MAAM,mBAAmB,GACvB,iBAAiB,CAAC,QAAQ,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC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EAAE,EAAE,EAAE,CAAC,EAAE;QACnC,MAAM,gBAAgB,GAAW,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;QAEvE,IAAI,UAAU,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\nfunction _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// 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 | 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 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(\n `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`\n );\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.4",
3
+ "version": "5.62.2",
4
4
  "description": "An API for interacting with the Rush engine",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,6 +9,7 @@
9
9
  },
10
10
  "homepage": "https://rushjs.io",
11
11
  "main": "lib/index.js",
12
+ "module": "lib/index.mjs",
12
13
  "typings": "dist/rush-lib.d.ts",
13
14
  "license": "MIT",
14
15
  "dependencies": {
@@ -17,13 +18,13 @@
17
18
  "tapable": "2.2.1"
18
19
  },
19
20
  "devDependencies": {
20
- "@microsoft/rush-lib": "5.61.4",
21
+ "@microsoft/rush-lib": "5.62.2",
21
22
  "@rushstack/eslint-config": "2.5.1",
22
23
  "@rushstack/heft": "0.44.2",
23
24
  "@rushstack/heft-node-rig": "1.7.1",
24
25
  "@types/heft-jest": "1.0.1",
25
- "@types/node": "12.20.24",
26
- "@types/semver": "7.3.5"
26
+ "@types/semver": "7.3.5",
27
+ "@types/webpack-env": "1.13.0"
27
28
  },
28
29
  "scripts": {
29
30
  "build": "heft build --clean",