-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for import maps with ESZIP (#109)
* feat: add support for import maps with ESZIP BREAKING CHANGE: `importMaps` now expects a `baseURL` containing the URL of the import map file * refactor: simplify import map parsing * refactor: use `URL` objects internally Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
c155d26
commit 19031eb
Showing
9 changed files
with
147 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface InputFunction { | ||
name: string | ||
path: string | ||
} | ||
|
||
export interface WriteStage2Options { | ||
basePath: string | ||
destPath: string | ||
functions: InputFunction[] | ||
importMapURL?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { writeStage2 } from './lib/stage2.ts' | ||
|
||
const [payload] = Deno.args | ||
const { basePath, destPath, functions, imports } = JSON.parse(payload) | ||
const { basePath, destPath, functions, importMapURL } = JSON.parse(payload) | ||
|
||
await writeStage2({ basePath, destPath, functions, imports }) | ||
await writeStage2({ basePath, destPath, functions, importMapURL }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import test from 'ava' | ||
|
||
import { ImportMap } from '../src/import_map.js' | ||
|
||
test('Handles import maps with full URLs without specifying a base URL', (t) => { | ||
const inputFile1 = { | ||
baseURL: new URL('file:///some/path/import-map.json'), | ||
imports: { | ||
'alias:jamstack': 'https://jamstack.org', | ||
}, | ||
} | ||
const inputFile2 = { | ||
baseURL: new URL('file:///some/path/import-map.json'), | ||
imports: { | ||
'alias:pets': 'https://petsofnetlify.com/', | ||
}, | ||
} | ||
|
||
const map = new ImportMap([inputFile1, inputFile2]) | ||
const { imports } = JSON.parse(map.getContents()) | ||
|
||
t.is(imports['netlify:edge'], 'https://edge.netlify.com/v1/index.ts') | ||
t.is(imports['alias:jamstack'], 'https://jamstack.org/') | ||
t.is(imports['alias:pets'], 'https://petsofnetlify.com/') | ||
}) | ||
|
||
test('Handles import maps with relative paths', (t) => { | ||
const inputFile1 = { | ||
baseURL: new URL('file:///Users/jane-doe/my-site/import-map.json'), | ||
imports: { | ||
'alias:pets': './heart/pets/', | ||
}, | ||
} | ||
|
||
const map = new ImportMap([inputFile1]) | ||
const { imports } = JSON.parse(map.getContents()) | ||
|
||
t.is(imports['netlify:edge'], 'https://edge.netlify.com/v1/index.ts') | ||
t.is(imports['alias:pets'], 'file:///Users/jane-doe/my-site/heart/pets/') | ||
}) |