Skip to content
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

build: enable importHelpers to avoid duplicating helpers #208

Merged
merged 1 commit into from
May 29, 2024
Merged

build: enable importHelpers to avoid duplicating helpers #208

merged 1 commit into from
May 29, 2024

Conversation

arturovt
Copy link
Contributor

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
Copy link
Member

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?

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.
@arturovt
Copy link
Contributor Author

@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
Copy link
Member

Thank you for the additional context. That was helpful!

@jasonbosco jasonbosco merged commit d6b65a6 into typesense:master May 29, 2024
1 check passed
@arturovt arturovt deleted the build/use-helpers branch May 29, 2024 18:27
@jasonbosco
Copy link
Member

Published this in v1.9.0-7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants