diff --git a/packages/cli/src/loader.js b/packages/cli/src/loader.js index 8e139c353..cd03ef14e 100644 --- a/packages/cli/src/loader.js +++ b/packages/cli/src/loader.js @@ -17,11 +17,11 @@ function getCustomLoaderPlugins(url, body, headers) { // https://nodejs.org/docs/latest-v16.x/api/esm.html#resolvespecifier-context-nextresolve export function resolve(specifier, context, defaultResolve) { - const { baseURL } = context; + const { parentURL } = context; if (getCustomLoaderPlugins(specifier).length > 0) { return { - url: new URL(specifier, baseURL).href, + url: new URL(specifier, parentURL).href, shortCircuit: true }; } diff --git a/test/test-loader.js b/test/test-loader.js index 3d7177ffa..e0d9cb7be 100644 --- a/test/test-loader.js +++ b/test/test-loader.js @@ -2,7 +2,7 @@ // https://github.com/nodejs/node/discussions/41711 import fs from 'fs'; import path from 'path'; -import { load as experimentalLoad } from '../packages/cli/src/loader.js'; +import { load as experimentalLoad, resolve as experimentalResolve } from '../packages/cli/src/loader.js'; export async function load(url, context, defaultLoad) { const ext = path.extname(url); @@ -14,6 +14,16 @@ export async function load(url, context, defaultLoad) { } } +export function resolve(specifier, context, defaultResolve) { + const ext = path.extname(specifier); + + if (ext === '') { + return experimentalResolve(specifier, context, defaultResolve); + } else { + return defaultResolve(specifier, context, defaultResolve); + } +} + async function loadBin(url, context, defaultLoad) { const dirs = path.dirname(url.replace(/[A-Z]:\//g, '')).split('/'); const parentDir = dirs.at(-1);