fix(deploy-suite): extract CJS->ESM converter to standalone script#1209
Merged
Conversation
The CJS->ESM next.config converter was inlined into scripts/e2e-deploy.sh
via 'node -e ...' with bash single-quote escapes ('"'"'). The escaping
rebalanced quotes such that later code (a comment containing '(e.g.') sat
outside any single-quoted bash region, causing 'bash -n' to fail with:
scripts/e2e-deploy.sh: line 490: syntax error near unexpected token `('
The script died before doing anything in every deploy-suite shard, producing
2480 identical 'Custom deploy script failed: undefined (2)' failures and a
misleading 9.5% pass rate (almost all 'passes' were 'should skip next deploy'
no-ops). See run 25869359604.
- Extract the converter to scripts/cjs-to-esm-config.mjs (same regex
pipeline, no behavioural change).
- Replace the inlined 'node -e' block with a plain 'node ./script.mjs'
invocation.
- Add a 'bash -n scripts/*.sh' gate to the Check job so a future regression
here can't ship green.
commit: |
|
james-elicx
commented
May 14, 2026
james-elicx
added a commit
that referenced
this pull request
May 15, 2026
…in CJS→ESM converter The CJS→ESM converter extracted in #1209 only handled require("mod") in declaration and expression contexts plus module.exports = X. Real-world next.config.{js,ts} fixtures in the deploy suite also use: - require.resolve('./my-adapter.mjs') — cache-components, edge-pages-support, adapter-dynamic-metadata - __dirname references in the config body — webpack-loader-set-environment-variable, next-config-ts/node-api-cjs - __filename references (rarer) These were left untransformed, producing ReferenceError at config load time and failing the entire test app's deploy. Fix: after running the existing regex pipeline, detect any remaining __dirname / __filename / require.* references and prepend a small ESM prelude that polyfills them via fileURLToPath / createRequire(import.meta.url). The prelude is only injected when actually referenced, so simple configs stay unchanged. Affected suites: - test/e2e/app-dir/cache-components/cache-components.server-action.test.ts - test/e2e/edge-pages-support/index.test.ts - test/e2e/edge-pages-support/edge-document.test.ts - test/e2e/app-dir/app-prefetch-static/app-prefetch-static.test.ts - test/e2e/app-dir/webpack-loader-set-environment-variable/...test.ts - test/e2e/app-dir/next-config-ts/node-api-cjs/...test.ts - test/e2e/app-dir/adapter-dynamic-metadata/... The 'Cannot find module @next/bundle-analyzer' subset of the cluster (converter rewrites require('@next/bundle-analyzer') to ESM but the package isn't installed) is intentionally left to the missing-deps agent. Refs run 25870737355.
james-elicx
added a commit
that referenced
this pull request
May 15, 2026
…in CJS→ESM converter (#1217) The CJS→ESM converter extracted in #1209 only handled require("mod") in declaration and expression contexts plus module.exports = X. Real-world next.config.{js,ts} fixtures in the deploy suite also use: - require.resolve('./my-adapter.mjs') — cache-components, edge-pages-support, adapter-dynamic-metadata - __dirname references in the config body — webpack-loader-set-environment-variable, next-config-ts/node-api-cjs - __filename references (rarer) These were left untransformed, producing ReferenceError at config load time and failing the entire test app's deploy. Fix: after running the existing regex pipeline, detect any remaining __dirname / __filename / require.* references and prepend a small ESM prelude that polyfills them via fileURLToPath / createRequire(import.meta.url). The prelude is only injected when actually referenced, so simple configs stay unchanged. Affected suites: - test/e2e/app-dir/cache-components/cache-components.server-action.test.ts - test/e2e/edge-pages-support/index.test.ts - test/e2e/edge-pages-support/edge-document.test.ts - test/e2e/app-dir/app-prefetch-static/app-prefetch-static.test.ts - test/e2e/app-dir/webpack-loader-set-environment-variable/...test.ts - test/e2e/app-dir/next-config-ts/node-api-cjs/...test.ts - test/e2e/app-dir/adapter-dynamic-metadata/... The 'Cannot find module @next/bundle-analyzer' subset of the cluster (converter rewrites require('@next/bundle-analyzer') to ESM but the package isn't installed) is intentionally left to the missing-deps agent. Refs run 25870737355.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
next.config.{js,ts}CJS→ESM converter out of an inlinednode -e '…'blob inscripts/e2e-deploy.shand into a standalonescripts/cjs-to-esm-config.mjs. Same regex pipeline, no behavioural change.bash -n scripts/*.shgate to the Check job so this class of regression can't ship green.Why
The deploy-suite run 25869359604 reported
329 passed, 2480 failed, 653 skipped— a 9.5% pass rate. Investigating, every single failure was byte-identical:…and the runner logs showed the real cause:
bash -n scripts/e2e-deploy.shreproduces the error locally on843df83.Root cause
The CJS→ESM converter (added in #1189) was passed to
node -eas a single-quoted bash argument. The JS body used the'\"'\"'quote-escape trick repeatedly inside regex literals. The net effect rebalanced quoting such that some later lines — notably the comment// TODO: … (e.g. dynamic …on line 490 — sat outside a single-quoted bash region. Bash then saw(e.g. dynamic …)as shell syntax and refused to parse the whole script.The deploy step exited with status 2 before doing any work, so every deploy-suite test failed at
createNext()setup before any vinext code was exercised. The 329 "passes" were almost entirelyshould skip next deployplaceholders, not real assertions — effective real-test pass rate this run was 0%.What the fix does
scripts/cjs-to-esm-config.mjs: new standalone Node script with the identical regex pipeline (handlesmodule.exports = X,const X = require('mod'),const X = require('mod')(args),const { a, b } = require('mod'), and barerequire('mod')in expressions). Lives in a.mjsfile so its source is never re-parsed by bash.scripts/e2e-deploy.sh: the old 60-linenode -e '…'blob is replaced bynode "${VINEXT_DIR}/scripts/cjs-to-esm-config.mjs" "${config_file}". Net-65 / +13lines in the bash script..github/workflows/ci.yml: new step in the Check job runsbash -non everyscripts/*.sh. If anyone reintroduces a syntax error in a deploy-critical shell script, the Check gate fails on the PR.Verification
Locally:
Smoke-tested the converter against a representative
next.config.js:The regex pipeline is byte-for-byte the one that was inlined; only the wrapping changed.
Follow-up (not in this PR)
The harness reported
undefinedfor stderr in every failure (Custom deploy script failed: undefined (2)), which made the root cause invisible in the test report — you have to dig into raw runner logs to find the bash syntax error. Thedeploy-debug-Nartifacts also only containcontext.txtandpackage.json, no stdout/stderr capture from the deploy script itself. Worth a separate PR to fix the harness so future failures of this class are visible in the test report.After this lands, re-run the deploy suite to get the first real parity signal. With the harness fixed, the run will surface actual vinext bugs and parity gaps instead of one repeated harness error.