Skip to content

feat(rspeedy): express SWC baseline via env instead of jsc.target#2748

Merged
upupming merged 9 commits into
mainfrom
feat/swc-target-to-env
May 29, 2026
Merged

feat(rspeedy): express SWC baseline via env instead of jsc.target#2748
upupming merged 9 commits into
mainfrom
feat/swc-target-to-env

Conversation

@upupming

@upupming upupming commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Move the per-layer SWC compilation baseline from jsc.target to SWC env (a high targets baseline plus an explicit include transform list), across @lynx-js/rspeedy (background/base) and @lynx-js/react-rsbuild-plugin (main thread).

The artifact format is completely unchanged. For existing projects the emitted output is byte-for-byte identical — env: { targets: <high>, include: [...] } runs the exact same set of transforms that the previous jsc.target lowered. Verified by building examples/* with DEBUG='rspeedy,rsbuild' pnpm build old-vs-new under a determinism control: main-thread.js, background.js, sourcemaps and the chunk hashes are all identical.

Why do this: env (unlike jsc.target) supports include/exclude, so the transform set can be tuned per layer later (e.g. adding transform-block-scoping for the let/const to var perf win) without switching config shape.

Behavior changes

  • tools.swc.jsc.target is no longer accepted (it is mutually exclusive with env). Instead of silently dropping it, the build now throws a clear error pointing users to tools.swc.env.include.
  • User-provided tools.swc.env.include transforms are merged on top of the baseline (background keeps its es2015 set, main thread stays es2019-equivalent), so users can opt into extra transforms.

Tests

  • swc.plugin.test.ts: env-based defaults (prod es2015 / dev es2019, no jsc.target); user jsc.target throws; user env.include is merged onto the baseline.
  • swc-config.test.ts: main thread uses es2019 env; user jsc.target is rejected; user env.include is merged into both layers.
  • Full @lynx-js/rspeedy + @lynx-js/react-rsbuild-plugin suites pass (582 tests).

Test plan

  • turbo build + turbo api-extractor
  • changeset status shows @lynx-js/rspeedy + @lynx-js/react-rsbuild-plugin bumping minor
  • Existing example artifacts unchanged (modulo build nondeterminism)

Summary by CodeRabbit

  • Chores

    • SWC target management moved to an env-based configuration with explicit baseline transform lists; existing build output remains compatible.
    • Main-thread SWC baseline is now enforced and user-added transforms merge only where allowed.
    • Tooling rejects legacy target settings and instructs adding transforms to env.include when downleveling.
    • Dev tooling updated to a newer SWC runtime.
  • Documentation

    • Release notes updated with migration guidance.
  • Tests

    • Tests updated to cover env-based config, merging behavior, and target rejection.

Review Change Stack

Move the per-layer SWC compilation baseline from `jsc.target` to `env`
(a high `targets` plus an explicit `include` transform list). The emitted
build output is byte-identical for existing projects.

Since `env` and `jsc.target` are mutually exclusive in SWC, a user-set
`tools.swc.jsc.target` now throws a clear error pointing to
`tools.swc.env.include`; user-provided `env.include` transforms are merged
on top of the baseline (per layer). This unblocks tuning the transform set
(e.g. adding `transform-block-scoping`) without changing today's output.
@changeset-bot

changeset-bot Bot commented May 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c98fa8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@lynx-js/rspeedy Minor
@lynx-js/react-rsbuild-plugin Minor
create-rspeedy Minor
upgrade-rspeedy Minor
@lynx-js/react-alias-rsbuild-plugin Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec9da075-38ea-4bd2-85cf-f5f91b0f0834

📥 Commits

Reviewing files that changed from the base of the PR and between 2b215e3 and c98fa8e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • packages/rspeedy/core/package.json
  • packages/rspeedy/core/test/utils/getESVersionEnvInclude.test.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/rspeedy/core/package.json

📝 Walkthrough

Walkthrough

Migrates SWC compilation target configuration from jsc.target to env with explicit transform include lists, introduces canonical include sets and a high env.targets baseline, updates core and react plugins to set env.targets/env.include, rejects user jsc.target, and updates tests and the changeset.

Changes

SWC Target Configuration Migration to env

Layer / File(s) Summary
Transform include definitions and constants
packages/rspeedy/core/src/utils/getESVersionTarget.ts
Defines canonical ES2019_INCLUDE and ES2015_INCLUDE SWC transform arrays, adds getESVersionEnvInclude() to select a list for a target, and exports ES_ENV_TARGETS ({ chrome: '120' }) to prevent SWC auto-inclusion.
Core SWC plugin configuration
packages/rspeedy/core/src/plugins/swc.plugin.ts
Updates pluginSwc to import transform definitions and ES_ENV_TARGETS, constructs config.env with env.targets and merged env.include, and throws if user sets config.jsc?.target.
React plugin loader and configuration updates
packages/rspeedy/plugin-react/src/loaders.ts, packages/rspeedy/plugin-react/src/swc.ts
Adds MAIN_THREAD env.include and env.targets constants, updates MAIN_THREAD loader rewrite to remove jsc.target and set the baseline env block, and removes env-deletion post-processing from the React SWC config.
Core plugin test suite updates
packages/rspeedy/core/test/plugins/swc.plugin.test.ts
Updates production and development snapshots to assert env.targets and env.include, replaces custom-target test with a rejection test for user jsc.target, and verifies merging of user tools.swc.env.include onto the baseline.
React plugin test suite updates
packages/rspeedy/plugin-react/test/swc-config.test.ts
Updates snapshots and assertions to expect env-based SWC config, removes the test setup hook that deleted config.env, adds a test asserting rejection of user jsc.target, and verifies user env.include applies to background but not main-thread baseline.
Test helpers and dev dependency
packages/rspeedy/core/test/utils/getESVersionEnvInclude.test.ts, packages/rspeedy/core/package.json
Adds a unit test that verifies getESVersionEnvInclude() reproduces jsc.target lowering byte-for-byte and adds @swc/core to devDependencies for test use.
Release notes documentation
.changeset/swc-target-to-env.md
Bumps affected packages to minor and documents the migration from tools.swc.jsc.target to tools.swc.env/tools.swc.env.include, the new rejection behavior for jsc.target, and guidance to add downlevel transforms via env.include.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

framework:React

Suggested reviewers

  • luhc228
  • colinaaa

🐰 From dusk 'til dawn I hop and hum,

chrome set high so transforms stay mum,
includes merge in, no target to pry,
env now leads as the old flags fly,
carrots and snapshots updated—hip hooray! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: migrating SWC baseline configuration from jsc.target to env. It is specific, directly related to the core objective, and uses proper conventional commit format.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/swc-target-to-env

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@pkg-pr-new

pkg-pr-new Bot commented May 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

@lynx-js/rspeedy

npm i https://pkg.pr.new/@lynx-js/rspeedy@2748

create-rspeedy

npm i https://pkg.pr.new/create-rspeedy@2748

@lynx-js/react-rsbuild-plugin

npm i https://pkg.pr.new/@lynx-js/react-rsbuild-plugin@2748

@lynx-js/react-alias-rsbuild-plugin

npm i https://pkg.pr.new/@lynx-js/react-alias-rsbuild-plugin@2748

upgrade-rspeedy

npm i https://pkg.pr.new/upgrade-rspeedy@2748

commit: c98fa8e

Add `afterEach(vi.unstubAllEnvs)` so a stubbed `NODE_ENV` never leaks into
a later test. The `include` defaults test relied on an inherited
`development` env for the dev-only `@rsbuild/core/dist` include entry; it
now stubs that explicitly. Stub the mode only where it is meaningful.
@codspeed-hq

codspeed-hq Bot commented May 28, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 17.14%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 80 untouched benchmarks
⏩ 26 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
transform 1000 view elements 47.1 ms 40.2 ms +17.14%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/swc-target-to-env (c98fa8e) with main (87990b5)

Open in CodSpeed

Footnotes

  1. 26 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

upupming added 3 commits May 28, 2026 22:00
- Drop orphaned `config.jsc ??= {}` in swc.plugin.ts (no longer sets jsc.target)
- Trim verbose comment blocks in swc.plugin.ts and loaders.ts
- Rely on the all-dev NODE_ENV leak in swc-config tests (drop afterEach
  cleanup and the prod stubs) to match main's existing pattern

No change to emitted build output.
Restore the `toHaveLoader` layer-separation assertions and main's
multi-line formatting that were dropped while adapting the layer tests;
change only the target-specific assertions that the env refactor forces.
@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

UI Judge

GEQI weighted score: 62.9 / 100 across 8 examples.
Average visual-correctness score: 3.4 / 5.

Dimension Weight Average Results Status
Usability & Interaction 30% 3.4 / 5 8 OK
Visual & Aesthetics 25% 3.1 / 5 8 OK
Consistency & Standards 15% 3 / 5 8 OK
Architecture & UX Writing 15% 3 / 5 8 OK
Accessibility & Performance 15% 3 / 5 8 OK
# Example Visual Correctness Usability & Interaction (30%) Visual & Aesthetics (25%) Consistency & Standards (15%) Architecture & UX Writing (15%) Accessibility & Performance (15%) GEQI Page Status
1 recs 2 / 5 2 / 5 2 / 5 2 / 5 2 / 5 2 / 5 40 / 100 preview OK
2 cast-grid 5 / 5 5 / 5 4 / 5 4 / 5 4 / 5 3 / 5 83 / 100 preview OK
3 citywalk-list 2 / 5 3 / 5 3 / 5 2 / 5 2 / 5 3 / 5 54 / 100 preview OK
4 fridge-search 4 / 5 3 / 5 3 / 5 4 / 5 3 / 5 3 / 5 63 / 100 preview OK
5 trip-planner 2 / 5 2 / 5 3 / 5 2 / 5 2 / 5 3 / 5 48 / 100 preview OK
6 weather-current 5 / 5 5 / 5 4 / 5 4 / 5 4 / 5 4 / 5 86 / 100 preview OK
7 product-card 5 / 5 5 / 5 4 / 5 4 / 5 5 / 5 4 / 5 89 / 100 preview OK
8 workout-plan 2 / 5 2 / 5 2 / 5 2 / 5 2 / 5 2 / 5 40 / 100 preview OK
Details

Result 1

  • Example: recs
  • Dimension: visual-correctness
  • Visual correctness: 2 / 5
  • GEQI dimensions:
    • Usability & Interaction: 2 / 5 (30%)
    • Visual & Aesthetics: 2 / 5 (25%)
    • Consistency & Standards: 2 / 5 (15%)
    • Architecture & UX Writing: 2 / 5 (15%)
    • Accessibility & Performance: 2 / 5 (15%)
  • Task: The A2UI playground preview should show date-night dining recommendations for Moonlight Terrace, Pinewood Bistro, and Sea Breeze Kitchen.

Result 2

  • Example: cast-grid
  • Dimension: visual-correctness
  • Visual correctness: 5 / 5
  • GEQI dimensions:
    • Usability & Interaction: 5 / 5 (30%)
    • Visual & Aesthetics: 4 / 5 (25%)
    • Consistency & Standards: 4 / 5 (15%)
    • Architecture & UX Writing: 4 / 5 (15%)
    • Accessibility & Performance: 3 / 5 (15%)
  • Task: The A2UI playground preview should show a cast grid for the short film Night Notes, including Lin Xia and Zhou Ning cast cards.

Result 3

  • Example: citywalk-list
  • Dimension: visual-correctness
  • Visual correctness: 2 / 5
  • GEQI dimensions:
    • Usability & Interaction: 3 / 5 (30%)
    • Visual & Aesthetics: 3 / 5 (25%)
    • Consistency & Standards: 2 / 5 (15%)
    • Architecture & UX Writing: 2 / 5 (15%)
    • Accessibility & Performance: 3 / 5 (15%)
  • Task: The A2UI playground preview should show weekend citywalk coffee picks with Rooftop Brew Room, Corner Canvas Lab, and Late Sun Roastery.

Result 4

  • Example: fridge-search
  • Dimension: visual-correctness
  • Visual correctness: 4 / 5
  • GEQI dimensions:
    • Usability & Interaction: 3 / 5 (30%)
    • Visual & Aesthetics: 3 / 5 (25%)
    • Consistency & Standards: 4 / 5 (15%)
    • Architecture & UX Writing: 3 / 5 (15%)
    • Accessibility & Performance: 3 / 5 (15%)
  • Task: The A2UI playground preview should show refrigerator search results with Siemens, Hualing, Haier, and Midea product cards.

Result 5

  • Example: trip-planner
  • Dimension: visual-correctness
  • Visual correctness: 2 / 5
  • GEQI dimensions:
    • Usability & Interaction: 2 / 5 (30%)
    • Visual & Aesthetics: 3 / 5 (25%)
    • Consistency & Standards: 2 / 5 (15%)
    • Architecture & UX Writing: 2 / 5 (15%)
    • Accessibility & Performance: 3 / 5 (15%)
  • Task: The A2UI playground preview should show a Kyoto 48-hour trip planner with Day 1 and Day 2 itinerary sections, including Monkey Park Viewpoint.

Result 6

  • Example: weather-current
  • Dimension: visual-correctness
  • Visual correctness: 5 / 5
  • GEQI dimensions:
    • Usability & Interaction: 5 / 5 (30%)
    • Visual & Aesthetics: 4 / 5 (25%)
    • Consistency & Standards: 4 / 5 (15%)
    • Architecture & UX Writing: 4 / 5 (15%)
    • Accessibility & Performance: 4 / 5 (15%)
  • Task: The A2UI playground preview should show the current weather for Austin, TX, including clear skies with light breeze.

Result 7

  • Example: product-card
  • Dimension: visual-correctness
  • Visual correctness: 5 / 5
  • GEQI dimensions:
    • Usability & Interaction: 5 / 5 (30%)
    • Visual & Aesthetics: 4 / 5 (25%)
    • Consistency & Standards: 4 / 5 (15%)
    • Architecture & UX Writing: 5 / 5 (15%)
    • Accessibility & Performance: 4 / 5 (15%)
  • Task: The A2UI playground preview should show a Wireless Headphones Pro product card with a visible Add to Cart action.

Result 8

  • Example: workout-plan
  • Dimension: visual-correctness
  • Visual correctness: 2 / 5
  • GEQI dimensions:
    • Usability & Interaction: 2 / 5 (30%)
    • Visual & Aesthetics: 2 / 5 (25%)
    • Consistency & Standards: 2 / 5 (15%)
    • Architecture & UX Writing: 2 / 5 (15%)
    • Accessibility & Performance: 2 / 5 (15%)
  • Task: The A2UI playground preview should show a weekly workout plan with five days from Monday Ramp-Up through Friday Conditioning.

Workflow run

`@lynx-js/genui-a2ui`'s `api-extractor` task runs `build:catalog`, which
invokes the genui CLI and dynamically imports
`@lynx-js/genui-a2ui-catalog-extractor/dist/cli.js`. The `api-extractor`
task only depended on `//#build`, so turbo never guaranteed the catalog
extractor was built first — whichever genui package's api-extractor won
the (lock-serialized but unordered) race decided pass/fail, intermittently
failing CI with "Cannot find module .../a2ui-catalog-extractor/dist/cli.js".

Add an explicit `@lynx-js/genui-a2ui-catalog-extractor#build` dependency to
genui-a2ui's `api-extractor` task so the CLI is always present.
upupming added a commit that referenced this pull request May 29, 2026
…tor (#2751)

## Summary

`@lynx-js/genui-a2ui`'s `api-extractor` task runs `pnpm run build`,
whose `build:catalog` step invokes the `genui` CLI and dynamically
imports `@lynx-js/genui-a2ui-catalog-extractor/dist/cli.js`.

The shared `api-extractor` task only declared `dependsOn: ["//#build"]`,
so turbo never guaranteed `@lynx-js/genui-a2ui-catalog-extractor` was
built before `genui-a2ui`'s api-extractor ran. The genui packages run
`run-api-extractor.mjs` under a shared lock that serializes them but
does **not** order them, so whichever genui package's api-extractor
happened to run first decided the outcome. When `genui-a2ui` won the
race, its `build:catalog` failed with:

```
Cannot find module '.../packages/genui/a2ui-catalog-extractor/dist/cli.js'
  imported from .../packages/genui/cli/bin/cli.js
```

This intermittently broke `code-style-check` and `test-api` on unrelated
PRs.

## Fix

Give `genui-a2ui`'s `api-extractor` task an explicit
`@lynx-js/genui-a2ui-catalog-extractor#build` dependency (in addition to
the existing `//#build`), so turbo always builds the catalog extractor —
producing `dist/cli.js` — before the catalog generation step runs.

No dependency cycle: `@lynx-js/genui-a2ui-catalog-extractor` only
depends on `typedoc`.

## Failing CI (before this fix)

- `code-style-check` on #2748 (after merging main, without this fix):
https://github.com/lynx-family/lynx-stack/actions/runs/26581640592/job/78316111246
— fails with `Cannot find module
.../a2ui-catalog-extractor/dist/cli.js`.

## Verification that the fix works

- `turbo api-extractor --filter=@lynx-js/genui-a2ui --dry-run=json` now
reports `@lynx-js/genui-a2ui#api-extractor -> ['//#build',
'@lynx-js/genui-a2ui-catalog-extractor#build']` (previously `->
['//#build']`).
- This PR's own `code-style-check` passes:
https://github.com/lynx-family/lynx-stack/actions/runs/26584778467/job/78327588583
- Cherry-picked onto #2748 (the branch that was failing), the same
`code-style-check` job goes from red to green:
https://github.com/lynx-family/lynx-stack/actions/runs/26584934732/job/78328149767

## Test plan

- [x] `code-style-check` passes in CI.
@upupming upupming marked this pull request as ready for review May 29, 2026 03:52
@upupming upupming requested review from colinaaa and luhc228 as code owners May 29, 2026 03:52

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4dd58b8671

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rspeedy/plugin-react/src/loaders.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/rspeedy/core/src/plugins/swc.plugin.ts (1)

39-45: ⚡ Quick win

Only env.include is honored; other env fields are silently dropped.

env.targets, env.exclude, and any other user env fields are discarded here. This is inconsistent with jsc.target, which now throws — a user who sets tools.swc.env.exclude to opt out of a transform would be silently ignored rather than told it's unsupported. Consider rejecting unsupported env keys (mirroring the jsc.target error) or clearly documenting that only include is merged. The MAIN_THREAD override in loaders.ts has the same drop behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/rspeedy/core/src/plugins/swc.plugin.ts` around lines 39 - 45, The
current swc plugin code unconditionally replaces config.env with a new object
containing only targets and include, dropping any user-provided env properties
(e.g., env.exclude) which is inconsistent with jsc.target behavior; update the
assignment in swc.plugin.ts (the config.env block that calls
getESVersionEnvInclude/getESVersionTarget and uses isProd) to either (a) merge
user env fields: create config.env = { ...config.env, targets: ES_ENV_TARGETS,
include: [ ...getESVersionEnvInclude(getESVersionTarget(isProd)),
...(config.env?.include ?? []) ] } so existing env.exclude and other keys are
preserved, or (b) validate config.env for unsupported keys and throw an error
mirroring jsc.target behavior; apply the same fix/validation to the MAIN_THREAD
override in loaders.ts so user env fields are not silently dropped.
packages/rspeedy/plugin-react/src/loaders.ts (1)

13-44: ⚡ Quick win

Avoid re-declaring ES transform baseline lists in plugin-react

packages/rspeedy/plugin-react/src/loaders.ts duplicates ES2019_INCLUDE, ES_ENV_TARGETS (chrome: '120'), and the ES2016→ES2019 transform slice that already exist in packages/rspeedy/core/src/utils/getESVersionTarget.ts (getESVersionEnvInclude, ES_ENV_TARGETS). If the core canonical list ever changes, these copies can silently drift and break the intended es2019-equivalence/byte-identical output.

Consider importing/reusing the shared definitions from the core package (or re-export them from the core entry point—packages/rspeedy/core/package.json only exposes . and ./client).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/rspeedy/plugin-react/src/loaders.ts` around lines 13 - 44, The
arrays MAIN_THREAD_ENV_INCLUDE, MAIN_THREAD_ENV_TARGETS, and
ES2016_TO_ES2019_INCLUDE are duplicate copies of the canonical lists in core
(getESVersionEnvInclude / ES_ENV_TARGETS); replace these local declarations by
importing the shared definitions from the core module (or have core re-export
them and import those exports) so the plugin-react file uses the single source
of truth (refer to MAIN_THREAD_ENV_INCLUDE, MAIN_THREAD_ENV_TARGETS,
ES2016_TO_ES2019_INCLUDE in this file and getESVersionEnvInclude /
ES_ENV_TARGETS in core to locate the matching constants), removing the
duplicated arrays here and updating any usage sites to the imported names.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/rspeedy/core/src/plugins/swc.plugin.ts`:
- Around line 39-45: The current swc plugin code unconditionally replaces
config.env with a new object containing only targets and include, dropping any
user-provided env properties (e.g., env.exclude) which is inconsistent with
jsc.target behavior; update the assignment in swc.plugin.ts (the config.env
block that calls getESVersionEnvInclude/getESVersionTarget and uses isProd) to
either (a) merge user env fields: create config.env = { ...config.env, targets:
ES_ENV_TARGETS, include: [
...getESVersionEnvInclude(getESVersionTarget(isProd)), ...(config.env?.include
?? []) ] } so existing env.exclude and other keys are preserved, or (b) validate
config.env for unsupported keys and throw an error mirroring jsc.target
behavior; apply the same fix/validation to the MAIN_THREAD override in
loaders.ts so user env fields are not silently dropped.

In `@packages/rspeedy/plugin-react/src/loaders.ts`:
- Around line 13-44: The arrays MAIN_THREAD_ENV_INCLUDE,
MAIN_THREAD_ENV_TARGETS, and ES2016_TO_ES2019_INCLUDE are duplicate copies of
the canonical lists in core (getESVersionEnvInclude / ES_ENV_TARGETS); replace
these local declarations by importing the shared definitions from the core
module (or have core re-export them and import those exports) so the
plugin-react file uses the single source of truth (refer to
MAIN_THREAD_ENV_INCLUDE, MAIN_THREAD_ENV_TARGETS, ES2016_TO_ES2019_INCLUDE in
this file and getESVersionEnvInclude / ES_ENV_TARGETS in core to locate the
matching constants), removing the duplicated arrays here and updating any usage
sites to the imported names.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: eacd2ee6-00b6-4dcf-9957-46782e6a31d8

📥 Commits

Reviewing files that changed from the base of the PR and between 9b1792c and 4dd58b8.

📒 Files selected for processing (7)
  • .changeset/swc-target-to-env.md
  • packages/rspeedy/core/src/plugins/swc.plugin.ts
  • packages/rspeedy/core/src/utils/getESVersionTarget.ts
  • packages/rspeedy/core/test/plugins/swc.plugin.test.ts
  • packages/rspeedy/plugin-react/src/loaders.ts
  • packages/rspeedy/plugin-react/src/swc.ts
  • packages/rspeedy/plugin-react/test/swc-config.test.ts
💤 Files with no reviewable changes (1)
  • packages/rspeedy/plugin-react/src/swc.ts

The main thread targets an es2019 engine, so its baseline is a platform
constant. Drop the attempt to merge user `tools.swc.env.include` onto the
main-thread layer: user transforms now extend only the base/background
config, matching the previous `jsc.target` behavior (which the main thread
also ignored, hardcoding es2019).

This removes the `ES2016_TO_ES2019_INCLUDE` filter, which could silently
drop a user-provided es2016~es2019 transform from the main thread.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b215e389f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rspeedy/core/src/utils/getESVersionTarget.ts
colinaaa
colinaaa previously approved these changes May 29, 2026
Add a test that compiles a fixture spanning ES2016~ES2025+ syntax with both
`jsc.target` and the `env` config built from `getESVersionEnvInclude`, and
asserts byte-identical output. If a future SWC upgrade lowers some syntax at
the target that the explicit `include` list omits, the outputs diverge and the
test fails — catching the drift automatically.

Empirically the current list already reproduces `jsc.target` exactly (es2015
and es2019), including the es2024 `v` regex flag and es2025 regex features, so
no transforms needed adding; this just locks the equivalence in.
@upupming upupming enabled auto-merge (squash) May 29, 2026 07:12
@upupming upupming merged commit 40701bd into main May 29, 2026
46 checks passed
@upupming upupming deleted the feat/swc-target-to-env branch May 29, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants