Skip to content

Commit 53c90fc

Browse files
committed
fix: error where not all files were watched
1 parent cd1734d commit 53c90fc

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

src/processResult.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ function processResult(loaderContext, resultPromise) {
1111
const { callback } = loaderContext;
1212

1313
resultPromise
14-
.then(({ css, map }) => {
14+
.then(({ css, map, imports }) => {
15+
imports.forEach(loaderContext.addDependency, loaderContext);
1516
return {
1617
// Removing the sourceMappingURL comment.
1718
// See removeSourceMappingUrl.js for the reasoning behind this.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "./error-syntax";

test/helpers/createSpec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ignore = [
1313
'error-import-not-existing',
1414
'error-mixed-resolvers',
1515
'error-syntax',
16+
'error-import-file-with-error',
1617
];
1718
const lessReplacements = [
1819
[/~some\//g, '../node_modules/some/'],

test/index.test.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ async function compileAndCompare(fixture, { lessLoaderOptions, lessLoaderContext
2020
expect(actualCss).toBe(expectedCss);
2121
}
2222

23+
function lessFixturePath(fixture) {
24+
return path.resolve(__dirname, 'fixtures', 'less', fixture);
25+
}
26+
2327
test('should compile simple less without errors', async () => {
2428
await compileAndCompare('basic');
2529
});
@@ -28,10 +32,50 @@ test('should resolve all imports', async () => {
2832
await compileAndCompare('import');
2933
});
3034

35+
test('should add all resolved imports as dependencies', async () => {
36+
const dependencies = [];
37+
38+
await compileAndCompare('import', {
39+
lessLoaderContext: {
40+
addDependency(dep) {
41+
if (dependencies.indexOf(dep) === -1) {
42+
dependencies.push(dep);
43+
}
44+
},
45+
},
46+
});
47+
48+
expect(dependencies.sort()).toEqual([
49+
lessFixturePath('import.less'),
50+
lessFixturePath('css.css'),
51+
lessFixturePath('basic.less'),
52+
].sort());
53+
});
54+
3155
test('should resolve all imports from node_modules using webpack\'s resolver', async () => {
3256
await compileAndCompare('import-webpack');
3357
});
3458

59+
test('should add all resolved imports as dependencies, including node_modules', async () => {
60+
const dependencies = [];
61+
62+
await compileAndCompare('import-webpack', {
63+
lessLoaderContext: {
64+
addDependency(dep) {
65+
if (dependencies.indexOf(dep) === -1) {
66+
dependencies.push(dep);
67+
}
68+
},
69+
},
70+
});
71+
72+
expect(dependencies.sort()).toEqual([
73+
lessFixturePath('import-webpack.less'),
74+
lessFixturePath('../node_modules/some/module.less'),
75+
lessFixturePath('../node_modules/some/css.css'),
76+
].sort());
77+
});
78+
3579
test('should resolve aliases as configured', async () => {
3680
await compileAndCompare('import-webpack-alias', {
3781
resolveAlias: {
@@ -40,12 +84,54 @@ test('should resolve aliases as configured', async () => {
4084
});
4185
});
4286

87+
test('should add all resolved imports as dependencies, including aliased ones', async () => {
88+
const dependencies = [];
89+
90+
await compileAndCompare('import-webpack-alias', {
91+
resolveAlias: {
92+
'aliased-some': 'some',
93+
},
94+
lessLoaderContext: {
95+
addDependency(dep) {
96+
if (dependencies.indexOf(dep) === -1) {
97+
dependencies.push(dep);
98+
}
99+
},
100+
},
101+
});
102+
103+
expect(dependencies.sort()).toEqual([
104+
lessFixturePath('import-webpack-alias.less'),
105+
lessFixturePath('../node_modules/some/module.less'),
106+
].sort());
107+
});
108+
43109
test('should resolve all imports from the given paths using Less\' resolver', async () => {
44110
await compileAndCompare('import-paths', {
45111
lessLoaderOptions: { paths: [__dirname, nodeModulesPath] },
46112
});
47113
});
48114

115+
test('should add all resolved imports as dependencies, including those from the Less resolver', async () => {
116+
const dependencies = [];
117+
118+
await compileAndCompare('import-paths', {
119+
lessLoaderOptions: { paths: [__dirname, nodeModulesPath] },
120+
lessLoaderContext: {
121+
addDependency(dep) {
122+
if (dependencies.indexOf(dep) === -1) {
123+
dependencies.push(dep);
124+
}
125+
},
126+
},
127+
});
128+
129+
expect(dependencies.sort()).toEqual([
130+
lessFixturePath('import-paths.less'),
131+
lessFixturePath('../node_modules/some/module.less'),
132+
].sort());
133+
});
134+
49135
test('should allow to disable webpack\'s resolver by passing an empty paths array', async () => {
50136
const err = await compile('import-webpack', moduleRules.basic({ paths: [] }))
51137
.catch(e => e);
@@ -140,3 +226,23 @@ test('should provide a useful error message if there was a syntax error', async
140226
expect(err).toBeInstanceOf(Error);
141227
compareErrorMessage(err.message);
142228
});
229+
230+
test('should add a file with an error as dependency so that the watcher is triggered when the error is fixed', async () => {
231+
const dependencies = [];
232+
const lessLoaderContext = {
233+
addDependency(dep) {
234+
if (dependencies.indexOf(dep) === -1) {
235+
dependencies.push(dep);
236+
}
237+
},
238+
};
239+
const rules = moduleRules.basic({}, lessLoaderContext);
240+
241+
await compile('error-import-file-with-error', rules)
242+
.catch(e => e);
243+
244+
expect(dependencies.sort()).toEqual([
245+
lessFixturePath('error-import-file-with-error.less'),
246+
lessFixturePath('error-syntax.less'),
247+
].sort());
248+
});

0 commit comments

Comments
 (0)