From 540bc81e0e779c614f5c3d8d01326b53b33d6044 Mon Sep 17 00:00:00 2001 From: Trygve Lie Date: Tue, 1 Nov 2022 16:12:18 +0100 Subject: [PATCH 1/2] feat: Full import map support BREAKING CHANGE: This ads full import map support and can in some cases, depending on the import map, make a build differ from previous builds. Though; the build should from now on be more correct than previous builds due to improvements in the mapping algorithm. --- README.md | 1 + package.json | 2 +- src/plugin.js | 7 +++++-- test/plugin.js | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 599cb78..be80168 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ This plugin takes an [import map](https://github.com/WICG/import-maps) as option | path | `cwd/eik.json` | `string` | `false` | Path to eik.json file. | | urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. | | maps | `[]` | `array` | `false` | Array of import map as objects. | +| base | `` | `string` | `false` | Base URL to be applied when parsing the import map. | ## Note on the rollup external option diff --git a/package.json b/package.json index e823b42..0ea1f1e 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,6 @@ "dependencies": { "@eik/common": "3.0.1", "undici": "5.12.0", - "rollup-plugin-import-map": "3.0.0" + "rollup-plugin-import-map": "4.0.0-next.1" } } diff --git a/src/plugin.js b/src/plugin.js index 1d03bf1..b346094 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -29,10 +29,11 @@ const fetchImportMaps = async (urls = []) => { } }; -export default function esmImportToUrl({ +export default function eikPlugin({ path = process.cwd(), maps = [], urls = [], + base = '', } = {}) { const pMaps = Array.isArray(maps) ? maps : [maps]; const pUrls = Array.isArray(urls) ? urls : [urls]; @@ -48,7 +49,9 @@ export default function esmImportToUrl({ // Fetch import maps from the server const fetched = await fetchImportMaps([...config.map, ...pUrls]); - plugin = importMapPlugin([...fetched, ...pMaps]); + const pBase = (base === '') ? config.server : base; + + plugin = importMapPlugin(pBase, [...fetched, ...pMaps]); await plugin.buildStart(options); }, diff --git a/test/plugin.js b/test/plugin.js index da2c27b..53ded27 100644 --- a/test/plugin.js +++ b/test/plugin.js @@ -46,6 +46,7 @@ tap.test('plugin() - import map fetched from a URL', async (t) => { }, }], urls: [`${address}/one`, `${address}/two`], + base: 'https://cdn.eik.dev', })], }; From 1c828f9c46b2b25ae6e8aba775479583f34d2323 Mon Sep 17 00:00:00 2001 From: Trygve Lie Date: Tue, 1 Nov 2022 16:18:03 +0100 Subject: [PATCH 2/2] fix: lint love --- src/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.js b/src/plugin.js index b346094..caea10d 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -49,7 +49,7 @@ export default function eikPlugin({ // Fetch import maps from the server const fetched = await fetchImportMaps([...config.map, ...pUrls]); - const pBase = (base === '') ? config.server : base; + const pBase = (base === '') ? config.server : base; plugin = importMapPlugin(pBase, [...fetched, ...pMaps]); await plugin.buildStart(options);