node, browser bundles, esm, cjs, and all that stuff #2544
Replies: 5 comments 3 replies
-
For node runtimes, I think we should probably only officially support nodejs versions that are still support from nodejs itself. Right now I think that's 21, 20, and 18. I think that lets us use a typescript target of es2022 and import/export syntax for modules. If we take that and run it through caniuse for browser support, you get a slightly worse story (scroll down to the Feature Summary section). Safari got support for its last feature pretty late (in 2023) which feels a little uncomfortable. es2021 is a bit better. That probably gets us enough browser support that anyone consuming our modules directly into their bundles is unlikely to need to transpile our code? We might also just take the standpoint that if you're consuming our stuff, we target esnext and you should transpile them to your desired browser support. I know how to accomplish this in a bundling step, but perhaps its too large of a barrier to impose on our consumers who may be less familiar with how to set this sort of thing up. Separately, we have a browser target for @turfjs/turf, we could potentially pick an even earlier target to provide better compatibility across the board for that file. |
Beta Was this translation helpful? Give feedback.
-
Thanks @mfedderly . Summarising all the dimensions to help keep track: Ecmascript target version: Do we want to stick with something even older than es2021? es2017 for example would let Svelte, React Native, and a few others use us without needing to further transpile. Unless we need new language features, we should go with the oldest target possible yes? turf-min browser target: same as the above node module resolution: We could make it esnext (currently node16) though what happens when esnext recalibrates to point to something newer? Lock it at node16? ESM first: From what I understand we currently take a "CJS first" approach. Modules are assumed to contain commonjs except for the /dist/es directory where we plonk a We could potentially tidy this up by switching to an ESM first approach, and using the .cjs file extension to identify the legacy commonjs parts? So we would go from:
To this:
Then those three entry points are listed in the module package.json. Sure to be some wrinkles around export code from old 3rd party libraries. The above seems like it would work and be simpler in the majority of cases. |
Beta Was this translation helpful? Give feedback.
-
Going to retire our two rollup-plugins also. Can't see where either of them are used any more:
|
Beta Was this translation helpful? Give feedback.
-
I'm open to any level of ecmascript target version, preferably as high as we think we can reasonably make it given consumer needs. |
Beta Was this translation helpful? Give feedback.
-
PR #2555 created as a result of this discussion and #2400 🎉 Thanks for all your thoughts. |
Beta Was this translation helpful? Give feedback.
-
Before v7 release is it worth working through the environments we want Turf to be compatible in? Node and browser, ESM and CJS, etc. There might be some old build artefacts we can remove now given how much typescript, rollup, etc have progressed in the last four or five years.
Any pain points you know of or suggestions where to start?
Beta Was this translation helpful? Give feedback.
All reactions