# smart-glob

> Smart glob that can ignore files

Latest version **1.0.2** (published 2021-01-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install smart-glob
pnpm add smart-glob
yarn add smart-glob
bun add smart-glob
```

Provides the command `smart-glob`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-01-28 |
| First published | 2020-07-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 55 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Tommaso De Rossi, morse |
| Maintainers | xmorse |

## Links

- npm: https://www.npmjs.com/package/smart-glob
- Repository: https://github.com/remorses/smart-glob
- npm.io page: https://npm.io/package/smart-glob

## Dependencies (8)

- [slash](https://npm.io/package/slash.md) ^3.0.0
- [tslib](https://npm.io/package/tslib.md) ^2.0.0
- [yargs](https://npm.io/package/yargs.md) ^16.0.3
- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [globrex](https://npm.io/package/globrex.md) ^0.1.2
- [memoizee](https://npm.io/package/memoizee.md) ^0.4.14
- [globalyzer](https://npm.io/package/globalyzer.md) ^0.1.4
- [promisify-child-process](https://npm.io/package/promisify-child-process.md) ^4.1.1

## Recent versions

- 1.0.2 (latest) — 2021-01-28
- 1.0.1 — 2020-10-11
- 0.0.41 — 2020-10-11
- 0.0.40 — 2020-10-11
- 0.0.39 — 2020-10-10
- 0.0.38 — 2020-10-09
- 0.0.37 — 2020-10-09
- 0.0.36 — 2020-10-09
- 0.0.35 — 2020-10-09
- 0.0.34 — 2020-10-05
- 0.0.33 — 2020-10-05
- 0.0.32 — 2020-10-05
- 0.0.31 — 2020-10-05
- 0.0.30 — 2020-10-05
- 0.0.29 — 2020-10-05
- … 25 more at https://npm.io/package/smart-glob/versions

## README

# smart-glob

`smart-glob` exports 2 functions

-   `globWithGit` uses the git cache to search for files, the search time should be constant (around 40ms)
-   `glob` does a normal glob search, it also can ignore directories in the `ignore` field

Both functions are tested in unix and windows environments (in windows return paths with `\\` delimiter unless `alwaysReturnUnixPaths` is provided)

In [bump-version](https://github.com/remorses/bump-version) github action i reduced the glob search time form 50 seconds down to 13 seconds using `glob` and to 0.5 seconds using `globWithGit`

```
npm i smart-glob
```

## Usage

```js
import { glob, globWithGit } from 'smart-glob'

const paths = await globWithGit(path.resolve('./tests/**.ts'), {
    cwd: './someFolder',
    // ignore patterns in gitignore
    gitignore: true,
    // output paths are absolute paths
    absolute: true,
    // ignore certain directories
    ignoreGlobs: ['**/dir/**'],
})

const files = await glob('**', {
    gitignore: true, // add the ignore from the .gitignore in current path
    filesOnly: true,
    ignore: ['node_modules'],
})
```

## Cli

```
npm i -g smart-glob
smart-glob './tests/**/*.tsx'
```

## Benchmark

Here is a benchmark with other globs solutions run on this package folder ignoring the `node_modules` directory

You can find this benchmark in the `/tests` folder

```
benchmarks

tiny-glob: 360.615ms
    ✓ tiny-glob (361ms)
fast-glob: 14.863ms
    ✓ fast-glob
globby: 18.128ms
    ✓ globby
glob: 930.975ms
    ✓ glob (931ms)
smart-glob: 6.296ms
    ✓ smart-glob
smart-glob using git: 54.845ms
    ✓ smart-glob using git (55ms)
```

---
_Source: https://npm.io/package/smart-glob · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
