feat(napi/parser)!: change oxc-parser to ESM#13432
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
ef96fbd to
70d2beb
Compare
module7be216d to
a76003d
Compare
a76003d to
53d04e4
Compare
Merge activity
|
53d04e4 to
27358db
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR converts the oxc-parser NAPI package from CommonJS module format to ESM format by changing all .js file extensions to .mjs and updating module syntax.
- Updates generated file extensions from
.jsto.mjsthroughout the codebase - Converts CommonJS
require()statements to ESMimportstatements - Changes
module.exportsto ES6exportstatements - Updates build configurations and file references to use
.mjsextensions
Reviewed Changes
Copilot reviewed 30 out of 40 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
tasks/ast_tools/src/generators/raw_transfer_lazy.rs |
Updates generated file paths to use .mjs extensions and converts generated JS code to ESM format |
tasks/ast_tools/src/generators/raw_transfer.rs |
Changes generated file paths to .mjs and converts generated JavaScript to use ESM syntax |
napi/parser/test/*.ts |
Updates test file imports to use .mjs extensions |
napi/parser/raw-transfer/*.mjs |
Converts CommonJS modules to ESM format with proper import/export syntax |
napi/parser/index.mjs |
Main entry point converted from CommonJS to ESM |
napi/parser/bindings.mjs |
NAPI bindings file converted to ESM format |
napi/parser/package.json |
Updates build configuration and file references for ESM |
napi/oxlint2/** |
Updates references to parser files to use .mjs extensions |
Comments suppressed due to low confidence (6)
napi/parser/index.mjs:1
- The function still uses
require()with.jsextension instead of ESMimport. This should be updated to use dynamic import with.mjsextension.
import { parseAsync as parseAsyncBinding, parseSync as parseSyncBinding } from './bindings.mjs';
napi/parser/index.mjs:1
- The function still uses
require()with.jsextension instead of ESMimport. This should be updated to use dynamic import with.mjsextension.
import { parseAsync as parseAsyncBinding, parseSync as parseSyncBinding } from './bindings.mjs';
napi/parser/raw-transfer/eager.mjs:1
- Still uses
require()with.jsextension. Should be updated to use dynamic import with.mjsextension.
import { isJsAst, parseAsyncRawImpl, parseSyncRawImpl, returnBufferToCache } from './common.mjs';
napi/parser/raw-transfer/eager.mjs:1
- Still uses
require()with.jsextension. Should be updated to use dynamic import with.mjsextension.
import { isJsAst, parseAsyncRawImpl, parseSyncRawImpl, returnBufferToCache } from './common.mjs';
napi/parser/test/parse-raw-worker.mjs:1
- Import references
.cjsextension which should be.mjsto match the file extension changes in this PR.
// Worker for raw transfer tests.
napi/parser/raw-transfer/visitor.mjs:1
- Still uses CommonJS
module.exportssyntax. Should be converted to ES6 export syntax.
import { LEAF_NODE_TYPES_COUNT, NODE_TYPE_IDS_MAP, NODE_TYPES_COUNT } from '../generated/lazy/types.mjs';
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
27358db to
ae34489
Compare
7529a98 to
05dcce9
Compare
|
Tests for both However, I'm not familiar enough with the build/publish system to be confident this PR doesn't break anything, especially related to WASM. There remain some files in
Note: |
oxc-parser to ESM
05dcce9 to
4577b71
Compare
Follow-on after #13432. That PR removed usage of `constructor_names`, so it's now dead code. Remove it.
In #13432 the filename was changed but `main` remained as is. I'm now seeing following error in Vitest: ``` ⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯ Error: Failed to resolve entry for package "oxc-parser". The package may have incorrect main/module/exports specified in its package.json. 1 | import { parse as BabelParser } from "@babel/parser"; 2 | import { parse as AcornParser } from "acorn"; 3 | import { parseSync as OxcParser } from "oxc-parser"; | ^ 4 | import { parseAst as ViteParser } from "vite"; 5 | import { expectTypeOf, test } from "vitest"; ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ ``` https://github.com/AriPerkkio/ast-v8-to-istanbul/actions/runs/17722503037/job/50357275013?pr=86 See errors from https://publint.dev/oxc-parser@0.88.0. Signed-off-by: Ari Perkkiö <ari.perkkio@gmail.com>
Completion of the work begun in #13432. Make `oxc-parser` package fully ESM. Aside from adding `"type": "module"` to `package.json`, only other change required is renaming `webcontainer-fallback.js` -> `webcontainer-fallback.cjs`. All other files already have the extension matching their ESM/CommonJS content.

closes #13329