Skip to content

Commit

Permalink
fix: handle yarn command fail when root does not exist (#18141)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Oct 7, 2024
1 parent 0e6d4a5 commit 460aaff
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import {
import { openBrowser as _openBrowser } from './openBrowser'
import type { TransformOptions, TransformResult } from './transformRequest'
import { transformRequest } from './transformRequest'
import { searchForWorkspaceRoot } from './searchRoot'
import { searchForPackageRoot, searchForWorkspaceRoot } from './searchRoot'
import { warmupFiles } from './warmup'
import type { DevEnvironment } from './environment'

Expand Down Expand Up @@ -1045,14 +1045,17 @@ export function resolveServerOptions(
}

if (process.versions.pnp) {
// running a command fails if cwd doesn't exist and root may not exist
// search for package root to find a path that exists
const cwd = searchForPackageRoot(root)
try {
const enableGlobalCache =
execSync('yarn config get enableGlobalCache', { cwd: root })
execSync('yarn config get enableGlobalCache', { cwd })
.toString()
.trim() === 'true'
const yarnCacheDir = execSync(
`yarn config get ${enableGlobalCache ? 'globalFolder' : 'cacheFolder'}`,
{ cwd: root },
{ cwd },
)
.toString()
.trim()
Expand Down

0 comments on commit 460aaff

Please sign in to comment.