gulp icon indicating copy to clipboard operation
gulp copied to clipboard

gulp does not work if base path has brackets [ ]

Open MischaVreeburg opened this issue 2 years ago • 1 comments

What were you expecting to happen?

When executing a gulp task

gulp.src('dist/js/**/*.js')
.pipe(gulp.dest('wwwroot/assets')

the task failed. When I used gulp-debug it reported no items found even though they were there and I can find them using

const glob = require("glob");
var glb = glob.sync('dist/js/**/*.js')
console.log(glb);

this listed the files correctly

I expected the gulp task to copy the files from the dist/js folder to the wwwroot/assets folder.

What actually happened?

Nothing happened. After much debugging, I finally discovered that the issue is the the basepath. If the basepath is something like 'c:\users\myname\projects[currentCompany]\webproject' and I execute the gulp task in this path, nothing happens. When I changed the basepath to 'c:\users\myname\projects\currentCompany\webproject' the gulp task worked like it should.

Please change the globbing to deal with paths that have the [] brackets.

I would expect that gulp would work with every legal path.

MischaVreeburg avatar Jul 09 '23 21:07 MischaVreeburg

The issue you are encountering is that square bracket have a special meaning in glob patterns. They are often used to match a single character, i.e. folder[123] will match folder1 but not folder4.

If you want to match projects[currentCompany], you need to escape the brackets. i.e.

src('projects\\[currentCompany\\]')

lachlanmcdonald avatar Aug 14 '23 13:08 lachlanmcdonald

This should be resolved in v5, but feel free to let me know if not and I'll reopen.

yocontra avatar Apr 06 '24 20:04 yocontra