Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/angular/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"semver": "7.8.4",
"source-map-support": "0.5.21",
"tinyglobby": "0.2.17",
"vite": "7.3.5",
"vite": "8.0.16",
"watchpack": "2.5.2"
},
"optionalDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion packages/angular/build/src/builders/dev-server/vite/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import type { ɵdestroyAngularServerApp as destroyAngularServerApp } from '@angular/ssr';
import type { BuilderContext } from '@angular-devkit/architect';
import { join } from 'node:path';
import type { ViteDevServer } from 'vite';
import type { ViteDevServer } from 'vite' with {
'resolution-mode': 'import',
};
import type { ComponentStyleRecord } from '../../../tools/vite/middlewares';
import { BuildOutputFileType } from '../internal';
import type { NormalizedDevServerOptions } from '../options';
Expand Down
10 changes: 6 additions & 4 deletions packages/angular/build/src/builders/dev-server/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import type { BuilderContext } from '@angular-devkit/architect';
import type { Plugin } from 'esbuild';
import assert from 'node:assert';
import { join } from 'node:path';
import type { Connect, ViteDevServer } from 'vite';
import type * as Vite from 'vite' with {
'resolution-mode': 'import',
};
import type { ComponentStyleRecord } from '../../../tools/vite/middlewares';
import { ServerSsrMode } from '../../../tools/vite/plugins';
import { EsbuildLoaderOption, updateExternalMetadata } from '../../../tools/vite/utils';
Expand Down Expand Up @@ -58,7 +60,7 @@ export async function* serveWithVite(
indexHtml?: (content: string) => Promise<string>;
},
extensions?: {
middleware?: Connect.NextHandleFunction[];
middleware?: Vite.Connect.NextHandleFunction[];
buildPlugins?: Plugin[];
},
): AsyncIterableIterator<DevServerBuilderOutput> {
Expand Down Expand Up @@ -191,9 +193,9 @@ export async function* serveWithVite(
// The index HTML path will be updated from the build results if provided by the builder
let htmlIndexPath = 'index.html';

const { createServer, normalizePath } = await import('vite');
const { createServer, normalizePath } = (await import('vite' as string)) as typeof Vite;

let server: ViteDevServer | undefined;
let server: Vite.ViteDevServer | undefined;
let serverUrl: URL | undefined;
let hadError = false;
const generatedFiles = new Map<string, OutputFileRecord>();
Expand Down
20 changes: 11 additions & 9 deletions packages/angular/build/src/builders/dev-server/vite/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import type { Connect, InlineConfig, SSROptions, ServerOptions } from 'vite';
import type * as Vite from 'vite' with {
'resolution-mode': 'import',
};
import type { ComponentStyleRecord } from '../../../tools/vite/middlewares';
import {
ServerSsrMode,
Expand All @@ -30,7 +32,7 @@ async function createServerConfig(
ssrMode: ServerSsrMode,
preTransformRequests: boolean,
cacheDir: string,
): Promise<ServerOptions> {
): Promise<Vite.ServerOptions> {
const proxy = await loadProxyConfiguration(
serverOptions.workspaceRoot,
serverOptions.proxyConfig,
Expand All @@ -47,7 +49,7 @@ async function createServerConfig(
break;
}

const server: ServerOptions = {
const server: Vite.ServerOptions = {
preTransformRequests,
warmup: {
ssrFiles,
Expand Down Expand Up @@ -101,7 +103,7 @@ function createSsrConfig(
prebundleLoaderExtensions: EsbuildLoaderOption | undefined,
thirdPartySourcemaps: boolean,
define: ApplicationBuilderInternalOptions['define'],
): SSROptions {
): Vite.SSROptions {
return {
// Note: `true` and `/.*/` have different sematics. When true, the `external` option is ignored.
noExternal: /.*/,
Expand Down Expand Up @@ -139,11 +141,11 @@ export async function setupServer(
templateUpdates: Map<string, string>,
prebundleLoaderExtensions: EsbuildLoaderOption | undefined,
define: ApplicationBuilderInternalOptions['define'],
extensionMiddleware?: Connect.NextHandleFunction[],
extensionMiddleware?: Vite.Connect.NextHandleFunction[],
indexHtmlTransformer?: (content: string) => Promise<string>,
thirdPartySourcemaps = false,
): Promise<InlineConfig> {
const { normalizePath } = await import('vite');
): Promise<Vite.InlineConfig> {
const { normalizePath } = (await import('vite' as string)) as typeof Vite;

// Path will not exist on disk and only used to provide separate path for Vite requests
const virtualProjectRoot = normalizePath(
Expand All @@ -161,13 +163,13 @@ export async function setupServer(
externalMetadata.explicitBrowser.length === 0 && ssrMode === ServerSsrMode.NoSsr;
const cacheDir = join(serverOptions.cacheOptions.path, serverOptions.buildTarget.project, 'vite');

const configuration: InlineConfig = {
const configuration: Vite.InlineConfig = {
configFile: false,
envFile: false,
cacheDir,
root: virtualProjectRoot,
publicDir: false,
esbuild: false,
oxc: false,
Comment thread
alan-agius4 marked this conversation as resolved.
mode: 'development',
// We use custom as we do not rely on Vite's htmlFallbackMiddleware and indexHtmlMiddleware.
appType: 'custom',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import type { BuilderContext, BuilderOutput } from '@angular-devkit/architect';
import assert from 'node:assert';
import path from 'node:path';
import type * as Vite from 'vite' with {
'resolution-mode': 'import',
};
import type { Vitest } from 'vitest/node';
import {
DevServerExternalResultMetadata,
Expand Down Expand Up @@ -96,7 +99,7 @@ export class VitestExecutor implements TestExecutor {

async *execute(buildResult: FullResult | IncrementalResult): AsyncIterable<BuilderOutput> {
this.debugLog(DebugLogLevel.Info, `Executing test run (kind: ${buildResult.kind}).`);
this.normalizePath ??= (await import('vite')).normalizePath;
this.normalizePath ??= ((await import('vite' as string)) as typeof Vite).normalizePath;

if (buildResult.kind === ResultKind.Full) {
this.buildResultFiles.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { createHash } from 'node:crypto';
import { readFileSync } from 'node:fs';
import type { ServerResponse } from 'node:http';
import { extname } from 'node:path';
import type { Connect, ViteDevServer } from 'vite';
import type { Connect, ViteDevServer } from 'vite' with {
'resolution-mode': 'import',
};
import { ResultFile } from '../../../builders/application/results';
import { AngularMemoryOutputFiles, AngularOutputAssets, pathnameWithoutBasePath } from '../utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

import type { IncomingMessage, ServerResponse } from 'node:http';
import type { Connect } from 'vite';
import type { Connect } from 'vite' with {
'resolution-mode': 'import',
};
import { addLeadingSlash } from '../../../utils/url';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import assert from 'node:assert';
import { randomUUID } from 'node:crypto';
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import type { Connect } from 'vite';
import type { Connect } from 'vite' with {
'resolution-mode': 'import',
};

type DevToolsJson = {
workspace: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { Connect, ViteDevServer } from 'vite';
import type { Connect, ViteDevServer } from 'vite' with {
'resolution-mode': 'import',
};
import { pathnameWithoutBasePath } from '../utils';

const ANGULAR_COMPONENT_PREFIX = '/@ng/component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

import type { ServerResponse } from 'node:http';
import type { Connect, ViteDevServer } from 'vite';
import type { Connect, ViteDevServer } from 'vite' with {
'resolution-mode': 'import',
};

/**
* Creates a middleware for adding custom headers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

import type { IncomingMessage, ServerResponse } from 'node:http';
import type { Connect } from 'vite';
import type { Connect } from 'vite' with {
'resolution-mode': 'import',
};

export function patchHostValidationMiddleware(middlewares: Connect.Server): void {
const entry = middlewares.stack.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

import type { ServerResponse } from 'node:http';
import type { Connect } from 'vite';
import type { Connect } from 'vite' with {
'resolution-mode': 'import',
};
import { lookupMimeTypeFromRequest } from '../utils';

const ALLOWED_FALLBACK_METHODS = Object.freeze(['GET', 'HEAD']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

import { extname } from 'node:path';
import type { Connect, ViteDevServer } from 'vite';
import type { Connect, ViteDevServer } from 'vite' with {
'resolution-mode': 'import',
};
import { AngularMemoryOutputFiles, pathnameWithoutBasePath } from '../utils';

export function createAngularIndexHtmlMiddleware(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import type {
ɵgetOrCreateAngularServerApp as getOrCreateAngularServerApp,
} from '@angular/ssr';
import type { ServerResponse } from 'node:http';
import type { Connect, ViteDevServer } from 'vite';
import type { Connect, ViteDevServer } from 'vite' with {
'resolution-mode': 'import',
};
import {
isSsrNodeRequestHandler,
isSsrRequestHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import { dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Plugin } from 'vite';
import type * as Vite from 'vite' with {
'resolution-mode': 'import',
};
import { AngularMemoryOutputFiles } from '../utils';

interface AngularMemoryPluginOptions {
Expand All @@ -27,9 +29,9 @@ const FILE_PROTOCOL = 'file:';

export async function createAngularMemoryPlugin(
options: AngularMemoryPluginOptions,
): Promise<Plugin> {
): Promise<Vite.Plugin> {
const { virtualProjectRoot, outputFiles, external } = options;
const { normalizePath } = await import('vite');
const { normalizePath } = (await import('vite' as string)) as typeof Vite;

return {
name: 'vite:angular-memory',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { Plugin } from 'vite';
import type { Plugin } from 'vite' with {
'resolution-mode': 'import',
};

// NOTE: the implementation for this Vite plugin is roughly based on:
// https://github.com/MilanKovacic/vite-plugin-externalize-dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { Connect, Plugin } from 'vite';
import type { Connect, Plugin } from 'vite' with {
'resolution-mode': 'import',
};
import {
ComponentStyleRecord,
angularHtmlFallbackMiddleware,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

import { getCACertificates, setDefaultCACertificates } from 'node:tls';
import type { Plugin } from 'vite';
import type { Plugin } from 'vite' with {
'resolution-mode': 'import',
};

export function createAngularServerSideSSLPlugin(): Plugin {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
*/

import remapping, { SourceMapInput } from '@ampproject/remapping';
import type { Plugin } from 'vite';
import type * as Vite from 'vite' with {
'resolution-mode': 'import',
};

export async function createAngularSsrTransformPlugin(workspaceRoot: string): Promise<Plugin> {
const { normalizePath } = await import('vite');
export async function createAngularSsrTransformPlugin(workspaceRoot: string): Promise<Vite.Plugin> {
const { normalizePath } = (await import('vite' as string)) as typeof Vite;

return {
name: 'vite:angular-ssr-transform',
Expand Down
9 changes: 6 additions & 3 deletions packages/angular/build/src/tools/vite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { OnLoadArgs, PluginBuild } from 'esbuild';
import { lookup as lookupMimeType } from 'mrmime';
import { builtinModules, isBuiltin } from 'node:module';
import { extname } from 'node:path';
import type { DepOptimizationConfig } from 'vite';
import type { DepOptimizationConfig } from 'vite' with {
'resolution-mode': 'import',
};
import type { ExternalResultMetadata } from '../esbuild/bundler-execution-result';
import { JavaScriptTransformer } from '../esbuild/javascript-transformer';
import { getFeatureSupport } from '../esbuild/utils';
Expand Down Expand Up @@ -78,8 +81,8 @@ export function getDepOptimizationConfig({
name: `angular-vite-optimize-deps${ssr ? '-ssr' : ''}${
thirdPartySourcemaps ? '-vendor-sourcemap' : ''
}`,
setup(build) {
build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
setup(build: PluginBuild) {
build.onLoad({ filter: /\.[cm]?js$/ }, async (args: OnLoadArgs) => {
return {
contents: await prebundleTransformer.transformFile(args.path),
loader: 'js',
Expand Down
Loading
Loading