Skip to content

Commit da19dd6

Browse files
fix: Catch promise errors.
1 parent 4ccd20b commit da19dd6

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

index.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var path = require('path');
2-
var DtsCreator = require('typed-css-modules');
3-
var loaderUtils = require('loader-utils');
1+
var path = require("path");
2+
var DtsCreator = require("typed-css-modules");
3+
var loaderUtils = require("loader-utils");
44

55
module.exports = function(source, map) {
66
this.cacheable && this.cacheable();
@@ -13,7 +13,7 @@ module.exports = function(source, map) {
1313
var options = loaderUtils.getOptions(this) || {};
1414
var context = options.context || this.context || this.rootContext;
1515
var emitFile = !options.noEmit;
16-
16+
1717
// Make sure to not modify options object directly
1818
var creatorOptions = Object.assign({}, options);
1919
delete creatorOptions.noEmit;
@@ -22,13 +22,21 @@ module.exports = function(source, map) {
2222

2323
// creator.create(..., source) tells the module to operate on the
2424
// source variable. Check API for more details.
25-
creator.create(this.resourcePath, source).then(content => {
26-
if (emitFile) {
25+
creator
26+
.create(this.resourcePath, source)
27+
.then(content => {
28+
if (emitFile) {
2729
// Emit the created content as well
28-
this.emitFile(path.relative(context, content.outputFilePath), content.contents || [''], map);
29-
}
30-
content.writeFile().then(_ => {
31-
callback(null, source, map);
32-
});
33-
});
30+
this.emitFile(
31+
path.relative(context, content.outputFilePath),
32+
content.contents || [""],
33+
map
34+
);
35+
}
36+
37+
return content.writeFile().then(_ => {
38+
callback(null, source, map);
39+
});
40+
})
41+
.catch(callback);
3442
};

0 commit comments

Comments
 (0)