Socket
Socket
Sign inDemoInstall

globby

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

globby - npm Package Compare versions

Comparing version 13.2.2 to 14.0.0

8

ignore.js
import process from 'node:process';
import fs from 'node:fs';
import fsPromises from 'node:fs/promises';
import path from 'node:path';

@@ -7,3 +8,4 @@ import fastGlob from 'fast-glob';

import slash from 'slash';
import {toPath, isNegativePattern} from './utilities.js';
import {toPath} from 'unicorn-magic';
import {isNegativePattern} from './utilities.js';

@@ -61,3 +63,3 @@ const ignoreFilesGlobOptions = {

const normalizeOptions = (options = {}) => ({
cwd: toPath(options.cwd) || process.cwd(),
cwd: toPath(options.cwd) ?? process.cwd(),
suppressErrors: Boolean(options.suppressErrors),

@@ -75,3 +77,3 @@ deep: typeof options.deep === 'number' ? options.deep : Number.POSITIVE_INFINITY,

filePath,
content: await fs.promises.readFile(filePath, 'utf8'),
content: await fsPromises.readFile(filePath, 'utf8'),
})),

@@ -78,0 +80,0 @@ );

@@ -1,9 +0,10 @@

import {Options as FastGlobOptions, Entry} from 'fast-glob';
import type FastGlob from 'fast-glob';
import {type Options as FastGlobOptions, type Entry} from 'fast-glob';
export type GlobEntry = Entry;
export interface GlobTask {
export type GlobTask = {
readonly patterns: string[];
readonly options: Options;
}
};

@@ -17,3 +18,3 @@ export type ExpandDirectoriesOption =

export interface Options extends FastGlobOptionsWithoutCwd {
export type Options = {
/**

@@ -65,7 +66,7 @@ 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.

readonly cwd?: URL | string;
}
} & FastGlobOptionsWithoutCwd;
export interface GitignoreOptions {
export type GitignoreOptions = {
readonly cwd?: URL | string;
}
};

@@ -208,1 +209,3 @@ export type GlobbyFilterFunction = (path: URL | string) => boolean;

export function isGitIgnoredSync(options?: GitignoreOptions): GlobbyFilterFunction;
export function convertPathToPattern(source: string): FastGlob.Pattern;

@@ -0,6 +1,8 @@

import process from 'node:process';
import fs from 'node:fs';
import nodePath from 'node:path';
import merge2 from 'merge2';
import mergeStreams from '@sindresorhus/merge-streams';
import fastGlob from 'fast-glob';
import dirGlob from 'dir-glob';
import {isDirectory, isDirectorySync} from 'path-type';
import {toPath} from 'unicorn-magic';
import {

@@ -11,3 +13,3 @@ GITIGNORE_FILES_PATTERN,

} from './ignore.js';
import {FilterStream, toPath, isNegativePattern} from './utilities.js';
import {isNegativePattern} from './utilities.js';

@@ -20,2 +22,32 @@ const assertPatternsInput = patterns => {

const normalizePathForDirectoryGlob = (filePath, cwd) => {
const path = isNegativePattern(filePath) ? filePath.slice(1) : filePath;
return nodePath.isAbsolute(path) ? path : nodePath.join(cwd, path);
};
const getDirectoryGlob = ({directoryPath, files, extensions}) => {
const extensionGlob = extensions?.length > 0 ? `.${extensions.length > 1 ? `{${extensions.join(',')}}` : extensions[0]}` : '';
return files
? files.map(file => nodePath.posix.join(directoryPath, `**/${nodePath.extname(file) ? file : `${file}${extensionGlob}`}`))
: [nodePath.posix.join(directoryPath, `**${extensionGlob ? `/${extensionGlob}` : ''}`)];
};
const directoryToGlob = async (directoryPaths, {
cwd = process.cwd(),
files,
extensions,
} = {}) => {
const globs = await Promise.all(directoryPaths.map(async directoryPath =>
(await isDirectory(normalizePathForDirectoryGlob(directoryPath, cwd))) ? getDirectoryGlob({directoryPath, files, extensions}) : directoryPath),
);
return globs.flat();
};
const directoryToGlobSync = (directoryPaths, {
cwd = process.cwd(),
files,
extensions,
} = {}) => directoryPaths.flatMap(directoryPath => isDirectorySync(normalizePathForDirectoryGlob(directoryPath, cwd)) ? getDirectoryGlob({directoryPath, files, extensions}) : directoryPath);
const toPatternsArray = patterns => {

@@ -27,4 +59,4 @@ patterns = [...new Set([patterns].flat())];

const checkCwdOption = options => {
if (!options.cwd) {
const checkCwdOption = cwd => {
if (!cwd) {
return;

@@ -35,3 +67,3 @@ }

try {
stat = fs.statSync(options.cwd);
stat = fs.statSync(cwd);
} catch {

@@ -49,10 +81,8 @@ return;

...options,
ignore: options.ignore || [],
expandDirectories: options.expandDirectories === undefined
? true
: options.expandDirectories,
ignore: options.ignore ?? [],
expandDirectories: options.expandDirectories ?? true,
cwd: toPath(options.cwd),
};
checkCwdOption(options);
checkCwdOption(options.cwd);

@@ -62,4 +92,4 @@ return options;

const normalizeArguments = fn => async (patterns, options) => fn(toPatternsArray(patterns), normalizeOptions(options));
const normalizeArgumentsSync = fn => (patterns, options) => fn(toPatternsArray(patterns), normalizeOptions(options));
const normalizeArguments = function_ => async (patterns, options) => function_(toPatternsArray(patterns), normalizeOptions(options));
const normalizeArgumentsSync = function_ => (patterns, options) => function_(toPatternsArray(patterns), normalizeOptions(options));

@@ -95,7 +125,11 @@ const getIgnoreFilesPatterns = options => {

return fastGlobResult => {
const path = fastGlobResult.path || fastGlobResult;
const pathKey = nodePath.normalize(path);
const seenOrIgnored = seen.has(pathKey) || (isIgnored && isIgnored(path));
const pathKey = nodePath.normalize(fastGlobResult.path ?? fastGlobResult);
if (seen.has(pathKey) || (isIgnored && isIgnored(pathKey))) {
return false;
}
seen.add(pathKey);
return !seenOrIgnored;
return true;
};

@@ -105,3 +139,2 @@ };

const unionFastGlobResults = (results, filter) => results.flat().filter(fastGlobResult => filter(fastGlobResult));
const unionFastGlobStreams = (streams, filter) => merge2(streams).pipe(new FilterStream(fastGlobResult => filter(fastGlobResult)));

@@ -144,3 +177,3 @@ const convertNegativePatterns = (patterns, options) => {

const getDirGlobOptions = (options, cwd) => ({
const normalizeExpandDirectoriesOption = (options, cwd) => ({
...(cwd ? {cwd} : {}),

@@ -159,4 +192,3 @@ ...(Array.isArray(options) ? {files: options} : options),

const patternExpandOptions = getDirGlobOptions(expandDirectories, cwd);
const ignoreExpandOptions = cwd ? {cwd} : undefined;
const directoryToGlobOptions = normalizeExpandDirectoriesOption(expandDirectories, cwd);

@@ -171,4 +203,4 @@ return Promise.all(

] = await Promise.all([
dirGlob(patterns, patternExpandOptions),
dirGlob(options.ignore, ignoreExpandOptions),
directoryToGlob(patterns, directoryToGlobOptions),
directoryToGlob(options.ignore, {cwd}),
]);

@@ -183,3 +215,2 @@

const globTasks = convertNegativePatterns(patterns, options);
const {cwd, expandDirectories} = options;

@@ -191,9 +222,8 @@

const patternExpandOptions = getDirGlobOptions(expandDirectories, cwd);
const ignoreExpandOptions = cwd ? {cwd} : undefined;
const directoryToGlobSyncOptions = normalizeExpandDirectoriesOption(expandDirectories, cwd);
return globTasks.map(task => {
let {patterns, options} = task;
patterns = dirGlob.sync(patterns, patternExpandOptions);
options.ignore = dirGlob.sync(options.ignore, ignoreExpandOptions);
patterns = directoryToGlobSync(patterns, directoryToGlobSyncOptions);
options.ignore = directoryToGlobSync(options.ignore, {cwd});
return {patterns, options};

@@ -211,4 +241,4 @@ });

]);
const results = await Promise.all(tasks.map(task => fastGlob(task.patterns, task.options)));
return unionFastGlobResults(results, filter);

@@ -221,3 +251,2 @@ });

const results = tasks.map(task => fastGlob.sync(task.patterns, task.options));
return unionFastGlobResults(results, filter);

@@ -230,4 +259,8 @@ });

const streams = tasks.map(task => fastGlob.stream(task.patterns, task.options));
const stream = mergeStreams(streams).filter(fastGlobResult => filter(fastGlobResult));
return unionFastGlobStreams(streams, filter);
// TODO: Make it return a web stream at some point.
// return Readable.toWeb(stream);
return stream;
});

@@ -246,1 +279,3 @@

} from './ignore.js';
export const {convertPathToPattern} = fastGlob;
{
"name": "globby",
"version": "13.2.2",
"version": "14.0.0",
"description": "User-friendly glob matching",

@@ -14,5 +14,9 @@ "license": "MIT",

"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
"node": ">=18"
},

@@ -63,19 +67,18 @@ "scripts": {

"dependencies": {
"dir-glob": "^3.0.1",
"fast-glob": "^3.3.0",
"@sindresorhus/merge-streams": "^1.0.0",
"fast-glob": "^3.3.2",
"ignore": "^5.2.4",
"merge2": "^1.4.1",
"slash": "^4.0.0"
"path-type": "^5.0.0",
"slash": "^5.1.0",
"unicorn-magic": "^0.1.0"
},
"devDependencies": {
"@globby/main-branch": "sindresorhus/globby#main",
"@types/node": "^20.3.3",
"@types/node": "^20.9.0",
"ava": "^5.3.1",
"benchmark": "2.1.4",
"glob-stream": "^8.0.0",
"rimraf": "^5.0.1",
"tempy": "^3.0.0",
"tsd": "^0.28.1",
"typescript": "^5.1.6",
"xo": "^0.54.2"
"tempy": "^3.1.0",
"tsd": "^0.29.0",
"xo": "^0.56.0"
},

@@ -85,8 +88,3 @@ "xo": {

"fixtures"
],
"rules": {
"@typescript-eslint/consistent-type-definitions": "off",
"n/prefer-global/url": "off",
"@typescript-eslint/consistent-type-imports": "off"
}
]
},

@@ -93,0 +91,0 @@ "ava": {

@@ -18,5 +18,5 @@ # globby

```sh
npm install globby
```
$ npm install globby
```

@@ -70,13 +70,11 @@ ## Usage

(async () => {
const paths = await globby('images', {
expandDirectories: {
files: ['cat', 'unicorn', '*.jpg'],
extensions: ['png']
}
});
const paths = await globby('images', {
expandDirectories: {
files: ['cat', 'unicorn', '*.jpg'],
extensions: ['png']
}
});
console.log(paths);
//=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']
})();
console.log(paths);
//=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']
```

@@ -110,3 +108,3 @@

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:
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:

@@ -116,9 +114,11 @@ ```js

(async () => {
for await (const path of globbyStream('*.tmp')) {
console.log(path);
}
})();
for await (const path of globbyStream('*.tmp')) {
console.log(path);
}
```
### convertPathToPattern(path)
Convert a path to a pattern. [Learn more.](https://github.com/mrmlnc/fast-glob#convertpathtopatternpath)
### generateGlobTasks(patterns, options?)

@@ -176,8 +176,2 @@

## 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

@@ -184,0 +178,0 @@

@@ -1,17 +0,1 @@

import {fileURLToPath} from 'node:url';
import {Transform} from 'node:stream';
export const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
export class FilterStream extends Transform {
constructor(filter) {
super({
objectMode: true,
transform(data, encoding, callback) {
callback(undefined, filter(data) ? data : undefined);
},
});
}
}
export const isNegativePattern = pattern => pattern[0] === '!';
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc