-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Fix: ignored-paths for Windows path (fixes #10687) #10691
Conversation
lib/ignored-paths.js
Outdated
? relativePathToOldBaseDir.replace(/\\/g, "/") | ||
: relativePathToOldBaseDir; | ||
|
||
return `${prefix}/${relativePathPrefix}${globWithoutPrefix}`; |
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.
I found relativePathToOldBaseDir
can be ../../../foo/bar
, is this a problem?
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.
Hmm, it might be. I had assumed that one of this.ignoreFileDir
and this.options.cwd
would be the parent of the other. If this.ignoreFileDir
and this.options.cwd
are in different directories, maybe this.getBaseDir()
should return a common ancestor.
lib/ignored-paths.js
Outdated
@@ -94,7 +94,11 @@ function relativize(globPattern, relativePathToOldBaseDir) { | |||
const globWithoutPrefix = globPattern.replace(/^!/, ""); | |||
|
|||
if (globWithoutPrefix.startsWith("/")) { | |||
return `${prefix}/${relativePathToOldBaseDir}${globWithoutPrefix}`; | |||
const relativePathPrefix = (typeof process !== "undefined" && process.platform === "win32") |
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.
Could this be:
const relativePathPrefix = relativePathToOldBaseDir.replace(
new RegExp(`\\${path.sep}`, "g"),
"/"
);
That would avoid the need to depend on process
.
35e5724
to
82b83c4
Compare
I updated this PR. |
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.
With some of the logic we're doing to handle filesystem-specific quirks, should we add debug()
calls for some of the transformations (showing before vs after)?
Otherwise LGTM.
I added some |
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, thanks!
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.
I left a couple more comments, but this mostly looks good.
this._baseDir = a.length < b.length ? a : b; | ||
|
||
// Set the common ancestor. | ||
for (let i = 0; i < a.length && i < b.length; ++i) { |
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.
Would it work to split on path.sep
rather than iterating over each character?
const cwd = path.resolve(this.options.cwd);
const ignoreFileDir = path.resolve(this.ignoreFileDir);
if (cwd === ignoreFileDir) {
this._baseDir = cwd;
} else {
const cwdParts = cwd.split(path.sep);
const ignoreFileDirParts = ignoreFileDir.split(path.sep);
const longerParts = cwdParts.length > ignoreFileDirParts.length
? cwdParts
: ignoreFileDirParts;
this._baseDir = longerParts.slice(
0,
longerParts.findIndex((_, index) => cwdParts[index] !== ignoreFileDirParts[index])
);
}
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.
Hm. I wrote that code as being careful to use only one traverse on the path strings. Indeed, though it's O(n)
as is...
tests/lib/ignored-paths.js
Outdated
|
||
assert.strictEqual(ignoredPaths.getBaseDir(), path.resolve(ignoreFilePath, "../../..")); | ||
}); | ||
|
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.
Can you add tests for an ignore file with \r\n
? (Git would convert the linebreaks to \n
when the repository is cloned, so it would probably be necessary to create the file at runtime.)
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.
I added it.
tests/lib/ignored-paths.js
Outdated
|
||
assert.strictEqual(ignoredPaths.getBaseDir(), path.resolve(ignoreFilePath, "../../..")); | ||
}); | ||
|
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.
Can you add tests for ignoredPaths.contains
when ignoreFilePath
and cwd
are siblings? It would be useful to make sure that the default ignore patterns (e.g. node_modules
) and custom ignore patterns both work.
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.
Probably I added it.
tests/lib/ignored-paths.js
Outdated
|
||
assert.strictEqual(ignoredPaths.getBaseDir(), path.resolve(ignoreFilePath, "../../..")); | ||
}); | ||
|
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.
Is it feasible to add a test for when the baseDir is only a windows drive letter?
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.
The base directory was only a Windows drive letter on Appvoyer environments.
But I'm not sure if we can write such a test safely or not, because of permissions. On my PC, the base directory has often became the home directory of my login user because the temporary directory for tests is in ~\AppData\Local\Temp
.
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, thanks!
What is the purpose of this pull request? (put an "X" next to item)
[X] Bug fix: fixes #10687
What changes did you make? (Give an overview)
This PR fixes some problems of ignored-paths on Windows.
.eslintignore
files.Is there anything you'd like reviewers to focus on?
I'm not sure why Appvoyer didn't find this...