chore(refactor): cli-build unbarreled imports#1465
Conversation
…t to cli-build repo
📦 Bundle Stats —
|
| Metric | Value | vs main (abe72c1) |
|---|---|---|
| Internal (raw) | 2.2 KB | - |
| Internal (gzip) | 838 B | - |
| Bundled (raw) | 11.16 MB | - |
| Bundled (gzip) | 2.10 MB | - |
| Import time | 713ms | +10ms, +1.5% |
bin:sanity
| Metric | Value | vs main (abe72c1) |
|---|---|---|
| Internal (raw) | 782 B | - |
| Internal (gzip) | 423 B | - |
| Bundled (raw) | 9.87 MB | - |
| Bundled (gzip) | 1.78 MB | - |
| Import time | 1.83s | +20ms, +1.1% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — @sanity/cli-core
Compared against main (abe72c10)
| Metric | Value | vs main (abe72c1) |
|---|---|---|
| Internal (raw) | 108.1 KB | - |
| Internal (gzip) | 27.0 KB | - |
| Bundled (raw) | 21.72 MB | - |
| Bundled (gzip) | 3.46 MB | - |
| Import time | 641ms | +12ms, +2.0% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — create-sanity
Compared against main (abe72c10)
| Metric | Value | vs main (abe72c1) |
|---|---|---|
| Internal (raw) | 908 B | - |
| Internal (gzip) | 483 B | - |
| Bundled (raw) | 931 B | - |
| Bundled (gzip) | 491 B | - |
| Import time | ❌ ChildProcess denied: node | - |
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
Coverage Delta
Comparing 17 changed files against main @ Overall Coverage
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5ae0aea. Configure here.
| })) | ||
|
|
||
| vi.mock(import('../buildDebug'), () => ({ | ||
| buildDebug: vi.fn() as unknown as (typeof import('../buildDebug'))['buildDebug'], |
There was a problem hiding this comment.
Odd that you had to override the type in this case.
There was a problem hiding this comment.
When you pass in an import return type to vi.mock as the first parameter, then vi.mock can infer what the mock's shape should look like, so then you do need to type it. Can be helpful, or can be annoying. Sometimes it is easier to just pass a string. Sometimes if you want the test/mock to be kept up to date with module changes, it can be nice to get a type error if your mock drifts out of date. In this case, probably not worth it and should drop the import to ignore the types. I'll do that.
| const mockWriteFile = vi.hoisted(() => vi.fn()) | ||
|
|
||
| vi.mock(import('node:fs/promises'), async (importOriginal) => { | ||
| const actual = await importOriginal() |
There was a problem hiding this comment.
What would happen if we mocked the whole module instead? Is it a lot of other mocking?
There was a problem hiding this comment.
I think because the source-under-test imports the default export, we can't do that. I think if we changed that, then it would work. I'll try that!

Description
cli-builduse the granularcli-coreandcli-testexportscli-test-providedcli-coremocksbuildStaticFilesintegration test - replaced with new unit testsWhat to review
Testing
Note
Medium Risk
Import-path changes touch all build/schema entry points but are mostly mechanical; dropping the heavy
buildStaticFilesintegration test reduces regression signal for vendor/import-map behavior unless the new unit tests fully cover those paths.Overview
@sanity/cli-buildstops importing the@sanity/cli-corebarrel and pulls types, config, package-manager, telemetry, util, tasks, and debug from the package’s subpath exports.tsconfigpaths are extended so tests resolve those entry points (and new@sanity/cli-test/paths/ mock paths) consistently.Unit tests are realigned with shared
@sanity/cli-test/mocks/cli-core/*helpers (createMockOutput, package-manager/config mocks) instead of partialimportOriginalmocks on the whole package.buildStaticFilesgains a non–workbench-app unit test (Vite build, static copy, favicons, chunk stats);resolveEntriesandgetModuleUrlget focused tests; dependency-version tests assert onoutput.errorinstead of simulatingprocess.exit.The CLI
buildStaticFilesintegration test (real studio build, import maps, vendor chunks) is removed, along with thees-module-lexerdev dependency used there.cli-buildVitest enablestsconfigPaths, disables console intercept for oclif helpers, and excludes integration tests from the unit project; the root Vitest project points atcli-build/vitest.config.ts. Global fixture setup logsconsole.time/timeEndfor initialization duration.Reviewed by Cursor Bugbot for commit 1661f7e. Bugbot is set up for automated code reviews on this repo. Configure here.