-
Notifications
You must be signed in to change notification settings - Fork 8
ESM support & various other compat improvements #100
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
toptobes
added a commit
that referenced
this pull request
Apr 7, 2025
* update eslint config * run eslint --fix + fix other linting issues * added & fixed consistent-type-* lints * migrated source code to esm * made tests run using tsx/esm import * removed hard unstable dep on fetch-h2... now defaults to plain fetch by default * removed hard unstable dep on events... now uses minimal event emitter implementaiton * added dual support for cjs & esm * use tslib * update examples to work with latest version of astra-db-ts * fixed node10 & node16:cjs type resolution issues * update examples to reflect new compat changes * update some http options documentation * update readme
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-ts
to target both CJS & ESM ❗astra-db-ts
has 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-ts
as CJS may continue to do so without any issues.Types were verified using
@arethetypeswrong/cli
and some manual testing.Import path conversions were done using
ts2esm
.The new
dist
structure looks like so:And the root
package.json
was 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-h2
andevents
for 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:events
await
not always supportedTo simplify everything:
fetch-h2
is no longer the default HTTP client forastra-db-ts
.astra-db-ts
now defaults to using the standardfetch
API.If you want to use
fetch-h2
, you need to install it yourself (npm i fetch-h2
) and pass it as an option:DataAPIClient
is no longer a Node-compliantEventEmitter
It now uses a custom, micro
EventEmitter
implementation (how original, I know 🙄)This improves compatibility across different environments while keeping things simple.
As a bonus, the
typed-emitter
dependency was able to be removed, sinceMicroEmitter
is natively typedUses
tslib
w/importHelpers
to save a few bytes of bundle sizeyaaaaayyyyyyyy