@rushstack/rush-sdk 5.109.2 → 5.110.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,24 +1,24 @@
1
- @rushstack/rush-sdk
2
-
3
- Copyright (c) Microsoft Corporation. All rights reserved.
4
-
5
- MIT License
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining
8
- a copy of this software and associated documentation files (the
9
- "Software"), to deal in the Software without restriction, including
10
- without limitation the rights to use, copy, modify, merge, publish,
11
- distribute, sublicense, and/or sell copies of the Software, and to
12
- permit persons to whom the Software is furnished to do so, subject to
13
- the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be
16
- included in all copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1
+ @rushstack/rush-sdk
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
24
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,159 +1,159 @@
1
- ## @rushstack/rush-sdk
2
-
3
- This is a companion package for the Rush tool. See the [@microsoft/rush](https://www.npmjs.com/package/@microsoft/rush) package for details.
4
-
5
- ⚠ **_THIS PACKAGE IS EXPERIMENTAL_** ⚠
6
-
7
- The **@rushstack/rush-sdk** package acts as a lightweight proxy for accessing the APIs of the **@microsoft/rush-lib** engine. It is intended to support five different use cases:
8
-
9
- 1. **Rush plugins:** Rush plugins should import from **@rushstack/rush-sdk** instead of **@microsoft/rush-lib**. This gives plugins full access to Rush APIs while avoiding a redundant installation of those packages. At runtime, the APIs will be bound to the correct `rushVersion` from **rush.json**, and guaranteed to be the same **@microsoft/rush-lib** module instance as the plugin host.
10
-
11
- 2. **Unit tests:** When authoring unit tests (for a Rush plugin, for example), developers should add **@microsoft/rush-lib** to their **package.json** `devDependencies` and add **@rushstack/rush-sdk** to the regular `dependencies`. In this context, **@rushstack/rush-sdk** will resolve to the locally installed instance for testing purposes.
12
-
13
- 3. **Rush subprocesses:** For tools within a monorepo that import **@rushstack/rush-sdk** during their build process, child processes will inherit the installation of Rush that invoked them. This is communicated using the `_RUSH_LIB_PATH` environment variable.
14
-
15
- 4. **Monorepo tools:** For scripts and tools that are designed to be used in a Rush monorepo, **@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.
16
-
17
- 5. **Advanced scenarios:** The secondary `@rushstack/rush-sdk/loader` entry point can be imported by tools that need to explicitly control where **@microsoft/rush-lib** gets loaded from. This API also allows monitoring installation and canceling the operation. This API is used by the Rush Stack VS Code extension, for example.
18
-
19
- The **@rushstack/rush-sdk** API declarations are identical to the corresponding version of **@microsoft/rush-lib**.
20
-
21
- ## Basic usage
22
-
23
- Here's an example of basic usage that works with cases 1-4 above:
24
-
25
- ```ts
26
- // CommonJS notation:
27
- const { RushConfiguration } = require('@rushstack/rush-sdk');
28
-
29
- const config = RushConfiguration.loadFromDefaultLocation();
30
- console.log(config.commonFolder);
31
- ```
32
-
33
- ```ts
34
- // TypeScript notation:
35
- import { RushConfiguration } from '@rushstack/rush-sdk';
36
-
37
- const config = RushConfiguration.loadFromDefaultLocation();
38
- console.log(config.commonFolder);
39
- ```
40
-
41
- ## Loader API
42
-
43
- Here's a basic example of how to manually load **@rushstack/rush-sdk** and monitor installation progress:
44
-
45
- ```ts
46
- import { RushSdkLoader, ISdkCallbackEvent } from '@rushstack/rush-sdk/loader';
47
-
48
- if (!RushSdkLoader.isLoaded) {
49
- await RushSdkLoader.loadAsync({
50
- // the search for rush.json starts here:
51
- rushJsonSearchFolder: "path/to/my-repo/apps/my-app",
52
-
53
- onNotifyEvent: (event: ISdkCallbackEvent) => {
54
- if (event.logMessage) {
55
- // Your tool can show progress about the loading:
56
- if (event.logMessage.kind === 'info') {
57
- console.log(event.logMessage.text);
58
- }
59
- }
60
- }
61
- });
62
- }
63
-
64
- // Any subsequent attempts to call require() will return the same instance
65
- // that was loaded above.
66
- const rushSdk = require('@rushstack/rush-sdk');
67
- const config = rushSdk.RushConfiguration.loadFromDefaultLocation();
68
- ```
69
-
70
- Here's a more elaborate example illustrating other API features:
71
-
72
- ```ts
73
- import { RushSdkLoader, ISdkCallbackEvent } from '@rushstack/rush-sdk/loader';
74
-
75
- // Use an AbortController to cancel the operation after a certain time period
76
- const abortController = new AbortController();
77
- setTimeout(() => {
78
- abortController.abort();
79
- }, 1000);
80
-
81
- if (!RushSdkLoader.isLoaded) {
82
- await RushSdkLoader.loadAsync({
83
- // the search for rush.json starts here:
84
- rushJsonSearchFolder: "path/to/my-repo/apps/my-app",
85
-
86
- abortSignal: abortController.signal,
87
-
88
- onNotifyEvent: (event: ISdkCallbackEvent) => {
89
- if (event.logMessage) {
90
- // Your tool can show progress about the loading:
91
- if (event.logMessage.kind === 'info') {
92
- console.log(event.logMessage.text);
93
- }
94
- }
95
-
96
- if (event.progressPercent !== undefined) {
97
- // If installation takes a long time, your tool can display a progress bar
98
- displayYourProgressBar(event.progressPercent);
99
- }
100
- }
101
- });
102
- }
103
-
104
- // Any subsequent attempts to call require() will return the same instance
105
- // that was loaded above.
106
- const rushSdk = require('@rushstack/rush-sdk');
107
- const config = rushSdk.RushConfiguration.loadFromDefaultLocation();
108
- ```
109
-
110
-
111
- ## Importing internal APIs
112
-
113
- Backwards compatibility is only guaranteed for the APIs marked as `@public` in the official `rush-lib.d.ts` entry point.
114
- However, sometimes it is expedient for a script to import internal modules from `@microsoft/rush-lib` to access
115
- unofficial APIs. This practice faces a technical challenge that `@microsoft/rush-lib` is bundled using Webpack.
116
- The `@rushstack/rush-sdk` package provides stub files that import the corresponding internal module from the
117
- Webpack bundle, via the `@rushstack/webpack-deep-imports-plugin` mechanism.
118
-
119
- > **WARNING:** If the loaded `rush-lib` package has a different version from `rush-sdk`, there is
120
- > no guarantee that the corresponding path will exist or have the same type signature.
121
- > Access internal APIs at your own risk. If you find an internal API to be useful, we recommend
122
- > that you create a GitHub issue proposing to make it public.
123
-
124
- Example 1: Conventional import of a public API:
125
-
126
- ```ts
127
- // THIS IS THE RECOMMENDED PRACTICE:
128
- import { RushConfiguration } from '@rushstack/rush-sdk';
129
- const config = RushConfiguration.loadFromDefaultLocation();
130
- console.log(config.commonFolder);
131
- ```
132
-
133
- Example 2: How to import an internal API:
134
-
135
- ```ts
136
- // WARNING: INTERNAL APIS MAY CHANGE AT ANY TIME -- USE THIS AT YOUR OWN RISK:
137
-
138
- // Important: Since we're calling an internal API, we need to use the unbundled .d.ts files
139
- // instead of the normal .d.ts rollup, otherwise TypeScript will complain about a type mismatch.
140
- import { RushConfiguration } from '@rushstack/rush-sdk/lib/index';
141
- const config = RushConfiguration.loadFromDefaultLocation();
142
- console.log(config.commonFolder);
143
-
144
- // Load an internal module from the Webpack bundle using a path-based import of a stub file:
145
- import { GitEmailPolicy } from '@rushstack/rush-sdk/lib/logic/policy/GitEmailPolicy';
146
- console.log(GitEmailPolicy.getEmailExampleLines(config));
147
- ```
148
-
149
- ## Debugging
150
-
151
- Verbose logging can be enabled by setting environment variable `RUSH_SDK_DEBUG=1`.
152
-
153
- ## Links
154
-
155
- - [CHANGELOG.md](https://github.com/microsoft/rushstack/blob/main/apps/rush/CHANGELOG.md) - Find
156
- out what's new in the latest version
157
- - [API Reference](https://api.rushstack.io/pages/rush-lib/)
158
-
159
- Rush is part of the [Rush Stack](https://rushstack.io/) family of projects.
1
+ ## @rushstack/rush-sdk
2
+
3
+ This is a companion package for the Rush tool. See the [@microsoft/rush](https://www.npmjs.com/package/@microsoft/rush) package for details.
4
+
5
+ ⚠ **_THIS PACKAGE IS EXPERIMENTAL_** ⚠
6
+
7
+ The **@rushstack/rush-sdk** package acts as a lightweight proxy for accessing the APIs of the **@microsoft/rush-lib** engine. It is intended to support five different use cases:
8
+
9
+ 1. **Rush plugins:** Rush plugins should import from **@rushstack/rush-sdk** instead of **@microsoft/rush-lib**. This gives plugins full access to Rush APIs while avoiding a redundant installation of those packages. At runtime, the APIs will be bound to the correct `rushVersion` from **rush.json**, and guaranteed to be the same **@microsoft/rush-lib** module instance as the plugin host.
10
+
11
+ 2. **Unit tests:** When authoring unit tests (for a Rush plugin, for example), developers should add **@microsoft/rush-lib** to their **package.json** `devDependencies` and add **@rushstack/rush-sdk** to the regular `dependencies`. In this context, **@rushstack/rush-sdk** will resolve to the locally installed instance for testing purposes.
12
+
13
+ 3. **Rush subprocesses:** For tools within a monorepo that import **@rushstack/rush-sdk** during their build process, child processes will inherit the installation of Rush that invoked them. This is communicated using the `_RUSH_LIB_PATH` environment variable.
14
+
15
+ 4. **Monorepo tools:** For scripts and tools that are designed to be used in a Rush monorepo, **@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.
16
+
17
+ 5. **Advanced scenarios:** The secondary `@rushstack/rush-sdk/loader` entry point can be imported by tools that need to explicitly control where **@microsoft/rush-lib** gets loaded from. This API also allows monitoring installation and canceling the operation. This API is used by the Rush Stack VS Code extension, for example.
18
+
19
+ The **@rushstack/rush-sdk** API declarations are identical to the corresponding version of **@microsoft/rush-lib**.
20
+
21
+ ## Basic usage
22
+
23
+ Here's an example of basic usage that works with cases 1-4 above:
24
+
25
+ ```ts
26
+ // CommonJS notation:
27
+ const { RushConfiguration } = require('@rushstack/rush-sdk');
28
+
29
+ const config = RushConfiguration.loadFromDefaultLocation();
30
+ console.log(config.commonFolder);
31
+ ```
32
+
33
+ ```ts
34
+ // TypeScript notation:
35
+ import { RushConfiguration } from '@rushstack/rush-sdk';
36
+
37
+ const config = RushConfiguration.loadFromDefaultLocation();
38
+ console.log(config.commonFolder);
39
+ ```
40
+
41
+ ## Loader API
42
+
43
+ Here's a basic example of how to manually load **@rushstack/rush-sdk** and monitor installation progress:
44
+
45
+ ```ts
46
+ import { RushSdkLoader, ISdkCallbackEvent } from '@rushstack/rush-sdk/loader';
47
+
48
+ if (!RushSdkLoader.isLoaded) {
49
+ await RushSdkLoader.loadAsync({
50
+ // the search for rush.json starts here:
51
+ rushJsonSearchFolder: "path/to/my-repo/apps/my-app",
52
+
53
+ onNotifyEvent: (event: ISdkCallbackEvent) => {
54
+ if (event.logMessage) {
55
+ // Your tool can show progress about the loading:
56
+ if (event.logMessage.kind === 'info') {
57
+ console.log(event.logMessage.text);
58
+ }
59
+ }
60
+ }
61
+ });
62
+ }
63
+
64
+ // Any subsequent attempts to call require() will return the same instance
65
+ // that was loaded above.
66
+ const rushSdk = require('@rushstack/rush-sdk');
67
+ const config = rushSdk.RushConfiguration.loadFromDefaultLocation();
68
+ ```
69
+
70
+ Here's a more elaborate example illustrating other API features:
71
+
72
+ ```ts
73
+ import { RushSdkLoader, ISdkCallbackEvent } from '@rushstack/rush-sdk/loader';
74
+
75
+ // Use an AbortController to cancel the operation after a certain time period
76
+ const abortController = new AbortController();
77
+ setTimeout(() => {
78
+ abortController.abort();
79
+ }, 1000);
80
+
81
+ if (!RushSdkLoader.isLoaded) {
82
+ await RushSdkLoader.loadAsync({
83
+ // the search for rush.json starts here:
84
+ rushJsonSearchFolder: "path/to/my-repo/apps/my-app",
85
+
86
+ abortSignal: abortController.signal,
87
+
88
+ onNotifyEvent: (event: ISdkCallbackEvent) => {
89
+ if (event.logMessage) {
90
+ // Your tool can show progress about the loading:
91
+ if (event.logMessage.kind === 'info') {
92
+ console.log(event.logMessage.text);
93
+ }
94
+ }
95
+
96
+ if (event.progressPercent !== undefined) {
97
+ // If installation takes a long time, your tool can display a progress bar
98
+ displayYourProgressBar(event.progressPercent);
99
+ }
100
+ }
101
+ });
102
+ }
103
+
104
+ // Any subsequent attempts to call require() will return the same instance
105
+ // that was loaded above.
106
+ const rushSdk = require('@rushstack/rush-sdk');
107
+ const config = rushSdk.RushConfiguration.loadFromDefaultLocation();
108
+ ```
109
+
110
+
111
+ ## Importing internal APIs
112
+
113
+ Backwards compatibility is only guaranteed for the APIs marked as `@public` in the official `rush-lib.d.ts` entry point.
114
+ However, sometimes it is expedient for a script to import internal modules from `@microsoft/rush-lib` to access
115
+ unofficial APIs. This practice faces a technical challenge that `@microsoft/rush-lib` is bundled using Webpack.
116
+ The `@rushstack/rush-sdk` package provides stub files that import the corresponding internal module from the
117
+ Webpack bundle, via the `@rushstack/webpack-deep-imports-plugin` mechanism.
118
+
119
+ > **WARNING:** If the loaded `rush-lib` package has a different version from `rush-sdk`, there is
120
+ > no guarantee that the corresponding path will exist or have the same type signature.
121
+ > Access internal APIs at your own risk. If you find an internal API to be useful, we recommend
122
+ > that you create a GitHub issue proposing to make it public.
123
+
124
+ Example 1: Conventional import of a public API:
125
+
126
+ ```ts
127
+ // THIS IS THE RECOMMENDED PRACTICE:
128
+ import { RushConfiguration } from '@rushstack/rush-sdk';
129
+ const config = RushConfiguration.loadFromDefaultLocation();
130
+ console.log(config.commonFolder);
131
+ ```
132
+
133
+ Example 2: How to import an internal API:
134
+
135
+ ```ts
136
+ // WARNING: INTERNAL APIS MAY CHANGE AT ANY TIME -- USE THIS AT YOUR OWN RISK:
137
+
138
+ // Important: Since we're calling an internal API, we need to use the unbundled .d.ts files
139
+ // instead of the normal .d.ts rollup, otherwise TypeScript will complain about a type mismatch.
140
+ import { RushConfiguration } from '@rushstack/rush-sdk/lib/index';
141
+ const config = RushConfiguration.loadFromDefaultLocation();
142
+ console.log(config.commonFolder);
143
+
144
+ // Load an internal module from the Webpack bundle using a path-based import of a stub file:
145
+ import { GitEmailPolicy } from '@rushstack/rush-sdk/lib/logic/policy/GitEmailPolicy';
146
+ console.log(GitEmailPolicy.getEmailExampleLines(config));
147
+ ```
148
+
149
+ ## Debugging
150
+
151
+ Verbose logging can be enabled by setting environment variable `RUSH_SDK_DEBUG=1`.
152
+
153
+ ## Links
154
+
155
+ - [CHANGELOG.md](https://github.com/microsoft/rushstack/blob/main/apps/rush/CHANGELOG.md) - Find
156
+ out what's new in the latest version
157
+ - [API Reference](https://api.rushstack.io/pages/rush-lib/)
158
+
159
+ Rush is part of the [Rush Stack](https://rushstack.io/) family of projects.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,oEAAkE;AAGrD,QAAA,aAAa,GAA0B,qBAAqB,CAAC;AAC7D,QAAA,0BAA0B,GAAmD,gBAAgB,CAAC;AAQ9F,QAAA,UAAU,GAAgB;IACrC,aAAa,EAAE,SAAS;CACzB,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,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;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;AApBD,0DAoBC;AAED,SAAgB,QAAQ,CAAU,UAAkB;IAClD,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;AAVD,4BAUC;AAED;;GAEG;AACH,SAAgB,6BAA6B,CAAC,UAAkB;IAC9D,MAAM,iBAAiB,GAAW,0BAAM,CAAC,aAAa,CAAC;QACrD,UAAU,EAAE,qBAAa;QACzB,cAAc,EAAE,UAAU;KAC3B,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAPD,sEAOC","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
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;A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C;AAPD,sEAOC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport * as path from 'path';\r\nimport { Import, FileSystem } from '@rushstack/node-core-library';\r\nimport type { EnvironmentVariableNames } from '@microsoft/rush-lib';\r\n\r\nexport const RUSH_LIB_NAME: '@microsoft/rush-lib' = '@microsoft/rush-lib';\r\nexport const RUSH_LIB_PATH_ENV_VAR_NAME: typeof EnvironmentVariableNames._RUSH_LIB_PATH = '_RUSH_LIB_PATH';\r\n\r\nexport type RushLibModuleType = Record<string, unknown>;\r\n\r\nexport interface ISdkContext {\r\n rushLibModule: RushLibModuleType | undefined;\r\n}\r\n\r\nexport const sdkContext: ISdkContext = {\r\n rushLibModule: undefined\r\n};\r\n\r\n/**\r\n * Find the rush.json location and return the path, or undefined if a rush.json can't be found.\r\n *\r\n * @privateRemarks\r\n * Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`.\r\n */\r\nexport function tryFindRushJsonLocation(startingFolder: string): string | undefined {\r\n let currentFolder: string = startingFolder;\r\n\r\n // Look upwards at parent folders until we find a folder containing rush.json\r\n for (let i: number = 0; i < 10; ++i) {\r\n const rushJsonFilename: string = path.join(currentFolder, 'rush.json');\r\n\r\n if (FileSystem.exists(rushJsonFilename)) {\r\n return rushJsonFilename;\r\n }\r\n\r\n const parentFolder: string = path.dirname(currentFolder);\r\n if (parentFolder === currentFolder) {\r\n break;\r\n }\r\n\r\n currentFolder = parentFolder;\r\n }\r\n\r\n return undefined;\r\n}\r\n\r\nexport function _require<TResult>(moduleName: string): TResult {\r\n if (typeof __non_webpack_require__ === 'function') {\r\n // If this library has been bundled with Webpack, we need to call the real `require` function\r\n // that doesn't get turned into a `__webpack_require__` statement.\r\n // `__non_webpack_require__` is a Webpack macro that gets turned into a `require` statement\r\n // during bundling.\r\n return __non_webpack_require__(moduleName);\r\n } else {\r\n return require(moduleName);\r\n }\r\n}\r\n\r\n/**\r\n * Require `@microsoft/rush-lib` under the specified folder path.\r\n */\r\nexport function requireRushLibUnderFolderPath(folderPath: string): RushLibModuleType {\r\n const rushLibModulePath: string = Import.resolveModule({\r\n modulePath: RUSH_LIB_NAME,\r\n baseFolderPath: folderPath\r\n });\r\n\r\n return _require(rushLibModulePath);\r\n}\r\n"]}
package/lib-shim/index.js CHANGED
@@ -153,8 +153,8 @@ if (helpers_1.sdkContext.rushLibModule === undefined) {
153
153
  // instance cannot be found. If you are writing Jest tests for a Rush plugin, add "@microsoft/rush-lib"
154
154
  // to the devDependencies for your project.
155
155
  // eslint-disable-next-line no-console
156
- console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:
157
- ${errorMessage}
156
+ console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:
157
+ ${errorMessage}
158
158
  `);
159
159
  process.exit(1);
160
160
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,oEAQsC;AAEtC,uCAQmB;AAEnB,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,cAAc;CACf,CAAC,CACH,CAAC;AAQF,IAAI,YAAY,GAAW,EAAE,CAAC;AAE9B,qGAAqG;AACrG,gGAAgG;AAChG,IAAI,oBAAU,CAAC,aAAa,KAAK,SAAS,EAAE;IAC1C,oBAAU,CAAC,aAAa;QACtB,MAAM,CAAC,uBAAuB;YAC9B,MAAM,CAAC,sCAAsC;YAC7C,MAAM,CAAC,4CAA4C,CAAC;CACvD;AAED,6FAA6F;AAC7F,+FAA+F;AAC/F,IAAI,oBAAU,CAAC,aAAa,KAAK,SAAS,EAAE;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C,CAAC,CAAC;SACpF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,WAAW;QACX,YAAY,GAAI,CAAW,CAAC,OAAO,CAAC;KACrC;CACF;AAED,IAAI,oBAAU,CAAC,aAAa,KAAK,SAAS,EAAE;IAC1C,qGAAqG;IACrG,wGAAwG;IACxG,2CAA2C;IAC3C,sCAAsC;IACtC,OAAO,CAAC,KAAK,CAAC;EACd,YAAY;CACb,CAAC,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,uCAAuC;AACvC,KAAK,MAAM,QAAQ,IAAI,oBAAU,CAAC,aAAa,EAAE;IAC/C,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;QAC/D,MAAM,uBAAuB,GAAsB,oBAAU,CAAC,aAAa,CAAC;QAE5E,0CAA0C;QAC1C,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE;YACvC,UAAU,EAAE,IAAI;YAChB,GAAG,EAAE;gBACH,OAAO,uBAAuB,CAAC,QAAQ,CAAC,CAAC;YAC3C,CAAC;SACF,CAAC,CAAC;KACJ;CACF;AAED;;GAEG;AACH,SAAgB,2BAA2B,CAAC,aAAqB;IAC/D,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,gBAAgB,OAAO,CAAC,IAAI,CAAC,OAAO,qDAAqD,CAC1F,CAAC;KACH;IACD,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAC1D,CAAC;AAPD,kEAOC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as path from 'path';\nimport {\n JsonFile,\n type JsonObject,\n type IPackageJson,\n PackageJsonLookup,\n Executable,\n Terminal,\n ConsoleTerminalProvider\n} from '@rushstack/node-core-library';\nimport type { SpawnSyncReturns } from 'child_process';\nimport {\n RUSH_LIB_NAME,\n RUSH_LIB_PATH_ENV_VAR_NAME,\n type RushLibModuleType,\n _require,\n requireRushLibUnderFolderPath,\n tryFindRushJsonLocation,\n sdkContext\n} from './helpers';\n\nconst verboseEnabled: boolean = typeof process !== 'undefined' && process.env.RUSH_SDK_DEBUG === '1';\nconst terminal: Terminal = new Terminal(\n new ConsoleTerminalProvider({\n verboseEnabled\n })\n);\n\ndeclare const global: typeof globalThis & {\n ___rush___rushLibModule?: RushLibModuleType;\n ___rush___rushLibModuleFromEnvironment?: RushLibModuleType;\n ___rush___rushLibModuleFromInstallAndRunRush?: RushLibModuleType;\n};\n\nlet errorMessage: string = '';\n\n// SCENARIO 1: Rush's PluginManager has initialized \"rush-sdk\" with Rush's own instance of rush-lib.\n// The Rush host process will assign \"global.___rush___rushLibModule\" before loading the plugin.\nif (sdkContext.rushLibModule === undefined) {\n sdkContext.rushLibModule =\n global.___rush___rushLibModule ||\n global.___rush___rushLibModuleFromEnvironment ||\n global.___rush___rushLibModuleFromInstallAndRunRush;\n}\n\n// SCENARIO 2: The project importing \"rush-sdk\" has installed its own instance of \"rush-lib\"\n// as a package.json dependency. For example, this is used by the Jest tests for Rush plugins.\nif (sdkContext.rushLibModule === undefined) {\n const importingPath: string | null | undefined = module?.parent?.filename;\n if (importingPath) {\n const callerPackageFolder: string | undefined =\n PackageJsonLookup.instance.tryGetPackageFolderFor(importingPath);\n\n if (callerPackageFolder !== undefined) {\n const callerPackageJson: IPackageJson = _require(path.join(callerPackageFolder, 'package.json'));\n\n // Does the caller properly declare a dependency on rush-lib?\n if (\n (callerPackageJson.dependencies && callerPackageJson.dependencies[RUSH_LIB_NAME] !== undefined) ||\n (callerPackageJson.devDependencies &&\n callerPackageJson.devDependencies[RUSH_LIB_NAME] !== undefined) ||\n (callerPackageJson.peerDependencies &&\n callerPackageJson.peerDependencies[RUSH_LIB_NAME] !== undefined)\n ) {\n // Try to resolve rush-lib from the caller's folder\n terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from caller package`);\n try {\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(callerPackageFolder);\n } catch (error) {\n // If we fail to resolve it, ignore the error\n terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from caller package`);\n }\n\n // If two different libraries invoke `rush-sdk`, and one of them provides \"rush-lib\"\n // then the first version to be loaded wins. We do not support side-by-side instances of \"rush-lib\".\n if (sdkContext.rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModule = sdkContext.rushLibModule;\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from caller`);\n }\n }\n }\n }\n}\n\n// SCENARIO 3: A tool or script has been invoked as a child process by an instance of \"rush-lib\" and can use the\n// version that invoked it. In this case, use process.env._RUSH_LIB_PATH to find \"rush-lib\".\nif (sdkContext.rushLibModule === undefined) {\n const rushLibPath: string | undefined = process.env[RUSH_LIB_PATH_ENV_VAR_NAME];\n if (rushLibPath) {\n terminal.writeVerboseLine(\n `Try to load ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME} from caller package`\n );\n try {\n sdkContext.rushLibModule = _require(rushLibPath);\n } catch (error) {\n // Log this as a warning, since it is unexpected to define an incorrect value of the variable.\n terminal.writeWarningLine(\n `Failed to load ${RUSH_LIB_NAME} via process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`\n );\n }\n\n if (sdkContext.rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModuleFromEnvironment = sdkContext.rushLibModule;\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`);\n }\n }\n}\n\n// SCENARIO 4: A standalone tool or script depends on \"rush-sdk\", and is meant to be used inside a monorepo folder.\n// In this case, we can use install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.\nif (sdkContext.rushLibModule === undefined) {\n try {\n const rushJsonPath: string | undefined = tryFindRushJsonLocation(process.cwd());\n if (!rushJsonPath) {\n throw new Error(\n 'Unable to find rush.json in the current folder or its parent folders.\\n' +\n 'This tool is meant to be invoked from a working directory inside a Rush repository.'\n );\n }\n const monorepoRoot: string = path.dirname(rushJsonPath);\n\n const rushJson: JsonObject = JsonFile.load(rushJsonPath);\n const { rushVersion } = rushJson;\n\n 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 sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\n } catch (e1) {\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 installAndRunRushProcess: SpawnSyncReturns<string> = Executable.spawnSync(\n 'node',\n [installAndRunRushJSPath, '--help'],\n {\n stdio: 'pipe'\n }\n );\n\n installAndRunRushStderrContent = installAndRunRushProcess.stderr;\n if (installAndRunRushProcess.status !== 0) {\n throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);\n }\n\n // Retry to load \"rush-lib\" after install-run-rush run\n terminal.writeVerboseLine(\n `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`\n );\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\n } catch (e2) {\n // eslint-disable-next-line no-console\n console.error(`${installAndRunRushStderrContent}`);\n throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);\n }\n }\n\n if (sdkContext.rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModuleFromInstallAndRunRush = sdkContext.rushLibModule;\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed by install-run-rush`);\n }\n } catch (e) {\n // no-catch\n errorMessage = (e as Error).message;\n }\n}\n\nif (sdkContext.rushLibModule === undefined) {\n // This error indicates that a project is trying to import \"@rushstack/rush-sdk\", but the Rush engine\n // instance cannot be found. If you are writing Jest tests for a Rush plugin, add \"@microsoft/rush-lib\"\n // to the devDependencies for your project.\n // eslint-disable-next-line no-console\n console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:\n${errorMessage}\n`);\n process.exit(1);\n}\n\n// Based on TypeScript's __exportStar()\nfor (const property in sdkContext.rushLibModule) {\n if (property !== 'default' && !exports.hasOwnProperty(property)) {\n const rushLibModuleForClosure: RushLibModuleType = sdkContext.rushLibModule;\n\n // Based on TypeScript's __createBinding()\n Object.defineProperty(exports, property, {\n enumerable: true,\n get: function () {\n return rushLibModuleForClosure[property];\n }\n });\n }\n}\n\n/**\n * Used by the .js stubs for path-based imports of `@microsoft/rush-lib` internal APIs.\n */\nexport function _rushSdk_loadInternalModule(srcImportPath: string): unknown {\n if (!exports._RushInternals) {\n throw new Error(\n `Rush version ${exports.Rush.version} does not support internal API imports via rush-sdk`\n );\n }\n return exports._RushInternals.loadModule(srcImportPath);\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,oEAQsC;AAEtC,uCAQmB;AAEnB,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,cAAc;CACf,CAAC,CACH,CAAC;AAQF,IAAI,YAAY,GAAW,EAAE,CAAC;AAE9B,qGAAqG;AACrG,gGAAgG;AAChG,IAAI,oBAAU,CAAC,aAAa,KAAK,SAAS,EAAE;IAC1C,oBAAU,CAAC,a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reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport * as path from 'path';\r\nimport {\r\n JsonFile,\r\n type JsonObject,\r\n type IPackageJson,\r\n PackageJsonLookup,\r\n Executable,\r\n Terminal,\r\n ConsoleTerminalProvider\r\n} from '@rushstack/node-core-library';\r\nimport type { SpawnSyncReturns } from 'child_process';\r\nimport {\r\n RUSH_LIB_NAME,\r\n RUSH_LIB_PATH_ENV_VAR_NAME,\r\n type RushLibModuleType,\r\n _require,\r\n requireRushLibUnderFolderPath,\r\n tryFindRushJsonLocation,\r\n sdkContext\r\n} from './helpers';\r\n\r\nconst verboseEnabled: boolean = typeof process !== 'undefined' && process.env.RUSH_SDK_DEBUG === '1';\r\nconst terminal: Terminal = new Terminal(\r\n new ConsoleTerminalProvider({\r\n verboseEnabled\r\n })\r\n);\r\n\r\ndeclare const global: typeof globalThis & {\r\n ___rush___rushLibModule?: RushLibModuleType;\r\n ___rush___rushLibModuleFromEnvironment?: RushLibModuleType;\r\n ___rush___rushLibModuleFromInstallAndRunRush?: RushLibModuleType;\r\n};\r\n\r\nlet errorMessage: string = '';\r\n\r\n// SCENARIO 1: Rush's PluginManager has initialized \"rush-sdk\" with Rush's own instance of rush-lib.\r\n// The Rush host process will assign \"global.___rush___rushLibModule\" before loading the plugin.\r\nif (sdkContext.rushLibModule === undefined) {\r\n sdkContext.rushLibModule =\r\n global.___rush___rushLibModule ||\r\n global.___rush___rushLibModuleFromEnvironment ||\r\n global.___rush___rushLibModuleFromInstallAndRunRush;\r\n}\r\n\r\n// SCENARIO 2: The project importing \"rush-sdk\" has installed its own instance of \"rush-lib\"\r\n// as a package.json dependency. For example, this is used by the Jest tests for Rush plugins.\r\nif (sdkContext.rushLibModule === undefined) {\r\n const importingPath: string | null | undefined = module?.parent?.filename;\r\n if (importingPath) {\r\n const callerPackageFolder: string | undefined =\r\n PackageJsonLookup.instance.tryGetPackageFolderFor(importingPath);\r\n\r\n if (callerPackageFolder !== undefined) {\r\n const callerPackageJson: IPackageJson = _require(path.join(callerPackageFolder, 'package.json'));\r\n\r\n // Does the caller properly declare a dependency on rush-lib?\r\n if (\r\n (callerPackageJson.dependencies && callerPackageJson.dependencies[RUSH_LIB_NAME] !== undefined) ||\r\n (callerPackageJson.devDependencies &&\r\n callerPackageJson.devDependencies[RUSH_LIB_NAME] !== undefined) ||\r\n (callerPackageJson.peerDependencies &&\r\n callerPackageJson.peerDependencies[RUSH_LIB_NAME] !== undefined)\r\n ) {\r\n // Try to resolve rush-lib from the caller's folder\r\n terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from caller package`);\r\n try {\r\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(callerPackageFolder);\r\n } catch (error) {\r\n // If we fail to resolve it, ignore the error\r\n terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from caller package`);\r\n }\r\n\r\n // If two different libraries invoke `rush-sdk`, and one of them provides \"rush-lib\"\r\n // then the first version to be loaded wins. We do not support side-by-side instances of \"rush-lib\".\r\n if (sdkContext.rushLibModule !== undefined) {\r\n // to track which scenario is active and how it got initialized.\r\n global.___rush___rushLibModule = sdkContext.rushLibModule;\r\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from caller`);\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\n// SCENARIO 3: A tool or script has been invoked as a child process by an instance of \"rush-lib\" and can use the\r\n// version that invoked it. In this case, use process.env._RUSH_LIB_PATH to find \"rush-lib\".\r\nif (sdkContext.rushLibModule === undefined) {\r\n const rushLibPath: string | undefined = process.env[RUSH_LIB_PATH_ENV_VAR_NAME];\r\n if (rushLibPath) {\r\n terminal.writeVerboseLine(\r\n `Try to load ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME} from caller package`\r\n );\r\n try {\r\n sdkContext.rushLibModule = _require(rushLibPath);\r\n } catch (error) {\r\n // Log this as a warning, since it is unexpected to define an incorrect value of the variable.\r\n terminal.writeWarningLine(\r\n `Failed to load ${RUSH_LIB_NAME} via process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`\r\n );\r\n }\r\n\r\n if (sdkContext.rushLibModule !== undefined) {\r\n // to track which scenario is active and how it got initialized.\r\n global.___rush___rushLibModuleFromEnvironment = sdkContext.rushLibModule;\r\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`);\r\n }\r\n }\r\n}\r\n\r\n// SCENARIO 4: A standalone tool or script depends on \"rush-sdk\", and is meant to be used inside a monorepo folder.\r\n// In this case, we can use install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.\r\nif (sdkContext.rushLibModule === undefined) {\r\n try {\r\n const rushJsonPath: string | undefined = tryFindRushJsonLocation(process.cwd());\r\n if (!rushJsonPath) {\r\n throw new Error(\r\n 'Unable to find rush.json in the current folder or its parent folders.\\n' +\r\n 'This tool is meant to be invoked from a working directory inside a Rush repository.'\r\n );\r\n }\r\n const monorepoRoot: string = path.dirname(rushJsonPath);\r\n\r\n const rushJson: JsonObject = JsonFile.load(rushJsonPath);\r\n const { rushVersion } = rushJson;\r\n\r\n const installRunNodeModuleFolder: string = path.join(\r\n monorepoRoot,\r\n `common/temp/install-run/@microsoft+rush@${rushVersion}`\r\n );\r\n\r\n try {\r\n // First, try to load the version of \"rush-lib\" that was installed by install-run-rush.js\r\n terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`);\r\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\r\n } catch (e1) {\r\n let installAndRunRushStderrContent: string = '';\r\n try {\r\n const installAndRunRushJSPath: string = path.join(monorepoRoot, 'common/scripts/install-run-rush.js');\r\n\r\n terminal.writeLine('The Rush engine has not been installed yet. Invoking install-run-rush.js...');\r\n\r\n const installAndRunRushProcess: SpawnSyncReturns<string> = Executable.spawnSync(\r\n 'node',\r\n [installAndRunRushJSPath, '--help'],\r\n {\r\n stdio: 'pipe'\r\n }\r\n );\r\n\r\n installAndRunRushStderrContent = installAndRunRushProcess.stderr;\r\n if (installAndRunRushProcess.status !== 0) {\r\n throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);\r\n }\r\n\r\n // Retry to load \"rush-lib\" after install-run-rush run\r\n terminal.writeVerboseLine(\r\n `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`\r\n );\r\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\r\n } catch (e2) {\r\n // eslint-disable-next-line no-console\r\n console.error(`${installAndRunRushStderrContent}`);\r\n throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);\r\n }\r\n }\r\n\r\n if (sdkContext.rushLibModule !== undefined) {\r\n // to track which scenario is active and how it got initialized.\r\n global.___rush___rushLibModuleFromInstallAndRunRush = sdkContext.rushLibModule;\r\n terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed by install-run-rush`);\r\n }\r\n } catch (e) {\r\n // no-catch\r\n errorMessage = (e as Error).message;\r\n }\r\n}\r\n\r\nif (sdkContext.rushLibModule === undefined) {\r\n // This error indicates that a project is trying to import \"@rushstack/rush-sdk\", but the Rush engine\r\n // instance cannot be found. If you are writing Jest tests for a Rush plugin, add \"@microsoft/rush-lib\"\r\n // to the devDependencies for your project.\r\n // eslint-disable-next-line no-console\r\n console.error(`Error: The @rushstack/rush-sdk package was not able to load the Rush engine:\r\n${errorMessage}\r\n`);\r\n process.exit(1);\r\n}\r\n\r\n// Based on TypeScript's __exportStar()\r\nfor (const property in sdkContext.rushLibModule) {\r\n if (property !== 'default' && !exports.hasOwnProperty(property)) {\r\n const rushLibModuleForClosure: RushLibModuleType = sdkContext.rushLibModule;\r\n\r\n // Based on TypeScript's __createBinding()\r\n Object.defineProperty(exports, property, {\r\n enumerable: true,\r\n get: function () {\r\n return rushLibModuleForClosure[property];\r\n }\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Used by the .js stubs for path-based imports of `@microsoft/rush-lib` internal APIs.\r\n */\r\nexport function _rushSdk_loadInternalModule(srcImportPath: string): unknown {\r\n if (!exports._RushInternals) {\r\n throw new Error(\r\n `Rush version ${exports.Rush.version} does not support internal API imports via rush-sdk`\r\n );\r\n }\r\n return exports._RushInternals.loadModule(srcImportPath);\r\n}\r\n"]}
@@ -1 +1 @@
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;YACzB,OAAO;SACR;QAED,IAAI,aAAa,EAAE;YACjB,aAAa,CAAC;gBACZ,UAAU,EAAE;oBACV,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,4BAA4B;iBACnC;gBACD,eAAe;aAChB,CAAC,CAAC;SACJ;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,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAA8B;QAC1D,sFAAsF;;QAEtF,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,EAAE,CAAC;SACd;QAED,IAAI,aAAa,CAAC,QAAQ,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;SACrG;QAED,MAAM,a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ACF;YAED,IAAI,oBAAU,CAAC,aAAa,KAAK,SAAS,EAAE;gBAC1C,gEAAgE;gBAChE,MAAM,CAAC,4CAA4C,GAAG,oBAAU,CAAC,aAAa,CAAC;gBAC/E,IAAI,aAAa,EAAE;oBACjB,aAAa,CAAC;wBACZ,UAAU,EAAE;4BACV,IAAI,EAAE,OAAO;4BACb,IAAI,EAAE,UAAU,uBAAa,gCAAgC;yBAC9D;wBACD,eAAe;qBAChB,CAAC,CAAC;iBACJ;aACF;SACF;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,aAAa,EAAE;gBACjB,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;aACJ;YACD,MAAM,CAAC,CAAC;SACT;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
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;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aACF;SACF;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,aAAa,EAAE;gBACjB,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;aACJ;YACD,MAAM,CAAC,CAAC;SACT;IACH,CAAC;CACF;AA7LD,sCA6LC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport * as path from 'path';\r\nimport type { SpawnSyncReturns } from 'child_process';\r\nimport { JsonFile, type JsonObject, Executable } from '@rushstack/node-core-library';\r\n\r\nimport {\r\n tryFindRushJsonLocation,\r\n RUSH_LIB_NAME,\r\n type RushLibModuleType,\r\n requireRushLibUnderFolderPath,\r\n sdkContext\r\n} from './helpers';\r\n\r\ndeclare const global: typeof globalThis & {\r\n ___rush___rushLibModule?: RushLibModuleType;\r\n ___rush___rushLibModuleFromEnvironment?: RushLibModuleType;\r\n ___rush___rushLibModuleFromInstallAndRunRush?: RushLibModuleType;\r\n};\r\n\r\n/**\r\n * Type of {@link ISdkCallbackEvent.logMessage}\r\n * @public\r\n */\r\nexport interface IProgressBarCallbackLogMessage {\r\n /**\r\n * A status message to print in the log window, or `undefined` if there are\r\n * no further messages. This string may contain newlines.\r\n */\r\n text: string;\r\n\r\n /**\r\n * The type of message. More message types may be added in the future.\r\n */\r\n kind: 'info' | 'debug';\r\n}\r\n\r\n/**\r\n * Event options for {@link ILoadSdkAsyncOptions.onNotifyEvent}\r\n * @public\r\n */\r\nexport interface ISdkCallbackEvent {\r\n /**\r\n * Allows the caller to display log information about the operation.\r\n */\r\n logMessage: IProgressBarCallbackLogMessage | undefined;\r\n\r\n /**\r\n * Allows the caller to display a progress bar for long-running operations.\r\n *\r\n * @remarks\r\n * If a long-running operation is required, then `progressPercent` will\r\n * start at 0.0 and count upwards and finish at 100.0 if the operation completes\r\n * successfully. If the long-running operation has not yet started, or\r\n * is not required, then the value will be `undefined`.\r\n */\r\n progressPercent: number | undefined;\r\n}\r\n\r\n/**\r\n * Type of {@link ILoadSdkAsyncOptions.onNotifyEvent}\r\n * @public\r\n */\r\nexport type SdkNotifyEventCallback = (sdkEvent: ISdkCallbackEvent) => void;\r\n\r\n/**\r\n * Options for {@link RushSdkLoader.loadAsync}\r\n * @public\r\n */\r\nexport interface ILoadSdkAsyncOptions {\r\n /**\r\n * The folder to start from when searching for the Rush workspace configuration.\r\n * If this folder does not contain a `rush.json` file, then each parent folder\r\n * will be searched. If `rush.json` is not found, then the SDK fails to load.\r\n */\r\n rushJsonSearchFolder?: string;\r\n\r\n /**\r\n * A cancellation token that the caller can use to prematurely abort the operation.\r\n */\r\n abortSignal?: AbortSignal;\r\n\r\n /**\r\n * Allows the caller to monitor the progress of the operation.\r\n */\r\n onNotifyEvent?: SdkNotifyEventCallback;\r\n}\r\n\r\n/**\r\n * Exposes operations that control how the `@microsoft/rush-lib` engine is\r\n * located and loaded.\r\n * @public\r\n */\r\nexport class RushSdkLoader {\r\n /**\r\n * Throws an \"AbortError\" exception if abortSignal.aborted is true.\r\n */\r\n private static _checkForCancel(\r\n abortSignal: AbortSignal,\r\n onNotifyEvent: SdkNotifyEventCallback | undefined,\r\n progressPercent: number | undefined\r\n ): void {\r\n if (!abortSignal?.aborted) {\r\n return;\r\n }\r\n\r\n if (onNotifyEvent) {\r\n onNotifyEvent({\r\n logMessage: {\r\n kind: 'info',\r\n text: `The operation was canceled`\r\n },\r\n progressPercent\r\n });\r\n }\r\n\r\n const error: Error = new Error('The operation was canceled');\r\n error.name = 'AbortError';\r\n throw error;\r\n }\r\n\r\n /**\r\n * Returns true if the Rush engine has already been loaded.\r\n */\r\n public static get isLoaded(): boolean {\r\n return sdkContext.rushLibModule !== undefined;\r\n }\r\n\r\n /**\r\n * Manually load the Rush engine based on rush.json found for `rushJsonSearchFolder`.\r\n * Throws an exception if {@link RushSdkLoader.isLoaded} is already `true`.\r\n *\r\n * @remarks\r\n * This API supports an callback that can be used display a progress bar,\r\n * log of operations, and allow the operation to be canceled prematurely.\r\n */\r\n public static async loadAsync(options?: ILoadSdkAsyncOptions): Promise<void> {\r\n // SCENARIO 5: The rush-lib engine is loaded manually using rushSdkLoader.loadAsync().\r\n\r\n if (!options) {\r\n options = {};\r\n }\r\n\r\n if (RushSdkLoader.isLoaded) {\r\n throw new Error('RushSdkLoader.loadAsync() failed because the Rush engine has already been loaded');\r\n }\r\n\r\n const onNotifyEvent: SdkNotifyEventCallback | undefined = options.onNotifyEvent;\r\n let progressPercent: number | undefined = undefined;\r\n\r\n const abortSignal: AbortSignal | undefined = options.abortSignal;\r\n\r\n try {\r\n const rushJsonSearchFolder: string = options.rushJsonSearchFolder ?? process.cwd();\r\n\r\n if (onNotifyEvent) {\r\n onNotifyEvent({\r\n logMessage: {\r\n kind: 'debug',\r\n text: `Searching for rush.json starting from: ` + rushJsonSearchFolder\r\n },\r\n progressPercent\r\n });\r\n }\r\n\r\n const rushJsonPath: string | undefined = tryFindRushJsonLocation(rushJsonSearchFolder);\r\n if (!rushJsonPath) {\r\n throw new Error(\r\n 'Unable to find rush.json in the specified folder or its parent folders:\\n' +\r\n `${rushJsonSearchFolder}\\n`\r\n );\r\n }\r\n const monorepoRoot: string = path.dirname(rushJsonPath);\r\n\r\n const rushJson: JsonObject = await JsonFile.loadAsync(rushJsonPath);\r\n const { rushVersion } = rushJson;\r\n\r\n const installRunNodeModuleFolder: string = path.join(\r\n monorepoRoot,\r\n `common/temp/install-run/@microsoft+rush@${rushVersion}`\r\n );\r\n\r\n try {\r\n // First, try to load the version of \"rush-lib\" that was installed by install-run-rush.js\r\n if (onNotifyEvent) {\r\n onNotifyEvent({\r\n logMessage: {\r\n kind: 'info',\r\n text: `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`\r\n },\r\n progressPercent\r\n });\r\n }\r\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\r\n } catch (e1) {\r\n let installAndRunRushStderrContent: string = '';\r\n try {\r\n const installAndRunRushJSPath: string = path.join(\r\n monorepoRoot,\r\n 'common/scripts/install-run-rush.js'\r\n );\r\n\r\n if (onNotifyEvent) {\r\n onNotifyEvent({\r\n logMessage: {\r\n kind: 'info',\r\n text: 'The Rush engine has not been installed yet. Invoking install-run-rush.js...'\r\n },\r\n progressPercent\r\n });\r\n }\r\n\r\n // Start the installation\r\n progressPercent = 0;\r\n\r\n const installAndRunRushProcess: SpawnSyncReturns<string> = Executable.spawnSync(\r\n 'node',\r\n [installAndRunRushJSPath, '--help'],\r\n {\r\n stdio: 'pipe'\r\n }\r\n );\r\n\r\n installAndRunRushStderrContent = installAndRunRushProcess.stderr;\r\n if (installAndRunRushProcess.status !== 0) {\r\n throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);\r\n }\r\n\r\n if (abortSignal) {\r\n RushSdkLoader._checkForCancel(abortSignal, onNotifyEvent, progressPercent);\r\n }\r\n\r\n // TODO: Implement incremental progress updates\r\n progressPercent = 90;\r\n\r\n // Retry to load \"rush-lib\" after install-run-rush run\r\n if (onNotifyEvent) {\r\n onNotifyEvent({\r\n logMessage: {\r\n kind: 'debug',\r\n text: `Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`\r\n },\r\n progressPercent\r\n });\r\n }\r\n\r\n sdkContext.rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);\r\n\r\n progressPercent = 100;\r\n } catch (e2) {\r\n // eslint-disable-next-line no-console\r\n console.error(`${installAndRunRushStderrContent}`);\r\n throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);\r\n }\r\n }\r\n\r\n if (sdkContext.rushLibModule !== undefined) {\r\n // to track which scenario is active and how it got initialized.\r\n global.___rush___rushLibModuleFromInstallAndRunRush = sdkContext.rushLibModule;\r\n if (onNotifyEvent) {\r\n onNotifyEvent({\r\n logMessage: {\r\n kind: 'debug',\r\n text: `Loaded ${RUSH_LIB_NAME} installed by install-run-rush`\r\n },\r\n progressPercent\r\n });\r\n }\r\n }\r\n } catch (e) {\r\n if (onNotifyEvent) {\r\n onNotifyEvent({\r\n logMessage: {\r\n kind: 'info',\r\n text: 'The operation failed: ' + (e.message ?? 'An unknown error occurred')\r\n },\r\n progressPercent\r\n });\r\n }\r\n throw e;\r\n }\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/rush-sdk",
3
- "version": "5.109.2",
3
+ "version": "5.110.0",
4
4
  "description": "An API for interacting with the Rush engine",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,12 +30,12 @@
30
30
  "devDependencies": {
31
31
  "@types/semver": "7.5.0",
32
32
  "@types/webpack-env": "1.18.0",
33
- "@microsoft/rush-lib": "5.109.2",
34
- "@rushstack/heft": "0.62.3",
33
+ "@microsoft/rush-lib": "5.110.0",
34
+ "@rushstack/heft": "0.63.0",
35
35
  "local-node-rig": "1.0.0",
36
- "@rushstack/stream-collator": "4.1.10",
37
- "@rushstack/ts-command-line": "4.16.1",
38
- "@rushstack/terminal": "0.7.9"
36
+ "@rushstack/ts-command-line": "4.17.0",
37
+ "@rushstack/stream-collator": "4.1.11",
38
+ "@rushstack/terminal": "0.7.10"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "heft build --clean",