Skip to content

refactor: use module.registerHooks for the gi: ESM loader - #486

Merged
romgrk merged 1 commit into
masterfrom
esm-register-hooks
Jul 4, 2026
Merged

romgrk merged 1 commit into
masterfrom
esm-register-hooks

Conversation

@romgrk

@romgrk romgrk commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Switches the gi: scheme ESM loader from module.register to module.registerHooks.

What

  • lib/esm/register.mjs — calls registerHooks({ resolve, load }) with the hook functions directly. Because registerHooks takes functions (not a module URL) and runs them synchronously, in-thread, the whole implementation is consolidated here.
  • lib/esm/hooks.mjs — removed. It only needed to be a separate URL-loaded file for the old register(url) mechanism. The resolve/load hooks are now synchronous (as registerHooks requires) and module-private.
  • package.json — dropped the now-dead ./hooks export (undocumented and unused; existed solely for URL-based registration).
  • doc/importing.md — minimum bumped from Node ≥ 20.6 (module.register) to Node ≥ 22.15 (module.registerHooks). node-gtk v4 already targets Node 22/24/26.

The synthetic gi.require module emitted by load is unchanged, so runtime behavior of gi: imports is identical.

Verified locally

All import paths pass against the consolidated file:

  • Static import GLib from 'gi:GLib-2.0' via --import node-gtk/register
  • tests/esm__gi_import.js runner (exit 0)
  • Programmatic import 'node-gtk/register' + dynamic import
  • Versionless gi:GLib

Note

Removing the ./hooks export is a (dead) public-API change — it was never documented and nothing imported node-gtk/hooks.

🤖 Generated with Claude Code

Switch the `gi:` scheme loader from `module.register` (async hooks on a
separate loader thread, loaded by URL) to `module.registerHooks` (synchronous,
in-thread hooks passed directly as functions).

Since registerHooks takes the hook functions rather than a module URL, the
whole implementation now lives in register.mjs and the separate hooks.mjs file
(plus its `./hooks` package export, which was unused) is removed. The resolve
and load hooks are now synchronous, as registerHooks requires; the synthetic
`gi.require` module emitted by `load` is unchanged.

Bumps the minimum from Node >= 20.6 (module.register) to Node >= 22.15
(module.registerHooks); node-gtk v4 already targets Node 22/24/26.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@romgrk
romgrk merged commit 6132b2d into master Jul 4, 2026
17 of 18 checks passed
@romgrk
romgrk deleted the esm-register-hooks branch July 4, 2026 22:45
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