@@ -36,11 +36,12 @@ export class PlatformService extends EventEmitter implements IPlatformService {
36
36
private $mobileHelper : Mobile . IMobileHelper ,
37
37
private $hostInfo : IHostInfo ,
38
38
private $devicePathProvider : IDevicePathProvider ,
39
- private $npm : INodePackageManager ,
40
39
private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
41
40
private $projectChangesService : IProjectChangesService ,
42
41
private $analyticsService : IAnalyticsService ,
43
- private $terminalSpinnerService : ITerminalSpinnerService ) {
42
+ private $terminalSpinnerService : ITerminalSpinnerService ,
43
+ private $pacoteService : IPacoteService
44
+ ) {
44
45
super ( ) ;
45
46
}
46
47
@@ -92,10 +93,6 @@ export class PlatformService extends EventEmitter implements IPlatformService {
92
93
93
94
const platformData = this . $platformsData . getPlatformData ( platform , projectData ) ;
94
95
95
- if ( version === undefined ) {
96
- version = this . getCurrentPlatformVersion ( platform , projectData ) ;
97
- }
98
-
99
96
// Log the values for project
100
97
this . $logger . trace ( "Creating NativeScript project for the %s platform" , platform ) ;
101
98
this . $logger . trace ( "Path: %s" , platformData . projectRoot ) ;
@@ -105,28 +102,28 @@ export class PlatformService extends EventEmitter implements IPlatformService {
105
102
this . $logger . out ( "Copying template files..." ) ;
106
103
107
104
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
+ }
112
112
113
- if ( ! frameworkPath ) {
114
- packageToInstall = platformData . frameworkPackageName ;
115
- npmOptions [ "version" ] = version ;
113
+ packageToInstall = `${ platformData . frameworkPackageName } @${ version } ` ;
116
114
}
117
115
118
116
const spinner = this . $terminalSpinnerService . createSpinner ( ) ;
119
- const projectDir = projectData . projectDir ;
120
117
const platformPath = path . join ( projectData . platformsDir , platform ) ;
121
118
122
119
try {
123
120
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 ) ;
125
124
let frameworkDir = path . join ( downloadedPackagePath , constants . PROJECT_FRAMEWORK_FOLDER_NAME ) ;
126
125
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 ) ;
130
127
} catch ( err ) {
131
128
this . $fs . deleteDirectory ( platformPath ) ;
132
129
throw err ;
@@ -135,7 +132,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
135
132
}
136
133
137
134
this . $fs . ensureDirectoryExists ( platformPath ) ;
138
- this . $logger . out ( "Project successfully created." ) ;
135
+ this . $logger . out ( `Platform ${ platform } successfully added.` ) ;
139
136
}
140
137
141
138
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 {
842
839
const data = this . $projectDataService . getNSValue ( projectData . projectDir , platformData . frameworkPackageName ) ;
843
840
const currentVersion = data && data . version ? data . version : "0.2.0" ;
844
841
842
+ const installedModuleDir = temp . mkdirSync ( "runtime-to-update" ) ;
845
843
let newVersion = version === constants . PackageVersion . NEXT ?
846
844
await this . $npmInstallationManager . getNextVersion ( platformData . frameworkPackageName ) :
847
845
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 ) ;
849
847
const cachedPackageData = this . $fs . readJson ( path . join ( installedModuleDir , "package.json" ) ) ;
850
848
newVersion = ( cachedPackageData && cachedPackageData . version ) || newVersion ;
851
849
852
850
const canUpdate = platformData . platformProjectService . canUpdatePlatform ( installedModuleDir , projectData ) ;
853
- await this . $npm . uninstall ( platformData . frameworkPackageName , { save : true } , projectData . projectDir ) ;
854
851
if ( canUpdate ) {
855
852
if ( ! semver . valid ( newVersion ) ) {
856
853
this . $errors . fail ( "The version %s is not valid. The version should consists from 3 parts separated by dot." , newVersion ) ;
0 commit comments