From aab9669399ce2a6f097c3b7d8e1a85cf35056cef Mon Sep 17 00:00:00 2001 From: Blake Wilson Date: Fri, 9 Feb 2024 14:57:16 -0600 Subject: [PATCH 1/7] Detect wpengine.com TLD --- package-lock.json | 60 +++++++++++++++++++ .../src/healthCheck/validateFaustEnvVars.ts | 9 ++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 859177815..f756f2fc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36006,6 +36006,66 @@ "plugins/faustwp": { "name": "@faustwp/wordpress-plugin", "version": "1.2.1" + }, + "packages/experimental-app-router/node_modules/@next/swc-android-arm-eabi": { + "version": "12.3.4", + "resolved": "https://registry.npmjs.org/@next/swc-android-arm-eabi/-/swc-android-arm-eabi-12.3.4.tgz", + "integrity": "sha512-cM42Cw6V4Bz/2+j/xIzO8nK/Q3Ly+VSlZJTa1vHzsocJRYz8KT6MrreXaci2++SIZCF1rVRCDgAg5PpqRibdIA==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/experimental-app-router/node_modules/@next/swc-android-arm64": { + "version": "12.3.4", + "resolved": "https://registry.npmjs.org/@next/swc-android-arm64/-/swc-android-arm64-12.3.4.tgz", + "integrity": "sha512-5jf0dTBjL+rabWjGj3eghpLUxCukRhBcEJgwLedewEA/LJk2HyqCvGIwj5rH+iwmq1llCWbOky2dO3pVljrapg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/experimental-app-router/node_modules/@next/swc-freebsd-x64": { + "version": "12.3.4", + "resolved": "https://registry.npmjs.org/@next/swc-freebsd-x64/-/swc-freebsd-x64-12.3.4.tgz", + "integrity": "sha512-KM9JXRXi/U2PUM928z7l4tnfQ9u8bTco/jb939pdFUHqc28V43Ohd31MmZD1QzEK4aFlMRaIBQOWQZh4D/E5lQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 10" + } + }, + "packages/experimental-app-router/node_modules/@next/swc-linux-arm-gnueabihf": { + "version": "12.3.4", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-12.3.4.tgz", + "integrity": "sha512-3zqD3pO+z5CZyxtKDTnOJ2XgFFRUBciOox6EWkoZvJfc9zcidNAQxuwonUeNts6Xbm8Wtm5YGIRC0x+12YH7kw==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } } } } diff --git a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts index 066d18e89..e1e7d8a14 100644 --- a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts +++ b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts @@ -1,5 +1,5 @@ import { getWpSecret } from '../utils/index.js'; -import { errorLog, warnLog } from '../stdout/index.js'; +import { errorLog, infoLog, warnLog } from '../stdout/index.js'; /** * Validates that the appropriate Faust related environment variables are set. @@ -11,6 +11,13 @@ export const validateFaustEnvVars = () => { process.exit(1); } + const regex = /\b\w+\.wpengine\.com\b/; + if (regex.test(process.env.NEXT_PUBLIC_WORDPRESS_URL)) { + infoLog( + 'We detected your NEXT_PUBLIC_WORDPRESS_URL is using wpengine.com. It is recommended to use the wpenginepowered.com TLD', + ); + } + if (!getWpSecret()) { warnLog('Could not find FAUST_SECRET_KEY environment variable.'); warnLog('Some functionality may be limited.'); From fc96a488380105dbe00d915a9412e1ef1d3f98e1 Mon Sep 17 00:00:00 2001 From: Blake Wilson Date: Tue, 13 Feb 2024 10:01:35 -0600 Subject: [PATCH 2/7] Create unit tests --- .../src/healthCheck/validateFaustEnvVars.ts | 13 +++++++-- .../healthCheck/validateFaustEnvVars.test.ts | 29 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts index e1e7d8a14..44a3fcc2b 100644 --- a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts +++ b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts @@ -1,6 +1,16 @@ import { getWpSecret } from '../utils/index.js'; import { errorLog, infoLog, warnLog } from '../stdout/index.js'; +export function isWPEngineComSubdomain(url: string) { + const regex = /\b\w+\.wpengine\.com\b/; + + if (regex.test(url)) { + return true; + } + + return false; +} + /** * Validates that the appropriate Faust related environment variables are set. */ @@ -11,8 +21,7 @@ export const validateFaustEnvVars = () => { process.exit(1); } - const regex = /\b\w+\.wpengine\.com\b/; - if (regex.test(process.env.NEXT_PUBLIC_WORDPRESS_URL)) { + if (isWPEngineComSubdomain(process.env.NEXT_PUBLIC_WORDPRESS_URL)) { infoLog( 'We detected your NEXT_PUBLIC_WORDPRESS_URL is using wpengine.com. It is recommended to use the wpenginepowered.com TLD', ); diff --git a/packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts b/packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts index 1d6c86ef5..a346b4398 100644 --- a/packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts +++ b/packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts @@ -1,4 +1,7 @@ -import { validateFaustEnvVars } from '../../src/healthCheck/validateFaustEnvVars'; +import { + isWPEngineComSubdomain, + validateFaustEnvVars, +} from '../../src/healthCheck/validateFaustEnvVars'; /** * @jest-environment jsdom */ @@ -50,3 +53,27 @@ describe('healthCheck/validateFaustEnvVars', () => { expect(mockExit).toBeCalledTimes(0); }); }); + +describe('isWPEngineComTLD', () => { + it('matches subdomains on wpengine.com', () => { + expect(isWPEngineComSubdomain('https://my-site.wpengine.com')).toBeTruthy(); + expect( + isWPEngineComSubdomain('http://some-site.wpengine.com/graphql'), + ).toBeTruthy(); + expect(isWPEngineComSubdomain('https://example.wpengine.com')).toBeTruthy(); + expect( + isWPEngineComSubdomain('https://some-long-weird-subdomain.wpengine.com'), + ); + }); + + it('does not match urls that are not subdomains of wpengine.com', () => { + expect(isWPEngineComSubdomain('https://example.com')).toBeFalsy(); + expect(isWPEngineComSubdomain('https://wpengine.com')).toBeFalsy(); + expect(isWPEngineComSubdomain('https://wpengine.com/plans')).toBeFalsy(); + expect(isWPEngineComSubdomain('https://my-site.wpengine.co')).toBeFalsy(); + expect( + isWPEngineComSubdomain('https://my-site.wpenginepowered.com'), + ).toBeFalsy(); + expect(isWPEngineComSubdomain('https://my-site.wpengine.co')); + }); +}); From 666e1b0e885aa31c8de2b0a0117b496fdaaab151 Mon Sep 17 00:00:00 2001 From: Blake Wilson Date: Tue, 13 Feb 2024 10:09:58 -0600 Subject: [PATCH 3/7] Update messaging --- packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts index 44a3fcc2b..50134ab5c 100644 --- a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts +++ b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts @@ -22,8 +22,10 @@ export const validateFaustEnvVars = () => { } if (isWPEngineComSubdomain(process.env.NEXT_PUBLIC_WORDPRESS_URL)) { + infoLog(`Found NEXT_PUBLIC_WORDPRESS_URL using wpengine.com TLD.`); + infoLog(`It is recommended to use the wpenginepowered.com TLD instead.`); infoLog( - 'We detected your NEXT_PUBLIC_WORDPRESS_URL is using wpengine.com. It is recommended to use the wpenginepowered.com TLD', + `Ex: https://example.wpengine.com -> https://example.wpenginepowered.com`, ); } From cd938d626d79f7e8924d09dbf4a0723446ffa88b Mon Sep 17 00:00:00 2001 From: Blake Wilson Date: Tue, 13 Feb 2024 10:17:10 -0600 Subject: [PATCH 4/7] Add changeset --- .changeset/neat-foxes-develop.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/neat-foxes-develop.md diff --git a/.changeset/neat-foxes-develop.md b/.changeset/neat-foxes-develop.md new file mode 100644 index 000000000..343b53e0d --- /dev/null +++ b/.changeset/neat-foxes-develop.md @@ -0,0 +1,5 @@ +--- +'@faustwp/cli': minor +--- + +Added: Detect if the `NEXT_PUBLIC_WORDPRESS_URL` is a `wpengine.com` TLD and if so recommend a switch to `wpenginepowered.com` From 94f131e19f873ba40e61894263676482bcc49a22 Mon Sep 17 00:00:00 2001 From: Blake Wilson Date: Tue, 13 Feb 2024 10:52:08 -0600 Subject: [PATCH 5/7] Update packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts Co-authored-by: John Parris --- .../faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts b/packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts index a346b4398..f56540283 100644 --- a/packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts +++ b/packages/faustwp-cli/tests/healthCheck/validateFaustEnvVars.test.ts @@ -74,6 +74,5 @@ describe('isWPEngineComTLD', () => { expect( isWPEngineComSubdomain('https://my-site.wpenginepowered.com'), ).toBeFalsy(); - expect(isWPEngineComSubdomain('https://my-site.wpengine.co')); }); }); From 2ae842cba0e0274e051a0ae5653e9499f6e98810 Mon Sep 17 00:00:00 2001 From: Blake Wilson Date: Wed, 14 Feb 2024 11:48:32 -0600 Subject: [PATCH 6/7] Simplify regex test return statement --- .../faustwp-cli/src/healthCheck/validateFaustEnvVars.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts index 50134ab5c..3ff6f4ae1 100644 --- a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts +++ b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts @@ -4,11 +4,7 @@ import { errorLog, infoLog, warnLog } from '../stdout/index.js'; export function isWPEngineComSubdomain(url: string) { const regex = /\b\w+\.wpengine\.com\b/; - if (regex.test(url)) { - return true; - } - - return false; + return regex.test(url); } /** From afc778ce4f2cfe1b8c2814813783e4b671d687e6 Mon Sep 17 00:00:00 2001 From: Blake Wilson Date: Wed, 14 Feb 2024 11:53:10 -0600 Subject: [PATCH 7/7] Update info message --- packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts index 3ff6f4ae1..a91e07a68 100644 --- a/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts +++ b/packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts @@ -23,6 +23,9 @@ export const validateFaustEnvVars = () => { infoLog( `Ex: https://example.wpengine.com -> https://example.wpenginepowered.com`, ); + infoLog( + `This will leverage WP Engine's Advanced Network CDN. See: https://wpengine.com/support/network/`, + ); } if (!getWpSecret()) {