Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 468
BREAKING(shared): Revamp package to use subpaths#1898
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
234a01a6c209ea46c5b55b5409e3ca49589ccd428221ec0ef0357351707247a3e85dafb6850a25d776fcabb5056c53ad696fdeaf530391c46477433ea774b674ddfcb797c495235e2e0c678874e271a800aa5f6854a52a685489c05506ab87fd38a3feb461d3a7b7af2ae0fa6d669ec91f653bd36fd977741e7c377f96e63e856cde7f7d4adf792232fb297983cfe183f0fdf78734a60d7d3a39e15af40bed6b727855fdcf6ba951514b6f3552195d24538e5626b3360fbb88f7847fcd65d64d9f9232b3e6bf6f8d0938176b4e081File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| "@clerk/shared": major | ||
| --- | ||
| The package was reworked to allow for better isomorphic use cases and ESM support, resulting in some breaking changes. It now allows for [subpath exports](https://nodejs.org/api/packages.html#subpath-exports) and restricts some imports to specific subpaths. | ||
| Instead of importing from the root `@clerk/shared` import you can now use subpaths for most things: | ||
| ```diff | ||
| - import { deprecated, OrganizationProvider } from "@clerk/shared" | ||
| + import { deprecated } from "@clerk/shared/deprecated" | ||
| + import { OrganizationProvider } from "@clerk/shared/react" | ||
| ``` | ||
| By using subpaths you can tell bundlers to only bundle specific parts, potentially helping with tree-shaking. It also mitigates issues where e.g. modules only relevant for React where picked up in Node.js-only environments. | ||
| If you're not using `@clerk/shared` directly (only by proxy through e.g. `@clerk/clerk-react`) you don't need to do anything. If you are relying on `@clerk/shared`, please read through the breaking changes below and change your code accordingly. You can rely on your IDE to give you hints on which exports are available at `@clerk/shared` and `@clerk/shared/<name>` subpaths. | ||
| **Breaking Changes** | ||
| - `@clerk/shared` was and still is a dual CJS/ESM package. The ESM files provided by `@clerk/shared` now use `.mjs` file extensions and also define them in their import paths, following the ESM spec. Your bundler should handle this for you. | ||
| - Some imports where moved from the root `@clerk/shared` import to isolated subpaths. | ||
| - Helper utils for cookies and globs: | ||
| ```diff | ||
| - import { createCookieHandler, globs } from "@clerk/shared" | ||
| + import { createCookieHandler } from "@clerk/shared/cookie" | ||
| + import { globs } from "@clerk/shared/globs" | ||
| ``` | ||
| - Everything related to React. Below is a small example and the full list of exports: | ||
| ```diff | ||
| - import { useSafeLayoutEffect, ClerkInstanceContext } from "@clerk/shared" | ||
| + import { useSafeLayoutEffect, ClerkInstanceContext } from "@clerk/shared/react" | ||
| ``` | ||
| Full list of exports moved to `@clerk/shared/react`: | ||
| ```ts | ||
| export { | ||
| ClerkInstanceContext, | ||
| ClientContext, | ||
| OrganizationContext, | ||
| OrganizationProvider, | ||
| SessionContext, | ||
| UserContext, | ||
| assertContextExists, | ||
| createContextAndHook, | ||
| useClerkInstanceContext, | ||
| useClientContext, | ||
| useOrganization, | ||
| useOrganizationContext, | ||
| useOrganizationList, | ||
| useOrganizations, | ||
| useSafeLayoutEffect, | ||
| useSessionContext, | ||
| useUserContext | ||
| } | ||
| ``` | ||
| If you run into an issues that might be a bug, please [open a bug report](https://github.com/clerkinc/javascript/issues/new?assignees=&labels=needs-triage&projects=&template=BUG_REPORT.yml) with a minimal reproduction. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,7 +7,10 @@ | ||
| "moduleResolution": "Node", | ||
| "noImplicitAny": false, | ||
| "outDir": "./tests/dist", | ||
| "target": "ES2020" | ||
| "target": "ES2020", | ||
| "paths": { | ||
| "@clerk/shared/*": ["../shared/dist/*.js"] | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switching | ||
| } | ||
| }, | ||
| "include": ["src/**/*.test.ts"], | ||
| "exclude": ["node_modules", "dist", "src/__tests__"] | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
When running the tests, this threw an error because for the
tsconfig.test.jsonthis didn't seem to fail. It's one of the quirks about ourtsconfigsetup so let's disregard it for this PRThere 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 we need to update the tests in
backendpackage to build withtsupinstead oftscandtsconfig.test.json. (that change is not part of the current PR)