Skip to content

Commit

Permalink
refactor: move safeModulesPath set to server
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Mar 11, 2024
1 parent 4808b27 commit 95ae29b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
4 changes: 1 addition & 3 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
// record as safe modules
// safeModulesPath should not include the base prefix.
// See https://github.com/vitejs/vite/issues/9438#issuecomment-1465270409
server?.browserEnvironment.moduleGraph.safeModulesPath.add(
fsPathFromUrl(stripBase(url, base)),
)
server?._safeModulesPath.add(fsPathFromUrl(stripBase(url, base)))

if (url !== specifier) {
let rewriteDone = false
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 @@ -385,6 +385,10 @@ export interface ViteDevServer {
abort: () => void
}
>
/**
* @internal
*/
_safeModulesPath: Set<string>
/**
* @internal
*/
Expand Down Expand Up @@ -696,6 +700,7 @@ export async function _createServer(
_importGlobMap: new Map(),
_forceOptimizeOnRestart: false,
_pendingRequests: new Map(),
_safeModulesPath: new Set(),
_fsDenyGlob: picomatch(config.server.fs.deny, {
matchBase: true,
nocase: true,
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/node/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ export function isFileServingAllowed(

if (server._fsDenyGlob(file)) return false

if (server.browserEnvironment.moduleGraph.safeModulesPath.has(file))
return true // TODO: safeModulePaths shouldn't be part of a moduleGraph
if (server._safeModulesPath.has(file)) return true

if (
server.config.server.fs.allow.some(
Expand Down
7 changes: 0 additions & 7 deletions packages/vite/src/node/server/moduleGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ export class EnvironmentModuleGraph {
// a single file may corresponds to multiple modules with different queries
fileToModulesMap = new Map<string, Set<EnvironmentModuleNode>>()

// TODO: this property should be shared across all module graphs
safeModulesPath = new Set<string>()

/**
* @internal
*/
Expand Down Expand Up @@ -634,10 +631,6 @@ export class ModuleGraph {

fileToModulesMap: Map<string, Set<ModuleNode>>

get safeModulesPath(): Set<string> {
return this._browser.safeModulesPath
}

constructor(moduleGraphs: {
browser: EnvironmentModuleGraph
node: EnvironmentModuleGraph
Expand Down

0 comments on commit 95ae29b

Please sign in to comment.