From d2eda5cf51e00b4a121e1e486670a8d96ccb392a Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 15 Aug 2022 09:33:23 +0200 Subject: [PATCH] Extracted oembed service to separate package refs https://github.com/TryGhost/Toolbox/issues/363 - the oembed service is completely standalone and could do with some individual unit tests - moving it out to a package allows us to draw the boundaries better and allows us to remove some dependencies from the core package.json --- .../core/core/server/api/endpoints/oembed.js | 2 +- ghost/core/package.json | 11 +---- ghost/oembed-service/.eslintrc.js | 6 +++ ghost/oembed-service/README.md | 23 ++++++++++ ghost/oembed-service/index.js | 1 + .../lib/oembed-service.js} | 0 ghost/oembed-service/package.json | 42 +++++++++++++++++++ ghost/oembed-service/test/.eslintrc.js | 6 +++ ghost/oembed-service/test/hello.test.js | 7 ++++ 9 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 ghost/oembed-service/.eslintrc.js create mode 100644 ghost/oembed-service/README.md create mode 100644 ghost/oembed-service/index.js rename ghost/{core/core/server/services/oembed.js => oembed-service/lib/oembed-service.js} (100%) create mode 100644 ghost/oembed-service/package.json create mode 100644 ghost/oembed-service/test/.eslintrc.js create mode 100644 ghost/oembed-service/test/hello.test.js diff --git a/ghost/core/core/server/api/endpoints/oembed.js b/ghost/core/core/server/api/endpoints/oembed.js index f04ee161d2..f9ac28de36 100644 --- a/ghost/core/core/server/api/endpoints/oembed.js +++ b/ghost/core/core/server/api/endpoints/oembed.js @@ -1,7 +1,7 @@ const config = require('../../../shared/config'); const externalRequest = require('../../lib/request-external'); -const OEmbed = require('../../services/oembed'); +const OEmbed = require('@tryghost/oembed-service'); const oembed = new OEmbed({config, externalRequest}); const NFT = require('../../services/nft-oembed'); diff --git a/ghost/core/package.json b/ghost/core/package.json index 493048aef5..5fdb8a5f4d 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -100,6 +100,7 @@ "@tryghost/mw-vhost": "0.0.0", "@tryghost/nodemailer": "0.3.25", "@tryghost/nql": "0.9.2", + "@tryghost/oembed-service": "0.0.0", "@tryghost/package-json": "0.0.0", "@tryghost/pretty-cli": "1.2.30", "@tryghost/promise": "0.1.21", @@ -159,15 +160,6 @@ "knex-migrator": "5.0.3", "lodash": "4.17.21", "luxon": "3.0.1", - "metascraper": "5.30.1", - "metascraper-author": "5.29.15", - "metascraper-description": "5.29.15", - "metascraper-image": "5.29.15", - "metascraper-logo": "5.29.15", - "metascraper-logo-favicon": "5.30.1", - "metascraper-publisher": "5.29.15", - "metascraper-title": "5.29.15", - "metascraper-url": "5.29.15", "moment": "2.24.0", "moment-timezone": "0.5.23", "multer": "1.4.4", @@ -181,7 +173,6 @@ "sanitize-html": "2.7.1", "semver": "7.3.7", "stoppable": "1.1.0", - "tough-cookie": "4.0.0", "uuid": "8.3.2", "xml": "1.0.1" }, diff --git a/ghost/oembed-service/.eslintrc.js b/ghost/oembed-service/.eslintrc.js new file mode 100644 index 0000000000..c9c1bcb522 --- /dev/null +++ b/ghost/oembed-service/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/node' + ] +}; diff --git a/ghost/oembed-service/README.md b/ghost/oembed-service/README.md new file mode 100644 index 0000000000..be30a645e9 --- /dev/null +++ b/ghost/oembed-service/README.md @@ -0,0 +1,23 @@ +# Oembed Service + +Oembed service for Ghost + + +## Usage + + +## Develop + +This is a monorepo package. + +Follow the instructions for the top-level repo. +1. `git clone` this repo & `cd` into it as usual +2. Run `yarn` to install top-level dependencies. + + + +## Test + +- `yarn lint` run just eslint +- `yarn test` run lint and tests + diff --git a/ghost/oembed-service/index.js b/ghost/oembed-service/index.js new file mode 100644 index 0000000000..6e6e4c3bbd --- /dev/null +++ b/ghost/oembed-service/index.js @@ -0,0 +1 @@ +module.exports = require('./lib/oembed-service'); diff --git a/ghost/core/core/server/services/oembed.js b/ghost/oembed-service/lib/oembed-service.js similarity index 100% rename from ghost/core/core/server/services/oembed.js rename to ghost/oembed-service/lib/oembed-service.js diff --git a/ghost/oembed-service/package.json b/ghost/oembed-service/package.json new file mode 100644 index 0000000000..efa840b179 --- /dev/null +++ b/ghost/oembed-service/package.json @@ -0,0 +1,42 @@ +{ + "name": "@tryghost/oembed-service", + "version": "0.0.0", + "repository": "https://github.com/TryGhost/Ghost/tree/main/packages/oembed-service", + "author": "Ghost Foundation", + "private": true, + "main": "index.js", + "scripts": { + "dev": "echo \"Implement me!\"", + "test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", + "lint:code": "eslint *.js lib/ --ext .js --cache", + "lint": "yarn lint:code && yarn lint:test", + "lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache" + }, + "files": [ + "index.js", + "lib" + ], + "devDependencies": { + "c8": "7.12.0", + "mocha": "10.0.0", + "should": "13.2.3", + "sinon": "14.0.0" + }, + "dependencies": { + "@tryghost/errors": "1.2.15", + "@tryghost/logging": "2.2.4", + "@tryghost/tpl": "0.1.18", + "lodash": "4.17.21", + "metascraper": "5.30.1", + "metascraper-author": "5.29.15", + "metascraper-description": "5.29.15", + "metascraper-image": "5.29.15", + "metascraper-logo": "5.29.15", + "metascraper-logo-favicon": "5.30.1", + "metascraper-publisher": "5.29.15", + "metascraper-title": "5.29.15", + "metascraper-url": "5.29.15", + "oembed-parser": "1.4.9", + "tough-cookie": "4.0.0" + } +} diff --git a/ghost/oembed-service/test/.eslintrc.js b/ghost/oembed-service/test/.eslintrc.js new file mode 100644 index 0000000000..829b601eb0 --- /dev/null +++ b/ghost/oembed-service/test/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ['ghost'], + extends: [ + 'plugin:ghost/test' + ] +}; diff --git a/ghost/oembed-service/test/hello.test.js b/ghost/oembed-service/test/hello.test.js new file mode 100644 index 0000000000..3f9e671446 --- /dev/null +++ b/ghost/oembed-service/test/hello.test.js @@ -0,0 +1,7 @@ +const assert = require('assert'); + +describe('Hello world', function () { + it('Runs a test', function () { + assert.equal('hello', 'hello'); + }); +});