Skip to content

remove class-validator and rejigger types loading to shrink bundles - #3312

Draft
danoswaltCL wants to merge 2 commits into
devfrom
wip/reduce-js-bundle-size
Draft

danoswaltCL wants to merge 2 commits into
devfrom
wip/reduce-js-bundle-size

Conversation

@danoswaltCL

Copy link
Copy Markdown
Collaborator
  • removing the need for UpgradeClient.BINARY_REWARD_VALUE as an import from upgrade_types allows for rejiggering the building of types so we can slice out class-validator from our bundle, which hugely reduces the bundle size (the lite version used by cli-services will go from 400kb to 36kb, it was really that bad)

  • also removes a double-bundling of tslib which was apparently happening 🤷

  • also quicktest now has a good built-in way of testing the lite bundle

…update quicktest to include easy lite lib testing
@danoswaltCL
danoswaltCL requested review from bcb37 and zackcl and a lite review from Copilot September 4, 2026 15:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new lite quick-test HTTP client and scripts have correctness issues that can cause runtime failures (header normalization in fetch wrapper; build-skip logic in quicktest scripts).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors the JS clientlib to import only the needed upgrade_types submodules (interfaces/enums) so the bundled SDK can avoid pulling in class-validator, significantly shrinking the “lite” bundle; it also dedupes tslib in the webpack build and improves local smoke-testing for the lite bundle.

Changes:

  • Switches many upgrade_types imports to upgrade_types/Experiment/{interfaces,enums} and introduces a local BINARY_REWARD_VALUE enum to avoid importing reward types from upgrade_types.
  • Forces webpack to resolve a single physical tslib to prevent double-bundling.
  • Adds a lite-bundle quick test path (BYO HTTP client) and a minimal fetch-based IHttpClientWrapper for smoke tests.
File summaries
File Description
clientlibs/js/webpack.config.ts Adds a tslib alias to prevent webpack from bundling multiple tslib copies.
clientlibs/js/tsconfig.json Adjusts TS project root/paths and includes quick test files for typechecking.
clientlibs/js/src/UpGradeClient/UpgradeClient.ts Repoints type imports to narrower upgrade_types/Experiment/* modules and swaps BINARY_REWARD_VALUE to a local enum.
clientlibs/js/src/types/requests.ts Updates enum import to upgrade_types/Experiment/enums.
clientlibs/js/src/types/Interfaces.ts Updates enum import to upgrade_types/Experiment/enums.
clientlibs/js/src/types/enums.ts Adds UpGradeClientEnums.BINARY_REWARD_VALUE enum for SDK consumers.
clientlibs/js/src/index.ts Updates named export imports to narrower upgrade_types/Experiment/* modules.
clientlibs/js/src/DataService/DataService.ts Updates assignment type import to upgrade_types/Experiment/interfaces.
clientlibs/js/src/Assignment/Assignment.ts Splits interface/enums imports to upgrade_types/Experiment/{interfaces,enums}.
clientlibs/js/src/ApiService/ApiService.ts Updates request/log type imports to upgrade_types/Experiment/interfaces.
clientlibs/js/quickTestLiteHttpClient.ts Adds a minimal fetch-based HTTP client wrapper for lite bundle smoke testing.
clientlibs/js/quickTest.ts Adds variant selection to test node vs lite bundle and unifies error logging across HTTP clients.
clientlibs/js/package.json Adds quicktest:lite and updates quicktest scripts.
Review details
  • Files reviewed: 13/13 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread clientlibs/js/package.json Outdated
Comment thread clientlibs/js/quickTestLiteHttpClient.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@bcb37

bcb37 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

It seems unnecessary to define an enum in two places, which we'd have to keep in sync manually. The BinaryRewardAllowedValue enum is inert and only pulls class-validator along with it because it's defined in a file that imports reflect-metadata. If we move the inert exports to a separate file and import them where they're needed in Mooclet/index.ts, they can be imported directly using the deep path, like the other enums from Experiment/...
Maybe it doesn't matter that much if we're getting rid of the mooclet stuff, but if we're keeping the binary rewards enum it might be a good idea to move that now, so we're not defining and maintaining it in two places going forward.

@danoswaltCL

Copy link
Copy Markdown
Collaborator Author

i didn't think about the fact that the mooclet-removal already does the major work here in removing class-validator as a factor at all in upgrade_types, and it does do this enum more sensibly, and the build reflects that because it's 44kb instead 400+.

There are a couple other smaller wins in this PR that bring it down to ~36kb, but might as well hold off on this one until the mooclet-removal pr is in.

@danoswaltCL
danoswaltCL marked this pull request as draft September 9, 2026 18:58
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.

3 participants