@@ -569,7 +569,7 @@ namespace ts.projectSystem {
569569 }
570570 executeRequest ( requestKind : TI . RequestKind , requestId : number , args : string [ ] , cwd : string , cb : TI . RequestCompletedAction ) : void {
571571 if ( requestKind === TI . NpmInstallRequest ) {
572- let typingFiles : ( FileOrFolder & { typings : string } ) [ ] = [ ] ;
572+ let typingFiles : ( FileOrFolder & { typings : string } ) [ ] = [ ] ;
573573 if ( args . indexOf ( "@types/commander" ) >= 0 ) {
574574 typingFiles = [ commander , jquery , lodash , cordova ] ;
575575 }
@@ -591,7 +591,7 @@ namespace ts.projectSystem {
591591 projectFileName : projectFileName1 ,
592592 options : { allowJS : true , moduleResolution : ModuleResolutionKind . NodeJs } ,
593593 rootFiles : [ toExternalFile ( lodashJs . path ) , toExternalFile ( commanderJs . path ) , toExternalFile ( file3 . path ) ] ,
594- typingOptions : { include : [ "jquery" , "cordova" ] }
594+ typingOptions : { include : [ "jquery" , "cordova" ] }
595595 } ) ;
596596
597597 installer . checkPendingCommands ( [ TI . NpmViewRequest , TI . NpmViewRequest , TI . NpmViewRequest ] ) ;
@@ -626,7 +626,7 @@ namespace ts.projectSystem {
626626 installer . executePendingCommands ( ) ;
627627
628628 checkProjectActualFiles ( p1 , [ lodashJs . path , commanderJs . path , file3 . path , commander . path , jquery . path , lodash . path , cordova . path ] ) ;
629- checkProjectActualFiles ( p2 , [ file3 . path , grunt . path , gulp . path ] ) ;
629+ checkProjectActualFiles ( p2 , [ file3 . path , grunt . path , gulp . path ] ) ;
630630 } ) ;
631631
632632 it ( "configured projects discover from node_modules" , ( ) => {
@@ -687,10 +687,10 @@ namespace ts.projectSystem {
687687 const bowerJson = {
688688 path : "/bower.json" ,
689689 content : JSON . stringify ( {
690- "dependencies" : {
691- "jquery" : "^3.1.0"
692- }
693- } )
690+ "dependencies" : {
691+ "jquery" : "^3.1.0"
692+ }
693+ } )
694694 } ;
695695 const jqueryDTS = {
696696 path : "/tmp/node_modules/@types/jquery/index.d.ts" ,
@@ -720,34 +720,77 @@ namespace ts.projectSystem {
720720 checkNumberOfProjects ( projectService , { configuredProjects : 1 } ) ;
721721 checkProjectActualFiles ( p , [ app . path , jqueryDTS . path ] ) ;
722722 } ) ;
723+
724+ it ( "Malformed package.json should be watched" , ( ) => {
725+ const f = {
726+ path : "/a/b/app.js" ,
727+ content : "var x = require('commander')"
728+ } ;
729+ const brokenPackageJson = {
730+ path : "/a/b/package.json" ,
731+ content : `{ "dependencies": { "co } }`
732+ } ;
733+ const fixedPackageJson = {
734+ path : brokenPackageJson . path ,
735+ content : `{ "dependencies": { "commander": "0.0.2" } }`
736+ } ;
737+ const cachePath = "/a/cache/" ;
738+ const commander = {
739+ path : cachePath + "node_modules/@types/commander/index.d.ts" ,
740+ content : "export let x: number"
741+ } ;
742+ const host = createServerHost ( [ f , brokenPackageJson ] ) ;
743+ const installer = new ( class extends Installer {
744+ constructor ( ) {
745+ super ( host , { globalTypingsCacheLocation : cachePath } ) ;
746+ }
747+ executeRequest ( requestKind : TI . RequestKind , requestId : number , args : string [ ] , cwd : string , cb : server . typingsInstaller . RequestCompletedAction ) {
748+ const installedTypings = [ "@types/commander" ] ;
749+ const typingFiles = [ commander ] ;
750+ executeCommand ( this , host , installedTypings , typingFiles , requestKind , cb ) ;
751+ }
752+ } ) ( ) ;
753+ const service = createProjectService ( host , { typingsInstaller : installer } ) ;
754+ service . openClientFile ( f . path ) ;
755+
756+ installer . checkPendingCommands ( [ ] ) ;
757+
758+ host . reloadFS ( [ f , fixedPackageJson ] ) ;
759+ host . triggerFileWatcherCallback ( fixedPackageJson . path , /*removed*/ false ) ;
760+ // expected one view and one install request
761+ installer . installAll ( [ TI . NpmViewRequest ] , [ TI . NpmInstallRequest ] ) ;
762+
763+ service . checkNumberOfProjects ( { inferredProjects : 1 } ) ;
764+ checkProjectActualFiles ( service . inferredProjects [ 0 ] , [ f . path , commander . path ] ) ;
765+ } ) ;
723766 } ) ;
724767
725768 describe ( "Validate package name:" , ( ) => {
726- it ( "name cannot be too long" , ( ) => {
769+ it ( "name cannot be too long" , ( ) => {
727770 let packageName = "a" ;
728771 for ( let i = 0 ; i < 8 ; i ++ ) {
729772 packageName += packageName ;
730773 }
731774 assert . equal ( TI . validatePackageName ( packageName ) , TI . PackageNameValidationResult . NameTooLong ) ;
732775 } ) ;
733- it ( "name cannot start with dot" , ( ) => {
776+ it ( "name cannot start with dot" , ( ) => {
734777 assert . equal ( TI . validatePackageName ( ".foo" ) , TI . PackageNameValidationResult . NameStartsWithDot ) ;
735778 } ) ;
736- it ( "name cannot start with underscore" , ( ) => {
779+ it ( "name cannot start with underscore" , ( ) => {
737780 assert . equal ( TI . validatePackageName ( "_foo" ) , TI . PackageNameValidationResult . NameStartsWithUnderscore ) ;
738781 } ) ;
739- it ( "scoped packages not supported" , ( ) => {
782+ it ( "scoped packages not supported" , ( ) => {
740783 assert . equal ( TI . validatePackageName ( "@scope/bar" ) , TI . PackageNameValidationResult . ScopedPackagesNotSupported ) ;
741784 } ) ;
742- it ( "non URI safe characters are not supported" , ( ) => {
785+ it ( "non URI safe characters are not supported" , ( ) => {
743786 assert . equal ( TI . validatePackageName ( " scope " ) , TI . PackageNameValidationResult . NameContainsNonURISafeCharacters ) ;
744787 assert . equal ( TI . validatePackageName ( "; say ‘Hello from TypeScript!’ #" ) , TI . PackageNameValidationResult . NameContainsNonURISafeCharacters ) ;
745788 assert . equal ( TI . validatePackageName ( "a/b/c" ) , TI . PackageNameValidationResult . NameContainsNonURISafeCharacters ) ;
746789 } ) ;
747790 } ) ;
748791
749792 describe ( "Invalid package names" , ( ) => {
750- it ( "should not be installed" , ( ) => {
793+ it ( "should not be installed" , ( ) => {
751794 const f1 = {
752795 path : "/a/b/app.js" ,
753796 content : "let x = 1"
0 commit comments