Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
},
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
"dependencies": {
"@voidzero-dev/vite-task-client": "^0.1.1",
"lightningcss": "^1.32.0",
"picomatch": "^4.0.4",
"postcss": "^8.5.15",
Expand Down
18 changes: 18 additions & 0 deletions packages/vite/src/node/config.ts
Comment thread
wan9chi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { inspect, promisify } from 'node:util'
import { performance } from 'node:perf_hooks'
import { createRequire } from 'node:module'
import crypto from 'node:crypto'
import {
getEnv,
ignoreInput,
ignoreOutput,
} from '@voidzero-dev/vite-task-client'
import colors from 'picocolors'
import picomatch from 'picomatch'
import {
Expand Down Expand Up @@ -1401,6 +1406,14 @@ export async function resolveConfig(

let configFileDependencies: string[] = []
let mode = inlineConfig.mode || defaultMode
// When `NODE_ENV` isn't set locally, ask Vite Task for it; the runner
// also records the env in the build's cache key.
if (process.env.NODE_ENV === undefined) {
const nodeEnv = getEnv('NODE_ENV')
if (nodeEnv !== undefined) {
process.env.NODE_ENV = nodeEnv
}
}
const isNodeEnvSet = !!process.env.NODE_ENV
const packageCache: PackageCache = new Map()

Expand Down Expand Up @@ -2581,6 +2594,11 @@ async function loadConfigFromBundledFile(
`.vite-temp/${path.basename(fileName)}.${hash}.mjs`,
)
: `${fileName}.${hash}.mjs`

// Tell Vite Task to ignore this transient file as both input and output,
// so the read-write of this file doesn't affect the cache fingerprints.
ignoreInput(tempFileName)
ignoreOutput(tempFileName)
await fsp.writeFile(tempFileName, bundledCode)
try {
return (await import(pathToFileURL(tempFileName).href)).default
Expand Down
7 changes: 7 additions & 0 deletions packages/vite/src/node/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'node:fs'
import path from 'node:path'
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- our supported nodejs range supports `parseEnv` but in experimental state, which is fine
import { parseEnv } from 'node:util'
import { getEnvs } from '@voidzero-dev/vite-task-client'
import { type DotenvPopulateInput, expand } from 'dotenv-expand'
import colors from 'picocolors'
import { arraify, createDebugger, normalizePath, tryStatSync } from './utils'
Expand Down Expand Up @@ -82,6 +83,12 @@ export function loadEnv(
}
}

// Vite Task may know prefixed envs not present here; fetch them and let
// the runner record each glob in the build's cache key.
for (const prefix of prefixes) {
Object.assign(env, getEnvs(`${prefix}*`))
}

// check if there are actual env variables starting with VITE_*
// these are typically provided inline and should be prioritized
for (const key in process.env) {
Expand Down
9 changes: 9 additions & 0 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fsp from 'node:fs/promises'
import path from 'node:path'
import { promisify } from 'node:util'
import { performance } from 'node:perf_hooks'
import { ignoreInput, ignoreOutput } from '@voidzero-dev/vite-task-client'
import colors from 'picocolors'
import { init, parse } from 'es-module-lexer'
import { isDynamicPattern } from 'tinyglobby'
Expand Down Expand Up @@ -397,6 +398,14 @@ export async function loadCachedDepOptimizationMetadata(

const depsCacheDir = getDepsCacheDir(environment)

// When run inside Vite Task, the dep optimizer cache is both read and
// written under this directory (metadata + pre-bundled deps). Tell Vite
// Task to treat it as neither a build input nor a build output: the
// lockfile hash stored in the metadata already drives re-optimization,
// and the cache is process-local scratch space, not a build artifact.
ignoreInput(depsCacheDir)
ignoreOutput(depsCacheDir)

Comment thread
sapphi-red marked this conversation as resolved.
if (!force) {
let cachedMetadata: DepOptimizationMetadata | undefined
try {
Expand Down
6 changes: 6 additions & 0 deletions packages/vite/src/node/plugins/prepareOutDir.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { ignoreInput } from '@voidzero-dev/vite-task-client'
import colors from 'picocolors'
import type { Plugin } from '../plugin'
import { getResolvedOutDirs, resolveEmptyOutDir } from '../watch'
Expand Down Expand Up @@ -51,6 +52,11 @@ function prepareOutDir(
const { publicDir } = environment.config
const outDirsArray = [...outDirs]
for (const outDir of outDirs) {
// When run inside Vite Task, `emptyDir` below reads the entries of
// `outDir`. Without this, those reads would be recorded as build inputs
// and mix with the writes that follow, tripping Vite Task's read-write
// overlap check.
ignoreInput(outDir)

@wan9chi wan9chi May 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if (emptyOutDir !== false && fs.existsSync(outDir)) {
// skip those other outDirs which are nested in current outDir
const skipDirs = outDirsArray
Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import sirv from 'sirv'
import compression from '@polka/compression'
import connect from 'connect'
import corsMiddleware from 'cors'
import { disableCache } from '@voidzero-dev/vite-task-client'
import type { Connect } from '#dep-types/connect'
import type {
HttpServer,
Expand Down Expand Up @@ -126,6 +127,10 @@ export type PreviewServerHook = (
export async function preview(
inlineConfig: InlineConfig = {},
): Promise<PreviewServer> {
// The preview server is a long-running, interactive process whose
// responses cannot be replayed from a cache.
disableCache()

const config = await resolveConfig(
inlineConfig,
'serve',
Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import colors from 'picocolors'
import chokidar from 'chokidar'
import launchEditorMiddleware from 'launch-editor-middleware'
import { determineAgent } from '@vercel/detect-agent'
import { disableCache } from '@voidzero-dev/vite-task-client'
import type { SourceMap } from 'rolldown'
import type { ModuleRunner } from 'vite/module-runner'
import type { FSWatcher, WatchOptions } from '#dep-types/chokidar'
Expand Down Expand Up @@ -483,6 +484,10 @@ export async function _createServer(
previousForceOptimizeOnRestart?: boolean
},
): Promise<ViteDevServer> {
// The dev server is a long-running, interactive process whose outputs
// (network responses, HMR updates) cannot be replayed from a cache.
disableCache()

@wan9chi wan9chi May 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Effect verified in vite_dev_disables_cache.md.

Comment thread
wan9chi marked this conversation as resolved.

const config = isResolvedConfig(inlineConfig)
? inlineConfig
: await resolveConfig(inlineConfig, 'serve')
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading