mirror of https://github.com/nodejs/node.git
esm: fix relative imports for https
PR-URL: https://github.com/nodejs/node/pull/42119 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
6b6bada16a
commit
f860b3810f
|
@ -1125,7 +1125,7 @@ async function defaultResolve(specifier, context = {}, defaultResolveUnused) {
|
|||
)
|
||||
)
|
||||
) {
|
||||
return { url: specifier };
|
||||
return { url: parsed.href };
|
||||
}
|
||||
} catch {
|
||||
// Ignore exception
|
||||
|
|
|
@ -61,6 +61,10 @@ for (const { protocol, createServer } of [
|
|||
const host = new URL(base);
|
||||
host.protocol = protocol;
|
||||
host.hostname = hostname;
|
||||
// /not-found is a 404
|
||||
// ?redirect causes a redirect, no body. JSON.parse({status:number,location:string})
|
||||
// ?mime sets the content-type, string
|
||||
// ?body sets the body, string
|
||||
const server = createServer(function(_req, res) {
|
||||
const url = new URL(_req.url, host);
|
||||
const redirect = url.searchParams.get('redirect');
|
||||
|
@ -133,6 +137,14 @@ for (const { protocol, createServer } of [
|
|||
assert.strict.equal(depsNS.data, 1);
|
||||
assert.strict.equal(depsNS.http, ns);
|
||||
|
||||
const relativeDeps = new URL(url.href);
|
||||
relativeDeps.searchParams.set('body', `
|
||||
import * as http from "./";
|
||||
export {http};
|
||||
`);
|
||||
const relativeDepsNS = await import(relativeDeps.href);
|
||||
assert.strict.deepStrictEqual(Object.keys(relativeDepsNS), ['http']);
|
||||
assert.strict.equal(relativeDepsNS.http, ns);
|
||||
const fileDep = new URL(url.href);
|
||||
const { href } = pathToFileURL(path('/es-modules/message.mjs'));
|
||||
fileDep.searchParams.set('body', `
|
||||
|
|
Loading…
Reference in New Issue