Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import type { Connect, InlineConfig, SSROptions, ServerOptions } from 'vite';
import { type Connect, type InlineConfig, type SSROptions, type ServerOptions, searchForPackageRoot } from 'vite';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This change introduces a top-level runtime import of vite. The existing code in this file follows a pattern of using dynamic imports for Vite's runtime utilities (see line 152) to avoid eagerly loading the vite package when the module is first evaluated. To maintain this pattern, searchForPackageRoot should be imported dynamically where it is used, keeping this import as type-only.

Suggested change
import { type Connect, type InlineConfig, type SSROptions, type ServerOptions, searchForPackageRoot } from 'vite';
import type { Connect, InlineConfig, SSROptions, ServerOptions } from 'vite';

import type { ComponentStyleRecord } from '../../../tools/vite/middlewares';
import {
ServerSsrMode,
Expand Down Expand Up @@ -75,9 +75,12 @@ async function createServerConfig(
// The first two are required for Vite to function in prebundling mode (the default) and to load
// the Vite client-side code for browser reloading. These would be available by default but when
// the `allow` option is explicitly configured, they must be included manually.
// The package root search handles monorepo setups where node_modules may be hoisted
// to a parent directory above the Angular workspace root.
allow: [
cacheDir,
join(serverOptions.workspaceRoot, 'node_modules'),
searchForPackageRoot(serverOptions.workspaceRoot),
Comment on lines 82 to +83
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The entry join(serverOptions.workspaceRoot, 'node_modules') is redundant because searchForPackageRoot(serverOptions.workspaceRoot) will always return either the workspaceRoot itself or one of its parent directories. In either case, the local node_modules directory will be covered by the allowed package root. Additionally, using a dynamic import here maintains the lazy-loading pattern for Vite runtime dependencies used elsewhere in this file.

Suggested change
join(serverOptions.workspaceRoot, 'node_modules'),
searchForPackageRoot(serverOptions.workspaceRoot),
(await import('vite')).searchForPackageRoot(serverOptions.workspaceRoot),

...[...assets.values()].map(({ source }) => source),
],
},
Expand Down
Loading