-
-
Notifications
You must be signed in to change notification settings - Fork 678
fix: CLIPlugin dynamic import interop under Bun #4799
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
+69
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "webpack-cli": patch | ||
| --- | ||
|
|
||
| fix: `CLIPlugin` dynamic import interop under Bun |
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,46 @@ | ||
| const path = require("node:path"); | ||
|
|
||
| // Simulate Bun's ESM↔CJS interop: the dynamic import of cli-plugin resolves to | ||
| // the class itself instead of Node's `{ __esModule, default }` wrapper. Guards | ||
| // the interop-safe unwrap in `webpack-cli.ts` against reintroducing the | ||
| // Node-only double-`.default` unwrap (which crashes every build under Bun). | ||
| jest.mock( | ||
| "../../../packages/webpack-cli/lib/plugins/cli-plugin", | ||
| () => jest.requireActual("../../../packages/webpack-cli/lib/plugins/cli-plugin").default, | ||
| ); | ||
|
|
||
| const CLIPlugin = jest.requireActual( | ||
| "../../../packages/webpack-cli/lib/plugins/cli-plugin", | ||
| ).default; | ||
|
|
||
| describe("CLIPlugin import interop", () => { | ||
| it("applies CLIPlugin when the dynamic import resolves to the class itself", async () => { | ||
| process.env.WEBPACK_PACKAGE = path.resolve(__dirname, "./mock-webpack.js"); | ||
|
|
||
| const WebpackCLI = require("../../../packages/webpack-cli/lib/webpack-cli").default; | ||
|
|
||
| const exitSpy = jest.spyOn(process, "exit").mockImplementation((code) => { | ||
| throw new Error(`process.exit(${code})`); | ||
| }); | ||
| const errors = []; | ||
| const errorSpy = jest | ||
| .spyOn(console, "error") | ||
| .mockImplementation((message) => errors.push(`${message}`)); | ||
|
|
||
| try { | ||
| await new WebpackCLI().run(["node", "webpack", "build"]); | ||
| } catch (error) { | ||
| throw new Error(`${error.message}\n${errors.join("\n")}`, { | ||
| cause: error, | ||
| }); | ||
| } finally { | ||
| exitSpy.mockRestore(); | ||
| errorSpy.mockRestore(); | ||
| delete process.env.WEBPACK_PACKAGE; | ||
| } | ||
|
|
||
| const options = globalThis.__capturedWebpackOptions; | ||
|
|
||
| expect(options.plugins[0]).toBeInstanceOf(CLIPlugin); | ||
| }); | ||
| }); |
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,14 @@ | ||
| // Minimal webpack stand-in (loaded via WEBPACK_PACKAGE): captures the config | ||
| // webpack-cli assembles so tests can assert on the applied plugins. | ||
| const realWebpack = require("webpack"); | ||
|
|
||
| const webpack = (options) => { | ||
| globalThis.__capturedWebpackOptions = options; | ||
|
|
||
| return { options }; | ||
| }; | ||
|
|
||
| webpack.cli = realWebpack.cli; | ||
| webpack.version = realWebpack.version; | ||
|
|
||
| module.exports = webpack; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 5727a55:
test/api/cli-plugin-interop/mocks the cli-plugin module to the shape Bun's__esModule-aware interop produces (the class itself, no nested.default) and asserts a build still appliesCLIPlugin. Verified it fails with "CLIPlugin is not a constructor" against the previous double-unwrap code.Generated by Claude Code