module: convert schema-only core module on convertCJSFilenameToURL

Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/58612
Fixes: https://github.com/nodejs/node/issues/58607
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Alex Yang 2025-06-25 09:49:56 -07:00 committed by GitHub
parent f08e0a0fa0
commit a705e240b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 93 additions and 4 deletions

View file

@ -6,6 +6,7 @@ const {
ArrayPrototypeSplice,
ObjectAssign,
ObjectFreeze,
StringPrototypeSlice,
StringPrototypeStartsWith,
Symbol,
} = primordials;
@ -126,9 +127,12 @@ function registerHooks(hooks) {
*/
function convertCJSFilenameToURL(filename) {
if (!filename) { return filename; }
const builtinId = BuiltinModule.normalizeRequirableId(filename);
if (builtinId) {
return `node:${builtinId}`;
let normalizedId = filename;
if (StringPrototypeStartsWith(filename, 'node:')) {
normalizedId = StringPrototypeSlice(filename, 5);
}
if (BuiltinModule.canBeRequiredByUsers(normalizedId)) {
return `node:${normalizedId}`;
}
// Handle the case where filename is neither a path, nor a built-in id,
// which is possible via monkey-patching.