From 782de52678294fe85b3419f6ac2eece40ca8e135 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 7 Jul 2021 21:41:34 +0100 Subject: [PATCH] Moved labs utlity to shared - This isn't really a "service" - it's a set of utilities for working with labs flags - It's also required all over the place, and doesn't require anything that isn't shared - Therefore, it should live in shared --- core/frontend/services/proxy.js | 2 +- core/frontend/services/theme-engine/middleware.js | 2 +- core/server/api/canary/members.js | 2 +- core/server/api/canary/utils/serializers/input/settings.js | 2 +- .../server/api/canary/utils/serializers/output/utils/clean.js | 2 +- core/server/data/importer/importers/data/settings.js | 2 +- core/server/models/settings.js | 2 +- core/server/services/mega/mega.js | 2 +- core/server/services/members/importer/importer.js | 2 +- core/server/services/members/middleware.js | 2 +- core/server/services/public-config/config.js | 2 +- core/server/web/shared/middlewares/labs.js | 2 +- core/{server/services => shared}/labs.js | 4 ++-- test/api-acceptance/admin/members.test.js | 2 +- test/regression/api/canary/admin/members.test.js | 2 +- test/regression/api/canary/admin/members_signin_url.test.js | 2 +- test/regression/api/canary/content/posts.test.js | 2 +- test/regression/api/v2/content/posts.test.js | 2 +- test/regression/api/v3/admin/members.test.js | 2 +- test/regression/api/v3/admin/members_signin_url.test.js | 2 +- test/regression/api/v3/content/posts.test.js | 2 +- test/unit/helpers/cancel_link.test.js | 2 +- test/unit/helpers/match.test.js | 2 +- test/unit/services/labs.test.js | 2 +- test/unit/services/routing/helpers/context.test.js | 2 +- test/utils/fixture-utils.js | 2 +- 26 files changed, 27 insertions(+), 27 deletions(-) rename core/{server/services => shared}/labs.js (96%) diff --git a/core/frontend/services/proxy.js b/core/frontend/services/proxy.js index 9c8e0cb6aa..3061208736 100644 --- a/core/frontend/services/proxy.js +++ b/core/frontend/services/proxy.js @@ -47,7 +47,7 @@ module.exports = { }, // Labs utils for enabling/disabling helpers - labs: require('../../server/services/labs'), + labs: require('../../shared/labs'), // Things required from data/meta metaData: require('../meta'), diff --git a/core/frontend/services/theme-engine/middleware.js b/core/frontend/services/theme-engine/middleware.js index ecb65d4fa8..0adcacb06c 100644 --- a/core/frontend/services/theme-engine/middleware.js +++ b/core/frontend/services/theme-engine/middleware.js @@ -5,7 +5,7 @@ const {api} = require('../proxy'); const errors = require('@tryghost/errors'); const tpl = require('@tryghost/tpl'); const settingsCache = require('../../../shared/settings-cache'); -const labs = require('../../../server/services/labs'); +const labs = require('../../../shared/labs'); const activeTheme = require('./active'); const preview = require('./preview'); diff --git a/core/server/api/canary/members.js b/core/server/api/canary/members.js index d82509e317..da309d5fab 100644 --- a/core/server/api/canary/members.js +++ b/core/server/api/canary/members.js @@ -5,7 +5,7 @@ const moment = require('moment-timezone'); const errors = require('@tryghost/errors'); const models = require('../../models'); const membersService = require('../../services/members'); -const labsService = require('../../services/labs'); +const labsService = require('../../../shared/labs'); const settingsCache = require('../../../shared/settings-cache'); const i18n = require('../../../shared/i18n'); diff --git a/core/server/api/canary/utils/serializers/input/settings.js b/core/server/api/canary/utils/serializers/input/settings.js index 67e5663622..2c910d30df 100644 --- a/core/server/api/canary/utils/serializers/input/settings.js +++ b/core/server/api/canary/utils/serializers/input/settings.js @@ -2,7 +2,7 @@ const _ = require('lodash'); const url = require('./utils/url'); const typeGroupMapper = require('../../../../shared/serializers/input/utils/settings-filter-type-group-mapper'); const settingsCache = require('../../../../../../shared/settings-cache'); -const {WRITABLE_KEYS_ALLOWLIST} = require('../../../../../services/labs'); +const {WRITABLE_KEYS_ALLOWLIST} = require('../../../../../../shared/labs'); const DEPRECATED_SETTINGS = [ 'bulk_email_settings', diff --git a/core/server/api/canary/utils/serializers/output/utils/clean.js b/core/server/api/canary/utils/serializers/output/utils/clean.js index 75c23e559c..c5a1b36da7 100644 --- a/core/server/api/canary/utils/serializers/output/utils/clean.js +++ b/core/server/api/canary/utils/serializers/output/utils/clean.js @@ -1,6 +1,6 @@ const _ = require('lodash'); const localUtils = require('../../../index'); -const labsService = require('../../../../../../services/labs'); +const labsService = require('../../../../../../../shared/labs'); const tag = (attrs, frame) => { if (localUtils.isContentAPI(frame)) { diff --git a/core/server/data/importer/importers/data/settings.js b/core/server/data/importer/importers/data/settings.js index 460822b00e..1af65cf8c0 100644 --- a/core/server/data/importer/importers/data/settings.js +++ b/core/server/data/importer/importers/data/settings.js @@ -7,7 +7,7 @@ const models = require('../../../../models'); const defaultSettings = require('../../../schema').defaultSettings; const keyGroupMapper = require('../../../../api/shared/serializers/input/utils/settings-key-group-mapper'); const keyTypeMapper = require('../../../../api/shared/serializers/input/utils/settings-key-type-mapper'); -const {WRITABLE_KEYS_ALLOWLIST} = require('../../../../services/labs'); +const {WRITABLE_KEYS_ALLOWLIST} = require('../../../../../shared/labs'); const labsDefaults = JSON.parse(defaultSettings.labs.labs.defaultValue); const ignoredSettings = ['slack_url', 'members_from_address', 'members_support_address']; diff --git a/core/server/models/settings.js b/core/server/models/settings.js index 261c80b3b1..abe1317ac7 100644 --- a/core/server/models/settings.js +++ b/core/server/models/settings.js @@ -9,7 +9,7 @@ const i18n = require('../../shared/i18n'); const errors = require('@tryghost/errors'); const validator = require('@tryghost/validator'); const urlUtils = require('../../shared/url-utils'); -const {WRITABLE_KEYS_ALLOWLIST} = require('../services/labs'); +const {WRITABLE_KEYS_ALLOWLIST} = require('../../shared/labs'); const internalContext = {context: {internal: true}}; let Settings; diff --git a/core/server/services/mega/mega.js b/core/server/services/mega/mega.js index 260e48f667..cd1fa001bc 100644 --- a/core/server/services/mega/mega.js +++ b/core/server/services/mega/mega.js @@ -17,7 +17,7 @@ const db = require('../../data/db'); const models = require('../../models'); const postEmailSerializer = require('./post-email-serializer'); const {getSegmentsFromHtml} = require('./segment-parser'); -const labs = require('../labs'); +const labs = require('../../../shared/labs'); // Used to listen to email.added and email.edited model events originally, I think to offload this - ideally would just use jobs now if possible const events = require('../../lib/common/events'); diff --git a/core/server/services/members/importer/importer.js b/core/server/services/members/importer/importer.js index 84d9ae3f32..d460f95ed9 100644 --- a/core/server/services/members/importer/importer.js +++ b/core/server/services/members/importer/importer.js @@ -7,7 +7,7 @@ const urlUtils = require('../../../../shared/url-utils'); const db = require('../../../data/db'); const emailTemplate = require('./email-template'); const jobsService = require('../../jobs'); -const labsService = require('../../labs'); +const labsService = require('../../../../shared/labs'); const ghostMailer = new GhostMailer(); module.exports = class MembersCSVImporter { diff --git a/core/server/services/members/middleware.js b/core/server/services/members/middleware.js index 2d2203ab84..cf533ea87a 100644 --- a/core/server/services/members/middleware.js +++ b/core/server/services/members/middleware.js @@ -5,7 +5,7 @@ const urlUtils = require('../../../shared/url-utils'); const ghostVersion = require('@tryghost/version'); const settingsCache = require('../../../shared/settings-cache'); const {formattedMemberResponse} = require('./utils'); -const labsService = require('../labs'); +const labsService = require('../../../shared/labs'); const config = require('../../../shared/config'); // @TODO: This piece of middleware actually belongs to the frontend, not to the member app diff --git a/core/server/services/public-config/config.js b/core/server/services/public-config/config.js index 8a05f09cf0..6adbf45cb1 100644 --- a/core/server/services/public-config/config.js +++ b/core/server/services/public-config/config.js @@ -1,6 +1,6 @@ const {isPlainObject} = require('lodash'); const config = require('../../../shared/config'); -const labs = require('../labs'); +const labs = require('../../../shared/labs'); const ghostVersion = require('@tryghost/version'); module.exports = function getConfigProperties() { diff --git a/core/server/web/shared/middlewares/labs.js b/core/server/web/shared/middlewares/labs.js index 0c1b926f76..c67e40bb0f 100644 --- a/core/server/web/shared/middlewares/labs.js +++ b/core/server/web/shared/middlewares/labs.js @@ -1,5 +1,5 @@ const errors = require('@tryghost/errors'); -const labsUtil = require('../../../services/labs'); +const labsUtil = require('../../../../shared/labs'); const labs = flag => (req, res, next) => { if (labsUtil.isSet(flag) === true) { diff --git a/core/server/services/labs.js b/core/shared/labs.js similarity index 96% rename from core/server/services/labs.js rename to core/shared/labs.js index 8d2fe5d993..fd12c4ce76 100644 --- a/core/server/services/labs.js +++ b/core/shared/labs.js @@ -5,8 +5,8 @@ const errors = require('@tryghost/errors'); const logging = require('@tryghost/logging'); const tpl = require('@tryghost/tpl'); -const settingsCache = require('../../shared/settings-cache'); -const config = require('../../shared/config'); +const settingsCache = require('./settings-cache'); +const config = require('./config'); const messages = { errorMessage: 'The \\{\\{{helperName}\\}\\} helper is not available.', diff --git a/test/api-acceptance/admin/members.test.js b/test/api-acceptance/admin/members.test.js index 9e2ef79f5a..9eb528fee3 100644 --- a/test/api-acceptance/admin/members.test.js +++ b/test/api-acceptance/admin/members.test.js @@ -5,7 +5,7 @@ const sinon = require('sinon'); const testUtils = require('../../utils'); const localUtils = require('./utils'); const config = require('../../../core/shared/config'); -const labs = require('../../../core/server/services/labs'); +const labs = require('../../../core/shared/labs'); const Papa = require('papaparse'); const moment = require('moment-timezone'); diff --git a/test/regression/api/canary/admin/members.test.js b/test/regression/api/canary/admin/members.test.js index d62723942c..ff02373971 100644 --- a/test/regression/api/canary/admin/members.test.js +++ b/test/regression/api/canary/admin/members.test.js @@ -6,7 +6,7 @@ const sinon = require('sinon'); const testUtils = require('../../../../utils'); const localUtils = require('./utils'); const config = require('../../../../../core/shared/config'); -const labs = require('../../../../../core/server/services/labs'); +const labs = require('../../../../../core/shared/labs'); const mailService = require('../../../../../core/server/services/mail'); const ghost = testUtils.startGhost; diff --git a/test/regression/api/canary/admin/members_signin_url.test.js b/test/regression/api/canary/admin/members_signin_url.test.js index bb951d1d56..8eb8c5d9e3 100644 --- a/test/regression/api/canary/admin/members_signin_url.test.js +++ b/test/regression/api/canary/admin/members_signin_url.test.js @@ -5,7 +5,7 @@ const sinon = require('sinon'); const testUtils = require('../../../../utils'); const localUtils = require('./utils'); const config = require('../../../../../core/shared/config'); -const labs = require('../../../../../core/server/services/labs'); +const labs = require('../../../../../core/shared/labs'); const ghost = testUtils.startGhost; diff --git a/test/regression/api/canary/content/posts.test.js b/test/regression/api/canary/content/posts.test.js index a8e7f57d28..512e7a27f0 100644 --- a/test/regression/api/canary/content/posts.test.js +++ b/test/regression/api/canary/content/posts.test.js @@ -3,7 +3,7 @@ const sinon = require('sinon'); const moment = require('moment'); const supertest = require('supertest'); const _ = require('lodash'); -const labs = require('../../../../../core/server/services/labs'); +const labs = require('../../../../../core/shared/labs'); const testUtils = require('../../../../utils'); const localUtils = require('./utils'); const configUtils = require('../../../../utils/configUtils'); diff --git a/test/regression/api/v2/content/posts.test.js b/test/regression/api/v2/content/posts.test.js index ef3fe80dc3..6db1eaf5dd 100644 --- a/test/regression/api/v2/content/posts.test.js +++ b/test/regression/api/v2/content/posts.test.js @@ -5,7 +5,7 @@ const moment = require('moment'); const supertest = require('supertest'); const _ = require('lodash'); const cheerio = require('cheerio'); -const labs = require('../../../../../core/server/services/labs'); +const labs = require('../../../../../core/shared/labs'); const testUtils = require('../../../../utils'); const localUtils = require('./utils'); const configUtils = require('../../../../utils/configUtils'); diff --git a/test/regression/api/v3/admin/members.test.js b/test/regression/api/v3/admin/members.test.js index e8999cba5e..c8075b4aa5 100644 --- a/test/regression/api/v3/admin/members.test.js +++ b/test/regression/api/v3/admin/members.test.js @@ -6,7 +6,7 @@ const sinon = require('sinon'); const testUtils = require('../../../../utils'); const localUtils = require('./utils'); const config = require('../../../../../core/shared/config'); -const labs = require('../../../../../core/server/services/labs'); +const labs = require('../../../../../core/shared/labs'); const mailService = require('../../../../../core/server/services/mail'); const ghost = testUtils.startGhost; diff --git a/test/regression/api/v3/admin/members_signin_url.test.js b/test/regression/api/v3/admin/members_signin_url.test.js index bb951d1d56..8eb8c5d9e3 100644 --- a/test/regression/api/v3/admin/members_signin_url.test.js +++ b/test/regression/api/v3/admin/members_signin_url.test.js @@ -5,7 +5,7 @@ const sinon = require('sinon'); const testUtils = require('../../../../utils'); const localUtils = require('./utils'); const config = require('../../../../../core/shared/config'); -const labs = require('../../../../../core/server/services/labs'); +const labs = require('../../../../../core/shared/labs'); const ghost = testUtils.startGhost; diff --git a/test/regression/api/v3/content/posts.test.js b/test/regression/api/v3/content/posts.test.js index d28f96e952..c4b5e66566 100644 --- a/test/regression/api/v3/content/posts.test.js +++ b/test/regression/api/v3/content/posts.test.js @@ -3,7 +3,7 @@ const sinon = require('sinon'); const moment = require('moment'); const supertest = require('supertest'); const _ = require('lodash'); -const labs = require('../../../../../core/server/services/labs'); +const labs = require('../../../../../core/shared/labs'); const testUtils = require('../../../../utils'); const localUtils = require('./utils'); const configUtils = require('../../../../utils/configUtils'); diff --git a/test/unit/helpers/cancel_link.test.js b/test/unit/helpers/cancel_link.test.js index cb01855679..3b24824fd3 100644 --- a/test/unit/helpers/cancel_link.test.js +++ b/test/unit/helpers/cancel_link.test.js @@ -2,7 +2,7 @@ const should = require('should'); const sinon = require('sinon'); const hbs = require('../../../core/frontend/services/theme-engine/engine'); const helpers = require('../../../core/frontend/helpers'); -const labs = require('../../../core/server/services/labs'); +const labs = require('../../../core/shared/labs'); const configUtils = require('../../utils/configUtils'); describe('{{cancel_link}} helper', function () { diff --git a/test/unit/helpers/match.test.js b/test/unit/helpers/match.test.js index 1930f0b52e..19f0329479 100644 --- a/test/unit/helpers/match.test.js +++ b/test/unit/helpers/match.test.js @@ -2,7 +2,7 @@ const should = require('should'); const sinon = require('sinon'); const _ = require('lodash'); const helpers = require('../../../core/frontend/helpers'); -const labs = require('../../../core/server/services/labs'); +const labs = require('../../../core/shared/labs'); const handlebars = require('../../../core/frontend/services/theme-engine/engine').handlebars; describe('Match helper', function () { diff --git a/test/unit/services/labs.test.js b/test/unit/services/labs.test.js index f64ba79224..a5db33ec75 100644 --- a/test/unit/services/labs.test.js +++ b/test/unit/services/labs.test.js @@ -2,7 +2,7 @@ const should = require('should'); const sinon = require('sinon'); const configUtils = require('../../utils/configUtils'); -const labs = require('../../../core/server/services/labs'); +const labs = require('../../../core/shared/labs'); const settingsCache = require('../../../core/shared/settings-cache'); describe('Labs Service', function () { diff --git a/test/unit/services/routing/helpers/context.test.js b/test/unit/services/routing/helpers/context.test.js index 0f9ec012c1..f6ab2cc59d 100644 --- a/test/unit/services/routing/helpers/context.test.js +++ b/test/unit/services/routing/helpers/context.test.js @@ -3,7 +3,7 @@ const sinon = require('sinon'); const _ = require('lodash'); const testUtils = require('../../../../utils'); const helpers = require('../../../../../core/frontend/services/routing/helpers'); -const labs = require('../../../../../core/server/services/labs'); +const labs = require('../../../../../core/shared/labs'); describe('Contexts', function () { let req; diff --git a/test/utils/fixture-utils.js b/test/utils/fixture-utils.js index 77b57dcea7..40d285811a 100644 --- a/test/utils/fixture-utils.js +++ b/test/utils/fixture-utils.js @@ -14,7 +14,7 @@ const fixtureUtils = require('../../core/server/data/schema/fixtures/utils'); const emailAnalyticsService = require('../../core/server/services/email-analytics'); const permissions = require('../../core/server/services/permissions'); const settingsService = require('../../core/server/services/settings'); -const labsService = require('../../core/server/services/labs'); +const labsService = require('../../core/shared/labs'); // Other Test Utilities const context = require('./fixtures/context');