-
Notifications
You must be signed in to change notification settings - Fork 666
[rush-sdk]: add named export support for CommonJS compatibility #5539
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
iclanton
merged 17 commits into
microsoft:main
from
LPegasus:chore/optimize-named-exports
Feb 5, 2026
+320
−51
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5574c08
feat(rush-sdk): add named export support for CommonJS compatibility
LPegasus 3d52a11
Update common/changes/@microsoft/rush/chore-optimize-named-exports_20…
LPegasus 8c8cc14
[rush-sdk] Revert test snapshot
LPegasus 7c42835
feat(webpack-deep-imports-plugin): add named exports code generation …
LPegasus 0e9d213
refactor(rush-sdk): reuse rush-lib/lib assets exports placehold code
LPegasus e160ebe
fix(rush-sdk): fix unit test in CI with node <= 20.18
LPegasus b286070
Update webpack/webpack-deep-imports-plugin/src/DeepImportsPlugin.ts
LPegasus 7105e45
Update libraries/rush-sdk/webpack.config.js
LPegasus cce271a
Update libraries/rush-sdk/src/generate-stubs.ts
LPegasus f9eb19d
refactor(webpack-deep-imports-plugin): Use compilation.webpack.Webpac…
LPegasus 475c61a
feat: Generate sidecar .exports.json files instead of injecting expor…
iclanton 255fd67
fix(rush-sdk): Fix ESM named exports for deep imports
iclanton 96c84e9
refactor(rush-sdk): Use footer instead of banner for ESM exports hints
iclanton 8d3f74e
chore(rush-lib): Exclude .exports.json sidecar files from npm package
iclanton 5438963
refactor(rush-sdk): Use async filesystem operations in generate-stubs
iclanton ed0b358
refactor(tests): Convert synchronous named exports tests to async
iclanton 6b573a5
Merge remote-tracking branch 'microsoft/main' into chore/optimize-nam…
iclanton 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
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
10 changes: 10 additions & 0 deletions
10
common/changes/@microsoft/rush/chore-optimize-named-exports_2026-01-06-12-36.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": "Add named exports to support named imports to `@rushstack/rush-sdk`.", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@microsoft/rush" | ||
| } |
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
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
103 changes: 103 additions & 0 deletions
103
libraries/rush-sdk/src/test/__snapshots__/script.test.ts.snap
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,103 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`@rushstack/rush-sdk Should load via env when Rush has loaded (for child processes): stderr 1`] = `""`; | ||
|
|
||
| exports[`@rushstack/rush-sdk Should load via env when Rush has loaded (for child processes): stdout 1`] = ` | ||
| "Try to load @microsoft/rush-lib from process.env._RUSH_LIB_PATH from caller package | ||
| Loaded @microsoft/rush-lib from process.env._RUSH_LIB_PATH | ||
| [ | ||
| 'ApprovedPackagesConfiguration', | ||
| 'ApprovedPackagesItem', | ||
| 'ApprovedPackagesPolicy', | ||
| 'BuildCacheConfiguration', | ||
| 'BumpType', | ||
| 'ChangeManager', | ||
| 'CobuildConfiguration', | ||
| 'CommonVersionsConfiguration', | ||
| 'CredentialCache', | ||
| 'CustomTipId', | ||
| 'CustomTipSeverity', | ||
| 'CustomTipType', | ||
| 'CustomTipsConfiguration', | ||
| 'DependencyType', | ||
| 'EnvironmentConfiguration', | ||
| 'EnvironmentVariableNames', | ||
| 'Event', | ||
| 'EventHooks', | ||
| 'ExperimentsConfiguration', | ||
| 'FileSystemBuildCacheProvider', | ||
| 'IndividualVersionPolicy', | ||
| 'LockStepVersionPolicy', | ||
| 'LookupByPath', | ||
| 'NpmOptionsConfiguration', | ||
| 'Operation', | ||
| 'OperationStatus', | ||
| 'PackageJsonDependency', | ||
| 'PackageJsonDependencyMeta', | ||
| 'PackageJsonEditor', | ||
| 'PackageManager', | ||
| 'PackageManagerOptionsConfigurationBase', | ||
| 'PhasedCommandHooks', | ||
| 'PnpmOptionsConfiguration', | ||
| 'ProjectChangeAnalyzer', | ||
| 'RepoStateFile', | ||
| 'Rush', | ||
| 'RushCommandLine', | ||
| 'RushConfiguration', | ||
| 'RushConfigurationProject', | ||
| 'RushConstants', | ||
| 'RushLifecycleHooks', | ||
| 'RushProjectConfiguration', | ||
| 'RushSession', | ||
| 'RushUserConfiguration', | ||
| 'Subspace', | ||
| 'SubspacesConfiguration', | ||
| 'VersionPolicy', | ||
| 'VersionPolicyConfiguration', | ||
| 'VersionPolicyDefinitionName', | ||
| 'YarnOptionsConfiguration', | ||
| '_FlagFile', | ||
| '_OperationBuildCache', | ||
| '_OperationMetadataManager', | ||
| '_OperationStateFile', | ||
| '_RushGlobalFolder', | ||
| '_RushInternals', | ||
| '_rushSdk_loadInternalModule' | ||
| ]" | ||
| `; | ||
|
|
||
| exports[`@rushstack/rush-sdk Should load via global (for plugins): stderr 1`] = `""`; | ||
|
|
||
| exports[`@rushstack/rush-sdk Should load via global (for plugins): stdout 1`] = ` | ||
| "[ | ||
| '_rushSdk_loadInternalModule', | ||
| 'foo' | ||
| ]" | ||
| `; | ||
|
|
||
| exports[`@rushstack/rush-sdk Should load via install-run (for standalone tools): stderr 1`] = `""`; | ||
|
|
||
| exports[`@rushstack/rush-sdk Should load via install-run (for standalone tools): stdout 1`] = ` | ||
| "Try to load @microsoft/rush-lib from rush global folder | ||
| The expected global rush installed folder is \\"<RUSH_GLOBAL_FOLDER>\\" | ||
| Failed to load @microsoft/rush-lib from rush global folder: File does not exist: <RUSH_GLOBAL_FOLDER> | ||
| ENOENT: no such file or directory, lstat '<RUSH_GLOBAL_FOLDER>' | ||
| Trying to load @microsoft/rush-lib installed by install-run-rush | ||
| Loaded @microsoft/rush-lib installed by install-run-rush | ||
| [ | ||
| '_rushSdk_loadInternalModule', | ||
| 'foo' | ||
| ] | ||
| " | ||
| `; | ||
iclanton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| exports[`@rushstack/rush-sdk Should load via process.env._RUSH_LIB_PATH (for child processes): stderr 1`] = `""`; | ||
|
|
||
| exports[`@rushstack/rush-sdk Should load via process.env._RUSH_LIB_PATH (for child processes): stdout 1`] = ` | ||
| "Try to load @microsoft/rush-lib from process.env._RUSH_LIB_PATH from caller package | ||
| Loaded @microsoft/rush-lib from process.env._RUSH_LIB_PATH | ||
| [ | ||
| '_rushSdk_loadInternalModule', | ||
| 'foo' | ||
| ]" | ||
| `; | ||
43 changes: 43 additions & 0 deletions
43
libraries/rush-sdk/src/test/build-assets-with-named-exports.test.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| import { Executable } from '@rushstack/node-core-library'; | ||
|
|
||
| describe('@rushstack/rush-sdk named exports check', () => { | ||
| it('Should import named exports correctly (lib-shim)', async () => { | ||
| const childProcess = Executable.spawn(process.argv0, [ | ||
| '-e', | ||
| // Do not use top level await here because it is not supported in Node.js < 20.20 | ||
| ` | ||
| import('@rushstack/rush-sdk').then(({ RushConfiguration }) => { | ||
| console.log(typeof RushConfiguration.loadFromConfigurationFile); | ||
| }); | ||
| ` | ||
| ]); | ||
| const { stdout, exitCode, signal } = await Executable.waitForExitAsync(childProcess, { | ||
| encoding: 'utf8' | ||
| }); | ||
|
|
||
| expect(stdout.trim()).toEqual('function'); | ||
| expect(exitCode).toBe(0); | ||
| expect(signal).toBeNull(); | ||
| }); | ||
|
|
||
| it('Should import named exports correctly (lib)', async () => { | ||
| const childProcess = Executable.spawn(process.argv0, [ | ||
| '-e', | ||
| ` | ||
| import('@rushstack/rush-sdk/lib/utilities/NullTerminalProvider').then(({ NullTerminalProvider }) => { | ||
| console.log(NullTerminalProvider.name); | ||
| }); | ||
| ` | ||
| ]); | ||
| const { stdout, exitCode, signal } = await Executable.waitForExitAsync(childProcess, { | ||
| encoding: 'utf8' | ||
| }); | ||
|
|
||
| expect(stdout.trim()).toEqual('NullTerminalProvider'); | ||
| expect(exitCode).toBe(0); | ||
| expect(signal).toBeNull(); | ||
| }); | ||
| }); |
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.