Check package.json files and fail if they start with a UTF-8 BOM

This commit is contained in:
Hristo Deshev
2015-12-01 15:16:21 +02:00
parent 61882e678f
commit 198ac10943

View File

@@ -564,6 +564,25 @@ module.exports = function(grunt) {
"copy:readyAppFiles",
"clean:readyAppFiles"
]);
grunt.registerTask("check-packagejson-boms", function() {
function hasBOM(filepath) {
var buf = grunt.file.read(filepath, { encoding: null });
return (buf[0] === 0xEF && buf[1] === 0xBB && buf[2] === 0xBF);
}
var packageDescriptors = grunt.file.expand({}, [
'**/package.json',
'!node_modules/**'
]);
var errors = packageDescriptors.map(function(packagePath) {
if (hasBOM(packagePath)) {
return "File " + packagePath + " contains a UTF-8 BOM.";
} else {
return null;
}
}).filter(function(errorMessage) { return !!errorMessage; });
if (errors.length > 0)
grunt.fail.fatal("\n" + errors.join("\n"));
});
grunt.registerTask("distribute-ts-apps-files", [
"copy:readyTsAppFiles"
]);
@@ -606,6 +625,7 @@ module.exports = function(grunt) {
grunt.registerTask("compile-modules", [
"clean:build",
"shell:getGitSHA",
"check-packagejson-boms",
"compile-ts",
"bom:allTargetFiles",
"collect-modules-raw-files",