Skip to content

Commit a1cf249

Browse files
refactor: moving processResult in index (#344)
1 parent bffbc5e commit a1cf249

File tree

3 files changed

+23
-41
lines changed

3 files changed

+23
-41
lines changed

src/formatLessError.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const os = require('os');
2-
31
/**
42
* Tries to get an excerpt of the file where the error happened.
53
* Uses err.line and err.column.
@@ -51,11 +49,11 @@ function formatLessError(err) {
5149
err.hideStack = true;
5250

5351
err.message = [
54-
os.EOL,
52+
'\n',
5553
...getFileExcerptIfPossible(err),
5654
msg.charAt(0).toUpperCase() + msg.slice(1),
5755
` in ${err.filename} (line ${err.line}, column ${err.column})`,
58-
].join(os.EOL);
56+
].join('\n');
5957

6058
return err;
6159
} /* eslint-enable no-param-reassign */

src/index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { getOptions } from 'loader-utils';
66
import validateOptions from 'schema-utils';
77

88
import schema from './options.json';
9-
import processResult from './processResult';
109
import getLessOptions from './getLessOptions';
10+
import removeSourceMappingUrl from './removeSourceMappingUrl';
11+
import formatLessError from './formatLessError';
1112

1213
const render = promisify(less.render.bind(less));
1314

@@ -22,7 +23,25 @@ function lessLoader(source) {
2223
const callback = this.async();
2324
const lessOptions = getLessOptions(this, options, source);
2425

25-
processResult(this, render(lessOptions.data, lessOptions), callback);
26+
render(lessOptions.data, lessOptions)
27+
.then(({ css, map, imports }) => {
28+
imports.forEach(this.addDependency, this);
29+
30+
// Removing the sourceMappingURL comment.
31+
// See removeSourceMappingUrl.js for the reasoning behind this.
32+
callback(
33+
null,
34+
removeSourceMappingUrl(css),
35+
typeof map === 'string' ? JSON.parse(map) : map
36+
);
37+
})
38+
.catch((lessError) => {
39+
if (lessError.filename) {
40+
this.addDependency(lessError.filename);
41+
}
42+
43+
callback(formatLessError(lessError));
44+
});
2645
}
2746

2847
export default lessLoader;

src/processResult.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)