-
Notifications
You must be signed in to change notification settings - Fork 417
feat(clerk-js): Add bundleless ESM build #5964
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
base: main
Are you sure you want to change the base?
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| "main": "dist/clerk.js", | ||
| "jsdelivr": "dist/clerk.browser.js", | ||
| "module": "dist/clerk.mjs", | ||
| "module": "dist/esm/index.mjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be a breaking change in some cases ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would only break if someone was importing directly from dist/. The only reason this is in a folder is because Rslib will, for some reason, run on all files in the input folder. So it would emit index.browser.js which was confusing. Not a strong suggestion that we do it this way, just wanted to get it working for experimental purposes!
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
|
currently blocked by web-infra-dev/rslib#1007 and web-infra-dev/rslib#882 |
|
Hello 👋 We currently close PRs after 60 days of inactivity. It's been 50 days since the last update here. If we missed this PR, please reply here. Otherwise, we'll close this PR in 10 days. Thanks for being a part of the Clerk community! 🙏 |
📝 WalkthroughWalkthroughThe changes introduce a new build system configuration for the Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (2)
packages/clerk-js/package.json (1)
1-104: No tests cover the new bundleless outputThe PR alters the public ESM entry and introduces a second build pipeline yet adds no automated checks. Consider adding at least one Jest/TS test that:
import pkg from '../dist/esm/index.mjs'; expect(pkg).toBeDefined();to assert the file exists and loads without syntax errors.
packages/clerk-js/rslib.config.ts (1)
1-42: Missing test/build smoke checks for rslib outputSimilar to the package.json feedback, please add CI smoke tests that import a component from
dist/esmto detect tree-shaking / JSX transform regressions early.
♻️ Duplicate comments (1)
packages/clerk-js/package.json (1)
24-27: Potential breaking change – newmoduleentry pathChanging the ESM entry from
dist/clerk.mjstodist/esm/index.mjscan break consumers that import directly from the previous path (e.g.import … from "@clerk/clerk-js/dist/clerk.mjs"). Although unofficial paths are discouraged, they do exist in the wild.Please confirm whether:
dist/esm/index.mjsis generated by the new build and published.- A deprecation notice or compatibility shim is required.
🧹 Nitpick comments (3)
packages/clerk-js/package.json (1)
34-38: Build script now performs two full builds – consider sequencing & caching
"build:bundle": "pnpm clean && rspack … && rslib build"means
1️⃣ clean → 2️⃣ Rspack build (CJS, UMD, etc.) → 3️⃣ Rslib ESM build.
Running two full compilers back-to-back significantly increases CI time and can double compile-time type-checking.Optional refactor: invoke
rslibfirst, then reuse TS program outputs (or at least skiptscinsiderslib) to avoid duplicate work, or gate the second build behind an env flag while the experiment is in flight.packages/clerk-js/rslib.config.ts (2)
1-5: Sort import groups to satisfy ESLint / simple-import-sortESLint reports unsorted imports. Apply:
-import { defineConfig } from '@rslib/core'; -import { pluginReact } from '@rsbuild/plugin-react'; -import { pluginSvgr } from '@rsbuild/plugin-svgr'; +import { defineConfig } from '@rslib/core'; +import { pluginReact } from '@rsbuild/plugin-react'; +import { pluginSvgr } from '@rsbuild/plugin-svgr'; + import packageJSON from './package.json';(Only the blank line needs moving.)
9-18: Hard-coding production flags removes flexibilityAll compile-time constants are set to production values. For local debugging a bundleless dev build could be handy. Consider parameterising via
process.env.BUILD_ENV(defaulting to production) sorslib build --mode developmentremains possible.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
packages/clerk-js/package.json(3 hunks)packages/clerk-js/rslib.config.ts(1 hunks)packages/clerk-js/rspack.config.js(0 hunks)
💤 Files with no reviewable changes (1)
- packages/clerk-js/rspack.config.js
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/package.jsonpackages/clerk-js/rslib.config.ts
packages/*/package.json
📄 CodeRabbit Inference Engine (.cursor/rules/global.mdc)
All publishable packages should be placed under the packages/ directory
packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.
Files:
packages/clerk-js/package.json
**/*
⚙️ CodeRabbit Configuration File
**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.Whenever reviewing a pull request, if there are any changes that could impact security, always tag
@clerk/securityin the PR.Security-impacting changes include, but are not limited to:
- Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
- Any modification to access control, authorization checks, or role-based permissions
- Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
- Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
- Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
- Modifications to security headers, cookie flags, CORS policies, or CSRF protections
- Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
- Changes to rate limiting, abuse prevention, or input validation
If you're unsure whether a change is security-relevant, err on the side of caution and tag
@clerk/security.Any time that you tag
@clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.
Files:
packages/clerk-js/package.jsonpackages/clerk-js/rslib.config.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/rslib.config.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/rslib.config.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/rslib.config.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/rslib.config.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/clerk-js/rslib.config.ts
🧬 Code Graph Analysis (1)
packages/clerk-js/rslib.config.ts (1)
packages/clerk-js/rspack.config.js (1)
packageJSON(3-3)
🪛 ESLint
packages/clerk-js/rslib.config.ts
[error] 1-5: Run autofix to sort these imports!
(simple-import-sort/imports)
🔇 Additional comments (4)
packages/clerk-js/package.json (1)
82-86: Verify dev-dependency alignment & workspace hoistingThe three new packages (@rsbuild/plugin-react, @rsbuild/plugin-svgr, @rslib/core) are added as devDependencies here.
• If any of them are required at runtime (e.g. imported by generated code), they must move todependencies.
• Ensure the root workspace installs matching versions to avoid duplication in lockfiles.packages/clerk-js/rslib.config.ts (3)
5-5: Ensure TS config supports JSON imports
import packageJSON from './package.json'requiresresolveJsonModule: truein the package’stsconfig.json. Verify this flag is enabled, otherwise the build will fail under strict TS compilation.
20-26: ESM output path matches package.json – looks good
lib.format = 'esm'withbundle: falseanddistPath.root = './dist/esm'aligns with the updated"module"field. ✅
31-39: React SWC options – double-check automatic runtime + EmotionUsing
runtime: 'automatic'withimportSource: '@emotion/react'is correct for Emotion 11, but it disables React Refresh. Ensure this is intentional; otherwise setrefresh: truein non-prod builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/clerk-js/rslib.config.ts (2)
1-6: Fix import-order violation flagged by ESLint
simple-import-sortreports a deterministic ordering issue (Lines 1-5). Run the fixer or manually re-order the groups to keep CI green.-import { defineConfig } from '@rslib/core'; -import { pluginReact } from '@rsbuild/plugin-react'; -import { pluginSvgr } from '@rsbuild/plugin-svgr'; - -import packageJSON from './package.json'; +import { defineConfig } from '@rslib/core'; +import { pluginReact } from '@rsbuild/plugin-react'; +import { pluginSvgr } from '@rsbuild/plugin-svgr'; + +import packageJSON from './package.json';
19-20: Avoid hard-coding environment flags to “production”Locking
process.env.NODE_ENVandprocess.env.CLERK_ENVto'production'at build time prevents tree-shaking or debugging builds that rely on the actual environment. Consider forwarding the current env with a fallback:- 'process.env.CLERK_ENV': JSON.stringify('production'), - 'process.env.NODE_ENV': JSON.stringify('production'), + 'process.env.CLERK_ENV': JSON.stringify(process.env.CLERK_ENV ?? 'production'), + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'production'),This preserves existing behaviour while keeping the config flexible for dev/test pipelines.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (1)
packages/clerk-js/rslib.config.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/rslib.config.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/rslib.config.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/rslib.config.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/rslib.config.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/rslib.config.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/clerk-js/rslib.config.ts
**/*
⚙️ CodeRabbit Configuration File
**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.Whenever reviewing a pull request, if there are any changes that could impact security, always tag
@clerk/securityin the PR.Security-impacting changes include, but are not limited to:
- Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
- Any modification to access control, authorization checks, or role-based permissions
- Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
- Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
- Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
- Modifications to security headers, cookie flags, CORS policies, or CSRF protections
- Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
- Changes to rate limiting, abuse prevention, or input validation
If you're unsure whether a change is security-relevant, err on the side of caution and tag
@clerk/security.Any time that you tag
@clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.
Files:
packages/clerk-js/rslib.config.ts
🧬 Code Graph Analysis (1)
packages/clerk-js/rslib.config.ts (1)
packages/clerk-js/rspack.config.js (1)
packageJSON(3-3)
🪛 ESLint
packages/clerk-js/rslib.config.ts
[error] 1-5: Run autofix to sort these imports!
(simple-import-sort/imports)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
| define: { | ||
| __DEV__: false, | ||
| __PKG_NAME__: JSON.stringify(packageJSON.name), | ||
| __PKG_VERSION__: JSON.stringify(packageJSON.version), | ||
| __BUILD_FLAG_KEYLESS_UI__: false, | ||
| __BUILD_DISABLE_RHC__: JSON.stringify('false'), | ||
| __BUILD_VARIANT_CHIPS__: false, | ||
| 'process.env.CLERK_ENV': JSON.stringify('production'), | ||
| 'process.env.NODE_ENV': JSON.stringify('production'), | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Align compile-time constants to a single primitive type
__BUILD_DISABLE_RHC__ is injected as the string "false" whereas the neighbouring flags are injected as booleans.
If downstream code does if (__BUILD_DISABLE_RHC__) the branch behaviour will differ from the others.
- __BUILD_DISABLE_RHC__: JSON.stringify('false'),
+ __BUILD_DISABLE_RHC__: false,Double-check any code paths that expect a string before applying.
🏁 Script executed:
#!/bin/bash
rg "__BUILD_DISABLE_RHC__" -n -C2Length of output: 5820
Align __BUILD_DISABLE_RHC__ to a boolean primitive
The __BUILD_DISABLE_RHC__ flag is currently injected as a string literal (“false”) but used in boolean contexts—causing "false" to be truthy at runtime. Let’s switch it to a real boolean and keep your type defs in sync:
• In packages/clerk-js/rslib.config.ts
define: {
@@
- __BUILD_DISABLE_RHC__: JSON.stringify('false'),
+ __BUILD_DISABLE_RHC__: false,
},• In packages/clerk-js/src/global.d.ts
- declare const __BUILD_DISABLE_RHC__: string;
+ declare const __BUILD_DISABLE_RHC__: boolean;• Also update other bundler configs for consistency:
– packages/clerk-js/rspack.config.js
– packages/chrome-extension/tsup.config.ts
Double-check that no code path relies on a string value before landing these changes.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| define: { | |
| __DEV__: false, | |
| __PKG_NAME__: JSON.stringify(packageJSON.name), | |
| __PKG_VERSION__: JSON.stringify(packageJSON.version), | |
| __BUILD_FLAG_KEYLESS_UI__: false, | |
| __BUILD_DISABLE_RHC__: JSON.stringify('false'), | |
| __BUILD_VARIANT_CHIPS__: false, | |
| 'process.env.CLERK_ENV': JSON.stringify('production'), | |
| 'process.env.NODE_ENV': JSON.stringify('production'), | |
| }, | |
| // packages/clerk-js/rslib.config.ts | |
| define: { | |
| __DEV__: false, | |
| __PKG_NAME__: JSON.stringify(packageJSON.name), | |
| __PKG_VERSION__: JSON.stringify(packageJSON.version), | |
| __BUILD_FLAG_KEYLESS_UI__: false, | |
| - __BUILD_DISABLE_RHC__: JSON.stringify('false'), | |
| + __BUILD_DISABLE_RHC__: false, | |
| __BUILD_VARIANT_CHIPS__: false, | |
| 'process.env.CLERK_ENV': JSON.stringify('production'), | |
| 'process.env.NODE_ENV': JSON.stringify('production'), | |
| }, |
🤖 Prompt for AI Agents
In packages/clerk-js/rslib.config.ts lines 12 to 21, the __BUILD_DISABLE_RHC__
flag is set as a string "false" but used as a boolean, causing incorrect
truthiness. Change its value to the boolean false instead of a string. Also
update the corresponding type definitions in packages/clerk-js/src/global.d.ts
and ensure the same boolean usage is reflected in other bundler configs like
packages/clerk-js/rspack.config.js and packages/chrome-extension/tsup.config.ts.
Verify no code depends on the string form before applying these changes.
|
The ESM bundle being emitted seems well formed, but I think we might have some circular dependency issues. Vite's dev server has issues resolving |
|
Hello 👋 We currently close PRs after 60 days of inactivity. It's been 50 days since the last update here. If we missed this PR, please reply here. Otherwise, we'll close this PR in 10 days. Thanks for being a part of the Clerk community! 🙏 |
|
Hello 👋 We currently close PRs after 60 days of inactivity. It's been 50 days since the last update here. If we missed this PR, please reply here. Otherwise, we'll close this PR in 10 days. Thanks for being a part of the Clerk community! 🙏 |
Description
(This PR is technically a draft; the pr.pkg.new workflow doesn't run on draft PRs.)
This experimental PR adds support for building a "bundleless" version of
clerk-js, specifically the ESM build. More details to come if this experiment proves successful!Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit