less 3.0.0-pre.2 → 3.0.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.
Files changed (205) hide show
  1. package/.eslintrc.json +88 -0
  2. package/.github/stale.yml +17 -0
  3. package/.project +17 -0
  4. package/.settings/org.eclipse.buildship.core.prefs +2 -0
  5. package/.travis.yml +22 -3
  6. package/.vscode/launch.json +14 -0
  7. package/CHANGELOG.md +27 -0
  8. package/Gruntfile.js +191 -86
  9. package/README.md +5 -7
  10. package/appveyor.yml +9 -10
  11. package/bin/lessc +37 -50
  12. package/dist/less.js +1357 -1269
  13. package/dist/less.min.js +7 -7
  14. package/lib/less/contexts.js +20 -16
  15. package/lib/less/default-options.js +65 -0
  16. package/lib/less/environment/abstract-file-manager.js +13 -14
  17. package/lib/less/environment/abstract-plugin-loader.js +45 -36
  18. package/lib/less/environment/environment.js +5 -0
  19. package/lib/less/functions/boolean.js +15 -0
  20. package/lib/less/functions/color.js +54 -24
  21. package/lib/less/functions/data-uri.js +5 -2
  22. package/lib/less/functions/function-registry.js +1 -1
  23. package/lib/less/functions/index.js +2 -1
  24. package/lib/less/functions/number.js +2 -2
  25. package/lib/less/functions/string.js +2 -2
  26. package/lib/less/functions/svg.js +4 -4
  27. package/lib/less/import-manager.js +41 -29
  28. package/lib/less/index.js +28 -3
  29. package/lib/less/less-error.js +112 -13
  30. package/lib/less/parse.js +18 -15
  31. package/lib/less/parser/parser-input.js +4 -4
  32. package/lib/less/parser/parser.js +208 -114
  33. package/lib/less/plugin-manager.js +8 -33
  34. package/lib/less/render.js +6 -2
  35. package/lib/less/source-map-builder.js +3 -0
  36. package/lib/less/source-map-output.js +13 -8
  37. package/lib/less/transform-tree.js +2 -2
  38. package/lib/less/tree/anonymous.js +4 -1
  39. package/lib/less/tree/atrule.js +7 -6
  40. package/lib/less/tree/call.js +25 -3
  41. package/lib/less/tree/color.js +2 -2
  42. package/lib/less/tree/debug-info.js +1 -1
  43. package/lib/less/tree/declaration.js +6 -5
  44. package/lib/less/tree/dimension.js +4 -1
  45. package/lib/less/tree/extend.js +2 -2
  46. package/lib/less/tree/import.js +17 -9
  47. package/lib/less/tree/index.js +3 -7
  48. package/lib/less/tree/js-eval-node.js +1 -1
  49. package/lib/less/tree/media.js +3 -14
  50. package/lib/less/tree/mixin-definition.js +3 -3
  51. package/lib/less/tree/node.js +9 -6
  52. package/lib/less/tree/operation.js +1 -1
  53. package/lib/less/tree/property.js +70 -0
  54. package/lib/less/tree/quoted.js +11 -10
  55. package/lib/less/tree/ruleset.js +115 -71
  56. package/lib/less/tree/selector.js +38 -23
  57. package/lib/less/tree/unit.js +1 -1
  58. package/lib/less/tree/value.js +6 -1
  59. package/lib/less/tree/{ruleset-call.js → variable-call.js} +5 -5
  60. package/lib/less/tree/variable.js +6 -6
  61. package/lib/less/utils.js +40 -0
  62. package/lib/less/visitors/extend-visitor.js +14 -14
  63. package/lib/less/visitors/import-visitor.js +2 -2
  64. package/lib/less/visitors/join-selector-visitor.js +1 -1
  65. package/lib/less/visitors/to-css-visitor.js +51 -84
  66. package/lib/less/visitors/visitor.js +15 -15
  67. package/lib/less-browser/bootstrap.js +21 -5
  68. package/lib/less-browser/cache.js +2 -2
  69. package/lib/less-browser/error-reporting.js +5 -5
  70. package/lib/less-browser/file-manager.js +27 -35
  71. package/lib/less-browser/index.js +12 -17
  72. package/lib/less-browser/plugin-loader.js +8 -45
  73. package/lib/less-browser/utils.js +1 -1
  74. package/lib/less-node/file-manager.js +99 -69
  75. package/lib/less-node/fs.js +1 -1
  76. package/lib/less-node/image-size.js +2 -2
  77. package/lib/less-node/index.js +7 -57
  78. package/lib/less-node/lessc-helper.js +38 -38
  79. package/lib/less-node/plugin-loader.js +18 -79
  80. package/lib/less-node/url-file-manager.js +1 -1
  81. package/lib/less-rhino/index.js +29 -44
  82. package/package.json +16 -9
  83. package/test/browser/common.js +54 -18
  84. package/test/browser/css/plugin/plugin.css +3 -0
  85. package/test/browser/jasmine-jsreporter.js +4 -4
  86. package/test/browser/less/plugin/plugin.js +7 -0
  87. package/test/browser/less/plugin/plugin.less +4 -0
  88. package/test/browser/less.js +11685 -13
  89. package/test/browser/runner-browser-options.js +6 -1
  90. package/test/browser/runner-filemanagerPlugin-options.js +3 -2
  91. package/test/browser/runner-legacy-options.js +2 -1
  92. package/test/browser/runner-main-options.js +0 -1
  93. package/test/browser/runner-modify-vars-spec.js +2 -2
  94. package/test/browser/test-runner-template.tmpl +38 -14
  95. package/test/copy-bom.js +1 -1
  96. package/test/css/calc.css +5 -0
  97. package/test/css/comments2.css +1 -1
  98. package/test/css/compression/compression.css +1 -1
  99. package/test/css/css-grid.css +11 -0
  100. package/test/css/debug/linenumbers-all.css +0 -1
  101. package/test/css/debug/linenumbers-comments.css +0 -1
  102. package/test/css/debug/linenumbers-mediaquery.css +0 -1
  103. package/test/css/functions.css +16 -3
  104. package/test/css/import-module.css +9 -0
  105. package/test/css/import.css +0 -1
  106. package/test/css/legacy/legacy.css +1 -1
  107. package/test/css/merge.css +5 -4
  108. package/test/css/plugin-module.css +1 -0
  109. package/test/css/plugin.css +20 -0
  110. package/test/css/property-accessors.css +49 -0
  111. package/test/css/{css.css → strict-math/css.css} +0 -0
  112. package/test/css/{mixins-args.css → strict-math/mixins-args.css} +0 -0
  113. package/test/css/{parens.css → strict-math/parens.css} +0 -0
  114. package/test/import-module/one/1.less +3 -0
  115. package/test/import-module/one/two/2.less +3 -0
  116. package/test/import-module/one/two/three/3.less +3 -0
  117. package/test/import-module/package.json +11 -0
  118. package/test/index.js +55 -49
  119. package/test/less/calc.less +7 -0
  120. package/test/less/css-grid.less +15 -0
  121. package/test/less/detached-rulesets.less +2 -2
  122. package/test/less/errors/color-invalid-hex-code.less +1 -0
  123. package/test/less/errors/color-invalid-hex-code.txt +1 -1
  124. package/test/less/errors/color-invalid-hex-code2.less +1 -0
  125. package/test/less/errors/color-invalid-hex-code2.txt +1 -1
  126. package/test/less/errors/import-missing.txt +1 -1
  127. package/test/less/errors/plugin/plugin-error-2.js +5 -0
  128. package/test/less/errors/plugin/plugin-error-3.js +5 -0
  129. package/test/less/errors/plugin/plugin-error.js +1 -0
  130. package/test/less/errors/plugin-1.less +1 -0
  131. package/test/less/errors/plugin-1.txt +2 -0
  132. package/test/less/errors/plugin-2.less +1 -0
  133. package/test/less/errors/plugin-2.txt +5 -0
  134. package/test/less/errors/plugin-3.less +1 -0
  135. package/test/less/errors/plugin-3.txt +5 -0
  136. package/test/less/functions.less +18 -0
  137. package/test/less/import-module.less +3 -0
  138. package/test/less/import.less +0 -2
  139. package/test/less/legacy/legacy.less +1 -1
  140. package/test/less/media.less +2 -2
  141. package/test/less/merge.less +6 -3
  142. package/test/less/plugin/plugin-collection.js +9 -0
  143. package/test/less/plugin/plugin-local.js +2 -2
  144. package/test/less/plugin/plugin-scope1.js +3 -0
  145. package/test/less/plugin/plugin-scope2.js +3 -0
  146. package/test/less/plugin/plugin-simple.js +7 -0
  147. package/test/less/plugin/plugin-tree-nodes.js +33 -31
  148. package/test/less/plugin-module.less +7 -0
  149. package/test/less/plugin.less +33 -3
  150. package/test/less/property-accessors.less +67 -0
  151. package/test/less/root-registry/file.less +1 -0
  152. package/test/less/root-registry/root.less +3 -0
  153. package/test/less/{css.less → strict-math/css.less} +0 -0
  154. package/test/less/{mixins-args.less → strict-math/mixins-args.less} +0 -0
  155. package/test/less/{parens.less → strict-math/parens.less} +0 -0
  156. package/test/less-bom/calc.less +7 -0
  157. package/test/less-bom/css-grid.less +15 -0
  158. package/test/less-bom/detached-rulesets.less +2 -2
  159. package/test/less-bom/errors/color-invalid-hex-code.less +1 -0
  160. package/test/less-bom/errors/color-invalid-hex-code.txt +1 -1
  161. package/test/less-bom/errors/color-invalid-hex-code2.less +1 -0
  162. package/test/less-bom/errors/color-invalid-hex-code2.txt +1 -1
  163. package/test/less-bom/errors/import-missing.txt +1 -1
  164. package/test/less-bom/errors/plugin/plugin-error-2.js +5 -0
  165. package/test/less-bom/errors/plugin/plugin-error-3.js +5 -0
  166. package/test/less-bom/errors/plugin/plugin-error.js +1 -0
  167. package/test/less-bom/errors/plugin-1.less +1 -0
  168. package/test/less-bom/errors/plugin-1.txt +2 -0
  169. package/test/less-bom/errors/plugin-2.less +1 -0
  170. package/test/less-bom/errors/plugin-2.txt +5 -0
  171. package/test/less-bom/errors/plugin-3.less +1 -0
  172. package/test/less-bom/errors/plugin-3.txt +5 -0
  173. package/test/less-bom/functions.less +18 -0
  174. package/test/less-bom/import-module.less +3 -0
  175. package/test/less-bom/import.less +0 -2
  176. package/test/less-bom/legacy/legacy.less +1 -1
  177. package/test/less-bom/media.less +2 -2
  178. package/test/less-bom/merge.less +6 -3
  179. package/test/less-bom/plugin/plugin-collection.js +9 -0
  180. package/test/less-bom/plugin/plugin-local.js +2 -2
  181. package/test/less-bom/plugin/plugin-scope1.js +3 -0
  182. package/test/less-bom/plugin/plugin-scope2.js +3 -0
  183. package/test/less-bom/plugin/plugin-simple.js +7 -0
  184. package/test/less-bom/plugin/plugin-tree-nodes.js +33 -31
  185. package/test/less-bom/plugin-module.less +7 -0
  186. package/test/less-bom/plugin.less +33 -3
  187. package/test/less-bom/property-accessors.less +67 -0
  188. package/test/less-bom/root-registry/file.less +1 -0
  189. package/test/less-bom/root-registry/root.less +3 -0
  190. package/test/less-bom/{css.less → strict-math/css.less} +0 -0
  191. package/test/less-bom/{mixins-args.less → strict-math/mixins-args.less} +0 -0
  192. package/test/less-bom/{parens.less → strict-math/parens.less} +0 -0
  193. package/test/less-test.js +75 -17
  194. package/test/modify-vars.js +1 -1
  195. package/test/plugins/visitor/index.js +1 -1
  196. package/.jscsrc +0 -73
  197. package/.jshintrc +0 -11
  198. package/lib/less/tree/alpha.js +0 -28
  199. package/lib/less/tree/directive.js +0 -12
  200. package/lib/less/tree/rule.js +0 -12
  201. package/test/less/errors/functions-2-alpha.less +0 -2
  202. package/test/less/errors/functions-2-alpha.txt +0 -3
  203. package/test/less-bom/errors/functions-2-alpha.less +0 -2
  204. package/test/less-bom/errors/functions-2-alpha.txt +0 -3
  205. package/test/sourcemaps/maps/import-map.map +0 -1
@@ -1,3 +1,6 @@
1
+ // TODO: Add tests for browser @plugin
2
+ /*global window */
3
+
1
4
  var AbstractPluginLoader = require("../less/environment/abstract-plugin-loader.js");
2
5
 
3
6
  /**
@@ -5,57 +8,17 @@ var AbstractPluginLoader = require("../less/environment/abstract-plugin-loader.j
5
8
  */
6
9
  var PluginLoader = function(less) {
7
10
  this.less = less;
11
+ // shim for browser require?
8
12
  this.require = require;
9
13
  };
10
14
 
11
15
  PluginLoader.prototype = new AbstractPluginLoader();
12
16
 
13
- PluginLoader.prototype.tryLoadPlugin = function(name, basePath, callback) {
14
- var self = this;
15
- var prefix = name.slice(0, 1);
16
- var explicit = prefix === "." || prefix === "/" || name.slice(-3).toLowerCase() === ".js";
17
- this.tryLoadFromEnvironment(name, basePath, explicit, function(err, data) {
18
- if (explicit) {
19
- callback(err, data);
20
- }
21
- else {
22
- if (!err) {
23
- callback(null, data);
24
- }
25
- else {
26
- self.tryLoadFromEnvironment('less-plugin-' + name, basePath, explicit, function(err2, data) {
27
- callback(err, data);
28
- });
29
- }
30
- }
17
+ PluginLoader.prototype.loadPlugin = function(filename, basePath, context, environment, fileManager) {
18
+ return new Promise(function(fulfill, reject) {
19
+ fileManager.loadFile(filename, basePath, context, environment)
20
+ .then(fulfill).catch(reject);
31
21
  });
32
-
33
- };
34
-
35
- PluginLoader.prototype.tryLoadFromEnvironment = function(filename, basePath, explicit, callback) {
36
- var fileManager = new this.less.FileManager();
37
-
38
- if (basePath) {
39
- filename = (fileManager.extractUrlParts(filename, basePath)).url;
40
- }
41
-
42
- if (filename) {
43
-
44
- filename = fileManager.tryAppendExtension(filename, '.js');
45
-
46
- var done = function(err, data) {
47
- if (err) {
48
- callback(err);
49
- } else {
50
- callback(null, data);
51
- }
52
- };
53
- fileManager.loadFile(filename, null, null, null, done);
54
-
55
- }
56
- else {
57
- callback({ message: 'Plugin could not be found.'});
58
- }
59
22
  };
60
23
 
61
24
  module.exports = PluginLoader;
@@ -16,7 +16,7 @@ module.exports = {
16
16
  try {
17
17
  options[opt] = JSON.parse(tag.dataset[opt]);
18
18
  }
19
- catch(_) {}
19
+ catch (_) {}
20
20
  }
21
21
  }
22
22
  }
@@ -1,14 +1,10 @@
1
1
  var path = require('path'),
2
2
  fs = require('./fs'),
3
- PromiseConstructor,
3
+ PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
4
4
  AbstractFileManager = require("../less/environment/abstract-file-manager.js");
5
5
 
6
- try {
7
- PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
8
- } catch(e) {
9
- }
10
-
11
6
  var FileManager = function() {
7
+ this.contents = {};
12
8
  };
13
9
 
14
10
  FileManager.prototype = new AbstractFileManager();
@@ -21,88 +17,122 @@ FileManager.prototype.supportsSync = function(filename, currentDirectory, option
21
17
  };
22
18
 
23
19
  FileManager.prototype.loadFile = function(filename, currentDirectory, options, environment, callback) {
20
+
24
21
  var fullFilename,
25
- data,
26
22
  isAbsoluteFilename = this.isPathAbsolute(filename),
27
- filenamesTried = [];
23
+ filenamesTried = [],
24
+ self = this,
25
+ prefix = filename.slice(0, 1),
26
+ explicit = prefix === "." || prefix === "/",
27
+ result = null;
28
28
 
29
29
  options = options || {};
30
30
 
31
- if (options.syncImport || !PromiseConstructor) {
32
- data = this.loadFileSync(filename, currentDirectory, options, environment, 'utf-8');
33
- callback(data.error, data);
34
- return;
35
- }
31
+ var paths = isAbsoluteFilename ? [''] : [currentDirectory];
36
32
 
37
- var paths = isAbsoluteFilename ? [""] : [currentDirectory];
38
33
  if (options.paths) { paths.push.apply(paths, options.paths); }
39
- if (!isAbsoluteFilename && paths.indexOf('.') === -1) { paths.push('.'); }
40
34
 
41
- // promise is guaranteed to be asyncronous
42
- // which helps as it allows the file handle
43
- // to be closed before it continues with the next file
44
- return new PromiseConstructor(function(fulfill, reject) {
45
- (function tryPathIndex(i) {
46
- if (i < paths.length) {
47
- fullFilename = filename;
48
- if (paths[i]) {
49
- fullFilename = path.join(paths[i], fullFilename);
50
- }
51
- fs.stat(fullFilename, function (err) {
52
- if (err) {
53
- filenamesTried.push(fullFilename);
54
- tryPathIndex(i + 1);
55
- } else {
56
- fs.readFile(fullFilename, 'utf-8', function(e, data) {
57
- if (e) { reject(e); return; }
35
+ // Search node_modules
36
+ if (!explicit) { paths.push.apply(paths, this.modulePaths); }
58
37
 
59
- fulfill({ contents: data, filename: fullFilename});
60
- });
61
- }
62
- });
63
- } else {
64
- reject({ type: 'File', message: "'" + filename + "' wasn't found. Tried - " + filenamesTried.join(",") });
65
- }
66
- }(0));
67
- });
68
- };
38
+ if (!isAbsoluteFilename && paths.indexOf('.') === -1) { paths.push('.'); }
69
39
 
70
- FileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment, encoding) {
71
- var fullFilename, paths, filenamesTried = [], isAbsoluteFilename = this.isPathAbsolute(filename) , data;
72
- options = options || {};
40
+ var prefixes = options.prefixes || [''];
41
+ var fileParts = this.extractUrlParts(filename);
73
42
 
74
- paths = isAbsoluteFilename ? [""] : [currentDirectory];
75
- if (options.paths) {
76
- paths.push.apply(paths, options.paths);
43
+ if (options.syncImport) {
44
+ getFileData(returnData, returnData);
45
+ if (callback) {
46
+ callback(result.error, result);
47
+ }
48
+ else {
49
+ return result;
50
+ }
77
51
  }
78
- if (!isAbsoluteFilename && paths.indexOf('.') === -1) {
79
- paths.push('.');
52
+ else {
53
+ // promise is guaranteed to be asyncronous
54
+ // which helps as it allows the file handle
55
+ // to be closed before it continues with the next file
56
+ return new PromiseConstructor(getFileData);
80
57
  }
81
58
 
82
- var err, result;
83
- for (var i = 0; i < paths.length; i++) {
84
- try {
85
- fullFilename = filename;
86
- if (paths[i]) {
87
- fullFilename = path.join(paths[i], fullFilename);
88
- }
89
- filenamesTried.push(fullFilename);
90
- fs.statSync(fullFilename);
91
- break;
92
- } catch (e) {
93
- fullFilename = null;
59
+ function returnData(data) {
60
+ if (!data.filename) {
61
+ result = { error: data };
62
+ }
63
+ else {
64
+ result = data;
94
65
  }
95
66
  }
96
67
 
97
- if (!fullFilename) {
98
- err = { type: 'File', message: "'" + filename + "' wasn't found. Tried - " + filenamesTried.join(",") };
99
- result = { error: err };
100
- } else {
101
- data = fs.readFileSync(fullFilename, encoding);
102
- result = { contents: data, filename: fullFilename};
68
+ function getFileData(fulfill, reject) {
69
+ (function tryPathIndex(i) {
70
+ if (i < paths.length) {
71
+ (function tryPrefix(j) {
72
+ if (j < prefixes.length) {
73
+ fullFilename = fileParts.rawPath + prefixes[j] + fileParts.filename;
74
+
75
+ if (paths[i]) {
76
+ fullFilename = path.join(paths[i], fullFilename);
77
+ }
78
+
79
+ if (paths[i].indexOf('node_modules') > -1) {
80
+ try {
81
+ fullFilename = require.resolve(fullFilename);
82
+ }
83
+ catch (e) {}
84
+ }
85
+
86
+ fullFilename = options.ext ? self.tryAppendExtension(fullFilename, options.ext) : fullFilename;
87
+
88
+ if (self.contents[fullFilename]) {
89
+ fulfill({ contents: self.contents[fullFilename], filename: fullFilename});
90
+ }
91
+ else {
92
+ var readFileArgs = [fullFilename];
93
+ if (!options.rawBuffer) {
94
+ readFileArgs.push('utf-8');
95
+ }
96
+ if (options.syncImport) {
97
+ try {
98
+ var data = fs.readFileSync.apply(this, readFileArgs);
99
+ self.contents[fullFilename] = data;
100
+ fulfill({ contents: data, filename: fullFilename});
101
+ }
102
+ catch (e) {
103
+ filenamesTried.push(fullFilename);
104
+ return tryPrefix(j + 1);
105
+ }
106
+ }
107
+ else {
108
+ readFileArgs.push(function(e, data) {
109
+ if (e) {
110
+ filenamesTried.push(fullFilename);
111
+ return tryPrefix(j + 1);
112
+ }
113
+ self.contents[fullFilename] = data;
114
+ fulfill({ contents: data, filename: fullFilename});
115
+ });
116
+ fs.readFile.apply(this, readFileArgs);
117
+ }
118
+
119
+ }
120
+
121
+ }
122
+ else {
123
+ tryPathIndex(i + 1);
124
+ }
125
+ })(0);
126
+ } else {
127
+ reject({ type: 'File', message: "'" + filename + "' wasn't found. Tried - " + filenamesTried.join(",") });
128
+ }
129
+ }(0));
103
130
  }
131
+ };
104
132
 
105
- return result;
133
+ FileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment) {
134
+ options.syncImport = true;
135
+ return this.loadFile(filename, currentDirectory, options, environment);
106
136
  };
107
137
 
108
138
  module.exports = FileManager;
@@ -3,7 +3,7 @@ try
3
3
  {
4
4
  fs = require("graceful-fs");
5
5
  }
6
- catch(e)
6
+ catch (e)
7
7
  {
8
8
  fs = require("fs");
9
9
  }
@@ -1,7 +1,7 @@
1
1
  module.exports = function(environment) {
2
2
  var Dimension = require("../less/tree/dimension"),
3
- Expression = require("../less/tree/expression"),
4
- functionRegistry = require("./../less/functions/function-registry");
3
+ Expression = require("../less/tree/expression"),
4
+ functionRegistry = require("./../less/functions/function-registry");
5
5
 
6
6
  function imageSize(functionContext, filePathNode) {
7
7
  var filePath = filePathNode.value;
@@ -3,7 +3,8 @@ var environment = require("./environment"),
3
3
  UrlFileManager = require("./url-file-manager"),
4
4
  createFromEnvironment = require("../less"),
5
5
  less = createFromEnvironment(environment, [new FileManager(), new UrlFileManager()]),
6
- lesscHelper = require('./lessc-helper');
6
+ lesscHelper = require('./lessc-helper'),
7
+ path = require('path');
7
8
 
8
9
  // allow people to create less with their own environment
9
10
  less.createFromEnvironment = createFromEnvironment;
@@ -12,63 +13,12 @@ less.PluginLoader = require("./plugin-loader");
12
13
  less.fs = require("./fs");
13
14
  less.FileManager = FileManager;
14
15
  less.UrlFileManager = UrlFileManager;
15
- less.options = less.options || {};
16
16
 
17
- less.formatError = function(ctx, options) {
18
- options = options || {};
19
-
20
- var message = "";
21
- var extract = ctx.extract;
22
- var error = [];
23
- var stylize = options.color ? lesscHelper.stylize : function (str) { return str; };
24
-
25
- // only output a stack if it isn't a less error
26
- if (ctx.stack && !ctx.type) { return stylize(ctx.stack, 'red'); }
27
-
28
- if (!ctx.hasOwnProperty('index') || !extract) {
29
- return ctx.stack || ctx.message;
30
- }
31
-
32
- if (typeof extract[0] === 'string') {
33
- error.push(stylize((ctx.line - 1) + ' ' + extract[0], 'grey'));
34
- }
35
-
36
- if (typeof extract[1] === 'string') {
37
- var errorTxt = ctx.line + ' ';
38
- if (extract[1]) {
39
- errorTxt += extract[1].slice(0, ctx.column) +
40
- stylize(stylize(stylize(extract[1].substr(ctx.column, 1), 'bold') +
41
- extract[1].slice(ctx.column + 1), 'red'), 'inverse');
42
- }
43
- error.push(errorTxt);
44
- }
45
-
46
- if (typeof extract[2] === 'string') {
47
- error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
48
- }
49
- error = error.join('\n') + stylize('', 'reset') + '\n';
50
-
51
- message += stylize(ctx.type + 'Error: ' + ctx.message, 'red');
52
- if (ctx.filename) {
53
- message += stylize(' in ', 'red') + ctx.filename +
54
- stylize(' on line ' + ctx.line + ', column ' + (ctx.column + 1) + ':', 'grey');
55
- }
56
-
57
- message += '\n' + error;
58
-
59
- if (ctx.callLine) {
60
- message += stylize('from ', 'red') + (ctx.filename || '') + '/n';
61
- message += stylize(ctx.callLine, 'grey') + ' ' + ctx.callExtract + '/n';
62
- }
63
-
64
- return message;
65
- };
66
-
67
- less.writeError = function (ctx, options) {
68
- options = options || {};
69
- if (options.silent) { return; }
70
- console.error(less.formatError(ctx, options));
71
- };
17
+ // Set up options
18
+ less.options = require('../less/default-options')();
19
+ less.options.paths = [
20
+ path.join(process.cwd(), "node_modules")
21
+ ];
72
22
 
73
23
  // provide image-size functionality
74
24
  require('./image-size')(less.environment);
@@ -3,7 +3,7 @@
3
3
  // helper functions for lessc
4
4
  var lessc_helper = {
5
5
 
6
- //Stylize a string
6
+ // Stylize a string
7
7
  stylize : function(str, style) {
8
8
  var styles = {
9
9
  'reset' : [0, 0],
@@ -19,49 +19,49 @@ var lessc_helper = {
19
19
  '\x1b[' + styles[style][1] + 'm';
20
20
  },
21
21
 
22
- //Print command line options
22
+ // Print command line options
23
23
  printUsage: function() {
24
24
  console.log("usage: lessc [option option=parameter ...] <source> [destination]");
25
25
  console.log("");
26
26
  console.log("If source is set to `-' (dash or hyphen-minus), input is read from stdin.");
27
27
  console.log("");
28
28
  console.log("options:");
29
- console.log(" -h, --help Prints help (this message) and exit.");
30
- console.log(" --include-path=PATHS Sets include paths. Separated by `:'. `;' also supported on windows.");
31
- console.log(" -M, --depends Outputs a makefile import dependency list to stdout.");
32
- console.log(" --no-color Disables colorized output.");
33
- console.log(" --no-ie-compat Disables IE compatibility checks.");
34
- console.log(" --inline-js Enables inline JavaScript in less files");
35
- console.log(" -l, --lint Syntax check only (lint).");
36
- console.log(" -s, --silent Suppresses output of error messages.");
37
- console.log(" --strict-imports Forces evaluation of imports.");
38
- console.log(" --insecure Allows imports from insecure https hosts.");
39
- console.log(" -v, --version Prints version number and exit.");
40
- console.log(" --verbose Be verbose.");
41
- console.log(" --source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map).");
42
- console.log(" --source-map-rootpath=X Adds this path onto the sourcemap filename and less file paths.");
43
- console.log(" --source-map-basepath=X Sets sourcemap base path, defaults to current working directory.");
44
- console.log(" --source-map-less-inline Puts the less files into the map instead of referencing them.");
45
- console.log(" --source-map-map-inline Puts the map (and any less files) as a base64 data uri into the output css file.");
46
- console.log(" --source-map-url=URL Sets a custom URL to map file, for sourceMappingURL comment");
47
- console.log(" in generated CSS file.");
48
- console.log(" -rp, --rootpath=URL Sets rootpath for url rewriting in relative imports and urls");
49
- console.log(" Works with or without the relative-urls option.");
50
- console.log(" -ru, --relative-urls Re-writes relative urls to the base less file.");
51
- console.log(" -sm=on|off Turns on or off strict math, where in strict mode, math.");
52
- console.log(" --strict-math=on|off Requires brackets. This option may default to on and then");
53
- console.log(" be removed in the future.");
54
- console.log(" -su=on|off Allows mixed units, e.g. 1px+1em or 1px*1px which have units");
55
- console.log(" --strict-units=on|off that cannot be represented.");
56
- console.log(" --global-var='VAR=VALUE' Defines a variable that can be referenced by the file.");
57
- console.log(" --modify-var='VAR=VALUE' Modifies a variable already declared in the file.");
58
- console.log(" --url-args='QUERYSTRING' Adds params into url tokens (e.g. 42, cb=42 or 'a=1&b=2')");
59
- console.log(" --plugin=PLUGIN=OPTIONS Loads a plugin. You can also omit the --plugin= if the plugin begins");
60
- console.log(" less-plugin. E.g. the clean css plugin is called less-plugin-clean-css");
61
- console.log(" once installed (npm install less-plugin-clean-css), use either with");
62
- console.log(" --plugin=less-plugin-clean-css or just --clean-css");
63
- console.log(" specify options afterwards e.g. --plugin=less-plugin-clean-css=\"advanced\"");
64
- console.log(" or --clean-css=\"advanced\"");
29
+ console.log(" -h, --help Prints help (this message) and exit.");
30
+ console.log(" --include-path=PATHS Sets include paths. Separated by `:'. `;' also supported on windows.");
31
+ console.log(" -M, --depends Outputs a makefile import dependency list to stdout.");
32
+ console.log(" --no-color Disables colorized output.");
33
+ console.log(" --ie-compat Enables IE8 compatibility checks.");
34
+ console.log(" --js Enables inline JavaScript in less files");
35
+ console.log(" -l, --lint Syntax check only (lint).");
36
+ console.log(" -s, --silent Suppresses output of error messages.");
37
+ console.log(" --strict-imports Forces evaluation of imports.");
38
+ console.log(" --insecure Allows imports from insecure https hosts.");
39
+ console.log(" -v, --version Prints version number and exit.");
40
+ console.log(" --verbose Be verbose.");
41
+ console.log(" --source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map).");
42
+ console.log(" --source-map-rootpath=X Adds this path onto the sourcemap filename and less file paths.");
43
+ console.log(" --source-map-basepath=X Sets sourcemap base path, defaults to current working directory.");
44
+ console.log(" --source-map-include-source Puts the less files into the map instead of referencing them.");
45
+ console.log(" --source-map-inline Puts the map (and any less files) as a base64 data uri into the output css file.");
46
+ console.log(" --source-map-url=URL Sets a custom URL to map file, for sourceMappingURL comment");
47
+ console.log(" in generated CSS file.");
48
+ console.log(" -rp, --rootpath=URL Sets rootpath for url rewriting in relative imports and urls");
49
+ console.log(" Works with or without the relative-urls option.");
50
+ console.log(" -ru, --relative-urls Re-writes relative urls to the base less file.");
51
+ console.log(" -sm=on|off Turns on or off strict math, where in strict mode, math.");
52
+ console.log(" --strict-math=on|off Requires brackets. This option may default to on and then");
53
+ console.log(" be removed in the future.");
54
+ console.log(" -su=on|off Allows mixed units, e.g. 1px+1em or 1px*1px which have units");
55
+ console.log(" --strict-units=on|off that cannot be represented.");
56
+ console.log(" --global-var='VAR=VALUE' Defines a variable that can be referenced by the file.");
57
+ console.log(" --modify-var='VAR=VALUE' Modifies a variable already declared in the file.");
58
+ console.log(" --url-args='QUERYSTRING' Adds params into url tokens (e.g. 42, cb=42 or 'a=1&b=2')");
59
+ console.log(" --plugin=PLUGIN=OPTIONS Loads a plugin. You can also omit the --plugin= if the plugin begins");
60
+ console.log(" less-plugin. E.g. the clean css plugin is called less-plugin-clean-css");
61
+ console.log(" once installed (npm install less-plugin-clean-css), use either with");
62
+ console.log(" --plugin=less-plugin-clean-css or just --clean-css");
63
+ console.log(" specify options afterwards e.g. --plugin=less-plugin-clean-css=\"advanced\"");
64
+ console.log(" or --clean-css=\"advanced\"");
65
65
  console.log("");
66
66
  console.log("-------------------------- Deprecated ----------------");
67
67
  console.log(" --line-numbers=TYPE Outputs filename and line numbers.");
@@ -1,4 +1,5 @@
1
1
  var path = require("path"),
2
+ PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise,
2
3
  AbstractPluginLoader = require("../less/environment/abstract-plugin-loader.js");
3
4
 
4
5
  /**
@@ -23,93 +24,31 @@ var PluginLoader = function(less) {
23
24
 
24
25
  PluginLoader.prototype = new AbstractPluginLoader();
25
26
 
26
- PluginLoader.prototype.tryLoadPlugin = function(name, basePath, callback) {
27
+ PluginLoader.prototype.loadPlugin = function(filename, basePath, context, environment, fileManager) {
27
28
  var self = this;
28
- var prefix = name.slice(0, 1);
29
- var explicit = prefix === "." || prefix === "/" || name.slice(-3).toLowerCase() === ".js";
30
- if (explicit) {
31
- this.tryLoadFromEnvironment(name, basePath, explicit, callback);
29
+ var prefix = filename.slice(0, 1);
30
+ var explicit = prefix === "." || prefix === "/" || filename.slice(-3).toLowerCase() === ".js";
31
+ if (!explicit) {
32
+ context.prefixes = ['less-plugin-', ''];
32
33
  }
33
- else {
34
- this.tryLoadFromEnvironment('less-plugin-' + name, basePath, explicit, function(err, data) {
35
- if (!err) {
36
- callback(null, data);
37
- }
38
- else {
39
- self.tryLoadFromEnvironment(name, basePath, explicit, callback);
40
- }
41
- });
42
- }
43
-
44
- };
45
-
46
- PluginLoader.prototype.tryLoadFromEnvironment = function(name, basePath, explicit, callback) {
47
- var filename = name;
48
- var self = this;
49
34
 
50
- function getFile(filename) {
51
- var fileManager = new self.less.FileManager();
52
-
53
- filename = fileManager.tryAppendExtension(filename, '.js');
54
- fileManager.loadFile(filename).then(
35
+ return new PromiseConstructor(function(fulfill, reject) {
36
+ fileManager.loadFile(filename, basePath, context, environment).then(
55
37
  function(data) {
56
38
  try {
57
- self.require = self.requireRelative(filename);
39
+ self.require = self.requireRelative(data.filename);
40
+ fulfill(data);
58
41
  }
59
- catch(e) {
60
- callback(e);
42
+ catch (e) {
43
+ console.log(e);
44
+ reject(e);
61
45
  }
62
- callback(null, data);
63
- },
64
-
65
- function(err) {
66
- callback(err);
67
- }
68
- );
69
- }
70
- if (explicit) {
71
- if (basePath) {
72
- filename = path.join(basePath, name);
73
- }
74
- getFile(filename);
75
- }
76
- else {
77
- // Search node_modules for a possible plugin name match
78
- try {
79
- filename = require.resolve(path.join("../../../", name));
80
- }
81
- catch(e) {
82
- }
83
- // is installed as a sub dependency of the current folder
84
- try {
85
- filename = require.resolve(path.join(process.cwd(), "node_modules", name));
86
- }
87
- catch(e) {
88
- }
89
- // is referenced relative to the current directory
90
- try {
91
- filename = require.resolve(path.join(process.cwd(), name));
92
- }
93
- catch(e) {
94
- }
95
- // unlikely - would have to be a dependency of where this code was running (less.js)...
96
- if (name[0] !== '.') {
97
- try {
98
- filename = require.resolve(name);
99
46
  }
100
- catch(e) {
101
- }
102
- }
103
- if (basePath) {
104
- filename = path.join(basePath, name);
105
- }
106
- if (filename) {
107
- getFile(filename);
108
- }
109
- else {
110
- callback({ message: 'Plugin could not be found.'});
111
- }
112
- }
47
+ ).catch(function(err) {
48
+ reject(err);
49
+ });
50
+ });
51
+
113
52
  };
114
53
 
115
54
  module.exports = PluginLoader;
@@ -21,7 +21,7 @@ UrlFileManager.prototype.loadFile = function(filename, currentDirectory, options
21
21
  return new PromiseConstructor(function(fulfill, reject) {
22
22
  if (request === undefined) {
23
23
  try { request = require('request'); }
24
- catch(e) { request = null; }
24
+ catch (e) { request = null; }
25
25
  }
26
26
  if (!request) {
27
27
  reject({ type: 'File', message: "optional dependency 'request' required to import over http(s)\n" });