Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm: fix relative imports for https #42119

Merged
merged 2 commits into from Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/resolve.js
Expand Up @@ -1125,7 +1125,7 @@ async function defaultResolve(specifier, context = {}, defaultResolveUnused) {
)
)
) {
return { url: specifier };
return { url: parsed.href };
}
} catch {
// Ignore exception
Expand Down
12 changes: 12 additions & 0 deletions test/es-module/test-http-imports.mjs
Expand Up @@ -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');
Expand Down Expand Up @@ -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', `
Expand Down