Socket
Socket
Sign inDemoInstall

grunt-ts

Package Overview
Dependencies
Maintainers
3
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-ts - npm Package Compare versions

Comparing version 1.8.0 to 1.8.1

.tscache/fail/hashes/19e6f00b4b5ba8c8706e5323adcd1612

2

package.json

@@ -5,3 +5,3 @@ {

"description": "Compile and manage your TypeScript project",
"version": "1.8.0",
"version": "1.8.1",
"homepage": "https://github.com/grunt-ts/grunt-ts",

@@ -8,0 +8,0 @@ "repository": {

@@ -6,2 +6,3 @@ /// <reference path="../../defs/tsd.d.ts"/>

var path = require('path');
var crypto = require('crypto');
var grunt = require('grunt');

@@ -16,4 +17,9 @@

/////////////////////
var cacheDir = '.tscache';
//////////////////////////////
// File stamp based filtering
//////////////////////////////
function getStampPath(targetName) {
return path.join('.tscache', targetName, 'timestamp');
return path.join(cacheDir, targetName, 'timestamp');
}

@@ -44,8 +50,87 @@

function filterPathsByTime(paths, targetName) {
var time = getLastSuccessfullCompile(targetName);
return getFilesNewerThan(paths, time);
}
exports.filterPathsByTime = filterPathsByTime;
;
//////////////////////////////
// File hash based filtering
//////////////////////////////
/**
* Get path to cached file hash for a target.
* @return {string} Path to hash.
*/
function getHashPath(filePath, targetName) {
var hashedName = crypto.createHash('md5').update(filePath).digest('hex');
return path.join(cacheDir, targetName, 'hashes', hashedName);
}
;
/**
* Get an existing hash for a file (if it exists).
*/
function getExistingHash(filePath, targetName) {
var hashPath = getHashPath(filePath, targetName);
var exists = fs.existsSync(hashPath);
if (!exists) {
return null;
}
return fs.readFileSync(hashPath).toString();
}
;
/**
* Generate a hash (md5sum) of a file contents.
* @param {string} filePath Path to file.
*/
function generateFileHash(filePath) {
var md5sum = crypto.createHash('md5');
var data = fs.readFileSync(filePath);
md5sum.update(data);
return md5sum.digest('hex');
}
;
/**
* Filter files based on hashed contents.
* @param {Array.<string>} paths List of paths to files.
* @param {string} cacheDir Cache directory.
* @param {string} taskName Task name.
* @param {string} targetName Target name.
* @param {function(Error, Array.<string>)} callback Callback called with any
* error and a filtered list of files that only includes files with hashes
* that are different than the cached hashes for the same files.
*/
function filterPathsByHash(filePaths, targetName) {
var filtered = _.filter(filePaths, function (filePath) {
var previous = getExistingHash(filePath, targetName);
var current = generateFileHash(filePath);
return previous !== current;
});
return filtered;
}
;
function updateHashes(filePaths, targetName) {
_.forEach(filePaths, function (filePath) {
var hashPath = getHashPath(filePath, targetName);
var hash = generateFileHash(filePath);
grunt.file.write(hashPath, hash);
});
}
//////////////////////////////
// External functions
//////////////////////////////
/**
* Filter a list of files by target
*/
function getNewFilesForTarget(paths, targetName) {
var time = getLastSuccessfullCompile(targetName);
return getFilesNewerThan(paths, time);
var step1 = exports.filterPathsByTime(paths, targetName);
var step2 = filterPathsByHash(step1, targetName);
return step2;
}

@@ -58,6 +143,10 @@ exports.getNewFilesForTarget = getNewFilesForTarget;

*/
function compileSuccessfull(targetName) {
function compileSuccessfull(paths, targetName) {
// update timestamp
grunt.file.write(getStampPath(targetName), '');
// update filehash
updateHashes(paths, targetName);
}
exports.compileSuccessfull = compileSuccessfull;
//# sourceMappingURL=cacheUtils.js.map

@@ -8,2 +8,3 @@ /// <reference path="../../defs/tsd.d.ts"/>

import path = require('path');
import crypto = require('crypto');
var grunt: IGrunt = require('grunt');

@@ -19,5 +20,11 @@

var cacheDir = '.tscache';
//////////////////////////////
// File stamp based filtering
//////////////////////////////
function getStampPath(targetName: string): string {
return path.join('.tscache', targetName, 'timestamp');
return path.join(cacheDir, targetName, 'timestamp');
}

@@ -47,9 +54,85 @@

export function filterPathsByTime(paths: string[], targetName): string[] {
var time = getLastSuccessfullCompile(targetName);
return getFilesNewerThan(paths, time);
};
//////////////////////////////
// File hash based filtering
//////////////////////////////
/**
* Get path to cached file hash for a target.
* @return {string} Path to hash.
*/
function getHashPath(filePath, targetName) {
var hashedName = crypto.createHash('md5').update(filePath).digest('hex');
return path.join(cacheDir, targetName, 'hashes', hashedName);
};
/**
* Get an existing hash for a file (if it exists).
*/
function getExistingHash(filePath, targetName) {
var hashPath = getHashPath(filePath, targetName);
var exists = fs.existsSync(hashPath);
if (!exists) {
return null;
}
return fs.readFileSync(hashPath).toString();
};
/**
* Generate a hash (md5sum) of a file contents.
* @param {string} filePath Path to file.
*/
function generateFileHash(filePath: string) {
var md5sum = crypto.createHash('md5');
var data = fs.readFileSync(filePath);
md5sum.update(data);
return md5sum.digest('hex');
};
/**
* Filter files based on hashed contents.
* @param {Array.<string>} paths List of paths to files.
* @param {string} cacheDir Cache directory.
* @param {string} taskName Task name.
* @param {string} targetName Target name.
* @param {function(Error, Array.<string>)} callback Callback called with any
* error and a filtered list of files that only includes files with hashes
* that are different than the cached hashes for the same files.
*/
function filterPathsByHash(filePaths: string[], targetName) {
var filtered = _.filter(filePaths, (filePath) => {
var previous = getExistingHash(filePath, targetName);
var current = generateFileHash(filePath);
return previous !== current;
});
return filtered;
};
function updateHashes(filePaths: string[], targetName) {
_.forEach(filePaths, (filePath) => {
var hashPath = getHashPath(filePath, targetName);
var hash = generateFileHash(filePath);
grunt.file.write(hashPath, hash);
});
}
//////////////////////////////
// External functions
//////////////////////////////
/**
* Filter a list of files by target
*/
export function getNewFilesForTarget(paths: string[], targetName): string[] {
var step1 = filterPathsByTime(paths, targetName);
var step2 = filterPathsByHash(step1, targetName);
var time = getLastSuccessfullCompile(targetName);
return getFilesNewerThan(paths, time);
return step2;
};

@@ -60,4 +143,7 @@

*/
export function compileSuccessfull(targetName) {
export function compileSuccessfull(paths: string[], targetName) {
// update timestamp
grunt.file.write(getStampPath(targetName), '');
// update filehash
updateHashes(paths, targetName);
}

@@ -58,11 +58,21 @@ /// <reference path="../../defs/tsd.d.ts"/>

var newFiles;
if (task.fast) {
if (target.out) {
exports.grunt.log.write('Fast compile will not work when --out is specified. Ignoring fast compilation'.red);
newFiles = files;
} else {
var newFiles = getChangedFiles(files);
newFiles = getChangedFiles(files);
if (newFiles.length !== 0) {
files = newFiles;
} else {
exports.grunt.log.writeln('Compiling all files as no changed files were detected'.green);
exports.grunt.log.writeln('No file changes were detected. Skipping Compile'.green);
return new Promise(function (resolve) {
var ret = {
code: 0,
fileCount: 0,
output: 'No files compiled as no change detected'
};
resolve(ret);
});
}

@@ -151,3 +161,3 @@ }

if (task.fast) {
resetChangedFiles();
resetChangedFiles(newFiles);
}

@@ -184,6 +194,6 @@

function resetChangedFiles() {
function resetChangedFiles(files) {
var targetName = exports.grunt.task.current.target;
cache.compileSuccessfull(targetName);
cache.compileSuccessfull(files, targetName);
}
//# sourceMappingURL=compile.js.map

@@ -10,3 +10,2 @@ /// <reference path="../../defs/tsd.d.ts"/>

var Promise: typeof Promise = require('es6-promise').Promise;

@@ -67,11 +66,21 @@ export var grunt: IGrunt = require('grunt');

var newFiles: string[];
if (task.fast) {
if (target.out) {
grunt.log.write('Fast compile will not work when --out is specified. Ignoring fast compilation'.red);
newFiles = files;
}
else {
var newFiles = getChangedFiles(files);
newFiles = getChangedFiles(files);
if (newFiles.length !== 0) { files = newFiles; }
else {
grunt.log.writeln('Compiling all files as no changed files were detected'.green);
grunt.log.writeln('No file changes were detected. Skipping Compile'.green);
return new Promise((resolve) => {
var ret: ICompileResult = {
code: 0,
fileCount:0,
output: 'No files compiled as no change detected'
};
resolve(ret);
});
}

@@ -160,3 +169,3 @@ }

if (task.fast) {
resetChangedFiles();
resetChangedFiles(newFiles);
}

@@ -195,5 +204,5 @@

function resetChangedFiles() {
function resetChangedFiles(files) {
var targetName = grunt.task.current.target;
cache.compileSuccessfull(targetName);
cache.compileSuccessfull(files, targetName);
}
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