index.js 695 B

12345678910111213141516171819202122
  1. const fs = require('../fs.js')
  2. const getOptions = require('../common/get-options.js')
  3. const node = require('../common/node.js')
  4. const polyfill = require('./polyfill.js')
  5. // node 14.14.0 added fs.rm, which allows both the force and recursive options
  6. const useNative = node.satisfies('>=14.14.0')
  7. const rm = async (path, opts) => {
  8. const options = getOptions(opts, {
  9. copy: ['retryDelay', 'maxRetries', 'recursive', 'force'],
  10. })
  11. // the polyfill is tested separately from this module, no need to hack
  12. // process.version to try to trigger it just for coverage
  13. // istanbul ignore next
  14. return useNative
  15. ? fs.rm(path, options)
  16. : polyfill(path, options)
  17. }
  18. module.exports = rm