From 7686cfa37973398774103bd3f666addb830bd230 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 16 Jan 2025 12:34:01 +0100 Subject: [PATCH 1/2] initial --- .changeset/sixty-eggs-hug.md | 2 ++ packages/chrome-extension/package.json | 1 + scripts/search-for-rhc.mjs | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 .changeset/sixty-eggs-hug.md create mode 100644 scripts/search-for-rhc.mjs diff --git a/.changeset/sixty-eggs-hug.md b/.changeset/sixty-eggs-hug.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/sixty-eggs-hug.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/chrome-extension/package.json b/packages/chrome-extension/package.json index 7d041753674..1478380af5a 100644 --- a/packages/chrome-extension/package.json +++ b/packages/chrome-extension/package.json @@ -33,6 +33,7 @@ ], "scripts": { "build": "tsup", + "postbuild": "node ../../scripts/search-for-rhc.mjs dist", "build:declarations": "tsc -p tsconfig.declarations.json", "clean": "rimraf ./dist", "dev": "tsup --watch", diff --git a/scripts/search-for-rhc.mjs b/scripts/search-for-rhc.mjs new file mode 100644 index 00000000000..7d62923cdf0 --- /dev/null +++ b/scripts/search-for-rhc.mjs @@ -0,0 +1,23 @@ +#!/usr/bin/env zx + +/** + * The purpose of this script is to search for RHC (remotely hosted code) in the build outputs of a package. + * For example, @clerk/chrome-extension should not have any RHC in it, this includes unused functions that include remote URLs. + */ + +import { $, argv } from 'zx'; + +async function run() { + const buildFolder = argv._[0]; + console.log(`🔍 Inspecting folder: ${buildFolder}`); + const flags = ['--recursive', '--quiet', '--include=*.js', '--include=*.mjs']; + + // Leveraging https://google.github.io/zx/process-promise#nothrow to avoid throwing an error if the command fails + if ((await $`grep ${flags} 'npm/@clerk/clerk-js' ${buildFolder}`.exitCode) === 0) { + throw new Error('Found RHC in build output'); + } else { + console.log('✅ No RHC found in build output'); + } +} + +run(); From 6d4ccc9d071bde16c8948ba5dc524ad137446364 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 16 Jan 2025 12:38:24 +0100 Subject: [PATCH 2/2] improve search string --- scripts/search-for-rhc.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/search-for-rhc.mjs b/scripts/search-for-rhc.mjs index 7d62923cdf0..a3b3ba2b1a7 100644 --- a/scripts/search-for-rhc.mjs +++ b/scripts/search-for-rhc.mjs @@ -13,7 +13,7 @@ async function run() { const flags = ['--recursive', '--quiet', '--include=*.js', '--include=*.mjs']; // Leveraging https://google.github.io/zx/process-promise#nothrow to avoid throwing an error if the command fails - if ((await $`grep ${flags} 'npm/@clerk/clerk-js' ${buildFolder}`.exitCode) === 0) { + if ((await $`grep ${flags} 'https://\${scriptHost}/npm/@clerk/clerk-js' ${buildFolder}`.exitCode) === 0) { throw new Error('Found RHC in build output'); } else { console.log('✅ No RHC found in build output');