Skip to content

Kddimitrov/fix update invalid tag #4839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/man_pages/general/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ position: 16

### Description

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

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

**NOTE:** The provided version should be an existing version of the project template for this project type.

### Commands

Usage | Synopsis
Expand Down
29 changes: 0 additions & 29 deletions docs/man_pages/project/configuration/update.md

This file was deleted.

14 changes: 8 additions & 6 deletions lib/controllers/update-controller-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class UpdateControllerBase {
protected $packageInstallationManager: IPackageInstallationManager,
protected $packageManager: IPackageManager,
protected $pacoteService: IPacoteService) {
this.getPackageManifest = _.memoize(this._getManifestManifest, (...args) => {
this.getPackageManifest = _.memoize(this._getPackageManifest, (...args) => {
return args.join("@");
});
}
Expand Down Expand Up @@ -73,11 +73,13 @@ export class UpdateControllerBase {
return maxDependencyVersion;
}

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

return await this.$pacoteService.manifest(`${templateName}@${packageVersion}`, { fullMetadata: true });
if (packageVersion && semver.valid(packageVersion)) {
return await this.$pacoteService.manifest(`${templateName}@${packageVersion}`, { fullMetadata: true });
} else {
throw new Error(`Failed to get information for package: ${templateName}@${version}`);
}
}
}
21 changes: 17 additions & 4 deletions lib/controllers/update-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
static readonly backupFolder: string = ".update_backup";
static readonly updateFailMessage: string = "Could not update the project!";
static readonly backupFailMessage: string = "Could not backup project folders!";
static readonly failedToGetTemplateManifestMessage = "Failed to get template information for the specified version. Original error: %s";

constructor(
protected $fs: IFileSystem,
Expand All @@ -29,6 +30,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $addPlatformService: IAddPlatformService,
private $logger: ILogger,
private $errors: IErrors,
private $pluginsService: IPluginsService,
protected $pacoteService: IPacoteService,
private $projectDataService: IProjectDataService) {
Expand Down Expand Up @@ -58,8 +60,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon

public async shouldUpdate({ projectDir, version }: { projectDir: string, version?: string }): Promise<boolean> {
const projectData = this.$projectDataService.getProjectData(projectDir);
const templateName = this.getTemplateName(projectData);
const templateManifest = await this.getPackageManifest(templateName, version);
const templateManifest = await this.getTemplateManifest(projectData, version);
const dependencies = this.getUpdatableDependencies(templateManifest.dependencies);
const devDependencies = this.getUpdatableDependencies(templateManifest.devDependencies);

Expand Down Expand Up @@ -92,8 +93,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon
}

private async updateProject(projectData: IProjectData, version: string): Promise<void> {
const templateName = this.getTemplateName(projectData);
const templateManifest = await this.getPackageManifest(templateName, version);
const templateManifest = await this.getTemplateManifest(projectData, version);
const dependencies = this.getUpdatableDependencies(templateManifest.dependencies);
const devDependencies = this.getUpdatableDependencies(templateManifest.devDependencies);

Expand Down Expand Up @@ -208,6 +208,19 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon

return template;
}

private async getTemplateManifest(projectData: IProjectData, version: string): Promise<any> {
let templateManifest;
const templateName = this.getTemplateName(projectData);
version = version || await this.$packageInstallationManager.getLatestCompatibleVersionSafe(templateName);
try {
templateManifest = await this.getPackageManifest(templateName, version);
} catch (err) {
this.$errors.fail(UpdateController.failedToGetTemplateManifestMessage, err.message);
}

return templateManifest;
}
}

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