diff --git a/src/glob.ts b/src/glob.ts index ac0c654e..30d4bc3c 100644 --- a/src/glob.ts +++ b/src/glob.ts @@ -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. @@ -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 @@ -389,7 +389,7 @@ export class Glob implements GlobOptions { dot: boolean dotRelative: boolean follow: boolean - ignore?: string | string[] | IgnoreLike + ignore?: string | readonly string[] | IgnoreLike magicalBraces: boolean mark?: boolean matchBase: boolean diff --git a/src/ignore.ts b/src/ignore.ts index 583c67f5..b26ed588 100644 --- a/src/ignore.ts +++ b/src/ignore.ts @@ -36,7 +36,7 @@ export class Ignore implements IgnoreLike { mmopts: MinimatchOptions constructor( - ignored: string[], + ignored: readonly string[], { nobrace, nocase, diff --git a/src/walker.ts b/src/walker.ts index c70e38bb..758b0e50 100644 --- a/src/walker.ts +++ b/src/walker.ts @@ -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()", @@ -74,12 +74,12 @@ export type MatchStream = 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 diff --git a/test/ignore.ts b/test/ignore.ts index 460117b0..3f1a8448 100644 --- a/test/ignore.ts +++ b/test/ignore.ts @@ -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/*'