module: fix loading from global folders on Windows#9283
module: fix loading from global folders on Windows#9283richardlau wants to merge 2 commits intonodejs:masterfrom
Conversation
380a0b6 to
37e049a
Compare
|
cc/ @nodejs/platform-windows I feel like this would be a semver-patch change, as it's fixing the actual behaviour to match the docs. |
|
Given past history, we need to be very careful with changes to the module loader logic. @nodejs/ctc ... thoughts on this? |
|
There was already some discussion of this in #6434 , but no decision. What about removing those 3 search locations altogether? As the doc says, "these are mostly for historic reasons", so perhaps it's time to see them gone. If not, I would rather see these paths changed to places that actually make sense on Windows (like |
|
cc @nodejs/testing since this PR also adds a new testcase to cover the documented behaviour. |
|
@joaocgreis Removing them is an even larger change to a system we are trying to not break! I doubt anyone has an appetite for adding new default paths. I don't think adding $PREFIX/lib/node into the default module resolution path would fly as a new feature, but @richardlau isn't proposing that. Its an existing documented feature, we just want it to work. We have a use-case for it, which is why we noticed its broken on Windows. |
sam-github
left a comment
There was a problem hiding this comment.
Existing Windows behaviour seems so wrong, its hard to imagine any user-code relying on it. I'm +1. And its great to see tests.
lib/module.js
Outdated
There was a problem hiding this comment.
If I understand this correctly, on non-Windows we have
$PREFIX/
bin/node
lib/
and on Windows we have
$PREFIX\
node.exe
lib/
So the previous code was adding a path like c:\Program Files\lib to the default node search path.. which is just flat-out wrong?
I think the code above could benefit from a comment describing what its doing. Particularly if my guess above is wrong!
There was a problem hiding this comment.
Yes, your understanding is correct. I have added some comments to the code to clarify.
37e049a to
33f2cf5
Compare
33f2cf5 to
d96e6e0
Compare
|
Rebased and added a comment to the changed code as suggested by @sam-github. I've also edited the PR description to (hopefully) make it clearer what problem this is trying to address with an example showing the current (incorrect) behavior. |
d96e6e0 to
53dd46b
Compare
53dd46b to
72e0f9d
Compare
|
Cherry-picked to both v4 and v6. I plan to do a maintenance release for v4 including this and a couple other bugs that have been caught |
Test executes with a copy of the node executable since $PREFIX/lib/node is relative to the executable location. PR-URL: #9283 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Code was calculating $PREFIX/lib/node relative to process.execPath, but on Windows process.execPath is $PREFIX\node.exe whereas everywhere else process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the installed Node.js). PR-URL: #9283 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Test executes with a copy of the node executable since $PREFIX/lib/node is relative to the executable location. PR-URL: #9283 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Code was calculating $PREFIX/lib/node relative to process.execPath, but on Windows process.execPath is $PREFIX\node.exe whereas everywhere else process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the installed Node.js). PR-URL: #9283 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Test executes with a copy of the node executable since $PREFIX/lib/node is relative to the executable location. PR-URL: #9283 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Code was calculating $PREFIX/lib/node relative to process.execPath, but on Windows process.execPath is $PREFIX\node.exe whereas everywhere else process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the installed Node.js). PR-URL: #9283 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) #9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) #11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) #11947
* (Ben Noordhuis) #11898
* (jBarz) #11776
PR-URL: #12499
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) #9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) #11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) #11947
* (Ben Noordhuis) #11898
* (jBarz) #11776
PR-URL: #12497
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) #9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) #11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) #11947
* (Ben Noordhuis) #11898
* (jBarz) #11776
PR-URL: #12499
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) #9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) #11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) #11947
* (Ben Noordhuis) #11898
* (jBarz) #11776
PR-URL: #12497
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) nodejs/node#9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) nodejs/node#11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) nodejs/node#11947
* (Ben Noordhuis) nodejs/node#11898
* (jBarz) nodejs/node#11776
PR-URL: nodejs/node#12499
Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) nodejs/node#9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) nodejs/node#11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) nodejs/node#11947
* (Ben Noordhuis) nodejs/node#11898
* (jBarz) nodejs/node#11776
PR-URL: nodejs/node#12497
Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) nodejs/node#9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) nodejs/node#11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) nodejs/node#11947
* (Ben Noordhuis) nodejs/node#11898
* (jBarz) nodejs/node#11776
PR-URL: nodejs/node#12499
Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) nodejs/node#9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) nodejs/node#11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) nodejs/node#11947
* (Ben Noordhuis) nodejs/node#11898
* (jBarz) nodejs/node#11776
PR-URL: nodejs/node#12497
Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) nodejs#9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) nodejs#11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) nodejs#11947
* (Ben Noordhuis) nodejs#11898
* (jBarz) nodejs#11776
PR-URL: nodejs#12499
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) nodejs#9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) nodejs#11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) nodejs#11947
* (Ben Noordhuis) nodejs#11898
* (jBarz) nodejs#11776
PR-URL: nodejs#12497
|
🎉🎉🎉🎉🎉🎉🎉🎉🎉 |
Test executes with a copy of the node executable since $PREFIX/lib/node is relative to the executable location. PR-URL: nodejs/node#9283 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Code was calculating $PREFIX/lib/node relative to process.execPath, but on Windows process.execPath is $PREFIX\node.exe whereas everywhere else process.execPath is $PREFIX/bin/node (where $PREFIX is the root of the installed Node.js). PR-URL: nodejs/node#9283 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Notable Changes:
* module:
- The module loading global fallback to the Node executable's
directory now works correctly on Windows.
(Richard Lau) nodejs/node#9283
* src:
- fix base64 decoding in rare edgecase
(Nikolai Vavilov) nodejs/node#11995
* tls:
- fix rare segmentation faults when using TLS
* (Trevor Norris) nodejs/node#11947
* (Ben Noordhuis) nodejs/node#11898
* (jBarz) nodejs/node#11776
PR-URL: nodejs/node#12497
Checklist
make -j8 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
module
Description of change
According to the
moduledocumentation:Loading from
$PREFIX/lib/nodeis broken on Windows as the code is calculating$PREFIX/lib/noderelative to
process.execPath, but on Windowsprocess.execPathis$PREFIX\node.exewhereas everywhere elseprocess.execPathis$PREFIX/bin/node(where$PREFIXis the root of theinstalled Node.js).
e.g. If Node.js is in
c:\node, the code is addingc:\lib\nodeto the lookup path instead ofc:\node\lib\node: