-
-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a `npm run benchmark` script.
- Loading branch information
Showing
13 changed files
with
892 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules | ||
/fixtures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { writeFile: writeFile_ } = require('fs') | ||
const writeFile = async (path, data) => new Promise((res, rej) => | ||
writeFile_(path, data, er => er ? rej(er) : res())) | ||
const mkdirp = require('mkdirp') | ||
const { resolve } = require('path') | ||
|
||
const create = async (path, start, end, maxDepth, depth = 0) => { | ||
await mkdirp(path) | ||
const promises = [] | ||
for (let i = start; i <= end; i++) { | ||
const c = String.fromCharCode(i) | ||
if (depth < maxDepth && (i-start >= depth)) | ||
await create(resolve(path, c), start, end, maxDepth, depth + 1) | ||
else | ||
promises.push(writeFile(resolve(path, c), c)) | ||
} | ||
await Promise.all(promises) | ||
return path | ||
} | ||
|
||
module.exports = async ({ start, end, depth, name }) => { | ||
const path = resolve(__dirname, 'fixtures', name, 'test') | ||
return await create(path, start.charCodeAt(0), end.charCodeAt(0), depth) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const cases = require('./rimrafs.js') | ||
const runTest = require('./run-test.js') | ||
const print = require('./print-results.js') | ||
|
||
const rimraf = require('../') | ||
const main = async () => { | ||
// cleanup first. since the windows impl works on all platforms, | ||
// use that. it's only relevant if the folder exists anyway. | ||
rimraf.sync(__dirname + '/fixtures') | ||
const results = {} | ||
for (const name of Object.keys(cases)) { | ||
results[name] = await runTest(name) | ||
} | ||
rimraf.sync(__dirname + '/fixtures') | ||
return results | ||
} | ||
|
||
main().then(print) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# v3.0 | ||
|
||
- Add `--preserve-root` option to executable (default true) | ||
- Drop support for Node.js below version 6 | ||
|
||
# v2.7 | ||
|
||
- Make `glob` an optional dependency | ||
|
||
# 2.6 | ||
|
||
- Retry on EBUSY on non-windows platforms as well | ||
- Make `rimraf.sync` 10000% more reliable on Windows | ||
|
||
# 2.5 | ||
|
||
- Handle Windows EPERM when lstat-ing read-only dirs | ||
- Add glob option to pass options to glob | ||
|
||
# 2.4 | ||
|
||
- Add EPERM to delay/retry loop | ||
- Add `disableGlob` option | ||
|
||
# 2.3 | ||
|
||
- Make maxBusyTries and emfileWait configurable | ||
- Handle weird SunOS unlink-dir issue | ||
- Glob the CLI arg for better Windows support | ||
|
||
# 2.2 | ||
|
||
- Handle ENOENT properly on Windows | ||
- Allow overriding fs methods | ||
- Treat EPERM as indicative of non-empty dir | ||
- Remove optional graceful-fs dep | ||
- Consistently return null error instead of undefined on success | ||
- win32: Treat ENOTEMPTY the same as EBUSY | ||
- Add `rimraf` binary | ||
|
||
# 2.1 | ||
|
||
- Fix SunOS error code for a non-empty directory | ||
- Try rmdir before readdir | ||
- Treat EISDIR like EPERM | ||
- Remove chmod | ||
- Remove lstat polyfill, node 0.7 is not supported | ||
|
||
# 2.0 | ||
|
||
- Fix myGid call to check process.getgid | ||
- Simplify the EBUSY backoff logic. | ||
- Use fs.lstat in node >= 0.7.9 | ||
- Remove gently option | ||
- remove fiber implementation | ||
- Delete files that are marked read-only | ||
|
||
# 1.0 | ||
|
||
- Allow ENOENT in sync method | ||
- Throw when no callback is provided | ||
- Make opts.gently an absolute path | ||
- use 'stat' if 'lstat' is not available | ||
- Consistent error naming, and rethrow non-ENOENT stat errors | ||
- add fiber implementation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
The ISC License | ||
|
||
Copyright (c) Isaac Z. Schlueter and Contributors | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
[![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. | ||
|
||
Install with `npm install rimraf`, or just drop rimraf.js somewhere. | ||
|
||
## API | ||
|
||
`rimraf(f, [opts], callback)` | ||
|
||
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. | ||
|
||
The callback will be called with an error if there is one. Certain | ||
errors are handled for you: | ||
|
||
* 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. | ||
|
||
## options | ||
|
||
* unlink, chmod, stat, lstat, rmdir, readdir, | ||
unlinkSync, chmodSync, statSync, lstatSync, rmdirSync, readdirSync | ||
|
||
In order to use a custom file system library, you can override | ||
specific fs functions on the options object. | ||
|
||
If any of these functions are present on the options object, then | ||
the supplied function will be used instead of the default fs | ||
method. | ||
|
||
Sync methods are only relevant for `rimraf.sync()`, of course. | ||
|
||
For example: | ||
|
||
```javascript | ||
var myCustomFS = require('some-custom-fs') | ||
|
||
rimraf('some-thing', myCustomFS, callback) | ||
``` | ||
|
||
* maxBusyTries | ||
|
||
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. | ||
|
||
Only relevant for async usage. | ||
|
||
* emfileWait | ||
|
||
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. | ||
|
||
If you repeatedly encounter `EMFILE` errors, then consider using | ||
[graceful-fs](http://npm.im/graceful-fs) in your program. | ||
|
||
Only relevant for async usage. | ||
|
||
* glob | ||
|
||
Set to `false` to disable [glob](http://npm.im/glob) pattern | ||
matching. | ||
|
||
Set to an object to pass options to the glob module. The default | ||
glob options are `{ nosort: true, silent: true }`. | ||
|
||
Glob version 6 is used in this module. | ||
|
||
Relevant for both sync and async usage. | ||
|
||
* disableGlob | ||
|
||
Set to any non-falsey value to disable globbing entirely. | ||
(Equivalent to setting `glob: false`.) | ||
|
||
## rimraf.sync | ||
|
||
It can remove stuff synchronously, too. But that's not so good. Use | ||
the async API. It's better. | ||
|
||
## CLI | ||
|
||
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. | ||
|
||
## mkdirp | ||
|
||
If you need to create a directory recursively, check out | ||
[mkdirp](https://github.com/substack/node-mkdirp). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env node | ||
|
||
const rimraf = require('./') | ||
|
||
const path = require('path') | ||
|
||
const isRoot = arg => /^(\/|[a-zA-Z]:\\)$/.test(path.resolve(arg)) | ||
const filterOutRoot = arg => { | ||
const ok = preserveRoot === false || !isRoot(arg) | ||
if (!ok) { | ||
console.error(`refusing to remove ${arg}`) | ||
console.error('Set --no-preserve-root to allow this') | ||
} | ||
return ok | ||
} | ||
|
||
let help = false | ||
let dashdash = false | ||
let noglob = false | ||
let preserveRoot = true | ||
const args = process.argv.slice(2).filter(arg => { | ||
if (dashdash) | ||
return !!arg | ||
else if (arg === '--') | ||
dashdash = true | ||
else if (arg === '--no-glob' || arg === '-G') | ||
noglob = true | ||
else if (arg === '--glob' || arg === '-g') | ||
noglob = false | ||
else if (arg.match(/^(-+|\/)(h(elp)?|\?)$/)) | ||
help = true | ||
else if (arg === '--preserve-root') | ||
preserveRoot = true | ||
else if (arg === '--no-preserve-root') | ||
preserveRoot = false | ||
else | ||
return !!arg | ||
}).filter(arg => !preserveRoot || filterOutRoot(arg)) | ||
|
||
const go = n => { | ||
if (n >= args.length) | ||
return | ||
const options = noglob ? { glob: false } : {} | ||
rimraf(args[n], options, er => { | ||
if (er) | ||
throw er | ||
go(n+1) | ||
}) | ||
} | ||
|
||
if (help || args.length === 0) { | ||
// If they didn't ask for help, then this is not a "success" | ||
const log = help ? console.log : console.error | ||
log('Usage: rimraf <path> [<path> ...]') | ||
log('') | ||
log(' Deletes all files and folders at "path" recursively.') | ||
log('') | ||
log('Options:') | ||
log('') | ||
log(' -h, --help Display this usage info') | ||
log(' -G, --no-glob Do not expand glob patterns in arguments') | ||
log(' -g, --glob Expand glob patterns in arguments (default)') | ||
log(' --preserve-root Do not remove \'/\' (default)') | ||
log(' --no-preserve-root Do not treat \'/\' specially') | ||
log(' -- Stop parsing flags') | ||
process.exit(help ? 0 : 1) | ||
} else | ||
go(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "rimraf", | ||
"version": "3.0.2", | ||
"main": "rimraf.js", | ||
"description": "A deep deletion module for node (like `rm -rf`)", | ||
"author": "Isaac Z. Schlueter <[email protected]> (http://blog.izs.me/)", | ||
"license": "ISC", | ||
"repository": "git://github.com/isaacs/rimraf.git", | ||
"scripts": { | ||
"preversion": "npm test", | ||
"postversion": "npm publish", | ||
"postpublish": "git push origin --follow-tags", | ||
"test": "tap test/*.js" | ||
}, | ||
"bin": "./bin.js", | ||
"dependencies": { | ||
"glob": "^7.1.3" | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"bin.js", | ||
"rimraf.js" | ||
], | ||
"devDependencies": { | ||
"mkdirp": "^0.5.1", | ||
"tap": "^12.1.1" | ||
}, | ||
"funding": { | ||
"url": "https://github.com/sponsors/isaacs" | ||
} | ||
} |
Oops, something went wrong.