0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-25 02:31:59 -05:00

Replaced ghost-version.js with @tryghost/version

no issue
Part of the effort to break up the Ghost codebase into smaller, decoupled modules.
This commit is contained in:
Sam Lord 2021-06-16 09:36:58 +01:00
parent 8ea577b58b
commit 24332c3d24
16 changed files with 21 additions and 111 deletions

View file

@ -1,5 +1,5 @@
const config = require('./core/shared/config');
const ghostVersion = require('./core/server/lib/ghost-version');
const ghostVersion = require('@tryghost/version');
/**
* knex-migrator can be used via CLI or within the application

View file

@ -267,7 +267,7 @@ async function bootGhost() {
// Version is required by sentry & Migration config & so is fundamental to booting
// However, it involves reading package.json so its slow & it's here for visibility on that slowness
debug('Begin: Load version info');
require('./server/lib/ghost-version');
require('@tryghost/version');
debug('End: Load version info');
// Sentry must be initialised early, but requires config

View file

@ -2,7 +2,7 @@ const _ = require('lodash');
const Promise = require('bluebird');
const db = require('../../data/db');
const commands = require('../schema').commands;
const ghostVersion = require('../../lib/ghost-version');
const ghostVersion = require('@tryghost/version');
const i18n = require('../../../shared/i18n');
const errors = require('@tryghost/errors');

View file

@ -1,27 +0,0 @@
const path = require('path');
const semver = require('semver');
const rootUtils = require('@tryghost/root-utils');
const packageInfo = require(path.join(rootUtils.getProcessRoot(), 'package.json'));
const version = packageInfo.version;
const plainVersion = version.match(/^(\d+\.)?(\d+\.)?(\d+)/)[0];
let _private = {};
_private.compose = function compose(type) {
switch (type) {
case 'pre':
return plainVersion + '-' + semver.prerelease(version).join('.');
default:
return version;
}
};
// major.minor
module.exports.safe = version.match(/^(\d+\.)?(\d+)/)[0];
// major.minor.patch-{prerelease}
module.exports.full = semver.prerelease(version) ? _private.compose('pre') : plainVersion;
// original string in package.json (can contain pre-release and build suffix)
module.exports.original = version;

View file

@ -2,7 +2,7 @@ const got = require('got');
const _ = require('lodash');
const validator = require('@tryghost/validator');
const errors = require('@tryghost/errors');
const ghostVersion = require('./ghost-version');
const ghostVersion = require('@tryghost/version');
const defaultOptions = {
headers: {

View file

@ -2,7 +2,7 @@ const _ = require('lodash');
const logging = require('@tryghost/logging');
const membersService = require('./service');
const urlUtils = require('../../../shared/url-utils');
const ghostVersion = require('../../lib/ghost-version');
const ghostVersion = require('@tryghost/version');
const settingsCache = require('../settings/cache');
const {formattedMemberResponse} = require('./utils');
const labsService = require('../labs');

View file

@ -10,7 +10,7 @@ const logging = require('@tryghost/logging');
const urlUtils = require('../../../shared/url-utils');
const settingsCache = require('../settings/cache');
const config = require('../../../shared/config');
const ghostVersion = require('../../lib/ghost-version');
const ghostVersion = require('@tryghost/version');
const _ = require('lodash');
const membersConfig = new MembersConfigProvider({

View file

@ -1,6 +1,6 @@
const settingsCache = require('../settings/cache');
const i18n = require('../../../shared/i18n');
const ghostVersion = require('../../lib/ghost-version');
const ghostVersion = require('@tryghost/version');
const Notifications = require('./notifications');
module.exports.notifications = new Notifications({settingsCache, i18n, ghostVersion});

View file

@ -1,7 +1,7 @@
const {isPlainObject} = require('lodash');
const config = require('../../../shared/config');
const labs = require('../labs');
const ghostVersion = require('../../lib/ghost-version');
const ghostVersion = require('@tryghost/version');
module.exports = function getConfigProperties() {
const configProperties = {

View file

@ -1,4 +1,4 @@
const ghostVersion = require('../../lib/ghost-version');
const ghostVersion = require('@tryghost/version');
const settingsCache = require('../settings/cache');
const config = require('../../../shared/config');
const urlUtils = require('../../../shared/url-utils');

View file

@ -8,7 +8,7 @@ const urlUtils = require('./../shared/url-utils');
const i18n = require('../shared/i18n');
const logging = require('@tryghost/logging');
const request = require('./lib/request');
const ghostVersion = require('./lib/ghost-version');
const ghostVersion = require('@tryghost/version');
const UpdateCheckService = require('@tryghost/update-check-service');
const ghostMailer = new GhostMailer();

View file

@ -1,4 +1,4 @@
const ghostVersion = require('../../../lib/ghost-version');
const ghostVersion = require('@tryghost/version');
const bridge = require('../../../../bridge');
// ### GhostLocals Middleware

View file

@ -77,6 +77,7 @@
"@tryghost/update-check-service": "0.1.0",
"@tryghost/url-utils": "1.1.4",
"@tryghost/validator": "0.1.0",
"@tryghost/version": "0.1.0",
"@tryghost/vhost-middleware": "1.0.15",
"@tryghost/zip": "1.1.14",
"amperize": "0.6.1",

View file

@ -3,7 +3,7 @@ const sinon = require('sinon');
const testUtils = require('../../utils');
const _ = require('lodash');
const ghostVersion = require('../../../core/server/lib/ghost-version');
const ghostVersion = require('@tryghost/version');
const {exportedBodyLatest} = require('../../utils/fixtures/export/body-generator');
// Stuff we are testing

View file

@ -1,72 +0,0 @@
const should = require('should');
const rewire = require('rewire');
const mockUtils = require('../../utils/mocks');
let ghostVersionUtils;
let version;
describe('Utils: Ghost Version', function () {
const beforeEachIt = function be() {
mockUtils.modules.mockNonExistentModule(/package\.json/, {version: version});
ghostVersionUtils = rewire('../../../core/server/lib/ghost-version');
};
afterEach(function () {
mockUtils.modules.unmockNonExistentModule(/package\.json/);
});
it('default', function () {
version = '1.10.0';
beforeEachIt();
ghostVersionUtils.full.should.eql(version);
ghostVersionUtils.original.should.eql(version);
ghostVersionUtils.safe.should.eql('1.10');
});
it('pre-release', function () {
version = '1.11.1-beta';
beforeEachIt();
ghostVersionUtils.full.should.eql(version);
ghostVersionUtils.original.should.eql(version);
ghostVersionUtils.safe.should.eql('1.11');
});
it('pre-release .1', function () {
version = '1.11.1-alpha.1';
beforeEachIt();
ghostVersionUtils.full.should.eql(version);
ghostVersionUtils.original.should.eql(version);
ghostVersionUtils.safe.should.eql('1.11');
});
it('build', function () {
version = '1.11.1+build';
beforeEachIt();
ghostVersionUtils.full.should.eql('1.11.1');
ghostVersionUtils.original.should.eql(version);
ghostVersionUtils.safe.should.eql('1.11');
});
it('mixed', function () {
version = '1.11.1-pre+build.1';
beforeEachIt();
ghostVersionUtils.full.should.eql('1.11.1-pre');
ghostVersionUtils.original.should.eql(version);
ghostVersionUtils.safe.should.eql('1.11');
});
it('mixed 1', function () {
version = '1.11.1-beta.12+build.2';
beforeEachIt();
ghostVersionUtils.full.should.eql('1.11.1-beta.12');
ghostVersionUtils.original.should.eql(version);
ghostVersionUtils.safe.should.eql('1.11');
});
});

View file

@ -1055,6 +1055,14 @@
moment-timezone "0.5.23"
validator "7.2.0"
"@tryghost/version@0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@tryghost/version/-/version-0.1.0.tgz#2d1ec5dd19206a5f7ec0f283588fa716980c666c"
integrity sha512-7IvYLn0IFRFNK61IeHLMHb1cPDbD/zfRMlJqUe9kLTFRlLG6D29390VnkXWHC/W+K4frXdP1kfAglXXfOsunmg==
dependencies:
"@tryghost/root-utils" "^0.3.0"
semver "^7.3.5"
"@tryghost/vhost-middleware@1.0.15":
version "1.0.15"
resolved "https://registry.yarnpkg.com/@tryghost/vhost-middleware/-/vhost-middleware-1.0.15.tgz#6f5e7e018fe6d9b09b0f2b7f5294f8133398cbd1"