Repository navigation
fix(parser): ship ESM entry points as .mjs - #182
pyramation wants to merge 1 commit into
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. 🟠 1 high · 🟡 1 medium 💬 Inline comments (1)
📍 Findings outside the diff (1) — 🟠 1 high — defects on lines GitHub can't attach comments to🟠 High — Renamed // parser/scripts/prepare.js
125 if (file.endsWith('.js') || file.endsWith('.cjs') || file.endsWith('.d.ts')) {
126 let content = fs.readFileSync(destPath, 'utf8');
127 // Node's ESM resolver rejects directory imports, so ESM files need the full path.
128 const typesPath = file.endsWith('.js') ? './types/index.js' : './types';The copy step now renames each version's ESM entry to Even if the rewrite condition is widened, the path selection ternary at parser/scripts/prepare.js:128 must treat the renamed file as ESM ( This PR switches the per-version ESM entry point to
Risk concentrates on published package resolution: the renamed ESM entry bypasses the existing Reviewed commit: eee3f00 |
There was a problem hiding this comment.
Renames the generated ESM entry to index.mjs and adds an ESM smoke test, but the renamed entry skips the @pgsql/types rewrite and the test masks spawn failures.
Key findings
- 🟠 Renamed
index.mjsskips the@pgsql/typesrewrite — prepare.js:125 - 🟡 spawnSync spawn failures surface as
null == 0— esm.test.mjs:42
| const { status, stderr } = spawnSync(process.execPath, [...flags, '--input-type=module', '-e', script], { | ||
| cwd: fileURLToPath(new URL('..', import.meta.url)), | ||
| encoding: 'utf8', | ||
| }); | ||
| assert.equal(status, 0, stderr); |
There was a problem hiding this comment.
🟡 bug · medium
spawnSync spawn failures surface as null == 0
spawnSync reports spawn failures (ENOENT, EACCES) and signal kills as status: null plus an error field, which the test destructures away (parser/test/esm.test.mjs:42). assert.equal(status, 0, stderr) at parser/test/esm.test.mjs:46 then fails as null == 0 with an empty or misleading message, turning an infrastructure failure into an opaque one. The child's stdout is also discarded and the inline script throws a bare 'bad parse', so a failing matrix entry may give no actionable output.
📋 Prompt for AI Agents
In parser/test/esm.test.mjs lines 42-46, destructure error and stdout from the spawnSync result; before assert.equal(status, 0, stderr) add assert.ifError(error), and change the assertion message to include the specifier and both streams, e.g. assert.equal(status, 0, import ${specifier} failed\nstdout: ${stdout}\nstderr: ${stderr}), so spawn failures (ENOENT, signal kills) and parse failures produce actionable CI output instead of null == 0 with an empty stderr.
|
Folded into #190 |
Summary
@pgsql/parser'simportentry points are ES modules in.jsfiles, but the package has no"type": "module". Node 18, and Node 20 before 20.19, therefore load them as CommonJS, soimport '@pgsql/parser'and every@pgsql/parser/v13…v18subpath fail withSyntaxError: Unexpected token 'export'. Newer Node versions only work because of module syntax detection.requirewas never affected, and neither are the sixlibpg-querypackages (they have noexportsmap, soimportresolves tomain, which is.cjs).Repro with 1.6.2 on Node 18.20.8:
Changes, all in
parser/:prepare.jswrites the ESM files as.mjs:wasm/index.mjs,wasm/v<n>.mjsandwasm/v<n>/index.mjs, which was copied fromversions/<n>/wasm/index.js. Theexport * as v<n>and dynamicimport()specifiers now point atindex.mjs.package.json: theimportconditions andmodulenow point at.mjs.typesis listed first in each condition so TypeScript keeps resolvingindex.d.ts(checked withtsc --module nodenextagainst the packed tarball).test/esm.test.mjs: imports the root and each subpath in a childnode --no-experimental-detect-module. That flag reproduces the Node 18 behaviour on current Node.Evidence:
ERR_REQUIRE_CYCLE_MODULE), and on Node 18 all 14 ESM tests fail.npm packtarball works with ESMimportand CJSrequirefor the rootParserand all six subpaths on all four Node versions.Link to Devin session: https://app.devin.ai/sessions/68876ce060664609ab6b63c8bed91e78
Open in Devin Desktop: https://app.devin.ai/desktop/session/68876ce060664609ab6b63c8bed91e78?variant=devin
Requested by: @pyramation