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
Support URL
as cwd
#201
Merged
Merged
Support URL
as cwd
#201
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
072a774
Support `URL` as `cwd`
fisker ae0bfbb
Remove unnecessary `toPath`
fisker 6fb51e9
Reduce diff
fisker f24eb04
Fix `cwd` in `isDynamicPattern`
fisker 695b22d
Linting
fisker 188c45c
Merge branch 'main' into cwd-url
fisker e4f161c
Remove `url-or-path`
fisker 05556fc
Move empty check to `toPath()`
fisker 245eb35
Use `file://` to check
fisker 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
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 |
---|---|---|
@@ -1,101 +1,120 @@ | ||
import path from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
import {fileURLToPath, pathToFileURL} from 'node:url'; | ||
import test from 'ava'; | ||
import slash from 'slash'; | ||
import {isGitIgnored, isGitIgnoredSync} from './gitignore.js'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const getCwdValues = cwd => [cwd, pathToFileURL(cwd), pathToFileURL(cwd).href]; | ||
|
||
test('gitignore', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['bar.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/gitignore'))) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['bar.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('gitignore - mixed path styles', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
t.true(isIgnored(slash(path.resolve(cwd, 'foo.js')))); | ||
const directory = path.join(__dirname, 'fixtures/gitignore'); | ||
for (const cwd of getCwdValues(directory)) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
t.true(isIgnored(slash(path.resolve(directory, 'foo.js')))); | ||
} | ||
}); | ||
|
||
test('gitignore - os paths', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
t.true(isIgnored(path.resolve(cwd, 'foo.js'))); | ||
const directory = path.join(__dirname, 'fixtures/gitignore'); | ||
for (const cwd of getCwdValues(directory)) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
t.true(isIgnored(path.resolve(directory, 'foo.js'))); | ||
} | ||
}); | ||
|
||
test('gitignore - sync', t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['bar.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/gitignore'))) { | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['bar.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('ignore ignored .gitignore', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const ignore = ['**/.gitignore']; | ||
|
||
const isIgnored = await isGitIgnored({cwd, ignore}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js', 'bar.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/gitignore'))) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd, ignore}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js', 'bar.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('ignore ignored .gitignore - sync', t => { | ||
const cwd = path.join(__dirname, 'fixtures/gitignore'); | ||
const ignore = ['**/.gitignore']; | ||
|
||
const isIgnored = isGitIgnoredSync({cwd, ignore}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js', 'bar.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/gitignore'))) { | ||
const isIgnored = isGitIgnoredSync({cwd, ignore}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js', 'bar.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('negative gitignore', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/negative'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/negative'))) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('negative gitignore - sync', t => { | ||
const cwd = path.join(__dirname, 'fixtures/negative'); | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/negative'))) { | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); | ||
const expected = ['foo.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('multiple negation', async t => { | ||
const cwd = path.join(__dirname, 'fixtures/multiple-negation'); | ||
const isIgnored = await isGitIgnored({cwd}); | ||
|
||
const actual = [ | ||
'!!!unicorn.js', | ||
'!!unicorn.js', | ||
'!unicorn.js', | ||
'unicorn.js', | ||
].filter(file => !isIgnored(file)); | ||
|
||
const expected = ['!!unicorn.js', '!unicorn.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/multiple-negation'))) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const isIgnored = await isGitIgnored({cwd}); | ||
|
||
const actual = [ | ||
'!!!unicorn.js', | ||
'!!unicorn.js', | ||
'!unicorn.js', | ||
'unicorn.js', | ||
].filter(file => !isIgnored(file)); | ||
|
||
const expected = ['!!unicorn.js', '!unicorn.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); | ||
|
||
test('multiple negation - sync', t => { | ||
const cwd = path.join(__dirname, 'fixtures/multiple-negation'); | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
|
||
const actual = [ | ||
'!!!unicorn.js', | ||
'!!unicorn.js', | ||
'!unicorn.js', | ||
'unicorn.js', | ||
].filter(file => !isIgnored(file)); | ||
|
||
const expected = ['!!unicorn.js', '!unicorn.js']; | ||
t.deepEqual(actual, expected); | ||
for (const cwd of getCwdValues(path.join(__dirname, 'fixtures/multiple-negation'))) { | ||
const isIgnored = isGitIgnoredSync({cwd}); | ||
|
||
const actual = [ | ||
'!!!unicorn.js', | ||
'!!unicorn.js', | ||
'!unicorn.js', | ||
'unicorn.js', | ||
].filter(file => !isIgnored(file)); | ||
|
||
const expected = ['!!unicorn.js', '!unicorn.js']; | ||
t.deepEqual(actual, expected); | ||
} | ||
}); |
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
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
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
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
Oops, something went wrong.
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.
CC @sindresorhus
URL
interface belongs tolib.dom.d.ts
, so now we force TS users to injectcompilerOptions.lib: ['dom']
to resolveURL
as global. It breaks TS builds and formally this is a breaking change.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.
https://nodejs.org/api/url.html#the-whatwg-url-api
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.
Otherwise it should be explicitly imported in
index.d.ts
. It does not belong to global by default.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.
@sindresorhus
I really don't want to fix hundreds of our
globby@^12
-dependant projects all night )). Could you plz roll the patch #206?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'm sorry for breaking your projects, but I know nothing about the typing, I can't help.