Skip to content

Commit

Permalink
chore(clerk-js,chrome-extension): Check for RHC (#5040)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilewski authored Jan 29, 2025
1 parent 1aa5bb6 commit b18de30
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .changeset/cyan-kids-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion packages/chrome-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 28 additions & 9 deletions scripts/search-for-rhc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit b18de30

Please sign in to comment.