Closed geekflyer closed 7 years ago
I also just checked the implementation of gulp.dest / vfs.dest and indeed they're calling mkdirp before every file write. There is a function prepareWrite
that is called before every single vinyl file is written and inside that prepareWrite is a mkdirp: https://github.com/gulpjs/vinyl-fs/blob/master/lib/prepare-write.js#L52
Thanks! Fixed directory handling in cdcca64393873db20f3c1f45e5b10345fd1f3f40 and a07f24c90e54ec7e20ff19268c278d30e3d46db5 (no longer relying on vinyl directories).
@turtlemay
let's say I have the following folder structure:
and the following gulp task:
This will fail with the following error:
This because gulp-mem does not handle / create subdirectories properly before attempting to write a file into it.
The root cause is basically here: https://github.com/turtlemay/gulp-mem/blob/master/index.js#L40-L44
The
if
branch to create an in memory directory is only reached whenfile.isBuffer() === true
. However a directory is never a buffer, so effectively gulp-mem will never ever create a subdirectory and the branch is basically currently unreachable code. Even if the if-condition is fixed I think you should not rely on vinyl directories being passed at all to the plugin (some plugins which generate completely new files in virtual subdirectories don't create the corresponding folders as vinyl file). Instead you should just automatically create the subdirectories for every file, by callingfs.mkdirpSync
before every file is being written. This will be closer to how gulp.dest behaves against a real file system.