Skip to content

Commit

Permalink
refactor(@angular/build): move vite plugins into a seperate directory
Browse files Browse the repository at this point in the history
Improve code structure
  • Loading branch information
alan-agius4 committed Sep 23, 2024
1 parent 92209dd commit 158774a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
12 changes: 6 additions & 6 deletions packages/angular/build/src/builders/dev-server/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { readFile } from 'node:fs/promises';
import { builtinModules, isBuiltin } from 'node:module';
import { join } from 'node:path';
import type { Connect, DepOptimizationConfig, InlineConfig, ViteDevServer } from 'vite';
import { createAngularMemoryPlugin } from '../../tools/vite/angular-memory-plugin';
import { createAngularLocaleDataPlugin } from '../../tools/vite/i18n-locale-plugin';
import { createRemoveIdPrefixPlugin } from '../../tools/vite/id-prefix-plugin';
import {
ServerSsrMode,
createAngularLocaleDataPlugin,
createAngularMemoryPlugin,
createAngularSetupMiddlewaresPlugin,
} from '../../tools/vite/setup-middlewares-plugin';
import { createAngularSsrServerPlugin } from '../../tools/vite/ssr-server-plugin';
createAngularSsrTransformPlugin,
createRemoveIdPrefixPlugin,
} from '../../tools/vite/plugins';
import { loadProxyConfiguration, normalizeSourceMaps } from '../../utils';
import { loadEsmModule } from '../../utils/load-esm';
import { Result, ResultFile, ResultKind } from '../application/results';
Expand Down Expand Up @@ -662,7 +662,7 @@ export async function setupServer(
ssrMode,
}),
createRemoveIdPrefixPlugin(externalMetadata.explicitBrowser),
await createAngularSsrServerPlugin(serverOptions.workspaceRoot),
await createAngularSsrTransformPlugin(serverOptions.workspaceRoot),
await createAngularMemoryPlugin({
virtualProjectRoot,
outputFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import { basename, dirname, join, relative } from 'node:path';
import type { Plugin } from 'vite';
import { loadEsmModule } from '../../utils/load-esm';
import { AngularMemoryOutputFiles } from './utils';
import { loadEsmModule } from '../../../utils/load-esm';
import { AngularMemoryOutputFiles } from '../utils';

export interface AngularMemoryPluginOptions {
interface AngularMemoryPluginOptions {
virtualProjectRoot: string;
outputFiles: AngularMemoryOutputFiles;
external?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Plugin } from 'vite';
/**
* The base module location used to search for locale specific data.
*/
export const LOCALE_DATA_BASE_MODULE = '@angular/common/locales/global';
const LOCALE_DATA_BASE_MODULE = '@angular/common/locales/global';

/**
* Creates a Vite plugin that resolves Angular locale data files from `@angular/common`.
Expand Down
13 changes: 13 additions & 0 deletions packages/angular/build/src/tools/vite/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

export { createAngularMemoryPlugin } from './angular-memory-plugin';
export { createAngularLocaleDataPlugin } from './i18n-locale-plugin';
export { createRemoveIdPrefixPlugin } from './id-prefix-plugin';
export { createAngularSetupMiddlewaresPlugin, ServerSsrMode } from './setup-middlewares-plugin';
export { createAngularSsrTransformPlugin } from './ssr-transform-plugin';
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
createAngularIndexHtmlMiddleware,
createAngularSsrExternalMiddleware,
createAngularSsrInternalMiddleware,
} from './middlewares';
import { AngularMemoryOutputFiles } from './utils';
} from '../middlewares';
import { AngularMemoryOutputFiles } from '../utils';

export enum ServerSsrMode {
/**
Expand All @@ -42,7 +42,7 @@ export enum ServerSsrMode {
ExternalSsrMiddleware,
}

export interface AngularSetupMiddlewaresPluginOptions {
interface AngularSetupMiddlewaresPluginOptions {
outputFiles: AngularMemoryOutputFiles;
assets: Map<string, string>;
extensionMiddleware?: Connect.NextHandleFunction[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import remapping, { SourceMapInput } from '@ampproject/remapping';
import type { Plugin } from 'vite';
import { loadEsmModule } from '../../utils/load-esm';
import { loadEsmModule } from '../../../utils/load-esm';

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

return {
name: 'vite:angular-ssr-server',
name: 'vite:angular-ssr-transform',
enforce: 'pre',
async configureServer(server) {
const originalssrTransform = server.ssrTransform;
Expand Down

0 comments on commit 158774a

Please sign in to comment.