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
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
shutdownSassWorkerPool,
} from '../../tools/esbuild/stylesheets/sass-language';
import { logMessages, withNoProgress, withSpinner } from '../../tools/esbuild/utils';
import { ChangedFiles } from '../../tools/esbuild/watcher';
import { initializeHash } from '../../utils/hash';
import { NormalizedCachedOptions } from '../../utils/normalize-cache';
import { ChangedFiles } from '../../utils/watcher';
import { NormalizedApplicationBuildOptions, NormalizedOutputOptions } from './options';
import {
ComponentUpdateResult,
Expand Down Expand Up @@ -88,7 +88,7 @@ export async function* runEsBuildBuildAction(
}
}

let watcher: import('../../tools/esbuild/watcher').BuildWatcher | undefined;
let watcher: import('../../utils/watcher').BuildWatcher | undefined;
let watchLoopStarted = false;
try {
// Setup watcher if watch mode enabled
Expand All @@ -98,7 +98,7 @@ export async function* runEsBuildBuildAction(
}

// Setup a watcher
const { setupWatcher } = await import('../../tools/esbuild/watcher');
const { setupWatcher } = await import('../../utils/watcher');
watcher = await setupWatcher({
workspaceRoot,
projectRoot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { BuildOutputFileType } from '../../tools/esbuild/bundler-files';
import { checkCommonJSModules } from '../../tools/esbuild/commonjs-checker';
import { LOCALE_DATA_BASE_MODULE } from '../../tools/esbuild/i18n-locale-plugin';
import { extractLicenses } from '../../tools/esbuild/license-extractor';
import { profileAsync } from '../../tools/esbuild/profiling';
import { transformSupportedBrowsersToTargets } from '../../tools/esbuild/target';
import {
calculateEstimatedTransferSizes,
Expand All @@ -29,6 +28,7 @@ import {
} from '../../tools/esbuild/utils';
import { BudgetCalculatorResult, checkBudgets } from '../../utils/bundle-calculator';
import { optimizeChunksThreshold } from '../../utils/environment-options';
import { profileAsync } from '../../utils/profiling';
import { resolveAssets } from '../../utils/resolve-assets';
import {
SERVER_APP_ENGINE_MANIFEST_FILENAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ import {
type InitialFileRecord,
createOutputFile,
} from '../../tools/esbuild/bundler-files';
import { generateIndexHtml } from '../../tools/esbuild/index-html-generator';
import { maxWorkers } from '../../utils/environment-options';
import {
SERVER_APP_MANIFEST_FILENAME,
generateAngularServerAppManifest,
} from '../../utils/server-rendering/manifest';
import {
RouteRenderMode,
WritableSerializableRouteTreeNode,
} from '../../utils/server-rendering/models';
import { WritableSerializableRouteTreeNode } from '../../utils/server-rendering/models';
import { prerenderPages } from '../../utils/server-rendering/prerender';
import { augmentAppWithServiceWorkerEsbuild } from '../../utils/service-worker';
import { generateIndexHtml } from './index-html-generator';
import { injectDebugIds } from './inject-debug-ids';
import { INDEX_HTML_CSR, INDEX_HTML_SERVER, NormalizedApplicationBuildOptions } from './options';
import { OutputMode } from './schema';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/build/src/builders/application/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
PrerenderedRoutesRecord,
} from '../../tools/esbuild/bundler-execution-result';
import { BuildOutputFileType, InitialFileRecord } from '../../tools/esbuild/bundler-files';
import { I18nInliner } from '../../tools/esbuild/i18n-inliner';
import { I18nInliner } from '../../tools/i18n';
import { maxInlinerWorkers } from '../../utils/environment-options';
import { loadTranslations } from '../../utils/i18n-options';
import { createTranslationLoader } from '../../utils/load-translations';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
import assert from 'node:assert';
import { createHash } from 'node:crypto';
import path from 'node:path';
import { NormalizedApplicationBuildOptions } from '../../builders/application/options';
import {
BuildOutputFile,
BuildOutputFileType,
InitialFileRecord,
} from '../../tools/esbuild/bundler-files';
import { IndexHtmlGenerator } from '../../utils/index-file/index-html-generator';
import { BuildOutputFile, BuildOutputFileType, InitialFileRecord } from './bundler-files';
import { NormalizedApplicationBuildOptions } from './options';

/**
* The maximum number of module preload link elements that should be added for
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/build/src/builders/dev-server/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

export { type BuildOutputFile, BuildOutputFileType } from '../../tools/esbuild/bundler-files';
export { createRxjsEsmResolutionPlugin } from '../../tools/esbuild/rxjs-esm-resolution-plugin';
export { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer';
export { JavaScriptTransformer } from '../../tools/javascript-transformer';
export { getFeatureSupport, isZonelessApp } from '../../tools/esbuild/utils';
export { type IndexHtmlTransform } from '../../utils/index-file/index-html-generator';
export { purgeStaleBuildCache } from '../../utils/purge-cache';
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/build/src/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export { transformSupportedBrowsersToTargets } from './tools/esbuild/target';
export { SassCompiler } from './tools/sass/sass-service';

export { SourceFileCache } from './tools/esbuild/angular/source-file-cache';
export { Cache } from './tools/esbuild/cache';
export { Cache } from './utils/cache';
export { createJitResourceTransformer } from './tools/angular/transformers/jit-resource-transformer';
export { JavaScriptTransformer } from './tools/esbuild/javascript-transformer';
export { JavaScriptTransformer } from './tools/javascript-transformer';

export function createCompilerPlugin(
pluginOptions: CompilerPluginOptions & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import assert from 'node:assert';
import { relative } from 'node:path';
import ts from 'typescript';
import { useTypeChecking } from '../../../utils/environment-options';
import { profileAsync, profileSync } from '../../esbuild/profiling';
import { profileAsync, profileSync } from '../../../utils/profiling';
import {
AngularHostOptions,
createAngularCompilerHost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import type * as ng from '@angular/compiler-cli';
import assert from 'node:assert';
import ts from 'typescript';
import { profileSync } from '../../esbuild/profiling';
import { profileSync } from '../../../utils/profiling';
import { AngularHostOptions, createAngularCompilerHost } from '../angular-host';
import { createJitResourceTransformer } from '../transformers/jit-resource-transformer';
import { lazyRoutesTransformer } from '../transformers/lazy-routes-transformer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import type { PartialMessage } from 'esbuild';
import { createRequire } from 'node:module';
import { MessageChannel } from 'node:worker_threads';
import { mergeCumulativeDurations } from '../../../utils/profiling';
import { WorkerPool } from '../../../utils/worker-pool';
import { mergeCumulativeDurations } from '../../esbuild/profiling';
import type { AngularHostOptions } from '../angular-host';
import {
AngularCompilation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import assert from 'node:assert';
import { randomUUID } from 'node:crypto';
import { type MessagePort, receiveMessageOnPort } from 'node:worker_threads';
import { initializeHash } from '../../../utils/hash';
import { getAndClearCumulativeDurations } from '../../esbuild/profiling';
import { getAndClearCumulativeDurations } from '../../../utils/profiling';
import type {
AngularCompilation,
AngularCompilationResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type * as ng from '@angular/compiler-cli';
import type { PartialMessage } from 'esbuild';
import ts from 'typescript';
import { toPosixPath } from '../../../utils/path';
import { profileAsync, profileSync } from '../../esbuild/profiling';
import { profileAsync, profileSync } from '../../../utils/profiling';
import { AngularCompilation, DiagnosticModes } from './angular-compilation';
import { type CompilerOptionOverrides, transformCompilerOptions } from './compiler-options';
import { convertTypeScriptDiagnostic } from './diagnostics';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ import type {
import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import * as path from 'node:path';
import { type PersistentCacheStore, createPersistentCacheStore } from '../../../utils/cache';
import { maxTransformWorkers, useTypeChecking } from '../../../utils/environment-options';
import { calculateHash, initializeHash } from '../../../utils/hash';
import {
logCumulativeDurations,
profileAsync,
resetCumulativeDurations,
} from '../../../utils/profiling';
import { AngularHostOptions } from '../../angular/angular-host';
import { AngularCompilation, DiagnosticModes } from '../../angular/compilation';
import { type PersistentCacheStore, createPersistentCacheStore } from '../cache';
import { JavaScriptTransformer } from '../javascript-transformer';
import { JavaScriptTransformer } from '../../javascript-transformer';
import { LoadResultCache, createCachedLoad } from '../load-result-cache';
import { logCumulativeDurations, profileAsync, resetCumulativeDurations } from '../profiling';
import { AngularCompilationContext, PrimaryCompilationContext } from './compilation-state';
import { ComponentStylesheetBundler } from './component-stylesheets';
import { FileReferenceTracker } from './file-reference-tracker';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import assert from 'node:assert';
import path from 'node:path';
import { MemoryCache } from '../../../utils/cache';
import { createContentHash } from '../../../utils/hash';
import { BundleContextResult, BundlerContext } from '../bundler-context';
import { type BuildOutputFile, BuildOutputFileType } from '../bundler-files';
import { MemoryCache } from '../cache';
import { MemoryLoadResultCache } from '../load-result-cache';
import {
BundleStylesheetOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import type { Message, PartialMessage } from 'esbuild';
import { normalize } from 'node:path';
import type { ChangedFiles } from '../../tools/esbuild/watcher';
import type { ChangedFiles } from '../../utils/watcher';
import type { ComponentStylesheetBundler } from './angular/component-stylesheets';
import type { SourceFileCache } from './angular/source-file-cache';
import type { BundlerContext } from './bundler-context';
Expand Down
145 changes: 16 additions & 129 deletions packages/angular/build/src/tools/esbuild/i18n-locale-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,136 +7,23 @@
*/

import type { Plugin } from 'esbuild';
import { readFile } from 'node:fs/promises';
import { createProjectResolver } from '../../utils/resolve-project';

/**
* The internal namespace used by generated locale import statements and Angular locale data plugin.
*/
export const LOCALE_DATA_NAMESPACE = 'angular:locale/data';

/**
* The base module location used to search for locale specific data.
*/
export const LOCALE_DATA_BASE_MODULE = '@angular/common/locales/global';

/**
* Result of resolving locale data for a given locale tag.
*/
export interface LocaleDataResolution {
path?: string;
warning?: string;
error?: string;
}

/**
* Result of loading locale data for a given locale tag.
*/
export interface LoadedLocaleData {
code?: string;
warning?: string;
error?: string;
}

const localeDataCache = new Map<string, Promise<LoadedLocaleData>>();

/**
* Resolves the path to the Angular locale data file for a given locale tag.
*
* @param rawLocaleTag The raw locale identifier (e.g. "fr-CA", "de", "en-US").
* @param projectResolve A function that attempts to resolve a path string to an absolute file path.
* @returns Resolution result with file path, or warning/error diagnostics if applicable.
*/
export function resolveLocaleDataPath(
rawLocaleTag: string,
projectResolve: (potentialPath: string) => string | undefined,
): LocaleDataResolution {
let partialLocaleTag: string;
try {
const locale = new Intl.Locale(rawLocaleTag);
partialLocaleTag = locale.baseName;
} catch {
return {
error: `Invalid or unsupported locale provided in configuration: "${rawLocaleTag}"`,
};
}

let exact = true;
while (partialLocaleTag) {
// Angular embeds the `en`/`en-US` locale into the framework and it does not need to be included again here.
if (partialLocaleTag === 'en' || partialLocaleTag === 'en-US') {
return {};
}

const potentialPath = `${LOCALE_DATA_BASE_MODULE}/${partialLocaleTag}`;
try {
const resolvedPath = projectResolve(potentialPath);
if (resolvedPath) {
return {
path: resolvedPath,
warning: exact
? undefined
: `Locale data for '${rawLocaleTag}' cannot be found. Using locale data for '${partialLocaleTag}'.`,
};
}
} catch {}

// Remove the last subtag and try again with a less specific locale.
const parts = partialLocaleTag.split('-');
partialLocaleTag = parts.slice(0, -1).join('-');
exact = false;
}

return {
warning: `Locale data for '${rawLocaleTag}' cannot be found. No locale data will be included for this locale.`,
};
}

/**
* Loads the Angular global locale data script for a specified locale tag.
*
* @param rawLocaleTag The raw locale identifier (e.g. "fr-CA", "de", "en-US").
* @param projectRoot Optional project root for module resolution.
* @returns A promise resolving to the loaded locale data script code and any diagnostic warnings.
*/
export function loadLocaleData(
rawLocaleTag: string,
projectRoot?: string,
): Promise<LoadedLocaleData> {
let cached = localeDataCache.get(rawLocaleTag);
if (!cached) {
cached = (async () => {
const projectResolve = createProjectResolver(projectRoot ?? process.cwd());
const resolution = resolveLocaleDataPath(rawLocaleTag, (potentialPath) => {
try {
return projectResolve(potentialPath);
} catch {
return undefined;
}
});

if (resolution.error) {
return { error: resolution.error };
}

if (resolution.path) {
try {
const code = await readFile(resolution.path, 'utf8');

return { code, warning: resolution.warning };
} catch (e) {
return { error: `Failed to read locale data file: ${(e as Error).message}` };
}
}

return { warning: resolution.warning };
})();

localeDataCache.set(rawLocaleTag, cached);
}

return cached;
}
import {
LOCALE_DATA_NAMESPACE,
type LoadedLocaleData,
type LocaleDataResolution,
loadLocaleData,
resolveLocaleDataPath,
} from '../i18n/locale-data';

export {
LOCALE_DATA_NAMESPACE,
LOCALE_DATA_BASE_MODULE,
type LoadedLocaleData,
type LocaleDataResolution,
loadLocaleData,
resolveLocaleDataPath,
} from '../i18n/locale-data';

/**
* Creates an esbuild plugin that resolves Angular locale data files from `@angular/common`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import type { Loader, OnLoadResult, PartialMessage } from 'esbuild';
import { readFile, stat } from 'node:fs/promises';
import { isAbsolute } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Cache as PersistentCacheStore } from '../../utils/cache';
import { mapConcurrent, runConcurrent } from '../../utils/concurrency';
import { calculateHash, createContentHash } from '../../utils/hash';
import type { Cache as PersistentCacheStore } from './cache';
import { LoadResultCache, MemoryLoadResultCache } from './load-result-cache';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { OnLoadResult } from 'esbuild';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import type { Cache as PersistentCacheStore } from '../../utils/cache';
import { initializeHash } from '../../utils/hash';
import type { Cache as PersistentCacheStore } from './cache';
import {
type CachedLoadResultEntry,
PersistentLoadResultCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { OnLoadResult, PartialMessage, PartialNote, ResolveResult } from 'e
import { dirname, join } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import type { CanonicalizeContext, CompileResult, Exception, Syntax } from 'sass-embedded';
import { MemoryCache } from '../../../utils/cache';
import type { SassCompiler } from '../../sass/sass-service';
import { MemoryCache } from '../cache';
import { StylesheetLanguage, StylesheetPluginOptions } from './stylesheet-plugin-factory';

let sassService: SassCompiler | undefined;
Expand Down
Loading
Loading