gulp-less-changed
Advanced tools
Comparing version 1.1.3 to 1.2.0
@@ -13,3 +13,3 @@ var gulp = require('gulp'); | ||
gulp.task('compile', function () { | ||
var tsResult = gulp.src(['src/**/*.ts', 'src/*.d.ts', 'typings/main.d.ts']) | ||
var tsResult = gulp.src(['src/**/*.ts', 'src/*.d.ts', 'typings/index.d.ts']) | ||
.pipe(plugins.sourcemaps.init()) | ||
@@ -16,0 +16,0 @@ .pipe(plugins.typescript(tsProject)); |
{ | ||
"name": "gulp-less-changed", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "Only pass .less files through the gulp stream if they or their dependencies have changed", | ||
"main": "release/main.js", | ||
"scripts": { | ||
"test": "gulp run-tests", | ||
"test": "node_modules/.bin/gulp run-tests", | ||
"send-coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
@@ -49,5 +49,7 @@ "semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
"dependencies": { | ||
"bluebird": "^3.3.4", | ||
"bluebird": "^3.4.0", | ||
"crypto": "0.0.3", | ||
"gulp-util": "^3.0.7", | ||
"less": "^2.6.0", | ||
"mkdirp": "^0.5.1", | ||
"object-assign": "^4.0.1", | ||
@@ -54,0 +56,0 @@ "stream-to-array": "^2.3.0", |
@@ -89,3 +89,3 @@ # `gulp-less-changed` | ||
As an optimisation, the import list for each file is kept in memory. If all of the imports for a particular file have the same timestamp, | ||
As an optimisation, the import list for each file is kept in memory and on disk. If all of the imports for a particular file have the same timestamp, | ||
the import list for that file is assumed to be the same. This helps to speed up incremental builds. | ||
@@ -92,0 +92,0 @@ |
@@ -9,3 +9,8 @@ 'use strict'; | ||
var Promise = require('bluebird'); | ||
var path = require('path'); | ||
var os = require('os'); | ||
var crypto = require('crypto'); | ||
var mkdirp = require('mkdirp'); | ||
var fsAsync = Promise.promisifyAll(fs); | ||
var mkdirpAsync = Promise.promisify(mkdirp); | ||
var listImports; | ||
@@ -20,9 +25,17 @@ (function (listImports) { | ||
}(Error)); | ||
var perBufferImportCache = {}; | ||
var ImportBuffer = (function () { | ||
function ImportBuffer(importLister) { | ||
this.importCache = {}; | ||
function ImportBuffer(importLister, bufferKey) { | ||
this.bufferKey = bufferKey; | ||
if (!importLister || !(importLister instanceof Function)) { | ||
throw new ExpectedError('Invalid importer.'); | ||
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] = {}; | ||
} | ||
} | ||
@@ -32,3 +45,3 @@ ImportBuffer.prototype.modifiedTimeIsTheSame = function (info) { | ||
.then(function (stat) { | ||
var same = stat.mtime.getTime() === info.stat.mtime.getTime(); | ||
var same = stat.mtime.getTime() === info.time; | ||
if (!same) { | ||
@@ -43,2 +56,36 @@ return Promise.reject(new ExpectedError('changed')); | ||
}; | ||
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) { | ||
var existingImports = this.importCache[filePath]; | ||
if (existingImports) { | ||
return Promise.resolve(existingImports); | ||
} | ||
var cacheFile = this.getCacheFile(filePath); | ||
return fsAsync.readFileAsync(cacheFile) | ||
.then(function (data) { | ||
return JSON.parse(data); | ||
}) | ||
.catch(Error, function (error) { | ||
if (error.code !== 'ENOENT') { | ||
console.error("Failed to load cached results from '" + cacheFile + "'. " + error); | ||
} | ||
return null; | ||
}); | ||
}; | ||
ImportBuffer.prototype.cacheResults = function (filePath, imports) { | ||
this.importCache[filePath] = imports; | ||
var cacheFile = this.getCacheFile(filePath); | ||
var outputPath = path.dirname(cacheFile); | ||
return mkdirpAsync(outputPath) | ||
.then(function () { return fsAsync.writeFileAsync(cacheFile, JSON.stringify(imports)); }) | ||
.catch(function (error) { | ||
console.error("Failed to cache results to '" + cacheFile + "'. " + error); | ||
return imports; | ||
}) | ||
.then(function () { return imports; }); | ||
}; | ||
ImportBuffer.prototype.listImports = function (file) { | ||
@@ -48,20 +95,3 @@ var _this = this; | ||
return _this.importLister(file) | ||
.then(function (files) { | ||
return Promise.map(files, function (file) { | ||
return fsAsync.statAsync(file) | ||
.catch(Error, function (error) { | ||
if (error.code === 'ENOENT') { | ||
console.error("Import '" + file + "' not found."); | ||
return Promise.resolve(null); | ||
} | ||
return Promise.reject(error); | ||
}) | ||
.then(function (stat) { return { path: file, stat: stat }; }); | ||
}); | ||
}) | ||
.then(function (results) { | ||
var successfulResults = results.filter(function (info) { return !!info.stat; }); | ||
_this.importCache[file.path] = successfulResults; | ||
return successfulResults; | ||
}) | ||
.then(function (results) { return _this.cacheResults(file.path, results); }) | ||
.catch(function (error) { | ||
@@ -72,13 +102,15 @@ console.error("An unknown error occurred: " + error); | ||
}; | ||
var existingImports = this.importCache[file.path]; | ||
if (existingImports) { | ||
return Promise.all(existingImports.map(this.modifiedTimeIsTheSame)) | ||
.then(function (results) { | ||
return Promise.resolve(_this.importCache[file.path]); | ||
}) | ||
.catch(ExpectedError, function () { | ||
return useImportLister(); | ||
}); | ||
} | ||
return useImportLister(); | ||
return this.loadPreviousResults(file.path) | ||
.then(function (existingImports) { | ||
if (existingImports) { | ||
return Promise.all(existingImports.map(_this.modifiedTimeIsTheSame)) | ||
.then(function (results) { | ||
return Promise.resolve(existingImports); | ||
}) | ||
.catch(ExpectedError, function () { | ||
return useImportLister(); | ||
}); | ||
} | ||
return useImportLister(); | ||
}); | ||
}; | ||
@@ -85,0 +117,0 @@ return ImportBuffer; |
'use strict'; | ||
var fs = require('fs'); | ||
var less = require('less'); | ||
var streamToArray = require('stream-to-array'); | ||
var Promise = require('bluebird'); | ||
var import_buffer_1 = require('./import-buffer'); | ||
var path_resolver_1 = require('./path-resolver'); | ||
var data_uri_visitor_plugin_1 = require('./data-uri-visitor-plugin'); | ||
var fsAsync = Promise.promisifyAll(fs); | ||
var assign = require('object-assign'); | ||
@@ -14,3 +15,2 @@ var importLister; | ||
this.lessOptions = lessOptions; | ||
this.importBuffer = new import_buffer_1.ImportBuffer(this.listImportsInternal.bind(this)); | ||
this.pathResolver = new path_resolver_1.PathResolver(); | ||
@@ -65,3 +65,21 @@ } | ||
} | ||
return this.importBuffer.listImports(file); | ||
return this.listImportsInternal(file) | ||
.then(function (files) { | ||
return Promise.map(files, function (file) { | ||
return fsAsync.statAsync(file) | ||
.catch(Error, function (error) { | ||
if (error.code === 'ENOENT') { | ||
console.error("Import '" + file + "' not found."); | ||
return Promise.resolve(null); | ||
} | ||
return Promise.reject(error); | ||
}) | ||
.then(function (stat) { return { path: file, stat: stat }; }); | ||
}); | ||
}) | ||
.then(function (results) { | ||
var successfulResults = results.filter(function (info) { return !!info.stat; }); | ||
successfulResults = successfulResults.map(function (i) { return { path: i.path, time: i.stat.mtime.getTime() }; }); | ||
return Promise.resolve(successfulResults); | ||
}); | ||
}; | ||
@@ -68,0 +86,0 @@ return ImportLister; |
@@ -7,2 +7,4 @@ 'use strict'; | ||
var import_lister_1 = require('./import-lister'); | ||
var import_buffer_1 = require('./import-buffer'); | ||
var crypto = require('crypto'); | ||
var fsAsync = Promise.promisifyAll(fs); | ||
@@ -12,7 +14,7 @@ var MODULE_NAME = 'gulp-less-changed'; | ||
(function (gulpLessChanged) { | ||
function checkImportsHaveChanged(file, mainFileDate, importLister) { | ||
function checkImportsHaveChanged(file, mainFileDate, importBuffer) { | ||
function importHasChanged(importFile) { | ||
return importFile.stat.mtime > mainFileDate; | ||
return importFile.time > mainFileDate.getTime(); | ||
} | ||
return importLister.listImports(file) | ||
return importBuffer.listImports(file) | ||
.then(function (imports) { | ||
@@ -22,11 +24,9 @@ return imports.some(importHasChanged); | ||
} | ||
var listerCache = {}; | ||
function run(options) { | ||
options = options || {}; | ||
var getOutputFileName = options.getOutputFileName || (function (input) { return gutil.replaceExtension(input, '.css'); }); | ||
var listerKey = JSON.stringify(options); | ||
var importLister = listerCache[listerKey]; | ||
if (!importLister) { | ||
importLister = listerCache[listerKey] = new import_lister_1.ImportLister(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); | ||
function transform(file, enc, callback) { | ||
@@ -56,3 +56,3 @@ var _this = this; | ||
} | ||
return checkImportsHaveChanged(file, intermediateResult.outputAge, importLister) | ||
return checkImportsHaveChanged(file, intermediateResult.outputAge, importBuffer) | ||
.catch(function (error) { | ||
@@ -59,0 +59,0 @@ console.error(error); |
{ | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"ambientDependencies": { | ||
"Q": "github:DefinitelyTyped/DefinitelyTyped/q/Q.d.ts#aae1368c8ee377f6e9c59c2d6faf1acb3ece7e05", | ||
"bluebird": "registry:dt/bluebird#2.0.0+20160319051630", | ||
"chalk": "github:DefinitelyTyped/DefinitelyTyped/chalk/chalk.d.ts#5d4a87811a8282f01bc1cdf2156020d78515fa2e", | ||
"gulp-util": "github:DefinitelyTyped/DefinitelyTyped/gulp-util/gulp-util.d.ts#5d4a87811a8282f01bc1cdf2156020d78515fa2e", | ||
"less": "registry:dt/less#0.0.0+20160317120654", | ||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#1c56e368e17bb28ca57577250624ca5bd561aa81", | ||
"object-assign": "registry:dt/object-assign#4.0.1+20160316155526", | ||
"through2": "github:DefinitelyTyped/DefinitelyTyped/through2/through2.d.ts#48f20e97bfaf70fc1a9537b38aed98e9749be0ae", | ||
"vinyl": "github:DefinitelyTyped/DefinitelyTyped/vinyl/vinyl.d.ts#70a1f40bc8ef810b4272d37553cf86c6785be7f8" | ||
} | ||
"globalDependencies": { | ||
"bluebird": "registry:dt/bluebird#2.0.0+20160319051630", | ||
"chalk": "registry:dt/chalk#0.4.0+20160317120654", | ||
"gulp-util": "registry:dt/gulp-util#0.0.0+20160316155526", | ||
"less": "registry:dt/less#0.0.0+20160317120654", | ||
"mkdirp": "registry:dt/mkdirp#0.3.0+20160317120654", | ||
"node": "registry:dt/node#6.0.0+20160514165920", | ||
"through2": "registry:dt/through2#2.0.0+20160317120654", | ||
"vinyl": "registry:dt/vinyl#1.1.0+20160316155526" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
108962
2773
0
9
4
+ Addedcrypto@0.0.3
+ Addedmkdirp@^0.5.1
+ Addedcrypto@0.0.3(transitive)
Updatedbluebird@^3.4.0