Conversation
benjamingr
left a comment
There was a problem hiding this comment.
Thanks for opening a pull request 🎉 .
Actual changes LGTM and a few people I talked to have run into this so +1 on the actual change too.
|
The catch here is that this may lead to surprising results if the program is run from a different working directory than what is expected. If we do support relative paths, I’d much prefer it if we could make it relative to the path of the caller script… |
|
Hi @addaleax I find that it would be very counter-intuitive for the path to be relative to the caller script. For instance, if I call |
|
I would expect |
|
I think changing it would require just resolving with |
|
Fair point @benjamingr. I tend to agree, though that would mean Is that what you're going for?
|
|
Come to think of it, I would say Also, I really don't know how to get the caller file path without hacking into the stack trace or something like that. It is a bit weird to expect a constructor to "know" which file his caller comes from. For an import statement (and |
|
@itaysabato so the current (non process.cwd) behaviour is similar to how |
I was explicitly referring to the CWD behaviour - although you can |
The thing is, this being the majority use case makes it easy to write code under that assumption… As you noticed, I’m not putting a red X on this or anything. I’m saying that this was a choice I made and that, if other people think it makes sense, I’m okay with it being aligned with somebody else’s expectations rather than mine. :) |
I'm not sure why you call it "non process.cwd" because the current code calls I didn't know |
targos
left a comment
There was a problem hiding this comment.
LGTM. Relative to cwd is what I expect. It is also closer to how Web Workers do it imo
|
One possible concern that I realized today: If we work towards full web compat, then allowing relative paths is going to conflict with URL strings and I think we’d need to either undo this or control it through the options object here. :/ Maybe we could use |
Can you explain this? |
|
@benjamingr One pain point we’ve had with |
|
@addaleax I'm -1 on accepting URL strings to worker - I'm +1 on accepting URL objects at some point in the future though though some people (namely @issacs) have objected to this due to the burden on third-party authors and security implications. Then again unlike file-reading I really don't see dynamic worker URLs as something too common. |
|
What about throwing for now if a valid URL is passed? |
That seems like it would be at odds with ever making |
|
@addaleax what if instead of opting in for relative paths users would opt in for urls? E.g. Does that make sense? |
|
Going to do one last ping to @devsnek to make sure they are OK with the behavior and land it tomorrow if there are no objections. |
|
@itaysabato That makes sense if we don’t expect URL usage by default / don’t care about the fact that WebWorkers use URLs … my gut feeling is still that we would rather want to put relative paths behind an option, but I can see valid points for either side here :) |
|
@addaleax if you really think supporting plain relative paths might conflict with URL strings then I agree this is a serious concern indeed. I thought that was only the case for fs because of how entrenched the workflows are, and would have assumed that such a brutal edge case wouldn't need to apply here for backwards compatibility concerns in future. But if it is a concern, then this could be restricted to only an absolute or relative path (starting with |
|
|
|
Another way to postpone the URL support decision is to only support relative paths starting with |
guybedford
left a comment
There was a problem hiding this comment.
I do think it's important to ensure the best outcome for URL compatibility here.
lib/internal/worker.js
Outdated
There was a problem hiding this comment.
I would prefer if we can add the filter here to only apply path.resolve for absolute, ./ and ../ paths.
There was a problem hiding this comment.
why the nextTick here? Seems a bit pointless.
There was a problem hiding this comment.
Actually it was simply copied from test-worker.js
There was a problem hiding this comment.
For context, inside that test the purpose is to make sure that both libuv bindings + process.nextTick() work – we don’t need that here, and I probably should have added a comment to the other test about it ;)
|
I can't tell from the build logs what's wrong. |
|
CI failures seem unrelated |
9348fe0 to
8defed3
Compare
apapirovski
left a comment
There was a problem hiding this comment.
As far as I can tell this isn't system aware hence the CI failures. Feel free to dismiss my objection if I'm incorrect.
The explicit test for './' and '../' seems to point in that direction though...
|
@apapirovski as far as I can see the build is passing now. |
|
@itaysabato The last CI I can see is red and certainly had related failures. |
|
Ah I see, so the Travis build doesn't cover everything Jenkins covers? |
Travis only covers linting and testing on Linux.
No. A collaborator has to manually trigger a Jenkins run. |
|
Finally managed to build on a windows vm. ***fixing... |
This commit adds support for relative paths in Worker. Paths are relative to the current working directory. PR-URL: nodejs#21407 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
ca338a3 to
c31ae12
Compare
|
Should be fixed now. |
|
thanks :) |
This commit adds support for relative paths in Worker. Paths are relative to the current working directory. PR-URL: #21407 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
|
CI is now green, good catch Anatoli and thanks for fixing Itay! Landed in 8d33bbf 🎉 I hope this is your first PR in many! Random nit - PR-URL should be a URL :) I amended that for you. |
This commit adds support for relative paths in Worker. Paths are relative to the current working directory. PR-URL: #21407 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Notable changes:
* build:
* Node.js should now be about 60% faster to startup than the previous version,
thanks to the use V8's code cache feature for core modules. [#21405](#21405)
* dns:
* An experimental promisified version of the dns module is now available. Give
it a try with `require('dns').promises`. [#21264](#21264)
* fs:
* `fs.lchown` has been undeprecated now that libuv supports it. [#21498](#21498)
* lib:
* `Atomics.wake` is being renamed to `Atomics.notify` in the ECMAScript
specification ([reference](tc39/ecma262#1220)).
Since Node.js now has experimental support for worker threads, we are being
proactive and added a `notify` alias, while emitting a warning if
`wake` is used. [#21413](#21413) [#21518](#21518)
* n-api:
* Add API for asynchronous functions. [#17887](#17887)
* util:
* `util.inspect` is now able to return a result instead of throwing when the
maximum call stack size is exceeded during inspection. [#20725](#20725)
* vm:
* Add `script.createCachedData()`. This API replaces the `produceCachedData`
option of the `Script` constructor that is now deprecated. [#20300](#20300)
* worker:
* Support for relative paths has been added to the `Worker` constructor. Paths
are interpreted relative to the current working directory. [#21407](#21407)
PR-URL: #21629
Notable changes:
* dns:
* An experimental promisified version of the dns module is now available. Give
it a try with `require('dns').promises`. [#21264](#21264)
* fs:
* `fs.lchown` has been undeprecated now that libuv supports it. [#21498](#21498)
* lib:
* `Atomics.wake` is being renamed to `Atomics.notify` in the ECMAScript
specification ([reference](tc39/ecma262#1220)).
Since Node.js now has experimental support for worker threads, we are being
proactive and added a `notify` alias, while emitting a warning if
`wake` is used. [#21413](#21413) [#21518](#21518)
* n-api:
* Add API for asynchronous functions. [#17887](#17887)
* util:
* `util.inspect` is now able to return a result instead of throwing when the
maximum call stack size is exceeded during inspection. [#20725](#20725)
* vm:
* Add `script.createCachedData()`. This API replaces the `produceCachedData`
option of the `Script` constructor that is now deprecated. [#20300](#20300)
* worker:
* Support for relative paths has been added to the `Worker` constructor. Paths
are interpreted relative to the current working directory. [#21407](#21407)
PR-URL: #21629
Notable changes:
* dns:
* An experimental promisified version of the dns module is now available. Give
it a try with `require('dns').promises`. [#21264](#21264)
* fs:
* `fs.lchown` has been undeprecated now that libuv supports it. [#21498](#21498)
* lib:
* `Atomics.wake` is being renamed to `Atomics.notify` in the ECMAScript
specification ([reference](tc39/ecma262#1220)).
Since Node.js now has experimental support for worker threads, we are being
proactive and added a `notify` alias, while emitting a warning if
`wake` is used. [#21413](#21413) [#21518](#21518)
* n-api:
* Add API for asynchronous functions. [#17887](#17887)
* util:
* `util.inspect` is now able to return a result instead of throwing when the
maximum call stack size is exceeded during inspection. [#20725](#20725)
* vm:
* Add `script.createCachedData()`. This API replaces the `produceCachedData`
option of the `Script` constructor that is now deprecated. [#20300](#20300)
* worker:
* Support for relative paths has been added to the `Worker` constructor. Paths
are interpreted relative to the current working directory. [#21407](#21407)
PR-URL: #21629
This commit adds support to relative paths in worker.
Hi, this is my first pull request in Node.js.
@benjamingr helped me find this issue.
CC @nodejs/workers @addaleax
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes