@rushstack/rush-sdk 5.100.2 → 5.101.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/README.md +97 -5
- package/dist/loader.d.ts +92 -0
- package/dist/rush-sdk.d.ts +92 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/logic/deploy/DeployScenarioConfiguration.d.ts +2 -0
- package/lib/logic/pnpm/PnpmShrinkwrapFile.d.ts +5 -0
- package/lib-shim/helpers.d.ts +21 -0
- package/lib-shim/helpers.d.ts.map +1 -0
- package/lib-shim/helpers.js +83 -0
- package/lib-shim/helpers.js.map +1 -0
- package/lib-shim/index.d.ts.map +1 -1
- package/lib-shim/index.js +44 -86
- package/lib-shim/index.js.map +1 -1
- package/lib-shim/loader.d.ts +86 -0
- package/lib-shim/loader.d.ts.map +1 -0
- package/lib-shim/loader.js +189 -0
- package/lib-shim/loader.js.map +1 -0
- package/package.json +21 -9
package/README.md
CHANGED
|
@@ -4,18 +4,110 @@ This is a companion package for the Rush tool. See the [@microsoft/rush](https:/
|
|
|
4
4
|
|
|
5
5
|
⚠ **_THIS PACKAGE IS EXPERIMENTAL_** ⚠
|
|
6
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
|
|
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
8
|
|
|
9
|
-
1. 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.
|
|
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
10
|
|
|
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
|
|
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
12
|
|
|
13
|
-
3. For
|
|
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
14
|
|
|
15
|
-
4. For scripts and tools that are designed to be used in a Rush monorepo,
|
|
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.
|
|
16
18
|
|
|
17
19
|
The **@rushstack/rush-sdk** API declarations are identical to the corresponding version of **@microsoft/rush-lib**.
|
|
18
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
|
+
|
|
19
111
|
## Importing internal APIs
|
|
20
112
|
|
|
21
113
|
Backwards compatibility is only guaranteed for the APIs marked as `@public` in the official `rush-lib.d.ts` entry point.
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link RushSdkLoader.loadAsync}
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare interface ILoadSdkAsyncOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The folder to start from when searching for the Rush workspace configuration.
|
|
10
|
+
* If this folder does not contain a `rush.json` file, then each parent folder
|
|
11
|
+
* will be searched. If `rush.json` is not found, then the SDK fails to load.
|
|
12
|
+
*/
|
|
13
|
+
rushJsonSearchFolder?: string;
|
|
14
|
+
/**
|
|
15
|
+
* A cancellation token that the caller can use to prematurely abort the operation.
|
|
16
|
+
*/
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
18
|
+
/**
|
|
19
|
+
* Allows the caller to monitor the progress of the operation.
|
|
20
|
+
*/
|
|
21
|
+
onNotifyEvent?: SdkNotifyEventCallback;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Type of {@link ISdkCallbackEvent.logMessage}
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare interface IProgressBarCallbackLogMessage {
|
|
29
|
+
/**
|
|
30
|
+
* A status message to print in the log window, or `undefined` if there are
|
|
31
|
+
* no further messages. This string may contain newlines.
|
|
32
|
+
*/
|
|
33
|
+
text: string;
|
|
34
|
+
/**
|
|
35
|
+
* The type of message. More message types may be added in the future.
|
|
36
|
+
*/
|
|
37
|
+
kind: 'info' | 'debug';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Event options for {@link ILoadSdkAsyncOptions.onNotifyEvent}
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare interface ISdkCallbackEvent {
|
|
45
|
+
/**
|
|
46
|
+
* Allows the caller to display log information about the operation.
|
|
47
|
+
*/
|
|
48
|
+
logMessage: IProgressBarCallbackLogMessage | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Allows the caller to display a progress bar for long-running operations.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* If a long-running operation is required, then `progressPercent` will
|
|
54
|
+
* start at 0.0 and count upwards and finish at 100.0 if the operation completes
|
|
55
|
+
* successfully. If the long-running operation has not yet started, or
|
|
56
|
+
* is not required, then the value will be `undefined`.
|
|
57
|
+
*/
|
|
58
|
+
progressPercent: number | undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Exposes operations that control how the `@microsoft/rush-lib` engine is
|
|
63
|
+
* located and loaded.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export declare class RushSdkLoader {
|
|
67
|
+
/**
|
|
68
|
+
* Throws an "AbortError" exception if abortSignal.aborted is true.
|
|
69
|
+
*/
|
|
70
|
+
private static _checkForCancel;
|
|
71
|
+
/**
|
|
72
|
+
* Returns true if the Rush engine has already been loaded.
|
|
73
|
+
*/
|
|
74
|
+
static get isLoaded(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Manually load the Rush engine based on rush.json found for `rushJsonSearchFolder`.
|
|
77
|
+
* Throws an exception if {@link RushSdkLoader.isLoaded} is already `true`.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* This API supports an callback that can be used display a progress bar,
|
|
81
|
+
* log of operations, and allow the operation to be canceled prematurely.
|
|
82
|
+
*/
|
|
83
|
+
static loadAsync(options?: ILoadSdkAsyncOptions): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Type of {@link ILoadSdkAsyncOptions.onNotifyEvent}
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export declare type SdkNotifyEventCallback = (sdkEvent: ISdkCallbackEvent) => void;
|
|
91
|
+
|
|
92
|
+
export { }
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link RushSdkLoader.loadAsync}
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare interface ILoadSdkAsyncOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The folder to start from when searching for the Rush workspace configuration.
|
|
10
|
+
* If this folder does not contain a `rush.json` file, then each parent folder
|
|
11
|
+
* will be searched. If `rush.json` is not found, then the SDK fails to load.
|
|
12
|
+
*/
|
|
13
|
+
rushJsonSearchFolder?: string;
|
|
14
|
+
/**
|
|
15
|
+
* A cancellation token that the caller can use to prematurely abort the operation.
|
|
16
|
+
*/
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
18
|
+
/**
|
|
19
|
+
* Allows the caller to monitor the progress of the operation.
|
|
20
|
+
*/
|
|
21
|
+
onNotifyEvent?: SdkNotifyEventCallback;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Type of {@link ISdkCallbackEvent.logMessage}
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare interface IProgressBarCallbackLogMessage {
|
|
29
|
+
/**
|
|
30
|
+
* A status message to print in the log window, or `undefined` if there are
|
|
31
|
+
* no further messages. This string may contain newlines.
|
|
32
|
+
*/
|
|
33
|
+
text: string;
|
|
34
|
+
/**
|
|
35
|
+
* The type of message. More message types may be added in the future.
|
|
36
|
+
*/
|
|
37
|
+
kind: 'info' | 'debug';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Event options for {@link ILoadSdkAsyncOptions.onNotifyEvent}
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare interface ISdkCallbackEvent {
|
|
45
|
+
/**
|
|
46
|
+
* Allows the caller to display log information about the operation.
|
|
47
|
+
*/
|
|
48
|
+
logMessage: IProgressBarCallbackLogMessage | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Allows the caller to display a progress bar for long-running operations.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* If a long-running operation is required, then `progressPercent` will
|
|
54
|
+
* start at 0.0 and count upwards and finish at 100.0 if the operation completes
|
|
55
|
+
* successfully. If the long-running operation has not yet started, or
|
|
56
|
+
* is not required, then the value will be `undefined`.
|
|
57
|
+
*/
|
|
58
|
+
progressPercent: number | undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Exposes operations that control how the `@microsoft/rush-lib` engine is
|
|
63
|
+
* located and loaded.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export declare class RushSdkLoader {
|
|
67
|
+
/**
|
|
68
|
+
* Throws an "AbortError" exception if abortSignal.aborted is true.
|
|
69
|
+
*/
|
|
70
|
+
private static _checkForCancel;
|
|
71
|
+
/**
|
|
72
|
+
* Returns true if the Rush engine has already been loaded.
|
|
73
|
+
*/
|
|
74
|
+
static get isLoaded(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Manually load the Rush engine based on rush.json found for `rushJsonSearchFolder`.
|
|
77
|
+
* Throws an exception if {@link RushSdkLoader.isLoaded} is already `true`.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* This API supports an callback that can be used display a progress bar,
|
|
81
|
+
* log of operations, and allow the operation to be canceled prematurely.
|
|
82
|
+
*/
|
|
83
|
+
static loadAsync(options?: ILoadSdkAsyncOptions): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Type of {@link ILoadSdkAsyncOptions.onNotifyEvent}
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
export declare type SdkNotifyEventCallback = (sdkEvent: ISdkCallbackEvent) => void;
|
|
91
|
+
|
|
92
|
+
export { }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.36.3"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -5,6 +5,8 @@ export interface IDeployScenarioProjectJson {
|
|
|
5
5
|
additionalProjectsToInclude?: string[];
|
|
6
6
|
additionalDependenciesToInclude?: string[];
|
|
7
7
|
dependenciesToExclude?: string[];
|
|
8
|
+
patternsToInclude?: string[];
|
|
9
|
+
patternsToExclude?: string[];
|
|
8
10
|
}
|
|
9
11
|
export interface IDeployScenarioJson {
|
|
10
12
|
deploymentProjectNames: string[];
|
|
@@ -94,6 +94,10 @@ export interface IPnpmShrinkwrapYaml {
|
|
|
94
94
|
registry: string;
|
|
95
95
|
/** The list of specifiers used to resolve direct dependency versions */
|
|
96
96
|
specifiers: Record<string, string>;
|
|
97
|
+
/** The list of override version number for dependencies */
|
|
98
|
+
overrides?: {
|
|
99
|
+
[dependency: string]: string;
|
|
100
|
+
};
|
|
97
101
|
}
|
|
98
102
|
/**
|
|
99
103
|
* Given an encoded "dependency key" from the PNPM shrinkwrap file, this parses it into an equivalent
|
|
@@ -111,6 +115,7 @@ export declare class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
|
|
|
111
115
|
readonly importers: ReadonlyMap<string, IPnpmShrinkwrapImporterYaml>;
|
|
112
116
|
readonly specifiers: ReadonlyMap<string, string>;
|
|
113
117
|
readonly packages: ReadonlyMap<string, IPnpmShrinkwrapDependencyYaml>;
|
|
118
|
+
readonly overrides: ReadonlyMap<string, string>;
|
|
114
119
|
private readonly _shrinkwrapJson;
|
|
115
120
|
private readonly _integrities;
|
|
116
121
|
private _pnpmfileConfiguration;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EnvironmentVariableNames } from '@microsoft/rush-lib';
|
|
2
|
+
export declare const RUSH_LIB_NAME: '@microsoft/rush-lib';
|
|
3
|
+
export declare const RUSH_LIB_PATH_ENV_VAR_NAME: typeof EnvironmentVariableNames.RUSH_LIB_PATH;
|
|
4
|
+
export type RushLibModuleType = Record<string, unknown>;
|
|
5
|
+
export interface ISdkContext {
|
|
6
|
+
rushLibModule: RushLibModuleType | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare const sdkContext: ISdkContext;
|
|
9
|
+
/**
|
|
10
|
+
* Find the rush.json location and return the path, or undefined if a rush.json can't be found.
|
|
11
|
+
*
|
|
12
|
+
* @privateRemarks
|
|
13
|
+
* Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function tryFindRushJsonLocation(startingFolder: string): string | undefined;
|
|
16
|
+
export declare function _require<TResult>(moduleName: string): TResult;
|
|
17
|
+
/**
|
|
18
|
+
* Require `@microsoft/rush-lib` under the specified folder path.
|
|
19
|
+
*/
|
|
20
|
+
export declare function requireRushLibUnderFolderPath(folderPath: string): RushLibModuleType;
|
|
21
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,eAAO,MAAM,aAAa,EAAE,qBAA6C,CAAC;AAC1E,eAAO,MAAM,0BAA0B,EAAE,OAAO,wBAAwB,CAAC,aAAgC,CAAC;AAE1G,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC9C;AAED,eAAO,MAAM,UAAU,EAAE,WAExB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAoBlF;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAU7D;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAOnF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.requireRushLibUnderFolderPath = exports._require = exports.tryFindRushJsonLocation = exports.sdkContext = exports.RUSH_LIB_PATH_ENV_VAR_NAME = exports.RUSH_LIB_NAME = void 0;
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
31
|
+
exports.RUSH_LIB_NAME = '@microsoft/rush-lib';
|
|
32
|
+
exports.RUSH_LIB_PATH_ENV_VAR_NAME = '_RUSH_LIB_PATH';
|
|
33
|
+
exports.sdkContext = {
|
|
34
|
+
rushLibModule: undefined
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Find the rush.json location and return the path, or undefined if a rush.json can't be found.
|
|
38
|
+
*
|
|
39
|
+
* @privateRemarks
|
|
40
|
+
* Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`.
|
|
41
|
+
*/
|
|
42
|
+
function tryFindRushJsonLocation(startingFolder) {
|
|
43
|
+
let currentFolder = startingFolder;
|
|
44
|
+
// Look upwards at parent folders until we find a folder containing rush.json
|
|
45
|
+
for (let i = 0; i < 10; ++i) {
|
|
46
|
+
const rushJsonFilename = path.join(currentFolder, 'rush.json');
|
|
47
|
+
if (node_core_library_1.FileSystem.exists(rushJsonFilename)) {
|
|
48
|
+
return rushJsonFilename;
|
|
49
|
+
}
|
|
50
|
+
const parentFolder = path.dirname(currentFolder);
|
|
51
|
+
if (parentFolder === currentFolder) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
currentFolder = parentFolder;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
exports.tryFindRushJsonLocation = tryFindRushJsonLocation;
|
|
59
|
+
function _require(moduleName) {
|
|
60
|
+
if (typeof __non_webpack_require__ === 'function') {
|
|
61
|
+
// If this library has been bundled with Webpack, we need to call the real `require` function
|
|
62
|
+
// that doesn't get turned into a `__webpack_require__` statement.
|
|
63
|
+
// `__non_webpack_require__` is a Webpack macro that gets turned into a `require` statement
|
|
64
|
+
// during bundling.
|
|
65
|
+
return __non_webpack_require__(moduleName);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return require(moduleName);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports._require = _require;
|
|
72
|
+
/**
|
|
73
|
+
* Require `@microsoft/rush-lib` under the specified folder path.
|
|
74
|
+
*/
|
|
75
|
+
function requireRushLibUnderFolderPath(folderPath) {
|
|
76
|
+
const rushLibModulePath = node_core_library_1.Import.resolveModule({
|
|
77
|
+
modulePath: exports.RUSH_LIB_NAME,
|
|
78
|
+
baseFolderPath: folderPath
|
|
79
|
+
});
|
|
80
|
+
return _require(rushLibModulePath);
|
|
81
|
+
}
|
|
82
|
+
exports.requireRushLibUnderFolderPath = requireRushLibUnderFolderPath;
|
|
83
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +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,GAAkD,gBAAgB,CAAC;AAQ7F,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"]}
|
package/lib-shim/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8MA;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAO1E"}
|
package/lib-shim/index.js
CHANGED
|
@@ -29,59 +29,49 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports._rushSdk_loadInternalModule = void 0;
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
31
|
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
32
|
-
const
|
|
33
|
-
const RUSH_LIB_PATH_ENV_VAR_NAME = '_RUSH_LIB_PATH';
|
|
32
|
+
const helpers_1 = require("./helpers");
|
|
34
33
|
const verboseEnabled = typeof process !== 'undefined' && process.env.RUSH_SDK_DEBUG === '1';
|
|
35
34
|
const terminal = new node_core_library_1.Terminal(new node_core_library_1.ConsoleTerminalProvider({
|
|
36
35
|
verboseEnabled
|
|
37
36
|
}));
|
|
38
|
-
|
|
39
|
-
if (typeof __non_webpack_require__ === 'function') {
|
|
40
|
-
// If this library has been bundled with Webpack, we need to call the real `require` function
|
|
41
|
-
// that doesn't get turned into a `__webpack_require__` statement.
|
|
42
|
-
// `__non_webpack_require__` is a Webpack macro that gets turned into a `require` statement
|
|
43
|
-
// during bundling.
|
|
44
|
-
return __non_webpack_require__(moduleName);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return require(moduleName);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
37
|
+
let errorMessage = '';
|
|
50
38
|
// SCENARIO 1: Rush's PluginManager has initialized "rush-sdk" with Rush's own instance of rush-lib.
|
|
51
39
|
// The Rush host process will assign "global.___rush___rushLibModule" before loading the plugin.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
41
|
+
helpers_1.sdkContext.rushLibModule =
|
|
42
|
+
global.___rush___rushLibModule ||
|
|
43
|
+
global.___rush___rushLibModuleFromEnvironment ||
|
|
44
|
+
global.___rush___rushLibModuleFromInstallAndRunRush;
|
|
45
|
+
}
|
|
56
46
|
// SCENARIO 2: The project importing "rush-sdk" has installed its own instance of "rush-lib"
|
|
57
47
|
// as a package.json dependency. For example, this is used by the Jest tests for Rush plugins.
|
|
58
|
-
if (rushLibModule === undefined) {
|
|
48
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
59
49
|
const importingPath = (_a = module === null || module === void 0 ? void 0 : module.parent) === null || _a === void 0 ? void 0 : _a.filename;
|
|
60
50
|
if (importingPath) {
|
|
61
51
|
const callerPackageFolder = node_core_library_1.PackageJsonLookup.instance.tryGetPackageFolderFor(importingPath);
|
|
62
52
|
if (callerPackageFolder !== undefined) {
|
|
63
|
-
const callerPackageJson = _require(path.join(callerPackageFolder, 'package.json'));
|
|
53
|
+
const callerPackageJson = (0, helpers_1._require)(path.join(callerPackageFolder, 'package.json'));
|
|
64
54
|
// Does the caller properly declare a dependency on rush-lib?
|
|
65
|
-
if ((callerPackageJson.dependencies && callerPackageJson.dependencies[RUSH_LIB_NAME] !== undefined) ||
|
|
55
|
+
if ((callerPackageJson.dependencies && callerPackageJson.dependencies[helpers_1.RUSH_LIB_NAME] !== undefined) ||
|
|
66
56
|
(callerPackageJson.devDependencies &&
|
|
67
|
-
callerPackageJson.devDependencies[RUSH_LIB_NAME] !== undefined) ||
|
|
57
|
+
callerPackageJson.devDependencies[helpers_1.RUSH_LIB_NAME] !== undefined) ||
|
|
68
58
|
(callerPackageJson.peerDependencies &&
|
|
69
|
-
callerPackageJson.peerDependencies[RUSH_LIB_NAME] !== undefined)) {
|
|
59
|
+
callerPackageJson.peerDependencies[helpers_1.RUSH_LIB_NAME] !== undefined)) {
|
|
70
60
|
// Try to resolve rush-lib from the caller's folder
|
|
71
|
-
terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from caller package`);
|
|
61
|
+
terminal.writeVerboseLine(`Try to load ${helpers_1.RUSH_LIB_NAME} from caller package`);
|
|
72
62
|
try {
|
|
73
|
-
rushLibModule = requireRushLibUnderFolderPath(callerPackageFolder);
|
|
63
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(callerPackageFolder);
|
|
74
64
|
}
|
|
75
65
|
catch (error) {
|
|
76
66
|
// If we fail to resolve it, ignore the error
|
|
77
|
-
terminal.writeVerboseLine(`Failed to load ${RUSH_LIB_NAME} from caller package`);
|
|
67
|
+
terminal.writeVerboseLine(`Failed to load ${helpers_1.RUSH_LIB_NAME} from caller package`);
|
|
78
68
|
}
|
|
79
69
|
// If two different libraries invoke `rush-sdk`, and one of them provides "rush-lib"
|
|
80
70
|
// then the first version to be loaded wins. We do not support side-by-side instances of "rush-lib".
|
|
81
|
-
if (rushLibModule !== undefined) {
|
|
71
|
+
if (helpers_1.sdkContext.rushLibModule !== undefined) {
|
|
82
72
|
// to track which scenario is active and how it got initialized.
|
|
83
|
-
global.___rush___rushLibModule = rushLibModule;
|
|
84
|
-
terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from caller`);
|
|
73
|
+
global.___rush___rushLibModule = helpers_1.sdkContext.rushLibModule;
|
|
74
|
+
terminal.writeVerboseLine(`Loaded ${helpers_1.RUSH_LIB_NAME} from caller`);
|
|
85
75
|
}
|
|
86
76
|
}
|
|
87
77
|
}
|
|
@@ -89,29 +79,29 @@ if (rushLibModule === undefined) {
|
|
|
89
79
|
}
|
|
90
80
|
// SCENARIO 3: A tool or script has been invoked as a child process by an instance of "rush-lib" and can use the
|
|
91
81
|
// version that invoked it. In this case, use process.env._RUSH_LIB_PATH to find "rush-lib".
|
|
92
|
-
if (rushLibModule === undefined) {
|
|
93
|
-
const rushLibPath = process.env[RUSH_LIB_PATH_ENV_VAR_NAME];
|
|
82
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
83
|
+
const rushLibPath = process.env[helpers_1.RUSH_LIB_PATH_ENV_VAR_NAME];
|
|
94
84
|
if (rushLibPath) {
|
|
95
|
-
terminal.writeVerboseLine(`Try to load ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME} from caller package`);
|
|
85
|
+
terminal.writeVerboseLine(`Try to load ${helpers_1.RUSH_LIB_NAME} from process.env.${helpers_1.RUSH_LIB_PATH_ENV_VAR_NAME} from caller package`);
|
|
96
86
|
try {
|
|
97
|
-
rushLibModule = _require(rushLibPath);
|
|
87
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1._require)(rushLibPath);
|
|
98
88
|
}
|
|
99
89
|
catch (error) {
|
|
100
90
|
// Log this as a warning, since it is unexpected to define an incorrect value of the variable.
|
|
101
|
-
terminal.writeWarningLine(`Failed to load ${RUSH_LIB_NAME} via process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`);
|
|
91
|
+
terminal.writeWarningLine(`Failed to load ${helpers_1.RUSH_LIB_NAME} via process.env.${helpers_1.RUSH_LIB_PATH_ENV_VAR_NAME}`);
|
|
102
92
|
}
|
|
103
|
-
if (rushLibModule !== undefined) {
|
|
93
|
+
if (helpers_1.sdkContext.rushLibModule !== undefined) {
|
|
104
94
|
// to track which scenario is active and how it got initialized.
|
|
105
|
-
global.___rush___rushLibModuleFromEnvironment = rushLibModule;
|
|
106
|
-
terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} from process.env.${RUSH_LIB_PATH_ENV_VAR_NAME}`);
|
|
95
|
+
global.___rush___rushLibModuleFromEnvironment = helpers_1.sdkContext.rushLibModule;
|
|
96
|
+
terminal.writeVerboseLine(`Loaded ${helpers_1.RUSH_LIB_NAME} from process.env.${helpers_1.RUSH_LIB_PATH_ENV_VAR_NAME}`);
|
|
107
97
|
}
|
|
108
98
|
}
|
|
109
99
|
}
|
|
110
100
|
// SCENARIO 4: A standalone tool or script depends on "rush-sdk", and is meant to be used inside a monorepo folder.
|
|
111
101
|
// In this case, we can use install-run-rush.js to obtain the appropriate rush-lib version for the monorepo.
|
|
112
|
-
if (rushLibModule === undefined) {
|
|
102
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
113
103
|
try {
|
|
114
|
-
const rushJsonPath = tryFindRushJsonLocation(process.cwd());
|
|
104
|
+
const rushJsonPath = (0, helpers_1.tryFindRushJsonLocation)(process.cwd());
|
|
115
105
|
if (!rushJsonPath) {
|
|
116
106
|
throw new Error('Unable to find rush.json in the current folder or its parent folders.\n' +
|
|
117
107
|
'This tool is meant to be invoked from a working directory inside a Rush repository.');
|
|
@@ -122,34 +112,34 @@ if (rushLibModule === undefined) {
|
|
|
122
112
|
const installRunNodeModuleFolder = path.join(monorepoRoot, `common/temp/install-run/@microsoft+rush@${rushVersion}`);
|
|
123
113
|
try {
|
|
124
114
|
// First, try to load the version of "rush-lib" that was installed by install-run-rush.js
|
|
125
|
-
terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush`);
|
|
126
|
-
rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
|
|
115
|
+
terminal.writeVerboseLine(`Trying to load ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush`);
|
|
116
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(installRunNodeModuleFolder);
|
|
127
117
|
}
|
|
128
118
|
catch (e) {
|
|
129
119
|
let installAndRunRushStderrContent = '';
|
|
130
120
|
try {
|
|
131
121
|
const installAndRunRushJSPath = path.join(monorepoRoot, 'common/scripts/install-run-rush.js');
|
|
132
122
|
terminal.writeLine('The Rush engine has not been installed yet. Invoking install-run-rush.js...');
|
|
133
|
-
const
|
|
123
|
+
const installAndRunRushProcess = node_core_library_1.Executable.spawnSync('node', [installAndRunRushJSPath, '--help'], {
|
|
134
124
|
stdio: 'pipe'
|
|
135
125
|
});
|
|
136
|
-
installAndRunRushStderrContent =
|
|
137
|
-
if (
|
|
138
|
-
throw new Error(`The ${RUSH_LIB_NAME} package failed to install`);
|
|
126
|
+
installAndRunRushStderrContent = installAndRunRushProcess.stderr;
|
|
127
|
+
if (installAndRunRushProcess.status !== 0) {
|
|
128
|
+
throw new Error(`The ${helpers_1.RUSH_LIB_NAME} package failed to install`);
|
|
139
129
|
}
|
|
140
130
|
// Retry to load "rush-lib" after install-run-rush run
|
|
141
|
-
terminal.writeVerboseLine(`Trying to load ${RUSH_LIB_NAME} installed by install-run-rush a second time`);
|
|
142
|
-
rushLibModule = requireRushLibUnderFolderPath(installRunNodeModuleFolder);
|
|
131
|
+
terminal.writeVerboseLine(`Trying to load ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush a second time`);
|
|
132
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(installRunNodeModuleFolder);
|
|
143
133
|
}
|
|
144
134
|
catch (e) {
|
|
145
135
|
console.error(`${installAndRunRushStderrContent}`);
|
|
146
|
-
throw new Error(`The ${RUSH_LIB_NAME} package failed to load`);
|
|
136
|
+
throw new Error(`The ${helpers_1.RUSH_LIB_NAME} package failed to load`);
|
|
147
137
|
}
|
|
148
138
|
}
|
|
149
|
-
if (rushLibModule !== undefined) {
|
|
139
|
+
if (helpers_1.sdkContext.rushLibModule !== undefined) {
|
|
150
140
|
// to track which scenario is active and how it got initialized.
|
|
151
|
-
global.___rush___rushLibModuleFromInstallAndRunRush = rushLibModule;
|
|
152
|
-
terminal.writeVerboseLine(`Loaded ${RUSH_LIB_NAME} installed by install-run-rush`);
|
|
141
|
+
global.___rush___rushLibModuleFromInstallAndRunRush = helpers_1.sdkContext.rushLibModule;
|
|
142
|
+
terminal.writeVerboseLine(`Loaded ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush`);
|
|
153
143
|
}
|
|
154
144
|
}
|
|
155
145
|
catch (e) {
|
|
@@ -157,7 +147,7 @@ if (rushLibModule === undefined) {
|
|
|
157
147
|
errorMessage = e.message;
|
|
158
148
|
}
|
|
159
149
|
}
|
|
160
|
-
if (rushLibModule === undefined) {
|
|
150
|
+
if (helpers_1.sdkContext.rushLibModule === undefined) {
|
|
161
151
|
// This error indicates that a project is trying to import "@rushstack/rush-sdk", but the Rush engine
|
|
162
152
|
// instance cannot be found. If you are writing Jest tests for a Rush plugin, add "@microsoft/rush-lib"
|
|
163
153
|
// to the devDependencies for your project.
|
|
@@ -167,9 +157,9 @@ ${errorMessage}
|
|
|
167
157
|
process.exit(1);
|
|
168
158
|
}
|
|
169
159
|
// Based on TypeScript's __exportStar()
|
|
170
|
-
for (const property in rushLibModule) {
|
|
160
|
+
for (const property in helpers_1.sdkContext.rushLibModule) {
|
|
171
161
|
if (property !== 'default' && !exports.hasOwnProperty(property)) {
|
|
172
|
-
const rushLibModuleForClosure = rushLibModule;
|
|
162
|
+
const rushLibModuleForClosure = helpers_1.sdkContext.rushLibModule;
|
|
173
163
|
// Based on TypeScript's __createBinding()
|
|
174
164
|
Object.defineProperty(exports, property, {
|
|
175
165
|
enumerable: true,
|
|
@@ -189,36 +179,4 @@ function _rushSdk_loadInternalModule(srcImportPath) {
|
|
|
189
179
|
return exports._RushInternals.loadModule(srcImportPath);
|
|
190
180
|
}
|
|
191
181
|
exports._rushSdk_loadInternalModule = _rushSdk_loadInternalModule;
|
|
192
|
-
/**
|
|
193
|
-
* Require `@microsoft/rush-lib` under the specified folder path.
|
|
194
|
-
*/
|
|
195
|
-
function requireRushLibUnderFolderPath(folderPath) {
|
|
196
|
-
const rushLibModulePath = node_core_library_1.Import.resolveModule({
|
|
197
|
-
modulePath: RUSH_LIB_NAME,
|
|
198
|
-
baseFolderPath: folderPath
|
|
199
|
-
});
|
|
200
|
-
return _require(rushLibModulePath);
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Find the rush.json location and return the path, or undefined if a rush.json can't be found.
|
|
204
|
-
*
|
|
205
|
-
* @privateRemarks
|
|
206
|
-
* Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`.
|
|
207
|
-
*/
|
|
208
|
-
function tryFindRushJsonLocation(startingFolder) {
|
|
209
|
-
let currentFolder = startingFolder;
|
|
210
|
-
// Look upwards at parent folders until we find a folder containing rush.json
|
|
211
|
-
for (let i = 0; i < 10; ++i) {
|
|
212
|
-
const rushJsonFilename = path.join(currentFolder, 'rush.json');
|
|
213
|
-
if (node_core_library_1.FileSystem.exists(rushJsonFilename)) {
|
|
214
|
-
return rushJsonFilename;
|
|
215
|
-
}
|
|
216
|
-
const parentFolder = path.dirname(currentFolder);
|
|
217
|
-
if (parentFolder === currentFolder) {
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
currentFolder = parentFolder;
|
|
221
|
-
}
|
|
222
|
-
return undefined;
|
|
223
|
-
}
|
|
224
182
|
//# sourceMappingURL=index.js.map
|
package/lib-shim/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,oEAUsC;AAItC,MAAM,aAAa,GAA0B,qBAAqB,CAAC;AACnE,MAAM,0BAA0B,GAAkD,gBAAgB,CAAC;AAEnG,MAAM,cAAc,GAAY,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,GAAG,CAAC;AACrG,MAAM,QAAQ,G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,CAAC,cAAc,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAC1D,CAAC;AAPD,kEAOC;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';\nimport type { EnvironmentVariableNames } from '@microsoft/rush-lib';\n\nconst RUSH_LIB_NAME: '@microsoft/rush-lib' = '@microsoft/rush-lib';\nconst RUSH_LIB_PATH_ENV_VAR_NAME: typeof EnvironmentVariableNames.RUSH_LIB_PATH = '_RUSH_LIB_PATH';\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___rushLibModuleFromEnvironment?: 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 ||\n global.___rush___rushLibModuleFromEnvironment ||\n 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 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 (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 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 (rushLibModule !== undefined) {\n // to track which scenario is active and how it got initialized.\n global.___rush___rushLibModuleFromEnvironment = 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 (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 * 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\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 }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U,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 JsonObject,\n 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 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: NodeJS.Global &\n 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 (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 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 (e) {\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 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"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Type of {@link ISdkCallbackEvent.logMessage}
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface IProgressBarCallbackLogMessage {
|
|
7
|
+
/**
|
|
8
|
+
* A status message to print in the log window, or `undefined` if there are
|
|
9
|
+
* no further messages. This string may contain newlines.
|
|
10
|
+
*/
|
|
11
|
+
text: string;
|
|
12
|
+
/**
|
|
13
|
+
* The type of message. More message types may be added in the future.
|
|
14
|
+
*/
|
|
15
|
+
kind: 'info' | 'debug';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Event options for {@link ILoadSdkAsyncOptions.onNotifyEvent}
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export interface ISdkCallbackEvent {
|
|
22
|
+
/**
|
|
23
|
+
* Allows the caller to display log information about the operation.
|
|
24
|
+
*/
|
|
25
|
+
logMessage: IProgressBarCallbackLogMessage | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Allows the caller to display a progress bar for long-running operations.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* If a long-running operation is required, then `progressPercent` will
|
|
31
|
+
* start at 0.0 and count upwards and finish at 100.0 if the operation completes
|
|
32
|
+
* successfully. If the long-running operation has not yet started, or
|
|
33
|
+
* is not required, then the value will be `undefined`.
|
|
34
|
+
*/
|
|
35
|
+
progressPercent: number | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Type of {@link ILoadSdkAsyncOptions.onNotifyEvent}
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export type SdkNotifyEventCallback = (sdkEvent: ISdkCallbackEvent) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Options for {@link RushSdkLoader.loadAsync}
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export interface ILoadSdkAsyncOptions {
|
|
47
|
+
/**
|
|
48
|
+
* The folder to start from when searching for the Rush workspace configuration.
|
|
49
|
+
* If this folder does not contain a `rush.json` file, then each parent folder
|
|
50
|
+
* will be searched. If `rush.json` is not found, then the SDK fails to load.
|
|
51
|
+
*/
|
|
52
|
+
rushJsonSearchFolder?: string;
|
|
53
|
+
/**
|
|
54
|
+
* A cancellation token that the caller can use to prematurely abort the operation.
|
|
55
|
+
*/
|
|
56
|
+
abortSignal?: AbortSignal;
|
|
57
|
+
/**
|
|
58
|
+
* Allows the caller to monitor the progress of the operation.
|
|
59
|
+
*/
|
|
60
|
+
onNotifyEvent?: SdkNotifyEventCallback;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Exposes operations that control how the `@microsoft/rush-lib` engine is
|
|
64
|
+
* located and loaded.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export declare class RushSdkLoader {
|
|
68
|
+
/**
|
|
69
|
+
* Throws an "AbortError" exception if abortSignal.aborted is true.
|
|
70
|
+
*/
|
|
71
|
+
private static _checkForCancel;
|
|
72
|
+
/**
|
|
73
|
+
* Returns true if the Rush engine has already been loaded.
|
|
74
|
+
*/
|
|
75
|
+
static get isLoaded(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Manually load the Rush engine based on rush.json found for `rushJsonSearchFolder`.
|
|
78
|
+
* Throws an exception if {@link RushSdkLoader.isLoaded} is already `true`.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* This API supports an callback that can be used display a progress bar,
|
|
82
|
+
* log of operations, and allow the operation to be canceled prematurely.
|
|
83
|
+
*/
|
|
84
|
+
static loadAsync(options?: ILoadSdkAsyncOptions): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAsBA;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,UAAU,EAAE,8BAA8B,GAAG,SAAS,CAAC;IAEvD;;;;;;;;OAQG;IACH,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAE3E;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;OAEG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAC;CACxC;AAED;;;;GAIG;AACH,qBAAa,aAAa;IACxB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAwB9B;;OAEG;IACH,WAAkB,QAAQ,IAAI,OAAO,CAEpC;IAED;;;;;;;OAOG;WACiB,SAAS,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CA+I7E"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.RushSdkLoader = void 0;
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
31
|
+
const helpers_1 = require("./helpers");
|
|
32
|
+
/**
|
|
33
|
+
* Exposes operations that control how the `@microsoft/rush-lib` engine is
|
|
34
|
+
* located and loaded.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
class RushSdkLoader {
|
|
38
|
+
/**
|
|
39
|
+
* Throws an "AbortError" exception if abortSignal.aborted is true.
|
|
40
|
+
*/
|
|
41
|
+
static _checkForCancel(abortSignal, onNotifyEvent, progressPercent) {
|
|
42
|
+
if (!abortSignal.aborted) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (onNotifyEvent) {
|
|
46
|
+
onNotifyEvent({
|
|
47
|
+
logMessage: {
|
|
48
|
+
kind: 'info',
|
|
49
|
+
text: `The operation was canceled`
|
|
50
|
+
},
|
|
51
|
+
progressPercent
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const error = new Error('The operation was canceled');
|
|
55
|
+
error.name = 'AbortError';
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns true if the Rush engine has already been loaded.
|
|
60
|
+
*/
|
|
61
|
+
static get isLoaded() {
|
|
62
|
+
return helpers_1.sdkContext.rushLibModule !== undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Manually load the Rush engine based on rush.json found for `rushJsonSearchFolder`.
|
|
66
|
+
* Throws an exception if {@link RushSdkLoader.isLoaded} is already `true`.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* This API supports an callback that can be used display a progress bar,
|
|
70
|
+
* log of operations, and allow the operation to be canceled prematurely.
|
|
71
|
+
*/
|
|
72
|
+
static async loadAsync(options) {
|
|
73
|
+
// SCENARIO 5: The rush-lib engine is loaded manually using rushSdkLoader.loadAsync().
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
if (!options) {
|
|
76
|
+
options = {};
|
|
77
|
+
}
|
|
78
|
+
if (RushSdkLoader.isLoaded) {
|
|
79
|
+
throw new Error('RushSdkLoader.loadAsync() failed because the Rush engine has already been loaded');
|
|
80
|
+
}
|
|
81
|
+
const onNotifyEvent = options.onNotifyEvent;
|
|
82
|
+
let progressPercent = undefined;
|
|
83
|
+
const abortSignal = (_a = options.abortSignal) !== null && _a !== void 0 ? _a : { aborted: false };
|
|
84
|
+
try {
|
|
85
|
+
const rushJsonSearchFolder = (_b = options.rushJsonSearchFolder) !== null && _b !== void 0 ? _b : process.cwd();
|
|
86
|
+
if (onNotifyEvent) {
|
|
87
|
+
onNotifyEvent({
|
|
88
|
+
logMessage: {
|
|
89
|
+
kind: 'debug',
|
|
90
|
+
text: `Searching for rush.json starting from: ` + rushJsonSearchFolder
|
|
91
|
+
},
|
|
92
|
+
progressPercent
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const rushJsonPath = (0, helpers_1.tryFindRushJsonLocation)(rushJsonSearchFolder);
|
|
96
|
+
if (!rushJsonPath) {
|
|
97
|
+
throw new Error('Unable to find rush.json in the specified folder or its parent folders:\n' +
|
|
98
|
+
`${rushJsonSearchFolder}\n`);
|
|
99
|
+
}
|
|
100
|
+
const monorepoRoot = path.dirname(rushJsonPath);
|
|
101
|
+
const rushJson = await node_core_library_1.JsonFile.loadAsync(rushJsonPath);
|
|
102
|
+
const { rushVersion } = rushJson;
|
|
103
|
+
const installRunNodeModuleFolder = path.join(monorepoRoot, `common/temp/install-run/@microsoft+rush@${rushVersion}`);
|
|
104
|
+
try {
|
|
105
|
+
// First, try to load the version of "rush-lib" that was installed by install-run-rush.js
|
|
106
|
+
if (onNotifyEvent) {
|
|
107
|
+
onNotifyEvent({
|
|
108
|
+
logMessage: {
|
|
109
|
+
kind: 'info',
|
|
110
|
+
text: `Trying to load ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush`
|
|
111
|
+
},
|
|
112
|
+
progressPercent
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(installRunNodeModuleFolder);
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
let installAndRunRushStderrContent = '';
|
|
119
|
+
try {
|
|
120
|
+
const installAndRunRushJSPath = path.join(monorepoRoot, 'common/scripts/install-run-rush.js');
|
|
121
|
+
if (onNotifyEvent) {
|
|
122
|
+
onNotifyEvent({
|
|
123
|
+
logMessage: {
|
|
124
|
+
kind: 'info',
|
|
125
|
+
text: 'The Rush engine has not been installed yet. Invoking install-run-rush.js...'
|
|
126
|
+
},
|
|
127
|
+
progressPercent
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// Start the installation
|
|
131
|
+
progressPercent = 0;
|
|
132
|
+
const installAndRunRushProcess = node_core_library_1.Executable.spawnSync('node', [installAndRunRushJSPath, '--help'], {
|
|
133
|
+
stdio: 'pipe'
|
|
134
|
+
});
|
|
135
|
+
installAndRunRushStderrContent = installAndRunRushProcess.stderr;
|
|
136
|
+
if (installAndRunRushProcess.status !== 0) {
|
|
137
|
+
throw new Error(`The ${helpers_1.RUSH_LIB_NAME} package failed to install`);
|
|
138
|
+
}
|
|
139
|
+
RushSdkLoader._checkForCancel(abortSignal, onNotifyEvent, progressPercent);
|
|
140
|
+
// TODO: Implement incremental progress updates
|
|
141
|
+
progressPercent = 90;
|
|
142
|
+
// Retry to load "rush-lib" after install-run-rush run
|
|
143
|
+
if (onNotifyEvent) {
|
|
144
|
+
onNotifyEvent({
|
|
145
|
+
logMessage: {
|
|
146
|
+
kind: 'debug',
|
|
147
|
+
text: `Trying to load ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush a second time`
|
|
148
|
+
},
|
|
149
|
+
progressPercent
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
helpers_1.sdkContext.rushLibModule = (0, helpers_1.requireRushLibUnderFolderPath)(installRunNodeModuleFolder);
|
|
153
|
+
progressPercent = 100;
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
console.error(`${installAndRunRushStderrContent}`);
|
|
157
|
+
throw new Error(`The ${helpers_1.RUSH_LIB_NAME} package failed to load`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (helpers_1.sdkContext.rushLibModule !== undefined) {
|
|
161
|
+
// to track which scenario is active and how it got initialized.
|
|
162
|
+
global.___rush___rushLibModuleFromInstallAndRunRush = helpers_1.sdkContext.rushLibModule;
|
|
163
|
+
if (onNotifyEvent) {
|
|
164
|
+
onNotifyEvent({
|
|
165
|
+
logMessage: {
|
|
166
|
+
kind: 'debug',
|
|
167
|
+
text: `Loaded ${helpers_1.RUSH_LIB_NAME} installed by install-run-rush`
|
|
168
|
+
},
|
|
169
|
+
progressPercent
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
if (onNotifyEvent) {
|
|
176
|
+
onNotifyEvent({
|
|
177
|
+
logMessage: {
|
|
178
|
+
kind: 'info',
|
|
179
|
+
text: 'The operation failed: ' + ((_c = e.message) !== null && _c !== void 0 ? _c : 'An unknown error occurred')
|
|
180
|
+
},
|
|
181
|
+
progressPercent
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
throw e;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.RushSdkLoader = RushSdkLoader;
|
|
189
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAE7B,oEAAgF;AAEhF,uCAMmB;AA6EnB;;;;GAIG;AACH,MAAa,aAAa;IACxB;;OAEG;IACK,MAAM,CAAC,eAAe,CAC5B,WAAwB,EACxB,aAAiD,EACjD,eAAmC;QAEnC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;YACxB,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;;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GAAG,IAAA,uCAA6B,EAAC,0BAA0B,CAAC,CAAC;oBAErF,eAAe,GAAG,GAAG,CAAC;iBACvB;gBAAC,OAAO,CAAC,EAAE;oBACV,OAAO,CAAC,KAAK,CAAC,GAAG,8BAA8B,EAAE,CAAC,CAAC;oBACnD,MAAM,IAAI,KAAK,CAAC,OAAO,uBAAa,yBAAyB,CAAC,CAAC;iBAChE;aACF;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;AA1LD,sCA0LC","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, JsonObject, Executable } from '@rushstack/node-core-library';\n\nimport {\n tryFindRushJsonLocation,\n RUSH_LIB_NAME,\n RushLibModuleType,\n requireRushLibUnderFolderPath,\n sdkContext\n} from './helpers';\n\ndeclare const global: NodeJS.Global &\n 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 = options.abortSignal ?? { aborted: false };\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 (e) {\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 RushSdkLoader._checkForCancel(abortSignal, onNotifyEvent, progressPercent);\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 (e) {\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/rush-sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.101.0",
|
|
4
4
|
"description": "An API for interacting with the Rush engine",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,22 +10,34 @@
|
|
|
10
10
|
"homepage": "https://rushjs.io",
|
|
11
11
|
"main": "lib-shim/index.js",
|
|
12
12
|
"typings": "dist/rush-lib.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./lib-shim/index.js",
|
|
15
|
+
"./loader": "./lib-shim/loader.js"
|
|
16
|
+
},
|
|
17
|
+
"typesVersions": {
|
|
18
|
+
"*": {
|
|
19
|
+
"loader": [
|
|
20
|
+
"./dist/loader.d.ts"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
13
24
|
"license": "MIT",
|
|
14
25
|
"dependencies": {
|
|
15
26
|
"@types/node-fetch": "2.6.2",
|
|
16
27
|
"tapable": "2.2.1",
|
|
17
|
-
"@rushstack/node-core-library": "3.59.
|
|
28
|
+
"@rushstack/node-core-library": "3.59.7"
|
|
18
29
|
},
|
|
19
30
|
"devDependencies": {
|
|
31
|
+
"@types/node": "14.18.36",
|
|
20
32
|
"@types/semver": "7.5.0",
|
|
21
33
|
"@types/webpack-env": "1.18.0",
|
|
22
|
-
"@microsoft/rush-lib": "5.
|
|
23
|
-
"@rushstack/eslint-config": "3.3.
|
|
24
|
-
"@rushstack/heft": "0.58.
|
|
25
|
-
"@rushstack/heft-node-rig": "2.2.
|
|
26
|
-
"@rushstack/stream-collator": "4.0.
|
|
27
|
-
"@rushstack/ts-command-line": "4.15.
|
|
28
|
-
"@rushstack/terminal": "0.5.
|
|
34
|
+
"@microsoft/rush-lib": "5.101.0",
|
|
35
|
+
"@rushstack/eslint-config": "3.3.3",
|
|
36
|
+
"@rushstack/heft": "0.58.2",
|
|
37
|
+
"@rushstack/heft-node-rig": "2.2.22",
|
|
38
|
+
"@rushstack/stream-collator": "4.0.262",
|
|
39
|
+
"@rushstack/ts-command-line": "4.15.2",
|
|
40
|
+
"@rushstack/terminal": "0.5.37"
|
|
29
41
|
},
|
|
30
42
|
"scripts": {
|
|
31
43
|
"build": "heft build --clean",
|