Skip to content

Commit 8208fb8

Browse files
committed
Moved @tryghost/link-replacer to core folder
fix https://linear.app/ghost/issue/ENG-2384/link-replacer - this commit moves the lib code and tests to the core folder so we can colocate code in one place rather than splitting it out across packages, which increases the cognitive load and overhead
1 parent 257eca9 commit 8208fb8

File tree

16 files changed

+8
-114
lines changed

16 files changed

+8
-114
lines changed

.docker/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ COPY ghost/email-service/package.json ghost/email-service/package.json
7979
COPY ghost/html-to-plaintext/package.json ghost/html-to-plaintext/package.json
8080
COPY ghost/i18n/package.json ghost/i18n/package.json
8181
COPY ghost/job-manager/package.json ghost/job-manager/package.json
82-
COPY ghost/link-replacer/package.json ghost/link-replacer/package.json
8382
COPY ghost/members-csv/package.json ghost/members-csv/package.json
8483
COPY ghost/mw-error-handler/package.json ghost/mw-error-handler/package.json
8584
COPY ghost/mw-vhost/package.json ghost/mw-vhost/package.json

compose.yml

-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ services:
4444
- node_modules_ghost_html-to-plaintext:/home/ghost/ghost/html-to-plaintext/node_modules:delegated
4545
- node_modules_ghost_i18n:/home/ghost/ghost/i18n/node_modules:delegated
4646
- node_modules_ghost_job-manager:/home/ghost/ghost/job-manager/node_modules:delegated
47-
- node_modules_ghost_link-replacer:/home/ghost/ghost/link-replacer/node_modules:delegated
4847
- node_modules_ghost_members-csv:/home/ghost/ghost/members-csv/node_modules:delegated
4948
- node_modules_ghost_mw-error-handler:/home/ghost/ghost/mw-error-handler/node_modules:delegated
5049
- node_modules_ghost_mw-vhost:/home/ghost/ghost/mw-vhost/node_modules:delegated
@@ -190,7 +189,6 @@ volumes:
190189
node_modules_ghost_html-to-plaintext: {}
191190
node_modules_ghost_i18n: {}
192191
node_modules_ghost_job-manager: {}
193-
node_modules_ghost_link-replacer: {}
194192
node_modules_ghost_members-csv: {}
195193
node_modules_ghost_mw-error-handler: {}
196194
node_modules_ghost_mw-vhost: {}

ghost/core/core/server/services/email-service/EmailServiceWrapper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class EmailServiceWrapper {
3434
const lexicalLib = require('../../lib/lexical');
3535
const urlUtils = require('../../../shared/url-utils');
3636
const memberAttribution = require('../member-attribution');
37-
const linkReplacer = require('@tryghost/link-replacer');
37+
const linkReplacer = require('../lib/link-replacer');
3838
const linkTracking = require('../link-tracking');
3939
const audienceFeedback = require('../audience-feedback');
4040
const storageUtils = require('../../adapters/storage/utils');

ghost/link-replacer/lib/link-replacer.js renamed to ghost/core/core/server/services/lib/link-replacer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class LinkReplacer {
22
/**
33
* Replaces the links in the provided HTML
44
* @param {string} html
5-
* @param {(url: URL, originalPath: string): Promise<URL|string|false>} replaceLink
5+
* @param {(url: URL, originalPath: string) => Promise<URL|string|false>} replaceLink
66
* @param {object} options
77
* @param {string} [options.base] If you want to replace relative links, this will replace them to an absolute link and call the replaceLink method too
88
* @returns {Promise<string>}

ghost/core/core/server/services/member-attribution/OutboundLinkTagger.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const {slugify} = require('@tryghost/string');
2-
const LinkReplacer = require('@tryghost/link-replacer');
2+
const LinkReplacer = require('../lib/link-replacer');
33

44
const blockedReferrerDomains = [
55
// Facebook has some restrictions on the 'ref' attribute (max 15 chars + restricted character set) that breaks links if we add ?ref=longer-string

ghost/core/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
"@tryghost/kg-lexical-html-renderer": "1.3.5",
9999
"@tryghost/kg-mobiledoc-html-renderer": "7.1.1",
100100
"@tryghost/limit-service": "1.2.15",
101-
"@tryghost/link-replacer": "0.0.0",
102101
"@tryghost/logging": "2.4.21",
103102
"@tryghost/members-csv": "0.0.0",
104103
"@tryghost/members-offers": "0.0.0",
@@ -147,6 +146,7 @@
147146
"date-fns": "2.30.0",
148147
"dompurify": "3.2.5",
149148
"downsize": "0.0.8",
149+
"entities": "4.5.0",
150150
"express": "4.21.2",
151151
"express-brute": "1.0.1",
152152
"express-hbs": "2.5.0",
@@ -164,6 +164,7 @@
164164
"gscan": "4.48.0",
165165
"handlebars": "4.7.8",
166166
"html-to-text": "5.1.1",
167+
"html5parser": "2.0.2",
167168
"human-number": "2.0.4",
168169
"iconv-lite": "0.6.3",
169170
"image-size": "1.2.1",

ghost/link-replacer/test/LinkReplacer.test.js renamed to ghost/core/test/unit/server/services/lib/LinkReplacer.test.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const assert = require('assert/strict');
2-
const linkReplacer = require('../lib/link-replacer');
2+
const linkReplacer = require('../../../../../core/server/services/lib/link-replacer');
33
const html5parser = require('html5parser');
44
const sinon = require('sinon');
55

@@ -8,10 +8,6 @@ describe('LinkReplacementService', function () {
88
sinon.restore();
99
});
1010

11-
it('exported', function () {
12-
assert.equal(require('../index'), linkReplacer);
13-
});
14-
1511
describe('replace', function () {
1612
it('Can replace to URL', async function () {
1713
const html = '<a href="http://localhost:2368/dir/path">link</a>';

ghost/email-service/test/email-renderer.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const {EmailRenderer} = require('../');
22
const assert = require('assert/strict');
33
const cheerio = require('cheerio');
44
const {createModel, createModelClass} = require('./utils');
5-
const linkReplacer = require('@tryghost/link-replacer');
5+
const linkReplacer = require('../../core/core/server/services/lib/link-replacer');
66
const sinon = require('sinon');
77
const logging = require('@tryghost/logging');
88
const {HtmlValidate} = require('html-validate');
@@ -2701,7 +2701,7 @@ describe('Email renderer', function () {
27012701
beforeEach(function () {
27022702
renderedPost = '<p>Lexical Test</p><img class="is-light-background" src="test-dark" /><img class="is-dark-background" src="test-light" />';
27032703
labsEnabled = true; // TODO: odd default because it means we're testing the unused email-customization template
2704-
2704+
27052705
postUrl = 'http://example.com';
27062706
customSettings = {
27072707
locale: 'fr',

ghost/link-replacer/.eslintrc.js

-6
This file was deleted.

ghost/link-replacer/README.md

-23
This file was deleted.

ghost/link-replacer/index.js

-1
This file was deleted.

ghost/link-replacer/package.json

-31
This file was deleted.

ghost/link-replacer/test/.eslintrc.js

-6
This file was deleted.

ghost/link-replacer/test/benchmark.js

-14
This file was deleted.

yarn.lock

-19
Original file line numberDiff line numberDiff line change
@@ -4270,25 +4270,6 @@
42704270
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f"
42714271
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==
42724272

4273-
"@probe.gl/[email protected]":
4274-
version "4.1.0"
4275-
resolved "https://registry.yarnpkg.com/@probe.gl/bench/-/bench-4.1.0.tgz#2a0d1aa58f21874fdfb9cf49b3268cc0c169c773"
4276-
integrity sha512-4Jb1B1NHXDayWGzz4oHs3IgymdBq2AVzMUlcE428lELFqGP7nnRMqeGR/PmwElCqvYLJE39Av4QK8E64lUw/cA==
4277-
dependencies:
4278-
"@probe.gl/log" "4.1.0"
4279-
4280-
"@probe.gl/[email protected]":
4281-
version "4.1.0"
4282-
resolved "https://registry.yarnpkg.com/@probe.gl/env/-/env-4.1.0.tgz#c2af9030a8711f2d98590850aa47a5f58feef211"
4283-
integrity sha512-5ac2Jm2K72VCs4eSMsM7ykVRrV47w32xOGMvcgqn8vQdEMF9PRXyBGYEV9YbqRKWNKpNKmQJVi4AHM/fkCxs9w==
4284-
4285-
"@probe.gl/[email protected]":
4286-
version "4.1.0"
4287-
resolved "https://registry.yarnpkg.com/@probe.gl/log/-/log-4.1.0.tgz#b5501f96e3aa7f04c75a9800431314d46911cb98"
4288-
integrity sha512-r4gRReNY6f+OZEMgfWEXrAE2qJEt8rX0HsDJQXUBMoc+5H47bdB7f/5HBHAmapK8UydwPKL9wCDoS22rJ0yq7Q==
4289-
dependencies:
4290-
"@probe.gl/env" "4.1.0"
4291-
42924273
"@radix-ui/[email protected]":
42934274
version "1.0.1"
42944275
resolved "https://registry.yarnpkg.com/@radix-ui/number/-/number-1.0.1.tgz#644161a3557f46ed38a042acf4a770e826021674"

0 commit comments

Comments
 (0)