Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emit errors instead throw #362

Merged
merged 1 commit into from Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/preProcessPattern.js
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
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
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