-
Notifications
You must be signed in to change notification settings - Fork 142
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
⚡️ [RUMF-1043] remove TSLib dependency #1347
Conversation
This commit makes tsc output its helpers directly in each module files, instead of trying to import tslib.
The assign function now returns the first argument, as Object.assign does. Typings inspired from: https://github.com/microsoft/TypeScript/blob/main/lib/lib.es2015.core.d.ts#L280-L305
4999eea
to
9f58edd
Compare
Codecov Report
@@ Coverage Diff @@
## main #1347 +/- ##
==========================================
+ Coverage 91.07% 91.14% +0.07%
==========================================
Files 104 104
Lines 4268 4268
Branches 950 950
==========================================
+ Hits 3887 3890 +3
+ Misses 381 378 -3
Continue to review full report at Codecov.
|
💭 thought: I get the gain of this PR but of course I'm not a big fan to forbid object and array spread. |
Motivation
We observed that sometimes, our Browser SDK NPM packages is used with a bundler configuration which does not always remove unused parts of TSLib (ex: when using Webpack with a
resolve.mainFields
set to"main"
). In this case, TSLib adds a large amount of unused code to the user bundle. This is one of the actions identified to reduce the SDK size.Our TSLib version is also a bit old, and our users are probably using a newer, incompatible version, which could produce duplicate code in the bundle (see #1183).
Changes
This PR removes the TSLib dependency and replace its usage with inlined TS helpers via the
importHelpers
TS config.By doing so, the bundle grows a bit because helpers are duplicated in various modules. To mitigate this, this PR also forbid two syntaxes (object and array spread) that are known to produce such helpers (respectively
assign
and spreadArrays).Note: some TS helpers are still used:
decorate
, used by the Logger class. Because it is used a single time, no need to change / factorize it.commonjs module declaration helpers, which are used when using tsc to produce commonjs modules. Those can't really be replaced with alternative code without important drawbacks. In total, those two functions are duplicated 4 times in core and 3 times in rum. This may be improved by shiping pre-built NPM packages.
Testing
To verify that our build does not produce more code than before, I run
yarn build
on both the PR branch and onmain
(in two different directories), and compare the result with something like:The difference should be minimal.
I have gone over the contributing documentation.