From 6333a6c74c648333b68d771cf3a40f9f7962834a Mon Sep 17 00:00:00 2001 From: Kristian Dimitrov Date: Thu, 11 Jul 2019 13:15:52 +0300 Subject: [PATCH 1/2] docs: fix update command help --- docs/man_pages/general/update.md | 2 +- .../man_pages/project/configuration/update.md | 29 ------------------- 2 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 docs/man_pages/project/configuration/update.md diff --git a/docs/man_pages/general/update.md b/docs/man_pages/general/update.md index 868686aa40..9df25b52df 100644 --- a/docs/man_pages/general/update.md +++ b/docs/man_pages/general/update.md @@ -7,7 +7,7 @@ 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` diff --git a/docs/man_pages/project/configuration/update.md b/docs/man_pages/project/configuration/update.md deleted file mode 100644 index a59fa8720b..0000000000 --- a/docs/man_pages/project/configuration/update.md +++ /dev/null @@ -1,29 +0,0 @@ -<% if (isJekyll) { %>--- -title: tns update -position: 8 ----<% } %> - -# tns update - -### Description - -Updates a NativeScript to the latest compatible combination of NativeScript dependencies. The combination of dependencies is taken from the latest(or specified) version of the template for the type of the target project (Angular, Vue.js and etc.). - -### Commands - -Usage | Synopsis -------|------- -Update with the latest version |`$ tns update` -Update with specific version | `$ tns update ` - -### Related Commands - -Command | Description -----------|---------- -[install](install.html) | Installs all platforms and dependencies described in the `package.json` file in the current directory. -[platform add](platform-add.html) | Configures the current project to target the selected platform. -[platform remove](platform-remove.html) | Removes the selected platform from the platforms that the project currently targets. -[platform](platform.html) | Lists all platforms that the project currently targets. -[prepare](prepare.html) | Copies common and relevant platform-specific content from the app directory to the subdirectory for the selected target platform in the platforms directory. -[platform update](platform-update.html) | Updates the NativeScript runtime for the specified platform. -[resources update android](resources-update.html) | Updates the App_Resources/Android directory to the new v4.0 directory structure \ No newline at end of file From 0e1c13d650ea194e9c73a6014eb1e51043b6cf79 Mon Sep 17 00:00:00 2001 From: Kristian Dimitrov Date: Thu, 11 Jul 2019 17:03:04 +0300 Subject: [PATCH 2/2] fix: update with invalid tag will execute for latest compatible version --- docs/man_pages/general/update.md | 2 ++ lib/controllers/update-controller-base.ts | 14 ++++++++------ lib/controllers/update-controller.ts | 21 +++++++++++++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/docs/man_pages/general/update.md b/docs/man_pages/general/update.md index 9df25b52df..53bf2bef1d 100644 --- a/docs/man_pages/general/update.md +++ b/docs/man_pages/general/update.md @@ -14,6 +14,8 @@ In order to get the latest development release instead, pass `next` as argument: 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 diff --git a/lib/controllers/update-controller-base.ts b/lib/controllers/update-controller-base.ts index 54cbc3ab7e..5451b9d822 100644 --- a/lib/controllers/update-controller-base.ts +++ b/lib/controllers/update-controller-base.ts @@ -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("@"); }); } @@ -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 { + 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}`); + } } } diff --git a/lib/controllers/update-controller.ts b/lib/controllers/update-controller.ts index 82b14d64dd..873451cca0 100644 --- a/lib/controllers/update-controller.ts +++ b/lib/controllers/update-controller.ts @@ -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, @@ -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) { @@ -58,8 +60,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon public async shouldUpdate({ projectDir, version }: { projectDir: string, version?: string }): Promise { 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); @@ -92,8 +93,7 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon } private async updateProject(projectData: IProjectData, version: string): Promise { - 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); @@ -208,6 +208,19 @@ export class UpdateController extends UpdateControllerBase implements IUpdateCon return template; } + + private async getTemplateManifest(projectData: IProjectData, version: string): Promise { + 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);