Revamp clerk-sdk-node build#612
Merged
Merged
Conversation
nikosdouvlis
force-pushed
the
js-66-fix-clerk-sdk-node-esm-export_
branch
from
December 13, 2022 02:49
d2685e3 to
3084825
Compare
nikosdouvlis
requested review from
SokratisVidros,
anagstef,
desiprisg,
raptisj and
yourtallness
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, |
|
|
||
| import { name, version } from './package.json'; | ||
|
|
||
| console.log({ name, version }); |
This file contains hidden or 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
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/sharedbuild/tooling/choreDescription
npm testruns as expected.npm run buildruns as expected.This PR introduces changes to the build process of the
clerk/clerk-sdk-nodepackage. Specifically,tsupinstead oftsc/esmand/cjspaths while retaining their default exportsexportsfield in package.json in preparation forclerk/clerk-sdk-node@5Supporting all possible host app build configurations (module vs commonjs, pure JS vs TS, and the various
moduleResolutionstrategies 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-nodecurrently.1. Host application configured as a module, or Clerk is used within a module file
This scenario includes one of the following cases:
.mjsfile, or.jsfile and host app'spackage.jsonincludes"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:
.cjsfile, or.jsfile and host app'spackage.jsonincludes"type": "commonjs"or it does not explicitly specify atype3. Host application is configured as a module and is using TS
package.jsonincludes"type": "module"tsconfig.jsonsets"module": "ESNext"(or other module strategies)tsconfig.jsonsets"moduleResolution": "Node"With the above settings, the generated js file will be a module file. The user can import from
/esmand 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
/cjsbut they'll need to also use the.defaultprop:4. Host application is configured as a commonjs package and is using TS
package.jsonincludes"type": "commonjs"tsconfig.jsonsets"module": "Commonjs"(or other commonjs strategies)tsconfig.jsonsets"moduleResolution": "Node"With the above settings, the generated js file will be a commonjs file. The user can import from
/cjsand 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 theexportsfield 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.tstod.mtsmanually so they are always handled as modules.Plan for v5
v5 will be released once we finish refactoring the package to use the new
backendpackage. 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:
exportsfield:What will change:
/cjsand/esmpaths will no longer be needed/and/instnacepath would handle both esm and cjs formats automatically through theexportsfieldexportsfieldLet me hear your thoughts, happy to discuss further :)