Skip to content

Commit 07f1a44

Browse files
authored
Merge pull request #4839 from NativeScript/kddimitrov/fix-update-invalid-tag
Kddimitrov/fix update invalid tag
2 parents d291adc + 0e1c13d commit 07f1a44

File tree

4 files changed

+28
-40
lines changed

4 files changed

+28
-40
lines changed

docs/man_pages/general/update.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ position: 16
77

88
### Description
99

10-
Updates the project with the latest versions of iOS/Android runtimes and cross-platform modules.
10+
Updates the project with the latest versions of iOS/Android runtimes, cross-platform modules and "nativescript-dev-webpack".
1111
In order to get the latest development release instead, pass `next` as argument:
1212
`tns update next`
1313

1414
You can also switch to specific version by passing it to the command:
1515
`tns update 5.0.0`
1616

17+
**NOTE:** The provided version should be an existing version of the project template for this project type.
18+
1719
### Commands
1820

1921
Usage | Synopsis

docs/man_pages/project/configuration/update.md

-29
This file was deleted.

lib/controllers/update-controller-base.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class UpdateControllerBase {
1010
protected $packageInstallationManager: IPackageInstallationManager,
1111
protected $packageManager: IPackageManager,
1212
protected $pacoteService: IPacoteService) {
13-
this.getPackageManifest = _.memoize(this._getManifestManifest, (...args) => {
13+
this.getPackageManifest = _.memoize(this._getPackageManifest, (...args) => {
1414
return args.join("@");
1515
});
1616
}
@@ -73,11 +73,13 @@ export class UpdateControllerBase {
7373
return maxDependencyVersion;
7474
}
7575

76-
private async _getManifestManifest(templateName: string, version?: string) {
77-
const packageVersion = semver.valid(version) ||
78-
await this.$packageManager.getTagVersion(templateName, version) ||
79-
await this.$packageInstallationManager.getLatestCompatibleVersionSafe(templateName);
76+
private async _getPackageManifest(templateName: string, version: string): Promise<any> {
77+
const packageVersion = semver.valid(version) || await this.$packageManager.getTagVersion(templateName, version);
8078

81-
return await this.$pacoteService.manifest(`${templateName}@${packageVersion}`, { fullMetadata: true });
79+
if (packageVersion && semver.valid(packageVersion)) {
80+
return await this.$pacoteService.manifest(`${templateName}@${packageVersion}`, { fullMetadata: true });
81+
} else {
82+
throw new Error(`Failed to get information for package: ${templateName}@${version}`);
83+
}
8284
}
8385
}

lib/controllers/update-controller.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
1919
static readonly backupFolder: string = ".update_backup";
2020
static readonly updateFailMessage: string = "Could not update the project!";
2121
static readonly backupFailMessage: string = "Could not backup project folders!";
22+
static readonly failedToGetTemplateManifestMessage = "Failed to get template information for the specified version. Original error: %s";
2223

2324
constructor(
2425
protected $fs: IFileSystem,
@@ -29,6 +30,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
2930
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
3031
private $addPlatformService: IAddPlatformService,
3132
private $logger: ILogger,
33+
private $errors: IErrors,
3234
private $pluginsService: IPluginsService,
3335
protected $pacoteService: IPacoteService,
3436
private $projectDataService: IProjectDataService) {
@@ -58,8 +60,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
5860

5961
public async shouldUpdate({ projectDir, version }: { projectDir: string, version?: string }): Promise<boolean> {
6062
const projectData = this.$projectDataService.getProjectData(projectDir);
61-
const templateName = this.getTemplateName(projectData);
62-
const templateManifest = await this.getPackageManifest(templateName, version);
63+
const templateManifest = await this.getTemplateManifest(projectData, version);
6364
const dependencies = this.getUpdatableDependencies(templateManifest.dependencies);
6465
const devDependencies = this.getUpdatableDependencies(templateManifest.devDependencies);
6566

@@ -92,8 +93,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
9293
}
9394

9495
private async updateProject(projectData: IProjectData, version: string): Promise<void> {
95-
const templateName = this.getTemplateName(projectData);
96-
const templateManifest = await this.getPackageManifest(templateName, version);
96+
const templateManifest = await this.getTemplateManifest(projectData, version);
9797
const dependencies = this.getUpdatableDependencies(templateManifest.dependencies);
9898
const devDependencies = this.getUpdatableDependencies(templateManifest.devDependencies);
9999

@@ -208,6 +208,19 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
208208

209209
return template;
210210
}
211+
212+
private async getTemplateManifest(projectData: IProjectData, version: string): Promise<any> {
213+
let templateManifest;
214+
const templateName = this.getTemplateName(projectData);
215+
version = version || await this.$packageInstallationManager.getLatestCompatibleVersionSafe(templateName);
216+
try {
217+
templateManifest = await this.getPackageManifest(templateName, version);
218+
} catch (err) {
219+
this.$errors.fail(UpdateController.failedToGetTemplateManifestMessage, err.message);
220+
}
221+
222+
return templateManifest;
223+
}
211224
}
212225

213226
$injector.register("updateController", UpdateController);

0 commit comments

Comments
 (0)