Skip to content

Commit 1e9c504

Browse files
committed
feat(bindgen): copy threads wasm and js bindings to typescript package
1 parent f829e86 commit 1e9c504

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

packages/core/typescript/itk-wasm/src/bindgen/typescript/typescript-bindings.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,35 @@ function typescriptBindings(
129129
path.join(distPipelinesDir, `${path.basename(prefix)}.js`)
130130
)
131131

132+
// Check for and copy threaded WASM files if present
133+
const wasmBinaryNameWithoutFirstDir = wasmBinaryName
134+
.split(path.sep)
135+
.slice(1)
136+
.join(path.sep)
137+
const threadsWasmPath = path.join(
138+
'emscripten-threads-build',
139+
wasmBinaryNameWithoutFirstDir
140+
)
141+
const threadsThreadsWasmPath =
142+
threadsWasmPath.substring(0, threadsWasmPath.length - 5) +
143+
'.threads.wasm.zst'
144+
const jsThreadsWasmPath =
145+
threadsWasmPath.substring(0, threadsWasmPath.length - 5) + '.js'
146+
if (fs.existsSync(threadsThreadsWasmPath)) {
147+
fs.copyFileSync(
148+
threadsThreadsWasmPath,
149+
path.join(distPipelinesDir, path.basename(threadsThreadsWasmPath))
150+
)
151+
const jsThreadsWasmBasename = path.basename(jsThreadsWasmPath)
152+
const jsThreadsWasm =
153+
jsThreadsWasmBasename.substring(0, jsThreadsWasmBasename.length - 3) +
154+
'.threads.js'
155+
fs.copyFileSync(
156+
jsThreadsWasmPath,
157+
path.join(distPipelinesDir, jsThreadsWasm)
158+
)
159+
}
160+
132161
const { interfaceJson, parsedPath } = wasmBinaryInterfaceJson(
133162
outputDir,
134163
buildDir,

packages/core/typescript/itk-wasm/src/pipeline/internal/load-emscripten-module-main-thread.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async function loadEmscriptenModuleMainThread(
8484
}
8585

8686
const wasmBinary = decompressedArray.buffer
87-
const fullModulePath = `${modulePrefix}.js`
87+
const fullModulePath = `${modulePrefix}.threads.js`
8888
const result = await import(
8989
/* webpackIgnore: true */ /* @vite-ignore */ fullModulePath
9090
)

packages/core/typescript/itk-wasm/src/pipeline/internal/load-emscripten-module-web-worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async function loadEmscriptenModuleWebWorker(
8585
}
8686

8787
const wasmBinary = decompressedArray.buffer
88-
const modulePath = `${modulePrefix}.js`
88+
const modulePath = `${modulePrefix}.threads.js`
8989
const result = await import(
9090
/* webpackIgnore: true */ /* @vite-ignore */ modulePath
9191
)

0 commit comments

Comments
 (0)