-
Notifications
You must be signed in to change notification settings - Fork 657
[rush-sdk] Introduce a proxy API for customizing how rush-lib is loaded #4270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e7a31f4
Extract some logic from index.ts into helpers.ts (pure refactoring)
octogonz 3b2310f
Add an entry point require("@rushstack/rush-sdk/proxy") that returns …
octogonz da98590
Fix a missing dependency
octogonz eee0941
Enable API Extractor .d.ts rollup
octogonz d6ca4d1
rush change
octogonz 656cb8e
Rename startingFolder to rushJsonSearchFolder
octogonz 77ee306
Fix the VS Code extension
octogonz 4f69c50
Clarify that rush-vscode-command-webview does not publish to NPM
octogonz d1c0bda
Bump the version
octogonz e2388af
Fix Jest tests
octogonz 39075de
PR feedback
octogonz 87e459b
Rebuild install-test-workspace
octogonz 3934344
Based on PR feedback from David, I removed the ISdkCallbackEvent.stat…
octogonz ee469f5
PR feedback: Triggering ILoadSdkAsyncOptions.abortSignal now throws a…
octogonz aa3781c
PR feedback
octogonz 3c21aba
PR feedback: Rename "proxy" to "loader"
octogonz 069260a
Introduce RushSdkLoader.alreadyLoaded, where RushSdkLoader.loadAsync(…
octogonz 7a69cb8
Improve IProgressBarCallbackLogMessage API
octogonz 8f4339e
Add README.md docs
octogonz e2c60d7
PR feedback
octogonz ab411e3
PR feedback
octogonz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 8 additions & 8 deletions
16
build-tests/install-test-workspace/workspace/common/pnpm-lock.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
common/changes/@microsoft/rush/octogonz-rush-sdk-proxy_2023-08-04-23-41.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@microsoft/rush", | ||
| "comment": "@rushstack/rush-sdk now exposes a proxy API for customizing how the Rush engine is loaded and monitoring progress", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@microsoft/rush" | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| ## API Report File for "@rushstack/rush-sdk" | ||
|
|
||
| > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
|
|
||
| ```ts | ||
|
|
||
| /// <reference types="node" /> | ||
|
|
||
| // @public | ||
| export interface ILoadSdkAsyncOptions { | ||
| abortSignal?: AbortSignal; | ||
| onNotifyEvent?: SdkNotifyEventCallback; | ||
| rushJsonSearchFolder?: string; | ||
| } | ||
|
|
||
| // @public | ||
| export interface IProgressBarCallbackLogMessage { | ||
| message: string; | ||
| messageType: 'info' | 'debug'; | ||
| } | ||
|
|
||
| // @public | ||
| export interface ISdkCallbackEvent { | ||
| logMessage: IProgressBarCallbackLogMessage | undefined; | ||
| progressBarPercent: number | undefined; | ||
| state: SdkCallbackState; | ||
| } | ||
|
|
||
| // @public | ||
| export namespace rushSdkProxy { | ||
| export function loadAsync(options?: ILoadSdkAsyncOptions): Promise<void>; | ||
| } | ||
|
|
||
| // @public | ||
| export type SdkCallbackState = | ||
| /** | ||
| * The task has started and is still running. | ||
| */ | ||
| 'running' | ||
| /** | ||
| * The task has completed successfully. No further events will be fired. | ||
| */ | ||
| | 'succeeded' | ||
| /** | ||
| * The task was aborted by the caller. No further events will be fired. | ||
| */ | ||
| | 'aborted' | ||
| /** | ||
| * The task has failed due to an error. No further events will be fired. | ||
| */ | ||
| | 'failed'; | ||
|
|
||
| // @public | ||
| export type SdkNotifyEventCallback = (sdkEvent: ISdkCallbackEvent) => void; | ||
|
|
||
| // (No @packageDocumentation comment for this package) | ||
|
|
||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
|
|
||
| "mainEntryPointFilePath": "<projectFolder>/lib-shim/proxy.d.ts", | ||
|
|
||
| "apiReport": { | ||
| "enabled": true, | ||
| "reportFolder": "../../../common/reviews/api" | ||
| }, | ||
|
|
||
| "docModel": { | ||
| "enabled": false, | ||
| "apiJsonFilePath": "../../../common/temp/api/<unscopedPackageName>.api.json" | ||
| }, | ||
|
|
||
| "dtsRollup": { | ||
| "enabled": true, | ||
| "publicTrimmedFilePath": "<projectFolder>/dist/proxy.d.ts" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import * as path from 'path'; | ||
| import { Import, FileSystem } from '@rushstack/node-core-library'; | ||
| import type { EnvironmentVariableNames } from '@microsoft/rush-lib'; | ||
|
|
||
| export const RUSH_LIB_NAME: '@microsoft/rush-lib' = '@microsoft/rush-lib'; | ||
| export const RUSH_LIB_PATH_ENV_VAR_NAME: typeof EnvironmentVariableNames.RUSH_LIB_PATH = '_RUSH_LIB_PATH'; | ||
|
|
||
| export type RushLibModuleType = Record<string, unknown>; | ||
|
|
||
| export interface ISdkContext { | ||
| rushLibModule: RushLibModuleType | undefined; | ||
| } | ||
|
|
||
| export const sdkContext: ISdkContext = { | ||
| rushLibModule: undefined | ||
| }; | ||
|
|
||
| /** | ||
| * Find the rush.json location and return the path, or undefined if a rush.json can't be found. | ||
| * | ||
| * @privateRemarks | ||
| * Keep this in sync with `RushConfiguration.tryFindRushJsonLocation`. | ||
| */ | ||
| export function tryFindRushJsonLocation(startingFolder: string): string | undefined { | ||
| let currentFolder: string = startingFolder; | ||
|
|
||
| // Look upwards at parent folders until we find a folder containing rush.json | ||
| for (let i: number = 0; i < 10; ++i) { | ||
iclanton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const rushJsonFilename: string = path.join(currentFolder, 'rush.json'); | ||
iclanton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (FileSystem.exists(rushJsonFilename)) { | ||
iclanton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return rushJsonFilename; | ||
| } | ||
|
|
||
| const parentFolder: string = path.dirname(currentFolder); | ||
| if (parentFolder === currentFolder) { | ||
| break; | ||
| } | ||
|
|
||
| currentFolder = parentFolder; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| export function _require<TResult>(moduleName: string): TResult { | ||
| if (typeof __non_webpack_require__ === 'function') { | ||
| // If this library has been bundled with Webpack, we need to call the real `require` function | ||
| // that doesn't get turned into a `__webpack_require__` statement. | ||
| // `__non_webpack_require__` is a Webpack macro that gets turned into a `require` statement | ||
| // during bundling. | ||
| return __non_webpack_require__(moduleName); | ||
| } else { | ||
| return require(moduleName); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Require `@microsoft/rush-lib` under the specified folder path. | ||
| */ | ||
| export function requireRushLibUnderFolderPath(folderPath: string): RushLibModuleType { | ||
| const rushLibModulePath: string = Import.resolveModule({ | ||
| modulePath: RUSH_LIB_NAME, | ||
| baseFolderPath: folderPath | ||
| }); | ||
iclanton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return _require(rushLibModulePath); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.