-
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: use
netlify:import-map
specifier (#246)
* feat: use `netlify:import-map` specifier * refactor: conditionally set import map URL
- Loading branch information
1 parent
e521d7e
commit 9f2a947
Showing
17 changed files
with
106 additions
and
141 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { writeStage2 } from './lib/stage2.ts' | ||
|
||
const [payload] = Deno.args | ||
const { basePath, destPath, externals, functions, importMapURL } = JSON.parse(payload) | ||
const { basePath, destPath, externals, functions, importMapData } = JSON.parse(payload) | ||
|
||
await writeStage2({ basePath, destPath, externals, functions, importMapURL }) | ||
await writeStage2({ basePath, destPath, externals, functions, importMapData }) |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ import { build, LoadResponse } from 'https://deno.land/x/[email protected]/mod.ts' | |
import * as path from 'https://deno.land/[email protected]/path/mod.ts' | ||
|
||
import type { InputFunction, WriteStage2Options } from '../../shared/stage2.ts' | ||
import { virtualRoot } from '../../shared/consts.ts' | ||
import { importMapSpecifier, virtualRoot } from '../../shared/consts.ts' | ||
import { PUBLIC_SPECIFIER, STAGE2_SPECIFIER } from './consts.ts' | ||
import { inlineModule, loadFromVirtualRoot, loadWithRetry } from './common.ts' | ||
|
||
|
@@ -63,14 +63,18 @@ const getVirtualPath = (basePath: string, filePath: string) => { | |
return url | ||
} | ||
|
||
const stage2Loader = (basePath: string, functions: InputFunction[], externals: Set<string>) => { | ||
const stage2Loader = (basePath: string, functions: InputFunction[], externals: Set<string>, importMapData?: string) => { | ||
return async (specifier: string): Promise<LoadResponse | undefined> => { | ||
if (specifier === STAGE2_SPECIFIER) { | ||
const stage2Entry = getStage2Entry(basePath, functions) | ||
|
||
return inlineModule(specifier, stage2Entry) | ||
} | ||
|
||
if (specifier === importMapSpecifier && importMapData !== undefined) { | ||
return inlineModule(specifier, importMapData) | ||
} | ||
|
||
if (specifier === PUBLIC_SPECIFIER || externals.has(specifier)) { | ||
return { | ||
kind: 'external', | ||
|
@@ -86,8 +90,9 @@ const stage2Loader = (basePath: string, functions: InputFunction[], externals: S | |
} | ||
} | ||
|
||
const writeStage2 = async ({ basePath, destPath, externals, functions, importMapURL }: WriteStage2Options) => { | ||
const loader = stage2Loader(basePath, functions, new Set(externals)) | ||
const writeStage2 = async ({ basePath, destPath, externals, functions, importMapData }: WriteStage2Options) => { | ||
const importMapURL = importMapData ? importMapSpecifier : undefined | ||
const loader = stage2Loader(basePath, functions, new Set(externals), importMapData) | ||
const bytes = await build([STAGE2_SPECIFIER], loader, importMapURL) | ||
const directory = path.dirname(destPath) | ||
|
||
|
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 |
---|---|---|
|
@@ -7,5 +7,4 @@ export interface Bundle { | |
extension: string | ||
format: BundleFormat | ||
hash: string | ||
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
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
Oops, something went wrong.