Skip to content

chore(refactor): cli-build unbarreled imports#1465

Merged
filmaj merged 12 commits into
mainfrom
cli-build-unbarreled-imports
Jul 9, 2026
Merged

chore(refactor): cli-build unbarreled imports#1465
filmaj merged 12 commits into
mainfrom
cli-build-unbarreled-imports

Conversation

@filmaj

@filmaj filmaj commented Jul 9, 2026

Copy link
Copy Markdown
Member

Description

  • Have cli-build use the granular cli-core and cli-test exports
  • Update unit tests to use the new cli-test-provided cli-core mocks
  • Removed buildStaticFiles integration test - replaced with new unit tests
  • Added some timing information for global vitest fixture setup so it is obvious how much time we spend on that in CI

What to review

Testing


Note

Medium Risk
Import-path changes touch all build/schema entry points but are mostly mechanical; dropping the heavy buildStaticFiles integration test reduces regression signal for vendor/import-map behavior unless the new unit tests fully cover those paths.

Overview
@sanity/cli-build stops importing the @sanity/cli-core barrel and pulls types, config, package-manager, telemetry, util, tasks, and debug from the package’s subpath exports. tsconfig paths 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 partial importOriginal mocks on the whole package. buildStaticFiles gains a non–workbench-app unit test (Vite build, static copy, favicons, chunk stats); resolveEntries and getModuleUrl get focused tests; dependency-version tests assert on output.error instead of simulating process.exit.

The CLI buildStaticFiles integration test (real studio build, import maps, vendor chunks) is removed, along with the es-module-lexer dev dependency used there. cli-build Vitest enables tsconfigPaths, disables console intercept for oclif helpers, and excludes integration tests from the unit project; the root Vitest project points at cli-build/vitest.config.ts. Global fixture setup logs console.time/timeEnd for initialization duration.

Reviewed by Cursor Bugbot for commit 1661f7e. Bugbot is set up for automated code reviews on this repo. Configure here.

@filmaj filmaj self-assigned this Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — @sanity/cli

Compared against main (abe72c10)

@sanity/cli

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.

@filmaj filmaj marked this pull request as ready for review July 9, 2026 17:09
@filmaj filmaj requested a review from a team as a code owner July 9, 2026 17:09
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli-build/src/actions/build/buildApp.ts 93.8% (±0%)
packages/@sanity/cli-build/src/actions/build/buildDebug.ts 100.0% (±0%)
packages/@sanity/cli-build/src/actions/build/buildStaticFiles.ts 88.4% (+ 55.8%)
packages/@sanity/cli-build/src/actions/build/buildStudio.ts 94.0% (±0%)
packages/@sanity/cli-build/src/actions/build/checkRequiredDependencies.ts 100.0% (±0%)
packages/@sanity/cli-build/src/actions/build/checkStudioDependencyVersions.ts 100.0% (±0%)
packages/@sanity/cli-build/src/actions/build/decorateIndexWithStagingScript.ts 100.0% (±0%)
packages/@sanity/cli-build/src/actions/build/getViteConfig.ts 97.7% (±0%)
packages/@sanity/cli-build/src/actions/build/handlePrereleaseVersions.ts 100.0% (±0%)
packages/@sanity/cli-build/src/actions/build/renderDocument.ts 3.8% (±0%)
packages/@sanity/cli-build/src/actions/build/renderDocumentWorker/tryLoadDocumentComponent.ts 100.0% (±0%)
packages/@sanity/cli-build/src/actions/build/resolveVendorBuildConfig.ts 5.1% (±0%)
packages/@sanity/cli-build/src/actions/build/writeSanityRuntime.ts 96.2% (+ 7.7%)
packages/@sanity/cli-build/src/actions/schema/getExtractOptions.ts 0.0% (±0%)
packages/@sanity/cli-build/src/actions/schema/runSchemaExtraction.ts 0.0% (±0%)
packages/@sanity/cli-build/src/actions/schema/utils/extractValidationFromSchemaError.ts 0.0% (±0%)
packages/@sanity/cli-build/src/actions/schema/vite/plugin-schema-extraction.ts 91.3% (±0%)

Comparing 17 changed files against main @ abe72c1091656fe22b6d9ba4a86e03e4c9746a11

Overall Coverage

Metric Coverage
Statements 74.6% (+ 0.3%)
Branches 64.4% (+ 0.2%)
Functions 69.5% (+ 0.4%)
Lines 75.0% (+ 0.3%)

@filmaj filmaj requested a review from snocorp July 9, 2026 18:06

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread packages/@sanity/cli-build/src/actions/build/__tests__/writeSanityRuntime.test.ts Outdated
}))

vi.mock(import('../buildDebug'), () => ({
buildDebug: vi.fn() as unknown as (typeof import('../buildDebug'))['buildDebug'],

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.

Odd that you had to override the type in this case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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()

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.

What would happen if we mocked the whole module instead? Is it a lot of other mocking?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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!

@filmaj filmaj merged commit 2287ca1 into main Jul 9, 2026
91 of 93 checks passed
@filmaj filmaj deleted the cli-build-unbarreled-imports branch July 9, 2026 20:12
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