less 3.11.0 → 3.11.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.
@@ -14,17 +14,8 @@ class AbstractFileManager {
14
14
  return filename.slice(0, j + 1);
15
15
  }
16
16
 
17
- isPathWithExtension(path, ext) {
18
- let extPos = path.lastIndexOf(ext);
19
- return extPos !== -1 && extPos === path.length - ext.length
20
- }
21
-
22
17
  tryAppendExtension(path, ext) {
23
- if (this.isPathWithExtension(path, ext)) {
24
- return path;
25
- }
26
-
27
- return path + ext;
18
+ return /(\.[a-z]*$)|([\?;].*)$/.test(path) ? path : path + ext;
28
19
  }
29
20
 
30
21
  tryAppendLessExtension(path) {
@@ -133,4 +124,4 @@ class AbstractFileManager {
133
124
  };
134
125
  }
135
126
 
136
- export default AbstractFileManager;
127
+ export default AbstractFileManager;
package/lib/less/index.js CHANGED
@@ -42,7 +42,7 @@ export default (environment, fileManagers) => {
42
42
  * It's not clear what should / must be public and why.
43
43
  */
44
44
  const initial = {
45
- version: [3, 11, 0],
45
+ version: [3, 11, 1],
46
46
  data,
47
47
  tree,
48
48
  Environment,
@@ -12,20 +12,6 @@ class FileManager extends AbstractFileManager {
12
12
  return true;
13
13
  }
14
14
 
15
- getPossibleFileExtensions(path, ext) {
16
- if (this.isPathWithExtension(path, ext)) {
17
- return [''];
18
- }
19
-
20
- // if file doesn't have dot in name it require extention
21
- if (path.indexOf(".") === -1) {
22
- return [ext];
23
- }
24
-
25
- // path has dots in name it might be with or without extention (like .css)
26
- return [ext, ''];
27
- }
28
-
29
15
  join(basePath, laterPath) {
30
16
  if (!basePath) {
31
17
  return laterPath;
@@ -71,29 +57,6 @@ class FileManager extends AbstractFileManager {
71
57
  }
72
58
  }
73
59
 
74
- tryToLoad(href) {
75
- return new Promise((resolve, reject) => {
76
- if (options.useFileCache && fileCache[href]) {
77
- try {
78
- const lessText = fileCache[href];
79
- return resolve({ contents: lessText, filename: href, webInfo: { lastModified: new Date() }});
80
- } catch (e) {
81
- return reject({ filename: href, message: `Error loading file ${href} error was ${e.message}` });
82
- }
83
- }
84
-
85
- this.doXHR(href, options.mime, function doXHRCallback(data, lastModified) {
86
- // per file cache
87
- fileCache[href] = data;
88
-
89
- // Use remote copy (re-parse)
90
- resolve({ contents: data, filename: href, webInfo: { lastModified }});
91
- }, function doXHRError(status, url) {
92
- reject({ type: 'File', message: `'${url}' wasn't found (${status})`, href });
93
- });
94
- });
95
- }
96
-
97
60
  supports() {
98
61
  return true;
99
62
  }
@@ -110,7 +73,7 @@ class FileManager extends AbstractFileManager {
110
73
  filename = currentDirectory + filename;
111
74
  }
112
75
 
113
- const extensions = this.getPossibleFileExtensions(filename, options.ext || '');
76
+ filename = options.ext ? this.tryAppendExtension(filename, options.ext) : filename;
114
77
 
115
78
  options = options || {};
116
79
 
@@ -118,12 +81,28 @@ class FileManager extends AbstractFileManager {
118
81
  // some context variables for imports
119
82
  const hrefParts = this.extractUrlParts(filename, window.location.href);
120
83
  const href = hrefParts.url;
121
- const hrefs = extensions.map(ext => this.tryAppendExtension(href, ext))
84
+ const self = this;
85
+
86
+ return new Promise((resolve, reject) => {
87
+ if (options.useFileCache && fileCache[href]) {
88
+ try {
89
+ const lessText = fileCache[href];
90
+ return resolve({ contents: lessText, filename: href, webInfo: { lastModified: new Date() }});
91
+ } catch (e) {
92
+ return reject({ filename: href, message: `Error loading file ${href} error was ${e.message}` });
93
+ }
94
+ }
95
+
96
+ self.doXHR(href, options.mime, function doXHRCallback(data, lastModified) {
97
+ // per file cache
98
+ fileCache[href] = data;
122
99
 
123
- return hrefs.reduce(
124
- (prev, href) => prev.catch(() => this.tryToLoad(href)),
125
- this.tryToLoad(hrefs.shift())
126
- );
100
+ // Use remote copy (re-parse)
101
+ resolve({ contents: data, filename: href, webInfo: { lastModified }});
102
+ }, function doXHRError(status, url) {
103
+ reject({ type: 'File', message: `'${url}' wasn't found (${status})`, href });
104
+ });
105
+ });
127
106
  }
128
107
  }
129
108
 
@@ -3,32 +3,19 @@ import fs from './fs';
3
3
  import AbstractFileManager from '../less/environment/abstract-file-manager.js';
4
4
 
5
5
  class FileManager extends AbstractFileManager {
6
- constructor() {
7
- super();
8
-
9
- this.contents = {};
10
- }
11
-
12
- supports(filename, currentDirectory, options, environment) {
6
+ supports() {
13
7
  return true;
14
8
  }
15
9
 
16
- supportsSync(filename, currentDirectory, options, environment) {
10
+ supportsSync() {
17
11
  return true;
18
12
  }
19
13
 
20
- getPossibleFileExtensions(path, ext) {
21
- if (this.isPathWithExtension(path, ext)) {
22
- return [''];
23
- }
24
-
25
- return ['', ext];
26
- }
27
-
28
14
  loadFile(filename, currentDirectory, options, environment, callback) {
29
15
  let fullFilename;
30
16
  const isAbsoluteFilename = this.isPathAbsolute(filename);
31
17
  const filenamesTried = [];
18
+ const self = this;
32
19
  const prefix = filename.slice(0, 1);
33
20
  const explicit = prefix === '.' || prefix === '/';
34
21
  let result = null;
@@ -44,8 +31,6 @@ class FileManager extends AbstractFileManager {
44
31
  if (!isAbsoluteFilename && paths.indexOf('.') === -1) { paths.push('.'); }
45
32
 
46
33
  const prefixes = options.prefixes || [''];
47
-
48
- const extensions = this.getPossibleFileExtensions(filename, options.ext);
49
34
  const fileParts = this.extractUrlParts(filename);
50
35
 
51
36
  if (options.syncImport) {
@@ -78,54 +63,69 @@ class FileManager extends AbstractFileManager {
78
63
  if (i < paths.length) {
79
64
  (function tryPrefix(j) {
80
65
  if (j < prefixes.length) {
81
- (function tryExtension(k) {
82
- if (k < extensions.length) {
83
- isNodeModule = false;
84
- fullFilename = fileParts.rawPath + prefixes[j] + fileParts.filename + extensions[k];
66
+ isNodeModule = false;
67
+ fullFilename = fileParts.rawPath + prefixes[j] + fileParts.filename;
85
68
 
86
- if (paths[i]) {
87
- fullFilename = path.join(paths[i], fullFilename);
88
- }
69
+ if (paths[i]) {
70
+ fullFilename = path.join(paths[i], fullFilename);
71
+ }
89
72
 
90
- if (!explicit && paths[i] === '.') {
91
- try {
92
- fullFilename = require.resolve(fullFilename);
93
- isNodeModule = true;
94
- }
95
- catch (e) {
96
- filenamesTried.push(npmPrefix + fullFilename);
97
- }
98
- }
99
-
100
- const readFileArgs = [fullFilename];
101
- if (!options.rawBuffer) {
102
- readFileArgs.push('utf-8');
103
- }
104
- if (options.syncImport) {
105
- try {
106
- const data = fs.readFileSync.apply(this, readFileArgs);
107
- fulfill({ contents: data, filename: fullFilename});
108
- }
109
- catch (e) {
110
- filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
111
- return tryExtension(k + 1);
112
- }
73
+ if (!explicit && paths[i] === '.') {
74
+ try {
75
+ fullFilename = require.resolve(fullFilename);
76
+ isNodeModule = true;
77
+ }
78
+ catch (e) {
79
+ filenamesTried.push(npmPrefix + fullFilename);
80
+ tryWithExtension();
81
+ }
82
+ }
83
+ else {
84
+ tryWithExtension();
85
+ }
86
+
87
+ function tryWithExtension() {
88
+ const extFilename = options.ext ? self.tryAppendExtension(fullFilename, options.ext) : fullFilename;
89
+
90
+ if (extFilename !== fullFilename && !explicit && paths[i] === '.') {
91
+ try {
92
+ fullFilename = require.resolve(extFilename);
93
+ isNodeModule = true;
113
94
  }
114
- else {
115
- readFileArgs.push(function(e, data) {
116
- if (e) {
117
- filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
118
- return tryExtension(k + 1);
119
- }
120
- fulfill({ contents: data, filename: fullFilename});
121
- });
122
- fs.readFile.apply(this, readFileArgs);
95
+ catch (e) {
96
+ filenamesTried.push(npmPrefix + extFilename);
97
+ fullFilename = extFilename;
123
98
  }
124
99
  }
125
100
  else {
126
- tryPrefix(j + 1)
101
+ fullFilename = extFilename;
102
+ }
103
+ }
104
+
105
+ const readFileArgs = [fullFilename];
106
+ if (!options.rawBuffer) {
107
+ readFileArgs.push('utf-8');
108
+ }
109
+ if (options.syncImport) {
110
+ try {
111
+ const data = fs.readFileSync.apply(this, readFileArgs);
112
+ fulfill({ contents: data, filename: fullFilename});
127
113
  }
128
- })(0);
114
+ catch (e) {
115
+ filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
116
+ return tryPrefix(j + 1);
117
+ }
118
+ }
119
+ else {
120
+ readFileArgs.push(function(e, data) {
121
+ if (e) {
122
+ filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
123
+ return tryPrefix(j + 1);
124
+ }
125
+ fulfill({ contents: data, filename: fullFilename});
126
+ });
127
+ fs.readFile.apply(this, readFileArgs);
128
+ }
129
129
  }
130
130
  else {
131
131
  tryPathIndex(i + 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "less",
3
- "version": "3.11.0",
3
+ "version": "3.11.1",
4
4
  "description": "Leaner CSS",
5
5
  "homepage": "http://lesscss.org",
6
6
  "author": {
@@ -117,6 +117,7 @@
117
117
  "rawcurrent": "https://raw.github.com/less/less.js/v",
118
118
  "sourcearchive": "https://github.com/less/less.js/archive/v",
119
119
  "dependencies": {
120
- "clone": "^2.1.2"
120
+ "clone": "^2.1.2",
121
+ "tslib": "^1.10.0"
121
122
  }
122
123
  }
@@ -1,9 +1,6 @@
1
1
  #import {
2
2
  color: red;
3
3
  }
4
- .test-d > h1 {
5
- height: 20px;
6
- }
7
4
  body {
8
5
  width: 100%;
9
6
  }
@@ -1,7 +1,5 @@
1
1
  @import "import/import-once-test-c";
2
2
  @import "import/import-once-test-c";
3
- @import "import/import.once.test.d";
4
- @import "import/import.once.test.d.less";
5
3
  @import "import/import-once-test-c.less";
6
4
  @import "import/deeper/import-once-test-a";
7
5
  @import (multiple) "import/import-test-f.less";
@@ -1,3 +0,0 @@
1
- .test-d > h1 {
2
- height: 20px;
3
- }