mysticatea / cpx

A cli tool to watch and copy file globs.
MIT License
524 stars 36 forks source link

Throws ENOENT when dest is in tmpdir #60

Open nandenjin opened 4 years ago

nandenjin commented 4 years ago

Internally dest path is converted to relative one by normalizePath() but it make fs.open() failed when dest is in tmpdir.

Sample

Environment

Code

const os = require('os')
const cpx = require('cpx')

cpx.copySync('*.js', os.tmpdir())

Result

$ node tester.js
fs.js:114
    throw err;
    ^

Error: ENOENT: no such file or directory, copyfile 'tester.js' -> '../../../../../var/folders/1h/chh659g57sg3v_wks3v7z43h0000gn/T/tester.js'
    at Object.copyFileSync (fs.js:1723:3)
    at copyFile (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:68:8)
    at onFile (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:52:41)
    at getStats (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:47:39)
    at startCopy (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:37:10)
    at Object.copySync (/Users/nandenjin/sample_package/node_modules/cpx/node_modules/fs-extra/lib/copy-sync/copy-sync.js:32:10)
    at copyFileSync (/Users/nandenjin/sample_package/node_modules/cpx/lib/utils/copy-file-sync.js:50:12)
    at sourcePath (/Users/nandenjin/sample_package/node_modules/cpx/lib/copy-sync.js:63:13)
    at applyActionSync (/Users/nandenjin/sample_package/node_modules/cpx/lib/utils/apply-action-sync.js:36:9)
    at Object.copySync (/Users/nandenjin/sample_package/node_modules/cpx/lib/copy-sync.js:60:5)