Skip to content
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

Merged
merged 16 commits into from
Jan 17, 2025
Merged

Conversation

Acconut
Copy link
Member

@Acconut Acconut commented Jan 16, 2025

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, and browser fields, it can now utilize the new exports 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

@Acconut Acconut self-assigned this Jan 16, 2025
@Acconut Acconut marked this pull request as ready for review January 17, 2025 09:04
@Acconut Acconut linked an issue Jan 17, 2025 that may be closed by this pull request
@Acconut Acconut merged commit 14d583d into main Jan 17, 2025
8 of 10 checks passed
@Acconut Acconut deleted the exports branch January 17, 2025 09:05
@Acconut
Copy link
Member Author

Acconut commented Jan 20, 2025

Test pre-release in different scenarios (node/browser, JS/TS, different bundlers)

I did an extensive testing round using various setups and the pre-release v5.0.0-pre1 completed all of them. The tests included requiring the main package entry (tus-js-client), as well as a sub-path (e.g. tus-js-client/node/NodeHttpStack). In addition, I confirmed that it was not only able to load the packages, but can also complete a proper upload. If TypeScript was involved, I checked that TypeScript loaded the correct types and was able to spot type issues.

The tested scenarios were:

  • For Node.js:
    • CommonJS module requiring tus-js-client
    • ES module importing tus-js-client
    • TypeScript, compiled to CommonJS, importing tus-js-client
    • TypeScript, compiled to ESM, importing tus-js-client
  • For browsers:
    • ES module bundled by Webpack
    • ES module in TypeScript and bundled by Webpack
    • ES module bundled by Rollup
    • ES module bundled by Parcel
    • ES module bundled by esbuild
    • CommonJS script bundled by browserify

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refresh export structure in package.json
1 participant