module: preserve URL in the parent created by createRequire() · nodejs/node@edec5be · GitHub
Skip to content

Commit edec5be

Browse files
joyeecheungaduh95
authored andcommitted
module: preserve URL in the parent created by createRequire()
Previously, createRequire() does not preserve the URL it gets passed in the mock parent module created, which can be observable if it's used together with module.registerHooks(). This patch adds preservation of the URL if createRequire() is invoked with one. PR-URL: #60974 Fixes: #60973 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
1 parent 49f3672 commit edec5be

4 files changed

Lines changed: 50 additions & 13 deletions

File tree

lib/internal/modules/cjs/loader.js

Lines changed: 21 additions & 13 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createRequire } from 'node:module'
2+
const require = createRequire(import.meta.url);
3+
require('./empty.mjs');

test/fixtures/module-hooks/empty.mjs

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions

0 commit comments

Comments
 (0)