Skip to content

Commit

Permalink
fix: add file from an error to file dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Apr 24, 2020
1 parent b04641c commit 841423f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/fixtures/invalid.js → test/fixtures/error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import css from './invalid.css';
import css from './error.css';

__export__ = css;

Expand Down
5 changes: 4 additions & 1 deletion test/helpers/ast-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down

0 comments on commit 841423f

Please sign in to comment.