Skip to content

Commit 841423f

Browse files
fix: add file from an error to file dependencies
1 parent b04641c commit 841423f

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

src/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ export default function loader(content, map, meta) {
150150
return callback(null, `${importCode}${moduleCode}${exportCode}`);
151151
})
152152
.catch((error) => {
153+
if (error.file) {
154+
console.log(error.file);
155+
156+
this.addDependency(error.file);
157+
}
158+
153159
callback(
154160
error.name === 'CssSyntaxError' ? new CssSyntaxError(error) : error
155161
);
File renamed without changes.

test/fixtures/invalid.js renamed to test/fixtures/error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import css from './invalid.css';
1+
import css from './error.css';
22

33
__export__ = css;
44

test/helpers/ast-loader.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export default function astLoader(content) {
1111
const { spy = jest.fn() } = this.query;
1212

1313
postcss([postcssPresetEnv({ stage: 0 })])
14-
.process(content)
14+
.process(content, {
15+
// eslint-disable-next-line no-undefined
16+
from: undefined,
17+
})
1518
.then(({ css, map, root, messages }) => {
1619
const ast = {
1720
type: 'postcss',

test/loader.test.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,14 @@ describe('loader', () => {
123123
});
124124

125125
it('should throw error on invalid css syntax', async () => {
126-
const compiler = getCompiler('./invalid.js', {});
126+
const compiler = getCompiler('./error.js', {});
127127
const stats = await compile(compiler);
128128

129+
expect(
130+
stats.compilation.fileDependencies.has(
131+
path.resolve('./test/fixtures/error.css')
132+
)
133+
).toBe(true);
129134
expect(getWarnings(stats)).toMatchSnapshot('warnings');
130135
expect(getErrors(stats)).toMatchSnapshot('errors');
131136
});

0 commit comments

Comments
 (0)