copy
copy copied to clipboard
Weird behaviour if first glob in array is using '**'.
if I do a thing like
const copy = require('copy');
const files = ['dist/**/*','README.md','LICENSE.md'];
copy(files, '/tmp/folder', (err, files) => {
// handle result here
})
Result :
-
README.md
andLICENSE.md
are located in/tmp
- The content of the
dist
folder is in '/tmp/folder'
Should be :
-
README.md
andLICENSE.md
are located in/tmp/folder
- The content of the
dist
folder is in/tmp/folder/dist
Note that the order of the globs is important as if i declare it like :
const files = ['README.md','LICENSE.md','dist/**/*'];
It behaves as intended.
strange, I'll look into it. I'm guessing it has to do with how the glob parent is created. thanks for the issue
Honestly, I just switched to using vinyl-fs.
const vfs = require('vinyl-fs');
function copyFiles(glob, dest) {
return new Promise((resolve, reject) => {
// the base is important, if not set it will put all
// files directly in the 'dest' folder
const stream = vfs.src(glob, { base: '.' })
.pipe(vfs.dest(dest));
stream.on('finish', () => {
resolve();
});
stream.on('error', (error) => {
reject(err);
});
});
}
Honestly, I just switched to using vinyl-fs.
That's great. we use vinyl-fs quite a lot, and we contribute a lot to that ecosystem (gulp and vinyl). It's a bit overkill for simple copying, but I don't blame you after having issues with this lib.
FYI for anyone that comes across this issue... You can set the srcBase
option to specify the base
property used when creating file objects. This is similar to setting the base
option on vfs.src
in the example above.
updated example from original comment
const copy = require('copy');
const files = ['dist/**/*','README.md','LICENSE.md'];
copy(files, '/tmp/folder', {srcBase: '.'}, (err, files) => {
// handle result here
})
I'm going to keep this open for now since this is something we need to update in the documentation.