-
-
Notifications
You must be signed in to change notification settings - Fork 247
fix: #775 node_modules not ignored. #802
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { relative, isAbsolute } from 'path'; | ||
|
||
function isInsideAnotherPath(parent: string, directory: string): boolean { | ||
const relativePart = relative(parent, directory); | ||
// Tested folder is above parent. | ||
if (relativePart.startsWith('..')) { | ||
return false; | ||
} | ||
// Tested folder is the same as parent. | ||
if (relativePart.length === 0) { | ||
return false; | ||
} | ||
// Tested directory has nothing in common with parent. | ||
if (isAbsolute(relativePart)) { | ||
return false; | ||
} | ||
// Last option, must be subfolder. | ||
return true; | ||
} | ||
|
||
export { isInsideAnotherPath }; |
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { isInsideAnotherPath } from '../../../../src/utils/path/is-inside-another-path'; | ||
|
||
jest.mock('path', () => jest.requireActual('path').posix); | ||
|
||
const unixTests: [string, string, boolean][] = [ | ||
// Identical | ||
['/foo', '/foo', false], | ||
// Nothing in common | ||
['/foo', '/bar', false], | ||
// subfolder | ||
['/foo', '/foo/bar', true], | ||
// parallel | ||
['/foo', '/foo/../bar', false], | ||
// relative subfolder | ||
['/foo', '/foo/./bar', true], | ||
]; | ||
|
||
describe('Properly detects ignored sub-folders on Unix', () => { | ||
it('should work on Unix', () => { | ||
unixTests.forEach(([parent, testedPath, expectedResult]) => { | ||
const result = isInsideAnotherPath(parent, testedPath); | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
test/unit/utils/path/is-inside-another-path-windows.spec.ts
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { isInsideAnotherPath } from '../../../../src/utils/path/is-inside-another-path'; | ||
|
||
jest.mock('path', () => jest.requireActual('path').win32); | ||
|
||
const windowsTests: [string, string, boolean][] = [ | ||
// subfolder | ||
['C:\\Foo', 'C:\\Foo\\Bar', true], | ||
// Nothing in common | ||
['C:\\Foo', 'C:\\Bar', false], | ||
// Wrong drive. | ||
['C:\\Foo', 'D:\\Foo\\Bar', false], | ||
]; | ||
|
||
describe('Properly detects ignored sub-folders on Windows', () => { | ||
it('should work on Windows', () => { | ||
windowsTests.forEach(([parent, testedPath, expectedResult]) => { | ||
const result = isInsideAnotherPath(parent, testedPath); | ||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.