@@ -9,6 +9,11 @@ import * as constants from "./constants";
9
9
export class NpmInstallationManager implements INpmInstallationManager {
10
10
private static NPM_LOAD_FAILED = "Failed to retrieve data from npm. Please try again a little bit later." ;
11
11
private versionsCache : IDictionary < string [ ] > ;
12
+ private packageSpecificDirectories : IStringDictionary = {
13
+ "tns-android" : constants . PROJECT_FRAMEWORK_FOLDER_NAME ,
14
+ "tns-ios" : constants . PROJECT_FRAMEWORK_FOLDER_NAME ,
15
+ "tns-template-hello-world" : constants . APP_RESOURCES_FOLDER_NAME
16
+ } ;
12
17
13
18
constructor ( private $npm : INodePackageManager ,
14
19
private $logger : ILogger ,
@@ -36,7 +41,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
36
41
}
37
42
38
43
if ( ! this . isShasumOfPackageCorrect ( packageName , version ) . wait ( ) ) {
39
- // In some cases the package is not fully downloaded and the framework directory is missing
44
+ // In some cases the package is not fully downloaded and there are missing directories
40
45
// Try removing the old package and add the real one to cache again
41
46
this . addCleanCopyToCache ( packageName , version ) . wait ( ) ;
42
47
}
@@ -94,7 +99,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
94
99
return ( ( ) => {
95
100
this . $npm . cache ( packageName , version ) . wait ( ) ;
96
101
let packagePath = path . join ( this . getCacheRootPath ( ) , packageName , version , "package" ) ;
97
- if ( ! this . isPackageUnpacked ( packagePath ) . wait ( ) ) {
102
+ if ( ! this . isPackageUnpacked ( packagePath , packageName ) . wait ( ) ) {
98
103
this . cacheUnpack ( packageName , version ) . wait ( ) ;
99
104
}
100
105
} ) . future < void > ( ) ( ) ;
@@ -128,13 +133,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
128
133
} else {
129
134
version = version || this . getLatestVersion ( packageName ) . wait ( ) ;
130
135
let packagePath = this . getCachedPackagePath ( packageName , version ) ;
131
- if ( ! this . isPackageCached ( packagePath ) . wait ( ) ) {
132
- this . $npm . cache ( packageName , version ) . wait ( ) ;
133
- }
134
-
135
- if ( ! this . isPackageUnpacked ( packagePath ) . wait ( ) ) {
136
- this . cacheUnpack ( packageName , version ) . wait ( ) ;
137
- }
136
+ this . addToCache ( packageName , version ) . wait ( ) ;
138
137
return packagePath ;
139
138
}
140
139
} ) . future < string > ( ) ( ) ;
@@ -151,15 +150,17 @@ export class NpmInstallationManager implements INpmInstallationManager {
151
150
return this . $npm . install ( packageName , pathToSave ) ;
152
151
}
153
152
154
- private isPackageCached ( packagePath : string ) : IFuture < boolean > {
155
- return this . $fs . exists ( packagePath ) ;
156
- }
157
-
158
- private isPackageUnpacked ( packagePath : string ) : IFuture < boolean > {
153
+ private isPackageUnpacked ( packagePath : string , packageName : string ) : IFuture < boolean > {
159
154
return ( ( ) => {
155
+ let additionalDirectoryToCheck = this . packageSpecificDirectories [ packageName ] ;
160
156
return this . $fs . getFsStats ( packagePath ) . wait ( ) . isDirectory ( ) &&
161
- this . $fs . exists ( path . join ( packagePath , "framework" ) ) . wait ( ) &&
162
- this . $fs . enumerateFilesInDirectorySync ( path . join ( packagePath , "framework" ) ) . length > 1 ;
157
+ ( ! additionalDirectoryToCheck || this . hasFilesInDirectory ( path . join ( packagePath , additionalDirectoryToCheck ) ) . wait ( ) ) ;
158
+ } ) . future < boolean > ( ) ( ) ;
159
+ }
160
+
161
+ private hasFilesInDirectory ( directory : string ) : IFuture < boolean > {
162
+ return ( ( ) : boolean => {
163
+ return this . $fs . exists ( directory ) . wait ( ) && this . $fs . enumerateFilesInDirectorySync ( directory ) . length > 0 ;
163
164
} ) . future < boolean > ( ) ( ) ;
164
165
}
165
166
}
0 commit comments