Skip to content

fix: #851 — Rollup-bundled CJS-inside-ESM no longer triggers ImportExportInScript#882

Merged
proggeramlug merged 1 commit into
mainfrom
fix/851-rollup-cjs-in-esm
May 16, 2026
Merged

fix: #851 — Rollup-bundled CJS-inside-ESM no longer triggers ImportExportInScript#882
proggeramlug merged 1 commit into
mainfrom
fix/851-rollup-cjs-in-esm

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

  • crates/perry/src/commands/compile/cjs_wrap.rs::is_commonjs now short-circuits to ESM when any top-level (non-indented) import / export statement is present, regardless of module.exports / require( tokens deeper in the file
  • 7 new unit tests in cjs_wrap.rs cover Rollup hybrid shapes, identifier-continuation guards (exports.fooexport, importMapimport), export *, dynamic import('./x'), and indented-import guard
  • End-to-end smoke test test-files/test_issue_851_rollup_cjs_in_esm.ts compiles natively (ok-851)

Validation

  • cargo test --release -p perry cjs_wrap: 48 passed, 0 failed
  • Pre-fix vitest repro: parse error at offset 12817 (ImportExportInScript)
  • Post-fix vitest repro: parses cleanly, advances to link stage (then fails on missing libperry_jsruntime.a — separate downstream issue)

Test plan

  • Unit tests pass (48/48 in cjs_wrap)
  • End-to-end smoke test produces ok-851
  • vitest no longer hits ImportExportInScript

Closes #851.

… ImportExportInScript

When the entry file (or any file in a compilePackages target) has top-level
ESM `import`/`export` statements with inlined CJS bodies inside helper
IIFEs (the shape Rollup produces for bundled-with-CJS-deps output), the
file is unambiguously ESM — skip the CJS wrap regardless of whether
`module.exports`-style tokens appear deeper in the source.

Closes #851.
@proggeramlug proggeramlug merged commit 519581d into main May 16, 2026
9 checks passed
@proggeramlug proggeramlug deleted the fix/851-rollup-cjs-in-esm branch May 16, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vitest fails to compile under perry.compilePackages: Rollup-bundled CJS-inside-ESM module rejected as ImportExportInScript

1 participant