diff --git a/packages/compress-stringify/typescript/README.md b/packages/compress-stringify/typescript/README.md index 5405253ca..fb79eebc3 100644 --- a/packages/compress-stringify/typescript/README.md +++ b/packages/compress-stringify/typescript/README.md @@ -26,6 +26,8 @@ import { parseStringDecompress, setPipelinesBaseUrl, getPipelinesBaseUrl, + setPipelineWorkerUrl, + getPipelineWorkerUrl, } from "itk-compress-stringify" ``` @@ -109,6 +111,24 @@ function setPipelinesBaseUrl( function getPipelinesBaseUrl() : string | URL ``` +#### setPipelineWorkerUrl + +*Set base URL for the itk-wasm pipeline worker script when vendored.* + +```ts +function setPipelineWorkerUrl( + baseUrl: string | URL +) : void +``` + +#### getPipelineWorkerUrl + +*Get base URL for the itk-wasm pipeline worker script when vendored.* + +```ts +function getPipelineWorkerUrl() : string | URL +``` + ### Node interface Import: diff --git a/packages/compress-stringify/typescript/build/vite.config.js b/packages/compress-stringify/typescript/build/vite.config.js index cb96abdb6..c8a55d36e 100644 --- a/packages/compress-stringify/typescript/build/vite.config.js +++ b/packages/compress-stringify/typescript/build/vite.config.js @@ -13,6 +13,7 @@ export default defineConfig({ viteStaticCopy({ targets: [ { src: '../../dist/pipelines/*', dest: 'pipelines' }, + { src: '../../dist/web-workers/*', dest: 'web-workers' }, ], }) ], diff --git a/packages/compress-stringify/typescript/package.json b/packages/compress-stringify/typescript/package.json index 6d105f7be..b1b8aa7aa 100644 --- a/packages/compress-stringify/typescript/package.json +++ b/packages/compress-stringify/typescript/package.json @@ -38,7 +38,7 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "itk-wasm": "^1.0.0-b.60" + "itk-wasm": "^1.0.0-b.62" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.0", diff --git a/packages/compress-stringify/typescript/pnpm-lock.yaml b/packages/compress-stringify/typescript/pnpm-lock.yaml index 46cfbc345..612c5df3a 100644 --- a/packages/compress-stringify/typescript/pnpm-lock.yaml +++ b/packages/compress-stringify/typescript/pnpm-lock.yaml @@ -9,7 +9,7 @@ specifiers: '@types/node': ^18.11.18 ava: ^5.1.0 cypress: ^12.3.0 - itk-wasm: ^1.0.0-b.60 + itk-wasm: ^1.0.0-b.62 rollup: ^3.9.0 rollup-plugin-copy: ^3.4.0 rollup-plugin-ignore: ^1.0.10 @@ -20,7 +20,7 @@ specifiers: vite-plugin-static-copy: ^0.13.0 dependencies: - itk-wasm: 1.0.0-b.60 + itk-wasm: 1.0.0-b.62 devDependencies: '@rollup/plugin-commonjs': 24.0.0_rollup@3.9.1 @@ -1809,8 +1809,8 @@ packages: resolution: {integrity: sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==} dev: true - /itk-wasm/1.0.0-b.60: - resolution: {integrity: sha512-FWfT/h19Gep6xdT0ufBqnMHAqCmnOocv6tQ26N1Tkm0JjzQipQPz2NiTxs6xrFdbFjNGCb4Ar8MWaHeJlAMOHg==} + /itk-wasm/1.0.0-b.62: + resolution: {integrity: sha512-A5PEHEGtJ/ZPphaa1KNiRF+jSX5RLNjuaEwkRXtRzrRxo7TnDkSQR/vrSNtj9cYL0SQQtLAXjHbDn/UJUAD43A==} hasBin: true dependencies: '@babel/runtime': 7.20.7 diff --git a/packages/compress-stringify/typescript/src/compress-stringify.ts b/packages/compress-stringify/typescript/src/compress-stringify.ts index 2e83dc1ca..35a4358c0 100644 --- a/packages/compress-stringify/typescript/src/compress-stringify.ts +++ b/packages/compress-stringify/typescript/src/compress-stringify.ts @@ -11,6 +11,9 @@ import CompressStringifyResult from './compress-stringify-result.js' import { getPipelinesBaseUrl } from './pipelines-base-url.js' + +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + /** * Given a binary, compress and optionally base64 encode. * @@ -55,7 +58,7 @@ async function compressStringify( returnValue, stderr, outputs - } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, getPipelinesBaseUrl()) + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, getPipelinesBaseUrl(), getPipelineWorkerUrl()) if (returnValue !== 0) { throw new Error(stderr) } diff --git a/packages/compress-stringify/typescript/src/parse-string-decompress.ts b/packages/compress-stringify/typescript/src/parse-string-decompress.ts index 645210254..8e063697d 100644 --- a/packages/compress-stringify/typescript/src/parse-string-decompress.ts +++ b/packages/compress-stringify/typescript/src/parse-string-decompress.ts @@ -11,6 +11,9 @@ import ParseStringDecompressResult from './parse-string-decompress-result.js' import { getPipelinesBaseUrl } from './pipelines-base-url.js' + +import { getPipelineWorkerUrl } from './pipeline-worker-url.js' + /** * Given a binary or string produced with compress-stringify, decompress and optionally base64 decode. * @@ -49,7 +52,7 @@ async function parseStringDecompress( returnValue, stderr, outputs - } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, getPipelinesBaseUrl()) + } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, getPipelinesBaseUrl(), getPipelineWorkerUrl()) if (returnValue !== 0) { throw new Error(stderr) } diff --git a/packages/compress-stringify/typescript/src/pipeline-worker-url.ts b/packages/compress-stringify/typescript/src/pipeline-worker-url.ts new file mode 100644 index 000000000..42b71433b --- /dev/null +++ b/packages/compress-stringify/typescript/src/pipeline-worker-url.ts @@ -0,0 +1,9 @@ +let pipelineWorkerUrl: string | URL | null = new URL('/web-workers/pipeline.worker.js', document.location.origin).href + +export function setPipelineWorkerUrl (workerUrl: string | URL | null): void { + pipelineWorkerUrl = workerUrl +} + +export function getPipelineWorkerUrl (): string | URL | null { + return pipelineWorkerUrl +} diff --git a/src/bindgen/typescript-resources/pipeline-worker-url.ts b/src/bindgen/typescript-resources/pipeline-worker-url.ts new file mode 100644 index 000000000..42b71433b --- /dev/null +++ b/src/bindgen/typescript-resources/pipeline-worker-url.ts @@ -0,0 +1,9 @@ +let pipelineWorkerUrl: string | URL | null = new URL('/web-workers/pipeline.worker.js', document.location.origin).href + +export function setPipelineWorkerUrl (workerUrl: string | URL | null): void { + pipelineWorkerUrl = workerUrl +} + +export function getPipelineWorkerUrl (): string | URL | null { + return pipelineWorkerUrl +} diff --git a/src/bindgen/typescript-resources/template.package.json b/src/bindgen/typescript-resources/template.package.json index 113e0b2f5..0e041c56c 100644 --- a/src/bindgen/typescript-resources/template.package.json +++ b/src/bindgen/typescript-resources/template.package.json @@ -30,7 +30,7 @@ "author": "", "license": "Apache-2.0", "dependencies": { - "itk-wasm": "^1.0.0-b.60" + "itk-wasm": "^1.0.0-b.62" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.0", diff --git a/src/bindgen/typescript-resources/vite.config.js b/src/bindgen/typescript-resources/vite.config.js index cb96abdb6..c8a55d36e 100644 --- a/src/bindgen/typescript-resources/vite.config.js +++ b/src/bindgen/typescript-resources/vite.config.js @@ -13,6 +13,7 @@ export default defineConfig({ viteStaticCopy({ targets: [ { src: '../../dist/pipelines/*', dest: 'pipelines' }, + { src: '../../dist/web-workers/*', dest: 'web-workers' }, ], }) ], diff --git a/src/bindgen/typescript.js b/src/bindgen/typescript.js index 8ec037640..c46201836 100644 --- a/src/bindgen/typescript.js +++ b/src/bindgen/typescript.js @@ -315,6 +315,7 @@ function typescriptBindings(outputDir, buildDir, wasmBinaries, options, forNode= functionContent += "\nimport path from 'path'\n\n" } else { functionContent += "\nimport { getPipelinesBaseUrl } from './pipelines-base-url.js'\n\n" + functionContent += "\nimport { getPipelineWorkerUrl } from './pipeline-worker-url.js'\n\n" } const readmeParametersTable = [['Parameter', 'Type', 'Description'],] @@ -446,7 +447,7 @@ function typescriptBindings(outputDir, buildDir, wasmBinaries, options, forNode= functionContent += ` const {\n returnValue,\n stderr,\n outputs\n } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs)\n` } else { functionContent += `\n const pipelinePath = '${moduleKebabCase}'\n\n` - functionContent += ` const {\n webWorker: usedWebWorker,\n returnValue,\n stderr,\n outputs\n } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, getPipelinesBaseUrl())\n` + functionContent += ` const {\n webWorker: usedWebWorker,\n returnValue,\n stderr,\n outputs\n } = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, getPipelinesBaseUrl(), getPipelineWorkerUrl())\n` } functionContent += ' if (returnValue !== 0) {\n throw new Error(stderr)\n }\n\n' @@ -484,6 +485,10 @@ function typescriptBindings(outputDir, buildDir, wasmBinaries, options, forNode= if (!fs.existsSync(pipelinesBaseUrlPath)) { fs.copyFileSync(bindgenResource('pipelines-base-url.ts'), pipelinesBaseUrlPath) } + const pipelineWorkerUrlPath = path.join(outputDir, 'src', 'pipeline-worker-url.ts') + if (!fs.existsSync(pipelineWorkerUrlPath)) { + fs.copyFileSync(bindgenResource('pipeline-worker-url.ts'), pipelineWorkerUrlPath) + } const itkConfigPath = path.join(outputDir, 'src', 'itkConfig.js') if (!fs.existsSync(itkConfigPath)) { diff --git a/src/itk-wasm-cli.js b/src/itk-wasm-cli.js index 2872bd1b0..24f490724 100755 --- a/src/itk-wasm-cli.js +++ b/src/itk-wasm-cli.js @@ -13,7 +13,7 @@ const program = new Command() // Array of types that will require an import from itk-wasm const typesRequireImport = ['Image'] -const defaultImageTag = '20221222-d37dad3f' +const defaultImageTag = '20230122-5e3aea6c' function processCommonOptions() { const options = program.opts()