@cjser/globby 16.2.0-cjser.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,132 @@
1
+ {
2
+ "name": "@cjser/globby",
3
+ "version": "16.2.0-cjser.2",
4
+ "description": "User-friendly glob matching",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/sponsors/sindresorhus",
11
+ "author": {
12
+ "email": "sindresorhus@gmail.com",
13
+ "name": "Sindre Sorhus",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "types": "./index.d.ts",
19
+ "require": "./dist-cjser/index.cjs",
20
+ "default": "./index.js"
21
+ },
22
+ "sideEffects": false,
23
+ "engines": {
24
+ "node": ">=20"
25
+ },
26
+ "scripts": {
27
+ "bench": "npm update @globby/main-branch glob-stream fast-glob && node bench.js",
28
+ "test": "xo && ava && tsd"
29
+ },
30
+ "files": [
31
+ "index.js",
32
+ "index.d.ts",
33
+ "ignore.js",
34
+ "utilities.js",
35
+ "dist-cjser"
36
+ ],
37
+ "keywords": [
38
+ "all",
39
+ "array",
40
+ "directories",
41
+ "expand",
42
+ "files",
43
+ "filesystem",
44
+ "filter",
45
+ "find",
46
+ "fnmatch",
47
+ "folders",
48
+ "fs",
49
+ "glob",
50
+ "globbing",
51
+ "globs",
52
+ "gulpfriendly",
53
+ "match",
54
+ "matcher",
55
+ "minimatch",
56
+ "multi",
57
+ "multiple",
58
+ "paths",
59
+ "pattern",
60
+ "patterns",
61
+ "traverse",
62
+ "util",
63
+ "utility",
64
+ "wildcard",
65
+ "wildcards",
66
+ "promise",
67
+ "gitignore",
68
+ "git"
69
+ ],
70
+ "dependencies": {
71
+ "fast-glob": "^3.3.3",
72
+ "ignore": "^7.0.5",
73
+ "@cjser/sindresorhus__merge-streams": "4.0.0-cjser.2",
74
+ "@cjser/is-path-inside": "4.0.0-cjser.2",
75
+ "@cjser/slash": "5.1.0-cjser.2",
76
+ "@cjser/unicorn-magic": "0.4.0-cjser.2"
77
+ },
78
+ "devDependencies": {
79
+ "@globby/main-branch": "sindresorhus/globby#main",
80
+ "@types/node": "^24.5.2",
81
+ "ava": "^6.4.1",
82
+ "benchmark": "2.1.4",
83
+ "glob-stream": "^8.0.3",
84
+ "tempy": "^3.1.0",
85
+ "tsd": "^0.33.0",
86
+ "xo": "^1.2.2"
87
+ },
88
+ "xo": {
89
+ "ignores": [
90
+ "fixtures"
91
+ ]
92
+ },
93
+ "ava": {
94
+ "files": [
95
+ "!tests/utilities.js"
96
+ ],
97
+ "workerThreads": false
98
+ },
99
+ "types": "./index.d.ts",
100
+ "main": "./dist-cjser/index.cjs",
101
+ "cjser": {
102
+ "sourceVersion": "16.2.0",
103
+ "cjserVersion": 2,
104
+ "original": {
105
+ "name": "globby",
106
+ "version": "16.2.0",
107
+ "exports": {
108
+ "types": "./index.d.ts",
109
+ "default": "./index.js"
110
+ },
111
+ "repository": "sindresorhus/globby",
112
+ "dependencies": {
113
+ "@sindresorhus/merge-streams": "^4.0.0",
114
+ "fast-glob": "^3.3.3",
115
+ "ignore": "^7.0.5",
116
+ "is-path-inside": "^4.0.0",
117
+ "slash": "^5.1.0",
118
+ "unicorn-magic": "^0.4.0"
119
+ },
120
+ "files": [
121
+ "index.js",
122
+ "index.d.ts",
123
+ "ignore.js",
124
+ "utilities.js"
125
+ ],
126
+ "scripts": {
127
+ "bench": "npm update @globby/main-branch glob-stream fast-glob && node bench.js",
128
+ "test": "xo && ava && tsd"
129
+ }
130
+ }
131
+ }
132
+ }
package/readme.md ADDED
@@ -0,0 +1,406 @@
1
+ # globby
2
+
3
+ > User-friendly glob matching
4
+
5
+ Based on [`fast-glob`](https://github.com/mrmlnc/fast-glob) but adds a bunch of useful features.
6
+
7
+ ## Features
8
+
9
+ - Promise API
10
+ - Multiple patterns
11
+ - Negated patterns: `['foo*', '!foobar']`
12
+ - Negation-only patterns: `['!foobar']` → matches all files except `foobar`
13
+ - Expands directories: `foo` → `foo/**/*`
14
+ - Supports `.gitignore` and similar ignore config files
15
+ - Supports `URL` as `cwd`
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ npm install globby
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ ├── unicorn
27
+ ├── cake
28
+ └── rainbow
29
+ ```
30
+
31
+ ```js
32
+ import {globby} from 'globby';
33
+
34
+ const paths = await globby(['*', '!cake']);
35
+
36
+ console.log(paths);
37
+ //=> ['unicorn', 'rainbow']
38
+ ```
39
+
40
+ ## API
41
+
42
+ Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.
43
+
44
+ **Windows:** Patterns with backslashes will silently fail. Use `path.posix.join()` or [`convertPathToPattern()`](#convertpathtopatternpath).
45
+
46
+ ### globby(patterns, options?)
47
+
48
+ Returns a `Promise<string[]>` of matching paths.
49
+
50
+ #### patterns
51
+
52
+ Type: `string | string[]`
53
+
54
+ See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage).
55
+
56
+ #### options
57
+
58
+ Type: `object`
59
+
60
+ See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones below.
61
+
62
+ ##### expandDirectories
63
+
64
+ Type: `boolean | string[] | object`\
65
+ Default: `true`
66
+
67
+ If set to `true`, `globby` will automatically glob directories for you. If you define an `Array` it will only glob files that matches the patterns inside the `Array`. You can also define an `object` with `files` and `extensions` like below:
68
+
69
+ ```js
70
+ import {globby} from 'globby';
71
+
72
+ const paths = await globby('images', {
73
+ expandDirectories: {
74
+ files: ['cat', 'unicorn', '*.jpg'],
75
+ extensions: ['png']
76
+ }
77
+ });
78
+
79
+ console.log(paths);
80
+ //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']
81
+ ```
82
+
83
+ Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`.
84
+
85
+ ##### gitignore
86
+
87
+ Type: `boolean`\
88
+ Default: `false`
89
+
90
+ Respect ignore patterns in `.gitignore` files that apply to the globbed files.
91
+
92
+ When enabled, globby searches for `.gitignore` files from the current working directory downward, and if a Git repository is detected (by finding a `.git` directory), it also respects `.gitignore` files in parent directories up to the repository root. This matches Git's actual behavior where patterns from parent `.gitignore` files apply to subdirectories.
93
+
94
+ Gitignore patterns take priority over user patterns, matching Git's behavior. To include gitignored files, set this to `false`.
95
+
96
+ **Performance:** Globby reads `.gitignore` files before globbing. When there are no negation patterns (like `!important.log`) and no parent `.gitignore` files are found, it passes ignore patterns to fast-glob to skip traversing ignored directories entirely, which significantly improves performance for large `node_modules` or build directories. When negation patterns or parent `.gitignore` files are present, all filtering is done after traversal to ensure correct Git-compatible behavior. For optimal performance, prefer specific `.gitignore` patterns without negations, or use `ignoreFiles: '.gitignore'` to target only the root ignore file.
97
+
98
+ ##### globalGitignore
99
+
100
+ Type: `boolean`\
101
+ Default: `false`
102
+
103
+ Respect ignore patterns in the global gitignore file configured via `git config core.excludesfile`.
104
+
105
+ Values from `[include]` and `gitdir` or `gitdir/i` `[includeIf]` sections inside those user-level config files are also respected.
106
+
107
+ Patterns in the global gitignore are treated as root-level patterns, matching Git's own behavior.
108
+
109
+ This option only reads the user-level Git config (`GIT_CONFIG_GLOBAL`, `$XDG_CONFIG_HOME/git/config`, and `~/.gitconfig`). When `core.excludesfile` is unset, it falls back to Git's default user-level ignore file at `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore`. Repository `.git/config` and system config are intentionally not consulted. Other `includeIf` predicates such as `onbranch:` are intentionally not supported.
110
+
111
+ ##### ignoreFiles
112
+
113
+ Type: `string | string[]`\
114
+ Default: `undefined`
115
+
116
+ Glob patterns to look for ignore files, which are then used to ignore globbed files.
117
+
118
+ This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files.
119
+
120
+ **Performance tip:** Using a specific path like `'.gitignore'` is much faster than recursive patterns.
121
+
122
+ ##### expandNegationOnlyPatterns
123
+
124
+ Type: `boolean`\
125
+ Default: `true`
126
+
127
+ When only negation patterns are provided (e.g., `['!*.json']`), automatically prepend a catch-all pattern (`**/*`) to match all files before applying negations.
128
+
129
+ Set to `false` to return an empty array when only negation patterns are provided. This can be useful when patterns are user-controlled, to avoid unexpectedly matching all files.
130
+
131
+ ```js
132
+ import {globby} from 'globby';
133
+
134
+ // Default behavior: matches all files except .json
135
+ await globby(['!*.json']);
136
+ //=> ['file.txt', 'image.png', ...]
137
+
138
+ // Disable expansion: returns empty array
139
+ await globby(['!*.json'], {expandNegationOnlyPatterns: false});
140
+ //=> []
141
+ ```
142
+
143
+ ##### fs
144
+
145
+ Type: [`FileSystemAdapter`](https://github.com/mrmlnc/fast-glob#fs)\
146
+ Default: `undefined`
147
+
148
+ Custom file system implementation (useful for testing or virtual file systems).
149
+
150
+ **Note:** When using `gitignore`, `ignoreFiles`, or `globalGitignore`, the custom fs must also provide `readFile`/`readFileSync` methods. With `globalGitignore`, `globby()` and `globbyStream()` also require `fs.promises.stat` or `fs.stat`, and `globbySync()` requires `fs.statSync`.
151
+
152
+ ### globbySync(patterns, options?)
153
+
154
+ Returns `string[]` of matching paths.
155
+
156
+ ### globbyStream(patterns, options?)
157
+
158
+ Returns a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) of matching paths.
159
+
160
+ For example, loop over glob matches in a [`for await...of` loop](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) like this:
161
+
162
+ ```js
163
+ import {globbyStream} from 'globby';
164
+
165
+ for await (const path of globbyStream('*.tmp')) {
166
+ console.log(path);
167
+ }
168
+ ```
169
+
170
+ ### convertPathToPattern(path)
171
+
172
+ Converts a path to a pattern by escaping special glob characters like `()`, `[]`, `{}`. On Windows, also converts backslashes to forward slashes.
173
+
174
+ Use this when your literal paths contain characters with special meaning in globs.
175
+
176
+ ```js
177
+ import {globby, convertPathToPattern} from 'globby';
178
+
179
+ // ❌ Fails - parentheses are glob syntax
180
+ await globby('C:/Program Files (x86)/*.txt');
181
+ //=> []
182
+
183
+ // ✅ Works
184
+ const base = convertPathToPattern('C:/Program Files (x86)');
185
+ await globby(`${base}/*.txt`);
186
+ //=> ['C:/Program Files (x86)/file.txt']
187
+ ```
188
+
189
+ [Learn more.](https://github.com/mrmlnc/fast-glob#convertpathtopatternpath)
190
+
191
+ ### generateGlobTasks(patterns, options?)
192
+
193
+ Returns an `Promise<object[]>` in the format `{patterns: string[], options: Object}`, which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages.
194
+
195
+ Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration.
196
+
197
+ ### generateGlobTasksSync(patterns, options?)
198
+
199
+ Returns an `object[]` in the format `{patterns: string[], options: Object}`, which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages.
200
+
201
+ Takes the same arguments as `generateGlobTasks`.
202
+
203
+ ### isDynamicPattern(patterns, options?)
204
+
205
+ Returns a `boolean` of whether there are any special glob characters in the `patterns`.
206
+
207
+ Note that the options affect the results.
208
+
209
+ This function is backed by [`fast-glob`](https://github.com/mrmlnc/fast-glob#isdynamicpatternpattern-options).
210
+
211
+ ### isGitIgnored(options?)
212
+
213
+ Returns a `Promise<(path: URL | string) => boolean>` indicating whether a given path is ignored via a `.gitignore` file.
214
+
215
+ #### options
216
+
217
+ Type: `object`
218
+
219
+ ##### cwd
220
+
221
+ Type: `URL | string`\
222
+ Default: `process.cwd()`
223
+
224
+ The current working directory in which to search.
225
+
226
+ ##### suppressErrors
227
+
228
+ Type: `boolean`\
229
+ Default: `false`
230
+
231
+ Suppress errors when encountering directories or files without read permissions.
232
+
233
+ ##### deep
234
+
235
+ Type: `number`\
236
+ Default: `Infinity`
237
+
238
+ Maximum depth to search for `.gitignore` files.
239
+
240
+ - `0` - Only search in the start directory
241
+ - `1` - Search in the start directory and one level of subdirectories
242
+ - `2` - Search in the start directory and two levels of subdirectories
243
+
244
+ ##### ignore
245
+
246
+ Type: `string | string[]`\
247
+ Default: `[]`
248
+
249
+ Glob patterns to exclude from `.gitignore` file search.
250
+
251
+ ##### followSymbolicLinks
252
+
253
+ Type: `boolean`\
254
+ Default: `true`
255
+
256
+ Indicates whether to traverse descendants of symbolic link directories.
257
+
258
+ ##### concurrency
259
+
260
+ Type: `number`\
261
+ Default: `os.cpus().length`
262
+
263
+ Specifies the maximum number of concurrent requests from a reader to read directories.
264
+
265
+ ##### throwErrorOnBrokenSymbolicLink
266
+
267
+ Type: `boolean`\
268
+ Default: `false`
269
+
270
+ Throw an error when symbolic link is broken if `true` or safely return `lstat` call if `false`.
271
+
272
+ ##### fs
273
+
274
+ Type: [`FileSystemAdapter`](https://github.com/mrmlnc/fast-glob#fs)\
275
+ Default: `undefined`
276
+
277
+ Custom file system implementation (useful for testing or virtual file systems).
278
+
279
+ **Note:** The custom fs must provide `readFile`/`readFileSync` methods for reading `.gitignore` files.
280
+
281
+ ```js
282
+ import {isGitIgnored} from 'globby';
283
+
284
+ const isIgnored = await isGitIgnored();
285
+
286
+ console.log(isIgnored('some/file'));
287
+ ```
288
+
289
+ ```js
290
+ // Suppress errors when encountering unreadable directories
291
+ const isIgnored = await isGitIgnored({suppressErrors: true});
292
+ ```
293
+
294
+ ```js
295
+ // Limit search depth and exclude certain directories
296
+ const isIgnored = await isGitIgnored({
297
+ deep: 2,
298
+ ignore: ['**/node_modules/**', '**/dist/**']
299
+ });
300
+ ```
301
+
302
+ ### isGitIgnoredSync(options?)
303
+
304
+ Returns a `(path: URL | string) => boolean` indicating whether a given path is ignored via a `.gitignore` file.
305
+
306
+ See [`isGitIgnored`](#isgitignoredoptions) for options.
307
+
308
+
309
+ ### isIgnoredByIgnoreFiles(patterns, options?)
310
+
311
+ Returns a `Promise<(path: URL | string) => boolean>` indicating whether a given path is ignored via the ignore files.
312
+
313
+ This is a more generic form of the `isGitIgnored` function, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files.
314
+
315
+ #### patterns
316
+
317
+ Type: `string | string[]`
318
+
319
+ Glob patterns to look for ignore files.
320
+
321
+ #### options
322
+
323
+ Type: `object`
324
+
325
+ See [`isGitIgnored` options](#isgitignoredoptions) for all available options.
326
+
327
+ ```js
328
+ import {isIgnoredByIgnoreFiles} from 'globby';
329
+
330
+ const isIgnored = await isIgnoredByIgnoreFiles("**/.gitignore");
331
+
332
+ console.log(isIgnored('some/file'));
333
+ ```
334
+
335
+ ```js
336
+ // Suppress errors when encountering unreadable directories
337
+ const isIgnored = await isIgnoredByIgnoreFiles("**/.eslintignore", {suppressErrors: true});
338
+ ```
339
+
340
+ ```js
341
+ // Limit search depth and concurrency
342
+ const isIgnored = await isIgnoredByIgnoreFiles("**/.prettierignore", {
343
+ deep: 3,
344
+ concurrency: 4
345
+ });
346
+ ```
347
+
348
+ ### isIgnoredByIgnoreFilesSync(patterns, options?)
349
+
350
+ Returns a `(path: URL | string) => boolean` indicating whether a given path is ignored via the ignore files.
351
+
352
+ This is a more generic form of the `isGitIgnoredSync` function, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files.
353
+
354
+ See [`isIgnoredByIgnoreFiles`](#isignoredbyignorefilespatterns-options) for patterns and options.
355
+
356
+ ```js
357
+ import {isIgnoredByIgnoreFilesSync} from 'globby';
358
+
359
+ const isIgnored = isIgnoredByIgnoreFilesSync("**/.gitignore");
360
+
361
+ console.log(isIgnored('some/file'));
362
+ ```
363
+
364
+ ## Globbing patterns
365
+
366
+ Just a quick overview.
367
+
368
+ - `*` matches any number of characters, but not `/`
369
+ - `?` matches a single character, but not `/`
370
+ - `**` matches any number of characters, including `/`, as long as it's the only thing in a path part
371
+ - `{}` allows for a comma-separated list of "or" expressions
372
+ - `!` at the beginning of a pattern will negate the match
373
+
374
+ ### Negation patterns
375
+
376
+ Globby supports negation patterns to exclude files. There are two ways to use them:
377
+
378
+ **With positive patterns:**
379
+ ```js
380
+ await globby(['src/**/*.js', '!src/**/*.test.js']);
381
+ // Matches all .js files except test files
382
+ ```
383
+
384
+ **Negation-only patterns:**
385
+ ```js
386
+ await globby(['!*.json', '!*.xml'], {cwd: 'config'});
387
+ // Matches all files in config/ except .json and .xml files
388
+ ```
389
+
390
+ When using only negation patterns, globby implicitly prepends `**/*` to match all files, then applies the negations. This means `['!*.json', '!*.xml']` is equivalent to `['**/*', '!*.json', '!*.xml']`.
391
+
392
+ **Note:** The prepended `**/*` pattern respects the `dot` option. By default, dotfiles (files starting with `.`) are not matched unless you set `dot: true`.
393
+
394
+ [Various patterns and expected matches.](https://github.com/sindresorhus/multimatch/blob/main/test/test.js)
395
+
396
+ ## Related
397
+
398
+ - [multimatch](https://github.com/sindresorhus/multimatch) - Match against a list instead of the filesystem
399
+ - [matcher](https://github.com/sindresorhus/matcher) - Simple wildcard matching
400
+ - [del](https://github.com/sindresorhus/del) - Delete files and directories
401
+ - [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed
402
+
403
+ ## cjser
404
+
405
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
406
+ Original repository: https://github.com/sindresorhus/globby