Skip to content

Commit d1f7345

Browse files
committed
chore(utils): improve error message for incompatible ghost zip
refs TryGhost#681 refs TryGhost#587 Give the user more information why the installation of the zip file failed. Renders the required and the current installed CLI version and the command to run to solve the issue.
1 parent 981da23 commit d1f7345

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/utils/version-from-zip.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const errors = require('../errors');
55
const semver = require('semver');
66
const AdmZip = require('adm-zip');
77
const cliPackage = require('../../package.json');
8+
const chalk = require('chalk');
89

910
module.exports = function versionFromZip(zipPath, currentVersion) {
1011
if (!path.isAbsolute(zipPath)) {
@@ -40,7 +41,10 @@ module.exports = function versionFromZip(zipPath, currentVersion) {
4041
}
4142

4243
if (pkg.engines && pkg.engines.cli && !semver.satisfies(cliPackage.version, pkg.engines.cli)) {
43-
return Promise.reject(new errors.SystemError('Zip file contains a Ghost version incompatible with this version of the CLI.'));
44+
return Promise.reject(new errors.SystemError({
45+
message: 'Zip file contains a Ghost version incompatible with this version of the CLI.',
46+
help: `Required: v${pkg.engines.cli}, current: v${cliPackage.version}\n\n Please run ${chalk.green('sudo npm install -g ghost-cli@latest')} and try again.`
47+
}));
4448
}
4549

4650
if (currentVersion && semver.lt(pkg.version, currentVersion)) {

test/unit/utils/version-from-zip-spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe('Unit: Utils > versionFromZip', function () {
106106
}).catch((error) => {
107107
expect(error).to.be.an.instanceof(errors.SystemError);
108108
expect(error.message).to.equal('Zip file contains a Ghost version incompatible with this version of the CLI.');
109+
expect(error.options.help).to.equal('Required: v^0.0.1, current: v1.7.0\n\n Please run \u001b[32msudo npm install -g ghost-cli@latest\u001b[39m and try again.');
109110
});
110111
});
111112

0 commit comments

Comments
 (0)