Skip to content

Commit f860b38

Browse files
authored
esm: fix relative imports for https
PR-URL: #42119 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 6b6bada commit f860b38

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/internal/modules/esm/resolve.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ async function defaultResolve(specifier, context = {}, defaultResolveUnused) {
11251125
)
11261126
)
11271127
) {
1128-
return { url: specifier };
1128+
return { url: parsed.href };
11291129
}
11301130
} catch {
11311131
// Ignore exception

test/es-module/test-http-imports.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ for (const { protocol, createServer } of [
6161
const host = new URL(base);
6262
host.protocol = protocol;
6363
host.hostname = hostname;
64+
// /not-found is a 404
65+
// ?redirect causes a redirect, no body. JSON.parse({status:number,location:string})
66+
// ?mime sets the content-type, string
67+
// ?body sets the body, string
6468
const server = createServer(function(_req, res) {
6569
const url = new URL(_req.url, host);
6670
const redirect = url.searchParams.get('redirect');
@@ -133,6 +137,14 @@ for (const { protocol, createServer } of [
133137
assert.strict.equal(depsNS.data, 1);
134138
assert.strict.equal(depsNS.http, ns);
135139

140+
const relativeDeps = new URL(url.href);
141+
relativeDeps.searchParams.set('body', `
142+
import * as http from "./";
143+
export {http};
144+
`);
145+
const relativeDepsNS = await import(relativeDeps.href);
146+
assert.strict.deepStrictEqual(Object.keys(relativeDepsNS), ['http']);
147+
assert.strict.equal(relativeDepsNS.http, ns);
136148
const fileDep = new URL(url.href);
137149
const { href } = pathToFileURL(path('/es-modules/message.mjs'));
138150
fileDep.searchParams.set('body', `

0 commit comments

Comments
 (0)