Load esbuild-wasm more efficiently, fix tests

This commit is contained in:
Alex Gleason committed 2025-08-11 16:17:09 -07:00
1 parent b3ce6979c4
commit ebc180a850
2 files changed
+25 -7

No files matched your search

+2 -7
View File
@@ -1,15 +1,10 @@
import * as esbuild from "esbuild-wasm";
import { getEsbuild } from "@/lib/esbuild";
import { esmPlugin } from "./esmPlugin";
import { fsPlugin } from "./fsPlugin";
import type { JSRuntimeFS } from '@/lib/JSRuntime';
const esbuildInitPromise = esbuild.initialize({
worker: false,
wasmURL: "https://esm.sh/[email protected]/esbuild.wasm",
});
export interface BuildProjectOptions {
fs: JSRuntimeFS;
projectPath: string;
@@ -20,7 +15,7 @@ export interface BuildProjectOptions {
export async function buildProject(
options: BuildProjectOptions,
): Promise<Record<string, Uint8Array>> {
await esbuildInitPromise;
const esbuild = await getEsbuild();
const { fs, projectPath, domParser, target } = options;
+23
View File
@@ -0,0 +1,23 @@
import type _ESBuild from "esbuild-wasm";
type ESBuild = typeof _ESBuild;
let promise: Promise<ESBuild> | undefined;
export function getEsbuild(): Promise<ESBuild> {
if (!promise) {
promise = loadEsbuild();
}
return promise;
}
async function loadEsbuild(): Promise<ESBuild> {
const { default: esbuild } = await import("esbuild-wasm");
await esbuild.initialize({
worker: false,
wasmURL: "https://esm.sh/[email protected]/esbuild.wasm",
});
return esbuild;
}