Skip to content

Commit 1c41c98

Browse files
authored
[fix] Validate error path for addDependency() (#199)
Fixes #197
1 parent 201272b commit 1c41c98

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ module.exports = function(source, map) {
7878

7979
callback(null, js.code, js.map);
8080
}, err => {
81-
this.addDependency(err.file);
81+
const file = err.file || err.filename;
82+
if (typeof file === 'string' && file !== this.resourcePath) {
83+
this.addDependency(file);
84+
}
8285
callback(err);
8386
}).catch(err => {
8487
// wrap error to provide correct

test/loader.spec.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ function d([str]) {
1515
describe('loader', () => {
1616
function testLoader(fileName, callback, query, version = 2) {
1717
return done => {
18-
function cb() {
18+
const addedDependencies = new Set();
19+
20+
function cb(...args) {
21+
while (args.length < 4) {
22+
args.push(undefined);
23+
}
24+
args.push(addedDependencies);
1925
try {
20-
callback(...[].slice.call(arguments));
26+
callback(...args);
2127
} catch (err) {
2228
expect(callbackSpy).to.have.been.called;
2329
return done(err);
@@ -32,10 +38,13 @@ describe('loader', () => {
3238

3339
const callbackSpy = spy(cb);
3440

41+
const dependencySpy = spy(function(p) { addedDependencies.add(p); });
42+
3543
loader.call(
3644
{
3745
cacheable: cacheableSpy,
3846
async: () => callbackSpy,
47+
addDependency: dependencySpy,
3948
resourcePath: fileName,
4049
version,
4150
query
@@ -45,6 +54,10 @@ describe('loader', () => {
4554
);
4655

4756
expect(cacheableSpy).to.have.been.called;
57+
58+
for (const call of dependencySpy.getCalls()) {
59+
expect(call.firstArg).to.be.a('string');
60+
}
4861
};
4962
}
5063

@@ -246,23 +259,18 @@ describe('loader', () => {
246259
});
247260

248261
it('should not preprocess successfully', done => {
249-
const { warn } = console;
250-
const warnings = [];
251-
252-
console.warn = msg => {
253-
warnings.push(msg);
254-
};
255-
256262
testLoader(
257263
'test/fixtures/style-valid.html',
258-
(err, code, map) => {
264+
(err, code, map, context, addedDependencies) => {
259265
expect(err).to.exist;
260-
console.warn = warn;
266+
expect(addedDependencies).to.include('/some/subresource.css');
261267
},
262268
{
263269
preprocess: {
264270
style: () => {
265-
throw new Error('Error while preprocessing');
271+
const e = new Error('Error while preprocessing');
272+
e.filename = '/some/subresource.css';
273+
throw e;
266274
}
267275
}
268276
}

0 commit comments

Comments
 (0)