Comparing version 3.0.2 to 5.0.0
{ | ||
"name": "rimraf", | ||
"version": "3.0.2", | ||
"main": "rimraf.js", | ||
"version": "5.0.0", | ||
"main": "./dist/cjs/src/index.js", | ||
"module": "./dist/mjs/index.js", | ||
"types": "./dist/mjs/index.d.ts", | ||
"bin": "./dist/cjs/src/bin.js", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/mjs/index.d.ts", | ||
"default": "./dist/mjs/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/cjs/src/index.d.ts", | ||
"default": "./dist/cjs/src/index.js" | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"description": "A deep deletion module for node (like `rm -rf`)", | ||
@@ -12,22 +30,56 @@ "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", | ||
"postversion": "npm publish", | ||
"postpublish": "git push origin --follow-tags", | ||
"test": "tap test/*.js" | ||
"prepublishOnly": "git push origin --follow-tags", | ||
"preprepare": "rm -rf dist", | ||
"prepare": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json", | ||
"postprepare": "bash fixup.sh", | ||
"pretest": "npm run prepare", | ||
"presnap": "npm run prepare", | ||
"test": "c8 tap", | ||
"snap": "c8 tap", | ||
"format": "prettier --write . --loglevel warn", | ||
"benchmark": "node benchmark/index.js", | ||
"typedoc": "typedoc --tsconfig tsconfig-esm.json ./src/*.ts" | ||
}, | ||
"bin": "./bin.js", | ||
"dependencies": { | ||
"glob": "^7.1.3" | ||
"prettier": { | ||
"semi": false, | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"jsxSingleQuote": false, | ||
"bracketSameLine": true, | ||
"arrowParens": "avoid", | ||
"endOfLine": "lf" | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"bin.js", | ||
"rimraf.js" | ||
], | ||
"devDependencies": { | ||
"mkdirp": "^0.5.1", | ||
"tap": "^12.1.1" | ||
"@types/node": "^18.11.9", | ||
"@types/tap": "^15.0.7", | ||
"c8": "^7.12.0", | ||
"eslint-config-prettier": "^8.6.0", | ||
"mkdirp": "^3.0.0", | ||
"prettier": "^2.8.2", | ||
"tap": "^16.3.4", | ||
"ts-node": "^10.9.1", | ||
"typedoc": "^0.23.21", | ||
"typescript": "^5.0.4" | ||
}, | ||
"tap": { | ||
"coverage": false, | ||
"libtap-settings": "libtap-settings.js", | ||
"node-arg": [ | ||
"--no-warnings", | ||
"--loader", | ||
"ts-node/esm" | ||
], | ||
"ts": false | ||
}, | ||
"funding": { | ||
"url": "https://github.com/sponsors/isaacs" | ||
}, | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"dependencies": { | ||
"glob": "^10.0.0" | ||
} | ||
} |
237
README.md
@@ -1,101 +0,210 @@ | ||
[![Build Status](https://travis-ci.org/isaacs/rimraf.svg?branch=master)](https://travis-ci.org/isaacs/rimraf) [![Dependency Status](https://david-dm.org/isaacs/rimraf.svg)](https://david-dm.org/isaacs/rimraf) [![devDependency Status](https://david-dm.org/isaacs/rimraf/dev-status.svg)](https://david-dm.org/isaacs/rimraf#info=devDependencies) | ||
The [UNIX command](<http://en.wikipedia.org/wiki/Rm_(Unix)>) `rm -rf` for node. | ||
The [UNIX command](http://en.wikipedia.org/wiki/Rm_(Unix)) `rm -rf` for node. | ||
Install with `npm install rimraf`. | ||
Install with `npm install rimraf`, or just drop rimraf.js somewhere. | ||
## Major Changes from v3 to v4 | ||
- The function returns a `Promise` instead of taking a callback. | ||
- Globbing requires the `--glob` option to be set. (Removed in | ||
4.0 and 4.1, opt-in support added in 4.2.) | ||
- Functions take arrays of paths, as well as a single path. | ||
- Native implementation used by default when available, except on | ||
Windows, where this implementation is faster and more reliable. | ||
- New implementation on Windows, falling back to "move then | ||
remove" strategy when exponential backoff for `EBUSY` fails to | ||
resolve the situation. | ||
- Simplified implementation on Posix, since the Windows | ||
affordances are not necessary there. | ||
- As of 4.3, return/resolve value is boolean instead of undefined | ||
## API | ||
`rimraf(f, [opts], callback)` | ||
Hybrid module, load either with `import` or `require()`. | ||
The first parameter will be interpreted as a globbing pattern for files. If you | ||
want to disable globbing you can do so with `opts.disableGlob` (defaults to | ||
`false`). This might be handy, for instance, if you have filenames that contain | ||
globbing wildcard characters. | ||
```js | ||
// 'rimraf' export is the one you probably want, but other | ||
// strategies exported as well. | ||
import { rimraf, rimrafSync, native, nativeSync } from 'rimraf' | ||
// or | ||
const { rimraf, rimrafSync, native, nativeSync } = require('rimraf') | ||
``` | ||
The callback will be called with an error if there is one. Certain | ||
errors are handled for you: | ||
All removal functions return a boolean indicating that all | ||
entries were successfully removed. | ||
* Windows: `EBUSY` and `ENOTEMPTY` - rimraf will back off a maximum of | ||
`opts.maxBusyTries` times before giving up, adding 100ms of wait | ||
between each attempt. The default `maxBusyTries` is 3. | ||
* `ENOENT` - If the file doesn't exist, rimraf will return | ||
successfully, since your desired outcome is already the case. | ||
* `EMFILE` - Since `readdir` requires opening a file descriptor, it's | ||
possible to hit `EMFILE` if too many file descriptors are in use. | ||
In the sync case, there's nothing to be done for this. But in the | ||
async case, rimraf will gradually back off with timeouts up to | ||
`opts.emfileWait` ms, which defaults to 1000. | ||
The only case in which this will not return `true` is if | ||
something was omitted from the removal via a `filter` option. | ||
## options | ||
### `rimraf(f, [opts]) -> Promise` | ||
* unlink, chmod, stat, lstat, rmdir, readdir, | ||
unlinkSync, chmodSync, statSync, lstatSync, rmdirSync, readdirSync | ||
This first parameter is a path or array of paths. The second | ||
argument is an options object. | ||
In order to use a custom file system library, you can override | ||
specific fs functions on the options object. | ||
Options: | ||
If any of these functions are present on the options object, then | ||
the supplied function will be used instead of the default fs | ||
method. | ||
- `preserveRoot`: If set to boolean `false`, then allow the | ||
recursive removal of the root directory. Otherwise, this is | ||
not allowed. | ||
- `tmp`: Windows only. Temp folder to use to place files and | ||
folders for the "move then remove" fallback. Must be on the | ||
same physical device as the path being deleted. Defaults to | ||
`os.tmpdir()` when that is on the same drive letter as the path | ||
being deleted, or `${drive}:\temp` if present, or `${drive}:\` | ||
if not. | ||
- `maxRetries`: Windows and Native only. Maximum number of | ||
retry attempts in case of `EBUSY`, `EMFILE`, and `ENFILE` | ||
errors. Default `10` for Windows implementation, `0` for Native | ||
implementation. | ||
- `backoff`: Windows only. Rate of exponential backoff for async | ||
removal in case of `EBUSY`, `EMFILE`, and `ENFILE` errors. | ||
Should be a number greater than 1. Default `1.2` | ||
- `maxBackoff`: Windows only. Maximum total backoff time in ms to | ||
attempt asynchronous retries in case of `EBUSY`, `EMFILE`, and | ||
`ENFILE` errors. Default `200`. With the default `1.2` backoff | ||
rate, this results in 14 retries, with the final retry being | ||
delayed 33ms. | ||
- `retryDelay`: Native only. Time to wait between retries, using | ||
linear backoff. Default `100`. | ||
- `signal` Pass in an AbortSignal to cancel the directory | ||
removal. This is useful when removing large folder structures, | ||
if you'd like to limit the amount of time spent. | ||
Sync methods are only relevant for `rimraf.sync()`, of course. | ||
Using a `signal` option prevents the use of Node's built-in | ||
`fs.rm` because that implementation does not support abort | ||
signals. | ||
For example: | ||
- `filter` Method that returns a boolean indicating whether that | ||
path should be deleted. With async rimraf methods, this may | ||
return a Promise that resolves to a boolean. (Since Promises | ||
are truthy, returning a Promise from a sync filter is the same | ||
as just not filtering anything.) | ||
```javascript | ||
var myCustomFS = require('some-custom-fs') | ||
The first argument to the filter is the path string. The | ||
second argument is either a `Dirent` or `Stats` object for that | ||
path. (The first path explored will be a `Stats`, the rest | ||
will be `Dirent`.) | ||
rimraf('some-thing', myCustomFS, callback) | ||
``` | ||
If a filter method is provided, it will _only_ remove entries | ||
if the filter returns (or resolves to) a truthy value. Omitting | ||
a directory will still allow its children to be removed, unless | ||
they are also filtered out, but any parents of a filtered entry | ||
will not be removed, since the directory would not be empty in | ||
that case. | ||
* maxBusyTries | ||
Using a filter method prevents the use of Node's built-in | ||
`fs.rm` because that implementation does not support filtering. | ||
If an `EBUSY`, `ENOTEMPTY`, or `EPERM` error code is encountered | ||
on Windows systems, then rimraf will retry with a linear backoff | ||
wait of 100ms longer on each try. The default maxBusyTries is 3. | ||
Any other options are provided to the native Node.js `fs.rm` implementation | ||
when that is used. | ||
Only relevant for async usage. | ||
This will attempt to choose the best implementation, based on Node.js | ||
version and `process.platform`. To force a specific implementation, use | ||
one of the other functions provided. | ||
* emfileWait | ||
### `rimraf.sync(f, [opts])` `rimraf.rimrafSync(f, [opts])` | ||
If an `EMFILE` error is encountered, then rimraf will retry | ||
repeatedly with a linear backoff of 1ms longer on each try, until | ||
the timeout counter hits this max. The default limit is 1000. | ||
Synchronous form of `rimraf()` | ||
If you repeatedly encounter `EMFILE` errors, then consider using | ||
[graceful-fs](http://npm.im/graceful-fs) in your program. | ||
Note that, unlike many file system operations, the synchronous form will | ||
typically be significantly _slower_ than the async form, because recursive | ||
deletion is extremely parallelizable. | ||
Only relevant for async usage. | ||
### `rimraf.native(f, [opts])` | ||
* glob | ||
Uses the built-in `fs.rm` implementation that Node.js provides. This is | ||
used by default on Node.js versions greater than or equal to `14.14.0`. | ||
Set to `false` to disable [glob](http://npm.im/glob) pattern | ||
matching. | ||
### `rimraf.nativeSync(f, [opts])` `rimraf.native.sync(f, [opts])` | ||
Set to an object to pass options to the glob module. The default | ||
glob options are `{ nosort: true, silent: true }`. | ||
Synchronous form of `rimraf.native` | ||
Glob version 6 is used in this module. | ||
### `rimraf.manual(f, [opts])` | ||
Relevant for both sync and async usage. | ||
Use the JavaScript implementation appropriate for your operating system. | ||
* disableGlob | ||
### `rimraf.manualSync(f, [opts])` `rimraf.manualSync(f, opts)` | ||
Set to any non-falsey value to disable globbing entirely. | ||
(Equivalent to setting `glob: false`.) | ||
Synchronous form of `rimraf.manual()` | ||
## rimraf.sync | ||
### `rimraf.windows(f, [opts])` | ||
It can remove stuff synchronously, too. But that's not so good. Use | ||
the async API. It's better. | ||
JavaScript implementation of file removal appropriate for Windows | ||
platforms. Works around `unlink` and `rmdir` not being atomic | ||
operations, and `EPERM` when deleting files with certain | ||
permission modes. | ||
## CLI | ||
First deletes all non-directory files within the tree, and then | ||
removes all directories, which should ideally be empty by that | ||
time. When an `ENOTEMPTY` is raised in the second pass, falls | ||
back to the `rimraf.moveRemove` strategy as needed. | ||
If installed with `npm install rimraf -g` it can be used as a global | ||
command `rimraf <path> [<path> ...]` which is useful for cross platform support. | ||
### `rimraf.windows.sync(path, [opts])` `rimraf.windowsSync(path, [opts])` | ||
Synchronous form of `rimraf.windows()` | ||
### `rimraf.moveRemove(path, [opts])` | ||
Moves all files and folders to the parent directory of `path` | ||
with a temporary filename prior to attempting to remove them. | ||
Note that, in cases where the operation fails, this _may_ leave | ||
files lying around in the parent directory with names like | ||
`.file-basename.txt.0.123412341`. Until the Windows kernel | ||
provides a way to perform atomic `unlink` and `rmdir` operations, | ||
this is unfortunately unavoidable. | ||
To move files to a different temporary directory other than the | ||
parent, provide `opts.tmp`. Note that this _must_ be on the same | ||
physical device as the folder being deleted, or else the | ||
operation will fail. | ||
This is the slowest strategy, but most reliable on Windows | ||
platforms. Used as a last-ditch fallback by `rimraf.windows()`. | ||
### `rimraf.moveRemove.sync(path, [opts])` `rimraf.moveRemoveSync(path, [opts])` | ||
Synchronous form of `rimraf.moveRemove()` | ||
### Command Line Interface | ||
``` | ||
rimraf version 4.3.0 | ||
Usage: rimraf <path> [<path> ...] | ||
Deletes all files and folders at "path", recursively. | ||
Options: | ||
-- Treat all subsequent arguments as paths | ||
-h --help Display this usage info | ||
--preserve-root Do not remove '/' recursively (default) | ||
--no-preserve-root Do not treat '/' specially | ||
-G --no-glob Treat arguments as literal paths, not globs (default) | ||
-g --glob Treat arguments as glob patterns | ||
-v --verbose Be verbose when deleting files, showing them as | ||
they are removed. Not compatible with --impl=native | ||
-V --no-verbose Be silent when deleting files, showing nothing as | ||
they are removed (default) | ||
-i --interactive Ask for confirmation before deleting anything | ||
Not compatible with --impl=native | ||
-I --no-interactive Do not ask for confirmation before deleting | ||
--impl=<type> Specify the implementation to use: | ||
rimraf: choose the best option (default) | ||
native: the built-in implementation in Node.js | ||
manual: the platform-specific JS implementation | ||
posix: the Posix JS implementation | ||
windows: the Windows JS implementation (falls back to | ||
move-remove on ENOTEMPTY) | ||
move-remove: a slow reliable Windows fallback | ||
Implementation-specific options: | ||
--tmp=<path> Temp file folder for 'move-remove' implementation | ||
--max-retries=<n> maxRetries for 'native' and 'windows' implementations | ||
--retry-delay=<n> retryDelay for 'native' implementation, default 100 | ||
--backoff=<n> Exponential backoff factor for retries (default: 1.2) | ||
``` | ||
## mkdirp | ||
If you need to create a directory recursively, check out | ||
[mkdirp](https://github.com/substack/node-mkdirp). | ||
If you need to _create_ a directory recursively, check out | ||
[mkdirp](https://github.com/isaacs/node-mkdirp). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
277335
137
2431
0
211
10
10
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedglob@^10.0.0