@@ -34,7 +34,7 @@ export class NpmService implements INpmService {
34
34
let npmMainJsFile = require . resolve ( NpmService . NPM_MODULE_NAME ) ;
35
35
let pathToNpmBinary = path . join ( npmMainJsFile . substring ( 0 , npmMainJsFile . lastIndexOf ( constants . NODE_MODULES_DIR_NAME ) + constants . NODE_MODULES_DIR_NAME . length ) , ".bin" , this . npmExecutableName ) ;
36
36
37
- if ( ! this . $fs . exists ( pathToNpmBinary ) . wait ( ) ) {
37
+ if ( ! this . $fs . exists ( pathToNpmBinary ) ) {
38
38
throw new Error ( `The npm binary is not in ${ pathToNpmBinary } as expected.` ) ;
39
39
}
40
40
@@ -95,7 +95,7 @@ export class NpmService implements INpmService {
95
95
}
96
96
}
97
97
98
- this . generateReferencesFile ( projectDir ) . wait ( ) ;
98
+ this . generateReferencesFile ( projectDir ) ;
99
99
100
100
return npmInstallResult ;
101
101
} ) . future < INpmInstallResult > ( ) ( ) ;
@@ -104,7 +104,7 @@ export class NpmService implements INpmService {
104
104
@exportedPromise ( "npmService" )
105
105
public uninstall ( projectDir : string , dependency : string ) : IFuture < void > {
106
106
return ( ( ) => {
107
- let packageJsonContent = this . getPackageJsonContent ( projectDir ) . wait ( ) ;
107
+ let packageJsonContent = this . getPackageJsonContent ( projectDir ) ;
108
108
109
109
if ( packageJsonContent && packageJsonContent . dependencies && packageJsonContent . dependencies [ dependency ] ) {
110
110
this . npmUninstall ( projectDir , dependency , [ "--save" ] ) . wait ( ) ;
@@ -114,7 +114,7 @@ export class NpmService implements INpmService {
114
114
this . npmUninstall ( projectDir , `${ NpmService . TYPES_DIRECTORY } ${ dependency } ` , [ "--save-dev" ] ) . wait ( ) ;
115
115
}
116
116
117
- this . generateReferencesFile ( projectDir ) . wait ( ) ;
117
+ this . generateReferencesFile ( projectDir ) ;
118
118
} ) . future < void > ( ) ( ) ;
119
119
}
120
120
@@ -242,21 +242,18 @@ export class NpmService implements INpmService {
242
242
} ) . future < string > ( ) ( ) ;
243
243
}
244
244
245
- private getPackageJsonContent ( projectDir : string ) : IFuture < any > {
246
- return ( ( ) => {
247
- let pathToPackageJson = this . getPathToPackageJson ( projectDir ) ;
248
-
249
- try {
250
- return this . $fs . readJson ( pathToPackageJson ) . wait ( ) ;
251
- } catch ( err ) {
252
- if ( err . code === "ENOENT" ) {
253
- this . $errors . failWithoutHelp ( `Unable to find ${ this . $projectConstants . PACKAGE_JSON_NAME } in ${ projectDir } .` ) ;
254
- }
245
+ private getPackageJsonContent ( projectDir : string ) : any {
246
+ let pathToPackageJson = this . getPathToPackageJson ( projectDir ) ;
255
247
256
- throw err ;
248
+ try {
249
+ return this . $fs . readJson ( pathToPackageJson ) ;
250
+ } catch ( err ) {
251
+ if ( err . code === "ENOENT" ) {
252
+ this . $errors . failWithoutHelp ( `Unable to find ${ this . $projectConstants . PACKAGE_JSON_NAME } in ${ projectDir } .` ) ;
257
253
}
258
254
259
- } ) . future < any > ( ) ( ) ;
255
+ throw err ;
256
+ }
260
257
}
261
258
262
259
private getPathToPackageJson ( projectDir : string ) : string {
@@ -271,59 +268,56 @@ export class NpmService implements INpmService {
271
268
return this . npmInstall ( projectDir , `${ NpmService . TYPES_DIRECTORY } ${ dependency } ` , null , [ "--save-dev" , "--save-exact" ] ) ;
272
269
}
273
270
274
- private generateReferencesFile ( projectDir : string ) : IFuture < void > {
275
- return ( ( ) => {
276
- let packageJsonContent = this . getPackageJsonContent ( projectDir ) . wait ( ) ;
271
+ private generateReferencesFile ( projectDir : string ) : void {
272
+ let packageJsonContent = this . getPackageJsonContent ( projectDir ) ;
277
273
278
- let pathToReferenceFile = this . getPathToReferencesFile ( projectDir ) ,
279
- lines : string [ ] = [ ] ;
274
+ let pathToReferenceFile = this . getPathToReferencesFile ( projectDir ) ,
275
+ lines : string [ ] = [ ] ;
280
276
281
- if ( packageJsonContent && packageJsonContent . dependencies && packageJsonContent . dependencies [ constants . TNS_CORE_MODULES ] ) {
282
- let relativePathToTnsCoreModulesDts = `./${ constants . NODE_MODULES_DIR_NAME } /${ constants . TNS_CORE_MODULES } /${ NpmService . TNS_CORE_MODULES_DEFINITION_FILE_NAME } ` ;
277
+ if ( packageJsonContent && packageJsonContent . dependencies && packageJsonContent . dependencies [ constants . TNS_CORE_MODULES ] ) {
278
+ let relativePathToTnsCoreModulesDts = `./${ constants . NODE_MODULES_DIR_NAME } /${ constants . TNS_CORE_MODULES } /${ NpmService . TNS_CORE_MODULES_DEFINITION_FILE_NAME } ` ;
283
279
284
- if ( this . $fs . exists ( path . join ( projectDir , relativePathToTnsCoreModulesDts ) ) . wait ( ) ) {
285
- lines . push ( this . getReferenceLine ( relativePathToTnsCoreModulesDts ) ) ;
286
- }
280
+ if ( this . $fs . exists ( path . join ( projectDir , relativePathToTnsCoreModulesDts ) ) ) {
281
+ lines . push ( this . getReferenceLine ( relativePathToTnsCoreModulesDts ) ) ;
287
282
}
283
+ }
288
284
289
- _ ( packageJsonContent . devDependencies )
290
- . keys ( )
291
- . each ( devDependency => {
292
- if ( this . isFromTypesRepo ( devDependency ) ) {
293
- let nodeModulesDirectory = path . join ( projectDir , constants . NODE_MODULES_DIR_NAME ) ;
294
- let definitionFiles = this . $fs . enumerateFilesInDirectorySync ( path . join ( nodeModulesDirectory , devDependency ) ,
295
- ( file , stat ) => _ . endsWith ( file , constants . FileExtensions . TYPESCRIPT_DEFINITION_FILE ) || stat . isDirectory ( ) , { enumerateDirectories : false } ) ;
285
+ _ ( packageJsonContent . devDependencies )
286
+ . keys ( )
287
+ . each ( devDependency => {
288
+ if ( this . isFromTypesRepo ( devDependency ) ) {
289
+ let nodeModulesDirectory = path . join ( projectDir , constants . NODE_MODULES_DIR_NAME ) ;
290
+ let definitionFiles = this . $fs . enumerateFilesInDirectorySync ( path . join ( nodeModulesDirectory , devDependency ) ,
291
+ ( file , stat ) => _ . endsWith ( file , constants . FileExtensions . TYPESCRIPT_DEFINITION_FILE ) || stat . isDirectory ( ) , { enumerateDirectories : false } ) ;
296
292
297
- let defs = _ . map ( definitionFiles , def => this . getReferenceLine ( fromWindowsRelativePathToUnix ( path . relative ( projectDir , def ) ) ) ) ;
293
+ let defs = _ . map ( definitionFiles , def => this . getReferenceLine ( fromWindowsRelativePathToUnix ( path . relative ( projectDir , def ) ) ) ) ;
298
294
299
- this . $logger . trace ( `Adding lines for definition files: ${ definitionFiles . join ( ", " ) } ` ) ;
300
- lines = lines . concat ( defs ) ;
301
- }
302
- } ) ;
295
+ this . $logger . trace ( `Adding lines for definition files: ${ definitionFiles . join ( ", " ) } ` ) ;
296
+ lines = lines . concat ( defs ) ;
297
+ }
298
+ } ) ;
303
299
304
- // TODO: Make sure the android17.d.ts and ios.d.ts are added.
300
+ // TODO: Make sure the android17.d.ts and ios.d.ts are added.
305
301
306
- if ( lines . length ) {
307
- this . $logger . trace ( "Updating reference file with new entries..." ) ;
308
- this . $fs . writeFile ( pathToReferenceFile , lines . join ( os . EOL ) , "utf8" ) . wait ( ) ;
302
+ if ( lines . length ) {
303
+ this . $logger . trace ( "Updating reference file with new entries..." ) ;
304
+ this . $fs . writeFile ( pathToReferenceFile , lines . join ( os . EOL ) , "utf8" ) ;
309
305
310
- // Our old name for the file which contains the definitions imports was .abreferences.d.ts.
311
- // TypeScript 2.0 does not respect hidden definition files and we had to rename the file.
312
- this . removeOldAbReferencesFile ( projectDir ) . wait ( ) ;
313
- } else {
314
- this . $logger . trace ( `Could not find any .d.ts files for ${ this . $projectConstants . REFERENCES_FILE_NAME } file. Deleting the old file.` ) ;
315
- this . $fs . deleteFile ( pathToReferenceFile ) . wait ( ) ;
316
- }
317
- } ) . future < void > ( ) ( ) ;
306
+ // Our old name for the file which contains the definitions imports was .abreferences.d.ts.
307
+ // TypeScript 2.0 does not respect hidden definition files and we had to rename the file.
308
+ this . removeOldAbReferencesFile ( projectDir ) ;
309
+ } else {
310
+ this . $logger . trace ( `Could not find any .d.ts files for ${ this . $projectConstants . REFERENCES_FILE_NAME } file. Deleting the old file.` ) ;
311
+ this . $fs . deleteFile ( pathToReferenceFile ) ;
312
+ }
318
313
}
319
314
320
- private removeOldAbReferencesFile ( projectDir : string ) : IFuture < void > {
321
- return ( ( ) => {
322
- const pathToOldReferencesFile = path . join ( projectDir , this . $projectConstants . OLD_REFERENCES_FILE_NAME ) ;
323
- if ( this . $fs . exists ( pathToOldReferencesFile ) . wait ( ) ) {
324
- this . $fs . deleteFile ( pathToOldReferencesFile ) . wait ( ) ;
325
- }
326
- } ) . future < void > ( ) ( ) ;
315
+ private removeOldAbReferencesFile ( projectDir : string ) : void {
316
+ const pathToOldReferencesFile = path . join ( projectDir , this . $projectConstants . OLD_REFERENCES_FILE_NAME ) ;
317
+
318
+ if ( this . $fs . exists ( pathToOldReferencesFile ) ) {
319
+ this . $fs . deleteFile ( pathToOldReferencesFile ) ;
320
+ }
327
321
}
328
322
329
323
private isFromTypesRepo ( dependency : string ) : boolean {
0 commit comments