pax_global_header00006660000000000000000000000064137753266220014527gustar00rootroot0000000000000052 comment=4bb7f4a3ffb1a4ef23c86fbf70261110513e1fcc globby-11.0.2/000077500000000000000000000000001377532662200130665ustar00rootroot00000000000000globby-11.0.2/.editorconfig000066400000000000000000000002571377532662200155470ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 globby-11.0.2/.gitattributes000066400000000000000000000000231377532662200157540ustar00rootroot00000000000000* text=auto eol=lf globby-11.0.2/.github/000077500000000000000000000000001377532662200144265ustar00rootroot00000000000000globby-11.0.2/.github/funding.yml000066400000000000000000000001601377532662200166000ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/globby custom: https://sindresorhus.com/donate globby-11.0.2/.github/security.md000066400000000000000000000002631377532662200166200ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. globby-11.0.2/.github/workflows/000077500000000000000000000000001377532662200164635ustar00rootroot00000000000000globby-11.0.2/.github/workflows/main.yml000066400000000000000000000010451377532662200201320ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: node-version: - 14 - 12 - 10 os: - ubuntu-latest - macos-latest - windows-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test globby-11.0.2/.gitignore000066400000000000000000000000471377532662200150570ustar00rootroot00000000000000node_modules yarn.lock bench *.tmp tmp globby-11.0.2/.npmrc000066400000000000000000000000231377532662200142010ustar00rootroot00000000000000package-lock=false globby-11.0.2/bench.js000066400000000000000000000035421377532662200145070ustar00rootroot00000000000000'use strict'; /* global after, before, bench, suite */ const fs = require('fs'); const rimraf = require('rimraf'); const globbyMaster = require('globby'); const gs = require('glob-stream'); const fastGlob = require('fast-glob'); const globby = require('.'); const BENCH_DIR = 'bench'; const runners = [{ name: 'globby async (working directory)', run: async (patterns, callback) => { await globby(patterns); callback(); } }, { name: 'globby async (upstream/master)', run: async (patterns, callback) => { await globbyMaster(patterns); callback(); } }, { name: 'globby sync (working directory)', run: patterns => { globby.sync(patterns); } }, { name: 'globby sync (upstream/master)', run: patterns => { globbyMaster.sync(patterns); } }, { name: 'glob-stream', run: (patterns, cb) => { gs(patterns).on('data', () => {}).on('end', cb); } }, { name: 'fast-glob async', run: async (patterns, callback) => { await fastGlob(patterns); callback(); } }, { name: 'fast-glob sync', run: patterns => { fastGlob.sync(patterns); } }]; const benchs = [{ name: 'negative globs (some files inside dir)', patterns: [ 'a/*', '!a/c*' ] }, { name: 'negative globs (whole dir)', patterns: [ 'a/*', '!a/**' ] }, { name: 'multiple positive globs', patterns: [ 'a/*', 'b/*' ] }]; before(() => { process.chdir(__dirname); rimraf.sync(BENCH_DIR); fs.mkdirSync(BENCH_DIR); process.chdir(BENCH_DIR); ['a', 'b'] .map(directory => `${directory}/`) .forEach(directory => { fs.mkdirSync(directory); for (let i = 0; i < 500; i++) { fs.writeFileSync(directory + (i < 100 ? 'c' : 'd') + i, ''); } }); }); after(() => { process.chdir(__dirname); rimraf.sync(BENCH_DIR); }); benchs.forEach(benchmark => { suite(benchmark.name, () => { runners.forEach(runner => bench(runner.name, runner.run.bind(null, benchmark.patterns))); }); }); globby-11.0.2/fixtures/000077500000000000000000000000001377532662200147375ustar00rootroot00000000000000globby-11.0.2/fixtures/gitignore/000077500000000000000000000000001377532662200167265ustar00rootroot00000000000000globby-11.0.2/fixtures/gitignore/.gitignore000066400000000000000000000000171377532662200207140ustar00rootroot00000000000000foo.js !bar.js globby-11.0.2/fixtures/gitignore/bar.js000066400000000000000000000001361377532662200200300ustar00rootroot00000000000000import test from 'ava'; import fn from '..'; test(t => { t.is(fn('foo'), fn('foobar')); }); globby-11.0.2/fixtures/multiple-negation/000077500000000000000000000000001377532662200203745ustar00rootroot00000000000000globby-11.0.2/fixtures/multiple-negation/!!unicorn.js000066400000000000000000000000001377532662200224770ustar00rootroot00000000000000globby-11.0.2/fixtures/multiple-negation/!unicorn.js000066400000000000000000000000001377532662200224360ustar00rootroot00000000000000globby-11.0.2/fixtures/multiple-negation/.gitignore000066400000000000000000000000401377532662200223560ustar00rootroot00000000000000*.js !!unicorn.js !!!unicorn.js globby-11.0.2/fixtures/negative/000077500000000000000000000000001377532662200165415ustar00rootroot00000000000000globby-11.0.2/fixtures/negative/.gitignore000066400000000000000000000000151377532662200205250ustar00rootroot00000000000000*.js !foo.js globby-11.0.2/fixtures/negative/foo.js000066400000000000000000000000351377532662200176600ustar00rootroot00000000000000console.log('no semicolon'); globby-11.0.2/gitignore.js000066400000000000000000000050511377532662200154140ustar00rootroot00000000000000'use strict'; const {promisify} = require('util'); const fs = require('fs'); const path = require('path'); const fastGlob = require('fast-glob'); const gitIgnore = require('ignore'); const slash = require('slash'); const DEFAULT_IGNORE = [ '**/node_modules/**', '**/flow-typed/**', '**/coverage/**', '**/.git' ]; const readFileP = promisify(fs.readFile); const mapGitIgnorePatternTo = base => ignore => { if (ignore.startsWith('!')) { return '!' + path.posix.join(base, ignore.slice(1)); } return path.posix.join(base, ignore); }; const parseGitIgnore = (content, options) => { const base = slash(path.relative(options.cwd, path.dirname(options.fileName))); return content .split(/\r?\n/) .filter(Boolean) .filter(line => !line.startsWith('#')) .map(mapGitIgnorePatternTo(base)); }; const reduceIgnore = files => { const ignores = gitIgnore(); for (const file of files) { ignores.add(parseGitIgnore(file.content, { cwd: file.cwd, fileName: file.filePath })); } return ignores; }; const ensureAbsolutePathForCwd = (cwd, p) => { cwd = slash(cwd); if (path.isAbsolute(p)) { if (p.startsWith(cwd)) { return p; } throw new Error(`Path ${p} is not in cwd ${cwd}`); } return path.join(cwd, p); }; const getIsIgnoredPredecate = (ignores, cwd) => { return p => ignores.ignores(slash(path.relative(cwd, ensureAbsolutePathForCwd(cwd, p.path || p)))); }; const getFile = async (file, cwd) => { const filePath = path.join(cwd, file); const content = await readFileP(filePath, 'utf8'); return { cwd, filePath, content }; }; const getFileSync = (file, cwd) => { const filePath = path.join(cwd, file); const content = fs.readFileSync(filePath, 'utf8'); return { cwd, filePath, content }; }; const normalizeOptions = ({ ignore = [], cwd = slash(process.cwd()) } = {}) => { return {ignore, cwd}; }; module.exports = async options => { options = normalizeOptions(options); const paths = await fastGlob('**/.gitignore', { ignore: DEFAULT_IGNORE.concat(options.ignore), cwd: options.cwd }); const files = await Promise.all(paths.map(file => getFile(file, options.cwd))); const ignores = reduceIgnore(files); return getIsIgnoredPredecate(ignores, options.cwd); }; module.exports.sync = options => { options = normalizeOptions(options); const paths = fastGlob.sync('**/.gitignore', { ignore: DEFAULT_IGNORE.concat(options.ignore), cwd: options.cwd }); const files = paths.map(file => getFileSync(file, options.cwd)); const ignores = reduceIgnore(files); return getIsIgnoredPredecate(ignores, options.cwd); }; globby-11.0.2/gitignore.test.js000066400000000000000000000054251377532662200163770ustar00rootroot00000000000000const path = require('path'); const test = require('ava'); const slash = require('slash'); const gitignore = require('./gitignore'); test('gitignore', async t => { const cwd = path.join(__dirname, 'fixtures/gitignore'); const isIgnored = await gitignore({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 gitignore({cwd}); t.true(isIgnored(slash(path.resolve(cwd, 'foo.js')))); }); test('gitignore - sync', t => { const cwd = path.join(__dirname, 'fixtures/gitignore'); const isIgnored = gitignore.sync({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 gitignore({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 = gitignore.sync({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 gitignore({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 = gitignore.sync({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 gitignore({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 = gitignore.sync({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); }); globby-11.0.2/index.d.ts000066400000000000000000000132221377532662200147670ustar00rootroot00000000000000import {Options as FastGlobOptions} from 'fast-glob'; declare namespace globby { type ExpandDirectoriesOption = | boolean | readonly string[] | {files?: readonly string[]; extensions?: readonly string[]}; interface GlobbyOptions extends FastGlobOptions { /** 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 in the example below. Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`. @default true @example ``` import globby = require('globby'); (async () => { const paths = await globby('images', { expandDirectories: { files: ['cat', 'unicorn', '*.jpg'], extensions: ['png'] } }); console.log(paths); //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg'] })(); ``` */ readonly expandDirectories?: ExpandDirectoriesOption; /** Respect ignore patterns in `.gitignore` files that apply to the globbed files. @default false */ readonly gitignore?: boolean; } interface GlobTask { readonly pattern: string; readonly options: GlobbyOptions; } interface GitignoreOptions { readonly cwd?: string; readonly ignore?: readonly string[]; } type FilterFunction = (path: string) => boolean; } interface Gitignore { /** @returns A filter function indicating whether a given path is ignored via a `.gitignore` file. */ sync: (options?: globby.GitignoreOptions) => globby.FilterFunction; /** `.gitignore` files matched by the ignore config are not used for the resulting filter function. @returns A filter function indicating whether a given path is ignored via a `.gitignore` file. @example ``` import {gitignore} from 'globby'; (async () => { const isIgnored = await gitignore(); console.log(isIgnored('some/file')); })(); ``` */ (options?: globby.GitignoreOptions): Promise; } declare const globby: { /** Find files and directories using glob patterns. 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()`. @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package. @returns The matching paths. */ sync: ( patterns: string | readonly string[], options?: globby.GlobbyOptions ) => string[]; /** Find files and directories using glob patterns. 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()`. @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package. @returns The stream of matching paths. @example ``` import globby = require('globby'); (async () => { for await (const path of globby.stream('*.tmp')) { console.log(path); } })(); ``` */ stream: ( patterns: string | readonly string[], options?: globby.GlobbyOptions ) => NodeJS.ReadableStream; /** 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. @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package. @returns An object in the format `{pattern: 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. */ generateGlobTasks: ( patterns: string | readonly string[], options?: globby.GlobbyOptions ) => globby.GlobTask[]; /** Note that the options affect the results. This function is backed by [`fast-glob`](https://github.com/mrmlnc/fast-glob#isdynamicpatternpattern-options). @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3). @returns Whether there are any special glob characters in the `patterns`. */ hasMagic: ( patterns: string | readonly string[], options?: FastGlobOptions ) => boolean; readonly gitignore: Gitignore; /** Find files and directories using glob patterns. 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()`. @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns). @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package. @returns The matching paths. @example ``` import globby = require('globby'); (async () => { const paths = await globby(['*', '!cake']); console.log(paths); //=> ['unicorn', 'rainbow'] })(); ``` */ ( patterns: string | readonly string[], options?: globby.GlobbyOptions ): Promise; }; export = globby; globby-11.0.2/index.js000066400000000000000000000105711377532662200145370ustar00rootroot00000000000000'use strict'; const fs = require('fs'); const arrayUnion = require('array-union'); const merge2 = require('merge2'); const fastGlob = require('fast-glob'); const dirGlob = require('dir-glob'); const gitignore = require('./gitignore'); const {FilterStream, UniqueStream} = require('./stream-utils'); const DEFAULT_FILTER = () => false; const isNegative = pattern => pattern[0] === '!'; const assertPatternsInput = patterns => { if (!patterns.every(pattern => typeof pattern === 'string')) { throw new TypeError('Patterns must be a string or an array of strings'); } }; const checkCwdOption = (options = {}) => { if (!options.cwd) { return; } let stat; try { stat = fs.statSync(options.cwd); } catch { return; } if (!stat.isDirectory()) { throw new Error('The `cwd` option must be a path to a directory'); } }; const getPathString = p => p.stats instanceof fs.Stats ? p.path : p; const generateGlobTasks = (patterns, taskOptions) => { patterns = arrayUnion([].concat(patterns)); assertPatternsInput(patterns); checkCwdOption(taskOptions); const globTasks = []; taskOptions = { ignore: [], expandDirectories: true, ...taskOptions }; for (const [index, pattern] of patterns.entries()) { if (isNegative(pattern)) { continue; } const ignore = patterns .slice(index) .filter(pattern => isNegative(pattern)) .map(pattern => pattern.slice(1)); const options = { ...taskOptions, ignore: taskOptions.ignore.concat(ignore) }; globTasks.push({pattern, options}); } return globTasks; }; const globDirs = (task, fn) => { let options = {}; if (task.options.cwd) { options.cwd = task.options.cwd; } if (Array.isArray(task.options.expandDirectories)) { options = { ...options, files: task.options.expandDirectories }; } else if (typeof task.options.expandDirectories === 'object') { options = { ...options, ...task.options.expandDirectories }; } return fn(task.pattern, options); }; const getPattern = (task, fn) => task.options.expandDirectories ? globDirs(task, fn) : [task.pattern]; const getFilterSync = options => { return options && options.gitignore ? gitignore.sync({cwd: options.cwd, ignore: options.ignore}) : DEFAULT_FILTER; }; const globToTask = task => glob => { const {options} = task; if (options.ignore && Array.isArray(options.ignore) && options.expandDirectories) { options.ignore = dirGlob.sync(options.ignore); } return { pattern: glob, options }; }; module.exports = async (patterns, options) => { const globTasks = generateGlobTasks(patterns, options); const getFilter = async () => { return options && options.gitignore ? gitignore({cwd: options.cwd, ignore: options.ignore}) : DEFAULT_FILTER; }; const getTasks = async () => { const tasks = await Promise.all(globTasks.map(async task => { const globs = await getPattern(task, dirGlob); return Promise.all(globs.map(globToTask(task))); })); return arrayUnion(...tasks); }; const [filter, tasks] = await Promise.all([getFilter(), getTasks()]); const paths = await Promise.all(tasks.map(task => fastGlob(task.pattern, task.options))); return arrayUnion(...paths).filter(path_ => !filter(getPathString(path_))); }; module.exports.sync = (patterns, options) => { const globTasks = generateGlobTasks(patterns, options); const tasks = []; for (const task of globTasks) { const newTask = getPattern(task, dirGlob.sync).map(globToTask(task)); tasks.push(...newTask); } const filter = getFilterSync(options); let matches = []; for (const task of tasks) { matches = arrayUnion(matches, fastGlob.sync(task.pattern, task.options)); } return matches.filter(path_ => !filter(path_)); }; module.exports.stream = (patterns, options) => { const globTasks = generateGlobTasks(patterns, options); const tasks = []; for (const task of globTasks) { const newTask = getPattern(task, dirGlob.sync).map(globToTask(task)); tasks.push(...newTask); } const filter = getFilterSync(options); const filterStream = new FilterStream(p => !filter(p)); const uniqueStream = new UniqueStream(); return merge2(tasks.map(task => fastGlob.stream(task.pattern, task.options))) .pipe(filterStream) .pipe(uniqueStream); }; module.exports.generateGlobTasks = generateGlobTasks; module.exports.hasMagic = (patterns, options) => [] .concat(patterns) .some(pattern => fastGlob.isDynamicPattern(pattern, options)); module.exports.gitignore = gitignore; globby-11.0.2/index.test-d.ts000066400000000000000000000066061377532662200157540ustar00rootroot00000000000000import {expectType} from 'tsd'; import globby = require('.'); import { GlobTask, FilterFunction, sync as globbySync, stream as globbyStream, generateGlobTasks, hasMagic, gitignore } from '.'; // Globby expectType>(globby('*.tmp')); expectType>(globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp'])); expectType>(globby('*.tmp', {expandDirectories: false})); expectType>( globby('*.tmp', {expandDirectories: ['a*', 'b*']}) ); expectType>( globby('*.tmp', { expandDirectories: { files: ['a', 'b'], extensions: ['tmp'] } }) ); expectType>(globby('*.tmp', {gitignore: true})); expectType>(globby('*.tmp', {ignore: ['**/b.tmp']})); // Globby (sync) expectType(globbySync('*.tmp')); expectType(globbySync(['a.tmp', '*.tmp', '!{c,d,e}.tmp'])); expectType(globbySync('*.tmp', {expandDirectories: false})); expectType(globbySync('*.tmp', {expandDirectories: ['a*', 'b*']})); expectType( globbySync('*.tmp', { expandDirectories: { files: ['a', 'b'], extensions: ['tmp'] } }) ); expectType(globbySync('*.tmp', {gitignore: true})); expectType(globbySync('*.tmp', {ignore: ['**/b.tmp']})); // Globby (stream) expectType(globbyStream('*.tmp')); expectType(globbyStream(['a.tmp', '*.tmp', '!{c,d,e}.tmp'])); expectType(globbyStream('*.tmp', {expandDirectories: false})); expectType(globbyStream('*.tmp', {expandDirectories: ['a*', 'b*']})); expectType( globbyStream('*.tmp', { expandDirectories: { files: ['a', 'b'], extensions: ['tmp'] } }) ); expectType(globbyStream('*.tmp', {gitignore: true})); expectType(globbyStream('*.tmp', {ignore: ['**/b.tmp']})); (async () => { const streamResult = []; for await (const path of globbyStream('*.tmp')) { streamResult.push(path); } // `NodeJS.ReadableStream` is not generic, unfortunately, // so it seems `(string | Buffer)[]` is the best we can get here expectType>(streamResult); })(); // GenerateGlobTasks expectType(generateGlobTasks('*.tmp')); expectType(generateGlobTasks(['a.tmp', '*.tmp', '!{c,d,e}.tmp'])); expectType(generateGlobTasks('*.tmp', {expandDirectories: false})); expectType( generateGlobTasks('*.tmp', {expandDirectories: ['a*', 'b*']}) ); expectType( generateGlobTasks('*.tmp', { expandDirectories: { files: ['a', 'b'], extensions: ['tmp'] } }) ); expectType(generateGlobTasks('*.tmp', {gitignore: true})); expectType(generateGlobTasks('*.tmp', {ignore: ['**/b.tmp']})); // HasMagic expectType(hasMagic('**')); expectType(hasMagic(['**', 'path1', 'path2'])); expectType(hasMagic(['**', 'path1', 'path2'], {extglob: false})); // Gitignore expectType>(gitignore()); expectType>( gitignore({ cwd: __dirname }) ); expectType>( gitignore({ ignore: ['**/b.tmp'] }) ); // Gitignore (sync) expectType(gitignore.sync()); expectType( gitignore.sync({ cwd: __dirname }) ); expectType( gitignore.sync({ ignore: ['**/b.tmp'] }) ); globby-11.0.2/license000066400000000000000000000021251377532662200144330ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. globby-11.0.2/package.json000066400000000000000000000025611377532662200153600ustar00rootroot00000000000000{ "name": "globby", "version": "11.0.2", "description": "User-friendly glob matching", "license": "MIT", "repository": "sindresorhus/globby", "funding": "https://github.com/sponsors/sindresorhus", "author": { "email": "sindresorhus@gmail.com", "name": "Sindre Sorhus", "url": "https://sindresorhus.com" }, "engines": { "node": ">=10" }, "scripts": { "bench": "npm update glob-stream fast-glob && matcha bench.js", "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts", "gitignore.js", "stream-utils.js" ], "keywords": [ "all", "array", "directories", "expand", "files", "filesystem", "filter", "find", "fnmatch", "folders", "fs", "glob", "globbing", "globs", "gulpfriendly", "match", "matcher", "minimatch", "multi", "multiple", "paths", "pattern", "patterns", "traverse", "util", "utility", "wildcard", "wildcards", "promise", "gitignore", "git" ], "dependencies": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", "fast-glob": "^3.1.1", "ignore": "^5.1.4", "merge2": "^1.3.0", "slash": "^3.0.0" }, "devDependencies": { "ava": "^3.13.0", "get-stream": "^6.0.0", "glob-stream": "^6.1.0", "globby": "sindresorhus/globby#master", "matcha": "^0.7.0", "rimraf": "^3.0.2", "tsd": "^0.13.1", "xo": "^0.33.1" }, "xo": { "ignores": [ "fixtures" ] } } globby-11.0.2/readme.md000066400000000000000000000124561377532662200146550ustar00rootroot00000000000000# globby > User-friendly glob matching Based on [`fast-glob`](https://github.com/mrmlnc/fast-glob) but adds a bunch of useful features. ## Features - Promise API - Multiple patterns - Negated patterns: `['foo*', '!foobar']` - Expands directories: `foo` → `foo/**/*` - Supports `.gitignore` ## Install ``` $ npm install globby ``` ## Usage ``` ├── unicorn ├── cake └── rainbow ``` ```js const globby = require('globby'); (async () => { const paths = await globby(['*', '!cake']); console.log(paths); //=> ['unicorn', 'rainbow'] })(); ``` ## API 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()`. ### globby(patterns, options?) Returns a `Promise` of matching paths. #### patterns Type: `string | string[]` See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). #### options Type: `object` See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones below. ##### expandDirectories Type: `boolean | string[] | object`\ Default: `true` 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: ```js const globby = require('globby'); (async () => { const paths = await globby('images', { expandDirectories: { files: ['cat', 'unicorn', '*.jpg'], extensions: ['png'] } }); console.log(paths); //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg'] })(); ``` Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`. ##### gitignore Type: `boolean`\ Default: `false` Respect ignore patterns in `.gitignore` files that apply to the globbed files. ### globby.sync(patterns, options?) Returns `string[]` of matching paths. ### globby.stream(patterns, options?) Returns a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) of matching paths. Since Node.js 10, [readable streams are iterable](https://nodejs.org/api/stream.html#stream_readable_symbol_asynciterator), so you can 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: ```js const globby = require('globby'); (async () => { for await (const path of globby.stream('*.tmp')) { console.log(path); } })(); ``` ### globby.generateGlobTasks(patterns, options?) Returns an `object[]` in the format `{pattern: 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. 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. ### globby.hasMagic(patterns, options?) Returns a `boolean` of whether there are any special glob characters in the `patterns`. Note that the options affect the results. This function is backed by [`fast-glob`](https://github.com/mrmlnc/fast-glob#isdynamicpatternpattern-options). ### globby.gitignore(options?) Returns a `Promise<(path: string) => boolean>` indicating whether a given path is ignored via a `.gitignore` file. Takes `cwd?: string` and `ignore?: string[]` as options. `.gitignore` files matched by the ignore config are not used for the resulting filter function. ```js const {gitignore} = require('globby'); (async () => { const isIgnored = await gitignore(); console.log(isIgnored('some/file')); })(); ``` ### globby.gitignore.sync(options?) Returns a `(path: string) => boolean` indicating whether a given path is ignored via a `.gitignore` file. Takes the same options as `globby.gitignore`. ## Globbing patterns Just a quick overview. - `*` matches any number of characters, but not `/` - `?` matches a single character, but not `/` - `**` matches any number of characters, including `/`, as long as it's the only thing in a path part - `{}` allows for a comma-separated list of "or" expressions - `!` at the beginning of a pattern will negate the match [Various patterns and expected matches.](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) ## globby for enterprise Available as part of the Tidelift Subscription. The maintainers of globby and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-globby?utm_source=npm-globby&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) ## Related - [multimatch](https://github.com/sindresorhus/multimatch) - Match against a list instead of the filesystem - [matcher](https://github.com/sindresorhus/matcher) - Simple wildcard matching - [del](https://github.com/sindresorhus/del) - Delete files and directories - [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed globby-11.0.2/stream-utils.js000066400000000000000000000012451377532662200160570ustar00rootroot00000000000000'use strict'; const {Transform} = require('stream'); class ObjectTransform extends Transform { constructor() { super({ objectMode: true }); } } class FilterStream extends ObjectTransform { constructor(filter) { super(); this._filter = filter; } _transform(data, encoding, callback) { if (this._filter(data)) { this.push(data); } callback(); } } class UniqueStream extends ObjectTransform { constructor() { super(); this._pushed = new Set(); } _transform(data, encoding, callback) { if (!this._pushed.has(data)) { this.push(data); this._pushed.add(data); } callback(); } } module.exports = { FilterStream, UniqueStream }; globby-11.0.2/test.js000066400000000000000000000260561377532662200144140ustar00rootroot00000000000000const fs = require('fs'); const util = require('util'); const path = require('path'); const test = require('ava'); const getStream = require('get-stream'); const globby = require('.'); const cwd = process.cwd(); const temporary = 'tmp'; const fixture = [ 'a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp' ]; test.before(() => { if (!fs.existsSync(temporary)) { fs.mkdirSync(temporary); } for (const element of fixture) { fs.writeFileSync(element, ''); fs.writeFileSync(path.join(__dirname, temporary, element), ''); } }); test.after(() => { for (const element of fixture) { fs.unlinkSync(element); fs.unlinkSync(path.join(__dirname, temporary, element)); } fs.rmdirSync(temporary); }); test('glob - async', async t => { t.deepEqual((await globby('*.tmp')).sort(), ['a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp']); }); test('glob - async - multiple file paths', t => { t.deepEqual(globby.sync(['a.tmp', 'b.tmp']), ['a.tmp', 'b.tmp']); }); test('glob with multiple patterns - async', async t => { t.deepEqual(await globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp']), ['a.tmp', 'b.tmp']); }); test('respect patterns order - async', async t => { t.deepEqual(await globby(['!*.tmp', 'a.tmp']), ['a.tmp']); }); test('respect patterns order - sync', t => { t.deepEqual(globby.sync(['!*.tmp', 'a.tmp']), ['a.tmp']); }); test('glob - sync', t => { t.deepEqual(globby.sync('*.tmp'), ['a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp']); t.deepEqual(globby.sync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']), ['a.tmp', 'b.tmp']); t.deepEqual(globby.sync(['!*.tmp', 'a.tmp']), ['a.tmp']); }); test('glob - sync - multiple file paths', t => { t.deepEqual(globby.sync(['a.tmp', 'b.tmp']), ['a.tmp', 'b.tmp']); }); test('return [] for all negative patterns - sync', t => { t.deepEqual(globby.sync(['!a.tmp', '!b.tmp']), []); }); test('return [] for all negative patterns - async', async t => { t.deepEqual(await globby(['!a.tmp', '!b.tmp']), []); }); test('glob - stream', async t => { t.deepEqual((await getStream.array(globby.stream('*.tmp'))).sort(), ['a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp']); }); test('glob - stream async iterator support', async t => { const results = []; for await (const path of globby.stream('*.tmp')) { results.push(path); } t.deepEqual(results, ['a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp']); }); test('glob - stream - multiple file paths', async t => { t.deepEqual(await getStream.array(globby.stream(['a.tmp', 'b.tmp'])), ['a.tmp', 'b.tmp']); }); test('glob with multiple patterns - stream', async t => { t.deepEqual(await getStream.array(globby.stream(['a.tmp', '*.tmp', '!{c,d,e}.tmp'])), ['a.tmp', 'b.tmp']); }); test('respect patterns order - stream', async t => { t.deepEqual(await getStream.array(globby.stream(['!*.tmp', 'a.tmp'])), ['a.tmp']); }); test('return [] for all negative patterns - stream', async t => { t.deepEqual(await getStream.array(globby.stream(['!a.tmp', '!b.tmp'])), []); }); test('cwd option', t => { process.chdir(temporary); t.deepEqual(globby.sync('*.tmp', {cwd}), ['a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp']); t.deepEqual(globby.sync(['a.tmp', '*.tmp', '!{c,d,e}.tmp'], {cwd}), ['a.tmp', 'b.tmp']); process.chdir(cwd); }); test('don\'t mutate the options object - async', async t => { await globby(['*.tmp', '!b.tmp'], Object.freeze({ignore: Object.freeze([])})); t.pass(); }); test('don\'t mutate the options object - sync', t => { globby.sync(['*.tmp', '!b.tmp'], Object.freeze({ignore: Object.freeze([])})); t.pass(); }); test('don\'t mutate the options object - stream', async t => { await getStream.array(globby.stream(['*.tmp', '!b.tmp'], Object.freeze({ignore: Object.freeze([])}))); t.pass(); }); test('expose generateGlobTasks', t => { const tasks = globby.generateGlobTasks(['*.tmp', '!b.tmp'], {ignore: ['c.tmp']}); t.is(tasks.length, 1); t.is(tasks[0].pattern, '*.tmp'); t.deepEqual(tasks[0].options.ignore, ['c.tmp', 'b.tmp']); }); test('expose hasMagic', t => { t.true(globby.hasMagic('**')); t.true(globby.hasMagic(['**', 'path1', 'path2'])); t.false(globby.hasMagic(['path1', 'path2'])); }); test('expandDirectories option', t => { t.deepEqual(globby.sync(temporary), ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']); t.deepEqual(globby.sync('**', {cwd: temporary}), ['a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp']); t.deepEqual(globby.sync(temporary, {expandDirectories: ['a*', 'b*']}), ['tmp/a.tmp', 'tmp/b.tmp']); t.deepEqual(globby.sync(temporary, { expandDirectories: { files: ['a', 'b'], extensions: ['tmp'] } }), ['tmp/a.tmp', 'tmp/b.tmp']); t.deepEqual(globby.sync(temporary, { expandDirectories: { files: ['a', 'b'], extensions: ['tmp'] }, ignore: ['**/b.tmp'] }), ['tmp/a.tmp']); }); test('expandDirectories:true and onlyFiles:true option', t => { t.deepEqual(globby.sync(temporary, {onlyFiles: true}), ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']); }); test.failing('expandDirectories:true and onlyFiles:false option', t => { // Node-glob('tmp/**') => ['tmp', 'tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp'] // Fast-glob('tmp/**') => ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp'] // See https://github.com/mrmlnc/fast-glob/issues/47 t.deepEqual(globby.sync(temporary, {onlyFiles: false}), ['tmp', 'tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']); }); test('expandDirectories and ignores option', t => { t.deepEqual(globby.sync('tmp', { ignore: ['tmp'] }), []); t.deepEqual(globby.sync('tmp/**', { expandDirectories: false, ignore: ['tmp'] }), ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']); }); test.failing('relative paths and ignores option', t => { process.chdir(temporary); t.deepEqual(globby.sync('../tmp', { cwd: process.cwd(), ignore: ['tmp'] }), []); process.chdir(cwd); }); // Rejected for being an invalid pattern [ {}, [{}], true, [true], false, [false], null, [null], undefined, [undefined], Number.NaN, [Number.NaN], 5, [5], function () {}, [function () {}] ].forEach(value => { const valueString = util.format(value); const message = 'Patterns must be a string or an array of strings'; test(`rejects the promise for invalid patterns input: ${valueString} - async`, async t => { await t.throwsAsync(globby(value), {instanceOf: TypeError}); await t.throwsAsync(globby(value), {message}); }); test(`throws for invalid patterns input: ${valueString} - sync`, t => { t.throws(() => { globby.sync(value); }, {instanceOf: TypeError}); t.throws(() => { globby.sync(value); }, {message}); }); test(`throws for invalid patterns input: ${valueString} - stream`, t => { t.throws(() => { globby.stream(value); }, {instanceOf: TypeError}); t.throws(() => { globby.stream(value); }, {message}); }); test(`generateGlobTasks throws for invalid patterns input: ${valueString}`, t => { t.throws(() => { globby.generateGlobTasks(value); }, {instanceOf: TypeError}); t.throws(() => { globby.generateGlobTasks(value); }, {message}); }); }); test('gitignore option defaults to false - async', async t => { const actual = await globby('*', {onlyFiles: false}); t.true(actual.includes('node_modules')); }); test('gitignore option defaults to false - sync', t => { const actual = globby.sync('*', {onlyFiles: false}); t.true(actual.includes('node_modules')); }); test('gitignore option defaults to false - stream', async t => { const actual = await getStream.array(globby.stream('*', {onlyFiles: false})); t.true(actual.includes('node_modules')); }); test('respects gitignore option true - async', async t => { const actual = await globby('*', {gitignore: true, onlyFiles: false}); t.false(actual.includes('node_modules')); }); test('respects gitignore option true - sync', t => { const actual = globby.sync('*', {gitignore: true, onlyFiles: false}); t.false(actual.includes('node_modules')); }); test('respects gitignore option true - stream', async t => { const actual = await getStream.array(globby.stream('*', {gitignore: true, onlyFiles: false})); t.false(actual.includes('node_modules')); }); test('respects gitignore option false - async', async t => { const actual = await globby('*', {gitignore: false, onlyFiles: false}); t.true(actual.includes('node_modules')); }); test('respects gitignore option false - sync', t => { const actual = globby.sync('*', {gitignore: false, onlyFiles: false}); t.true(actual.includes('node_modules')); }); test('gitignore option with stats option', async t => { const result = await globby('*', {gitignore: true, stats: true}); const actual = result.map(x => x.path); t.false(actual.includes('node_modules')); }); test('gitignore option with absolute option', async t => { const result = await globby('*', {gitignore: true, absolute: true}); t.false(result.includes('node_modules')); }); test('respects gitignore option false - stream', async t => { const actual = await getStream.array(globby.stream('*', {gitignore: false, onlyFiles: false})); t.true(actual.includes('node_modules')); }); test('gitingore option and objectMode option - async', async t => { const result = await globby('fixtures/gitignore/*', {gitignore: true, objectMode: true}); t.is(result.length, 1); t.truthy(result[0].path); }); test('gitingore option and objectMode option - sync', t => { const result = globby.sync('fixtures/gitignore/*', {gitignore: true, objectMode: true}); t.is(result.length, 1); t.truthy(result[0].path); }); test('`{extension: false}` and `expandDirectories.extensions` option', t => { t.deepEqual( globby.sync('*', { cwd: temporary, extension: false, expandDirectories: { extensions: [ 'md', 'tmp' ] } }), [ 'a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp' ] ); }); test('throws when specifying a file as cwd - async', async t => { const isFile = path.resolve('fixtures/gitignore/bar.js'); await t.throwsAsync( globby('.', {cwd: isFile}), {message: 'The `cwd` option must be a path to a directory'} ); await t.throwsAsync( globby('*', {cwd: isFile}), {message: 'The `cwd` option must be a path to a directory'} ); }); test('throws when specifying a file as cwd - sync', t => { const isFile = path.resolve('fixtures/gitignore/bar.js'); t.throws(() => { globby.sync('.', {cwd: isFile}); }, {message: 'The `cwd` option must be a path to a directory'}); t.throws(() => { globby.sync('*', {cwd: isFile}); }, {message: 'The `cwd` option must be a path to a directory'}); }); test('throws when specifying a file as cwd - stream', t => { const isFile = path.resolve('fixtures/gitignore/bar.js'); t.throws(() => { globby.stream('.', {cwd: isFile}); }, {message: 'The `cwd` option must be a path to a directory'}); t.throws(() => { globby.stream('*', {cwd: isFile}); }, {message: 'The `cwd` option must be a path to a directory'}); }); test('don\'t throw when specifying a non-existing cwd directory - async', async t => { const actual = await globby('.', {cwd: '/unknown'}); t.is(actual.length, 0); }); test('don\'t throw when specifying a non-existing cwd directory - sync', t => { const actual = globby.sync('.', {cwd: '/unknown'}); t.is(actual.length, 0); });