diff --git a/gruntfile.js b/gruntfile.js index dc15eca93..df90d0675 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -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",