ESM support & various other compat improvements #100
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
woohoo yay 100th pr yay whatever ok with that out of the way, this PR:
Allows
astra-db-tsto target both CJS & ESM ❗astra-db-tshas been updated to dual-target both CommonJS (CJS) and ECMAScript Modules (ESM).While the package itself has been converted into pure ESM, it now transpiles in a way that should seamlessly support both module systems.
Users who were previously using
astra-db-tsas CJS may continue to do so without any issues.Types were verified using
@arethetypeswrong/cliand some manual testing.Import path conversions were done using
ts2esm.The new
diststructure looks like so:And the root
package.jsonwas updated to hold the new values:ESlint configs were updated to be type-aware
consistent-type-*lints were necessary to update to ESM (requiring types to be explicitly imported/exported withimport type/export type)As a result, this surfaced a wave of new linting errors, which have been fixed—though none of these changes should introduce any functional differences.
Removes hard dependencies on
fetch-h2andeventsfor better environment compatibilityIt's simply too painful & error-prone to deal with optional deps between CJS, ESM, and different runtime environments in general
require()vsawait import()node:eventsawaitnot always supportedTo simplify everything:
fetch-h2is no longer the default HTTP client forastra-db-ts.astra-db-tsnow defaults to using the standardfetchAPI.If you want to use
fetch-h2, you need to install it yourself (npm i fetch-h2) and pass it as an option:DataAPIClientis no longer a Node-compliantEventEmitterIt now uses a custom, micro
EventEmitterimplementation (how original, I know 🙄)This improves compatibility across different environments while keeping things simple.
As a bonus, the
typed-emitterdependency was able to be removed, sinceMicroEmitteris natively typedUses
tslibw/importHelpersto save a few bytes of bundle sizeyaaaaayyyyyyyy