remove-glob 0.4.10 → 1.0.0
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/README.md +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -18
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +9 -0
- package/package.json +3 -4
- package/src/index.ts +9 -19
- package/src/utils.ts +8 -0
package/README.md
CHANGED
|
@@ -9,10 +9,13 @@
|
|
|
9
9
|
|
|
10
10
|
## remove-glob
|
|
11
11
|
|
|
12
|
-
A tiny cross-platform utility to remove items or directories recursively, it also accepts an optional glob pattern. There's also a CLI for easy, cross-platform usage
|
|
12
|
+
A tiny cross-platform utility to remove items or directories recursively, it also accepts an optional glob pattern. There's also a CLI for easy, cross-platform usage using [cli-nano](https://www.npmjs.com/package/cli-nano) which is the only external dependency.
|
|
13
13
|
|
|
14
14
|
Inspired by [rimraf](https://www.npmjs.com/package/rimraf) and [premove](https://www.npmjs.com/package/premove) but also supports glob pattern to remove multiple files or directories.
|
|
15
15
|
|
|
16
|
+
> [!NOTE]
|
|
17
|
+
> This project now requires Node.JS >= 22.17.0 so that we can use the native `fs.glob`, however if you can't update your Node.JS just yet, then just stick with `remove-glob: ^0.4.10` since that is the only change in v1.0.0
|
|
18
|
+
|
|
16
19
|
### Install
|
|
17
20
|
```sh
|
|
18
21
|
npm install remove-glob
|
|
@@ -26,6 +29,9 @@ A `remove` binary is available, it takes an optional path argument (zero or mult
|
|
|
26
29
|
> The `paths` and `glob` arguments are both optionals, but you **must** provide at least 1 of them.
|
|
27
30
|
> However, please note that providing both of them simultaneously is not supported and will throw an error (choose the option that is best suited to your use case).
|
|
28
31
|
|
|
32
|
+
> [!NOTE]
|
|
33
|
+
> When using the `--glob` option, dotfiles and dot-directories (e.g. `.env`, `.gitignore`, `.config/`) are included by default. If you want to exclude them, you can adjust your glob pattern (e.g. use `**/[!.]*.js` or add an `!**/.*` pattern).
|
|
34
|
+
|
|
29
35
|
```
|
|
30
36
|
Usage:
|
|
31
37
|
remove [paths..] [options] Remove all items recursively
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,GAAE,aAAkB,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,qBAwElF"}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import { existsSync, rmSync, statSync, unlinkSync } from 'node:fs';
|
|
1
|
+
import { existsSync, globSync, rmSync, statSync, unlinkSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
/** Helper to throw or callback with error */
|
|
5
|
-
function throwOrCallback(err, cb) {
|
|
6
|
-
if (typeof cb === 'function') {
|
|
7
|
-
cb(err);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
throw err;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
3
|
+
import { throwOrCallback } from './utils.js';
|
|
13
4
|
/**
|
|
14
5
|
* Remove the files or directories, the item(s) can be provided via positional arguments or via a `--glob` pattern.
|
|
15
6
|
* @param {RemoveOptions} options - CLI options
|
|
@@ -32,13 +23,12 @@ export function removeSync(opts = {}, callback) {
|
|
|
32
23
|
}
|
|
33
24
|
const requiresCwdChange = !!(paths.length && opts.cwd);
|
|
34
25
|
if (!paths.length && opts.glob) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
26
|
+
// Use fs.globSync to match files. Dotfiles and dot-directories are always included.
|
|
27
|
+
paths = globSync(opts.glob, { cwd: opts.cwd });
|
|
28
|
+
// Manually resolve to absolute paths if cwd is set
|
|
29
|
+
if (opts.cwd) {
|
|
30
|
+
paths = paths.map(p => resolve(opts.cwd, p));
|
|
31
|
+
}
|
|
42
32
|
}
|
|
43
33
|
if (opts.stat || opts.verbose) {
|
|
44
34
|
console.time('Duration');
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,wBAAgB,eAAe,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,QAMpE"}
|
package/dist/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remove-glob",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A tiny utility to remove items or directories recursively, also supports glob",
|
|
5
5
|
"bin": {
|
|
6
6
|
"remove": "dist/cli.js"
|
|
@@ -35,11 +35,10 @@
|
|
|
35
35
|
"url": "https://github.com/ghiscoding/remove-glob/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"cli-nano": "^1.2.2"
|
|
39
|
-
"tinyglobby": "^0.2.15"
|
|
38
|
+
"cli-nano": "^1.2.2"
|
|
40
39
|
},
|
|
41
40
|
"engines": {
|
|
42
|
-
"node": "^
|
|
41
|
+
"node": "^22.17.0 || >=24.0.0"
|
|
43
42
|
},
|
|
44
43
|
"funding": {
|
|
45
44
|
"type": "ko_fi",
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import { existsSync, rmSync, statSync, unlinkSync } from 'node:fs';
|
|
1
|
+
import { existsSync, globSync, rmSync, statSync, unlinkSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
import { globSync } from 'tinyglobby';
|
|
4
|
-
|
|
5
3
|
import type { RemoveOptions } from './interfaces.js';
|
|
6
|
-
|
|
7
|
-
/** Helper to throw or callback with error */
|
|
8
|
-
function throwOrCallback(err?: Error, cb?: (e?: Error) => void) {
|
|
9
|
-
if (typeof cb === 'function') {
|
|
10
|
-
cb(err);
|
|
11
|
-
} else {
|
|
12
|
-
throw err;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
4
|
+
import { throwOrCallback } from './utils.js';
|
|
15
5
|
|
|
16
6
|
/**
|
|
17
7
|
* Remove the files or directories, the item(s) can be provided via positional arguments or via a `--glob` pattern.
|
|
@@ -43,13 +33,13 @@ export function removeSync(opts: RemoveOptions = {}, callback?: (e?: Error) => v
|
|
|
43
33
|
}
|
|
44
34
|
const requiresCwdChange = !!(paths.length && opts.cwd);
|
|
45
35
|
if (!paths.length && opts.glob) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
36
|
+
// Use fs.globSync to match files. Dotfiles and dot-directories are always included.
|
|
37
|
+
paths = globSync(opts.glob, { cwd: opts.cwd });
|
|
38
|
+
|
|
39
|
+
// Manually resolve to absolute paths if cwd is set
|
|
40
|
+
if (opts.cwd) {
|
|
41
|
+
paths = paths.map(p => resolve(opts.cwd as string, p));
|
|
42
|
+
}
|
|
53
43
|
}
|
|
54
44
|
if (opts.stat || opts.verbose) {
|
|
55
45
|
console.time('Duration');
|