developit / web-worker

Consistent Web Workers in browser and Node.

Home Page:https://npm.im/web-worker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

absolute paths to workers in windows not working when containing a drive letter

MartyHav opened this issue · comments

When we create a base url here:

const baseUrl = URL.pathToFileURL(process.cwd() + '/');

It will be ignored later here, if the given url contains drive letter ( like "c:/foo/bar") :

web-worker/node.js

Lines 100 to 102 in 4a46d3a

else {
mod = URL.fileURLToPath(new URL.URL(url, baseUrl));
}

And fileURLToPath will throw an error ( "URL not a file scheme" ) as the drive letter is set as protocol and file scheme of baseUrl is ignored.

I think we are safe when we do it like this:

const urlObject = new URL.URL(url, baseUrl);
mod = urlObject.pathName;

Not sure if this is bypassing the reason why fileUrlToPath is used at all.
But did work for me on Windows and macOS.

I've developed a fix for this and aim to have a PR up soon.