Skip to content

Commit 3946473

Browse files
authoredMar 22, 2019
fix: emit errors instead throw (#362)
1 parent 05963eb commit 3946473

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed
 

‎src/preProcessPattern.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function preProcessPattern(globalRef, pattern) {
3434

3535
logger.error(message);
3636

37-
throw new Error(message);
37+
compilation.errors.push(new Error(message));
3838
}
3939

4040
pattern.to = pattern.to || '';

‎src/processPattern.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import minimatch from 'minimatch';
77
import isObject from './utils/isObject';
88

99
export default function processPattern(globalRef, pattern) {
10-
const { logger, output, concurrency } = globalRef;
10+
const { logger, output, concurrency, compilation } = globalRef;
1111
const globOptions = Object.assign(
1212
{
1313
cwd: pattern.context,
@@ -103,7 +103,7 @@ export default function processPattern(globalRef, pattern) {
103103

104104
logger.error(message);
105105

106-
throw new Error(message);
106+
compilation.errors.push(new Error(message));
107107
}
108108

109109
file.webpackTo = path.relative(output, file.webpackTo);

‎test/CopyPlugin.test.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ describe('apply function', () => {
157157

158158
const runEmit = (opts) =>
159159
run(opts).then((compilation) => {
160+
if (opts.skipAssetsTesting) {
161+
return;
162+
}
163+
160164
if (opts.expectedAssetKeys && opts.expectedAssetKeys.length > 0) {
161165
expect(Object.keys(compilation.assets).sort()).toEqual(
162166
opts.expectedAssetKeys
@@ -884,7 +888,24 @@ describe('apply function', () => {
884888

885889
it('warns when pattern is empty', (done) => {
886890
runEmit({
887-
expectedAssetKeys: [],
891+
expectedAssetKeys: [
892+
'.file.txt',
893+
'[!]/hello.txt',
894+
'[special?directory]/(special-*file).txt',
895+
'[special?directory]/directoryfile.txt',
896+
'[special?directory]/nested/nestedfile.txt',
897+
'binextension.bin',
898+
'dir (86)/file.txt',
899+
'dir (86)/nesteddir/deepnesteddir/deepnesteddir.txt',
900+
'dir (86)/nesteddir/nestedfile.txt',
901+
'directory/.dottedfile',
902+
'directory/directoryfile.txt',
903+
'directory/nested/deep-nested/deepnested.txt',
904+
'directory/nested/nestedfile.txt',
905+
'file.txt',
906+
'file.txt.gz',
907+
'noextension',
908+
],
888909
expectedErrors: [new Error(`path "from" cannot be empty string`)],
889910
patterns: [
890911
{
@@ -964,7 +985,7 @@ describe('apply function', () => {
964985
compiler: new MockCompiler({
965986
outputPath: '/',
966987
}),
967-
expectedAssetKeys: [],
988+
skipAssetsTesting: true,
968989
expectedErrors: [
969990
new Error(
970991
'using older versions of webpack-dev-server, devServer.outputPath must be defined to write to absolute paths'

0 commit comments

Comments
 (0)
Please sign in to comment.