Skip to content

Commit

Permalink
fix: emit errors instead throw (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Mar 22, 2019
1 parent 05963eb commit 3946473
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/preProcessPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function preProcessPattern(globalRef, pattern) {

logger.error(message);

throw new Error(message);
compilation.errors.push(new Error(message));
}

pattern.to = pattern.to || '';
Expand Down
4 changes: 2 additions & 2 deletions src/processPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import minimatch from 'minimatch';
import isObject from './utils/isObject';

export default function processPattern(globalRef, pattern) {
const { logger, output, concurrency } = globalRef;
const { logger, output, concurrency, compilation } = globalRef;
const globOptions = Object.assign(
{
cwd: pattern.context,
Expand Down Expand Up @@ -103,7 +103,7 @@ export default function processPattern(globalRef, pattern) {

logger.error(message);

throw new Error(message);
compilation.errors.push(new Error(message));
}

file.webpackTo = path.relative(output, file.webpackTo);
Expand Down
25 changes: 23 additions & 2 deletions test/CopyPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ describe('apply function', () => {

const runEmit = (opts) =>
run(opts).then((compilation) => {
if (opts.skipAssetsTesting) {
return;
}

if (opts.expectedAssetKeys && opts.expectedAssetKeys.length > 0) {
expect(Object.keys(compilation.assets).sort()).toEqual(
opts.expectedAssetKeys
Expand Down Expand Up @@ -884,7 +888,24 @@ describe('apply function', () => {

it('warns when pattern is empty', (done) => {
runEmit({
expectedAssetKeys: [],
expectedAssetKeys: [
'.file.txt',
'[!]/hello.txt',
'[special?directory]/(special-*file).txt',
'[special?directory]/directoryfile.txt',
'[special?directory]/nested/nestedfile.txt',
'binextension.bin',
'dir (86)/file.txt',
'dir (86)/nesteddir/deepnesteddir/deepnesteddir.txt',
'dir (86)/nesteddir/nestedfile.txt',
'directory/.dottedfile',
'directory/directoryfile.txt',
'directory/nested/deep-nested/deepnested.txt',
'directory/nested/nestedfile.txt',
'file.txt',
'file.txt.gz',
'noextension',
],
expectedErrors: [new Error(`path "from" cannot be empty string`)],
patterns: [
{
Expand Down Expand Up @@ -964,7 +985,7 @@ describe('apply function', () => {
compiler: new MockCompiler({
outputPath: '/',
}),
expectedAssetKeys: [],
skipAssetsTesting: true,
expectedErrors: [
new Error(
'using older versions of webpack-dev-server, devServer.outputPath must be defined to write to absolute paths'
Expand Down

0 comments on commit 3946473

Please sign in to comment.