Copy-webpack-plugin: Won't copy files when there are square brackets [ ] in the path

Created on 23 Feb 2018  路  9Comments  路  Source: webpack-contrib/copy-webpack-plugin

A tiny repo to reproduce the issue:
https://github.com/flawiddsouza/Reproduce-bracket-bug-in-copy-webpack-plugin

Go to each folder & run:
npm install
npm start

The folder without brackets will copy the file "from" to "to" but the one with brackets will not.

4 (important) Patch 3 (broken) Bug

Most helpful comment

Windows 10 Version 1709

All 9 comments

@flawiddsouza Can you upgrade to latest version (npm cache clear --force & npm install)

Updated. Still broken. The files aren't copied if the path contains square brackets.

@flawiddsouza don't reproduce, what os you use?

Windows 10 Version 1709

this happens for me when using regex captures:

new CopyWebpackPlugin([ { from: '../../../src/**/docs/*.md', to: 'docs/[1][name].[ext]', toType: 'template', test: /([^/]+)\/([a-z,0-9]*)\/(\/?$).md/, } ], {debug: 'debug'}),

I am expecting to get files outputted as "dirName-fileName.md" however I am getting instead [1]-fileName.md".

I have the same issue with regular brackets in the path. I.e. D:/User/Dropbox (My Company)/project/**/*

Could it be related to this issue in Globby?
See also this very similar issue with globbing and windows folders in Chokidar. They ended up adding a "disable globbing" option.

@marcoqu looks like we have two issue - one in globby (i.e. node-glob) and second in chokidar :smile: Also latest globby use fast-glob package, maybe update deps can solve this problem

Sorry. In my case this has nothing to do with the globbing.
The issue is with path escaping in escape.js which escapes characters (the parentheses) that are part actual parts of the path.
If I remove the parentheses pattern from the regular expression, everything works fine.

_edit_
or does it?

Please only use forward-slashes in glob expressions.
https://github.com/isaacs/node-glob/#windows
https://github.com/isaacs/node-glob/issues/212

@goldenram If you are on Windows system. You should use \ as path separator in your test regexp.

if you want it works on both Windows and Mac/Linux. You can leverage path.sep. So you can try

const path = require('path');
// then
test: new RegExp(`([^/]+)\\${path.sep}([a-z,0-9]*)\\${path.sep}(\\/?$).md`)
Was this page helpful?
0 / 5 - 0 ratings