Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/preProcessPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,29 @@ export default function preProcessPattern(globalRef, pattern) {

debug(`determined '${pattern.from}' to be read from '${pattern.absoluteFrom}'`);

return stat(inputFileSystem, pattern.absoluteFrom)
.catch(() => {
const noStatsHandler = () => {
// If from doesn't appear to be a glob, then log a warning
if (isGlob(pattern.from) || pattern.from.indexOf('*') !== -1) {
pattern.fromType = 'glob';
pattern.glob = escape(pattern.context, pattern.from);
} else {
const msg = `unable to locate '${pattern.from}' at '${pattern.absoluteFrom}'`;
warning(msg);
compilation.errors.push(`[copy-webpack-plugin] ${msg}`);
const warningMsg = `[copy-webpack-plugin] ${msg}`;
// only display the same message once
if (compilation.errors.indexOf(warningMsg) === -1) {
warning(msg);
compilation.errors.push(warningMsg);
}

pattern.fromType = 'nonexistent';
}
})
};

return stat(inputFileSystem, pattern.absoluteFrom)
.catch(() => noStatsHandler())
.then((stat) => {
if (!stat) {
noStatsHandler();
return pattern;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class MockCompiler {
}
}


class MockCompilerNoStat extends MockCompiler {
constructor (options = {}) {
super(options);

this.inputFileSystem.stat = (file, cb) => cb(undefined, undefined);
}
}

describe('apply function', () => {
// Ideally we pass in patterns and confirm the resulting assets
const run = (opts) => {
Expand Down Expand Up @@ -621,6 +630,23 @@ describe('apply function', () => {
.catch(done);
});

it('warns when file not found and stats is undefined', (done) => {
runEmit({
compiler: new MockCompilerNoStat(),
expectedAssetKeys: [],
expectedErrors: [
`[copy-webpack-plugin] unable to locate 'nonexistent.txt' at '${HELPER_DIR}${path.sep}nonexistent.txt'`
],
patterns: [{
from: 'nonexistent.txt',
to: '.',
toType: 'dir'
}]
})
.then(done)
.catch(done);
});

it('warns when tranform failed', (done) => {
runEmit({
expectedAssetKeys: [],
Expand Down