EasyPost / easypost-node

EasyPost Shipping API Client Library for Node
https://easypost.com/docs/api
MIT License
139 stars 54 forks source link

Removes Webpack/Babel in favor of SWC #461

Closed ralexmatthews closed 4 months ago

ralexmatthews commented 4 months ago

Description

In its current state, the node library uses a webpack + babel build pipeline to bundle the whole library into one big CommonJS bundle. It uses maybe a dozen different webpack and babel settings, configs, plugins, etc to do this as well. This is probably not ideal for several reasons.

Enter SWC, the Babel replacement written in Rust. It is a dependency of Turbopack, Vercel's new transpiler/bundler for Next.js, and seems to be the current future.

As part of this move to SWC, I have also created both a CommonJS and ES6 build of the app to support the movement of the community away from CommonJS.

Getting rid of all the babel deps also removes these warnings when running npm install:

npm WARN deprecated @babel/plugin-proposal-export-namespace-from@7.18.9: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
npm WARN deprecated @babel/plugin-proposal-unicode-property-regex@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-unicode-property-regex instead.
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.

Overall, this greatly reduces the number of dependencies, config files, and improves support for CJS and ESM projects.

Also fixes https://github.com/EasyPost/easypost-node/issues/446. I was able to replicate the error by creating a new Nest app, and by changing the version to this, it fixes that error.

Also fixes https://github.com/EasyPost/easypost-node/issues/456 by exporting all errors and models from the root.

Testing

All tests are still passing, thanks to swapping out babel/register to swc-node/register

Pull Request Type

Please select the option(s) that are relevant to this PR.