Skip to content

Commit 2bc136d

Browse files
bmecksxa
authored andcommitted
esm: fix relative imports for https
PR-URL: #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>
1 parent cad7dde commit 2bc136d

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎lib/internal/modules/esm/resolve.js‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ for (const { protocol, createServer } of [
6161
consthost=newURL(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
constserver=createServer(function(_req,res){
6569
consturl=newURL(_req.url,host);
6670
constredirect=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+
constrelativeDeps=newURL(url.href);
141+
relativeDeps.searchParams.set('body',`
142+
import * as http from "./";
143+
export {http};
144+
`);
145+
constrelativeDepsNS=awaitimport(relativeDeps.href);
146+
assert.strict.deepStrictEqual(Object.keys(relativeDepsNS),['http']);
147+
assert.strict.equal(relativeDepsNS.http,ns);
136148
constfileDep=newURL(url.href);
137149
const{ href }=pathToFileURL(path('/es-modules/message.mjs'));
138150
fileDep.searchParams.set('body',`

0 commit comments

Comments
 (0)