less-loader 4.0.6 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ class LessError extends Error {
9
+ constructor(error) {
10
+ super();
11
+ this.message = ['\n', ...LessError.getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), ` Error in ${error.filename} (line ${error.line}, column ${error.column})`].join('\n');
12
+ this.hideStack = true;
13
+ }
14
+
15
+ static getFileExcerptIfPossible(lessErr) {
16
+ if (typeof lessErr.extract === 'undefined') {
17
+ return [];
18
+ }
19
+
20
+ const excerpt = lessErr.extract.slice(0, 2);
21
+ const column = Math.max(lessErr.column - 1, 0);
22
+
23
+ if (typeof excerpt[0] === 'undefined') {
24
+ excerpt.shift();
25
+ }
26
+
27
+ excerpt.push(`${new Array(column).join(' ')}^`);
28
+ return excerpt;
29
+ }
30
+
31
+ }
32
+
33
+ var _default = LessError;
34
+ exports.default = _default;
package/dist/cjs.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  module.exports = require('./index').default;
package/dist/index.js CHANGED
@@ -1,40 +1,55 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _less = require('less');
8
+ var _loaderUtils = require("loader-utils");
8
9
 
9
- var _less2 = _interopRequireDefault(_less);
10
+ var _schemaUtils = _interopRequireDefault(require("schema-utils"));
10
11
 
11
- var _pify = require('pify');
12
+ var _options = _interopRequireDefault(require("./options.json"));
12
13
 
13
- var _pify2 = _interopRequireDefault(_pify);
14
+ var _utils = require("./utils");
14
15
 
15
- var _processResult = require('./processResult');
16
-
17
- var _processResult2 = _interopRequireDefault(_processResult);
18
-
19
- var _getOptions = require('./getOptions');
20
-
21
- var _getOptions2 = _interopRequireDefault(_getOptions);
16
+ var _LessError = _interopRequireDefault(require("./LessError"));
22
17
 
23
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
19
 
25
- var render = (0, _pify2.default)(_less2.default.render.bind(_less2.default));
26
-
27
20
  function lessLoader(source) {
28
- var loaderContext = this;
29
- var options = (0, _getOptions2.default)(loaderContext);
30
- var done = loaderContext.async();
31
- var isSync = typeof done !== 'function';
21
+ const options = (0, _loaderUtils.getOptions)(this);
22
+ (0, _schemaUtils.default)(_options.default, options, {
23
+ name: 'Less Loader',
24
+ baseDataPath: 'options'
25
+ });
26
+ const callback = this.async();
27
+ const lessOptions = (0, _utils.getLessOptions)(this, options);
28
+ let data = source;
29
+
30
+ if (typeof options.prependData !== 'undefined') {
31
+ data = typeof options.prependData === 'function' ? `${options.prependData(this)}\n${data}` : `${options.prependData}\n${data}`;
32
+ }
32
33
 
33
- if (isSync) {
34
- throw new Error('Synchronous compilation is not supported anymore. See https://github.com/webpack-contrib/less-loader/issues/84');
34
+ if (typeof options.appendData !== 'undefined') {
35
+ data = typeof options.appendData === 'function' ? `${data}\n${options.appendData(this)}` : `${data}\n${options.appendData}`;
35
36
  }
36
37
 
37
- (0, _processResult2.default)(loaderContext, render(source, options));
38
+ (0, _utils.getLessImplementation)(options.implementation).render(data, lessOptions).then(({
39
+ css,
40
+ map,
41
+ imports
42
+ }) => {
43
+ imports.forEach(this.addDependency, this);
44
+ callback(null, css, typeof map === 'string' ? JSON.parse(map) : map);
45
+ }).catch(lessError => {
46
+ if (lessError.filename) {
47
+ this.addDependency(lessError.filename);
48
+ }
49
+
50
+ callback(new _LessError.default(lessError));
51
+ });
38
52
  }
39
53
 
40
- exports.default = lessLoader;
54
+ var _default = lessLoader;
55
+ exports.default = _default;
@@ -0,0 +1,48 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "lessOptions": {
5
+ "description": "Options to pass through to `Less` (https://github.com/webpack-contrib/less-loader#lessoptions).",
6
+ "anyOf": [
7
+ {
8
+ "type": "object",
9
+ "additionalProperties": true
10
+ },
11
+ {
12
+ "instanceof": "Function"
13
+ }
14
+ ]
15
+ },
16
+ "prependData": {
17
+ "description": "Prepends `Less` code before the actual entry file (https://github.com/webpack-contrib/less-loader#prependdata).",
18
+ "anyOf": [
19
+ {
20
+ "type": "string"
21
+ },
22
+ {
23
+ "instanceof": "Function"
24
+ }
25
+ ]
26
+ },
27
+ "appendData": {
28
+ "description": "Add `Less` code after the actual entry file (https://github.com/webpack-contrib/less-loader#postponeddata).",
29
+ "anyOf": [
30
+ {
31
+ "type": "string"
32
+ },
33
+ {
34
+ "instanceof": "Function"
35
+ }
36
+ ]
37
+ },
38
+ "sourceMap": {
39
+ "description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/less-loader#sourcemap).",
40
+ "type": "boolean"
41
+ },
42
+ "implementation": {
43
+ "description": "The implementation of the `Less` to be used (https://github.com/webpack-contrib/less-loader#implementation).",
44
+ "type": "object"
45
+ }
46
+ },
47
+ "additionalProperties": false
48
+ }
package/dist/utils.js ADDED
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getLessImplementation = getLessImplementation;
7
+ exports.getLessOptions = getLessOptions;
8
+
9
+ var _less = _interopRequireDefault(require("less"));
10
+
11
+ var _clone = _interopRequireDefault(require("clone"));
12
+
13
+ var _loaderUtils = require("loader-utils");
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+
17
+ /* eslint-disable class-methods-use-this */
18
+ const trailingSlash = /[/\\]$/; // This somewhat changed in Less 3.x. Now the file name comes without the
19
+ // automatically added extension whereas the extension is passed in as `options.ext`.
20
+ // So, if the file name matches this regexp, we simply ignore the proposed extension.
21
+
22
+ const isModuleName = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/;
23
+ /**
24
+ * Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext.
25
+ *
26
+ * @param {LoaderContext} loaderContext
27
+ * @returns {LessPlugin}
28
+ */
29
+
30
+ function createWebpackLessPlugin(loaderContext) {
31
+ const resolve = loaderContext.getResolve({
32
+ mainFields: ['less', 'style', 'main', '...'],
33
+ mainFiles: ['index', '...'],
34
+ extensions: ['.less', '.css']
35
+ });
36
+
37
+ class WebpackFileManager extends _less.default.FileManager {
38
+ supports(filename) {
39
+ if (this.isPathAbsolute(filename)) {
40
+ return false;
41
+ }
42
+
43
+ return true;
44
+ } // Sync resolving is used at least by the `data-uri` function.
45
+ // This file manager doesn't know how to do it, so let's delegate it
46
+ // to the default file manager of Less.
47
+ // We could probably use loaderContext.resolveSync, but it's deprecated,
48
+ // see https://webpack.js.org/api/loaders/#this-resolvesync
49
+
50
+
51
+ supportsSync() {
52
+ return false;
53
+ }
54
+
55
+ getUrl(filename, options) {
56
+ if (options.ext && !isModuleName.test(filename)) {
57
+ return this.tryAppendExtension(filename, options.ext);
58
+ }
59
+
60
+ return filename;
61
+ }
62
+
63
+ async resolveFilename(filename, currentDirectory, options) {
64
+ const url = this.getUrl(filename, options);
65
+ const moduleRequest = (0, _loaderUtils.urlToRequest)(url, url.charAt(0) === '/' ? '' : null); // Less is giving us trailing slashes, but the context should have no trailing slash
66
+
67
+ const context = currentDirectory.replace(trailingSlash, '');
68
+ return this.resolveRequests(context, [moduleRequest, url]);
69
+ }
70
+
71
+ resolveRequests(context, possibleRequests) {
72
+ if (possibleRequests.length === 0) {
73
+ return Promise.reject();
74
+ }
75
+
76
+ return resolve(context, possibleRequests[0]).then(result => {
77
+ return result;
78
+ }).catch(error => {
79
+ const [, ...tailPossibleRequests] = possibleRequests;
80
+
81
+ if (tailPossibleRequests.length === 0) {
82
+ throw error;
83
+ }
84
+
85
+ return this.resolveRequests(context, tailPossibleRequests);
86
+ });
87
+ }
88
+
89
+ async loadFile(filename, ...args) {
90
+ let result;
91
+
92
+ try {
93
+ if (isModuleName.test(filename)) {
94
+ const error = new Error();
95
+ error.type = 'Next';
96
+ throw error;
97
+ }
98
+
99
+ result = await super.loadFile(filename, ...args);
100
+ } catch (error) {
101
+ if (error.type !== 'File' && error.type !== 'Next') {
102
+ return Promise.reject(error);
103
+ }
104
+
105
+ try {
106
+ result = await this.resolveFilename(filename, ...args);
107
+ } catch (webpackResolveError) {
108
+ error.message = `Less resolver error:\n${error.message}\n\n` + `Webpack resolver error details:\n${webpackResolveError.details}\n\n` + `Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`;
109
+ return Promise.reject(error);
110
+ }
111
+
112
+ loaderContext.addDependency(result);
113
+ return super.loadFile(result, ...args);
114
+ }
115
+
116
+ loaderContext.addDependency(result.filename);
117
+ return result;
118
+ }
119
+
120
+ }
121
+
122
+ return {
123
+ install(lessInstance, pluginManager) {
124
+ pluginManager.addFileManager(new WebpackFileManager());
125
+ },
126
+
127
+ minVersion: [3, 0, 0]
128
+ };
129
+ }
130
+ /**
131
+ * Get the less options from the loader context and normalizes its values
132
+ *
133
+ * @param {object} loaderContext
134
+ * @param {object} loaderOptions
135
+ * @returns {Object}
136
+ */
137
+
138
+
139
+ function getLessOptions(loaderContext, loaderOptions) {
140
+ const options = (0, _clone.default)(loaderOptions.lessOptions ? typeof loaderOptions.lessOptions === 'function' ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions : {});
141
+ const lessOptions = {
142
+ plugins: [],
143
+ relativeUrls: true,
144
+ // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
145
+ filename: loaderContext.resourcePath,
146
+ ...options
147
+ };
148
+ lessOptions.plugins.unshift(createWebpackLessPlugin(loaderContext));
149
+ const useSourceMap = typeof loaderOptions.sourceMap === 'boolean' ? loaderOptions.sourceMap : loaderContext.sourceMap;
150
+
151
+ if (useSourceMap) {
152
+ lessOptions.sourceMap = {
153
+ outputSourceFiles: true
154
+ };
155
+ }
156
+
157
+ return lessOptions;
158
+ }
159
+
160
+ function getLessImplementation(implementation) {
161
+ if (typeof implementation !== 'undefined') {
162
+ return implementation;
163
+ }
164
+
165
+ return _less.default;
166
+ }
package/package.json CHANGED
@@ -1,78 +1,85 @@
1
1
  {
2
2
  "name": "less-loader",
3
- "version": "4.0.6",
4
- "author": "Johannes Ewald @jhnns",
5
- "description": "Less loader for webpack. Compiles Less to CSS.",
3
+ "version": "6.1.0",
4
+ "description": "A Less loader for webpack. Compiles Less to CSS.",
6
5
  "license": "MIT",
7
- "engines": {
8
- "node": ">= 4.8 < 5.0.0 || >= 5.10"
6
+ "repository": "webpack-contrib/less-loader",
7
+ "author": "Johannes Ewald @jhnns",
8
+ "homepage": "https://github.com/webpack-contrib/less-loader",
9
+ "bugs": "https://github.com/webpack-contrib/less-loader/issues",
10
+ "funding": {
11
+ "type": "opencollective",
12
+ "url": "https://opencollective.com/webpack"
9
13
  },
10
14
  "main": "dist/cjs.js",
11
- "files": [
12
- "dist"
13
- ],
15
+ "engines": {
16
+ "node": ">= 10.13.0"
17
+ },
14
18
  "scripts": {
15
- "create-spec": "babel-node test/helpers/createSpec.js",
16
- "pretest": "npm run create-spec",
17
- "test": "jest",
18
- "posttest": "npm run lint",
19
- "travis:test": "npm run test -- --runInBand",
20
- "appveyor:test": "npm run test",
21
- "lint": "eslint --cache src test",
22
- "webpack-defaults": "webpack-defaults",
23
19
  "start": "npm run build -- -w",
24
- "build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
25
- "lint-staged": "lint-staged",
20
+ "clean": "del-cli dist",
26
21
  "prebuild": "npm run clean",
22
+ "build": "cross-env NODE_ENV=production babel src -d dist --copy-files",
23
+ "commitlint": "commitlint --from=master",
24
+ "security": "npm audit",
25
+ "lint:prettier": "prettier --list-different .",
26
+ "lint:js": "eslint --cache .",
27
+ "lint": "npm-run-all -l -p \"lint:**\"",
28
+ "test:only": "cross-env NODE_ENV=test jest",
29
+ "test:watch": "npm run test:only -- --watch",
30
+ "test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
31
+ "pretest": "npm run lint",
32
+ "test": "npm run test:coverage",
27
33
  "prepare": "npm run build",
28
34
  "release": "standard-version",
29
- "security": "nsp check",
30
- "test:watch": "jest --watch",
31
- "test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
32
- "pretravis:coverage": "npm run pretest",
33
- "travis:coverage": "npm run test:coverage -- --runInBand",
34
- "travis:lint": "npm run lint && npm run security",
35
- "clean": "del-cli dist"
36
- },
37
- "dependencies": {
38
- "clone": "^2.1.1",
39
- "loader-utils": "^1.1.0",
40
- "pify": "^3.0.0"
35
+ "defaults": "webpack-defaults"
41
36
  },
37
+ "files": [
38
+ "dist"
39
+ ],
42
40
  "peerDependencies": {
43
- "less": "^2.3.1",
44
- "webpack": "^2.0.0 || ^3.0.0 || ^4.0.0"
41
+ "webpack": "^4.0.0 || ^5.0.0"
42
+ },
43
+ "dependencies": {
44
+ "clone": "^2.1.2",
45
+ "less": "^3.11.1",
46
+ "loader-utils": "^2.0.0",
47
+ "schema-utils": "^2.6.6"
45
48
  },
46
49
  "devDependencies": {
47
- "babel-cli": "^6.24.0",
48
- "babel-jest": "^21.2.0",
49
- "babel-plugin-transform-object-rest-spread": "^6.23.0",
50
- "babel-polyfill": "^6.23.0",
51
- "babel-preset-env": "^1.6.0",
52
- "cross-env": "^3.2.4",
53
- "del-cli": "^0.2.1",
54
- "eslint": "^3.18.0",
55
- "eslint-config-webpack": "^1.2.1",
56
- "eslint-plugin-import": "^2.2.0",
50
+ "@babel/cli": "^7.8.4",
51
+ "@babel/core": "^7.9.6",
52
+ "@babel/preset-env": "^7.9.6",
53
+ "@commitlint/cli": "^8.3.5",
54
+ "@commitlint/config-conventional": "^8.3.4",
55
+ "@webpack-contrib/defaults": "^6.3.0",
56
+ "@webpack-contrib/eslint-config-webpack": "^3.0.0",
57
+ "babel-jest": "^26.0.1",
58
+ "cross-env": "^7.0.2",
59
+ "del": "^5.1.0",
60
+ "del-cli": "^3.0.0",
61
+ "eslint": "^6.8.0",
62
+ "eslint-config-prettier": "^6.11.0",
63
+ "eslint-plugin-import": "^2.20.2",
64
+ "eslint-plugin-prettier": "^3.1.3",
65
+ "husky": "^4.2.5",
57
66
  "inspect-loader": "^1.0.0",
58
- "jest": "^21.2.1",
59
- "less": "^2.3.1",
60
- "lint-staged": "^3.4.0",
61
- "nodemon": "^1.11.0",
62
- "nsp": "^2.6.3",
63
- "pre-commit": "^1.2.2",
64
- "standard-version": "^4.0.0",
65
- "webpack": "latest",
66
- "webpack-defaults": "^1.6.0"
67
+ "jest": "^26.0.1",
68
+ "lint-staged": "^10.2.2",
69
+ "memfs": "^3.1.2",
70
+ "npm-run-all": "^4.1.5",
71
+ "prettier": "^2.0.5",
72
+ "standard-version": "^8.0.0",
73
+ "strip-ansi": "^6.0.0",
74
+ "webpack": "^4.43.0"
67
75
  },
68
- "repository": "https://github.com/webpack-contrib/less-loader.git",
69
- "bugs": "https://github.com/webpack-contrib/less-loader/issues",
70
- "homepage": "https://github.com/webpack-contrib/less-loader",
71
- "pre-commit": "lint-staged",
72
- "lint-staged": {
73
- "*.js": [
74
- "eslint --fix",
75
- "git add"
76
- ]
77
- }
76
+ "keywords": [
77
+ "webpack",
78
+ "loader",
79
+ "less",
80
+ "lesscss",
81
+ "less.js",
82
+ "css",
83
+ "preprocessor"
84
+ ]
78
85
  }
@@ -1,97 +0,0 @@
1
- 'use strict';
2
-
3
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
-
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
-
7
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
8
-
9
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
10
-
11
- var less = require('less');
12
- var loaderUtils = require('loader-utils');
13
- var pify = require('pify');
14
-
15
- var stringifyLoader = require.resolve('./stringifyLoader.js');
16
- var trailingSlash = /[/\\]$/;
17
- var isLessCompatible = /\.(le|c)ss$/;
18
- // Less automatically adds a .less file extension if no extension was given.
19
- // This is problematic if there is a module request like @import "~some-module";
20
- // because in this case Less will call our file manager with `~some-module.less`.
21
- // Since dots in module names are highly discouraged, we can safely assume that
22
- // this is an error and we need to remove the .less extension again.
23
- // However, we must not match something like @import "~some-module/file.less";
24
- var matchMalformedModuleFilename = /(~[^/\\]+)\.less$/;
25
-
26
- /**
27
- * Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext.
28
- *
29
- * @param {LoaderContext} loaderContext
30
- * @param {string=} root
31
- * @returns {LessPlugin}
32
- */
33
- function createWebpackLessPlugin(loaderContext) {
34
- var fs = loaderContext.fs;
35
-
36
- var resolve = pify(loaderContext.resolve.bind(loaderContext));
37
- var loadModule = pify(loaderContext.loadModule.bind(loaderContext));
38
- var readFile = pify(fs.readFile.bind(fs));
39
-
40
- var WebpackFileManager = function (_less$FileManager) {
41
- _inherits(WebpackFileManager, _less$FileManager);
42
-
43
- function WebpackFileManager() {
44
- _classCallCheck(this, WebpackFileManager);
45
-
46
- return _possibleConstructorReturn(this, (WebpackFileManager.__proto__ || Object.getPrototypeOf(WebpackFileManager)).apply(this, arguments));
47
- }
48
-
49
- _createClass(WebpackFileManager, [{
50
- key: 'supports',
51
- value: function supports() /* filename, currentDirectory, options, environment */{
52
- // eslint-disable-line class-methods-use-this
53
- // Our WebpackFileManager handles all the files
54
- return true;
55
- }
56
- }, {
57
- key: 'loadFile',
58
- value: function loadFile(filename, currentDirectory /* , options, environment */) {
59
- // eslint-disable-line class-methods-use-this
60
- var url = filename.replace(matchMalformedModuleFilename, '$1');
61
- var moduleRequest = loaderUtils.urlToRequest(url, url.charAt(0) === '/' ? '' : null);
62
- // Less is giving us trailing slashes, but the context should have no trailing slash
63
- var context = currentDirectory.replace(trailingSlash, '');
64
- var resolvedFilename = void 0;
65
-
66
- return resolve(context, moduleRequest).then(function (f) {
67
- resolvedFilename = f;
68
- loaderContext.addDependency(resolvedFilename);
69
-
70
- if (isLessCompatible.test(resolvedFilename)) {
71
- return readFile(resolvedFilename).then(function (contents) {
72
- return contents.toString('utf8');
73
- });
74
- }
75
-
76
- return loadModule([stringifyLoader, resolvedFilename].join('!')).then(JSON.parse);
77
- }).then(function (contents) {
78
- return {
79
- contents,
80
- filename: resolvedFilename
81
- };
82
- });
83
- }
84
- }]);
85
-
86
- return WebpackFileManager;
87
- }(less.FileManager);
88
-
89
- return {
90
- install(lessInstance, pluginManager) {
91
- pluginManager.addFileManager(new WebpackFileManager());
92
- },
93
- minVersion: [2, 1, 1]
94
- };
95
- }
96
-
97
- module.exports = createWebpackLessPlugin;
@@ -1,62 +0,0 @@
1
- 'use strict';
2
-
3
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
4
-
5
- var os = require('os');
6
-
7
- /**
8
- * Tries to get an excerpt of the file where the error happened.
9
- * Uses err.line and err.column.
10
- *
11
- * Returns an empty string if the excerpt could not be retrieved.
12
- *
13
- * @param {LessError} err
14
- * @returns {Array<string>}
15
- */
16
- function getFileExcerptIfPossible(lessErr) {
17
- try {
18
- var excerpt = lessErr.extract.slice(0, 2);
19
- var column = Math.max(lessErr.column - 1, 0);
20
-
21
- if (typeof excerpt[0] === 'undefined') {
22
- excerpt.shift();
23
- }
24
-
25
- excerpt.push(`${new Array(column).join(' ')}^`);
26
-
27
- return excerpt;
28
- } catch (unexpectedErr) {
29
- // If anything goes wrong here, we don't want any errors to be reported to the user
30
- return [];
31
- }
32
- }
33
-
34
- /**
35
- * Beautifies the error message from Less.
36
- *
37
- * @param {LessError} lessErr
38
- * @param {string} lessErr.type - e.g. 'Name'
39
- * @param {string} lessErr.message - e.g. '.undefined-mixin is undefined'
40
- * @param {string} lessErr.filename - e.g. '/path/to/style.less'
41
- * @param {number} lessErr.index - e.g. 352
42
- * @param {number} lessErr.line - e.g. 31
43
- * @param {number} lessErr.callLine - e.g. NaN
44
- * @param {string} lessErr.callExtract - e.g. undefined
45
- * @param {number} lessErr.column - e.g. 6
46
- * @param {Array<string>} lessErr.extract - e.g. [' .my-style {', ' .undefined-mixin;', ' display: block;']
47
- * @returns {LessError}
48
- */
49
- function formatLessError(err) {
50
- /* eslint-disable no-param-reassign */
51
- var msg = err.message;
52
-
53
- // Instruct webpack to hide the JS stack from the console
54
- // Usually you're only interested in the SASS stack in this case.
55
- err.hideStack = true;
56
-
57
- err.message = [os.EOL].concat(_toConsumableArray(getFileExcerptIfPossible(err)), [msg.charAt(0).toUpperCase() + msg.slice(1), ` in ${err.filename} (line ${err.line}, column ${err.column})`]).join(os.EOL);
58
-
59
- return err;
60
- } /* eslint-enable no-param-reassign */
61
-
62
- module.exports = formatLessError;