-
Notifications
You must be signed in to change notification settings - Fork 242
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
refactor: ESM and CJS transpilation #1067
Conversation
…s, and browserify bundling
|
554855d
to
5960b51
Compare
9149734
to
e98d2f2
Compare
Superseded by #1353 |
Pre-flight checklist
Motivation
This PR updates the new packages to support ESM and CJS transpilation from the TypeScript source. By supporting ESM modules we remove hurdles for working with new versions of NodeJS and ESM-based frameworks like Vite, addressing longstanding issues for developers.
Worth noting in this PR:
exports
andbrowser
.exports
points the consumer tolib/cjs
forrequire
imports andlib/esm
for nativeimport
.browser
referenceslib/cjs
and is currently required fornear-api-js
to build its bundle withbrowserify
.import
/export
and requiring that relative paths to JS modules include.js
file extensions.lib/esm
are tested currently. It may be overkill to also test the CJS output 🤔Test Plan
This is entirely a packaging change and so only affects consumers, not any specific runtime functionality. The new
example-esm
andexample-vite
packages have been added to demonstrate usage with native modules. Local testing has been done by runningnear-wallet
locally afteryarn link
ing the newnear-api-js
package, and current bundles have been compared to those produced by the changes in this PR.Related issues/PRs
This is the most directly-relevant one I found at a glance, but the cascading goodness stemming from this change (on top of breaking NAJ into packages) will likely resolve other issues related to polyfills, bundling, and other usage issues.