Skip to content

Commit

Permalink
fix: 🐛 normalize pattern.from
Browse files Browse the repository at this point in the history
normalize the path for wildcard in windows

Issues: fix #317
  • Loading branch information
VdustR committed Feb 18, 2019
1 parent 2f3ee34 commit 6457c76
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@
"webpack": "^4.0.0"
},
"dependencies": {
"globby": "^7.1.1",
"cacache": "^11.3.1",
"find-cache-dir": "^2.0.0",
"serialize-javascript": "^1.4.0",
"globby": "^7.1.1",
"is-glob": "^4.0.0",
"loader-utils": "^1.1.0",
"minimatch": "^3.0.4",
"p-limit": "^2.1.0"
"normalize-path": "^3.0.0",
"p-limit": "^2.1.0",
"serialize-javascript": "^1.4.0"
},
"devDependencies": {
"@babel/cli": "^7.1.5",
Expand Down
13 changes: 13 additions & 0 deletions src/preProcessPattern.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';

import isGlob from 'is-glob';
import normalizePath from 'normalize-path';

import escape from './utils/escape';
import isObject from './utils/isObject';
Expand Down Expand Up @@ -30,6 +31,18 @@ export default function preProcessPattern(globalRef, pattern) {
}
: Object.assign({}, pattern);

if (typeof pattern.from === 'string') {
pattern.from = normalizePath(pattern.from);
} else if (
typeof pattern.from === 'object' &&
typeof pattern.from.glob === 'string'
) {
pattern.from = {
...pattern.from,
glob: normalizePath(pattern.from.glob),
};
}

if (pattern.from === '') {
throw new Error('[copy-webpack-plugin] path "from" cannot be empty string');
}
Expand Down
13 changes: 13 additions & 0 deletions test/CopyPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ describe('apply function', () => {
.catch(done);
});

it('can normalize backslash path', (done) => {
runEmit({
expectedAssetKeys: ['directory/nested/nestedfile.txt'],
patterns: [
{
from: 'directory\\nested\\*',
},
],
})
.then(done)
.catch(done);
});

it('can use a bracketed glob to move a file to the root directory', (done) => {
runEmit({
expectedAssetKeys: [
Expand Down

0 comments on commit 6457c76

Please sign in to comment.