-
Notifications
You must be signed in to change notification settings - Fork 319
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
Update export structure, change bundler, move tests to ESM #749
Conversation
Browserify does not support `exports` in `package.json`, so we replace it with Rollup. In addition, the tests are moved to ESM.
I did an extensive testing round using various setups and the pre-release The tested scenarios were:
Finally, arethetypeswrong and publint now don't report any errors anymore. All in all, I am quite confident that with these changes tus-js-client achieves wide support and is compatible with modern and legacy system. |
This PR started out as an attempt at changing how tus-js-client's package.json defines its exports (see #693). Instead of using only the
main
,module
, andbrowser
fields, it can now utilize the newexports
syntax to allow bundlers and loaders to correctly resolve to CommonJS or ESM and their corresponding types. In addition, it paves the way to definition subpaths for environment-specific functionality, e.g.tus-js-client/node/NodeHttpStack
.Along the way, I switched the bundler for building tus-js-client and its tests from Browserify to Rollup because browserify does not support the new
exports
structure. Additionally, I changed the tests from CommonJS to ESM, because Rollup itself only supports ESM. In the end, it turned out that this change was not strictly necessary since we needed to install a plugin that makes Rollup consume CommonJS because some of tus-js-client's dependencies are not ESM-compatible yet.To better supports loaders that don't understand the
exports
structure, tus-js-client also ships with fallbacks as explained in https://github.com/andrewbranch/example-subpath-exports-ts-compat/tree/main/examples/node_modules/package-json-redirects.Finally, arethetypeswrong and publint are installed as additional linters to ensure
TODOs
Make TypeScript emit sourcemaps, so rollup can consume the sourcemap and build from that.EDIT: Let's not do this because Rollup needs another plugin for consuming sourcemaps: Read existing source maps for imported modules rollup/rollup#4532