remove-glob 0.3.6 → 0.4.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 CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
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. It uses 2 small dependencies [tinyglobby](https://www.npmjs.com/package/tinyglobby) for glob support and [cli-nano](https://www.npmjs.com/package/cli-nano) for the CLI.
13
13
 
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 files or directories.
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
16
  ### Install
17
17
  ```sh
@@ -20,11 +20,11 @@ npm install remove-glob
20
20
 
21
21
  ### Command Line
22
22
 
23
- A `remove` binary is available, it takes an optional paths argument (zero or multiple file/directory paths) to be removed **or** a `--glob` pattern instead of paths.
23
+ A `remove` binary is available, it takes an optional path argument (zero or multiple file/directory paths) to be removed **or** a `--glob` pattern instead of path(s).
24
24
 
25
25
  > [!NOTE]
26
- > The `paths` (argument) and `glob` (option) are both optional, but you **must** provide at least 1 of them.
27
- > However, providing both of them simultaneously is not supported (choose which option is best suited to your use case).
26
+ > The `paths` and `glob` arguments are both optionals, but you **must** provide at least 1 of them.
27
+ > 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
28
 
29
29
  ```
30
30
  Usage:
@@ -60,7 +60,7 @@ $ remove --glob \"dist/**/*.{js,map}\"
60
60
  ```
61
61
 
62
62
  > [!NOTE]
63
- > When using the `--glob` option, it will skips `.git/` and `node_modules/` directories by default.
63
+ > When using the `--glob` option, it will skip `.git/` and `node_modules/` directories by default.
64
64
 
65
65
  ### Usage
66
66
 
@@ -88,18 +88,26 @@ import { removeSync } from 'remove-glob';
88
88
  removeSync(opt, callback);
89
89
  ```
90
90
 
91
- The first argument is an object holding any of the options shown below. The last argument is an optional callback function which is executed (when defined) after all files are removed.
91
+ The first argument is an object holding any of the options shown below. The last argument is an optional callback function that will be executed after all files were removed.
92
92
 
93
93
  ```js
94
94
  {
95
- cwd: string, // directory to resolve your `filepath` from, defaults to `process.cwd()`
96
- dryRun: bool, // show what would be copied, without actually copying anything
97
- paths: string | string[], // filepath(s) to remove – may be a file or a directory.
98
- glob: string, // glob pattern to find which files/directories to remove
99
- stats: bool // show some statistics after execution (time + file count)
100
- verbose: bool, // print more information to console when executing the removal
95
+ cwd: string; // directory to resolve your `filepath` from, defaults to `process.cwd()`
96
+ dryRun: boolean; // show what would be copied, without actually copying anything
97
+ paths: string | string[]; // filepath(s) to remove – may be a file or a directory.
98
+ glob: string; // glob pattern to find which files/directories to remove
99
+ stats: boolean; // show some statistics after execution (time + file count)
100
+ verbose: boolean; // print more information to console when executing the removal
101
101
  }
102
102
  ```
103
103
 
104
104
  > [!NOTE]
105
105
  > The first argument is required and it **must** include either a `paths` or a `glob`, but it cannot include both options simultaneously.
106
+
107
+ ### Used by
108
+
109
+ I use it in most of my own open source projects as a Dev Dependency (feel free to modify this list and add your project(s) as well)
110
+
111
+ - [Lerna-Lite](https://github.com/lerna-lite/lerna-lite)
112
+ - [SlickGrid](https://github.com/6pac/SlickGrid)
113
+ - [Slickgrid-Universal](https://github.com/ghiscoding/slickgrid-universal)
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAWrD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,GAAE,aAAkB,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,qBA0ElF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAWrD;;;;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,5 +1,5 @@
1
- import { existsSync, readdirSync, rmSync, statSync, unlinkSync } from 'node:fs';
2
- import { join, resolve } from 'node:path';
1
+ import { existsSync, rmSync, statSync, unlinkSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
3
  import { globSync } from 'tinyglobby';
4
4
  /** Helper to throw or callback with error */
5
5
  function throwOrCallback(err, cb) {
@@ -23,7 +23,7 @@ export function removeSync(opts = {}, callback) {
23
23
  return;
24
24
  }
25
25
  if (paths.length && opts.glob) {
26
- throwOrCallback(new Error('Providing both `--paths` and `--glob` pattern are not supported, you must provide only one of these options.'), cb);
26
+ throwOrCallback(new Error('Providing both `--paths` and `--glob` pattern at the same time is not supported, you must chose only one.'), cb);
27
27
  return;
28
28
  }
29
29
  let pathExists = false;
@@ -40,35 +40,29 @@ export function removeSync(opts = {}, callback) {
40
40
  ignore: ['**/.git/**', '**/node_modules/**'],
41
41
  });
42
42
  }
43
- opts.stat && console.time('Duration');
44
- opts.dryRun && console.log('=== dry-run ===');
43
+ if (opts.stat || opts.verbose) {
44
+ console.time('Duration');
45
+ }
46
+ // start dry-run print
47
+ opts.dryRun && console.log('-- dry-run --');
45
48
  paths.forEach(path => {
46
49
  // do we need to resolve file/dir from a different cwd?
47
50
  if (requiresCwdChange) {
48
51
  path = resolve(opts.cwd || '.', path);
49
52
  }
50
53
  if (existsSync(path)) {
51
- if (statSync(path).isDirectory()) {
52
- // directories
53
- if (opts.dryRun) {
54
- console.log(`would remove directory: ${path}`);
55
- }
56
- else {
57
- opts.verbose && console.log(`removing directory: ${path}`);
58
- readdirSync(path).forEach(name => {
59
- removeSync({ paths: join(path, name) }); // recursively remove content
60
- });
61
- rmSync(path, { recursive: true, force: true, maxRetries: process.platform === 'win32' ? 10 : 0 });
62
- }
54
+ const isDir = statSync(path).isDirectory();
55
+ const pathLog = `${isDir ? 'directory' : 'file'}: ${path}`;
56
+ if (opts.dryRun) {
57
+ console.log(`would remove ${pathLog}`);
63
58
  }
64
59
  else {
65
- // files
66
- if (opts.dryRun) {
67
- console.log(`would remove file: ${path}`);
60
+ opts.verbose && console.log(`removing ${pathLog}`);
61
+ if (isDir) {
62
+ rmSync(path, { recursive: true, force: true, maxRetries: process.platform === 'win32' ? 10 : 0 }); // delete folder recursively
68
63
  }
69
64
  else {
70
- opts.verbose && console.log(`removing file: ${path}`);
71
- unlinkSync(path);
65
+ unlinkSync(path); // delete file
72
66
  }
73
67
  }
74
68
  pathExists = true;
@@ -78,8 +72,8 @@ export function removeSync(opts = {}, callback) {
78
72
  console.log(`Removed: ${paths.length} items`);
79
73
  console.timeEnd('Duration');
80
74
  }
81
- opts.dryRun && console.log('=== dry-run ===');
82
- if (typeof cb === 'function')
83
- cb();
75
+ // end dry-run print & execute callback when defined
76
+ opts.dryRun && console.log('-- end --');
77
+ typeof cb === 'function' && cb();
84
78
  return pathExists;
85
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remove-glob",
3
- "version": "0.3.6",
3
+ "version": "0.4.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"
@@ -17,7 +17,8 @@
17
17
  },
18
18
  "module": "./dist/index.js",
19
19
  "publishConfig": {
20
- "access": "public"
20
+ "access": "public",
21
+ "registry": "https://registry.npmjs.org/"
21
22
  },
22
23
  "files": [
23
24
  "/dist",
@@ -35,7 +36,7 @@
35
36
  },
36
37
  "dependencies": {
37
38
  "cli-nano": "^1.2.1",
38
- "tinyglobby": "^0.2.14"
39
+ "tinyglobby": "^0.2.15"
39
40
  },
40
41
  "engines": {
41
42
  "node": "^20.0.0 || >=22.0.0"
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { existsSync, readdirSync, rmSync, statSync, unlinkSync } from 'node:fs';
2
- import { join, resolve } from 'node:path';
1
+ import { existsSync, rmSync, statSync, unlinkSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
3
  import { globSync } from 'tinyglobby';
4
4
 
5
5
  import type { RemoveOptions } from './interfaces.js';
@@ -32,7 +32,7 @@ export function removeSync(opts: RemoveOptions = {}, callback?: (e?: Error) => v
32
32
  }
33
33
  if (paths.length && opts.glob) {
34
34
  throwOrCallback(
35
- new Error('Providing both `--paths` and `--glob` pattern are not supported, you must provide only one of these options.'),
35
+ new Error('Providing both `--paths` and `--glob` pattern at the same time is not supported, you must chose only one.'),
36
36
  cb,
37
37
  );
38
38
  return;
@@ -51,8 +51,11 @@ export function removeSync(opts: RemoveOptions = {}, callback?: (e?: Error) => v
51
51
  ignore: ['**/.git/**', '**/node_modules/**'],
52
52
  });
53
53
  }
54
- opts.stat && console.time('Duration');
55
- opts.dryRun && console.log('=== dry-run ===');
54
+ if (opts.stat || opts.verbose) {
55
+ console.time('Duration');
56
+ }
57
+ // start dry-run print
58
+ opts.dryRun && console.log('-- dry-run --');
56
59
 
57
60
  paths.forEach(path => {
58
61
  // do we need to resolve file/dir from a different cwd?
@@ -61,24 +64,17 @@ export function removeSync(opts: RemoveOptions = {}, callback?: (e?: Error) => v
61
64
  }
62
65
 
63
66
  if (existsSync(path)) {
64
- if (statSync(path).isDirectory()) {
65
- // directories
66
- if (opts.dryRun) {
67
- console.log(`would remove directory: ${path}`);
68
- } else {
69
- opts.verbose && console.log(`removing directory: ${path}`);
70
- readdirSync(path).forEach(name => {
71
- removeSync({ paths: join(path, name) }); // recursively remove content
72
- });
73
- rmSync(path, { recursive: true, force: true, maxRetries: process.platform === 'win32' ? 10 : 0 });
74
- }
67
+ const isDir = statSync(path).isDirectory();
68
+ const pathLog = `${isDir ? 'directory' : 'file'}: ${path}`;
69
+
70
+ if (opts.dryRun) {
71
+ console.log(`would remove ${pathLog}`);
75
72
  } else {
76
- // files
77
- if (opts.dryRun) {
78
- console.log(`would remove file: ${path}`);
73
+ opts.verbose && console.log(`removing ${pathLog}`);
74
+ if (isDir) {
75
+ rmSync(path, { recursive: true, force: true, maxRetries: process.platform === 'win32' ? 10 : 0 }); // delete folder recursively
79
76
  } else {
80
- opts.verbose && console.log(`removing file: ${path}`);
81
- unlinkSync(path);
77
+ unlinkSync(path); // delete file
82
78
  }
83
79
  }
84
80
  pathExists = true;
@@ -89,7 +85,9 @@ export function removeSync(opts: RemoveOptions = {}, callback?: (e?: Error) => v
89
85
  console.log(`Removed: ${paths.length} items`);
90
86
  console.timeEnd('Duration');
91
87
  }
92
- opts.dryRun && console.log('=== dry-run ===');
93
- if (typeof cb === 'function') cb();
88
+
89
+ // end dry-run print & execute callback when defined
90
+ opts.dryRun && console.log('-- end --');
91
+ typeof cb === 'function' && cb();
94
92
  return pathExists;
95
93
  }