Skip to content

Commit

Permalink
fix: cacheDir should be ignored from watch (#10242)
Browse files Browse the repository at this point in the history
Co-authored-by: sapphi-red <green@sapphi.red>
  • Loading branch information
shigma and sapphi-red authored Dec 3, 2022
1 parent 5935619 commit 75dbca2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ async function doBuild(
config.logger.info(colors.cyan(`\nwatching for file changes...`))

const resolvedChokidarOptions = resolveChokidarOptions(
config,
config.build.watch.chokidar
)

Expand Down
12 changes: 7 additions & 5 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,13 @@ export async function resolveConfig(

// resolve cache directory
const pkgPath = lookupFile(resolvedRoot, [`package.json`], { pathOnly: true })
const cacheDir = config.cacheDir
? path.resolve(resolvedRoot, config.cacheDir)
: pkgPath
? path.join(path.dirname(pkgPath), `node_modules/.vite`)
: path.join(resolvedRoot, `.vite`)
const cacheDir = normalizePath(
config.cacheDir
? path.resolve(resolvedRoot, config.cacheDir)
: pkgPath
? path.join(path.dirname(pkgPath), `node_modules/.vite`)
: path.join(resolvedRoot, `.vite`)
)

const assetsFilter =
config.assetsInclude &&
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export async function createServer(
const httpsOptions = await resolveHttpsConfig(config.server.https)
const { middlewareMode } = serverConfig

const resolvedWatchOptions = resolveChokidarOptions({
const resolvedWatchOptions = resolveChokidarOptions(config, {
disableGlobbing: true,
...serverConfig.watch
})
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/watch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { escapePath } from 'fast-glob'
import type { WatchOptions } from 'dep-types/chokidar'
import type { ResolvedConfig } from '.'

export function resolveChokidarOptions(
config: ResolvedConfig,
options: WatchOptions | undefined
): WatchOptions {
const { ignored = [], ...otherOptions } = options ?? {}
Expand All @@ -10,6 +13,7 @@ export function resolveChokidarOptions(
'**/.git/**',
'**/node_modules/**',
'**/test-results/**', // Playwright
escapePath(config.cacheDir) + '/**',
...(Array.isArray(ignored) ? ignored : [ignored])
],
ignoreInitial: true,
Expand Down

0 comments on commit 75dbca2

Please sign in to comment.