Skip to content

Commit b18de30

Browse files
authored
chore(clerk-js,chrome-extension): Check for RHC (clerk#5040)
1 parent 1aa5bb6 commit b18de30

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

.changeset/cyan-kids-boil.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/chrome-extension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
],
3434
"scripts": {
3535
"build": "tsup",
36-
"postbuild": "node ../../scripts/search-for-rhc.mjs dist",
36+
"postbuild": "node ../../scripts/search-for-rhc.mjs directory dist",
3737
"build:declarations": "tsc -p tsconfig.declarations.json",
3838
"clean": "rimraf ./dist",
3939
"dev": "tsup --watch",

packages/clerk-js/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
],
3333
"scripts": {
3434
"build": "pnpm build:bundle && pnpm build:declarations",
35+
"postbuild": "node ../../scripts/search-for-rhc.mjs file dist/clerk.no-rhc.mjs",
3536
"build:analyze": "rspack build --config rspack.config.js --env production --env variant=\"clerk.browser\" --env analysis --analyze",
3637
"build:bundle": "pnpm clean && rspack build --config rspack.config.js --env production",
3738
"build:declarations": "tsc -p tsconfig.declarations.json",

scripts/search-for-rhc.mjs

+28-9
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,32 @@
77

88
import { $, argv } from 'zx';
99

10-
const buildFolder = argv._[0];
11-
console.log(`🔍 Inspecting folder: ${buildFolder}`);
12-
const flags = ['--recursive', '--quiet', '--include=*.js', '--include=*.mjs'];
13-
14-
// Leveraging https://google.github.io/zx/process-promise#nothrow to avoid throwing an error if the command fails
15-
if ((await $`grep ${flags} 'https://\${scriptHost}/npm/@clerk/clerk-js' ${buildFolder}`.exitCode) === 0) {
16-
throw new Error('Found RHC in build output');
17-
} else {
18-
console.log('✅ No RHC found in build output');
10+
const targetType = argv._[0]; // file | directory
11+
const target = argv._[1]; // Target of the resource
12+
13+
async function asyncSearchRHC(name, search) {
14+
const cmd = () =>
15+
targetType === 'directory'
16+
? $`grep -rFq --include=\\*.js --include=\\*.mjs "${search}" ${target}`
17+
: $`grep -Fq "${search}" ${target}`;
18+
19+
if ((await cmd().exitCode) === 0) {
20+
throw new Error(`Found ${name} related RHC in build output. (Search: \`${search}\`)`);
21+
}
22+
23+
return;
1924
}
25+
26+
await Promise.allSettled([
27+
asyncSearchRHC('Turnstile', 'cloudflare.com/turnstile/v0/api.js'),
28+
asyncSearchRHC('clerk-js Hotloading', '/npm/@clerk/clerk-js'),
29+
asyncSearchRHC('Google One Tap', 'accounts.google.com/gsi/client'),
30+
]).then(results => {
31+
const errors = results.filter(result => result.status === 'rejected').map(result => result.reason.message);
32+
33+
if (errors.length > 0) {
34+
throw new Error(`\n${errors.join('\n')}`);
35+
}
36+
37+
console.log('✅ No RHC found in build output');
38+
});

0 commit comments

Comments
 (0)