You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IIRC we have prior art on accepting file urls for various APIs, but i don't remember which ones.
The initial URL support for the fs module supported this, but it was later withdrawn from the PR because a) it could invalidate previously existing security checks when reading from paths that are partially user-controlled and b) file URLs are, sadly, also valid paths for files in directories named file:.
Support for new Worker(import.meta) would eliminate ambiguity. Just a thought, not suggesting it's a good idea.
That said a filename matching /^file:/ or /^data:/ is very edge case for this API, does anyone even use new Worker(pathRelativeToCWD)? The documentation only suggests new Worker(__filename) which would never result in a filename that is ambiguous to URL's. new Worker('./other-file.js') would be unreliable as it would be based on process.cwd(), instead new Worker(require.resolve('./other-file.js')) or new Worker(new URL('./other-file.js', import.meta.url).href) would be needed. I'd go as far as saying that passing a relative path to this API should be an error.
does anyone even use new Worker(pathRelativeToCWD) ?
I used it multiple times. It is convenient in apps to always use new Worker('./src/workers/myworker.js') from anywhere in the hierarchy and as not necessarily unreliable. My apps are always started with their root as working directory.
Activity
devsnek commentedon Dec 3, 2019
IIRC we have prior art on accepting file urls for various APIs, but i don't remember which ones.
addaleax commentedon Dec 3, 2019
The initial URL support for the
fsmodule supported this, but it was later withdrawn from the PR because a) it could invalidate previously existing security checks when reading from paths that are partially user-controlled and b) file URLs are, sadly, also valid paths for files in directories namedfile:.I think a) is not a large concern here.
guybedford commentedon Dec 3, 2019
b) has typically been also seen as a backwards-incompatible change. Perhaps to implement it that way upfront now though would be permissible.
Then, if users really need a directory named file: they can convert the path into a URL.
coreyfarrell commentedon Dec 5, 2019
Support for
new Worker(import.meta)would eliminate ambiguity. Just a thought, not suggesting it's a good idea.That said a filename matching
/^file:/or/^data:/is very edge case for this API, does anyone even usenew Worker(pathRelativeToCWD)? The documentation only suggestsnew Worker(__filename)which would never result in a filename that is ambiguous to URL's.new Worker('./other-file.js')would be unreliable as it would be based onprocess.cwd(), insteadnew Worker(require.resolve('./other-file.js'))ornew Worker(new URL('./other-file.js', import.meta.url).href)would be needed. I'd go as far as saying that passing a relative path to this API should be an error.targos commentedon Dec 5, 2019
I used it multiple times. It is convenient in apps to always use
new Worker('./src/workers/myworker.js')from anywhere in the hierarchy and as not necessarily unreliable. My apps are always started with their root as working directory.jasnell commentedon Dec 5, 2019
Just having something like the following would work...
Jamesernator commentedon Jan 3, 2020
^ This approach is how
fsaccepts URLs, it just acceptsURLobjects, strings are always treated as paths.worker_threads: allow URL in Worker constructor
worker: allow URL in Worker constructor
worker: allow URL in Worker constructor
worker: allow URL in Worker constructor
worker: allow URL in Worker constructor