mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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:
parent
f08e0a0fa0
commit
a705e240b1
3 changed files with 93 additions and 4 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue