-
Notifications
You must be signed in to change notification settings - Fork 258
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
Revamp clerk-sdk-node build #612
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nikosdouvlis
force-pushed
the
js-66-fix-clerk-sdk-node-esm-export_
branch
from
December 13, 2022 02:49
d2685e3
to
3084825
Compare
nikosdouvlis
changed the title
Js 66 fix clerk sdk node esm export
Revamp clerk-sdk-node build
Dec 13, 2022
nikosdouvlis
requested review from
SokratisVidros,
anagstef,
yourtallness,
desiprisg and
raptisj
December 13, 2022 03:39
nikosdouvlis
force-pushed
the
js-66-fix-clerk-sdk-node-esm-export_
branch
from
December 13, 2022 03:47
3084825
to
0491215
Compare
desiprisg
approved these changes
Dec 13, 2022
anagstef
reviewed
Dec 13, 2022
anagstef
approved these changes
Dec 13, 2022
dimkl
reviewed
Mar 21, 2023
onSuccess: 'tsc', | ||
clean: true, | ||
// minify: isProd, | ||
minify: false, |
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.
❓ why is minify: false
?
|
||
import { name, version } from './package.json'; | ||
|
||
console.log({ name, version }); |
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.
✂️
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of change
Packages affected
@clerk/clerk-js
@clerk/clerk-react
@clerk/nextjs
@clerk/remix
@clerk/types
@clerk/themes
@clerk/localizations
@clerk/clerk-expo
@clerk/backend
@clerk/backend-core
@clerk/clerk-sdk-node
@clerk/edge
@clerk/shared
build/tooling/chore
Description
npm test
runs as expected.npm run build
runs as expected.This PR introduces changes to the build process of the
clerk/clerk-sdk-node
package. Specifically,tsup
instead oftsc
/esm
and/cjs
paths while retaining their default exportsexports
field in package.json in preparation forclerk/clerk-sdk-node@5
Supporting all possible host app build configurations (module vs commonjs, pure JS vs TS, and the various
moduleResolution
strategies that can be used by TS) without introducing breaking changes to the exports of this package is impossible right now.This PR correctly supports the APIs we've exported so far, with slight modifications that should improve compatibility with the latest node and TS versions.
Currently, the following formats are supported. Any other config combinations the host app package.json / tsconfig files should be invalid, except for the single scenario described in the Caveats section which is a valid config but cannot be supported by
clerk-sdk-node
currently.1. Host application configured as a module, or Clerk is used within a module file
This scenario includes one of the following cases:
.mjs
file, or.js
file and host app'spackage.json
includes"type": "module"
2. Host application configured as a commonjs package, or Clerk is used within a commonjs file
This scenario includes one of the following cases:
.cjs
file, or.js
file and host app'spackage.json
includes"type": "commonjs"
or it does not explicitly specify atype
3. Host application is configured as a module and is using TS
package.json
includes"type": "module"
tsconfig.json
sets"module": "ESNext"
(or other module strategies)tsconfig.json
sets"moduleResolution": "Node"
With the above settings, the generated js file will be a module file. The user can import from
/esm
and use Clerk directly:Although unusual, importing a commonjs module is also supported in this case because the generated file is a module. The user can import Clerk from
/cjs
but they'll need to also use the.default
prop:4. Host application is configured as a commonjs package and is using TS
package.json
includes"type": "commonjs"
tsconfig.json
sets"module": "Commonjs"
(or other commonjs strategies)tsconfig.json
sets"moduleResolution": "Node"
With the above settings, the generated js file will be a commonjs file. The user can import from
/cjs
and use Clerk directly:Caveats
If the host package uses TS and sets
"moduleResolution": "NodeNext"
or"moduleResolution": "Node16"
intsconfig.json
, the types for the default import will not be correctly inferred, so TS will throw an error during compilation even though the runtime value is correct. If these two new module resolution strategies are used, TS will respect theexports
field in package.json, however the correct types will not always be inferred because our package exports both default and named exports which are handled differently in ESM and CJS modules.Possible solutions for the above:
d.ts
tod.mts
manually so they are always handled as modules.Plan for v5
v5 will be released once we finish refactoring the package to use the new
backend
package. I'd suggest we also refactor our exports according to option 3 at the same time, because it is a breaking change.What we need to do:
exports
field:What will change:
/cjs
and/esm
paths will no longer be needed/
and/instnace
path would handle both esm and cjs formats automatically through theexports
fieldexports
fieldLet me hear your thoughts, happy to discuss further :)