@@ -22,8 +22,8 @@ const {
22
22
ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY ,
23
23
ERR_FS_CP_UNKNOWN ,
24
24
ERR_FS_EISDIR ,
25
- } = require ( '../errors.js' )
26
-
25
+ ERR_INVALID_ARG_TYPE ,
26
+ } = require ( '../errors.js' ) ;
27
27
const {
28
28
constants : {
29
29
errno : {
@@ -33,7 +33,7 @@ const {
33
33
ENOTDIR ,
34
34
}
35
35
}
36
- } = require ( 'os' )
36
+ } = require ( 'os' ) ;
37
37
const {
38
38
chmod,
39
39
copyFile,
@@ -53,9 +53,37 @@ const {
53
53
parse,
54
54
resolve,
55
55
sep,
56
+ toNamespacedPath,
56
57
} = require ( 'path' ) ;
58
+ const { fileURLToPath } = require ( 'url' ) ;
59
+
60
+ const defaultOptions = {
61
+ dereference : false ,
62
+ errorOnExist : false ,
63
+ filter : undefined ,
64
+ force : true ,
65
+ preserveTimestamps : false ,
66
+ recursive : false ,
67
+ } ;
57
68
58
69
async function cp ( src , dest , opts ) {
70
+ if ( opts != undefined && typeof opts !== 'object' ) {
71
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'Object' ] , opts ) ;
72
+ }
73
+ return cpFn (
74
+ toNamespacedPath ( getValidatedPath ( src ) ) ,
75
+ toNamespacedPath ( getValidatedPath ( dest ) ) ,
76
+ { ...defaultOptions , ...opts } ) ;
77
+ }
78
+
79
+ function getValidatedPath ( fileURLOrPath ) {
80
+ const path = fileURLOrPath != null && fileURLOrPath . href && fileURLOrPath . origin
81
+ ? fileURLToPath ( fileURLOrPath )
82
+ : fileURLOrPath
83
+ return path ;
84
+ }
85
+
86
+ async function cpFn ( src , dest , opts ) {
59
87
// Warn about using preserveTimestamps on 32-bit node
60
88
if ( opts . preserveTimestamps && process . arch === 'ia32' ) {
61
89
const warning = 'Using the preserveTimestamps option in 32-bit ' +
0 commit comments