Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit a63d238

Browse files
Merge pull request #22 from NativeScript/natanasova/local-package-json
Add runtime version in local package.json
2 parents a46f51d + 0410a4a commit a63d238

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/services/cloud-build-service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class CloudBuildService extends EventEmitter implements ICloudBuildServic
2525
private $cloudBuildOutputFilter: ICloudBuildOutputFilter,
2626
private $mobileHelper: Mobile.IMobileHelper,
2727
private $projectHelper: IProjectHelper,
28+
private $projectDataService: IProjectDataService,
2829
private $qr: IQrCodeGenerator) {
2930
super();
3031
}
@@ -51,7 +52,13 @@ export class CloudBuildService extends EventEmitter implements ICloudBuildServic
5152

5253
await this.waitForBuildToFinish(buildResponse);
5354

55+
const runtimePropertyName = `tns-${platform.toLowerCase()}`;
56+
if (!this.$projectDataService.getNSValue(projectSettings.projectDir, runtimePropertyName)) {
57+
this.$projectDataService.setNSValue(projectSettings.projectDir, runtimePropertyName, { version: buildProps.properties.runtimeVersion });
58+
}
59+
5460
const buildResult: IBuildResult = await this.getObjectFromS3File<IBuildResult>(buildResponse.resultUrl);
61+
5562
this.$logger.trace("Build result:");
5663
this.$logger.trace(buildResult);
5764

@@ -474,7 +481,7 @@ export class CloudBuildService extends EventEmitter implements ICloudBuildServic
474481
if (!runtimeVersion && coreModulesVersion) {
475482
// no runtime added. Let's find out which one we need based on the tns-core-modules.
476483
if (semver.valid(coreModulesVersion)) {
477-
runtimeVersion = `${semver.major(coreModulesVersion)}.${semver.minor(coreModulesVersion)}.*`;
484+
runtimeVersion = await this.getLatestMatchingVersion(runtimePackageName, this.getVersionRangeWithTilde(coreModulesVersion));
478485
} else if (semver.validRange(coreModulesVersion)) {
479486
// In case tns-core-modules in package.json are referred as `~x.x.x` - this is not a valid version, but is valid range.
480487
runtimeVersion = await this.getLatestMatchingVersion(runtimePackageName, coreModulesVersion);
@@ -486,7 +493,7 @@ export class CloudBuildService extends EventEmitter implements ICloudBuildServic
486493

487494
private async getCliVersion(runtimeVersion: string): Promise<string> {
488495
try {
489-
const latestMatchingVersion = await this.getLatestMatchingVersion("nativescript", `~${runtimeVersion}`);
496+
const latestMatchingVersion = await this.getLatestMatchingVersion("nativescript", this.getVersionRangeWithTilde(runtimeVersion));
490497
return latestMatchingVersion || CloudBuildService.DEFAULT_VERSION;
491498
} catch (err) {
492499
this.$logger.trace(`Unable to get information about CLI versions. Error is: ${err.message}`);
@@ -514,6 +521,10 @@ export class CloudBuildService extends EventEmitter implements ICloudBuildServic
514521
}
515522
}
516523

524+
private getVersionRangeWithTilde(versionString: string): string {
525+
return `~${semver.major(versionString)}.${semver.minor(versionString)}.0`;
526+
}
527+
517528
private getCertificateInfo(certificatePath: string, certificatePassword: string): ICertificateInfo {
518529
const certificateAbsolutePath = path.resolve(certificatePath);
519530
const certificateContents: any = this.$fs.readFile(certificateAbsolutePath, { encoding: 'binary' });

0 commit comments

Comments
 (0)