Skip to content

Commit ba14028

Browse files
committed
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
1 parent f11b6a3 commit ba14028

File tree

4 files changed

+432
-0
lines changed

4 files changed

+432
-0
lines changed

lib/cp/LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2011-2017 JP Richardson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
6+
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
7+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11+
12+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
14+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
15+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

lib/cp/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
6+
// node 16.7.0 added fs.cp
7+
const useNative = node.satisfies('>=16.7.0')
8+
9+
const rm = async (path, opts) => {
10+
const options = getOptions(opts, {
11+
copy: ['dereference', 'errorOnExist', 'filter', 'force', 'preserveTimestamps', 'recursive'],
12+
})
13+
14+
// the polyfill is tested separately from this module, no need to hack
15+
// process.version to try to trigger it just for coverage
16+
// istanbul ignore next
17+
return useNative
18+
? fs.rm(path, options)
19+
: polyfill(path, options)
20+
}
21+
22+
module.exports = rm

0 commit comments

Comments
 (0)