Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-less-changed

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-less-changed - npm Package Compare versions

Comparing version 1.3.4 to 1.4.0

.editorconfig

96

gulpfile.babel.js

@@ -1,29 +0,46 @@

import gulp from 'gulp';
import path from 'path';
import merge from 'merge2';
const plugins = require('gulp-load-plugins')();
import lazypipe from 'lazypipe';
import del from 'del';
import gulp from "gulp";
import path from "path";
import merge from "merge2";
const plugins = require("gulp-load-plugins")();
import lazypipe from "lazypipe";
import del from "del";
var tsProject = plugins.typescript.createProject('tsconfig.json', {
typescript: require('typescript')
var tsProject = plugins.typescript.createProject("tsconfig.json", {
typescript: require("typescript")
});
function istanbulTypeScriptIgnores() {
var ignoreReplacement = '/* istanbul ignore next */\n$1'
var ignoreReplacement = "/* istanbul ignore next */\n$1";
return lazypipe()
.pipe(plugins.replace, /(var __extends =)/, ignoreReplacement)
.pipe(plugins.replace, /(var __awaiter =)/, ignoreReplacement)
.pipe(plugins.replace, /(var __generator =)/, ignoreReplacement)
.pipe(plugins.replace, /(var _this = _super\.call)/, ignoreReplacement)();
.pipe(
plugins.replace,
/(var __extends =)/,
ignoreReplacement
)
.pipe(
plugins.replace,
/(var __awaiter =)/,
ignoreReplacement
)
.pipe(
plugins.replace,
/(var __generator =)/,
ignoreReplacement
)
.pipe(
plugins.replace,
/(var _this = _super\.call)/,
ignoreReplacement
)();
}
function clean() {
return del(['release', 'coverage', '.nyc_output']);
return del(["release", "coverage", ".nyc_output"]);
}
gulp.task('clean', clean);
gulp.task("clean", clean);
function compile() {
var tsResult = gulp.src(['src/**/*.ts', 'custom-typings/*.d.ts'])
var tsResult = gulp
.src(["src/**/*.ts", "custom-typings/*.d.ts"])
.pipe(plugins.sourcemaps.init())

@@ -33,20 +50,43 @@ .pipe(tsProject());

return merge([
tsResult.dts
.pipe(gulp.dest('release')),
tsResult.dts.pipe(gulp.dest("release")),
tsResult.js
.pipe(istanbulTypeScriptIgnores())
.pipe(plugins.sourcemaps.write('./', {
includeContent: false,
sourceRoot: function (file) {
return path.normalize(process.cwd() + '/src');
}
}))
.pipe(gulp.dest('release'))
.pipe(
plugins.sourcemaps.write("./", {
includeContent: false,
sourceRoot: function() {
return path.normalize(process.cwd() + "/src");
}
})
)
.pipe(gulp.dest("release"))
]);
}
gulp.task('compile', compile);
gulp.task("compile", compile);
const build = gulp.series('clean', 'compile');
function tslint() {
return gulp
.src("src/**/*.ts")
.pipe(plugins.tslint())
.pipe(plugins.tslint.report());
}
export default build;
gulp.task("tslint", tslint);
function eslint() {
return gulp
.src(["./gulpfile.babel.js", "test/**/*.js"])
.pipe(plugins.eslint())
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failAfterError());
}
gulp.task("eslint", eslint);
const build = gulp.series(
"clean",
gulp.parallel("compile", "tslint", "eslint")
);
export default build;
{
"name": "gulp-less-changed",
"version": "1.3.4",
"version": "1.4.0",
"description": "Only pass .less files through the gulp stream if they or their dependencies have changed",

@@ -8,3 +8,3 @@ "main": "release/main.js",

"build": "gulp",
"test": "niv less@2.7.2 && nyc mocha && node generate-coverage-reports",
"test": "niv less@2.7.2 && niv less@3.0.4 && nyc mocha && node generate-coverage-reports",
"clean": "gulp clean",

@@ -30,5 +30,6 @@ "semantic-release": "semantic-release"

"devDependencies": {
"@types/bluebird-global": "^3.5.4",
"@types/less": "^0.0.32",
"@types/bluebird-global": "^3.5.9",
"@types/less": "^0.0.34",
"@types/mkdirp": "^0.5.2",
"@types/object-assign": "^4.0.30",
"@types/plugin-error": "^0.1.0",

@@ -38,31 +39,35 @@ "@types/replace-ext": "0.0.27",

"@types/vinyl": "^2.0.2",
"babel-core": "^6.26.0",
"babel-core": "^6.26.3",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-env": "^1.7.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"del": "^3.0.0",
"eslint": "^5.5.0",
"fake-fs": "^0.5.0",
"gulp": "^4.0.0",
"gulp-cli": "^2.0.1",
"gulp-eslint": "^5.0.0",
"gulp-load-plugins": "^1.5.0",
"gulp-replace": "^0.6.1",
"gulp-replace": "^1.0.0",
"gulp-sourcemaps": "^2.6.4",
"gulp-typescript": "^4.0.1",
"gulp-tslint": "^8.1.3",
"gulp-typescript": "^5.0.0-alpha.3",
"istanbul": "^0.4.5",
"lazypipe": "^1.0.1",
"less": "^3.0.0",
"merge2": "^1.2.1",
"mocha": "^5.0.0",
"less": "^3.8.1",
"merge2": "^1.2.2",
"mocha": "^5.2.0",
"npm-install-version": "^6.0.2",
"nyc": "^11.4.1",
"nyc": "^13.0.1",
"pmock": "^0.2.3",
"proxyquire": "^1.8.0",
"remap-istanbul": "^0.10.1",
"semantic-release": "^12.4.1",
"sinon": "^4.2.2",
"sinon-chai": "^2.14.0",
"sinon-test": "^2.1.3",
"proxyquire": "^2.1.0",
"remap-istanbul": "^0.11.1",
"semantic-release": "^15.9.12",
"sinon": "^6.1.5",
"sinon-chai": "^3.2.0",
"sinon-test": "^2.2.1",
"stream-assert": "^2.0.3",
"typescript": "^2.7.1"
"tslint": "^5.11.0",
"typescript": "^3.0.3"
},

@@ -77,3 +82,3 @@ "dependencies": {

"through2": "^2.0.3",
"vinyl": "^2.1.0"
"vinyl": "^2.2.0"
},

@@ -80,0 +85,0 @@ "peerDependencies": {

@@ -13,2 +13,3 @@ # `gulp-less-changed`

[![devDependency Status](https://david-dm.org/bingnz/gulp-less-changed/dev-status.svg)](https://david-dm.org/bingnz/gulp-less-changed#info=devDependencies)
[![Greenkeeper badge](https://badges.greenkeeper.io/bingnz/gulp-less-changed.svg)](https://greenkeeper.io/)

@@ -15,0 +16,0 @@ ## Install

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var data_uri_visitor_1 = require("./data-uri-visitor");
var dataUriVisitorPlugin;
(function (dataUriVisitorPlugin) {
var DataUriVisitorPlugin = (function () {
function DataUriVisitorPlugin() {
}
DataUriVisitorPlugin.prototype.install = function (lessLocal, pluginManager) {
this._dataUriVisitor = new data_uri_visitor_1.DataUriVisitor(lessLocal);
pluginManager.addVisitor(this._dataUriVisitor);
};
Object.defineProperty(DataUriVisitorPlugin.prototype, "imports", {
get: function () {
return this._dataUriVisitor ? this._dataUriVisitor.imports : [];
},
enumerable: true,
configurable: true
});
return DataUriVisitorPlugin;
}());
dataUriVisitorPlugin.DataUriVisitorPlugin = DataUriVisitorPlugin;
})(dataUriVisitorPlugin || (dataUriVisitorPlugin = {}));
module.exports = dataUriVisitorPlugin;
var DataUriVisitorPlugin = (function () {
function DataUriVisitorPlugin(importFound) {
this.importFound = importFound;
}
DataUriVisitorPlugin.prototype.install = function (lessLocal, pluginManager) {
var visitor = new data_uri_visitor_1.DataUriVisitor(lessLocal, this.importFound);
pluginManager.addVisitor(visitor);
};
return DataUriVisitorPlugin;
}());
exports.DataUriVisitorPlugin = DataUriVisitorPlugin;
//# sourceMappingURL=data-uri-visitor-plugin.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");
var dataUriVisitor;
(function (dataUriVisitor) {
var DataUriVisitor = (function () {
function DataUriVisitor(less) {
this.isReplacing = false;
this.isPreEvalVisitor = true;
this._imports = [];
this._visitor = new less.visitors.Visitor(this);
var DataUriVisitor = (function () {
function DataUriVisitor(less, addImport) {
this.addImport = addImport;
this.isReplacing = false;
this.isPreEvalVisitor = true;
this.visitor = new less.visitors.Visitor(this);
}
DataUriVisitor.prototype.run = function (root) {
return this.visitor.visit(root);
};
DataUriVisitor.prototype.visitCall = function (callNode) {
var _a = this.getImportInfo(callNode), ruleNode = _a.ruleNode, importedFile = _a.importedFile, entryPath = _a.entryPath;
if (!importedFile) {
return ruleNode;
}
DataUriVisitor.prototype.run = function (root) {
return this._visitor.visit(root);
};
DataUriVisitor.prototype.tryGetImportedFileName = function (ruleNode) {
var fileName;
if (ruleNode.args.length === 2) {
fileName = ruleNode.args[1];
}
else {
fileName = ruleNode.args[0];
}
if (!fileName.value || /@/.test(fileName.value)) {
return null;
}
return fileName.value;
};
DataUriVisitor.prototype.getImportInfo = function (ruleNode) {
if (ruleNode.name !== 'data-uri' ||
ruleNode.args.length === 0) {
return { ruleNode: ruleNode };
}
var importedFile = this.tryGetImportedFileName(ruleNode);
if (!importedFile) {
return { ruleNode: ruleNode };
}
var fileInfo = typeof ruleNode.fileInfo === 'function' ? ruleNode.fileInfo() : ruleNode.currentFileInfo;
var entryPath = fileInfo.entryPath;
return { ruleNode: ruleNode, importedFile: importedFile, entryPath: entryPath };
};
DataUriVisitor.prototype.visitCall = function (callNode, visitArgs) {
var _a = this.getImportInfo(callNode), ruleNode = _a.ruleNode, importedFile = _a.importedFile, entryPath = _a.entryPath;
if (!importedFile) {
return ruleNode;
}
this._imports.push({ directory: entryPath ? path.normalize(entryPath) : '', relativePath: importedFile });
return ruleNode;
};
Object.defineProperty(DataUriVisitor.prototype, "imports", {
get: function () {
return this._imports;
},
enumerable: true,
configurable: true
this.addImport({
directory: entryPath ? path.normalize(entryPath) : "",
relativePath: importedFile
});
return DataUriVisitor;
}());
dataUriVisitor.DataUriVisitor = DataUriVisitor;
})(dataUriVisitor || (dataUriVisitor = {}));
module.exports = dataUriVisitor;
return ruleNode;
};
DataUriVisitor.prototype.tryGetImportedFileName = function (ruleNode) {
var fileName = ruleNode.args.length === 2 ? ruleNode.args[1] : ruleNode.args[0];
if (!fileName.value || /@/.test(fileName.value)) {
return null;
}
return fileName.value;
};
DataUriVisitor.prototype.getImportInfo = function (ruleNode) {
if (ruleNode.name !== "data-uri" || ruleNode.args.length === 0) {
return { ruleNode: ruleNode };
}
var importedFile = this.tryGetImportedFileName(ruleNode);
if (!importedFile) {
return { ruleNode: ruleNode };
}
var fileInfo = typeof ruleNode.fileInfo === "function"
? ruleNode.fileInfo()
: ruleNode.currentFileInfo;
var entryPath = fileInfo.entryPath;
return { ruleNode: ruleNode, importedFile: importedFile, entryPath: entryPath };
};
return DataUriVisitor;
}());
exports.DataUriVisitor = DataUriVisitor;
//# sourceMappingURL=data-uri-visitor.js.map

@@ -19,4 +19,4 @@ "use strict";

while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {

@@ -40,159 +40,158 @@ case 0: case 1: t = op; break;

};
var fs = require("fs");
Object.defineProperty(exports, "__esModule", { value: true });
var bluebird = require("bluebird");
var path = require("path");
var os = require("os");
var crypto = require("crypto");
var fs = require("fs");
var mkdirp = require("mkdirp");
var os = require("os");
var path = require("path");
var fsAsync = bluebird.promisifyAll(fs);
var mkdirpAsync = bluebird.promisify(mkdirp);
var listImports;
(function (listImports) {
var perBufferImportCache = {};
var ImportBuffer = (function () {
function ImportBuffer(importLister, bufferKey) {
this.bufferKey = bufferKey;
if (!importLister || !(importLister instanceof Function)) {
throw new Error('Invalid importer.');
}
if (!bufferKey) {
throw new Error('A buffer key is required.');
}
this.importLister = importLister;
this.importCache = perBufferImportCache[bufferKey];
if (!this.importCache) {
this.importCache = perBufferImportCache[bufferKey] = {};
}
var perBufferImportCache = {};
var ImportBuffer = (function () {
function ImportBuffer(importLister, bufferKey) {
this.bufferKey = bufferKey;
if (!importLister || !(importLister instanceof Function)) {
throw new Error("Invalid importer.");
}
ImportBuffer.prototype.modifiedTimeIsTheSame = function (info) {
return __awaiter(this, void 0, void 0, function () {
var stat, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, fsAsync.statAsync(info.path)];
case 1:
stat = _a.sent();
return [2, (stat.mtime.getTime() === info.time)];
case 2:
error_1 = _a.sent();
return [2, false];
case 3: return [2];
}
});
if (!bufferKey) {
throw new Error("A buffer key is required.");
}
this.importLister = importLister;
this.importCache = perBufferImportCache[bufferKey];
if (!this.importCache) {
this.importCache = perBufferImportCache[bufferKey] = {};
}
}
ImportBuffer.prototype.listImports = function (file) {
return __awaiter(this, void 0, void 0, function () {
var useImportLister, existingImports, results;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
useImportLister = function () { return __awaiter(_this, void 0, void 0, function () {
var importListerResults, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
return [4, this.importLister(file)];
case 1:
importListerResults = _a.sent();
return [4, this.cacheResults(file.path, importListerResults)];
case 2: return [2, _a.sent()];
case 3:
error_1 = _a.sent();
console.error("An unknown error occurred: " + error_1);
return [2, []];
case 4: return [2];
}
});
}); };
return [4, this.loadPreviousResults(file.path)];
case 1:
existingImports = _a.sent();
if (!existingImports) {
return [2, useImportLister()];
}
return [4, Promise.all(existingImports.map(this.modifiedTimeIsTheSame))];
case 2:
results = _a.sent();
if (results.every(function (r) { return r; })) {
return [2, existingImports];
}
return [2, useImportLister()];
}
});
};
ImportBuffer.prototype.getCacheFile = function (filePath) {
var filePathKey = crypto.createHash('md5').update(filePath).digest('hex') + "_" + path.basename(filePath);
var outputPath = path.join(os.tmpdir(), this.bufferKey);
return path.join(outputPath, filePathKey);
};
ImportBuffer.prototype.loadPreviousResults = function (filePath) {
return __awaiter(this, void 0, void 0, function () {
var existingImports, cacheFile, data, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
existingImports = this.importCache[filePath];
if (existingImports) {
return [2, existingImports];
}
cacheFile = this.getCacheFile(filePath);
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4, fsAsync.readFileAsync(cacheFile)];
case 2:
data = _a.sent();
return [2, JSON.parse(data)];
case 3:
error_2 = _a.sent();
if (error_2.code !== 'ENOENT') {
console.error("Failed to load cached results from '" + cacheFile + "'. " + error_2);
}
return [2, null];
case 4: return [2];
}
});
});
};
ImportBuffer.prototype.modifiedTimeIsTheSame = function (info) {
return __awaiter(this, void 0, void 0, function () {
var stat, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, fsAsync.statAsync(info.path)];
case 1:
stat = _a.sent();
return [2, stat.mtime.getTime() === info.time];
case 2:
error_2 = _a.sent();
return [2, false];
case 3: return [2];
}
});
};
ImportBuffer.prototype.cacheResults = function (filePath, imports) {
return __awaiter(this, void 0, void 0, function () {
var cacheFile, outputPath, error_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.importCache[filePath] = imports;
cacheFile = this.getCacheFile(filePath);
outputPath = path.dirname(cacheFile);
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
return [4, mkdirpAsync(outputPath)];
case 2:
_a.sent();
return [4, fsAsync.writeFileAsync(cacheFile, JSON.stringify(imports))];
case 3:
_a.sent();
return [3, 5];
case 4:
error_3 = _a.sent();
console.error("Failed to cache results to '" + cacheFile + "'. " + error_3);
return [3, 5];
case 5: return [2, imports];
}
});
});
};
ImportBuffer.prototype.getCacheFile = function (filePath) {
var filePathKey = crypto
.createHash("md5")
.update(filePath)
.digest("hex") + "_" + path.basename(filePath);
var outputPath = path.join(os.tmpdir(), this.bufferKey);
return path.join(outputPath, filePathKey);
};
ImportBuffer.prototype.loadPreviousResults = function (filePath) {
return __awaiter(this, void 0, void 0, function () {
var existingImports, cacheFile, data, error_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
existingImports = this.importCache[filePath];
if (existingImports) {
return [2, existingImports];
}
cacheFile = this.getCacheFile(filePath);
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4, fsAsync.readFileAsync(cacheFile)];
case 2:
data = _a.sent();
return [2, JSON.parse(data)];
case 3:
error_3 = _a.sent();
if (error_3.code !== "ENOENT") {
console.error("Failed to load cached results from '" + cacheFile + "'. " + error_3);
}
return [2, null];
case 4: return [2];
}
});
};
ImportBuffer.prototype.listImports = function (file) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var useImportLister, existingImports, results;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
useImportLister = function () { return __awaiter(_this, void 0, void 0, function () {
var results_1, error_4;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
return [4, this.importLister(file)];
case 1:
results_1 = _a.sent();
return [4, this.cacheResults(file.path, results_1)];
case 2: return [2, _a.sent()];
case 3:
error_4 = _a.sent();
console.error("An unknown error occurred: " + error_4);
return [2, []];
case 4: return [2];
}
});
}); };
return [4, this.loadPreviousResults(file.path)];
case 1:
existingImports = _a.sent();
if (!!existingImports) return [3, 3];
return [4, useImportLister()];
case 2: return [2, _a.sent()];
case 3: return [4, Promise.all(existingImports.map(this.modifiedTimeIsTheSame))];
case 4:
results = _a.sent();
if (results.every(function (r) { return r; })) {
return [2, existingImports];
}
return [4, useImportLister()];
case 5: return [2, _a.sent()];
}
});
});
};
ImportBuffer.prototype.cacheResults = function (filePath, imports) {
return __awaiter(this, void 0, void 0, function () {
var cacheFile, outputPath, error_4;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.importCache[filePath] = imports;
cacheFile = this.getCacheFile(filePath);
outputPath = path.dirname(cacheFile);
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
return [4, mkdirpAsync(outputPath)];
case 2:
_a.sent();
return [4, fsAsync.writeFileAsync(cacheFile, JSON.stringify(imports))];
case 3:
_a.sent();
return [3, 5];
case 4:
error_4 = _a.sent();
console.error("Failed to cache results to '" + cacheFile + "'. " + error_4);
return [3, 5];
case 5: return [2, imports];
}
});
};
return ImportBuffer;
}());
listImports.ImportBuffer = ImportBuffer;
})(listImports || (listImports = {}));
module.exports = listImports;
});
};
return ImportBuffer;
}());
exports.ImportBuffer = ImportBuffer;
//# sourceMappingURL=import-buffer.js.map

@@ -19,4 +19,4 @@ "use strict";

while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {

@@ -40,140 +40,149 @@ case 0: case 1: t = op; break;

};
Object.defineProperty(exports, "__esModule", { value: true });
var bluebird = require("bluebird");
var fs = require("fs");
var less = require("less");
var assign = require("object-assign");
var streamToArray = require("stream-to-array");
var bluebird = require("bluebird");
var data_uri_visitor_plugin_1 = require("./data-uri-visitor-plugin");
var path_resolver_1 = require("./path-resolver");
var data_uri_visitor_plugin_1 = require("./data-uri-visitor-plugin");
var fsAsync = bluebird.promisifyAll(fs);
var assign = require('object-assign');
var importLister;
(function (importLister) {
var ImportLister = (function () {
function ImportLister(lessOptions) {
this.lessOptions = lessOptions;
this.pathResolver = new path_resolver_1.PathResolver();
}
ImportLister.prototype.getLessData = function (file) {
return __awaiter(this, void 0, void 0, function () {
var parts, buffers, i, part;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (file.isBuffer()) {
return [2, new Promise(function (resolve, reject) {
process.nextTick(function () { return resolve(file.contents.toString()); });
})];
}
return [4, streamToArray(file.contents)];
case 1:
parts = _a.sent();
buffers = [];
for (i = 0; i < parts.length; ++i) {
part = parts[i];
buffers.push(Buffer.from(part));
}
return [2, Buffer.concat(buffers).toString()];
}
});
var ImportLister = (function () {
function ImportLister(lessOptions) {
this.lessOptions = lessOptions;
this.pathResolver = new path_resolver_1.PathResolver();
}
ImportLister.prototype.listImports = function (file) {
return __awaiter(this, void 0, void 0, function () {
var files, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!file) {
return [2, []];
}
_a = this.getExistingFiles;
return [4, this.listImportsInternal(file)];
case 1: return [4, _a.apply(this, [_b.sent()])];
case 2:
files = _b.sent();
return [2, files.map(function (i) { return ({ path: i.path, time: i.stat.mtime.getTime() }); })];
}
});
};
ImportLister.prototype.listImportsInternal = function (file) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var dataUriVisitorPlugin, options, lessData, renderResult, dataUriImports, reason_1, error;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (file == null || file.isNull()) {
console.error('Trying to process imports for null file.');
return [2, []];
}
dataUriVisitorPlugin = new data_uri_visitor_plugin_1.DataUriVisitorPlugin();
options = assign({ filename: file.path }, this.lessOptions);
options.plugins = options.plugins ? [dataUriVisitorPlugin].concat(options.plugins) : [dataUriVisitorPlugin];
_a.label = 1;
case 1:
_a.trys.push([1, 5, , 6]);
return [4, this.getLessData(file)];
case 2:
lessData = _a.sent();
return [4, less.render(lessData, options)];
case 3:
renderResult = _a.sent();
return [4, Promise.all(dataUriVisitorPlugin.imports
.map(function (i) { return _this.pathResolver.resolve(i.directory, i.relativePath, options.paths); }))];
case 4:
dataUriImports = _a.sent();
return [2, renderResult.imports.concat(dataUriImports)];
case 5:
reason_1 = _a.sent();
error = "Failed to process imports for '" + file.path + "': " + reason_1;
console.error(error);
throw new Error(error);
case 6: return [2];
}
});
});
};
ImportLister.prototype.getLessData = function (file) {
return __awaiter(this, void 0, void 0, function () {
var parts, buffers, _i, parts_1, part;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (file.isBuffer()) {
return [2, file.contents.toString()];
}
return [4, streamToArray(file.contents)];
case 1:
parts = _a.sent();
buffers = [];
for (_i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
part = parts_1[_i];
buffers.push(Buffer.from(part));
}
return [2, Buffer.concat(buffers).toString()];
}
});
};
ImportLister.prototype.getFileStatsIfExists = function (file) {
return __awaiter(this, void 0, void 0, function () {
var stat, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, fsAsync.statAsync(file)];
case 1:
stat = _a.sent();
return [2, { path: file, stat: stat }];
case 2:
error_1 = _a.sent();
if (error_1.code === 'ENOENT') {
console.error("Import '" + file + "' not found.");
return [2, null];
}
throw error_1;
case 3: return [2];
}
});
});
};
ImportLister.prototype.resolveImportPaths = function (additionalPaths, imports) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return [2, Promise.all(imports.map(function (i) {
return _this.pathResolver.resolve(i.directory, i.relativePath, additionalPaths);
}))];
});
};
ImportLister.prototype.getExistingFiles = function (files) {
return __awaiter(this, void 0, void 0, function () {
var results;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, Promise.all(files.map(this.getFileStatsIfExists))];
case 1:
results = _a.sent();
return [2, results.filter(function (info) { return !!info && !!info.stat; })];
}
});
});
};
ImportLister.prototype.getLessOptionsForImportListing = function (file, plugin) {
var options = assign({ filename: file.path }, this.lessOptions);
options.plugins = options.plugins
? [plugin].concat(options.plugins) : [plugin];
return options;
};
ImportLister.prototype.listImportsInternal = function (file) {
return __awaiter(this, void 0, void 0, function () {
var pluginImports, dataUriVisitorPlugin, options, lessData, renderResult, dataUriImports, reason_1, error;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (file == null || file.isNull()) {
console.error("Trying to process imports for null file.");
return [2, []];
}
pluginImports = [];
dataUriVisitorPlugin = new data_uri_visitor_plugin_1.DataUriVisitorPlugin(function (i) { return pluginImports.push(i); });
options = this.getLessOptionsForImportListing(file, dataUriVisitorPlugin);
_a.label = 1;
case 1:
_a.trys.push([1, 5, , 6]);
return [4, this.getLessData(file)];
case 2:
lessData = _a.sent();
return [4, less.render(lessData, options)];
case 3:
renderResult = _a.sent();
return [4, this.resolveImportPaths(options.paths, pluginImports)];
case 4:
dataUriImports = _a.sent();
return [2, renderResult.imports.concat(dataUriImports)];
case 5:
reason_1 = _a.sent();
error = "Failed to process imports for '" + file.path + "': " + reason_1;
console.error(error);
throw new Error(error);
case 6: return [2];
}
});
};
ImportLister.prototype.listImports = function (file) {
return __awaiter(this, void 0, void 0, function () {
var files, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!file) {
return [2, []];
}
_a = this.getExistingFiles;
return [4, this.listImportsInternal(file)];
case 1: return [4, _a.apply(this, [_b.sent()])];
case 2:
files = _b.sent();
return [2, files.map(function (i) { return { path: i.path, time: i.stat.mtime.getTime() }; })];
}
});
});
};
ImportLister.prototype.getFileStatsIfExists = function (file) {
return __awaiter(this, void 0, void 0, function () {
var stat, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, fsAsync.statAsync(file)];
case 1:
stat = _a.sent();
return [2, { path: file, stat: stat }];
case 2:
error_1 = _a.sent();
if (error_1.code === "ENOENT") {
console.error("Import '" + file + "' not found.");
return [2, null];
}
throw error_1;
case 3: return [2];
}
});
};
return ImportLister;
}());
importLister.ImportLister = ImportLister;
})(importLister || (importLister = {}));
module.exports = importLister;
});
};
ImportLister.prototype.getExistingFiles = function (files) {
return __awaiter(this, void 0, void 0, function () {
var results;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, Promise.all(files.map(this.getFileStatsIfExists))];
case 1:
results = _a.sent();
return [2, results.filter(function (info) { return !!info && !!info.stat; })];
}
});
});
};
return ImportLister;
}());
exports.ImportLister = ImportLister;
//# sourceMappingURL=import-lister.js.map

@@ -19,4 +19,4 @@ "use strict";

while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {

@@ -40,135 +40,135 @@ case 0: case 1: t = op; break;

};
Object.defineProperty(exports, "__esModule", { value: true });
var bluebird = require("bluebird");
var through = require("through2");
var crypto = require("crypto");
var fs = require("fs");
var PluginError = require("plugin-error");
var replaceExtension = require("replace-ext");
var PluginError = require("plugin-error");
var through = require("through2");
var import_buffer_1 = require("./import-buffer");
var import_lister_1 = require("./import-lister");
var import_buffer_1 = require("./import-buffer");
var crypto = require("crypto");
var fsAsync = bluebird.promisifyAll(fs);
var MODULE_NAME = 'gulp-less-changed';
var gulpLessChanged;
(function (gulpLessChanged) {
var ImportChecker = (function () {
function ImportChecker(options, importBuffer) {
this.options = options;
this.importBuffer = importBuffer;
this.getOutputFileName = options.getOutputFileName || (function (input) { return replaceExtension(input, '.css'); });
}
ImportChecker.prototype.checkImportsHaveChanged = function (file, mainFileDate) {
return __awaiter(this, void 0, void 0, function () {
function importHasChanged(importFile) {
return importFile.time > mainFileDate.getTime();
var MODULE_NAME = "gulp-less-changed";
var ImportChecker = (function () {
function ImportChecker(options, importBuffer) {
this.importBuffer = importBuffer;
this.getOutputFileName =
options.getOutputFileName || (function (input) { return replaceExtension(input, ".css"); });
}
ImportChecker.prototype.checkFileForChanges = function (transform, file, enc, callback) {
return __awaiter(this, void 0, void 0, function () {
var changed, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (file.isNull()) {
callback(null, null);
return [2];
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, 4, 5]);
return [4, this.hasFileOrDependenciesChanged(file, this.getOutputFileName(file.path))];
case 2:
changed = _a.sent();
if (changed) {
transform.push(file);
}
return [3, 5];
case 3:
error_1 = _a.sent();
transform.emit("error", new PluginError(MODULE_NAME, "Error processing '" + file.path + "': " + error_1));
return [3, 5];
case 4:
callback(null, null);
return [7];
case 5: return [2];
}
var imports, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, this.importBuffer.listImports(file)];
case 1:
imports = _a.sent();
return [2, imports.some(importHasChanged)];
case 2:
error_1 = _a.sent();
console.error(error_1);
return [2, true];
case 3: return [2];
}
});
});
};
ImportChecker.prototype.hasFileChanged = function (inputFile, outputFilePath) {
return __awaiter(this, void 0, void 0, function () {
var stats, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, fsAsync.statAsync(outputFilePath)];
case 1:
stats = _a.sent();
return [2, { modifiedTime: stats.mtime, hasFileChanged: stats.mtime < inputFile.stat.mtime }];
case 2:
error_2 = _a.sent();
if (error_2.code === 'ENOENT') {
return [2, { modifiedTime: undefined, hasFileChanged: true }];
}
else {
throw error_2;
}
return [3, 3];
case 3: return [2];
}
});
});
};
ImportChecker.prototype.checkImportsHaveChanged = function (file, mainFileDate) {
return __awaiter(this, void 0, void 0, function () {
function importHasChanged(importFile) {
return importFile.time > mainFileDate.getTime();
}
var imports, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, this.importBuffer.listImports(file)];
case 1:
imports = _a.sent();
return [2, imports.some(importHasChanged)];
case 2:
error_2 = _a.sent();
console.error(error_2);
return [2, true];
case 3: return [2];
}
});
};
ImportChecker.prototype.hasFileOrDependenciesChanged = function (inputFile, outputFilePath) {
return __awaiter(this, void 0, void 0, function () {
var _a, modifiedTime, hasFileChanged;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4, this.hasFileChanged(inputFile, outputFilePath)];
case 1:
_a = _b.sent(), modifiedTime = _a.modifiedTime, hasFileChanged = _a.hasFileChanged;
if (hasFileChanged) {
return [2, true];
}
return [4, this.checkImportsHaveChanged(inputFile, modifiedTime)];
case 2: return [2, _b.sent()];
}
});
});
};
ImportChecker.prototype.hasFileChanged = function (inputFile, outputFilePath) {
return __awaiter(this, void 0, void 0, function () {
var stats, error_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, fsAsync.statAsync(outputFilePath)];
case 1:
stats = _a.sent();
return [2, {
hasFileChanged: stats.mtime < inputFile.stat.mtime,
modifiedTime: stats.mtime,
}];
case 2:
error_3 = _a.sent();
if (error_3.code === "ENOENT") {
return [2, { modifiedTime: undefined, hasFileChanged: true }];
}
else {
throw error_3;
}
return [3, 3];
case 3: return [2];
}
});
};
ImportChecker.prototype.checkFileForChanges = function (transform, file, enc, callback) {
return __awaiter(this, void 0, void 0, function () {
var changed, error_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (file.isNull()) {
callback(null, null);
return [2];
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, 4, 5]);
return [4, this.hasFileOrDependenciesChanged(file, this.getOutputFileName(file.path))];
case 2:
changed = _a.sent();
if (changed) {
transform.push(file);
}
return [3, 5];
case 3:
error_3 = _a.sent();
transform.emit('error', new PluginError(MODULE_NAME, "Error processing '" + file.path + "': " + error_3));
return [3, 5];
case 4:
callback(null, null);
return [7];
case 5: return [2];
}
});
});
};
ImportChecker.prototype.hasFileOrDependenciesChanged = function (inputFile, outputFilePath) {
return __awaiter(this, void 0, void 0, function () {
var _a, modifiedTime, hasFileChanged;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4, this.hasFileChanged(inputFile, outputFilePath)];
case 1:
_a = _b.sent(), modifiedTime = _a.modifiedTime, hasFileChanged = _a.hasFileChanged;
if (hasFileChanged) {
return [2, true];
}
return [2, this.checkImportsHaveChanged(inputFile, modifiedTime)];
}
});
};
return ImportChecker;
}());
function run(options) {
options = options || {};
var importLister = new import_lister_1.ImportLister(options);
var instanceKey = crypto.createHash('md5').update(__dirname + JSON.stringify(options)).digest('hex');
var bufferKey = MODULE_NAME + "-" + instanceKey;
var importBuffer = new import_buffer_1.ImportBuffer(importLister.listImports.bind(importLister), bufferKey);
var importChecker = new ImportChecker(options, importBuffer);
return through.obj(function (file, enc, callback) {
importChecker.checkFileForChanges(this, file, enc, callback);
});
}
gulpLessChanged.run = run;
})(gulpLessChanged || (gulpLessChanged = {}));
module.exports = gulpLessChanged.run;
};
return ImportChecker;
}());
function run(options) {
options = options || {};
var importLister = new import_lister_1.ImportLister(options);
var instanceKey = crypto
.createHash("md5")
.update(__dirname + JSON.stringify(options))
.digest("hex");
var bufferKey = MODULE_NAME + "-" + instanceKey;
var importBuffer = new import_buffer_1.ImportBuffer(importLister.listImports.bind(importLister), bufferKey);
var importChecker = new ImportChecker(options, importBuffer);
return through.obj(function (file, enc, callback) {
importChecker.checkFileForChanges(this, file, enc, callback);
});
}
module.exports = run;
//# sourceMappingURL=main.js.map
"use strict";
/* istanbul ignore next */
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/* istanbul ignore next */
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -30,4 +19,4 @@ return new (P || (P = Promise))(function (resolve, reject) {

while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {

@@ -51,85 +40,69 @@ case 0: case 1: t = op; break;

};
Object.defineProperty(exports, "__esModule", { value: true });
var path_resolver_error_1 = require("./path-resolver-error");
var bluebird = require("bluebird");
var fs = require("fs");
var path = require("path");
var bluebird = require("bluebird");
var fsAsync = bluebird.promisifyAll(fs);
var pathResolver;
(function (pathResolver) {
var PathResolverError = (function (_super) {
__extends(PathResolverError, _super);
function PathResolverError(message) {
/* istanbul ignore next */
var _this = _super.call(this, message) || this;
_this.message = message;
_this.name = _this.constructor.name;
Object.setPrototypeOf(_this, PathResolverError.prototype);
Error.captureStackTrace(_this, _this.name);
return _this;
}
return PathResolverError;
}(Error));
pathResolver.PathResolverError = PathResolverError;
var PathResolver = (function () {
function PathResolver() {
}
PathResolver.prototype.filterExistingPaths = function (pathsToTry) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var checkedPaths;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, Promise.all(pathsToTry.map(function (path) { return __awaiter(_this, void 0, void 0, function () {
var error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, fsAsync.statAsync(path)];
case 1:
_a.sent();
return [2, path];
case 2:
error_1 = _a.sent();
return [2, null];
case 3: return [2];
}
});
}); }))];
case 1:
checkedPaths = _a.sent();
return [2, checkedPaths.filter(function (path) { return !!path; })];
}
});
var PathResolver = (function () {
function PathResolver() {
}
PathResolver.prototype.resolve = function (currentDirectory, inputPath, searchPaths) {
return __awaiter(this, void 0, void 0, function () {
var pathsToTry, resolvedPaths, validPath, triedPathsDisplay;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
pathsToTry = [path.join(currentDirectory, inputPath)];
if (searchPaths) {
pathsToTry.push.apply(pathsToTry, searchPaths.map(function (p) { return path.join(p, inputPath); }));
}
pathsToTry.push(path.join(process.cwd(), inputPath));
return [4, this.filterExistingPaths(pathsToTry)];
case 1:
resolvedPaths = _a.sent();
validPath = resolvedPaths[0];
if (!validPath) {
triedPathsDisplay = pathsToTry.map(function (p) { return "'" + p + "'"; }).join(", ");
throw new path_resolver_error_1.PathResolverError("Import file '" + inputPath + "' wasn't found. Tried: " + triedPathsDisplay + ".");
}
return [2, validPath];
}
});
};
PathResolver.prototype.resolve = function (currentDirectory, inputPath, searchPaths) {
return __awaiter(this, void 0, void 0, function () {
var pathsToTry, resolvedPaths, validPath, triedPathsDisplay;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
pathsToTry = [path.join(currentDirectory, inputPath)];
if (searchPaths) {
pathsToTry.push.apply(pathsToTry, searchPaths.map(function (p) { return path.join(p, inputPath); }));
}
pathsToTry.push(path.join(process.cwd(), inputPath));
return [4, this.filterExistingPaths(pathsToTry)];
case 1:
resolvedPaths = _a.sent();
validPath = resolvedPaths[0];
if (!validPath) {
triedPathsDisplay = pathsToTry.map(function (p) { return "'" + p + "'"; }).join(', ');
throw new PathResolverError("Import file '" + inputPath + "' wasn't found. Tried: " + triedPathsDisplay + ".");
}
return [2, validPath];
}
});
});
};
PathResolver.prototype.filterExistingPaths = function (pathsToTry) {
return __awaiter(this, void 0, void 0, function () {
var checkedPaths;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, Promise.all(pathsToTry.map(function (p) { return __awaiter(_this, void 0, void 0, function () {
var error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4, fsAsync.statAsync(p)];
case 1:
_a.sent();
return [2, p];
case 2:
error_1 = _a.sent();
return [2, null];
case 3: return [2];
}
});
}); }))];
case 1:
checkedPaths = _a.sent();
return [2, checkedPaths.filter(function (p) { return !!p; })];
}
});
};
return PathResolver;
}());
pathResolver.PathResolver = PathResolver;
})(pathResolver || (pathResolver = {}));
module.exports = pathResolver;
});
};
return PathResolver;
}());
exports.PathResolver = PathResolver;
//# sourceMappingURL=path-resolver.js.map

@@ -8,3 +8,4 @@ {

"lib": [
"es2015"
"es2015",
"dom"
],

@@ -19,2 +20,2 @@ "typeRoots": [

}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc