@@ -439,24 +439,37 @@ module.exports = function(grunt) {
439439 "copy:childPackageFiles"
440440 ] ) ;
441441
442- grunt . registerTask ( "check-packagejson-boms" , function ( ) {
443- function hasBOM ( filepath ) {
444- var buf = grunt . file . read ( filepath , { encoding : null } ) ;
445- return ( buf [ 0 ] === 0xEF && buf [ 1 ] === 0xBB && buf [ 2 ] === 0xBF ) ;
446- }
442+ function validatePackageJsons ( fileValidator , errorFormatter ) {
447443 var packageDescriptors = grunt . file . expand ( { } , [
448- '**/package.json' ,
449- '!node_modules/**'
444+ 'tns-core-modules/**/package.json'
450445 ] ) ;
451446 var errors = packageDescriptors . map ( function ( packagePath ) {
452- if ( hasBOM ( packagePath ) ) {
453- return "File " + packagePath + " contains a UTF-8 BOM." ;
447+ if ( fileValidator ( packagePath ) ) {
448+ return errorFormatter ( packagePath ) ;
454449 } else {
455450 return null ;
456451 }
457452 } ) . filter ( function ( errorMessage ) { return ! ! errorMessage ; } ) ;
458453 if ( errors . length > 0 )
459454 grunt . fail . fatal ( "\n" + errors . join ( "\n" ) ) ;
455+ }
456+
457+ grunt . registerTask ( "check-packagejson-boms" , function ( ) {
458+ validatePackageJsons ( function ( filepath ) {
459+ var buf = grunt . file . read ( filepath , { encoding : null } ) ;
460+ return ( buf [ 0 ] === 0xEF && buf [ 1 ] === 0xBB && buf [ 2 ] === 0xBF ) ;
461+ } , function ( filepath ) {
462+ return "File " + filepath + " contains a UTF-8 BOM." ;
463+ } ) ;
464+ } ) ;
465+
466+ grunt . registerTask ( "check-packagejson-mains" , function ( ) {
467+ validatePackageJsons ( function ( filepath ) {
468+ var packageData = grunt . file . readJSON ( filepath ) ;
469+ return / \. j s / i. test ( packageData . main || "" ) ;
470+ } , function ( filepath ) {
471+ return "File " + filepath + " contains a broken main setting." ;
472+ } ) ;
460473 } ) ;
461474
462475 grunt . registerTask ( "generate-tns-core-modules-dev-dts" , generateModulesDts . bind ( null , "." , localCfg . srcTnsCoreModules ) ) ;
@@ -475,6 +488,7 @@ module.exports = function(grunt) {
475488 "clean:build" ,
476489 "shell:getGitSHA" ,
477490 "check-packagejson-boms" ,
491+ "check-packagejson-mains" ,
478492 "compile-ts" ,
479493 "collect-modules-raw-files" ,
480494 "copy:definitionFiles" ,
@@ -557,4 +571,4 @@ module.exports = function(grunt) {
557571 "pack-apps" ,
558572 "get-ready-packages"
559573 ] ) ) ;
560- } ;
574+ } ;
0 commit comments