Skip to content

Commit

Permalink
handle resolution of relative URLs LHS in import maps (#2039)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Oct 5, 2019
1 parent e7af7c9 commit 958aa91
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit 958aa91

Please sign in to comment.