Skip to content

chore(vite): replace vite-node with Vite's native RunnableDevEnvironment#1717

Merged
Tobbe merged 19 commits into
cedarjs:mainfrom
lisa-assistant:lisa/replace-vite-node-with-vite-runner
May 5, 2026
Merged

chore(vite): replace vite-node with Vite's native RunnableDevEnvironment#1717
Tobbe merged 19 commits into
cedarjs:mainfrom
lisa-assistant:lisa/replace-vite-node-with-vite-runner

Conversation

@lisa-assistant
Copy link
Copy Markdown
Contributor

Summary

vite-node is a separate package that replicates functionality now built directly into Vite via the Environment API (introduced in Vite 6, and we're on Vite 7).

This replaces ViteNodeServer + ViteNodeRunner + installSourcemapsSupport with Vite's native RunnableDevEnvironment:

Before:

const node = new ViteNodeServer(server, { ... })
installSourcemapsSupport({ getSourceMap: (source) => node.getSourceMap(source) })
const runner = new ViteNodeRunner({ root, base, fetchModule, resolveId })
const result = await runner.executeFile(filePath)

After:

// In server config:
environments: { nodeRunnerEnv: {} }

// Then:
const env = server.environments.nodeRunnerEnv
if (!isRunnableDevEnvironment(env)) { await server.close(); throw new Error(...) }
const result = await env.runner.import(filePath)

Files changed

  • packages/cli/src/lib/exec.js — used by yarn cedar exec (script runner)
  • packages/prerender/src/graphql/node-runner.ts — used by prerender's GraphQL node runner
  • Both package.json files — vite-node dependency removed

Inspired by

remix-run/react-router#14862

🤖 Generated with Claude Code

@netlify
Copy link
Copy Markdown

netlify Bot commented May 5, 2026

Deploy Preview for cedarjs ready!

Name Link
🔨 Latest commit 6f604b4
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/69f9de2007c09e000882f79d
😎 Deploy Preview https://deploy-preview-1717--cedarjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@Tobbe Tobbe changed the title refactor: replace vite-node with Vite's native RunnableDevEnvironment chore(vite): replace vite-node with Vite's native RunnableDevEnvironment May 5, 2026
@github-actions github-actions Bot added this to the chore milestone May 5, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 5, 2026

Greptile Summary

Replaces vite-node (ViteNodeServer + ViteNodeRunner + installSourcemapsSupport) with Vite 7's native RunnableDevEnvironment across both the cedar exec script runner and the prerender GraphQL node runner, and introduces a new cedarCjsCompatPlugin to handle CJS-to-ESM transformation in those environments.

  • cedarCjsCompatPlugin (packages/vite/src/plugins/vite-plugin-cedar-cjs-compat.ts): new enforce: 'pre' plugin that wraps CJS files in an ESM shell using createRequire, with AST-based guards for unsupported patterns (re-exports, getter descriptors, local exports shadowing) and cjs-module-lexer for named-export extraction.
  • exec.js and node-runner.ts: both now create a Vite server with a nodeRunnerEnv environment, verify it via isRunnableDevEnvironment, and call env.runner.import() instead of runner.executeFile(); exec.js gains a resolveExtension helper to handle .js \u2192 .ts mapping since customResolver results are final.
  • Dependency cleanup: vite-node removed from @cedarjs/cli and @cedarjs/prerender; @cedarjs/vite added to @cedarjs/cli; acorn pinned as a direct dependency of @cedarjs/vite.

Confidence Score: 5/5

The migration is safe to merge; both execution paths are guarded with isRunnableDevEnvironment checks and the new CJS compat plugin has graceful fallback on any parse or lexer failure.

The vite-node removal is a clean like-for-like substitution: fetchModule/resolveId delegation is replaced by the native environment runner, and resolveExtension correctly handles the TS extension-mapping edge case. The only open question is whether cjs-module-lexer should be declared as a direct dep rather than relied upon as a Vite transitive dep.

packages/vite/src/plugins/vite-plugin-cedar-cjs-compat.ts — verify the cjs-module-lexer fallback is acceptable for CJS packages that use exports.foo-style named exports exclusively (the object-literal fallback won’t detect those)

Important Files Changed

Filename Overview
packages/vite/src/plugins/vite-plugin-cedar-cjs-compat.ts New CJS-to-ESM transform plugin for RunnableDevEnvironment; well-structured with graceful fallbacks, but relies on cjs-module-lexer as an undeclared transitive Vite dependency
packages/cli/src/lib/exec.js Migrated from ViteNodeServer/ViteNodeRunner to RunnableDevEnvironment; adds resolveExtension helper for TS project extension mapping and cedarCjsCompatPlugin
packages/prerender/src/graphql/node-runner.ts Clean migration from ViteNodeRunner to RunnableDevEnvironment; adds explicit error throw after the init null-check to satisfy TypeScript narrowing
packages/vite/src/index.ts Exports cedarCjsCompatPlugin from the package so exec.js and node-runner.ts can share it
packages/vite/package.json Adds acorn as a direct dependency (was previously only a transitive dep); cjs-module-lexer is still not declared despite being imported in the new plugin
packages/cli/package.json Removes vite-node, adds @cedarjs/vite as a direct dependency
docs/implementation-docs/2026-03-26-cedarjs-project-overview.md Whitespace-only box-drawing alignment fix; all factual content (Vite version, plugin list, package descriptions) remains accurate after this PR

Reviews (12): Last reviewed commit: "fix review comment" | Re-trigger Greptile

Comment thread packages/cli/src/lib/exec.js
Comment thread packages/prerender/src/graphql/node-runner.ts
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 5, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 6f604b4

Command Status Duration Result
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 2s View ↗
nx run-many -t build ✅ Succeeded 7s View ↗
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 1m 19s View ↗
nx run-many -t test:types ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-05 12:26:55 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 5, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 93d1016

Command Status Duration Result
nx run-many -t test --minWorkers=1 --maxWorkers=4 ❌ Failed 1m 14s View ↗
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 2s View ↗
nx run-many -t build ✅ Succeeded 18s View ↗
nx run-many -t test:types ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-05 10:05:41 UTC

lisa-assistant and others added 11 commits May 5, 2026 09:52
…t plugin

@rollup/plugin-commonjs requires Rollup's internal build context (isRequiredId,
resolveRequireSourcesAndUpdateMeta) which doesn't exist in Vite 6's
EnvironmentPluginContainer, causing all transforms to crash.

Replace with a custom transform plugin that:
- Detects CJS files by checking for module.exports / exports.x patterns
- Wraps them with CJS globals (module, exports, require, __dirname, __filename)
- Uses cjs-module-lexer (Vite transitive dep) to statically detect named exports
- Re-exports named exports individually so callers can use destructuring
Comment thread packages/vite/src/plugins/vite-plugin-cedar-cjs-compat.ts Outdated
@Tobbe Tobbe merged commit 7c28098 into cedarjs:main May 5, 2026
46 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

The changes in this PR are now available on npm.

Try them out by running yarn cedar upgrade -t 5.0.0-canary.13892

Or try it in a new app with yarn dlx create-cedar-app@5.0.0-canary.13892

Tobbe added a commit that referenced this pull request May 12, 2026
…ent (#1717)

Co-authored-by: Tobbe Lundberg <tobbe@tlundberg.com>
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