Skip to content

Commit a461426

Browse files
committed
feat(itkConfig): Support dynamic runtime specification for browser
version needs to go into its own module to avoid a circular import.
1 parent a408e7c commit a461426

File tree

11 files changed

+37
-10
lines changed

11 files changed

+37
-10
lines changed

cypress/e2e/pipeline/run_pipeline.cy.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('runPipeline', () => {
99
it('captures stdout and stderr', () => {
1010
cy.window().then(async (win) => {
1111
const itk = win.itk
12+
itk.itkConfig.pipelinesUrl = '/pipelines'
1213

1314
const args = []
1415
const outputs = null
@@ -19,6 +20,21 @@ describe('runPipeline', () => {
1920
})
2021

2122

23+
it('fetches WASM files from a custom config URL', () => {
24+
cy.window().then(async (win) => {
25+
const itk = win.itk
26+
const configPropertyPipelinesBaseUrl = 'customPipelinesUrl'
27+
itk.itkConfig[configPropertyPipelinesBaseUrl] = '/pipelines'
28+
29+
const args = []
30+
const outputs = null
31+
const inputs = null
32+
const stdoutStderrPath = 'stdout-stderr-test'
33+
const { webWorker, returnValue, stdout, stderr } = await itk.runPipeline(null, stdoutStderrPath, args, outputs, inputs, configPropertyPipelinesBaseUrl)
34+
})
35+
})
36+
37+
2238
it('re-uses a WebWorker', () => {
2339
cy.window().then(async (win) => {
2440
const itk = win.itk
@@ -261,7 +277,7 @@ Click. Perfect success.
261277
})
262278

263279

264-
it('runPipeline writes and reads an itk.Mesh via memory io', async () => {
280+
it('runPipeline writes and reads an itk.Mesh via memory io', () => {
265281
cy.window().then(async (win) => {
266282
const itk = win.itk
267283

src/core/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Core API interfaces, data structures, and functions
22

3+
export { default as itkConfig } from '../itkConfig.js'
4+
export { default as version } from './version.js'
5+
36
export { default as InterfaceTypes } from './InterfaceTypes.js'
47

58
export { default as TextStream } from './TextStream.js'
@@ -36,6 +39,3 @@ export { default as WorkerPool } from './WorkerPool.js'
3639
export { default as WorkerPoolFunction } from './WorkerPoolFunction.js'
3740
export { default as WorkerPoolProgressCallback } from './WorkerPoolProgressCallback.js'
3841
export { default as WorkerPoolRunTasksResult } from './WorkerPoolRunTasksResult.js'
39-
40-
const version = '0.0.0-semantically-released'
41-
export { version }

src/core/internal/createWebWorkerPromise.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ async function createWebWorkerPromise (existingWorker: Worker | null): Promise<c
2929
}
3030

3131
let worker = null
32+
// @ts-ignore: error TS2339: Property 'webWorkersUrl' does not exist on type '{ pipelineWorkerUrl: string; imageIOUrl: string; meshIOUrl: string; pipelinesUrl: string; }
3233
const webWorkersUrl = config.webWorkersUrl
3334
if (typeof webWorkersUrl !== 'undefined') {
3435
console.warn('itkConfig webWorkersUrl is deprecated. Please use pipelineWorkerUrl with the full path to the pipeline worker.')

src/core/version.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const version = '0.0.0-semantically-released'
2+
3+
export default version

src/itkConfig.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { version } from './browser/index.js'
1+
import version from './core/version.js'
22

33
const itkConfig = {
4-
webWorkersUrl: undefined,
54
pipelineWorkerUrl: `https://cdn.jsdelivr.net/npm/itk-wasm@${version}/dist/web-workers/min-bundles/pipeline.worker.js`,
65
imageIOUrl: `https://cdn.jsdelivr.net/npm/itk-image-io@${version}`,
76
meshIOUrl: `https://cdn.jsdelivr.net/npm/itk-mesh-io@${version}`,

src/itkConfigDevServer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const itkConfig = {
2-
webWorkersUrl: undefined,
32
pipelineWorkerUrl: `/web-workers/bundles/pipeline.worker.js`,
43
imageIOUrl: `/image-io`,
54
meshIOUrl: `/mesh-io`,

src/pipeline/runPipeline.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function loadPipelineModule (pipelinePath: string | URL): Promise<Pipeline
3636
}
3737
}
3838

39-
async function runPipeline (webWorker: Worker | null | boolean, pipelinePath: string | URL, args: string[], outputs: PipelineOutput[] | null, inputs: PipelineInput[] | null): Promise<RunPipelineResult> {
39+
async function runPipeline (webWorker: Worker | null | boolean, pipelinePath: string | URL, args: string[], outputs: PipelineOutput[] | null, inputs: PipelineInput[] | null, configPropertyPipelineBaseUrl: string | URL = 'pipelinesUrl'): Promise<RunPipelineResult> {
4040
if (webWorker === false) {
4141
const pipelineModule = await loadPipelineModule(pipelinePath.toString())
4242
const result = runPipelineEmscripten(pipelineModule, args, outputs, inputs)
@@ -137,6 +137,7 @@ async function runPipeline (webWorker: Worker | null | boolean, pipelinePath: st
137137
operation: 'runPipeline',
138138
config: config,
139139
pipelinePath: pipelinePath.toString(),
140+
configPropertyPipelineBaseUrl,
140141
args,
141142
outputs,
142143
inputs

src/update-versions.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ function rewriteVersion(filename) {
2222
fs.writeFileSync(filename, lines.join('\n'))
2323
}
2424

25-
rewriteVersion('dist/core/index.js')
25+
rewriteVersion('src/core/version.ts')
26+
rewriteVersion('dist/core/version.js')
2627
rewriteVersion('dist/itkConfigDevelopment.js')

src/web-workers/ITKConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ interface ITKConfig {
44
pipelinesUrl: string
55
imageIOUrl: string
66
meshIOUrl: string
7+
8+
[key: string]: string | undefined
79
}
810

911
export default ITKConfig

src/web-workers/RunPipelineInput.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import WebWorkerInput from './WebWorkerInput.js'
44

55
interface RunPipelineInput extends WebWorkerInput {
66
pipelinePath: string | object
7+
configPropertyPipelineBaseUrl: string,
78
args: string[]
89
outputs: PipelineOutput[]
910
inputs: PipelineInput[]

0 commit comments

Comments
 (0)