Comparing version
@@ -6,2 +6,4 @@ /** | ||
* | ||
* File separators on Windows will be yielded as `/` and not `\`. | ||
* | ||
* @example | ||
@@ -12,10 +14,5 @@ * | ||
* | ||
* const options = { | ||
* cwd // defaults to process.cwd | ||
* absolute // return absolute paths, defaults to false | ||
* nodir // only yield file paths, skip directories | ||
* // All options are passed through to fast-glob | ||
* const options = {} | ||
* | ||
* // all other options are passed to minimatch | ||
* } | ||
* | ||
* for await (const path of glob('/path/to/file', '**\/*', options)) { | ||
@@ -26,23 +23,9 @@ * console.info(path) | ||
* | ||
* See the [minimatch docs](https://www.npmjs.com/package/minimatch#options) for the full list of options. | ||
* See the [fast-glob docs](https://github.com/mrmlnc/fast-glob#options-3) for the full list of options. | ||
*/ | ||
import type { MinimatchOptions } from 'minimatch'; | ||
export interface GlobOptions extends MinimatchOptions { | ||
/** | ||
* The current working directory | ||
*/ | ||
cwd?: string; | ||
/** | ||
* If true produces absolute paths (default: false) | ||
*/ | ||
absolute?: boolean; | ||
/** | ||
* If true yields file paths and skip directories (default: false) | ||
*/ | ||
nodir?: boolean; | ||
} | ||
import type { Options } from 'fast-glob'; | ||
/** | ||
* Async iterable filename pattern matcher | ||
*/ | ||
export default function glob(dir: string, pattern: string, options?: GlobOptions): AsyncGenerator<string, void, undefined>; | ||
export default function glob(dir: string, pattern: string, options?: Options): AsyncGenerator<string, void, undefined>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,2 +6,4 @@ /** | ||
* | ||
* File separators on Windows will be yielded as `/` and not `\`. | ||
* | ||
* @example | ||
@@ -12,10 +14,5 @@ * | ||
* | ||
* const options = { | ||
* cwd // defaults to process.cwd | ||
* absolute // return absolute paths, defaults to false | ||
* nodir // only yield file paths, skip directories | ||
* // All options are passed through to fast-glob | ||
* const options = {} | ||
* | ||
* // all other options are passed to minimatch | ||
* } | ||
* | ||
* for await (const path of glob('/path/to/file', '**\/*', options)) { | ||
@@ -26,7 +23,7 @@ * console.info(path) | ||
* | ||
* See the [minimatch docs](https://www.npmjs.com/package/minimatch#options) for the full list of options. | ||
* See the [fast-glob docs](https://github.com/mrmlnc/fast-glob#options-3) for the full list of options. | ||
*/ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
import { minimatch } from 'minimatch'; | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import fastGlob from 'fast-glob'; | ||
/** | ||
@@ -37,31 +34,10 @@ * Async iterable filename pattern matcher | ||
const absoluteDir = path.resolve(dir); | ||
const relativeDir = path.relative(options.cwd ?? process.cwd(), dir); | ||
const stats = await fs.stat(absoluteDir); | ||
if (stats.isDirectory()) { | ||
for await (const entry of _glob(absoluteDir, '', pattern, options)) { | ||
yield entry; | ||
} | ||
return; | ||
for await (const entry of fastGlob.stream(pattern, { | ||
...options, | ||
cwd: stats.isDirectory() ? dir : process.cwd() | ||
})) { | ||
yield entry.toString(); | ||
} | ||
if (minimatch(relativeDir, pattern, options)) { | ||
yield options.absolute === true ? absoluteDir : relativeDir; | ||
} | ||
} | ||
async function* _glob(base, dir, pattern, options) { | ||
for await (const entry of await fs.opendir(path.join(base, dir))) { | ||
const relativeEntryPath = path.join(dir, entry.name); | ||
const absoluteEntryPath = path.join(base, dir, entry.name); | ||
let match = minimatch(relativeEntryPath, pattern, options); | ||
const isDirectory = entry.isDirectory(); | ||
if (isDirectory && options.nodir === true) { | ||
match = false; | ||
} | ||
if (match) { | ||
yield options.absolute === true ? absoluteEntryPath : relativeEntryPath; | ||
} | ||
if (isDirectory) { | ||
yield* _glob(base, relativeEntryPath, pattern, options); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"GlobOptions": "https://achingbrain.github.io/it/interfaces/it_glob.GlobOptions.html", | ||
".:GlobOptions": "https://achingbrain.github.io/it/interfaces/it_glob.GlobOptions.html", | ||
"default": "https://achingbrain.github.io/it/functions/it_glob.default.html", | ||
".:default": "https://achingbrain.github.io/it/functions/it_glob.default.html" | ||
} |
{ | ||
"name": "it-glob", | ||
"version": "2.0.7", | ||
"version": "3.0.0", | ||
"description": "Async iterable filename pattern matcher", | ||
@@ -41,3 +41,3 @@ "author": "Alex Potsides <alex@achingbrain.net>", | ||
"scripts": { | ||
"build": "aegir build", | ||
"build": "aegir build --bundle false", | ||
"lint": "aegir lint", | ||
@@ -49,3 +49,3 @@ "dep-check": "aegir dep-check", | ||
"dependencies": { | ||
"minimatch": "^9.0.4" | ||
"fast-glob": "^3.3.2" | ||
}, | ||
@@ -57,5 +57,4 @@ "devDependencies": { | ||
"browser": { | ||
"fs/promises": false, | ||
"path": false | ||
"./dist/src/index.js": "./dist/src/index.browser.js" | ||
} | ||
} |
@@ -27,2 +27,4 @@ # it-glob | ||
File separators on Windows will be yielded as `/` and not \`\`. | ||
## Example | ||
@@ -33,10 +35,5 @@ | ||
const options = { | ||
cwd // defaults to process.cwd | ||
absolute // return absolute paths, defaults to false | ||
nodir // only yield file paths, skip directories | ||
// All options are passed through to fast-glob | ||
const options = {} | ||
// all other options are passed to minimatch | ||
} | ||
for await (const path of glob('/path/to/file', '**/*', options)) { | ||
@@ -47,3 +44,3 @@ console.info(path) | ||
See the [minimatch docs](https://www.npmjs.com/package/minimatch#options) for the full list of options. | ||
See the [fast-glob docs](https://github.com/mrmlnc/fast-glob#options-3) for the full list of options. | ||
@@ -50,0 +47,0 @@ # Install |
@@ -6,2 +6,4 @@ /** | ||
* | ||
* File separators on Windows will be yielded as `/` and not `\`. | ||
* | ||
* @example | ||
@@ -12,10 +14,5 @@ * | ||
* | ||
* const options = { | ||
* cwd // defaults to process.cwd | ||
* absolute // return absolute paths, defaults to false | ||
* nodir // only yield file paths, skip directories | ||
* // All options are passed through to fast-glob | ||
* const options = {} | ||
* | ||
* // all other options are passed to minimatch | ||
* } | ||
* | ||
* for await (const path of glob('/path/to/file', '**\/*', options)) { | ||
@@ -26,70 +23,23 @@ * console.info(path) | ||
* | ||
* See the [minimatch docs](https://www.npmjs.com/package/minimatch#options) for the full list of options. | ||
* See the [fast-glob docs](https://github.com/mrmlnc/fast-glob#options-3) for the full list of options. | ||
*/ | ||
import fs from 'fs/promises' | ||
import path from 'path' | ||
import { minimatch } from 'minimatch' | ||
import type { MinimatchOptions } from 'minimatch' | ||
import fs from 'node:fs/promises' | ||
import path from 'node:path' | ||
import fastGlob from 'fast-glob' | ||
import type { Options } from 'fast-glob' | ||
export interface GlobOptions extends MinimatchOptions { | ||
/** | ||
* The current working directory | ||
*/ | ||
cwd?: string | ||
/** | ||
* If true produces absolute paths (default: false) | ||
*/ | ||
absolute?: boolean | ||
/** | ||
* If true yields file paths and skip directories (default: false) | ||
*/ | ||
nodir?: boolean | ||
} | ||
/** | ||
* Async iterable filename pattern matcher | ||
*/ | ||
export default async function * glob (dir: string, pattern: string, options: GlobOptions = {}): AsyncGenerator<string, void, undefined> { | ||
export default async function * glob (dir: string, pattern: string, options: Options = {}): AsyncGenerator<string, void, undefined> { | ||
const absoluteDir = path.resolve(dir) | ||
const relativeDir = path.relative(options.cwd ?? process.cwd(), dir) | ||
const stats = await fs.stat(absoluteDir) | ||
if (stats.isDirectory()) { | ||
for await (const entry of _glob(absoluteDir, '', pattern, options)) { | ||
yield entry | ||
} | ||
return | ||
for await (const entry of fastGlob.stream(pattern, { | ||
...options, | ||
cwd: stats.isDirectory() ? dir : process.cwd() | ||
})) { | ||
yield entry.toString() | ||
} | ||
if (minimatch(relativeDir, pattern, options)) { | ||
yield options.absolute === true ? absoluteDir : relativeDir | ||
} | ||
} | ||
async function * _glob (base: string, dir: string, pattern: string, options: GlobOptions): AsyncGenerator<string, void, undefined> { | ||
for await (const entry of await fs.opendir(path.join(base, dir))) { | ||
const relativeEntryPath = path.join(dir, entry.name) | ||
const absoluteEntryPath = path.join(base, dir, entry.name) | ||
let match = minimatch(relativeEntryPath, pattern, options) | ||
const isDirectory = entry.isDirectory() | ||
if (isDirectory && options.nodir === true) { | ||
match = false | ||
} | ||
if (match) { | ||
yield options.absolute === true ? absoluteEntryPath : relativeEntryPath | ||
} | ||
if (isDirectory) { | ||
yield * _glob(base, relativeEntryPath, pattern, options) | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
14
40%0
-100%8329
-75.41%116
-57.97%64
-4.48%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed