less-loader 11.0.0 → 11.1.1

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.
package/README.md CHANGED
@@ -6,10 +6,9 @@
6
6
 
7
7
  [![npm][npm]][npm-url]
8
8
  [![node][node]][node-url]
9
- [![deps][deps]][deps-url]
10
9
  [![tests][tests]][tests-url]
11
10
  [![cover][cover]][cover-url]
12
- [![chat][chat]][chat-url]
11
+ [![discussion][discussion]][discussion-url]
13
12
  [![size][size]][size-url]
14
13
 
15
14
  # less-loader
@@ -320,7 +319,7 @@ Default: `true`
320
319
 
321
320
  Enables/Disables the default `webpack` importer.
322
321
 
323
- This can improve performance in some cases. Use it with caution because aliases and `@import` at-rules starting with `~` will not work.
322
+ This can improve performance in some cases. Use it with caution because aliases and `@import` from [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules) will not work.
324
323
 
325
324
  **webpack.config.js**
326
325
 
@@ -487,7 +486,7 @@ Usually, it's recommended to extract the style sheets into a dedicated file in p
487
486
 
488
487
  ### Imports
489
488
 
490
- First we try to use built-in `less` resolve logic, then `webpack` resolve logic (aliases and `~`).
489
+ First we try to use built-in `less` resolve logic, then `webpack` resolve logic.
491
490
 
492
491
  #### Webpack Resolver
493
492
 
@@ -500,12 +499,7 @@ Thus you can import your Less modules from `node_modules`.
500
499
  ```
501
500
 
502
501
  Using `~` is deprecated and can be removed from your code (**we recommend it**), but we still support it for historical reasons.
503
- Why you can removed it? The loader will first try to resolve `@import` as relative, if it cannot be resolved, the loader will try to resolve `@import` inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolve-modules).
504
- Just prepend them with a `~` which tells webpack to look up the [`modules`](https://webpack.js.org/configuration/resolve/#resolve-modules).
505
-
506
- ```css
507
- @import "~bootstrap/less/bootstrap";
508
- ```
502
+ Why you can removed it? The loader will first try to resolve `@import` as relative, if it cannot be resolved, the loader will try to resolve `@import` inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
509
503
 
510
504
  Default resolver options can be modified by [`resolve.byDependency`](https://webpack.js.org/configuration/resolve/#resolvebydependency):
511
505
 
@@ -533,8 +527,6 @@ module.exports = {
533
527
  };
534
528
  ```
535
529
 
536
- It's important to only prepend it with `~`, because `~/` resolves to the home-directory. webpack needs to distinguish between `bootstrap` and `~bootstrap`, because CSS and Less files have no special syntax for importing relative files. Writing `@import "file"` is the same as `@import "./file";`
537
-
538
530
  #### Less Resolver
539
531
 
540
532
  If you specify the `paths` option, modules will be searched in the given `paths`. This is `less` default behavior. `paths` should be an array with absolute paths:
@@ -594,7 +586,9 @@ module.exports = {
594
586
  };
595
587
  ```
596
588
 
597
- > ℹ️ Access to the [loader context](https://webpack.js.org/api/loaders/#the-loader-context) inside the custom plugin can be done using the `pluginManager.webpackLoaderContext` property.
589
+ > **Note**
590
+ >
591
+ > Access to the [loader context](https://webpack.js.org/api/loaders/#the-loader-context) inside the custom plugin can be done using the `pluginManager.webpackLoaderContext` property.
598
592
 
599
593
  ```js
600
594
  module.exports = {
@@ -635,13 +629,11 @@ Please take a moment to read our contributing guidelines if you haven't yet done
635
629
  [npm-url]: https://npmjs.com/package/less-loader
636
630
  [node]: https://img.shields.io/node/v/less-loader.svg
637
631
  [node-url]: https://nodejs.org
638
- [deps]: https://david-dm.org/webpack-contrib/less-loader.svg
639
- [deps-url]: https://david-dm.org/webpack-contrib/less-loader
640
632
  [tests]: https://github.com/webpack-contrib/less-loader/workflows/less-loader/badge.svg
641
633
  [tests-url]: https://github.com/webpack-contrib/less-loader/actions
642
634
  [cover]: https://codecov.io/gh/webpack-contrib/less-loader/branch/master/graph/badge.svg
643
635
  [cover-url]: https://codecov.io/gh/webpack-contrib/less-loader
644
- [chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
645
- [chat-url]: https://gitter.im/webpack/webpack
636
+ [discussion]: https://img.shields.io/github/discussions/webpack/webpack
637
+ [discussion-url]: https://github.com/webpack/webpack/discussions
646
638
  [size]: https://packagephobia.now.sh/badge?p=less-loader
647
639
  [size-url]: https://packagephobia.now.sh/result?p=less-loader
package/dist/index.js CHANGED
@@ -11,14 +11,19 @@ var _options = _interopRequireDefault(require("./options.json"));
11
11
 
12
12
  var _utils = require("./utils");
13
13
 
14
- var _LessError = _interopRequireDefault(require("./LessError"));
15
-
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
 
18
16
  async function lessLoader(source) {
19
17
  const options = this.getOptions(_options.default);
20
18
  const callback = this.async();
21
- const implementation = (0, _utils.getLessImplementation)(this, options.implementation);
19
+ let implementation;
20
+
21
+ try {
22
+ implementation = (0, _utils.getLessImplementation)(this, options.implementation);
23
+ } catch (error) {
24
+ callback(error);
25
+ return;
26
+ }
22
27
 
23
28
  if (!implementation) {
24
29
  callback(new Error(`The Less implementation "${options.implementation}" not found`));
@@ -71,7 +76,7 @@ async function lessLoader(source) {
71
76
  this.addDependency(_path.default.normalize(error.filename));
72
77
  }
73
78
 
74
- callback(new _LessError.default(error));
79
+ callback((0, _utils.errorFactory)(error));
75
80
  return;
76
81
  } finally {
77
82
  // Fix memory leaks in `less`
package/dist/utils.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.errorFactory = errorFactory;
6
7
  exports.getLessImplementation = getLessImplementation;
7
8
  exports.getLessOptions = getLessOptions;
8
9
  exports.isUnsupportedUrl = isUnsupportedUrl;
@@ -19,7 +20,7 @@ const trailingSlash = /[/\\]$/; // This somewhat changed in Less 3.x. Now the fi
19
20
  // automatically added extension whereas the extension is passed in as `options.ext`.
20
21
  // So, if the file name matches this regexp, we simply ignore the proposed extension.
21
22
 
22
- const IS_SPECIAL_MODULE_IMPORT = /^~[^/]+$/; // `[drive_letter]:\` + `\\[server]\[sharename]\`
23
+ const IS_SPECIAL_MODULE_IMPORT = /^~[^/]+$/; // `[drive_letter]:\` + `\\[server]\[share_name]\`
23
24
 
24
25
  const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i; // Examples:
25
26
  // - ~package
@@ -42,7 +43,7 @@ const MODULE_REQUEST_REGEX = /^[^?]*~/;
42
43
  function createWebpackLessPlugin(loaderContext, implementation) {
43
44
  const resolve = loaderContext.getResolve({
44
45
  dependencyType: "less",
45
- conditionNames: ["less", "style"],
46
+ conditionNames: ["less", "style", "..."],
46
47
  mainFields: ["less", "style", "main", "..."],
47
48
  mainFiles: ["index", "..."],
48
49
  extensions: [".less", ".css"],
@@ -215,18 +216,36 @@ function getLessImplementation(loaderContext, implementation) {
215
216
  let resolvedImplementation = implementation;
216
217
 
217
218
  if (!implementation || typeof implementation === "string") {
218
- const lessImplPkg = implementation || "less";
219
+ const lessImplPkg = implementation || "less"; // eslint-disable-next-line import/no-dynamic-require, global-require
219
220
 
220
- try {
221
- // eslint-disable-next-line import/no-dynamic-require, global-require
222
- resolvedImplementation = require(lessImplPkg);
223
- } catch (error) {
224
- loaderContext.emitError(error); // eslint-disable-next-line consistent-return
225
-
226
- return;
227
- }
221
+ resolvedImplementation = require(lessImplPkg);
228
222
  } // eslint-disable-next-line consistent-return
229
223
 
230
224
 
231
225
  return resolvedImplementation;
226
+ }
227
+
228
+ function getFileExcerptIfPossible(error) {
229
+ if (typeof error.extract === "undefined") {
230
+ return [];
231
+ }
232
+
233
+ const excerpt = error.extract.slice(0, 2);
234
+ const column = Math.max(error.column - 1, 0);
235
+
236
+ if (typeof excerpt[0] === "undefined") {
237
+ excerpt.shift();
238
+ }
239
+
240
+ excerpt.push(`${new Array(column).join(" ")}^`);
241
+ return excerpt;
242
+ }
243
+
244
+ function errorFactory(error) {
245
+ const message = ["\n", ...getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), error.filename ? ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})` : ""].join("\n");
246
+ const obj = new Error(message, {
247
+ cause: error
248
+ });
249
+ obj.stack = null;
250
+ return obj;
232
251
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "less-loader",
3
- "version": "11.0.0",
3
+ "version": "11.1.1",
4
4
  "description": "A Less loader for webpack. Compiles Less to CSS.",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/less-loader",
@@ -24,7 +24,11 @@
24
24
  "security": "npm audit --production",
25
25
  "lint:prettier": "prettier --list-different .",
26
26
  "lint:js": "eslint --cache .",
27
+ "lint:spelling": "cspell \"**/*.*\"",
27
28
  "lint": "npm-run-all -l -p \"lint:**\"",
29
+ "fix:js": "npm run lint:js -- --fix",
30
+ "fix:prettier": "npm run lint:prettier -- --write",
31
+ "fix": "npm-run-all -l fix:js fix:prettier",
28
32
  "test:only": "cross-env NODE_ENV=test jest",
29
33
  "test:watch": "npm run test:only -- --watch",
30
34
  "test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
@@ -41,33 +45,35 @@
41
45
  "webpack": "^5.0.0"
42
46
  },
43
47
  "dependencies": {
44
- "klona": "^2.0.4"
48
+ "klona": "^2.0.6",
49
+ "v": "^0.3.0"
45
50
  },
46
51
  "devDependencies": {
47
- "@babel/cli": "^7.14.5",
48
- "@babel/core": "^7.14.6",
49
- "@babel/preset-env": "^7.14.7",
50
- "@commitlint/cli": "^17.0.0",
51
- "@commitlint/config-conventional": "^17.0.0",
52
+ "@babel/cli": "^7.21.5",
53
+ "@babel/core": "^7.21.5",
54
+ "@babel/preset-env": "^7.21.5",
55
+ "@commitlint/cli": "^17.6.1",
56
+ "@commitlint/config-conventional": "^17.6.1",
52
57
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
53
- "babel-jest": "^28.1.0",
58
+ "babel-jest": "^29.5.0",
54
59
  "cross-env": "^7.0.3",
55
- "del": "^6.0.0",
60
+ "cspell": "^6.31.1",
61
+ "del": "^6.1.1",
56
62
  "del-cli": "^4.0.1",
57
- "eslint": "^8.15.0",
58
- "eslint-config-prettier": "^8.3.0",
59
- "eslint-plugin-import": "^2.24.1",
60
- "husky": "^8.0.1",
61
- "jest": "^28.1.0",
62
- "less": "^4.1.1",
63
- "less-plugin-glob": "^3.0.0",
64
- "lint-staged": "^12.4.1",
65
- "memfs": "^3.2.2",
63
+ "eslint": "^8.39.0",
64
+ "eslint-config-prettier": "^8.8.0",
65
+ "eslint-plugin-import": "^2.27.5",
66
+ "husky": "^8.0.3",
67
+ "jest": "^29.5.0",
68
+ "less": "^4.1.3",
69
+ "less-plugin-glob": "^2.0.2",
70
+ "lint-staged": "^13.2.2",
71
+ "memfs": "^3.5.1",
66
72
  "npm-run-all": "^4.1.5",
67
- "prettier": "^2.3.2",
73
+ "prettier": "^2.8.8",
68
74
  "standard-version": "^9.3.1",
69
75
  "strip-ansi": "^7.0.0",
70
- "webpack": "^5.51.1"
76
+ "webpack": "^5.81.0"
71
77
  },
72
78
  "keywords": [
73
79
  "webpack",
package/dist/LessError.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- class LessError extends Error {
13
- constructor(error) {
14
- super();
15
- this.message = ["\n", ...LessError.getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), error.filename ? ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})` : ""].join("\n");
16
- this.hideStack = true;
17
- }
18
-
19
- static getFileExcerptIfPossible(lessError) {
20
- if (typeof lessError.extract === "undefined") {
21
- return [];
22
- }
23
-
24
- const excerpt = lessError.extract.slice(0, 2);
25
- const column = Math.max(lessError.column - 1, 0);
26
-
27
- if (typeof excerpt[0] === "undefined") {
28
- excerpt.shift();
29
- }
30
-
31
- excerpt.push(`${new Array(column).join(" ")}^`);
32
- return excerpt;
33
- }
34
-
35
- }
36
-
37
- var _default = LessError;
38
- exports.default = _default;