Skip to content

Commit

Permalink
fix(bundle): disable worker
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Dec 16, 2024
1 parent 5d04263 commit dbdc300
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions bundle/ts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import { delay } from "@std/async/delay"
*/
export async function bundle(input: URL | string, { builder = "binary", minify = "terser", format = "esm", debug = false, banner = "", shadow = true, config, exports, raw, overrides } = {} as options): Promise<string> {
const esbuild = builder === "wasm" ? await import("../vendored/esbuild/wasm.js") : await import("esbuild")
if (builder === "wasm") {
await esbuild.initialize({ worker: false })
}
const url = input instanceof URL ? input : new URL(`data:application/typescript;base64,${encodeBase64(input)}`)
let code = ""
try {
Expand Down
14 changes: 11 additions & 3 deletions bundle/ts/bundle_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bundle } from "./bundle.ts"
import { expect, test } from "@libs/testing"
import { expect, test, type testing } from "@libs/testing"
import { fromFileUrl } from "@std/path"

const base = new URL("testing/", import.meta.url)
Expand Down Expand Up @@ -27,8 +27,16 @@ test("`bundle()` handles banner option", async () => {
}, { permissions: { read: true, net: ["jsr.io"], env: true, run: true } })

test("`bundle()` handles builder version", async () => {
const url = new URL("test_bundle.ts", base)
await expect(bundle(url, { config, builder: "wasm" })).resolves.toContain("success")
const { Worker } = globalThis
try {
delete (globalThis as testing).Worker
const url = new URL("test_bundle.ts", base)
for (let i = 0; i < 2; i++) {
await expect(bundle(url, { config, builder: "wasm" })).resolves.toContain("success")
}
} finally {
globalThis.Worker = Worker
}
}, { permissions: { read: true, run: ["deno"] } })

test("`bundle()` handles minify option", async () => {
Expand Down

0 comments on commit dbdc300

Please sign in to comment.