@@ -36,11 +36,12 @@ export class PlatformService extends EventEmitter implements IPlatformService {
3636 private $mobileHelper : Mobile . IMobileHelper ,
3737 private $hostInfo : IHostInfo ,
3838 private $devicePathProvider : IDevicePathProvider ,
39- private $npm : INodePackageManager ,
4039 private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
4140 private $projectChangesService : IProjectChangesService ,
4241 private $analyticsService : IAnalyticsService ,
43- private $terminalSpinnerService : ITerminalSpinnerService ) {
42+ private $terminalSpinnerService : ITerminalSpinnerService ,
43+ private $pacoteService : IPacoteService
44+ ) {
4445 super ( ) ;
4546 }
4647
@@ -92,10 +93,6 @@ export class PlatformService extends EventEmitter implements IPlatformService {
9293
9394 const platformData = this . $platformsData . getPlatformData ( platform , projectData ) ;
9495
95- if ( version === undefined ) {
96- version = this . getCurrentPlatformVersion ( platform , projectData ) ;
97- }
98-
9996 // Log the values for project
10097 this . $logger . trace ( "Creating NativeScript project for the %s platform" , platform ) ;
10198 this . $logger . trace ( "Path: %s" , platformData . projectRoot ) ;
@@ -105,28 +102,28 @@ export class PlatformService extends EventEmitter implements IPlatformService {
105102 this . $logger . out ( "Copying template files..." ) ;
106103
107104 let packageToInstall = "" ;
108- const npmOptions : IStringDictionary = {
109- pathToSave : path . join ( projectData . platformsDir , platform ) ,
110- dependencyType : "save"
111- } ;
105+ if ( frameworkPath ) {
106+ packageToInstall = path . resolve ( frameworkPath ) ;
107+ } else {
108+ if ( ! version ) {
109+ version = this . getCurrentPlatformVersion ( platform , projectData ) ||
110+ await this . $npmInstallationManager . getLatestCompatibleVersion ( platformData . frameworkPackageName ) ;
111+ }
112112
113- if ( ! frameworkPath ) {
114- packageToInstall = platformData . frameworkPackageName ;
115- npmOptions [ "version" ] = version ;
113+ packageToInstall = `${ platformData . frameworkPackageName } @${ version } ` ;
116114 }
117115
118116 const spinner = this . $terminalSpinnerService . createSpinner ( ) ;
119- const projectDir = projectData . projectDir ;
120117 const platformPath = path . join ( projectData . platformsDir , platform ) ;
121118
122119 try {
123120 spinner . start ( ) ;
124- const downloadedPackagePath = await this . $npmInstallationManager . install ( packageToInstall , projectDir , npmOptions ) ;
121+ const downloadedPackagePath = temp . mkdirSync ( "runtimeDir" ) ;
122+ temp . track ( ) ;
123+ await this . $pacoteService . extractPackage ( packageToInstall , downloadedPackagePath ) ;
125124 let frameworkDir = path . join ( downloadedPackagePath , constants . PROJECT_FRAMEWORK_FOLDER_NAME ) ;
126125 frameworkDir = path . resolve ( frameworkDir ) ;
127-
128- const coreModuleName = await this . addPlatformCore ( platformData , frameworkDir , platformTemplate , projectData , config , nativePrepare ) ;
129- await this . $npm . uninstall ( coreModuleName , { save : true } , projectData . projectDir ) ;
126+ await this . addPlatformCore ( platformData , frameworkDir , platformTemplate , projectData , config , nativePrepare ) ;
130127 } catch ( err ) {
131128 this . $fs . deleteDirectory ( platformPath ) ;
132129 throw err ;
@@ -135,7 +132,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
135132 }
136133
137134 this . $fs . ensureDirectoryExists ( platformPath ) ;
138- this . $logger . out ( "Project successfully created." ) ;
135+ this . $logger . out ( `Platform ${ platform } successfully added.` ) ;
139136 }
140137
141138 private async addPlatformCore ( platformData : IPlatformData , frameworkDir : string , platformTemplate : string , projectData : IProjectData , config : IPlatformOptions , nativePrepare ?: INativePrepare ) : Promise < string > {
@@ -842,15 +839,15 @@ export class PlatformService extends EventEmitter implements IPlatformService {
842839 const data = this . $projectDataService . getNSValue ( projectData . projectDir , platformData . frameworkPackageName ) ;
843840 const currentVersion = data && data . version ? data . version : "0.2.0" ;
844841
842+ const installedModuleDir = temp . mkdirSync ( "runtime-to-update" ) ;
845843 let newVersion = version === constants . PackageVersion . NEXT ?
846844 await this . $npmInstallationManager . getNextVersion ( platformData . frameworkPackageName ) :
847845 version || await this . $npmInstallationManager . getLatestCompatibleVersion ( platformData . frameworkPackageName ) ;
848- const installedModuleDir = await this . $npmInstallationManager . install ( platformData . frameworkPackageName , projectData . projectDir , { version : newVersion , dependencyType : "save" } ) ;
846+ await this . $pacoteService . extractPackage ( ` ${ platformData . frameworkPackageName } @ ${ newVersion } ` , installedModuleDir ) ;
849847 const cachedPackageData = this . $fs . readJson ( path . join ( installedModuleDir , "package.json" ) ) ;
850848 newVersion = ( cachedPackageData && cachedPackageData . version ) || newVersion ;
851849
852850 const canUpdate = platformData . platformProjectService . canUpdatePlatform ( installedModuleDir , projectData ) ;
853- await this . $npm . uninstall ( platformData . frameworkPackageName , { save : true } , projectData . projectDir ) ;
854851 if ( canUpdate ) {
855852 if ( ! semver . valid ( newVersion ) ) {
856853 this . $errors . fail ( "The version %s is not valid. The version should consists from 3 parts separated by dot." , newVersion ) ;
0 commit comments