|
7 | 7 |
|
8 | 8 | import { $, argv } from 'zx';
|
9 | 9 |
|
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; |
19 | 24 | }
|
| 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