-
Notifications
You must be signed in to change notification settings - Fork 5k
cli: stop --jsx-* flags from switching the automatic JSX runtime to production #36209
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
Open
robobun
wants to merge
6
commits into
main
Choose a base branch
from
farm/f5de3a86/jsx-cli-flags-preserve-dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+75
−2
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e322649
cli: stop --jsx-* flags from switching the automatic runtime to produ…
robobun 54a8ef5
test: move --jsx-* dev-runtime coverage to its own file
robobun 1ac228a
drop explanatory comment on development:true
robobun c9f4327
test: cover the bunfig-merge branch of --jsx-* arg parsing
robobun ab00356
[autofix.ci] apply automated fixes
autofix-ci[bot] e481288
ci: retrigger
robobun 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
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,73 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe, tempDir } from "harness"; | ||
|
|
||
| // Passing a --jsx-* CLI flag must not flip the automatic runtime from | ||
| // jsx-dev-runtime (development) to jsx-runtime (production). The flag only | ||
| // overrides the field it names; dev/prod selection follows NODE_ENV exactly as | ||
| // it does when no --jsx-* flag is present. | ||
| describe.concurrent("jsx: --jsx-* CLI flags preserve development runtime", () => { | ||
|
robobun marked this conversation as resolved.
|
||
| const shimFiles = { | ||
| "node_modules/react/package.json": JSON.stringify({ | ||
| name: "react", | ||
| version: "1.0.0", | ||
| exports: { | ||
| ".": "./index.js", | ||
| "./jsx-runtime": "./prod.js", | ||
| "./jsx-dev-runtime": "./dev.js", | ||
| }, | ||
| }), | ||
| "node_modules/react/index.js": "module.exports = {};", | ||
| "node_modules/react/prod.js": | ||
| "exports.jsx = () => ({ rt: 'PROD' }); exports.jsxs = exports.jsx; exports.Fragment = {};", | ||
| "node_modules/react/dev.js": "exports.jsxDEV = () => ({ rt: 'DEV' }); exports.Fragment = {};", | ||
| "a.jsx": "console.log(JSON.stringify(<div/>));", | ||
| }; | ||
|
|
||
| type Case = [extraArgs: string[], nodeEnv: string | undefined, bunfig: string | undefined, expected: "DEV" | "PROD"]; | ||
| const cases: Case[] = [ | ||
| // Baselines (no --jsx-* flags): dev by default, prod only when NODE_ENV=production. | ||
| [[], undefined, undefined, "DEV"], | ||
| [[], "development", undefined, "DEV"], | ||
| [[], "production", undefined, "PROD"], | ||
| // Any --jsx-* flag must not change the dev/prod selection (no bunfig: fresh-construct branch). | ||
| [["--jsx-import-source=react"], undefined, undefined, "DEV"], | ||
| [["--jsx-import-source=react"], "development", undefined, "DEV"], | ||
| [["--jsx-import-source=react"], "production", undefined, "PROD"], | ||
| [["--jsx-fragment=Fragment"], undefined, undefined, "DEV"], | ||
| [["--jsx-fragment=Fragment"], "development", undefined, "DEV"], | ||
| [["--jsx-fragment=Fragment"], "production", undefined, "PROD"], | ||
| [["--jsx-factory=h"], undefined, undefined, "DEV"], | ||
| [["--jsx-runtime=automatic"], undefined, undefined, "DEV"], | ||
| [["--jsx-runtime=automatic"], "production", undefined, "PROD"], | ||
| // With a bunfig present, opts.jsx is already populated and CLI flags go through the | ||
| // merge-with-bunfig branch, which must preserve bunfig's `development` value. | ||
| [["--jsx-import-source=react"], undefined, "", "DEV"], | ||
| [["--jsx-import-source=react"], "production", "", "PROD"], | ||
| [["--jsx-fragment=Fragment"], undefined, "", "DEV"], | ||
| [["--jsx-import-source=react"], undefined, 'jsx = "react-jsx"\n', "PROD"], | ||
| [["--jsx-import-source=react"], undefined, 'jsx = "react-jsxDEV"\n', "DEV"], | ||
| ]; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| for (const [extraArgs, nodeEnv, bunfig, expected] of cases) { | ||
| const bunfigLabel = bunfig === undefined ? "no bunfig" : bunfig === "" ? "empty bunfig" : `bunfig ${bunfig.trim()}`; | ||
| const label = `bun ${extraArgs.join(" ") || "(no flags)"} NODE_ENV=${nodeEnv ?? "<unset>"} [${bunfigLabel}] -> ${expected}`; | ||
| test(label, async () => { | ||
| const files: Record<string, string> = { ...shimFiles }; | ||
| if (bunfig !== undefined) files["bunfig.toml"] = bunfig; | ||
| using dir = tempDir("jsx-cli-dev", files); | ||
| const env: Record<string, string | undefined> = { ...bunEnv, NODE_ENV: nodeEnv }; | ||
| if (nodeEnv === undefined) delete env.NODE_ENV; | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), ...extraArgs, "a.jsx"], | ||
| env, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| expect(stdout.trim()).toBe(JSON.stringify({ rt: expected })); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
| } | ||
| }); | ||
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.