Skip to content

Commit a804602

Browse files
committed
fix: workaround deno vendor limitation (not pulling static wasm files)
1 parent a860d2b commit a804602

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tools/build.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { createWriteStream } from 'node:fs'
12
import { cp, rm } from 'node:fs/promises'
2-
import { resolve, join } from 'node:path'
3+
import { join, resolve } from 'node:path'
4+
import { Readable } from 'stream'
5+
import { finished } from 'stream/promises'
36

47
import { build, context } from 'esbuild'
58
import { execaCommand } from 'execa'
@@ -94,6 +97,22 @@ async function vendorDeno() {
9497
console.log(`📦 Vendoring Deno modules into '${vendorDest}'...`)
9598

9699
await execaCommand(`deno vendor ${vendorSource} --output=${vendorDest} --force`)
100+
101+
// htmlrewriter contains wasm files and those don't currently work great with vendoring
102+
// see https://github.com/denoland/deno/issues/14123
103+
// to workaround this we copy the wasm files manually
104+
const filesToDownload = ['https://deno.land/x/[email protected]/pkg/htmlrewriter_bg.wasm']
105+
await Promise.all(
106+
filesToDownload.map(async (urlString) => {
107+
const url = new URL(urlString)
108+
109+
const destination = join(vendorDest, url.hostname, url.pathname)
110+
111+
const res = await fetch(url)
112+
const fileStream = createWriteStream(destination, { flags: 'wx' })
113+
await finished(Readable.fromWeb(res.body).pipe(fileStream))
114+
}),
115+
)
97116
}
98117

99118
const args = new Set(process.argv.slice(2))

0 commit comments

Comments
 (0)