-
-
Notifications
You must be signed in to change notification settings - Fork 480
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
feat: coerce all paths to forward slashes as a config option #468
Comments
Just clarifying, the config option would be disabled by default. |
How about this: With the caveat that if you set |
I like Most of my use cases for glob involve resolving paths to an absolute path, and then appending to that string. I'm not sure if my use case is common, but it seems like it would be common, and I think that |
I like
or "better" be an option to explicitly disable this possibility, |
There really is no way to have glob work as expected, if the escape character and the path separator are the same character. How can it know whether Either windows users cannot escape glob chars (which they've complained about), or they have to use / as path separators (which has been the recommendation for a decade now). |
So you can explicitly opt in to using \ as your path separator (and not have escaping), or maybe we make both the path separator and the escape character configurable? But "just use the implicit default path separator, and also be a bash style glob" isn't logically coherent. |
On Windows the path separator is always escaped. So In your examples above, it would be: Edit: couldn't you just replace every
|
The issue that I was describing was when dealing with paths run through either path.join or path.resolve. Most other cases still work, and don't need changes. |
That's actually pretty close to the implementation I was thinking of. My idea of the implementation of
Here's a quick implementation: const { pathSeparator } = opts;
if (typeof pathSeparator === "string") {
pattern = pattern.split(pathSeparator).join("/");
} Here's a couple things I don't like with that implementation:
So, after all of this, I just have two questions for @isaacs:
Once I have answers, I'll go ahead and link a draft PR to this. |
@juergba You're confusing "escaped in the JavaScript code" with "escaped in the string". For example: console.log('c:\\foo\\bar\\*\\baz')
// prints: c:\foo\bar\*\baz So that Say you want to find all the files in a directory that have a
This was exactly the problem with Glob v7 and before. It meant that there is almost no way to match filenames containing One possible approach to consider (semver minor change):
Another possible approach: if a glob pattern matches But "just allow @nicolas377 Regarding PRs and readability vs whatever, in this or any of my repos, here are some good rules of thumb:
This module is marked for rewriting once I get time to do it (maybe months, maybe years, idk, but it's on my list) so definitely try to keep any change as tight as possible ;) |
Alright! I'll work on this tomorrow, hopefully I'll have the PR ready for review tomorrow as well. |
Another point about code style: I try to follow Most Restrictive Production, so yes, use consts where possible, small functions, etc. |
Maybe another take on this, less general, but YAGNI, so maybe better: just let Windows users specify a Then the code change is just |
Updating minimatch and everything to make the |
@nicolas377 I don't know if you've had a chance to take a look at this, but the suggested fix in my last comment is pretty trivial. PR up at #470 if you want to review and see if you think it will solve the problem. |
Sorry that I've abandoned this! I'm in the middle of exam prep right now, but I'll try and review that PR over the weekend. |
No worries! I always interpret such intentions as aspirations, you don't owe your life to OSS ;) Good luck on your exams. |
Hello, I would like to ask if this was meant to be included in the 7.2.2 release? Two versions were released 8 hours ago, if it is, can the default value be |
Nothing user-facing should have changed while upgrading from 7.2.1 to 7.2.2. |
I do have a few ideas, here they are. Here are two ways I want users to be able to support windows (while removing support for escaping literal glob chars, which can be a feature to be discussed in the future). Keep in mind that all of these examples are just api calls that I would like to work. They also assume const { sep } = require("node:path/win32");
glob(path, { pathSep: sep }, () => {}); glob(path, { supportWindowsPaths: true }, () => {}); Let me explain these two options (I'll implement them this weekend): pathSeppathSep should be a string that the user intends to use as their path separator. Internally, pathSep should just perform a replacement on the inputted path, switching the given
supportWindowsPathssupportWindowsPaths is intended to just be a switch to flip so that glob does all the work on the backend. Here's a pseudocode implementation, assuming the passed options are at the object variable options and the passed pattern is available at the string variable pattern:
For right now, I'd close that PR, and I'll try to open up a PR this weekend. Expect a draft PR up today or tomorrow. |
v7.2.1 has never been published on npm, and from 7.2.0 to 7.2.2 their may be breaking changes on windows. |
Stay on 7.2.0 for right now, I'm gonna open a tracking issue for that. |
This comment was marked as resolved.
This comment was marked as resolved.
There is a bug in latest 7.2.* version of glob package isaacs/node-glob#468 (comment)
With the recent issues in glob v8 (see the conversation in #467), I thought it would be a good idea to add a config option that would coerce the inputted glob path to use forward slashes instead of just forcing users to convert their paths to forward slashes.
Some use cases allow users to predictably use forward slashes (e.x. using relative paths in glob calls), but most don't allow that.
I'm not sure of a name for the config option, I'm open to suggestions. Once I get approval from the owners, I'll go ahead and open a PR.
The text was updated successfully, but these errors were encountered: