typesense / typesense-js

JavaScript / TypeScript client for Typesense
https://typesense.org/docs/api
Apache License 2.0
393 stars 74 forks source link

build: enable `importHelpers` to avoid duplicating helpers #208

Closed arturovt closed 2 months ago

arturovt commented 2 months ago

In ES5 code, TypeScript relies on specific helpers (such as __spreadArrays()) to support ES2015+ features. These helpers can be either imported from tslib (by enabling the importHelpers TS compiler option) or inserted inline (by disabling both importHelpers and noEmitHelpers, which are both initially set to false).

Currently, the helpers are directly inserted into each JavaScript module, resulting in a larger final size compared to importing them from the tslib library. Therefore, in this commit, we enable the importHelpers option and include tslib as a dependency.

jasonbosco commented 2 months ago

Thank you for the PR @arturovt.

I'm not a Typescript expert, but does this change result in any backward incompatible changes for existing users of this library who upgrade to this version?

arturovt commented 2 months ago

@jasonbosco When users upgrade to the newer version and run npm install, npm will add tslib as a dependency, and the new code will simply require helpers from the tslib.

Enabling importHelpers in the library doesn't change its external API or behavior, so existing consumers should still be able to use library without any modifications.

TypeScript will insert helper functions from tslib into the compiled code instead of duplicating them in each file where they're used, thereby reducing the size of the compiled code.

jasonbosco commented 2 months ago

Thank you for the additional context. That was helpful!

jasonbosco commented 2 months ago

Published this in v1.9.0-7