Skip to content

Commit feeafc1

Browse files
committed
fix(bindgen): locate wasm module for Windows node execution
1 parent 684e738 commit feeafc1

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

packages/compress-stringify/typescript/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"cypress:open": "pnpm exec cypress open",
2727
"cypress:runChrome": "pnpm exec cypress run --browser chrome",
2828
"cypress:runFirefox": "pnpm exec cypress run --browser firefox",
29-
"build": "pnpm build:version && pnpm build:tsc && pnpm build:browser:workerEmbedded && pnpm build:browser:workerEmbeddedMin && pnpm build:demo",
29+
"build": "pnpm build:tsc && pnpm build:browser:workerEmbedded && pnpm build:browser:workerEmbeddedMin && pnpm build:demo",
3030
"build:version": "node -p \"'const version = ' + JSON.stringify(require('./package.json').version) + '\\nexport default version\\n'\" > src/version.ts",
3131
"build:browser:workerEmbedded": "esbuild --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.js ./src/index-worker-embedded.ts",
3232
"build:browser:workerEmbeddedMin": "esbuild --minify --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.min.js ./src/index-worker-embedded.min.ts",
33-
"build:tsc": "tsc --pretty",
33+
"build:tsc": "pnpm build:version && tsc --pretty",
3434
"build:demo": "pnpm copyShoelaceAssets && vite build"
3535
},
3636
"keywords": [

packages/compress-stringify/typescript/src/compress-stringify-node.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import CompressStringifyNodeOptions from './compress-stringify-node-options.js'
1212
import CompressStringifyNodeResult from './compress-stringify-node-result.js'
1313

1414
import path from 'path'
15+
import { fileURLToPath } from 'url'
1516

1617
/**
1718
* Given a binary, compress and optionally base64 encode.
@@ -57,7 +58,7 @@ async function compressStringifyNode(
5758

5859
}
5960

60-
const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), 'pipelines', 'compress-stringify')
61+
const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'compress-stringify')
6162

6263
const {
6364
returnValue,

packages/compress-stringify/typescript/src/parse-string-decompress-node.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ParseStringDecompressNodeOptions from './parse-string-decompress-node-opt
1212
import ParseStringDecompressNodeResult from './parse-string-decompress-node-result.js'
1313

1414
import path from 'path'
15+
import { fileURLToPath } from 'url'
1516

1617
/**
1718
* Given a binary or string produced with compress-stringify, decompress and optionally base64 decode.
@@ -49,7 +50,7 @@ async function parseStringDecompressNode(
4950
options.parseString && args.push('--parse-string')
5051
}
5152

52-
const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), 'pipelines', 'parse-string-decompress')
53+
const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', 'parse-string-decompress')
5354

5455
const {
5556
returnValue,

packages/core/typescript/itk-wasm/src/bindgen/typescript/function-module.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ function functionModule(
8989
}
9090
functionContent += `import ${modulePascalCase}${nodeTextCamel}Result from './${moduleKebabCase}${nodeTextKebab}-result.js'\n\n`
9191
if (forNode) {
92-
functionContent += "import path from 'path'\n\n"
92+
functionContent += "import path from 'path'\n"
93+
functionContent += "import { fileURLToPath } from 'url'\n\n"
9394
} else {
9495
functionContent +=
9596
"import { getPipelinesBaseUrl } from './pipelines-base-url.js'\n"
@@ -529,7 +530,7 @@ function functionModule(
529530
? ' outputs\n'
530531
: ''
531532
if (forNode) {
532-
functionContent += `\n const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), 'pipelines', '${moduleKebabCase}')\n\n`
533+
functionContent += `\n const pipelinePath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pipelines', '${moduleKebabCase}')\n\n`
533534
const mountDirsArg = needMountDirs ? ', mountDirs' : ''
534535
functionContent += ` const {\n returnValue,\n stderr,\n${outputsVar} } = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs${mountDirsArg})\n`
535536
} else {

packages/core/typescript/itk-wasm/src/bindgen/typescript/resources/template.package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"scripts": {
1818
"start": "pnpm copyShoelaceAssets && vite",
1919
"test": "echo \"Error: no test specified\" && exit 1",
20-
"build": "pnpm build:version && pnpm build:tsc && pnpm build:browser:workerEmbedded && pnpm build:browser:workerEmbeddedMin && pnpm build:demo",
20+
"build": "pnpm build:tsc && pnpm build:browser:workerEmbedded && pnpm build:browser:workerEmbeddedMin && pnpm build:demo",
2121
"build:browser:workerEmbedded": "esbuild --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.js ./src/index-worker-embedded.ts",
2222
"build:browser:workerEmbeddedMin": "esbuild --minify --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.min.js ./src/index-worker-embedded.min.ts",
2323
"build:version": "node -p \"'const version = ' + JSON.stringify(require('./package.json').version) + '\\nexport default version\\n'\" > src/version.ts",
24-
"build:tsc": "tsc --pretty",
24+
"build:tsc": "pnpm build:version && tsc --pretty",
2525
"copyShoelaceAssets": "shx mkdir -p test/browser/demo-app/public && shx cp -r node_modules/@shoelace-style/shoelace/dist/assets test/browser/demo-app/public/",
2626
"build:demo": "pnpm copyShoelaceAssets && vite build"
2727
},

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import fs from 'fs'
22
import EmscriptenModule from '../itk-wasm-emscripten-module.js'
33
import { pathToFileURL } from 'url'
44

5-
async function loadEmscriptenModuleNode (modulePath: string): Promise<EmscriptenModule> {
5+
async function loadEmscriptenModuleNode(
6+
modulePath: string
7+
): Promise<EmscriptenModule> {
68
let modulePrefix = modulePath
79
if (modulePath.endsWith('.js')) {
810
modulePrefix = modulePath.substring(0, modulePath.length - 3)
@@ -13,7 +15,9 @@ async function loadEmscriptenModuleNode (modulePath: string): Promise<Emscripten
1315
const wasmBinaryPath = `${modulePrefix}.wasm`
1416
const wasmBinary = fs.readFileSync(wasmBinaryPath)
1517
const fullModulePath = pathToFileURL(`${modulePrefix}.js`).href
16-
const result = await import(/* webpackIgnore: true */ /* @vite-ignore */ fullModulePath)
18+
const result = await import(
19+
/* webpackIgnore: true */ /* @vite-ignore */ fullModulePath
20+
)
1721
const instantiated = result.default({ wasmBinary }) as EmscriptenModule
1822
return instantiated
1923
}

packages/core/typescript/itk-wasm/src/pipeline/run-pipeline-node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PipelineOutput from './pipeline-output.js'
66
import PipelineInput from './pipeline-input.js'
77
import RunPipelineResult from './run-pipeline-result.js'
88

9-
async function runPipelineNode (
9+
async function runPipelineNode(
1010
pipelinePath: string,
1111
args: string[],
1212
outputs: PipelineOutput[],

0 commit comments

Comments
 (0)