Search code examples
node.jstypescriptgulp

gulp 4.0 allowEmpty : true is not working for empty array


gulp.task("f1", () => {
    gulp.src([], {"allowEmpty": true})
    .pipe(gulp.dest(location));
})

Error: Invalid glob argument: is thrown for the above snippet

gulp.task("f1", () => {
    gulp.src("[]", {"allowEmpty": true})
    .pipe(gulp.dest(location));
})

whereas, it is working fine. Is this the expected behaviour ? Anyway to use allowEmpty for empty array ?

Anyhow the issue can be solved by skipping the task for empty array, just wondering is there any proper way to use allowEmpty for empty array.

Any suggestion would be helpful. Thanks in advance


Solution

  • It's expected behavior. The first parameter of src() expects either a string or an array of strings, not an empty array. The allowEmpty option just suppresses the error that is thrown if no match is found—it doesn't change what can be passed in the first parameter.