Skip to content

Core: Use slimsemver instead of semver - #35762

Closed
Damin3927 wants to merge 1 commit into
storybookjs:nextfrom
Damin3927:slimsemver
Closed

Damin3927 wants to merge 1 commit into
storybookjs:nextfrom
Damin3927:slimsemver

Conversation

@Damin3927

@Damin3927 Damin3927 commented Aug 5, 2026 •

Copy link
Copy Markdown

What I did

Swapped semver for slimsemver in code/core, and dropped the @types/semver devDependency since slimsemver ships its own types.

code/core pulls in all of semver, and part of that ends up in the manager bundle, which runs in the browser — dist/manager/globals-runtime.js contains semver's error strings, so the whole library is in there.

Core imports coerce, diff, gt, gte, major, minor, minVersion, patch, prerelease, satisfies, sort, valid and validRange. semver is CommonJS with no exports field, so a bundler can't drop the rest.

slimsemver is an API-compatible reimplementation that ships ESM and tree-shakes. For the set core uses that's 5.1 KB gzip instead of 24.6 KB — roughly 19 KB off a manager bundle that is currently ~373 KB gzip.

Only the import specifier and the dependency change; no call sites were touched.

Two things you should weigh:

  • I wrote slimsemver. Flagging that rather than letting you find it.
  • It's new — published this week. That's a fair reason to say no, or to revisit once it has a track record. I won't push back either way.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

The existing code/core unit tests cover the call sites, since nothing but the import specifier changed.

On the library itself: it runs a differential suite against semver on every commit — 119,796 cases comparing return values and thrown error types across the range grammar and all option combinations — plus a seeded fuzzer. I also ran core's exact call sites against both libraries side by side (301 checks, identical output). Happy to share that script if it's useful.

Manual testing

The browser-side usage is the version check in manager-api, so that's what's worth exercising:

  1. yarn task --task sandbox --start-from auto --template react-vite/default-ts
  2. Open the sandbox in a browser
  3. Open the About Storybook page from the sidebar's ⚙ menu — it should show the current version and, if an update is available, the upgrade notice with a correct version comparison and a working "read the changelog" link
  4. Check the browser console for errors from the manager bundle

If it's easier, temporarily setting versions.latest to something higher than the local version in code/core/src/manager-api/modules/versions.ts will force the upgrade path.

I haven't run the monorepo build locally, so CI is the real check here.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update MIGRATION.MD

No user-facing behaviour changes, so no docs needed.

semver ships in the manager bundle, which runs in the browser. slimsemver is
a drop-in replacement that tree-shakes, so only the functions core actually
uses get bundled.

Also drops the @types/semver devDependency, since slimsemver ships its own
types.
@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor
Fails
🚫

PR is not labeled with one of: ["cleanup","BREAKING CHANGE","feature request","bug","documentation","maintenance","build","dependencies"]

🚫

PR is not labeled with one of: ["ci:normal","ci:merged","ci:daily","ci:docs"]

🚫

PR is not labeled with one of: ["qa:needed","qa:skip","qa:success"]

🚫 This PR needs an approving review from a Storybook Core or Developer Experience team member before it can be merged.

Generated by 🚫 dangerJS against 70fc8b7

@Damin3927 Damin3927 changed the title Use slimsemver in core Core: Use slimsemver instead of semver Aug 5, 2026

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.

Pull request overview

This PR replaces semver with slimsemver throughout code/core to reduce how much semver-related code ends up in the browser/manager bundle by switching to an ESM, tree-shakeable implementation.

Changes:

  • Swap semver imports to slimsemver across core (default and named-function import styles).
  • Update deep function imports (e.g. functions/sort.js) to point at slimsemver.
  • Replace the semver dependency with slimsemver in code/core/package.json and remove @types/semver.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
code/core/src/telemetry/get-known-packages.ts Switches telemetry semver parsing/coercion to slimsemver.
code/core/src/manager-api/modules/versions.ts Switches manager version comparisons/URL versioning logic to slimsemver.
code/core/src/core-server/utils/update-check.ts Switches server-side update-check semver comparisons to slimsemver.
code/core/src/common/node-version.ts Switches Node version range checks to slimsemver.
code/core/src/common/js-package-manager/util.ts Switches package manager semver helpers to slimsemver.
code/core/src/common/js-package-manager/PNPMProxy.ts Switches pnpm version gating/coercion to slimsemver.
code/core/src/common/js-package-manager/NPMProxy.ts Switches deep sort import to slimsemver/functions/sort.js.
code/core/src/common/js-package-manager/JsPackageManager.ts Switches shared package manager semver logic to slimsemver.
code/core/src/common/js-package-manager/BUNProxy.ts Switches deep sort import to slimsemver/functions/sort.js.
code/core/src/cli/helpers.ts Switches CLI semver coercion/range checks to slimsemver.
code/core/src/cli/detectLanguage.ts Switches language detection’s semver checks to slimsemver.
code/core/src/cli/AddonVitestService.ts Switches addon-vitest compatibility semver utilities to slimsemver.
code/core/package.json Replaces semver with slimsemver dependency; removes @types/semver.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 5 to 7
import memoize from 'memoizerific';
import semver from 'semver';
import semver from 'slimsemver';

Comment on lines 5 to 7
import picocolors from 'picocolors';
import semver from 'semver';
import semver from 'slimsemver';
import { dedent } from 'ts-dedent';
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f44cfb5-2077-43ff-a993-7535bf87b4bd

📥 Commits

Reviewing files that changed from the base of the PR and between c6b8914 and 70fc8b7.

📒 Files selected for processing (13)
  • code/core/package.json
  • code/core/src/cli/AddonVitestService.ts
  • code/core/src/cli/detectLanguage.ts
  • code/core/src/cli/helpers.ts
  • code/core/src/common/js-package-manager/BUNProxy.ts
  • code/core/src/common/js-package-manager/JsPackageManager.ts
  • code/core/src/common/js-package-manager/NPMProxy.ts
  • code/core/src/common/js-package-manager/PNPMProxy.ts
  • code/core/src/common/js-package-manager/util.ts
  • code/core/src/common/node-version.ts
  • code/core/src/core-server/utils/update-check.ts
  • code/core/src/manager-api/modules/versions.ts
  • code/core/src/telemetry/get-known-packages.ts

Walkthrough

Changes

semver dependency replacement

Layer / File(s) Summary
Dependency declaration and CLI version handling
code/core/package.json, code/core/src/cli/*
The core package uses slimsemver and removes @types/semver. CLI version checks keep their existing callers and behavior.
Package manager version handling
code/core/src/common/js-package-manager/*
Package manager modules use slimsemver for sorting, coercion, and version comparison.
Core version consumers
code/core/src/common/node-version.ts, code/core/src/core-server/utils/update-check.ts, code/core/src/manager-api/modules/versions.ts, code/core/src/telemetry/get-known-packages.ts
Core modules replace semver imports with slimsemver imports. Existing version operations remain unchanged.

Possibly related PRs

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Damin3927

Copy link
Copy Markdown
Author

Correcting myself: the number in this PR is wrong, and the change isn't worth making. Closing it.

I measured the module closure gzipped, which is not what a bundler emits. Running it through esbuild the way your build actually would:

minified min+gzip
semver, core's six functions 26.5 KB 8.6 KB
slimsemver, same six 20.7 KB 6.7 KB

So the real saving is 1.9 KB gzip, not 19 KB — about 0.5% of the manager bundle, not 5%.

The premise was wrong too. I claimed semver can't be tree-shaken because it's CommonJS with no exports field. It doesn't need to be: it's one function per file, so a bundler already pulls only what's imported. Via deep paths it's actually the smaller of the two — semver/functions/satisfies.js bundles to 5.6 KB gzip against 6.4 KB for mine.

1.9 KB is not a reason to take on a new dependency, least of all one published this week. Sorry for the noise, and thanks to whoever's triage queue this landed in.

@Damin3927 Damin3927 closed this Aug 5, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Aug 7, 2026
3 of 9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants