Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ export interface GlobOptions {
follow?: boolean

/**
* string or string[], or an object with `ignored` and `childrenIgnored`
* string or readonly string[], or an object with `ignored` and `childrenIgnored`
* methods.
*
* If a string or string[] is provided, then this is treated as a glob
* If a string or readonly string[] is provided, then this is treated as a glob
* pattern or array of glob patterns to exclude from matches. To ignore all
* children within a directory, as well as the entry itself, append `'/**'`
* to the ignore pattern.
Expand All @@ -117,7 +117,7 @@ export interface GlobOptions {
* determine whether any Path is a match or if its children should be
* traversed, respectively.
*/
ignore?: string | string[] | IgnoreLike
ignore?: string | readonly string[] | IgnoreLike

/**
* Treat brace expansion like `{a,b}` as a "magic" pattern. Has no
Expand Down Expand Up @@ -389,7 +389,7 @@ export class Glob<Opts extends GlobOptions> implements GlobOptions {
dot: boolean
dotRelative: boolean
follow: boolean
ignore?: string | string[] | IgnoreLike
ignore?: string | readonly string[] | IgnoreLike
magicalBraces: boolean
mark?: boolean
matchBase: boolean
Expand Down
2 changes: 1 addition & 1 deletion src/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Ignore implements IgnoreLike {
mmopts: MinimatchOptions

constructor(
ignored: string[],
ignored: readonly string[],
{
nobrace,
nocase,
Expand Down
6 changes: 3 additions & 3 deletions src/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface GlobWalkerOpts {
dot?: boolean
dotRelative?: boolean
follow?: boolean
ignore?: string | string[] | IgnoreLike
ignore?: string | readonly string[] | IgnoreLike
mark?: boolean
matchBase?: boolean
// Note: maxDepth here means "maximum actual Path.depth()",
Expand Down Expand Up @@ -74,12 +74,12 @@ export type MatchStream<O extends GlobWalkerOpts> = Minipass<
>

const makeIgnore = (
ignore: string | string[] | IgnoreLike,
ignore: string | readonly string[] | IgnoreLike,
opts: GlobWalkerOpts,
): IgnoreLike =>
typeof ignore === 'string' ? new Ignore([ignore], opts)
: Array.isArray(ignore) ? new Ignore(ignore, opts)
: ignore
: (ignore as IgnoreLike)

/**
* basic walking utilities that all the glob walker types use
Expand Down
18 changes: 18 additions & 0 deletions test/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,24 @@ for (const c of cases) {
})
}

t.test('readonly ignore patterns', async t => {
const ignore = ['b'] as const
const options: GlobOptions = { cwd: 'a', ignore }
const expect = j([
'abcdef',
'abcfed',
'bc',
'c',
'cb',
'symlink',
'x',
'z',
])

t.same((await glob('*', options)).sort(), expect)
t.same(glob.globSync('*', options).sort(), expect)
})

t.test('race condition', async t => {
process.chdir(__dirname)
var pattern = 'fixtures/*'
Expand Down