Skip to content

Commit 2e443c3

Browse files
authored
Fix relative paths on Windows by using the built-in conversion from file urls to paths. (#390)
1 parent 8d741aa commit 2e443c3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/master/implementation.node.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import getCallsites, { CallSite } from "callsites"
55
import { EventEmitter } from "events"
66
import { cpus } from 'os'
77
import * as path from "path"
8+
import { fileURLToPath } from "url";
89
import {
910
ImplementationExport,
1011
ThreadsWorkerOptions,
@@ -69,7 +70,10 @@ function rebaseScriptPath(scriptPath: string, ignoreRegex: RegExp) {
6970
})
7071

7172
const rawCallerPath = parentCallSite ? parentCallSite.getFileName() : null
72-
const callerPath = rawCallerPath ? rawCallerPath.replace(/^file:\//, "") : null
73+
let callerPath = rawCallerPath ? rawCallerPath : null;
74+
if (callerPath && callerPath.startsWith('file:')) {
75+
callerPath = fileURLToPath(callerPath);
76+
}
7377
const rebasedScriptPath = callerPath ? path.join(path.dirname(callerPath), scriptPath) : scriptPath
7478

7579
return rebasedScriptPath

0 commit comments

Comments
 (0)