Skip to content

Commit fbb937e

Browse files
committed
fix(run-pipeline-node): update args with mounted path on Windows
The Emscripten virtual filesystem, which is used by the Wasm processing piplen, mounted path does not match the Windows path that is mounted. Update the arguments accordingly.
1 parent 64d8b8e commit fbb937e

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'path'
2+
13
import loadEmscriptenModuleNode from './internal/load-emscripten-module-node.js'
24
import runPipelineEmscripten from './internal/run-pipeline-emscripten.js'
35

@@ -6,7 +8,38 @@ import PipelineOutput from './pipeline-output.js'
68
import PipelineInput from './pipeline-input.js'
79
import RunPipelineResult from './run-pipeline-result.js'
810

9-
async function runPipelineNode (
11+
function windowsToEmscriptenPath(filePath: string): string {
12+
// Following mount logic in itkJSPost.js
13+
const fileBasename = path.basename(filePath)
14+
const containingDir = path.dirname(filePath)
15+
let mountedPath = '/'
16+
const splitPath = containingDir.split(path.sep)
17+
for (let ii = 1; ii < splitPath.length; ii++) {
18+
mountedPath += splitPath[ii]
19+
mountedPath += '/'
20+
}
21+
mountedPath += fileBasename
22+
return mountedPath
23+
}
24+
25+
function replaceArgumentsWithEmscriptenPaths(
26+
args: string[],
27+
mountDirs: Set<string>
28+
): string[] {
29+
if (typeof process === 'undefined' || process.platform !== 'win32') {
30+
return args
31+
}
32+
return args.map((arg) => {
33+
for (const mountDir of mountDirs) {
34+
if (arg.startsWith(mountDir)) {
35+
return windowsToEmscriptenPath(arg)
36+
}
37+
}
38+
return arg
39+
})
40+
}
41+
42+
async function runPipelineNode(
1043
pipelinePath: string,
1144
args: string[],
1245
outputs: PipelineOutput[],
@@ -22,6 +55,9 @@ async function runPipelineNode (
2255
mountedDirs.add(Module.mountDir(dir))
2356
})
2457
}
58+
if (typeof mountDirs !== 'undefined') {
59+
args = replaceArgumentsWithEmscriptenPaths(args, mountDirs)
60+
}
2561
const result = runPipelineEmscripten(Module, args, outputs, inputs)
2662
if (typeof mountDirs !== 'undefined') {
2763
mountedDirs.forEach((dir) => {

0 commit comments

Comments
 (0)