Skip to content

Commit ba6d2ee

Browse files
authored
fix(clerk-js,chrome-extension): Stripe bundles (#5597)
1 parent a0cc247 commit ba6d2ee

5 files changed

Lines changed: 33 additions & 26 deletions

File tree

.changeset/open-cases-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/chrome-extension': patch
3+
---
4+
5+
Externalize all Stripe-related modules

.changeset/slick-taxis-cut.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Fully strip @stripe/stripe-js from non-RHC builds

packages/chrome-extension/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default defineConfig(overrideOptions => {
1717
legacyOutput: true,
1818
treeshake: true,
1919
noExternal: ['@clerk/clerk-react', '@clerk/shared'],
20-
external: ['use-sync-external-store'],
20+
external: ['use-sync-external-store', '@stripe/stripe-js', '@stripe/react-stripe-js'],
2121
define: {
2222
PACKAGE_NAME: `"${name}"`,
2323
PACKAGE_VERSION: `"${version}"`,

packages/clerk-js/rspack.config.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,27 @@ const prodConfig = ({ mode, env, analysis }) => {
405405
},
406406
});
407407

408+
/** @type { () => (import('@rspack/core').Configuration) } */
409+
const commonForNoRHC = () => ({
410+
plugins: [
411+
new rspack.IgnorePlugin({
412+
resourceRegExp: /^@stripe\/stripe-js$/,
413+
}),
414+
new rspack.optimize.LimitChunkCountPlugin({
415+
maxChunks: 1,
416+
}),
417+
],
418+
optimization: {
419+
splitChunks: false,
420+
},
421+
});
422+
408423
const clerkEsmNoRHC = merge(
409424
entryForVariant(variants.clerkNoRHC),
410425
common({ mode, disableRHC: true }),
411426
commonForProd(),
412427
commonForProdBundled(),
428+
commonForNoRHC(),
413429
{
414430
experiments: {
415431
outputModule: true,
@@ -418,17 +434,6 @@ const prodConfig = ({ mode, env, analysis }) => {
418434
filename: '[name].mjs',
419435
libraryTarget: 'module',
420436
},
421-
plugins: [
422-
// Include the lazy chunks in the bundle as well
423-
// so that the final bundle can be imported and bundled again
424-
// by a different bundler, eg the webpack instance used by react-scripts
425-
new rspack.optimize.LimitChunkCountPlugin({
426-
maxChunks: 1,
427-
}),
428-
],
429-
optimization: {
430-
splitChunks: false,
431-
},
432437
},
433438
);
434439

@@ -437,22 +442,12 @@ const prodConfig = ({ mode, env, analysis }) => {
437442
common({ mode, disableRHC: true }),
438443
commonForProd(),
439444
commonForProdBundled(),
445+
commonForNoRHC(),
440446
{
441447
output: {
442448
filename: '[name].js',
443449
libraryTarget: 'commonjs',
444450
},
445-
plugins: [
446-
// Include the lazy chunks in the bundle as well
447-
// so that the final bundle can be imported and bundled again
448-
// by a different bundler, eg the webpack instance used by react-scripts
449-
new rspack.optimize.LimitChunkCountPlugin({
450-
maxChunks: 1,
451-
}),
452-
],
453-
optimization: {
454-
splitChunks: false,
455-
},
456451
},
457452
);
458453

scripts/search-for-rhc.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { $, argv } from 'zx';
1010
const targetType = argv._[0]; // file | directory
1111
const target = argv._[1]; // Target of the resource
1212

13-
async function asyncSearchRHC(name, search) {
13+
async function asyncSearchRHC(name, search, regex = false) {
14+
const flag = regex ? 'E' : 'F';
1415
const cmd = () =>
1516
targetType === 'directory'
16-
? $`grep -rFq --include=\\*.js --include=\\*.mjs "${search}" ${target}`
17-
: $`grep -Fq "${search}" ${target}`;
17+
? $`grep -${flag}q --include=\\*.js --include=\\*.mjs ${search} ${target}`
18+
: $`grep -${flag}q ${search} ${target}`;
1819

1920
if ((await cmd().exitCode) === 0) {
2021
throw new Error(`Found ${name} related RHC in build output. (Search: \`${search}\`)`);
@@ -28,6 +29,7 @@ await Promise.allSettled([
2829
asyncSearchRHC('clerk-js Hotloading', '/npm/@clerk/clerk-js'),
2930
asyncSearchRHC('Google One Tap', 'accounts.google.com/gsi/client'),
3031
asyncSearchRHC('Stripe', 'js.stripe.com'),
32+
asyncSearchRHC('Stripe import', 'import\s*"@stripe/stripe-js', true), // eslint-disable-line no-useless-escape
3133
]).then(results => {
3234
const errors = results.filter(result => result.status === 'rejected').map(result => result.reason.message);
3335

0 commit comments

Comments
 (0)