From b18de30a3ee12affc4ec1054ee319e787e82c0ec Mon Sep 17 00:00:00 2001 From: Tom Milewski Date: Wed, 29 Jan 2025 14:29:58 -0500 Subject: [PATCH] chore(clerk-js,chrome-extension): Check for RHC (#5040) --- .changeset/cyan-kids-boil.md | 2 ++ packages/chrome-extension/package.json | 2 +- packages/clerk-js/package.json | 1 + scripts/search-for-rhc.mjs | 37 +++++++++++++++++++------- 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 .changeset/cyan-kids-boil.md diff --git a/.changeset/cyan-kids-boil.md b/.changeset/cyan-kids-boil.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/cyan-kids-boil.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/chrome-extension/package.json b/packages/chrome-extension/package.json index 5effbe57fd8..a30b4b4fa4b 100644 --- a/packages/chrome-extension/package.json +++ b/packages/chrome-extension/package.json @@ -33,7 +33,7 @@ ], "scripts": { "build": "tsup", - "postbuild": "node ../../scripts/search-for-rhc.mjs dist", + "postbuild": "node ../../scripts/search-for-rhc.mjs directory dist", "build:declarations": "tsc -p tsconfig.declarations.json", "clean": "rimraf ./dist", "dev": "tsup --watch", diff --git a/packages/clerk-js/package.json b/packages/clerk-js/package.json index b262501a48f..b154a32ad11 100644 --- a/packages/clerk-js/package.json +++ b/packages/clerk-js/package.json @@ -32,6 +32,7 @@ ], "scripts": { "build": "pnpm build:bundle && pnpm build:declarations", + "postbuild": "node ../../scripts/search-for-rhc.mjs file dist/clerk.no-rhc.mjs", "build:analyze": "rspack build --config rspack.config.js --env production --env variant=\"clerk.browser\" --env analysis --analyze", "build:bundle": "pnpm clean && rspack build --config rspack.config.js --env production", "build:declarations": "tsc -p tsconfig.declarations.json", diff --git a/scripts/search-for-rhc.mjs b/scripts/search-for-rhc.mjs index 4f6b971f878..8721f02c75d 100644 --- a/scripts/search-for-rhc.mjs +++ b/scripts/search-for-rhc.mjs @@ -7,13 +7,32 @@ import { $, argv } from 'zx'; -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} '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'); +const targetType = argv._[0]; // file | directory +const target = argv._[1]; // Target of the resource + +async function asyncSearchRHC(name, search) { + const cmd = () => + targetType === 'directory' + ? $`grep -rFq --include=\\*.js --include=\\*.mjs "${search}" ${target}` + : $`grep -Fq "${search}" ${target}`; + + if ((await cmd().exitCode) === 0) { + throw new Error(`Found ${name} related RHC in build output. (Search: \`${search}\`)`); + } + + return; } + +await Promise.allSettled([ + asyncSearchRHC('Turnstile', 'cloudflare.com/turnstile/v0/api.js'), + asyncSearchRHC('clerk-js Hotloading', '/npm/@clerk/clerk-js'), + asyncSearchRHC('Google One Tap', 'accounts.google.com/gsi/client'), +]).then(results => { + const errors = results.filter(result => result.status === 'rejected').map(result => result.reason.message); + + if (errors.length > 0) { + throw new Error(`\n${errors.join('\n')}`); + } + + console.log('✅ No RHC found in build output'); +});