Skip to content

Commit

Permalink
Fixes #3469 - Include tslib dependency (#3475)
Browse files Browse the repository at this point in the history
* Include tslib dependency
* Revert #3453
  • Loading branch information
matthew-dean authored Feb 11, 2020
1 parent 1adaadb commit 842386b
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 295 deletions.
120 changes: 59 additions & 61 deletions bin/lessc
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,8 @@ var AbstractFileManager = /** @class */ (function () {
}
return filename.slice(0, j + 1);
};
AbstractFileManager.prototype.isPathWithExtension = function (path, ext) {
var extPos = path.lastIndexOf(ext);
return extPos !== -1 && extPos === path.length - ext.length;
};
AbstractFileManager.prototype.tryAppendExtension = function (path, ext) {
if (this.isPathWithExtension(path, ext)) {
return path;
}
return path + ext;
return /(\.[a-z]*$)|([\?;].*)$/.test(path) ? path : path + ext;
};
AbstractFileManager.prototype.tryAppendLessExtension = function (path) {
return this.tryAppendExtension(path, '.less');
Expand Down Expand Up @@ -295,26 +288,19 @@ var AbstractFileManager = /** @class */ (function () {
var FileManager = /** @class */ (function (_super) {
tslib.__extends(FileManager, _super);
function FileManager() {
var _this = _super.call(this) || this;
_this.contents = {};
return _this;
return _super !== null && _super.apply(this, arguments) || this;
}
FileManager.prototype.supports = function (filename, currentDirectory, options, environment) {
FileManager.prototype.supports = function () {
return true;
};
FileManager.prototype.supportsSync = function (filename, currentDirectory, options, environment) {
FileManager.prototype.supportsSync = function () {
return true;
};
FileManager.prototype.getPossibleFileExtensions = function (path, ext) {
if (this.isPathWithExtension(path, ext)) {
return [''];
}
return ['', ext];
};
FileManager.prototype.loadFile = function (filename, currentDirectory, options, environment, callback) {
var fullFilename;
var isAbsoluteFilename = this.isPathAbsolute(filename);
var filenamesTried = [];
var self = this;
var prefix = filename.slice(0, 1);
var explicit = prefix === '.' || prefix === '/';
var result = null;
Expand All @@ -329,7 +315,6 @@ var FileManager = /** @class */ (function (_super) {
paths.push('.');
}
var prefixes = options.prefixes || [''];
var extensions = this.getPossibleFileExtensions(filename, options.ext);
var fileParts = this.extractUrlParts(filename);
if (options.syncImport) {
getFileData(returnData, returnData);
Expand Down Expand Up @@ -359,51 +344,64 @@ var FileManager = /** @class */ (function (_super) {
if (i < paths.length) {
(function tryPrefix(j) {
if (j < prefixes.length) {
(function tryExtension(k) {
if (k < extensions.length) {
isNodeModule = false;
fullFilename = fileParts.rawPath + prefixes[j] + fileParts.filename + extensions[k];
if (paths[i]) {
fullFilename = path.join(paths[i], fullFilename);
}
if (!explicit && paths[i] === '.') {
try {
fullFilename = require.resolve(fullFilename);
isNodeModule = true;
}
catch (e) {
filenamesTried.push(npmPrefix + fullFilename);
}
}
var readFileArgs = [fullFilename];
if (!options.rawBuffer) {
readFileArgs.push('utf-8');
}
if (options.syncImport) {
try {
var data = fs$1.readFileSync.apply(this, readFileArgs);
fulfill({ contents: data, filename: fullFilename });
}
catch (e) {
filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
return tryExtension(k + 1);
}
isNodeModule = false;
fullFilename = fileParts.rawPath + prefixes[j] + fileParts.filename;
if (paths[i]) {
fullFilename = path.join(paths[i], fullFilename);
}
if (!explicit && paths[i] === '.') {
try {
fullFilename = require.resolve(fullFilename);
isNodeModule = true;
}
catch (e) {
filenamesTried.push(npmPrefix + fullFilename);
tryWithExtension();
}
}
else {
tryWithExtension();
}
function tryWithExtension() {
var extFilename = options.ext ? self.tryAppendExtension(fullFilename, options.ext) : fullFilename;
if (extFilename !== fullFilename && !explicit && paths[i] === '.') {
try {
fullFilename = require.resolve(extFilename);
isNodeModule = true;
}
else {
readFileArgs.push(function (e, data) {
if (e) {
filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
return tryExtension(k + 1);
}
fulfill({ contents: data, filename: fullFilename });
});
fs$1.readFile.apply(this, readFileArgs);
catch (e) {
filenamesTried.push(npmPrefix + extFilename);
fullFilename = extFilename;
}
}
else {
tryPrefix(j + 1);
fullFilename = extFilename;
}
})(0);
}
var readFileArgs = [fullFilename];
if (!options.rawBuffer) {
readFileArgs.push('utf-8');
}
if (options.syncImport) {
try {
var data = fs$1.readFileSync.apply(this, readFileArgs);
fulfill({ contents: data, filename: fullFilename });
}
catch (e) {
filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
return tryPrefix(j + 1);
}
}
else {
readFileArgs.push(function (e, data) {
if (e) {
filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
return tryPrefix(j + 1);
}
fulfill({ contents: data, filename: fullFilename });
});
fs$1.readFile.apply(this, readFileArgs);
}
}
else {
tryPathIndex(i + 1);
Expand Down Expand Up @@ -10564,7 +10562,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
* It's not clear what should / must be public and why.
*/
var initial = {
version: [3, 11, 0],
version: [3, 11, 1],
data: data,
tree: tree,
Environment: environment$1,
Expand Down
120 changes: 59 additions & 61 deletions dist/less.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,8 @@ var AbstractFileManager = /** @class */ (function () {
}
return filename.slice(0, j + 1);
};
AbstractFileManager.prototype.isPathWithExtension = function (path, ext) {
var extPos = path.lastIndexOf(ext);
return extPos !== -1 && extPos === path.length - ext.length;
};
AbstractFileManager.prototype.tryAppendExtension = function (path, ext) {
if (this.isPathWithExtension(path, ext)) {
return path;
}
return path + ext;
return /(\.[a-z]*$)|([\?;].*)$/.test(path) ? path : path + ext;
};
AbstractFileManager.prototype.tryAppendLessExtension = function (path) {
return this.tryAppendExtension(path, '.less');
Expand Down Expand Up @@ -156,26 +149,19 @@ var AbstractFileManager = /** @class */ (function () {
var FileManager = /** @class */ (function (_super) {
tslib.__extends(FileManager, _super);
function FileManager() {
var _this = _super.call(this) || this;
_this.contents = {};
return _this;
return _super !== null && _super.apply(this, arguments) || this;
}
FileManager.prototype.supports = function (filename, currentDirectory, options, environment) {
FileManager.prototype.supports = function () {
return true;
};
FileManager.prototype.supportsSync = function (filename, currentDirectory, options, environment) {
FileManager.prototype.supportsSync = function () {
return true;
};
FileManager.prototype.getPossibleFileExtensions = function (path, ext) {
if (this.isPathWithExtension(path, ext)) {
return [''];
}
return ['', ext];
};
FileManager.prototype.loadFile = function (filename, currentDirectory, options, environment, callback) {
var fullFilename;
var isAbsoluteFilename = this.isPathAbsolute(filename);
var filenamesTried = [];
var self = this;
var prefix = filename.slice(0, 1);
var explicit = prefix === '.' || prefix === '/';
var result = null;
Expand All @@ -190,7 +176,6 @@ var FileManager = /** @class */ (function (_super) {
paths.push('.');
}
var prefixes = options.prefixes || [''];
var extensions = this.getPossibleFileExtensions(filename, options.ext);
var fileParts = this.extractUrlParts(filename);
if (options.syncImport) {
getFileData(returnData, returnData);
Expand Down Expand Up @@ -220,51 +205,64 @@ var FileManager = /** @class */ (function (_super) {
if (i < paths.length) {
(function tryPrefix(j) {
if (j < prefixes.length) {
(function tryExtension(k) {
if (k < extensions.length) {
isNodeModule = false;
fullFilename = fileParts.rawPath + prefixes[j] + fileParts.filename + extensions[k];
if (paths[i]) {
fullFilename = path.join(paths[i], fullFilename);
}
if (!explicit && paths[i] === '.') {
try {
fullFilename = require.resolve(fullFilename);
isNodeModule = true;
}
catch (e) {
filenamesTried.push(npmPrefix + fullFilename);
}
}
var readFileArgs = [fullFilename];
if (!options.rawBuffer) {
readFileArgs.push('utf-8');
}
if (options.syncImport) {
try {
var data = fs$1.readFileSync.apply(this, readFileArgs);
fulfill({ contents: data, filename: fullFilename });
}
catch (e) {
filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
return tryExtension(k + 1);
}
isNodeModule = false;
fullFilename = fileParts.rawPath + prefixes[j] + fileParts.filename;
if (paths[i]) {
fullFilename = path.join(paths[i], fullFilename);
}
if (!explicit && paths[i] === '.') {
try {
fullFilename = require.resolve(fullFilename);
isNodeModule = true;
}
catch (e) {
filenamesTried.push(npmPrefix + fullFilename);
tryWithExtension();
}
}
else {
tryWithExtension();
}
function tryWithExtension() {
var extFilename = options.ext ? self.tryAppendExtension(fullFilename, options.ext) : fullFilename;
if (extFilename !== fullFilename && !explicit && paths[i] === '.') {
try {
fullFilename = require.resolve(extFilename);
isNodeModule = true;
}
else {
readFileArgs.push(function (e, data) {
if (e) {
filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
return tryExtension(k + 1);
}
fulfill({ contents: data, filename: fullFilename });
});
fs$1.readFile.apply(this, readFileArgs);
catch (e) {
filenamesTried.push(npmPrefix + extFilename);
fullFilename = extFilename;
}
}
else {
tryPrefix(j + 1);
fullFilename = extFilename;
}
})(0);
}
var readFileArgs = [fullFilename];
if (!options.rawBuffer) {
readFileArgs.push('utf-8');
}
if (options.syncImport) {
try {
var data = fs$1.readFileSync.apply(this, readFileArgs);
fulfill({ contents: data, filename: fullFilename });
}
catch (e) {
filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
return tryPrefix(j + 1);
}
}
else {
readFileArgs.push(function (e, data) {
if (e) {
filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
return tryPrefix(j + 1);
}
fulfill({ contents: data, filename: fullFilename });
});
fs$1.readFile.apply(this, readFileArgs);
}
}
else {
tryPathIndex(i + 1);
Expand Down Expand Up @@ -10560,7 +10558,7 @@ var createFromEnvironment = (function (environment, fileManagers) {
* It's not clear what should / must be public and why.
*/
var initial = {
version: [3, 11, 0],
version: [3, 11, 1],
data: data,
tree: tree,
Environment: environment$1,
Expand Down
Loading

0 comments on commit 842386b

Please sign in to comment.