Repository navigation
Conversation
In native ESM, `import * as fs` is a read-only module namespace, so patching it threw `Cannot assign to read only property`. Patch the mutable CJS `fs` object behind the default export instead, and sync builtin ESM exports so named imports see the wrappers. The fs integration tests now also run in ESM. Fixes #25950 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
bugbot run |
size-limit report 📦Compared: fc15b78 (PR test merge using develop at b9d0f82) Against: b9d0f82 (develop) · base run #64917 ✅ Baseline matches: this diff contains only this PR's changes.
|
Optional E2E testsSome optional checks were not successful. They do not block the merge. 3 not successful, 41 successful. See the run.
Successful checks
|
The Bun build project runs a bundled scenario outside the test's tmp dir, so a path derived from the scenario location missed the fixtures. Also skip the ESM tests on Bun, whose ESM `node:fs` exports behave like Deno's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
bugbot run |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ded32e7. Configure here.
| const createRunner = (): ReturnType<typeof createTestRunner> => | ||
| createTestRunner().withEnv({ FIXTURES_DIR: join(cwd, 'fixtures') }); | ||
| // On Bun and Deno the ESM `node:fs` exports are not tied to the `fs` object we patch, so only `fs.promises` is traced there. | ||
| const testUnlessNonNodeEsm = test.runIf(mode === 'cjs' || supports({ runtimes: ['node'] })); |
There was a problem hiding this comment.
no strong feelings, but would it be good enough to just only run these tests in cjs...? 🤔
There was a problem hiding this comment.
Hm this would defeat the purpose of the pr then, since it is about native esm?
Why: In native ESM,
fsIntegrationcrashed withCannot assign to read only property, because it patched the read-onlyimport * as fsnamespace. It now patches the mutablefsobject behind the default export. A plainimport fs from 'fs'isn't an option: our rollupinterop: 'esModule'setting would turn it intorequire('fs').defaultin the CJS build, which is undefined. After patching, it callssyncBuiltinESMExports()so named imports (import { readFile } from 'fs') pick up the patched functions. That call is wrapped in try/catch because Cloudflare workerd exports it but throws when it's called.How to review: The fix is in
instrumentation.ts. The fs suite now runs in both ESM and CJS. On Bun and Deno, the ESMnode:fsexports aren't tied to the object we patch, so onlyfs.promisescalls get spans there. For that reason those ESM tests run on Node only. The named-import test is ESM-only, because CJS destructuring copies the functions before the patch is applied.Unsure about:
syncBuiltinESMExports()updates the ESM exports of every builtin module, not onlyfs. It only makes patches applied to the CJS objects visible to ESM importers, so it shouldn't affect anything else.Closes #25950