mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Check package.json files and fail if they start with a UTF-8 BOM
This commit is contained in:
20
gruntfile.js
20
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",
|
||||
|
||||
Reference in New Issue
Block a user