Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(chrome-extension): Add postbuild script to verify no RHC #4906

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/sixty-eggs-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
1 change: 1 addition & 0 deletions packages/chrome-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions scripts/search-for-rhc.mjs
Original file line number Diff line number Diff line change
@@ -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} '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');
}
}

run();
Loading