diff --git a/.eslintrc.yml b/.eslintrc.yml index b5a4fb3..44458d2 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,8 +1,18 @@ extends: airbnb-base plugins: - import + +parserOptions: + ecmaVersion: 5 + +env: + node: true + browser: false + es6: false + rules: no-console: off func-names: off max-len: off no-confusing-arrow: off + object-shorthand: off diff --git a/.travis.yml b/.travis.yml index 73bc85e..f9aeb0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - - "node" + - "10" - "8" - "6" - "4" @@ -16,11 +16,6 @@ env: - WEBPACK_VERSION=3 - WEBPACK_VERSION=4 -matrix: - exclude: - - node_js: "4" - env: WEBPACK_VERSION=4 - install: - npm install - npm rm webpack diff --git a/index.js b/index.js index 16c4037..22fe358 100644 --- a/index.js +++ b/index.js @@ -186,7 +186,7 @@ CaseSensitivePathsPlugin.prototype.apply = function (compiler) { if (resolvedFilesCount === compilation.fileDependencies.size) { if (errors.length) { // Send all errors to webpack - compilation.errors.push(...errors); + Array.prototype.push.apply(compilation.errors, errors); } callback(); } diff --git a/test/index.js b/test/index.js index a4eba58..f127e32 100644 --- a/test/index.js +++ b/test/index.js @@ -13,7 +13,7 @@ const webpackPkg = require('webpack/package.json'); const CaseSensitivePathsPlugin = require('../'); -function webpackCompilerAtDir(dir, otherOpts) { +function webpackCompilerAtDir(dir, otherOpts, useBeforeEmitHook) { const opts = Object.assign({ context: path.join(__dirname, 'fixtures', dir), entry: './entry', @@ -22,7 +22,9 @@ function webpackCompilerAtDir(dir, otherOpts) { filename: 'result.js', }, plugins: [ - new CaseSensitivePathsPlugin(), + new CaseSensitivePathsPlugin({ + useBeforeEmitHook: useBeforeEmitHook, + }), ], }, otherOpts); @@ -56,6 +58,26 @@ describe('CaseSensitivePathsPlugin', () => { done(); }); }); + + it('should handle errors correctly in emit hook mode', (done) => { + const compiler = webpackCompilerAtDir('wrong-case', {}, true); + + compiler.run((err, stats) => { + if (err) done(err); + assert(stats.hasErrors()); + assert.equal(stats.hasWarnings(), false); + const jsonStats = stats.toJson(); + assert.equal(jsonStats.errors.length, 1); + + const error = jsonStats.errors[0]; + // check that the plugin produces the correct output + assert(error.indexOf('[CaseSensitivePathsPlugin]') > -1); + assert(error.indexOf('ExistingTestFile.js') > -1); // wrong file require + assert(error.indexOf('existingTestFile.js') > -1); // actual file name + + done(); + }); + }); } // For future reference: This test is somewhat of a race condition, these values seem to work well.