Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows regex not passing group data #348

Closed
BoldBigflank opened this issue Mar 4, 2019 · 6 comments
Closed

Windows regex not passing group data #348

BoldBigflank opened this issue Mar 4, 2019 · 6 comments

Comments

@BoldBigflank
Copy link

  • Operating System: Windows
  • Node Version: v6.14.1
  • NPM Version: 5.8.0
  • webpack Version: 4.16.2
  • copy-webpack-plugin Version: 5.0.0

Expected Behavior

I expect my copy plugin will move json files to a different directory with a different name based on the name of the folder it came from. For example: app/js/games/aspen/json/test.json will move to /json/aspen-test.json

Actual Behavior

On Windows, this copies the literal '[1]-test.json' to the new directory, rather than the name of the first capturing group. This works properly in Linux.

Code

new CopyWebpackPlugin([
            {
                from: 'app/js/**/test.json',
                to: 'json/[1]-test.json',
                test:/app\/js\/(?:games|controllers)\/([^/]+)\/json\/test.json/
            }])

How Do We Reproduce?

I think using this plugin code in a small repository with a similar directory structure will show the proper result.

@alexander-akait
Copy link
Member

Thanks for issue, i think problem related to loader-utils, i will see in near future

@alexander-akait
Copy link
Member

Just note: /app\/js\/(?:games|controllers)\/([^/]+)\/json\/test.json/ should be /app\/js\/(?:games|controllers)\/([^/]+)\/json\/test\.json/ (you forget \.). Investigate what is problem.

@alexander-akait
Copy link
Member

Problem not in copy-webpack-plugin. Problem in loader-utils as i written above (https://github.com/webpack/loader-utils/blob/master/lib/interpolateName.js#L110). resourcePath contains platform specific path separator, so you regexp doesn't work on windows, unfortunately we can't fix it on plugins side and we can't fix it without major release loader-utils. I created issue webpack/loader-utils#143, we fix it for v2. As workaround you can use (/|\\) instead / in regexp. I closing issue in favor webpack/loader-utils#143. Thanks!

@alexander-akait
Copy link
Member

Find problem #353, with one side it is fix, with other it is breaking change, i am afraid release this as patch

@RPainter8West
Copy link

Could you at least put a note in the readme about this until a fix is available?

@alexander-akait
Copy link
Member

We remove the test option in favor transformPath, using the transformPath option allow to implement any logic, even async, no need write hard to read regexps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment