-
Notifications
You must be signed in to change notification settings - Fork 3
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
add commonjs support, remove type: module #118
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
nit: can you update the PR title since this doesn't use an esm wrapper? |
cea2aj
approved these changes
May 4, 2022
updated! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds commonjs support by separating the tsconfig into esm and commonjs versions,
updating our api extractor config, and using conditional exports to provide the right entry point.
At one point, this PR added commonjs support by instead building the library with module: commonjs,
and adding a thin esm wrapper to also support es6 syntax.
This was in order to prevent the dual package hazard documented in
https://nodejs.org/api/packages.html#dual-commonjses-module-packages
and
https://github.com/GeoffreyBooth/dual-package-hazard/blob/master/index.mjs
However, from personal testing vite was not able to tree shake our esm-wrapper.
Furthermore, the dual package hazard is primarily a concern when different plugin-like libraries
are written around some central library, for example if people were to write extensions of
answers-headless-react, and these extensions were written in a mix of only esm and only cjs.
Then, users who tried to use both plugins would find themselves with the dual package hazard.
This scenario is very unlikely because we can expect the vast majority of new code to be written in esm.
As a general trend ESM is the new standard for JS libraries, and is also promoted by typescript.
J=SLAP-2074
TEST=manual
test that the dev command works - I can hook up a local answers-headless-react to a local
project, and changes in answers-headless-react will automatically be reflected in my project
test that answers-headless-react works with yext sites SSR in both prod and dev mode
this was tested using npm pack