Skip to content

Commit

Permalink
feat(bindgen): Default to itk-wasm package asset configuration
Browse files Browse the repository at this point in the history
At runtime, we use in order of preference:

1. Package asset configuration
2. itk-wasm asset configuration
3. jsDeliver
  • Loading branch information
thewtex committed Jan 27, 2023
1 parent 927be66 commit 3341ca0
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/compress-stringify/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"itk-wasm": "^1.0.0-b.62"
"itk-wasm": "^1.0.0-b.65"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
28 changes: 16 additions & 12 deletions packages/compress-stringify/typescript/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions packages/compress-stringify/typescript/src/pipeline-worker-url.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// @ts-ignore: TS2305: Module '"itk-wasm"' has no exported member 'getPipelineWorkerUrl'.
import { getPipelineWorkerUrl as itkWasmGetPipelineWorkerUrl } from 'itk-wasm'
import packageJson from '../package.json'
let pipelineWorkerUrl: string | URL | null = `https://cdn.jsdelivr.net/npm/itk-compress-stringify@${packageJson.version}/dist/web-workers/pipeline.worker.js`

let pipelineWorkerUrl: string | URL | null | undefined
let defaultPipelineWorkerUrl: string | URL | null = `https://cdn.jsdelivr.net/npm/itk-compress-stringify@${packageJson.version}/dist/web-workers/pipeline.worker.js`

export function setPipelineWorkerUrl (workerUrl: string | URL | null): void {
pipelineWorkerUrl = workerUrl
}

export function getPipelineWorkerUrl (): string | URL | null {
return pipelineWorkerUrl
if (typeof pipelineWorkerUrl !== 'undefined') {
return pipelineWorkerUrl
}
const itkWasmPipelineWorkerUrl = itkWasmGetPipelineWorkerUrl()
if (typeof itkWasmPipelineWorkerUrl !== 'undefined') {
return itkWasmPipelineWorkerUrl
}
return defaultPipelineWorkerUrl
}
15 changes: 13 additions & 2 deletions packages/compress-stringify/typescript/src/pipelines-base-url.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// @ts-ignore: TS2305: Module '"itk-wasm"' has no exported member 'getPipelinesBaseUrl'.
import { getPipelinesBaseUrl as itkWasmGetPipelinesBaseUrl } from 'itk-wasm'
import packageJson from '../package.json'
let pipelinesBaseUrl: string | URL = `https://cdn.jsdelivr.net/npm/itk-compress-stringify@${packageJson.version}/dist/pipelines`

let pipelinesBaseUrl: string | URL | undefined
const defaultPipelinesBaseUrl = `https://cdn.jsdelivr.net/npm/itk-compress-stringify@${packageJson.version}/dist/pipelines`

export function setPipelinesBaseUrl (baseUrl: string | URL): void {
pipelinesBaseUrl = baseUrl
}

export function getPipelinesBaseUrl (): string | URL {
return pipelinesBaseUrl
if (typeof pipelinesBaseUrl !== 'undefined') {
return pipelinesBaseUrl
}
const itkWasmPipelinesBaseUrl = itkWasmGetPipelinesBaseUrl()
if (typeof itkWasmPipelinesBaseUrl !== 'undefined') {
return itkWasmPipelinesBaseUrl
}
return defaultPipelinesBaseUrl
}
1 change: 1 addition & 0 deletions packages/compress-stringify/typescript/test/browser/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as itkCompressStringify from '../../dist/bundles/itk-compress-stringify.js'
import * as itkWasm from 'itk-wasm'

// Use local, vendored WebAssembly module assets
const pipelinesBaseUrl: string | URL = new URL('/pipelines', document.location.origin).href
Expand Down
16 changes: 13 additions & 3 deletions src/bindgen/typescript-resources/pipeline-worker-url.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// @ts-expect-error error TS2732: Cannot find module '../package.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
// @ts-ignore: TS2305: Module '"itk-wasm"' has no exported member 'getPipelineWorkerUrl'.
import { getPipelineWorkerUrl as itkWasmGetPipelineWorkerUrl } from 'itk-wasm'
import packageJson from '../package.json'
let pipelineWorkerUrl: string | URL | null = `https://cdn.jsdelivr.net/npm/<bindgenPackageName>@${packageJson.version as string}/dist/web-workers/pipeline.worker.js`

let pipelineWorkerUrl: string | URL | null | undefined
const defaultPipelineWorkerUrl = `https://cdn.jsdelivr.net/npm/<bindgenPackageName>@${packageJson.version}/dist/web-workers/pipeline.worker.js`

export function setPipelineWorkerUrl (workerUrl: string | URL | null): void {
pipelineWorkerUrl = workerUrl
}

export function getPipelineWorkerUrl (): string | URL | null {
return pipelineWorkerUrl
if (typeof pipelineWorkerUrl !== 'undefined') {
return pipelineWorkerUrl
}
const itkWasmPipelineWorkerUrl = itkWasmGetPipelineWorkerUrl()
if (typeof itkWasmPipelineWorkerUrl !== 'undefined') {
return itkWasmPipelineWorkerUrl
}
return defaultPipelineWorkerUrl
}
16 changes: 13 additions & 3 deletions src/bindgen/typescript-resources/pipelines-base-url.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// @ts-expect-error error TS2732: Cannot find module '../package.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
// @ts-ignore: TS2305: Module '"itk-wasm"' has no exported member 'getPipelinesBaseUrl'.
import { getPipelinesBaseUrl as itkWasmGetPipelinesBaseUrl } from 'itk-wasm'
import packageJson from '../package.json'
let pipelinesBaseUrl: string | URL = `https://cdn.jsdelivr.net/npm/<bindgenPackageName>@${packageJson.version as string}/dist/pipelines`

let pipelinesBaseUrl: string | URL | undefined
let defaultPipelinesBaseUrl: string | URL = `https://cdn.jsdelivr.net/npm/itk-compress-stringify@${packageJson.version}/dist/pipelines`

export function setPipelinesBaseUrl (baseUrl: string | URL): void {
pipelinesBaseUrl = baseUrl
}

export function getPipelinesBaseUrl (): string | URL {
return pipelinesBaseUrl
if (typeof pipelinesBaseUrl !== 'undefined') {
return pipelinesBaseUrl
}
const itkWasmPipelinesBaseUrl = itkWasmGetPipelinesBaseUrl()
if (typeof itkWasmPipelinesBaseUrl !== 'undefined') {
return itkWasmPipelinesBaseUrl
}
return defaultPipelinesBaseUrl
}
2 changes: 1 addition & 1 deletion src/bindgen/typescript-resources/template.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"itk-wasm": "^1.0.0-b.62"
"itk-wasm": "^1.0.0-b.65"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down

0 comments on commit 3341ca0

Please sign in to comment.