Skip to content

Commit

Permalink
✨ Show logs of loading entry URL and import map
Browse files Browse the repository at this point in the history
  • Loading branch information
takker99 committed Nov 15, 2021
1 parent 9f4bf4c commit 5836a10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
21 changes: 14 additions & 7 deletions build.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { build, BuildFailure, initialize } from "./deps/esbuild-wasm.ts";
import { remoteLoader } from "./plugin.ts";
import { getLoader } from "././loader.ts";
import { fetch } from "./fetch.ts";
import { fetchImportMap } from "./importmap.ts";
import { fetchImportMap, ImportMap } from "./importmap.ts";
import type { BuildResult, BundleOptions } from "./types.ts";

const postMessage = (data: BuildResult) => self.postMessage(data);
Expand All @@ -20,16 +20,23 @@ self.addEventListener<"message">("message", async (event) => {
await initialized;
const { entryURL, reload, importmap, ...options } =
(event.data) as BundleOptions;
const { response } = await fetch(entryURL, reload);
const loader = getLoader(response);
const entryPointRes = await fetch(entryURL, reload);
postMessage({ type: entryPointRes.type, url: entryPointRes.response.url });
const loader = getLoader(entryPointRes.response);

const importMap = importmap
? (await fetchImportMap(new URL(importmap, entryURL), reload)).json
: undefined;
let importMap: ImportMap | undefined = undefined;
if (importmap) {
const { type, json } = await fetchImportMap(
new URL(importmap, entryURL),
reload,
);
postMessage({ type, url: new URL(importmap, entryURL).toString() });
importMap = json;
}

const result = await build({
stdin: {
contents: await response.text(),
contents: await entryPointRes.response.text(),
loader,
},
write: false,
Expand Down
1 change: 1 addition & 0 deletions importmap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fetch } from "./fetch.ts";
import type { ImportMap } from "./deps/importmap.ts";
export type { ImportMap };

export async function fetchImportMap(url: URL | string, reload = false) {
const { type, response } = await fetch(url, reload);
Expand Down

0 comments on commit 5836a10

Please sign in to comment.