Skip to content

Commit

Permalink
fix: apply correct fs restrictions for Yarn PnP when serving files fr…
Browse files Browse the repository at this point in the history
…om node_modules (#15957)
  • Loading branch information
smeng9 committed Mar 12, 2024
1 parent 592c95a commit a149d9e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'node:path'
import { execSync } from 'node:child_process'
import type * as net from 'node:net'
import { get as httpGet } from 'node:http'
import { get as httpsGet } from 'node:https'
Expand Down Expand Up @@ -989,6 +990,26 @@ export function resolveServerOptions(
allowDirs = [searchForWorkspaceRoot(root)]
}

if (process.versions.pnp) {
try {
const enableGlobalCache =
execSync('yarn config get enableGlobalCache', { cwd: root })
.toString()
.trim() === 'true'
const yarnCacheDir = execSync(
`yarn config get ${enableGlobalCache ? 'globalFolder' : 'cacheFolder'}`,
{ cwd: root },
)
.toString()
.trim()
allowDirs.push(yarnCacheDir)
} catch (e) {
logger.warn(`Get yarn cache dir error: ${e.message}`, {
timestamp: true,
})
}
}

allowDirs = allowDirs.map((i) => resolvedAllowDir(root, i))

// only push client dir when vite itself is outside-of-root
Expand Down

0 comments on commit a149d9e

Please sign in to comment.