diff --git a/mod.js b/mod.js index 64dbf48..f9e3ad6 100644 --- a/mod.js +++ b/mod.js @@ -85,7 +85,7 @@ export class Importer { * [dynamic `import()` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports). * Except with the faked modules applied. * @template T - * @param {string | URL} url + * @param {string} url * @returns {Promise} */ async import(url) { diff --git a/src/ImportResolver.js b/src/ImportResolver.js index fe75873..9d076d4 100644 --- a/src/ImportResolver.js +++ b/src/ImportResolver.js @@ -240,16 +240,18 @@ export class ImportResolver { * Once every file has loaded and its import urls replaced with blobs, * the entry point is imported with a regular async import call. * @template T - * @param {string | URL} url + * @param {string} url * @returns {Promise} */ async import(url) { this.#hasMadeImportCall = true; - if (typeof url === "string") { - url = new URL(url, this.#importMeta); - } + const newUrl = resolveModuleSpecifier( + this.#parsedImportMap, + new URL(this.#importMeta), + url, + ); await this.loadImportMap(); - const collectedImport = this.createCollectedImport(url.href); + const collectedImport = this.createCollectedImport(newUrl.href); let module; try { module = await import(await collectedImport.getBlobUrl()); diff --git a/test/integration/importMap.test.js b/test/integration/importMap.test.js index fed5a18..c896237 100644 --- a/test/integration/importMap.test.js +++ b/test/integration/importMap.test.js @@ -29,7 +29,7 @@ Deno.test({ }, }); - const module = await importer.import("main.js"); + const module = await importer.import("./main.js"); assertEquals(module.foo, "foo"); } finally { await cleanup(); @@ -83,7 +83,7 @@ Deno.test({ const importer = new Importer(basePath); importer.setImportMap("./importmap.json"); - const module = await importer.import("main.js"); + const module = await importer.import("./main.js"); assertEquals(module.foo, "foo"); } finally { await cleanup(); @@ -114,7 +114,7 @@ Deno.test({ }, }); - const module = await importer.import("main.js"); + const module = await importer.import("./main.js"); assertEquals(module.foo, "foo"); } finally { await cleanup(); @@ -146,7 +146,7 @@ Deno.test({ }, }); - const module = await importer.import("main.js"); + const module = await importer.import("./main.js"); assertEquals(module.foo, "foo"); } finally { await cleanup(); @@ -156,7 +156,6 @@ Deno.test({ Deno.test({ name: "importing a bare specifier directly without an import map", - ignore: true, async fn() { const { cleanup, basePath } = await simpleReplacementDir(); @@ -191,7 +190,7 @@ Deno.test({ const importer = new Importer(basePath); await assertRejects( async () => { - await importer.import("main.js"); + await importer.import("./main.js"); }, TypeError, `Relative import path "bare" not prefixed with / or ./ or ../`, @@ -204,7 +203,6 @@ Deno.test({ Deno.test({ name: "importing a bare specifier directly that is not in the import map", - ignore: true, async fn() { const { cleanup, basePath } = await simpleReplacementDir(); @@ -249,7 +247,7 @@ Deno.test({ }); await assertRejects( async () => { - await importer.import("main.js"); + await importer.import("./main.js"); }, TypeError, `Relative import path "bare" not prefixed with / or ./ or ../`, @@ -272,7 +270,7 @@ Deno.test({ const fullImportPath = new URL(importMapFileName, basePath); await assertRejects( async () => { - await importer.import("main.js"); + await importer.import("./main.js"); }, TypeError, `Failed install import map from "${fullImportPath}". A network error occurred while fetching the module.`, @@ -300,7 +298,7 @@ Deno.test({ const fullImportPath = new URL(importMapFileName, basePath); await assertRejects( async () => { - await importer.import("main.js"); + await importer.import("./main.js"); }, TypeError, `Failed install import map from "${fullImportPath}". The resource did not respond with an ok status code (404).`,