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

Handle resolution of relative URLs LHS in import maps #2039

Merged
merged 1 commit into from
Oct 5, 2019
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
3 changes: 2 additions & 1 deletion src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function objectAssign (to, from) {

function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap, parentUrl) {
for (let p in packages) {
const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
const rhs = packages[p];
// package fallbacks not currently supported
if (typeof rhs !== 'string')
Expand All @@ -129,7 +130,7 @@ function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap, p
if (!mapped)
targetWarning(p, rhs, 'bare specifier did not resolve');
else
outPackages[p] = mapped;
outPackages[resolvedLhs] = mapped;
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/import-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function doResolveImportMap (id, parentUrl, importMap) {
describe('Import Maps', function () {
const firstImportMap = resolveAndComposeImportMap({
imports: {
"./asdf": "./asdf-asdf",
"t": "./src/t",
"t/": "./src/t/",
"r": "./src/r"
Expand Down Expand Up @@ -55,6 +56,10 @@ describe('Import Maps', function () {
assert.equal(doResolveImportMap('/x', 'https://site.com/', baseImportMap), 'https://sample.com/x.js');
});

it('Can map relative URLs', function () {
assert.equal(doResolveImportMap('/asdf', 'https://sample.com/', baseImportMap), 'https://sample.com/asdf-asdf');
});

it('Resolves packages with main sugar', function () {
assert.equal(doResolveImportMap('x', 'https://site.com', baseImportMap), 'https://sample.com/y');
});
Expand Down