From 5dedfbe82e99afd1355a6497c18465755b93143f Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Wed, 9 Oct 2024 14:21:11 +0100 Subject: [PATCH] Lazyloaded dependencies - these dependencies do not need to be eagerly loaded so we can move them to the block of code where they are needed --- ghost/minifier/lib/Minifier.js | 8 ++++---- ghost/webmentions/lib/Mention.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ghost/minifier/lib/Minifier.js b/ghost/minifier/lib/Minifier.js index c1c2ad4b36..18cf5891a8 100644 --- a/ghost/minifier/lib/Minifier.js +++ b/ghost/minifier/lib/Minifier.js @@ -1,8 +1,6 @@ const errors = require('@tryghost/errors'); const debug = require('@tryghost/debug')('minifier'); const tpl = require('@tryghost/tpl'); -const csso = require('csso'); -const terser = require('terser'); const glob = require('tiny-glob'); const path = require('path'); const fs = require('fs').promises; @@ -53,6 +51,7 @@ class Minifier { } async minifyCSS(contents) { + const csso = require('csso'); const result = await csso.minify(contents); if (result && result.css) { return result.css; @@ -61,6 +60,7 @@ class Minifier { } async minifyJS(contents) { + const terser = require('terser'); const result = await terser.minify(contents); if (result && result.code) { return result.code; @@ -111,8 +111,8 @@ class Minifier { /** * Minify files - * - * @param {Object} globs An object in the form of + * + * @param {Object} globs An object in the form of * ```js * { * 'destination1.js': 'glob/*.js', diff --git a/ghost/webmentions/lib/Mention.js b/ghost/webmentions/lib/Mention.js index 5924510ce1..6fc029e133 100644 --- a/ghost/webmentions/lib/Mention.js +++ b/ghost/webmentions/lib/Mention.js @@ -1,7 +1,6 @@ const ObjectID = require('bson-objectid').default; const {ValidationError} = require('@tryghost/errors'); const MentionCreatedEvent = require('./MentionCreatedEvent'); -const cheerio = require('cheerio'); module.exports = class Mention { /** @type {Array} */ @@ -47,6 +46,7 @@ module.exports = class Mention { if (contentType.includes('text/html')) { try { + const cheerio = require('cheerio'); const $ = cheerio.load(html); const hasTargetUrl = $('a[href*="' + this.target.href + '"], img[src*="' + this.target.href + '"], video[src*="' + this.target.href + '"]').length > 0; this.#verified = hasTargetUrl;