index.js 692 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 16.7.0 added fs.cp
  6. const useNative = node.satisfies('>=16.7.0')
  7. const cp = async (src, dest, opts) => {
  8. const options = getOptions(opts, {
  9. copy: ['dereference', 'errorOnExist', 'filter', 'force', 'preserveTimestamps', 'recursive'],
  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.cp(src, dest, options)
  16. : polyfill(src, dest, options)
  17. }
  18. module.exports = cp