From 841423fca2932c18f8ac0cf0a1f0012fc0a62fb6 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Fri, 24 Apr 2020 14:30:41 +0300 Subject: [PATCH] fix: add file from an error to file dependencies --- src/index.js | 6 ++++++ test/fixtures/{invalid.css => error.css} | 0 test/fixtures/{invalid.js => error.js} | 2 +- test/helpers/ast-loader.js | 5 ++++- test/loader.test.js | 7 ++++++- 5 files changed, 17 insertions(+), 3 deletions(-) rename test/fixtures/{invalid.css => error.css} (100%) rename test/fixtures/{invalid.js => error.js} (54%) diff --git a/src/index.js b/src/index.js index 2ee1b781..38eaeb8d 100644 --- a/src/index.js +++ b/src/index.js @@ -150,6 +150,12 @@ export default function loader(content, map, meta) { return callback(null, `${importCode}${moduleCode}${exportCode}`); }) .catch((error) => { + if (error.file) { + console.log(error.file); + + this.addDependency(error.file); + } + callback( error.name === 'CssSyntaxError' ? new CssSyntaxError(error) : error ); diff --git a/test/fixtures/invalid.css b/test/fixtures/error.css similarity index 100% rename from test/fixtures/invalid.css rename to test/fixtures/error.css diff --git a/test/fixtures/invalid.js b/test/fixtures/error.js similarity index 54% rename from test/fixtures/invalid.js rename to test/fixtures/error.js index e4f257c2..ed1231f9 100644 --- a/test/fixtures/invalid.js +++ b/test/fixtures/error.js @@ -1,4 +1,4 @@ -import css from './invalid.css'; +import css from './error.css'; __export__ = css; diff --git a/test/helpers/ast-loader.js b/test/helpers/ast-loader.js index 392492d7..14b6f837 100644 --- a/test/helpers/ast-loader.js +++ b/test/helpers/ast-loader.js @@ -11,7 +11,10 @@ export default function astLoader(content) { const { spy = jest.fn() } = this.query; postcss([postcssPresetEnv({ stage: 0 })]) - .process(content) + .process(content, { + // eslint-disable-next-line no-undefined + from: undefined, + }) .then(({ css, map, root, messages }) => { const ast = { type: 'postcss', diff --git a/test/loader.test.js b/test/loader.test.js index ccaee08c..53e28c9b 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -123,9 +123,14 @@ describe('loader', () => { }); it('should throw error on invalid css syntax', async () => { - const compiler = getCompiler('./invalid.js', {}); + const compiler = getCompiler('./error.js', {}); const stats = await compile(compiler); + expect( + stats.compilation.fileDependencies.has( + path.resolve('./test/fixtures/error.css') + ) + ).toBe(true); expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); });