-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module: accept Windows relative path #22186
module: accept Windows relative path #22186
Conversation
if (parentIdPath === '.' && id.indexOf('/') === -1) { | ||
if (parentIdPath === '.' && | ||
id.indexOf('/') === -1 && | ||
(!isWindows || id.indexOf('\\') === -1)) { | ||
id = './' + id; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looked necessary, but this piece of code does not seem to be used anywhere in node core nor tested. newReturn
seems to be passed as true everywhere. Hence, I'm not sure about this, let me know if I should leave this as it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newReturn
is for backwards compatibility. There were some people using the private, underscored methods directly and were expecting the old return value.
runTest('./lodash'); | ||
if (common.isWindows) { | ||
runTest('.\\lodash'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be an else
clause added that asserts that runTest('.\\lodash')
on non-Windows throws or whatever it is supposed to do?
@Trott thanks! Updated. CI: https://ci.nodejs.org/view/All/job/node-test-pull-request/16346/ cc @nodejs/platform-windows. Not sure who to ping for modules (the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Food for thought and too big a discussion for the changes done here, but I feel it's kinda awkward we allow POSIX require paths on Windows, but not Windows paths on POSIX. If we did, it would mean better code portability. But again keeping to POSIX paths would provide that portability cross Windows/POSIX already so 🤷♂️ |
cc @nodejs/modules I plan to land this next week if there are no objections. |
@joaocgreis This seems fine for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a huge change and effectively means that code developed on Windows has a lower chance of working on linux/mac which can cause divergence.
Module paths are not file paths.
I'm not sure I object to the change itself but I think there needs to be more discussion before we simply land this.
@bmeck why would this be fine for Also cc @nodejs/platform-windows |
I'd be totally fine with fixing #21918 though only for |
@benjamingr mostly because |
This PR is a small bug fix for cjs. I'm not sure I fully understand all the red x's to hold it. @benjamingr are you objecting to the comment by @phillipj and not the PR? Much of Node's code already allows forward and back slashes for Windows in paths. This PR fixes one place where it was missed. |
@jdalton mostly, I did not want this to get merged without a LGTM from @nodejs/platform-windows since it changes the behaviour to diverge between windows and other platforms further. If it's consistent and aligns with the policy - then sure. |
@benjamingr Ah ok. @joaocgreis is on the Note: \cc @mhdawson I'd like to be added to @nodejs/platform-windows since its a neighboring Microsoft team (DevPlat) that's tasked with this and it has cross-over into my team (WebPlat DevX). |
Clearing my review given clarifications.
@jdalton: I added you to platform-windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's think about this a little bit more
What does this produce: console.log(require('.\\test.js') === require('./test.js')) P.S. I'm tending towards -1
@jdalton I'm not sure that is a good enough argument to change CJS semantics... This has been there for the lifespan of CJS, right? I'd rather not change it. Which brings up other windows FS quirks such as case sensitivity. console.log(require('.\\test.js') === require('.\\Test.js')) Or is that allowed while console.log(require('./test.js') === require('./Test.js')) is not... |
@refack The example below assumes a path of foo.jsconsole.log("\n" + [
path.resolve(".\\bar.js"),
require(path.resolve(".\\bar.js")),
require("./..\\demo\\bar.js"),
require("..\\demo\\bar.js"),
require("./bar.js")
].join("\n")) bar.jsmodule.exports = "bar" Running
While I can do As a Windows user I've hit this issue on more than one occasion and was surprised it wasn't addressed. It motivated me fix in my own module loader (a year or so back). This inconsistency/oversight is one of the many cuts that makes the Node Windows experience less-great than other platforms. |
BTW: isn't this |
@jdalton would you be able to perhaps open a PR to https://github.com/browserify/resolve that adds a test case for this new behavior? :-D |
Yep. Anywhere there is a one-off path separator check it's easy to overlook. One way to handled this is by abstracting the check to a helper method for broader internal use.
I dig more tests!
It can be.
Yep! |
Adding the semver-major tag per the discussion. |
I agree with CI: https://ci.nodejs.org/view/All/job/node-test-pull-request/16687/ Thanks for the reviews so far! Since this is now |
I rebased and tried to force push to fix the dreaded jinja LICENSE CRLF thing, but I don't have permissions to push. @joaocgreis: Can you rebase this against master? |
Wait. If this reproduces the CRLF issue, I want to investigate. |
9e10faa
to
98ce2d5
Compare
@Trott thanks! Rebased, here we go again: https://ci.nodejs.org/view/All/job/node-test-pull-request/16736/ @refack in case you need, the previous head was 9e10faa54ca78dea007b1b1997d92047c6512037, just the same 3 commits here on top of c6a54af. That was before #22340, the failures look as expected to me. Do you see something unexpected there? |
CI is green. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if CITGM doesn't find anything alarming.
Before this change, require('.\\test.js') failed while require('./test.js') succeeded. This changes _resolveLookupPaths so that both ways are accepted on Windows. Fixes: nodejs#21918
98ce2d5
to
cf41cb0
Compare
CitGM (this PR): https://ci.nodejs.org/view/All/job/citgm-smoker/1523/ |
@Trott CitGM looks quite red, but similar to master. Do you see anything alarming? |
@joaocgreis the failures all seem unrelated to me. These show up in all CITGM runs. There are still a couple of flakes. |
CI is all green. Landed in b36c581. Thanks for all reviews! |
Before this change, require('.\\test.js') failed while require('./test.js') succeeded. This changes _resolveLookupPaths so that both ways are accepted on Windows. Fixes: #21918 PR-URL: #22186 Reviewed-By: Phillip Johnsen <johphi@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
Before this change,
require('.\\test.js')
failed whilerequire('./test.js')
succeeded. This changes_resolveLookupPaths
so that both ways are accepted on Windows.Fixes: #21918 (cc @targos)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes