Skip to content

refactor(js_interop_gen): generate internal Node.js bindings using js_interop_gen - #559

Open
kevmoo wants to merge 7 commits into
mainfrom
more_dts
Open

refactor(js_interop_gen): generate internal Node.js bindings using js_interop_gen#559
kevmoo wants to merge 7 commits into
mainfrom
more_dts

Conversation

@kevmoo

@kevmoo kevmoo commented Jun 13, 2026

Copy link
Copy Markdown
Member

Replace hand-rolled Node.js interop bindings (filesystem_api.dart, node.dart) with bindings generated directly by js_interop_gen itself (lib/src/js/generated/node_api.dart).

Summary of Changes

  • Generated Internal Node.js Bindings: Added tool/update_node_bindings.dart, tool/node_gen.yaml, and tool/node_entry.d.ts to generate node_api.dart using js_interop_gen itself, replacing legacy hand-rolled binding files.
  • Generator Enhancements: Updated parser, transformer, and AST declarations to support emitting UpperCamelCase type names and interface constructors.
  • Internal Migration: Refactored internal call sites across js_interop_gen (dart_main.dart, util.dart, doc_provider.dart, etc.) to use the generated Fs, Process, and options bag interop types.
  • Updated Integration Test Goldens: Updated test goldens to reflect UpperCamelCase interface type names and constructor signatures.
  • Dependencies: Added @types/node dependency to package.json.

…ated

Migrates the hand-rolled Node.js interop bindings in `js_interop_gen` to 100% generated bindings, dogfooding the generator on itself.

- Added `tool/node_entry.d.ts` declaring the curated Node.js APIs we use.
- Added `tool/node_gen.yaml` configuration for generating Node bindings.
- Added `tool/update_node_bindings.dart` runner script.
- Replaced hand-rolled `fs` and `process` bindings in `lib/src/js/filesystem_api.dart` and `lib/src/js/node.dart` with the generated `lib/src/js/generated/node_api.dart`.
- Defined safe options creator helpers in `filesystem_api.dart` to avoid calling non-existent JS constructors at runtime.
- Refactored all internal callers of `fs` to use the new generated bindings and helpers, removing extensive manual `.toJS` and `.toDart` conversions for strings and booleans.
- Updated integration test expectation `web_types_expected.dart` to match updated JSDoc comments from the new TypeScript package.
@kevmoo
kevmoo requested review from nikeokoronkwo and srujzs June 13, 2026 19:40

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request replaces manual Node.js interop definitions with generated bindings using a dogfooded configuration. It introduces a curated TypeScript definition file (node_entry.d.ts) and a script to generate the bindings, and updates the codebase to use these new APIs. Feedback suggests changing options bag declarations in the TypeScript file from class to interface to prevent the generator from producing problematic external constructors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread js_interop_gen/tool/node_entry.d.ts Outdated
@kevmoo

kevmoo commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces dogfooded, generated Node.js API bindings (node_api.dart) created from curated TypeScript definitions, replacing several hand-rolled bindings and simplifying file system operations across the codebase. The review feedback highlights two key areas for improvement: first, the generated extension types (fs, process, console) violate Dart's naming conventions by using lowercase and lack explicit @JS annotations, which makes them fragile; second, the generator should be updated to automatically emit external factory constructors for TypeScript interfaces, which would eliminate the need for hand-rolled helper functions like mkdirOptions.

Comment thread js_interop_gen/lib/src/js/generated/node_api.dart Outdated
Comment thread js_interop_gen/lib/src/js/filesystem_api.dart Outdated
kevmoo added 2 commits June 30, 2026 16:15
…tors

- Updated generator to emit UpperCamelCase extension type names (Fs, Process, Console) with explicit @js(...) namespace annotations for TypeScript namespaces.
- Updated generator to automatically emit external factory constructors for TypeScript interface extension types.
- Removed hand-rolled helper functions in favor of direct options bag constructors and direct imports.
- Updated test expectation goldens.
@kevmoo
kevmoo marked this pull request as draft June 30, 2026 23:41
@kevmoo

kevmoo commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

Need to rebase this and drop the new Dart SDK type bits...

@kevmoo kevmoo changed the title refactor(node-interop): migrate hand-rolled Node.js bindings to generated refactor(js_interop_gen): generate internal Node.js bindings using js_interop_gen Jul 1, 2026
@kevmoo
kevmoo marked this pull request as ready for review July 1, 2026 00:41
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.

1 participant