copy-webpack-plugin
Advanced tools
Comparing version 6.0.0 to 6.0.1
@@ -5,2 +5,10 @@ # Changelog | ||
### [6.0.1](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v6.0.0...v6.0.1) (2020-05-16) | ||
### Bug Fixes | ||
* concurrency writing assets ([#484](https://github.com/webpack-contrib/copy-webpack-plugin/issues/484)) ([bfc712d](https://github.com/webpack-contrib/copy-webpack-plugin/commit/bfc712d77b4ba66caf72341e31a1dd5957bfa36c)) | ||
* escaping special characters in the `context` option ([0e62695](https://github.com/webpack-contrib/copy-webpack-plugin/commit/0e62695ee32216a133920f2ab5a1282e6a4a038b)) | ||
## [6.0.0](https://github.com/webpack-contrib/copy-webpack-plugin/compare/v5.1.1...v6.0.0) (2020-05-15) | ||
@@ -22,3 +30,3 @@ | ||
* the `2` version of `webpack-dev-server` is not supported anymore | ||
* the `logLever` was removed in favor the `infrastructureLogging.level` option, please read the [documentation](https://webpack.js.org/configuration/other-options/#infrastructurelogginglevel) | ||
* the `logLevel` was removed in favor the `infrastructureLogging.level` option, please read the [documentation](https://webpack.js.org/configuration/other-options/#infrastructurelogginglevel) | ||
@@ -25,0 +33,0 @@ |
@@ -48,5 +48,6 @@ "use strict"; | ||
}; | ||
let assets; | ||
try { | ||
await Promise.all(this.patterns.map(pattern => limit(async () => { | ||
assets = await Promise.all(this.patterns.map(pattern => limit(async () => { | ||
const patternAfterPreProcess = await (0, _preProcessPattern.default)(globalRef, pattern); | ||
@@ -59,12 +60,45 @@ const files = await (0, _processPattern.default)(globalRef, patternAfterPreProcess); | ||
return Promise.all(files.filter(Boolean).map(file => limit(() => { | ||
return (0, _postProcessPattern.default)(globalRef, patternAfterPreProcess, file); | ||
}))); | ||
return Promise.all(files.filter(Boolean).map(file => (0, _postProcessPattern.default)(globalRef, patternAfterPreProcess, file))); | ||
}))); | ||
logger.debug('end to adding additional assets'); | ||
callback(); | ||
} catch (error) { | ||
compilation.errors.push(error); | ||
callback(); | ||
} | ||
return; | ||
} // Avoid writing assets inside `p-limit`, because it creates concurrency. | ||
// It could potentially lead to an error - "Multiple assets emit different content to the same filename" | ||
assets.reduce((acc, val) => acc.concat(val), []).filter(Boolean).forEach(asset => { | ||
const { | ||
absoluteFrom, | ||
targetPath, | ||
webpackTo, | ||
source, | ||
force | ||
} = asset; // For old version webpack 4 | ||
/* istanbul ignore if */ | ||
if (typeof compilation.emitAsset !== 'function') { | ||
// eslint-disable-next-line no-param-reassign | ||
compilation.assets[targetPath] = source; | ||
return; | ||
} | ||
if (compilation.getAsset(targetPath)) { | ||
if (force) { | ||
logger.log(`force updating '${webpackTo}' to compilation assets from '${absoluteFrom}'`); | ||
compilation.updateAsset(targetPath, source); | ||
return; | ||
} | ||
logger.log(`skipping '${webpackTo}', because it already exists`); | ||
return; | ||
} | ||
logger.log(`writing '${webpackTo}' to compilation assets from '${absoluteFrom}'`); | ||
compilation.emitAsset(targetPath, source); | ||
}); | ||
logger.debug('end to adding additional assets'); | ||
callback(); | ||
}); | ||
@@ -71,0 +105,0 @@ }); |
@@ -38,20 +38,4 @@ "use strict"; | ||
inputFileSystem | ||
} = globalRef; | ||
logger.debug(`getting stats for '${file.absoluteFrom}' to write to assets`); | ||
const getStats = pattern.stats ? pattern.stats : (0, _promisify.stat)(inputFileSystem, file.absoluteFrom); | ||
let stats; | ||
} = globalRef; // If this came from a glob, add it to the file watchlist | ||
try { | ||
stats = await getStats; | ||
} catch (error) { | ||
compilation.errors.push(error); | ||
return; | ||
} | ||
if (stats.isDirectory()) { | ||
logger.debug(`skipping '${file.absoluteFrom}' because it is empty directory`); | ||
return; | ||
} // If this came from a glob, add it to the file watchlist | ||
if (pattern.fromType === 'glob') { | ||
@@ -132,25 +116,7 @@ logger.debug(`add ${file.absoluteFrom} as fileDependencies`); | ||
const targetPath = (0, _normalizePath.default)(file.webpackTo); | ||
const source = new _webpackSources.RawSource(content); // For old version webpack 4 | ||
file.source = new _webpackSources.RawSource(content); | ||
file.targetPath = (0, _normalizePath.default)(file.webpackTo); | ||
file.force = pattern.force; // eslint-disable-next-line consistent-return | ||
/* istanbul ignore if */ | ||
if (typeof compilation.emitAsset !== 'function') { | ||
compilation.assets[targetPath] = source; | ||
return; | ||
} | ||
if (compilation.getAsset(targetPath)) { | ||
if (pattern.force) { | ||
logger.log(`force updating '${file.webpackTo}' to compilation assets from '${file.absoluteFrom}'`); | ||
compilation.updateAsset(targetPath, source); | ||
return; | ||
} | ||
logger.log(`skipping '${file.webpackTo}', because it already exists`); | ||
return; | ||
} | ||
logger.log(`writing '${file.webpackTo}' to compilation assets from '${file.absoluteFrom}'`); | ||
compilation.emitAsset(targetPath, source); | ||
return file; | ||
} |
@@ -71,3 +71,2 @@ "use strict"; | ||
pattern.fromType = 'file'; | ||
pattern.stats = stats; | ||
} | ||
@@ -74,0 +73,0 @@ |
@@ -37,31 +37,23 @@ "use strict"; | ||
return paths.map(filepath => { | ||
let from; | ||
return paths // Exclude directories | ||
.filter(item => item.dirent.isFile()).map(item => { | ||
const from = item.path; | ||
logger.debug(`found ${from}`); // `globby`/`fast-glob` return the relative path when the path contains special characters on windows | ||
if (typeof filepath === 'string') { | ||
from = filepath; | ||
} else { | ||
from = filepath.path; | ||
} | ||
const absoluteFrom = _path.default.resolve(pattern.context, from); | ||
const file = { | ||
absoluteFrom: _path.default.resolve(pattern.context, from) | ||
}; | ||
file.relativeFrom = _path.default.relative(pattern.context, file.absoluteFrom); | ||
const relativeFrom = pattern.flatten ? _path.default.basename(absoluteFrom) : _path.default.relative(pattern.context, absoluteFrom); | ||
let webpackTo = pattern.toType === 'dir' ? _path.default.join(pattern.to, relativeFrom) : pattern.to; | ||
if (pattern.flatten) { | ||
file.relativeFrom = _path.default.basename(file.relativeFrom); | ||
if (_path.default.isAbsolute(webpackTo)) { | ||
webpackTo = _path.default.relative(output, webpackTo); | ||
} | ||
logger.debug(`found ${from}`); // Change the to path to be relative for webpack | ||
file.webpackTo = pattern.toType === 'dir' ? _path.default.join(pattern.to, file.relativeFrom) : pattern.to; | ||
if (_path.default.isAbsolute(file.webpackTo)) { | ||
file.webpackTo = _path.default.relative(output, file.webpackTo); | ||
} | ||
logger.log(`determined that '${from}' should write to '${file.webpackTo}'`); | ||
return file; | ||
logger.log(`determined that '${from}' should write to '${webpackTo}'`); | ||
return { | ||
absoluteFrom, | ||
relativeFrom, | ||
webpackTo | ||
}; | ||
}); | ||
} |
@@ -14,8 +14,8 @@ "use strict"; | ||
var _fastGlob = _interopRequireDefault(require("fast-glob")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getAbsoluteContext(context) { | ||
const result = (0, _normalizePath.default)(_path.default.resolve(context)); | ||
return result.replace( // eslint-disable-next-line no-useless-escape | ||
/[\*|\?|\!|\||\@|\+|\(|\)|\[|\]|\{|\}]/g, substring => `\\${substring}`); | ||
return _fastGlob.default.escapePath((0, _normalizePath.default)(_path.default.resolve(context))); | ||
} | ||
@@ -34,3 +34,4 @@ | ||
...{ | ||
cwd: pattern.context | ||
cwd: pattern.context, | ||
objectMode: true | ||
} | ||
@@ -37,0 +38,0 @@ }; |
{ | ||
"name": "copy-webpack-plugin", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"description": "Copy files && directories with webpack", | ||
@@ -45,2 +45,3 @@ "license": "MIT", | ||
"cacache": "^15.0.3", | ||
"fast-glob": "^3.2.2", | ||
"find-cache-dir": "^3.3.1", | ||
@@ -47,0 +48,0 @@ "glob-parent": "^5.1.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
63295
0
12
480
+ Addedfast-glob@^3.2.2