forked from npm/fs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cp): initial commit of cp from node
I need `fs.cp` in `npm copy` to copy node_modules files. I'm adapting node's [lib/internal/fs/cp/cp.js][0]. I'm checking in the original so I can record changes in git. ref npm/cli#4082 [0]: https://github.com/nodejs/node/blob/1fa507f098ca7a89012f76f0c849fa698e73a1a1/lib/internal/fs/cp/cp.js
- Loading branch information
Caleb ツ Everett
committed
Dec 6, 2021
1 parent
0d42518
commit 496205f
Showing
4 changed files
with
436 additions
and
0 deletions.
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
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,22 @@ | ||
const fs = require('../fs.js') | ||
const getOptions = require('../common/get-options.js') | ||
const node = require('../common/node.js') | ||
const polyfill = require('./polyfill.js') | ||
|
||
// node 16.7.0 added fs.cp | ||
const useNative = node.satisfies('>=16.7.0') | ||
|
||
const rm = async (path, opts) => { | ||
const options = getOptions(opts, { | ||
copy: ['dereference', 'errorOnExist', 'filter', 'force', 'preserveTimestamps', 'recursive'], | ||
}) | ||
|
||
// the polyfill is tested separately from this module, no need to hack | ||
// process.version to try to trigger it just for coverage | ||
// istanbul ignore next | ||
return useNative | ||
? fs.rm(path, options) | ||
: polyfill(path, options) | ||
} | ||
|
||
module.exports = rm |
Oops, something went wrong.