Skip to content

Commit 496205f

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 0d42518 commit 496205f

File tree

4 files changed

+436
-0
lines changed

4 files changed

+436
-0
lines changed

LICENSE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,22 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
1616
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1717
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
1818
USE OR PERFORMANCE OF THIS SOFTWARE.
19+
20+
- node-fs-extra, located at lib/cp/polyfill.js, is licensed as follows:
21+
"""
22+
(The MIT License)
23+
24+
Copyright (c) 2011-2017 JP Richardson
25+
26+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
27+
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
28+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
29+
furnished to do so, subject to the following conditions:
30+
31+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32+
33+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
34+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
35+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
36+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37+
"""

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)