Skip to content
Open
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 @@ -8,7 +8,6 @@

import { BuilderContext } from '@angular-devkit/architect';
import { createAngularCompilation } from '../../tools/angular/compilation';
import { SourceFileCache } from '../../tools/esbuild/angular/source-file-cache';
import { generateBudgetStats } from '../../tools/esbuild/budget-stats';
import {
BuildOutputFileType,
Expand Down Expand Up @@ -51,6 +50,7 @@ export async function executeBuild(
assets,
cacheOptions,
serverEntryPoint,
codeBundleCache,
baseHref,
ssrOptions,
verbose,
Expand All @@ -70,13 +70,11 @@ export async function executeBuild(
// Reuse rebuild state or create new bundle contexts for code and global stylesheets
let bundlerContexts;
let componentStyleBundler;
let codeBundleCache;
let bundlingResult: BundleContextResult;
let templateUpdates: Map<string, string> | undefined;
if (rebuildState) {
bundlerContexts = rebuildState.rebuildContexts;
componentStyleBundler = rebuildState.componentStyleBundler;
codeBundleCache = rebuildState.codeBundleCache;
templateUpdates = rebuildState.templateUpdates;
// Reset template updates for new rebuild
templateUpdates?.clear();
Expand All @@ -99,7 +97,6 @@ export async function executeBuild(
bundlingResult = BundlerContext.mergeResults([bundlingResult, ...typescriptResults]);
} else {
const target = transformSupportedBrowsersToTargets(browsers);
codeBundleCache = new SourceFileCache(cacheOptions.enabled ? cacheOptions.path : undefined);
componentStyleBundler = createComponentStyleBundler(options, target);
if (options.templateUpdates) {
templateUpdates = new Map<string, string>();
Expand Down
12 changes: 10 additions & 2 deletions packages/angular/build/src/builders/application/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { realpathSync } from 'node:fs';
import { access, constants, readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import path from 'node:path';
import { SourceFileCache } from '../../tools/esbuild/angular/source-file-cache';
import { normalizeAssetPatterns, normalizeOptimization, normalizeSourceMaps } from '../../utils';
import { supportColor } from '../../utils/color';
import { useJSONBuildLogs, usePartialSsrBuild } from '../../utils/environment-options';
Expand Down Expand Up @@ -70,6 +71,9 @@ interface InternalOptions {
*/
entryPoints?: Set<string> | Map<string, string>;

/** Allow to programatically provide a shared cache */
codeBundleCache?: SourceFileCache;

/** File extension to use for the generated output files. */
outExtension?: 'js' | 'mjs';

Expand Down Expand Up @@ -164,8 +168,11 @@ export async function normalizeOptions(
const { projectRoot, projectSourceRoot } = getProjectRootPaths(workspaceRoot, projectMetadata);

// Gather persistent caching option and provide a project specific cache location
const cacheOptions = normalizeCacheOptions(projectMetadata, workspaceRoot);
cacheOptions.path = path.join(cacheOptions.path, projectName);
const cacheOptions = normalizeCacheOptions(projectMetadata, workspaceRoot, projectName);

const codeBundleCache =
options.codeBundleCache ??
new SourceFileCache(cacheOptions.enabled ? cacheOptions.path : undefined);

const i18nOptions: I18nOptions & {
duplicateTranslationBehavior?: I18NTranslation;
Expand Down Expand Up @@ -446,6 +453,7 @@ export async function normalizeOptions(
allowedCommonJsDependencies,
baseHref,
cacheOptions,
codeBundleCache,
crossOrigin,
externalDependencies: normalizeExternals(externalDependencies),
externalPackages:
Expand Down
3 changes: 1 addition & 2 deletions packages/angular/build/src/builders/unit-test/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export async function normalizeOptions(
const { projectRoot, projectSourceRoot } = getProjectRootPaths(workspaceRoot, projectMetadata);

// Gather persistent caching option and provide a project specific cache location
const cacheOptions = normalizeCacheOptions(projectMetadata, workspaceRoot);
cacheOptions.path = path.join(cacheOptions.path, projectName);
const cacheOptions = normalizeCacheOptions(projectMetadata, workspaceRoot, projectName);

// Target specifier defaults to the current project's build target using a development configuration
const buildTargetSpecifier = options.buildTarget ?? `::development`;
Expand Down
7 changes: 6 additions & 1 deletion packages/angular/build/src/utils/normalize-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function hasCacheMetadata(value: unknown): value is { cli: { cache: CacheMetadat
export function normalizeCacheOptions(
projectMetadata: unknown,
worspaceRoot: string,
projectName?: string,
): NormalizedCachedOptions {
const cacheMetadata = hasCacheMetadata(projectMetadata) ? projectMetadata.cli.cache : {};

Expand All @@ -67,9 +68,13 @@ export function normalizeCacheOptions(

const cacheBasePath = resolve(worspaceRoot, path);

const cachePath = projectName
? join(cacheBasePath, VERSION, projectName)
: join(cacheBasePath, VERSION);

return {
enabled: cacheEnabled,
basePath: cacheBasePath,
path: join(cacheBasePath, VERSION),
path: cachePath,
};
}