From 7f6e4688a75798b93e6808187fbee28e4eb5d785 Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 28 Apr 2021 14:16:09 +0200 Subject: [PATCH 01/14] feat(gatsby-source-wordpress):Add searchAndReplace All credits should go to @philmuze, I just cherry picked his work at https://github.com/gatsbyjs/gatsby-source-wordpress-experimental/pull/129 --- .../docs/plugin-options.md | 64 +++++++++++++++++++ .../source-nodes/create-nodes/process-node.js | 31 +++++++++ 2 files changed, 95 insertions(+) diff --git a/packages/gatsby-source-wordpress/docs/plugin-options.md b/packages/gatsby-source-wordpress/docs/plugin-options.md index c704757bcde86..71e196d66060c 100644 --- a/packages/gatsby-source-wordpress/docs/plugin-options.md +++ b/packages/gatsby-source-wordpress/docs/plugin-options.md @@ -63,6 +63,9 @@ - [presets[].presetName](#presetspresetname) - [presets[].useIf](#presetsuseif) - [presets[].options](#presetsoptions) +- [searchAndReplace](#searchandreplace) + - [searchAndReplace[].search](#searchandreplacesearch) + - [searchAndReplace[].replace](#searchandreplacereplace) ## url (**required**) @@ -1279,6 +1282,67 @@ Any valid options except for `url` and `presets`. ``` +## searchAndReplace + +An array of options to search and replace strings in nodes. See below for options. + +**Field type**: `Array` + +```js +{ + resolve: `gatsby-source-wordpress`, + options: { + searchAndReplace: [ + { + search: /https:\/\/some-url.com/, + replace: "https://some-new-url.com", + } + ], + ... + }, +} +``` + +### searchAndReplace[].search + +The regex rule used to search a terme. + +**Field type**: `String` + +```js +{ + resolve: `gatsby-source-wordpress`, + options: { + searchAndReplace: [ + { + search: /https:\/\/some-url.com/, + } + ], + ... + }, +} +``` + +### searchAndReplace[].replace + +The replacement string for each regex match. + +**Field type**: `String` + +```js +{ + resolve: `gatsby-source-wordpress`, + options: { + searchAndReplace: [ + { + replace: "https://some-new-url.com", + } + ], + ... + }, +} +``` + # Up Next :point_right: - :boat: [Migrating from other WP source plugins](./migrating-from-other-wp-source-plugins.md) diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js index e30abfa8b8b9a..45e44f6fb12e6 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js @@ -850,6 +850,36 @@ const replaceNodeHtmlLinks = ({ wpUrl, nodeString, node }) => { return nodeString } +// replaces specific string or regex with a given string from the plugin options config +const replaceNodeHtmlStrings = ({ nodeString, node, pluginOptions }) => { + if (Array.isArray(pluginOptions?.searchAndReplace)) { + pluginOptions.searchAndReplace.forEach(({ search, replace }) => { + const searchRegex = new RegExp(search, `g`) + + const stringMatches = execall(searchRegex, nodeString) + + if (stringMatches.length) { + stringMatches.forEach(({ match }) => { + if (match) { + try { + nodeString = nodeString.replace(search, replace) + } catch (e) { + console.error(e) + console.warn( + formatLogMessage( + `Failed to process search and replace string in ${node.__typename} ${node.id}` + ) + ) + } + } + }) + } + }) + } + + return nodeString +} + const processNodeString = async ({ nodeString, node, @@ -861,6 +891,7 @@ const processNodeString = async ({ replaceNodeHtmlImages, replaceFileLinks, replaceNodeHtmlLinks, + replaceNodeHtmlStrings, ] for (const nodeStringFilter of nodeStringFilters) { From 278832d8e1a9af8e3f00431857d085586dc1b372 Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 5 May 2021 14:35:33 +0200 Subject: [PATCH 02/14] !fixup Rename filter function name --- .../src/steps/source-nodes/create-nodes/process-node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js index 45e44f6fb12e6..40c972a220fa9 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js @@ -851,7 +851,7 @@ const replaceNodeHtmlLinks = ({ wpUrl, nodeString, node }) => { } // replaces specific string or regex with a given string from the plugin options config -const replaceNodeHtmlStrings = ({ nodeString, node, pluginOptions }) => { +const searchAndReplaceNodeStrings = ({ nodeString, node, pluginOptions }) => { if (Array.isArray(pluginOptions?.searchAndReplace)) { pluginOptions.searchAndReplace.forEach(({ search, replace }) => { const searchRegex = new RegExp(search, `g`) @@ -891,7 +891,7 @@ const processNodeString = async ({ replaceNodeHtmlImages, replaceFileLinks, replaceNodeHtmlLinks, - replaceNodeHtmlStrings, + searchAndReplaceNodeStrings, ] for (const nodeStringFilter of nodeStringFilters) { From 6c4194d760d4137af3042b708c2306a7a9aa6663 Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 5 May 2021 15:42:44 +0200 Subject: [PATCH 03/14] !fixup Move options definition to options schema I replaced the regex literal with a string because prettier could not handle it and Joi does not have a Literal expression type. --- .../docs/plugin-options.md | 128 +++++++++--------- .../steps/declare-plugin-options-schema.ts | 39 ++++++ 2 files changed, 103 insertions(+), 64 deletions(-) diff --git a/packages/gatsby-source-wordpress/docs/plugin-options.md b/packages/gatsby-source-wordpress/docs/plugin-options.md index 71e196d66060c..5261aa182c350 100644 --- a/packages/gatsby-source-wordpress/docs/plugin-options.md +++ b/packages/gatsby-source-wordpress/docs/plugin-options.md @@ -38,6 +38,9 @@ - [schema.requestConcurrency](#schemarequestconcurrency) - [schema.previewRequestConcurrency](#schemapreviewrequestconcurrency) - [excludeFieldNames](#excludefieldnames) +- [searchAndReplace](#searchandreplace) + - [searchAndReplace[].search](#searchandreplacesearch) + - [searchAndReplace[].replace](#searchandreplacereplace) - [html](#html) - [html.useGatsbyImage](#htmlusegatsbyimage) - [html.imageMaxWidth](#htmlimagemaxwidth) @@ -63,9 +66,6 @@ - [presets[].presetName](#presetspresetname) - [presets[].useIf](#presetsuseif) - [presets[].options](#presetsoptions) -- [searchAndReplace](#searchandreplace) - - [searchAndReplace[].search](#searchandreplacesearch) - - [searchAndReplace[].replace](#searchandreplacereplace) ## url (**required**) @@ -781,6 +781,67 @@ A list of field names to globally exclude from the ingested schema. ``` +## searchAndReplace + +An array of options to search and replace strings in nodes. See below for options. + +**Field type**: `Array` + +```js +{ + resolve: `gatsby-source-wordpress`, + options: { + searchAndReplace: [ + { + search: "https://some-url.com", + replace: "https://some-new-url.com", + }, + ], + }, +} + +``` + +### searchAndReplace[].search + +The regex rule used to search a terme. + +**Field type**: `String` + +```js +{ + resolve: `gatsby-source-wordpress`, + options: { + searchAndReplace: [ + { + search: "https://some-url.com", + }, + ], + }, +} + +``` + +### searchAndReplace[].replace + +The replacement string for each regex match. + +**Field type**: `String` + +```js +{ + resolve: `gatsby-source-wordpress`, + options: { + searchAndReplace: [ + { + replace: "https://some-new-url.com", + }, + ], + }, +} + +``` + ## html Options related to html field processing. @@ -1282,67 +1343,6 @@ Any valid options except for `url` and `presets`. ``` -## searchAndReplace - -An array of options to search and replace strings in nodes. See below for options. - -**Field type**: `Array` - -```js -{ - resolve: `gatsby-source-wordpress`, - options: { - searchAndReplace: [ - { - search: /https:\/\/some-url.com/, - replace: "https://some-new-url.com", - } - ], - ... - }, -} -``` - -### searchAndReplace[].search - -The regex rule used to search a terme. - -**Field type**: `String` - -```js -{ - resolve: `gatsby-source-wordpress`, - options: { - searchAndReplace: [ - { - search: /https:\/\/some-url.com/, - } - ], - ... - }, -} -``` - -### searchAndReplace[].replace - -The replacement string for each regex match. - -**Field type**: `String` - -```js -{ - resolve: `gatsby-source-wordpress`, - options: { - searchAndReplace: [ - { - replace: "https://some-new-url.com", - } - ], - ... - }, -} -``` - # Up Next :point_right: - :boat: [Migrating from other WP source plugins](./migrating-from-other-wp-source-plugins.md) diff --git a/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts b/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts index cf22cb3ec3047..a492baf8d5cf1 100644 --- a/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts +++ b/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts @@ -530,6 +530,45 @@ When using this option, be sure to gitignore the wordpress-cache directory in th excludeFieldNames: [\`viewer\`], `), }), + searchAndReplace: Joi.array() + .description(`An array of options to search and replace strings in nodes. See below for options.`) + .allow(null) + .items( + Joi.object({ + search: Joi.string() + .description(`The regex rule used to search a terme.`) + .meta({ + example: wrapOptions(` + searchAndReplace: [ + { + search: "https://some-url\.com" + }, + ], + `), + }), + replace: Joi.string() + .description(`The replacement string for each regex match.`) + .meta({ + example: wrapOptions(` + searchAndReplace: [ + { + replace: "https://some-new-url.com", + }, + ], + `), + }) + }) + ) + .meta({ + example: wrapOptions(` + searchAndReplace: [ + { + search: "https://some-url\.com", + replace: "https://some-new-url.com", + }, + ], + `), + }), html: Joi.object({ useGatsbyImage: Joi.boolean() .default(true) From d9c7d9d9fcbe1861f443d4da5fcfef3c18c081e9 Mon Sep 17 00:00:00 2001 From: jo Date: Wed, 5 May 2021 15:44:57 +0200 Subject: [PATCH 04/14] !fixup Add test for searchAndReplaceNodeStrings --- .../__tests__/process-node.test.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/gatsby-source-wordpress/__tests__/process-node.test.js b/packages/gatsby-source-wordpress/__tests__/process-node.test.js index bcf7996a92f23..3064912e242fd 100644 --- a/packages/gatsby-source-wordpress/__tests__/process-node.test.js +++ b/packages/gatsby-source-wordpress/__tests__/process-node.test.js @@ -4,6 +4,7 @@ import { getImgSrcRemoteFileMatchesFromNodeString, getImgTagMatchesWithUrl, getWpLinkRegex, + searchAndReplaceNodeStrings, } from "../dist/steps/source-nodes/create-nodes/process-node" const wpUrl = `wp.fakesite.com` @@ -43,3 +44,28 @@ test(`HTML link transformation regex matches links`, async () => { expect(matches.length).toBe(2) }) + +test(`Search and replace node strings using regex matches`, async () => { + const nodeString = `Some stuff in a random string + + A new line with some stuff! + + We need to test some link as well!` + + const result = searchAndReplaceNodeStrings({ + nodeString, + node: { __typename: "FakeTypeName", id: "cG9zdDo0OQ==" }, + pluginOptions: { + searchAndReplace: [ + { search: "(S|s)ome stuff", replace: "some other thing" }, + { search: "https://old-site\.com", replace: "https://new-site.com" }, + ] + } + }) + + expect(result).toBe(`some other thing in a random string + + A new line with some other thing! + + We need to test some link as well!`) +}) From e699f66b9a85018186b588dd8118262349e4ce0a Mon Sep 17 00:00:00 2001 From: Jonas L Date: Mon, 10 May 2021 21:00:38 +0200 Subject: [PATCH 05/14] !fixup fix test regex Co-authored-by: Tyler Barnes --- packages/gatsby-source-wordpress/__tests__/process-node.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-wordpress/__tests__/process-node.test.js b/packages/gatsby-source-wordpress/__tests__/process-node.test.js index 3064912e242fd..dc87db89b6cc0 100644 --- a/packages/gatsby-source-wordpress/__tests__/process-node.test.js +++ b/packages/gatsby-source-wordpress/__tests__/process-node.test.js @@ -57,7 +57,7 @@ test(`Search and replace node strings using regex matches`, async () => { node: { __typename: "FakeTypeName", id: "cG9zdDo0OQ==" }, pluginOptions: { searchAndReplace: [ - { search: "(S|s)ome stuff", replace: "some other thing" }, + { search: /(S|s)ome stuff/gm, replace: `some other thing` }, { search: "https://old-site\.com", replace: "https://new-site.com" }, ] } From a5b82baa9c9f7f600a14bcd06e626a9262d4c32a Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 10 May 2021 21:02:13 +0200 Subject: [PATCH 06/14] !fixup Replace double quotes with backticks --- .../gatsby-source-wordpress/__tests__/process-node.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-wordpress/__tests__/process-node.test.js b/packages/gatsby-source-wordpress/__tests__/process-node.test.js index dc87db89b6cc0..e7ad415b63696 100644 --- a/packages/gatsby-source-wordpress/__tests__/process-node.test.js +++ b/packages/gatsby-source-wordpress/__tests__/process-node.test.js @@ -54,11 +54,11 @@ test(`Search and replace node strings using regex matches`, async () => { const result = searchAndReplaceNodeStrings({ nodeString, - node: { __typename: "FakeTypeName", id: "cG9zdDo0OQ==" }, + node: { __typename: `FakeTypeName`, id: `cG9zdDo0OQ==` }, pluginOptions: { searchAndReplace: [ { search: /(S|s)ome stuff/gm, replace: `some other thing` }, - { search: "https://old-site\.com", replace: "https://new-site.com" }, + { search: `https://old-site\.com`, replace: `https://new-site.com` }, ] } }) From 04bccbee8c1362fdb684943ce3ef7f839ee6d803 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 10 May 2021 21:04:41 +0200 Subject: [PATCH 07/14] Run search and replace filter first Filters are run in order one at a time and if we run it at the end we'll have already done a bunch of image/file processing and manipulation of the node data. Putting this at the end means we wont be able to rewrite our WP URL to a CDN url before Gatsby pulls all the images in from WP. --- .../src/steps/source-nodes/create-nodes/process-node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js index 40c972a220fa9..dfcfcabfd913d 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js @@ -888,10 +888,10 @@ const processNodeString = async ({ wpUrl, }) => { const nodeStringFilters = [ + searchAndReplaceNodeStrings, replaceNodeHtmlImages, replaceFileLinks, replaceNodeHtmlLinks, - searchAndReplaceNodeStrings, ] for (const nodeStringFilter of nodeStringFilters) { From af3f6a3c90b388a1e6c3cb59edc4305bac1ded88 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 10 May 2021 21:07:54 +0200 Subject: [PATCH 08/14] Add note about using regular expression literal --- .../src/steps/declare-plugin-options-schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts b/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts index a492baf8d5cf1..f0dfa23ffc90e 100644 --- a/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts +++ b/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts @@ -536,7 +536,7 @@ When using this option, be sure to gitignore the wordpress-cache directory in th .items( Joi.object({ search: Joi.string() - .description(`The regex rule used to search a terme.`) + .description(`The regex rule used to search a terme. Using a 'regular expression literal' is recommended over a simple regex string.`) .meta({ example: wrapOptions(` searchAndReplace: [ From 3714e9940860e83ace826ba99fa78c61c33f62a1 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 10 May 2021 21:10:31 +0200 Subject: [PATCH 09/14] !fixup Regenerate docs options --- packages/gatsby-source-wordpress/docs/plugin-options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-wordpress/docs/plugin-options.md b/packages/gatsby-source-wordpress/docs/plugin-options.md index 5261aa182c350..a5f1bb2492fc8 100644 --- a/packages/gatsby-source-wordpress/docs/plugin-options.md +++ b/packages/gatsby-source-wordpress/docs/plugin-options.md @@ -804,7 +804,7 @@ An array of options to search and replace strings in nodes. See below for option ### searchAndReplace[].search -The regex rule used to search a terme. +The regex rule used to search a terme. Using a 'regular expression literal' is recommended over a simple regex string. **Field type**: `String` From edea954881760447c47d49b4f1db912cba99d250 Mon Sep 17 00:00:00 2001 From: gatsbybot Date: Mon, 10 May 2021 19:20:21 +0000 Subject: [PATCH 10/14] chore: format --- .../src/steps/declare-plugin-options-schema.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts b/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts index f0dfa23ffc90e..9be381a7357d4 100644 --- a/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts +++ b/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts @@ -531,12 +531,16 @@ When using this option, be sure to gitignore the wordpress-cache directory in th `), }), searchAndReplace: Joi.array() - .description(`An array of options to search and replace strings in nodes. See below for options.`) + .description( + `An array of options to search and replace strings in nodes. See below for options.` + ) .allow(null) .items( Joi.object({ search: Joi.string() - .description(`The regex rule used to search a terme. Using a 'regular expression literal' is recommended over a simple regex string.`) + .description( + `The regex rule used to search a terme. Using a 'regular expression literal' is recommended over a simple regex string.` + ) .meta({ example: wrapOptions(` searchAndReplace: [ @@ -556,7 +560,7 @@ When using this option, be sure to gitignore the wordpress-cache directory in th }, ], `), - }) + }), }) ) .meta({ From fb81401c15b74c9af56e4c364eb6f0290e9bc44d Mon Sep 17 00:00:00 2001 From: Jonas L Date: Mon, 10 May 2021 21:28:19 +0200 Subject: [PATCH 11/14] Fix docs Co-authored-by: Tyler Barnes --- packages/gatsby-source-wordpress/docs/plugin-options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-wordpress/docs/plugin-options.md b/packages/gatsby-source-wordpress/docs/plugin-options.md index a5f1bb2492fc8..cc32b2efd4453 100644 --- a/packages/gatsby-source-wordpress/docs/plugin-options.md +++ b/packages/gatsby-source-wordpress/docs/plugin-options.md @@ -804,7 +804,7 @@ An array of options to search and replace strings in nodes. See below for option ### searchAndReplace[].search -The regex rule used to search a terme. Using a 'regular expression literal' is recommended over a simple regex string. +The regex rule used to search a string. Using a 'regular expression literal' is recommended over a simple regex string. **Field type**: `String` From c64643333e8e1f38da0bce1b4c070c71c7bce639 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 10 May 2021 21:30:41 +0200 Subject: [PATCH 12/14] !fixup Remove backlash from test regex --- packages/gatsby-source-wordpress/__tests__/process-node.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-wordpress/__tests__/process-node.test.js b/packages/gatsby-source-wordpress/__tests__/process-node.test.js index e7ad415b63696..b61376194def5 100644 --- a/packages/gatsby-source-wordpress/__tests__/process-node.test.js +++ b/packages/gatsby-source-wordpress/__tests__/process-node.test.js @@ -58,7 +58,7 @@ test(`Search and replace node strings using regex matches`, async () => { pluginOptions: { searchAndReplace: [ { search: /(S|s)ome stuff/gm, replace: `some other thing` }, - { search: `https://old-site\.com`, replace: `https://new-site.com` }, + { search: `https://old-site.com`, replace: `https://new-site.com` }, ] } }) From 7e204f518e97c2ab961b7f7c367245b889482e52 Mon Sep 17 00:00:00 2001 From: jo Date: Tue, 11 May 2021 20:48:33 +0200 Subject: [PATCH 13/14] !fixup Again useless escape char --- .../src/steps/declare-plugin-options-schema.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts b/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts index 9be381a7357d4..16d90cb8a474e 100644 --- a/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts +++ b/packages/gatsby-source-wordpress/src/steps/declare-plugin-options-schema.ts @@ -545,7 +545,7 @@ When using this option, be sure to gitignore the wordpress-cache directory in th example: wrapOptions(` searchAndReplace: [ { - search: "https://some-url\.com" + search: "https://some-url.com" }, ], `), @@ -567,7 +567,7 @@ When using this option, be sure to gitignore the wordpress-cache directory in th example: wrapOptions(` searchAndReplace: [ { - search: "https://some-url\.com", + search: "https://some-url.com", replace: "https://some-new-url.com", }, ], From 83287afe1281debd40e607ea2b2718147f97d648 Mon Sep 17 00:00:00 2001 From: jo Date: Tue, 11 May 2021 22:17:30 +0200 Subject: [PATCH 14/14] !fixup fix test missing func export --- .../src/steps/source-nodes/create-nodes/process-node.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js index dfcfcabfd913d..38d09bab6da99 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/create-nodes/process-node.js @@ -851,7 +851,11 @@ const replaceNodeHtmlLinks = ({ wpUrl, nodeString, node }) => { } // replaces specific string or regex with a given string from the plugin options config -const searchAndReplaceNodeStrings = ({ nodeString, node, pluginOptions }) => { +export const searchAndReplaceNodeStrings = ({ + nodeString, + node, + pluginOptions, +}) => { if (Array.isArray(pluginOptions?.searchAndReplace)) { pluginOptions.searchAndReplace.forEach(({ search, replace }) => { const searchRegex = new RegExp(search, `g`)