You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.5 KiB

4 years ago
  1. [![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)
  2. The [UNIX command](http://en.wikipedia.org/wiki/Rm_(Unix)) `rm -rf` for node.
  3. Install with `npm install rimraf`, or just drop rimraf.js somewhere.
  4. ## API
  5. `rimraf(f, [opts], callback)`
  6. The first parameter will be interpreted as a globbing pattern for files. If you
  7. want to disable globbing you can do so with `opts.disableGlob` (defaults to
  8. `false`). This might be handy, for instance, if you have filenames that contain
  9. globbing wildcard characters.
  10. The callback will be called with an error if there is one. Certain
  11. errors are handled for you:
  12. * Windows: `EBUSY` and `ENOTEMPTY` - rimraf will back off a maximum of
  13. `opts.maxBusyTries` times before giving up, adding 100ms of wait
  14. between each attempt. The default `maxBusyTries` is 3.
  15. * `ENOENT` - If the file doesn't exist, rimraf will return
  16. successfully, since your desired outcome is already the case.
  17. * `EMFILE` - Since `readdir` requires opening a file descriptor, it's
  18. possible to hit `EMFILE` if too many file descriptors are in use.
  19. In the sync case, there's nothing to be done for this. But in the
  20. async case, rimraf will gradually back off with timeouts up to
  21. `opts.emfileWait` ms, which defaults to 1000.
  22. ## options
  23. * unlink, chmod, stat, lstat, rmdir, readdir,
  24. unlinkSync, chmodSync, statSync, lstatSync, rmdirSync, readdirSync
  25. In order to use a custom file system library, you can override
  26. specific fs functions on the options object.
  27. If any of these functions are present on the options object, then
  28. the supplied function will be used instead of the default fs
  29. method.
  30. Sync methods are only relevant for `rimraf.sync()`, of course.
  31. For example:
  32. ```javascript
  33. var myCustomFS = require('some-custom-fs')
  34. rimraf('some-thing', myCustomFS, callback)
  35. ```
  36. * maxBusyTries
  37. If an `EBUSY`, `ENOTEMPTY`, or `EPERM` error code is encountered
  38. on Windows systems, then rimraf will retry with a linear backoff
  39. wait of 100ms longer on each try. The default maxBusyTries is 3.
  40. Only relevant for async usage.
  41. * emfileWait
  42. If an `EMFILE` error is encountered, then rimraf will retry
  43. repeatedly with a linear backoff of 1ms longer on each try, until
  44. the timeout counter hits this max. The default limit is 1000.
  45. If you repeatedly encounter `EMFILE` errors, then consider using
  46. [graceful-fs](http://npm.im/graceful-fs) in your program.
  47. Only relevant for async usage.
  48. * glob
  49. Set to `false` to disable [glob](http://npm.im/glob) pattern
  50. matching.
  51. Set to an object to pass options to the glob module. The default
  52. glob options are `{ nosort: true, silent: true }`.
  53. Glob version 6 is used in this module.
  54. Relevant for both sync and async usage.
  55. * disableGlob
  56. Set to any non-falsey value to disable globbing entirely.
  57. (Equivalent to setting `glob: false`.)
  58. ## rimraf.sync
  59. It can remove stuff synchronously, too. But that's not so good. Use
  60. the async API. It's better.
  61. ## CLI
  62. If installed with `npm install rimraf -g` it can be used as a global
  63. command `rimraf <path> [<path> ...]` which is useful for cross platform support.
  64. ## mkdirp
  65. If you need to create a directory recursively, check out
  66. [mkdirp](https://github.com/substack/node-mkdirp).