diff --git a/package-lock.json b/package-lock.json index f22f147e..cb6f488c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8103,8 +8103,7 @@ "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" }, "npm-path": { "version": "2.0.4", diff --git a/package.json b/package.json index 543d986f..6adfacf1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/preProcessPattern.js b/src/preProcessPattern.js index 234249e1..3dc14c8f 100644 --- a/src/preProcessPattern.js +++ b/src/preProcessPattern.js @@ -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'; @@ -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'); } diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js index b326bc3f..c98c60fb 100644 --- a/test/CopyPlugin.test.js +++ b/test/CopyPlugin.test.js @@ -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: [