Skip to content

refactor(cli-core): replace vite-node with Vite module runner#1224

Draft
stipsan wants to merge 4 commits into
mainfrom
cursor/replace-vite-node-with-module-runner-e38b
Draft

refactor(cli-core): replace vite-node with Vite module runner#1224
stipsan wants to merge 4 commits into
mainfrom
cursor/replace-vite-node-with-module-runner-e38b

Conversation

@stipsan

@stipsan stipsan commented Jun 8, 2026

Copy link
Copy Markdown
Member

Fixes #1210

Description

Migrates the studio worker loader from vite-node (ViteNodeServer / ViteNodeRunner) to Vite's built-in Module Runner API (createServerModuleRunner), and removes the vite-node dependency.

The migration preserves the custom behavior requested in the issue:

  • HTTPS importsfetchModule still fetches remote modules and runs them through ssrTransform
  • Relative imports from remote modules — resolved against the remote origin (e.g. esm.sh)
  • CommonJS compatibilityStudioModuleEvaluator adds the CJS module / exports / require context that vite-node used to provide
  • Source maps — handled by ModuleRunner's built-in sourcemapInterceptor (replaces installSourcemapsSupport)
  • /@vite/env — loaded via runner.import('/@vite/env') before the worker script

Follow-up simplification removed an unused bare-import re-transform branch, cutting 52 lines while keeping the integration tests green.

What to review

  • packages/@sanity/cli-core/src/loaders/studio/studioWorkerLoader.worker.ts — Module Runner setup and HTTPS fetchModule override
  • packages/@sanity/cli-core/src/loaders/studio/studioModuleEvaluator.ts — CJS execution evaluator
  • Dependency removal in packages/@sanity/cli-core/package.json and pnpm-workspace.yaml

Testing

  • pnpm check:types
  • pnpm check:lint
  • pnpm check:deps
  • pnpm build:cli
  • pnpm test packages/@sanity/cli-core packages/@sanity/cli-build/src/actions/build/renderDocumentWorker/__tests__/renderDocumentWorker.test.ts --bail=1 (282 tests)
  • pnpm test packages/@sanity/cli/src/commands/schemas/__tests__/extract.test.ts -t "should extract schema" --bail=1 (schema extraction integration via studio worker, including worst-case studio)
Open in Web Open in Cursor 

Migrate studioWorkerLoader.worker.ts from ViteNodeServer/ViteNodeRunner
to createServerModuleRunner, preserving https:// import handling and
source map support via the built-in ModuleRunner API.
Add StudioModuleEvaluator to execute CommonJS modules with vite-node-style
interop, and route bare imports through Vite transform to honor ssr.noExternal.
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — @sanity/cli

Compared against main (cdd349bf)

@sanity/cli

Metric Value vs main (cdd349b)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 11.13 MB -
Bundled (gzip) 2.10 MB -
Import time 882ms +15ms, +1.7%

bin:sanity

Metric Value vs main (cdd349b)
Internal (raw) 1023 B -
Internal (gzip) 486 B -
Bundled (raw) 9.87 MB -
Bundled (gzip) 1.77 MB -
Import time 1.99s +27ms, +1.4%

🗺️ 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 (cdd349bf)

Metric Value vs main (cdd349b)
Internal (raw) 96.3 KB -
Internal (gzip) 22.7 KB -
Bundled (raw) 21.70 MB -
Bundled (gzip) 3.45 MB -
Import time 784ms +13ms, +1.7%

🗺️ 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 (cdd349bf)

Metric Value vs main (cdd349b)
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.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli-core/src/loaders/studio/studioModuleEvaluator.ts 0.0%
packages/@sanity/cli-core/src/loaders/studio/studioWorkerLoader.worker.ts 0.0%

No baseline available — showing current coverage for 2 changed files

Overall Coverage

Metric Coverage
Statements 81.4%
Branches 72.6%
Functions 80.3%
Lines 81.9%

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.

Replace vite-node with Vite's built-in Module Runner

2 participants