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: 0 additions & 2 deletions packages/angular/build/src/builders/dev-server/vite/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { Connect, InlineConfig, SSROptions, ServerOptions } from 'vite';
import type { ComponentStyleRecord } from '../../../tools/vite/middlewares';
import {
ServerSsrMode,
createAngularLocaleDataPlugin,
createAngularMemoryPlugin,
createAngularSetupMiddlewaresPlugin,
createAngularSsrTransformPlugin,
Expand Down Expand Up @@ -221,7 +220,6 @@ export async function setupServer(
define,
),
plugins: [
createAngularLocaleDataPlugin(),
createAngularSetupMiddlewaresPlugin({
outputFiles,
assets,
Expand Down
53 changes: 36 additions & 17 deletions packages/angular/build/src/tools/esbuild/i18n-locale-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type { Plugin } from 'esbuild';
import type { Plugin, ResolveResult } from 'esbuild';
import { createRequire } from 'node:module';

/**
* The internal namespace used by generated locale import statements and Angular locale data plugin.
Expand All @@ -27,17 +28,6 @@ export function createAngularLocaleDataPlugin(): Plugin {
return {
name: 'angular-locale-data',
setup(build): void {
// If packages are configured to be external then leave the original angular locale import path.
// This happens when using the development server with caching enabled to allow Vite prebundling to work.
// There currently is no option on the esbuild resolve function to resolve while disabling the option. To
// workaround the inability to resolve the full locale location here, the Vite dev server prebundling also
// contains a plugin to allow the locales to be correctly resolved when prebundling.
// NOTE: If esbuild eventually allows controlling the external package options in a build.resolve call, this
// workaround can be removed.
if (build.initialOptions.packages === 'external') {
return;
}

build.onResolve({ filter: /^angular:locale\/data:/ }, async ({ path }) => {
// Extract the locale from the path
const rawLocaleTag = path.split(':', 3)[2];
Expand All @@ -60,6 +50,7 @@ export function createAngularLocaleDataPlugin(): Plugin {
}

let exact = true;
let localeRequire: NodeJS.Require | undefined;
while (partialLocaleTag) {
// Angular embeds the `en`/`en-US` locale into the framework and it does not need to be included again here.
// The onLoad hook below for the locale data namespace has an `empty` loader that will prevent inclusion.
Expand All @@ -73,11 +64,39 @@ export function createAngularLocaleDataPlugin(): Plugin {

// Attempt to resolve the locale tag data within the Angular base module location
const potentialPath = `${LOCALE_DATA_BASE_MODULE}/${partialLocaleTag}`;
const result = await build.resolve(potentialPath, {
kind: 'import-statement',
resolveDir: build.initialOptions.absWorkingDir,
});
if (result.path) {

// If packages are configured to be external then leave the original angular locale import path.
// This happens when using the development server with caching enabled to allow Vite prebundling to work.
// There currently is no option on the esbuild resolve function to resolve while disabling the option.
// NOTE: If esbuild eventually allows controlling the external package options in a build.resolve call, this
// workaround can be removed.
let result: ResolveResult | undefined;
const { packages, absWorkingDir } = build.initialOptions;
if (packages === 'external' && absWorkingDir) {
localeRequire ??= createRequire(absWorkingDir + '/');

try {
localeRequire.resolve(potentialPath);

result = {
errors: [],
warnings: [],
external: true,
sideEffects: true,
namespace: '',
suffix: '',
pluginData: undefined,
path: potentialPath,
};
} catch {}
} else {
result = await build.resolve(potentialPath, {
kind: 'import-statement',
resolveDir: absWorkingDir,
});
}

if (result?.path) {
if (exact) {
return result;
} else {
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/angular/build/src/tools/vite/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

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';