-
Notifications
You must be signed in to change notification settings - Fork 27
/
mod.ts
35 lines (30 loc) · 887 Bytes
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { load, LoadResponse } from "./loader.ts";
import {
instantiate,
Parser as InternalParser,
} from "./eszip_wasm.generated.js";
export type { LoadResponse } from "./loader.ts";
export const options: { wasmURL: URL | undefined } = { wasmURL: undefined };
export class Parser extends InternalParser {
private constructor() {
super();
}
static async createInstance() {
// insure instantiate is called
await instantiate({ url: options.wasmURL });
return new Parser();
}
}
export async function build(
roots: string[],
loader: (url: string) => Promise<LoadResponse | undefined> = load,
importMapUrl?: string,
): Promise<Uint8Array> {
const { build } = await instantiate({ url: options.wasmURL });
return build(
roots,
(specifier: string) =>
loader(specifier).catch((err) => Promise.reject(String(err))),
importMapUrl,
);
}