deno
e6041cdd - feat(ext/node): add module.register / module.registerHooks

Commit
163 days ago
feat(ext/node): add module.register / module.registerHooks Implements the Node.js customization-hooks public API on `node:module`: * `register(specifier, parentURL, options)` — async API. Loads the hooks module synchronously via `op_import_sync`, invokes `initialize(data)`, and stores any exported `resolve` / `load` hooks in a chain. * `registerHooks({ resolve, load })` — sync API. Returns `{ deregister() }` for removal. The two share the chain-of-hooks machinery (`nextResolve` / `nextLoad` threading toward defaults, re-entry guarding for hook-initiated requires) but maintain separate chains: the sync chain fires from CJS paths (`Module._resolveFilename`, `Module.prototype.load`); the async chain is reserved for ESM dynamic-import wiring, which requires deno_core support that will land in a follow-up. With this change `require('node:module').register` is no longer a missing function, `initialize()` runs on registration with `options.data`, and sync resolve/load hooks intercept CJS `require()` and `require.resolve()` calls. The CJS load path now falls back to the unresolved filename if `op_require_real_path` errors while hooks are active, so that a resolve hook can redirect to a synthetic URL that a load hook then services without first being canonicalised on disk. Refs denoland/orchid#120 Co-Authored-By: Divy Srivastava <me@littledivy.com>
Author
Parents
Loading