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
Normalize glob patterns with trailing slashes #2788
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,21 +110,26 @@ function normalizeFileForMatching(cwd, file) { | |
|
||
exports.normalizeFileForMatching = normalizeFileForMatching; | ||
|
||
const normalizeNegatedPattern = (cwd, pattern) => { | ||
// Remove `!` from pattern | ||
const patternPath = pattern.slice(1); | ||
const relativePath = path.relative(cwd, patternPath); | ||
return `!${relativePath}`; | ||
}; | ||
|
||
function normalizePattern(pattern) { | ||
const cwd = process.cwd(); | ||
// Always use `/` in patterns, harmonizing matching across platforms | ||
if (process.platform === 'win32') { | ||
pattern = slash(pattern); | ||
} | ||
|
||
if (pattern.startsWith('./')) { | ||
return pattern.slice(2); | ||
} | ||
|
||
if (pattern.startsWith('!./')) { | ||
return `!${pattern.slice(3)}`; | ||
if (pattern.startsWith('!')) { | ||
return normalizeNegatedPattern(cwd, pattern); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the helper function is all that useful, especially since it hides the critical |
||
} | ||
|
||
return pattern; | ||
const normalizedPattern = path.relative(cwd, pattern); | ||
return normalizedPattern; | ||
} | ||
|
||
exports.normalizePattern = normalizePattern; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
cwd
needs to be an argument here. AVA determines the directory to which patterns are relevant and it may not be the CWD.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.
thank you for pointing this out, I see now I think we should receive the CWD as an argument in the
normalizeGlobs
here:ava/lib/globs.js
Line 35 in dc93f37
Then we pass it to
normalizePatterns
call in the same function.Also i noticed this line in cli.js
ava/lib/cli.js
Line 396 in dc93f37
which using nearly the same function path.relative, but path.resolve is being used in the second parameter to get the absolute path