feat(DEP0205): migrate compatible module hooks to `module.registerHooks()`

Aperta
#561 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
devtools, tooling

Direzione di ricerca

Start by locating the codemod entry point and fixtures for module.register() calls; trace how it can inspect both the registration site and each referenced local hook module. Define conservative checks for compatible synchronous resolve hooks and preserve registration-before-application loading order. Done means supported cases are transformed and fixtures cover aliases, unresolved specifiers, unsupported hooks, and load order, while unsafe cases are skipped or reported.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

module.register() became runtime-deprecated in Node.js 26.0.0 under DEP0205. The replacement is module.registerHooks().

This is not a direct function rename. register() loads hook implementations on a separate loader thread, while registerHooks() receives synchronous hook functions that execute on the thread loading the modules.

Add a partial migration for local hook modules whose behavior is compatible with synchronous, same-thread execution. The codemod must inspect both the registration site and the referenced hook module before proposing edits.

Additional Information

  • Start with literal local module specifiers and simple, stateless resolve hooks that already use synchronous control flow and return plain objects or the result of nextResolve().
  • Introduce an import of the supported hook function and pass it through registerHooks({ resolve }), preserving binding names and avoiding collisions.
  • Preserve loading order: application modules that need customization must still be loaded after hook registration, using dynamic import() or an appropriate require().
  • Moving the hook module to the main thread can change its initialization order, global state, side effects, and interaction with other registered hooks. Skip cases where compatibility cannot be established.
  • Skip hooks using initialize, transferred data, MessagePorts, asynchronous I/O, unresolved dependencies, or thread-specific behavior.
  • Do not remove async or await mechanically. Async load hooks, CommonJS-specific behavior, mixed hook chains, and worker inheritance need separate analysis.
  • Programmatically registered synchronous hooks are not inherited by child workers in the same way as asynchronous hooks. Report applications relying on that inheritance; preloaded registration files require their own review.
  • Keep existing registerHooks() calls unchanged. Include fixtures for supported local hooks, aliases, unresolved module specifiers, unsupported hooks, and application load order.

Examples

For a local hooks.mjs containing only a compatible stateless resolve export, the registration file can change as follows:

-import { register } from 'node:module';
+import { registerHooks } from 'node:module';
+import { resolve } from './hooks.mjs';

-register('./hooks.mjs', import.meta.url);
+registerHooks({ resolve });
 await import('./app.mjs');

Example compatible hooks.mjs, unchanged by this migration:

export function resolve(specifier, context, nextResolve) {
  if (specifier === 'app:config') {
    return {
      url: new URL('./config.mjs', import.meta.url).href,
      shortCircuit: true,
    };
  }
  return nextResolve(specifier, context);
}

This example assumes that the hook module has no initialization effects or dependencies on loader-thread isolation, existing hook chains, or worker inheritance. More complex modules should be reported for manual migration.

Refs

Lingua principale
TypeScript
Stelle
85
Fork
58
Merge medio
1g 21h
PR unite (30g)
8

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/userland-migrations

Tutte le issue di nodejs/userland-migrations

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.