Skip to content

feat(napi/parser)!: change oxc-parser to ESM#13432

Merged
graphite-app[bot] merged 1 commit intomainfrom
08-30-feat_napi_parser_change_module_type_to_module_
Sep 8, 2025
Merged

feat(napi/parser)!: change oxc-parser to ESM#13432
graphite-app[bot] merged 1 commit intomainfrom
08-30-feat_napi_parser_change_module_type_to_module_

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Aug 30, 2025

closes #13329

@github-actions github-actions bot added the C-enhancement Category - New feature or request label Aug 30, 2025
Copy link
Member Author

Boshen commented Aug 30, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@Boshen Boshen marked this pull request as draft August 30, 2025 15:45
@Boshen Boshen force-pushed the 08-30-feat_napi_parser_change_module_type_to_module_ branch from ef96fbd to 70d2beb Compare August 31, 2025 08:53
@github-actions github-actions bot added the A-ast-tools Area - AST tools label Aug 31, 2025
@Boshen Boshen changed the title feat(napi/parser)!: change module type to module feat(napi/parser)!: change module type to ESM Aug 31, 2025
@Boshen Boshen force-pushed the 08-30-feat_napi_parser_change_module_type_to_module_ branch 4 times, most recently from 7be216d to a76003d Compare August 31, 2025 10:19
@Boshen Boshen marked this pull request as ready for review August 31, 2025 10:22
@Boshen Boshen requested a review from overlookmotel as a code owner August 31, 2025 10:22
@Boshen Boshen force-pushed the 08-30-feat_napi_parser_change_module_type_to_module_ branch from a76003d to 53d04e4 Compare August 31, 2025 10:27
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 1, 2025
Copy link
Member Author

Boshen commented Sep 1, 2025

Merge activity

  • Sep 1, 3:29 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Sep 8, 10:52 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Sep 8, 10:52 AM UTC: Boshen added this pull request to the Graphite merge queue.
  • Sep 8, 10:58 AM UTC: Merged by the Graphite merge queue.

@overlookmotel overlookmotel self-assigned this Sep 6, 2025
@overlookmotel overlookmotel removed the 0-merge Merge with Graphite Merge Queue label Sep 8, 2025
Copilot AI review requested due to automatic review settings September 8, 2025 04:55
@overlookmotel overlookmotel force-pushed the 08-30-feat_napi_parser_change_module_type_to_module_ branch from 53d04e4 to 27358db Compare September 8, 2025 04:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .js to .mjs throughout the codebase
  • Converts CommonJS require() statements to ESM import statements
  • Changes module.exports to ES6 export statements
  • Updates build configurations and file references to use .mjs extensions

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 .js extension instead of ESM import. This should be updated to use dynamic import with .mjs extension.
import { parseAsync as parseAsyncBinding, parseSync as parseSyncBinding } from './bindings.mjs';

napi/parser/index.mjs:1

  • The function still uses require() with .js extension instead of ESM import. This should be updated to use dynamic import with .mjs extension.
import { parseAsync as parseAsyncBinding, parseSync as parseSyncBinding } from './bindings.mjs';

napi/parser/raw-transfer/eager.mjs:1

  • Still uses require() with .js extension. Should be updated to use dynamic import with .mjs extension.
import { isJsAst, parseAsyncRawImpl, parseSyncRawImpl, returnBufferToCache } from './common.mjs';

napi/parser/raw-transfer/eager.mjs:1

  • Still uses require() with .js extension. Should be updated to use dynamic import with .mjs extension.
import { isJsAst, parseAsyncRawImpl, parseSyncRawImpl, returnBufferToCache } from './common.mjs';

napi/parser/test/parse-raw-worker.mjs:1

  • Import references .cjs extension which should be .mjs to match the file extension changes in this PR.
// Worker for raw transfer tests.

napi/parser/raw-transfer/visitor.mjs:1

  • Still uses CommonJS module.exports syntax. 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.

@overlookmotel overlookmotel force-pushed the 08-30-feat_napi_parser_change_module_type_to_module_ branch from 27358db to ae34489 Compare September 8, 2025 06:57
@overlookmotel overlookmotel marked this pull request as draft September 8, 2025 07:02
@overlookmotel overlookmotel force-pushed the 08-30-feat_napi_parser_change_module_type_to_module_ branch from 7529a98 to 05dcce9 Compare September 8, 2025 08:14
@overlookmotel overlookmotel marked this pull request as ready for review September 8, 2025 08:15
@overlookmotel
Copy link
Member

overlookmotel commented Sep 8, 2025

Tests for both napi/parser and napi/oxlint2 are now all passing without modification.

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 napi/parser which are ESM but with .js extension:

  • browser.js
  • header.js
  • parser.wasi-browser.js

package.json contains "type": "commonjs", so NodeJS module resolution says these files should be CJS. Should we make them .mjs too? Or are they all browser-only so it's not relevant?

Note: webcontainer-fallback.js also has .js ext, but that one is CJS.

@overlookmotel overlookmotel removed their assignment Sep 8, 2025
@Boshen Boshen changed the title feat(napi/parser)!: change module type to ESM feat(napi/parser)!: change oxc-parser to ESM Sep 8, 2025
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 8, 2025
@graphite-app graphite-app bot force-pushed the 08-30-feat_napi_parser_change_module_type_to_module_ branch from 05dcce9 to 4577b71 Compare September 8, 2025 10:53
@graphite-app graphite-app bot merged commit 4577b71 into main Sep 8, 2025
17 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 8, 2025
@graphite-app graphite-app bot deleted the 08-30-feat_napi_parser_change_module_type_to_module_ branch September 8, 2025 10:58
graphite-app bot pushed a commit that referenced this pull request Sep 8, 2025
Follow-on after #13432. That PR removed usage of `constructor_names`, so it's now dead code. Remove it.
Boshen pushed a commit that referenced this pull request Sep 15, 2025
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>
graphite-app bot pushed a commit that referenced this pull request Sep 23, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make oxc packages ESM-only

3 participants