-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.ts
More file actions
69 lines (65 loc) · 1.88 KB
/
stream.ts
File metadata and controls
69 lines (65 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @fileoverview `globStreamLicenses` — license-file discovery as an
* async stream. Specialized for the npm-packlist-style license file
* search (`LICENSE*`, `COPYING*`, etc.) with optional originals
* inclusion.
*/
import {
LICENSE_GLOB,
LICENSE_GLOB_RECURSIVE,
LICENSE_ORIGINAL_GLOB_RECURSIVE,
} from '../paths/globs'
import { ArrayIsArray } from '../primordials/array'
import {
defaultIgnore,
getFastGlob,
normalizeIgnorePatterns,
} from './_internal'
import type { GlobOptions } from './types'
/**
* Create a stream of license file paths matching glob patterns.
*
* @example
* ```typescript
* const stream = globStreamLicenses('/tmp/my-package')
* for await (const licensePath of stream) {
* console.log(licensePath)
* }
* ```
*/
/*@__NO_SIDE_EFFECTS__*/
export function globStreamLicenses(
dirname: string,
options?: GlobOptions,
): NodeJS.ReadableStream {
const {
ignore: ignoreOpt,
ignoreOriginals,
recursive,
...globOptions
} = { __proto__: null, ...options } as GlobOptions
// Caller-supplied ignore arrays may contain gitignore-style
// directory patterns (`dist/`); normalize them. Our defaultIgnore
// entries are already trailing-slash-free.
const baseIgnore = ArrayIsArray(ignoreOpt)
? normalizeIgnorePatterns(ignoreOpt)!
: (defaultIgnore as readonly string[] as string[])
const ignore: string[] = [...baseIgnore, '**/*.{cjs,cts,js,json,mjs,mts,ts}']
if (ignoreOriginals) {
ignore.push(LICENSE_ORIGINAL_GLOB_RECURSIVE)
}
/* c8 ignore start - External fast-glob call */
const fastGlob = getFastGlob()
return fastGlob.globStream(
[recursive ? LICENSE_GLOB_RECURSIVE : LICENSE_GLOB],
{
__proto__: null,
absolute: true,
caseSensitiveMatch: false,
cwd: dirname,
...globOptions,
...(ignore ? { ignore } : {}),
} as import('fast-glob').Options,
)
/* c8 ignore stop */
}