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 CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ the [depending-on-angular-internals](.claude/skills/depending-on-angular-interna
When Angular releases a new minor:

1. Move `@angular/build` (peer and dev dependency) and the `@angular-devkit/*` dependencies to
the new minor, e.g. `~22.2.0` and `^0.2202.0`.
the new minor, e.g. `~22.3.0` and `^0.2203.0`.
2. Fix what breaks in `pnpm typecheck` and `pnpm test`. Changes to `@angular/build/private` usually
show up there first.
3. Review every `// upstream: angular/angular-cli <path> @ <sha>` tag against the new minor's
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
"url": "http://www.angulararchitects.io"
},
"peerDependencies": {
"@angular/build": "~22.2.0",
"@angular/localize": "~22.2.0"
"@angular/build": "~22.3.0",
"@angular/localize": "~22.3.0"
},
"peerDependenciesMeta": {
"@angular/localize": {
"optional": true
}
},
"dependencies": {
"@angular-devkit/architect": "^0.2202.0",
"@angular-devkit/core": "~22.2.0",
"@angular-devkit/schematics": "~22.2.0",
"@angular-devkit/architect": "^0.2203.0",
"@angular-devkit/core": "~22.3.0",
"@angular-devkit/schematics": "~22.3.0",
"@chialab/esbuild-plugin-commonjs": "^0.19.0",
"@softarc/native-federation": "~4.11.0",
"@softarc/native-federation-orchestrator": "^4.10.0",
Expand Down Expand Up @@ -90,8 +90,8 @@
"test": "vitest"
},
"devDependencies": {
"@angular/build": "~22.2.0",
"@angular/localize": "~22.2.0",
"@angular/build": "~22.3.0",
"@angular/localize": "~22.3.0",
"@eslint/js": "^10.0.1",
"@nx/devkit": "^24.0.0",
"@types/node": "^24.10.0",
Expand Down
1,111 changes: 815 additions & 296 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

43 changes: 32 additions & 11 deletions src/builders/remote/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ beforeEach(() => {
write('projects/mfe/src/assets/Thumbs.db');
write('projects/mfe/public/robots.txt');
write('projects/mfe/public/nested/a.txt');
write('projects/mfe/public/nested/.gitkeep');
write('shared/drafts/wip.txt');
write('shared/drafts/keep.md');
write('shared/top.txt');
write('projects/mfe/README.md');
write('shared/brand/font.woff2');
write('shared/brand/skip.tmp');
Expand All @@ -62,6 +66,11 @@ const patterns = [
{ glob: '**/*', input: 'projects/mfe/public' },
{ glob: '**/*.txt', input: 'projects/mfe/public', output: 'static', flatten: true },
{ glob: '**/*', input: 'shared/brand', output: '/brand/', ignore: ['*.tmp'] },
{ glob: '**/*', input: 'shared', output: 'sh', ignore: ['drafts', 'brand/'] },
// Literal glob: 22.3 resolves it with a stat instead of tinyglobby, with the same result.
{ glob: 'robots.txt', input: 'projects/mfe/public', output: 'literal' },
// Since 22.3 a glob naming a directory no longer expands to its files (65f302c5df).
{ glob: 'nested', input: 'projects/mfe/public', output: 'dir-glob' },
];

describe('normalizeRemoteAssetEntries', () => {
Expand Down Expand Up @@ -108,19 +117,19 @@ describe('normalizeRemoteAssetEntries', () => {
).toThrow(/must be within the workspace root/);
});

// Deliberate divergence: Angular picks the root via `startsWith`, so a sibling sharing the
// sourceRoot prefix ("src-extra") resolves against sourceRoot and throws "outside of the output
// path". We match on real subdirectories, so it falls through to projectRoot.
// Before 22.3 Angular matched with `startsWith` and resolved this against sourceRoot
// (angular/angular-cli 58c30c05f6); kept as a regression test.
it('resolves a sourceRoot-prefixed sibling against projectRoot', () => {
write('projects/mfe/src-extra/x.txt');
const pattern = ['projects/mfe/src-extra/x.txt'];
const expected = [{ glob: 'x.txt', input: 'projects/mfe/src-extra', output: 'src-extra' }];

expect(() =>
expect(
normalizeAssetPatterns(structuredClone(pattern), ws, 'projects/mfe', 'projects/mfe/src')
).toThrow(/outside of the output path/);
expect(normalizeRemoteAssetEntries(pattern, ws, 'projects/mfe', 'projects/mfe/src')).toEqual([
{ glob: 'x.txt', input: 'projects/mfe/src-extra', output: 'src-extra' },
]);
).toEqual(expected);
expect(normalizeRemoteAssetEntries(pattern, ws, 'projects/mfe', 'projects/mfe/src')).toEqual(
expected
);
});

it('rejects outputs that escape the output path', () => {
Expand All @@ -147,12 +156,15 @@ describe('copyAllAssets', () => {
expect(expected).not.toContain('assets/.gitkeep');
expect(expected).not.toContain('assets/Thumbs.db');
expect(expected).not.toContain('brand/skip.tmp');
// Before 22.3 the default `.gitkeep` ignore only matched at the input root.
expect(expected).not.toContain('nested/.gitkeep');
expect(expected).toContain('literal/robots.txt');
expect(expected.filter(f => f.startsWith('sh/'))).toEqual(['sh/top.txt']);
expect(expected.filter(f => f.startsWith('dir-glob/'))).toEqual([]);
});
});

// Not part of the parity check: @angular/build 22.2.1 passes `undefined` to tinyglobby, which
// follows symlinks. Upstream fixed this on main (angular/angular-cli a0a6b422cd, #34164) to match
// the schema default of `false`; we follow the fix.
// Symlinks aren't followed by default since angular/angular-cli a0a6b422cd (#34164, 22.3).
describe('symlinked asset directories', () => {
beforeEach(() => {
write('linked/secret.txt');
Expand Down Expand Up @@ -194,4 +206,13 @@ describe('copyChangedAssets', () => {

expect(listFiles(out)).toEqual(['assets/logo.svg']);
});

it('copies a changed file matched by a literal glob', async () => {
const entries = normalizeRemoteAssetEntries(patterns, ws, 'projects/mfe', 'projects/mfe/src');

await copyChangedAssets(entries, out, ws, ['projects/mfe/public/robots.txt']);

// Matched by the `**/*`, the flattened `**/*.txt` and the literal `robots.txt` entries.
expect(listFiles(out)).toEqual(['literal/robots.txt', 'robots.txt', 'static/robots.txt']);
});
});
112 changes: 94 additions & 18 deletions src/builders/remote/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import * as fs from 'fs';
import * as path from 'path';
import { glob } from 'tinyglobby';
import { glob, isDynamicPattern } from 'tinyglobby';

import type { ApplicationBuilderOptions } from '@angular/build';

Expand All @@ -18,13 +18,13 @@ export type NormalizedAssetEntry = {

type AssetPattern = NonNullable<ApplicationBuilderOptions['assets']>[number];

// upstream: angular/angular-cli packages/angular/build/src/utils/path.ts @ 6c6bb21485
// upstream: angular/angular-cli packages/angular/build/src/utils/path.ts @ bdda8bbf1b
function isSubDirectory(parent: string, child: string): boolean {
const relative = path.relative(path.resolve(parent), path.resolve(parent, child));
return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
}

// upstream: angular/angular-cli packages/angular/build/src/utils/normalize-asset-patterns.ts @ 163a03264b
// upstream: angular/angular-cli packages/angular/build/src/utils/normalize-asset-patterns.ts @ bdda8bbf1b
export function normalizeRemoteAssetEntries(
assets: ApplicationBuilderOptions['assets'] | undefined,
workspaceRoot: string,
Expand Down Expand Up @@ -82,28 +82,104 @@ function normalizeAssetPattern(
};
}

// upstream: angular/angular-cli packages/angular/build/src/utils/resolve-assets.ts @ a0a6b422cd
const DEFAULT_ASSET_IGNORE = ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'];
// upstream: angular/angular-cli packages/angular/build/src/utils/resolve-assets.ts @ bdda8bbf1b
const DEFAULT_ASSET_IGNORE_FILES: ReadonlySet<string> = new Set(['.gitkeep', '.DS_Store', 'Thumbs.db']);
const DEFAULT_ASSET_IGNORE_PATTERNS: readonly string[] = Array.from(
DEFAULT_ASSET_IGNORE_FILES,
file => `**/${file}`
);

// upstream: angular/angular-cli packages/angular/build/src/utils/resolve-assets.ts @ bdda8bbf1b
function normalizeIgnorePattern(pattern: string): string[] {
if (!pattern) {
return [];
}

const posixNormalized = path.posix.normalize(pattern);
const normalized =
posixNormalized.length > 1 && posixNormalized.endsWith('/')
? posixNormalized.slice(0, -1)
: posixNormalized;

if (!normalized.endsWith('*')) {
return [`${normalized}/**`];
}

if (normalized === '**' || normalized.endsWith('/**')) {
return [normalized];
}

return [normalized, `${normalized}/**`];
}

// upstream: angular/angular-cli packages/angular/build/src/utils/resolve-assets.ts @ bdda8bbf1b
function normalizeAssetIgnorePatterns(ignore?: readonly string[]): string[] {
if (!ignore?.length) {
return [...DEFAULT_ASSET_IGNORE_PATTERNS];
}

return [...DEFAULT_ASSET_IGNORE_PATTERNS, ...ignore.flatMap(normalizeIgnorePattern)];
}

// upstream: angular/angular-cli packages/angular/build/src/utils/resolve-assets.ts @ bdda8bbf1b
async function resolveAssetEntry(
entry: NormalizedAssetEntry,
workspaceRoot: string
): Promise<{ source: string; destination: string }[]> {
if (!entry.glob || entry.glob.endsWith('/')) {
return [];
}

const cwd = path.resolve(workspaceRoot, entry.input);

if (!entry.ignore?.length && !isDynamicPattern(entry.glob)) {
const src = path.join(cwd, entry.glob);
if (isSubDirectory(cwd, src)) {
if (DEFAULT_ASSET_IGNORE_FILES.has(path.basename(src))) {
return [];
}

try {
const stats = await (entry.followSymlinks ? fs.promises.stat(src) : fs.promises.lstat(src));
if (stats.isFile()) {
const filePath = entry.flatten ? path.basename(src) : path.relative(cwd, src);

return [{ source: src, destination: path.join(entry.output, filePath) }];
}

return [];
} catch {
return [];
}
}
}

const files = await glob(entry.glob, {
cwd,
dot: true,
expandDirectories: false,
ignore: normalizeAssetIgnorePatterns(entry.ignore),
followSymbolicLinks: entry.followSymlinks ?? false,
});

return files.map(file => {
const destination = path.join(entry.output, entry.flatten ? path.basename(file) : file);
if (destination === '..' || destination.startsWith(`..${path.sep}`)) {
throw new Error('An asset cannot be written to a location outside of the output path.');
}

return { source: path.join(cwd, file), destination };
});
}

// Deviation: sequential instead of Angular's bounded `mapConcurrent`; a remote has few asset entries.
async function resolveAssets(
entries: NormalizedAssetEntry[],
workspaceRoot: string
): Promise<{ source: string; destination: string }[]> {
const resolved: { source: string; destination: string }[] = [];
for (const entry of entries) {
const cwd = path.resolve(workspaceRoot, entry.input);
const files = await glob(entry.glob, {
cwd,
dot: true,
ignore: [...DEFAULT_ASSET_IGNORE, ...(entry.ignore ?? [])],
followSymbolicLinks: entry.followSymlinks ?? false,
});
for (const file of files) {
resolved.push({
source: path.join(cwd, file),
destination: path.join(entry.output, entry.flatten ? path.basename(file) : file),
});
}
resolved.push(...(await resolveAssetEntry(entry, workspaceRoot)));
}
return resolved;
}
Expand Down
2 changes: 1 addition & 1 deletion src/schematics/init/steps/add-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SchematicsException, type SchematicContext, type Tree } from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks/index.js';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';

type DependencyType = 'dependencies' | 'devDependencies';
type PackageJson = Partial<Record<DependencyType, Record<string, string>>>;
Expand Down Expand Up @@ -33,8 +33,8 @@
addDependency('devDependencies', '@softarc/native-federation-orchestrator', '^4.10.0', true);

if (ssr) {
console.log('SSR detected ...');

Check warning on line 36 in src/schematics/init/steps/add-dependencies.ts

View workflow job for this annotation

GitHub Actions / verify

Unexpected console statement. Only these console methods are allowed: warn, error
console.log('Activating CORS ...');

Check warning on line 37 in src/schematics/init/steps/add-dependencies.ts

View workflow job for this annotation

GitHub Actions / verify

Unexpected console statement. Only these console methods are allowed: warn, error

addDependency('dependencies', 'cors', '^2.8.5');
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/esbuild/node-modules-bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export async function createNodeModulesEsbuildContext(
// Angular ties this to AOT too, but our bundles are always AOT.
const advancedOptimizations = settings.script.optimize;
// Keys the transform cache, so it must hold every option that changes transformer output.
// upstream: angular/angular-cli packages/angular/build/src/tools/javascript-transformer/javascript-transformer.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/tools/javascript-transformer/javascript-transformer.ts @ bdda8bbf1b
const outputOptions = {
sourcemap: !!settings.sourcemap,
thirdPartySourcemaps: false,
Expand Down
16 changes: 8 additions & 8 deletions src/tools/esbuild/script-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function resolveScriptSettings(
};
}

// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/application-code-bundle.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/application-code-bundle.ts @ bdda8bbf1b
export function getScriptBuildOptions(
settings: ScriptSettings,
platform: 'browser' | 'node'
Expand All @@ -62,7 +62,7 @@ export function getScriptBuildOptions(
};
}

// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/application-code-bundle.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/application-code-bundle.ts @ bdda8bbf1b
export function getConditions(optimize: boolean, customConditions: string[] | undefined): string[] {
// Required to support rxjs 7.x which will use es5 code if this condition is not present
const conditions = ['es2015', 'es2020'];
Expand All @@ -78,7 +78,7 @@ export function getConditions(optimize: boolean, customConditions: string[] | un
return conditions;
}

// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/utils.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/utils.ts @ bdda8bbf1b
export function getFeatureSupport(nativeAsyncAwait: boolean): BuildOptions['supported'] {
return {
// Native async/await is not supported with Zone.js. Disabling support here will cause
Expand All @@ -95,20 +95,20 @@ export function getFeatureSupport(nativeAsyncAwait: boolean): BuildOptions['supp
};
}

// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/utils.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/utils.ts @ bdda8bbf1b
export function isZonelessApp(polyfills: string[] | undefined): boolean {
return !polyfills?.some(p => p === 'zone.js' || /\.[mc]?[jt]s$/.test(p));
}

const TRUTHY_VALUES = new Set(['1', 'true']);
const FALSY_VALUES = new Set(['0', 'false']);

// upstream: angular/angular-cli packages/angular/build/src/utils/environment-options.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/utils/environment-options.ts @ bdda8bbf1b
function isPresent(variable: string | undefined): variable is string {
return typeof variable === 'string' && variable !== '';
}

// upstream: angular/angular-cli packages/angular/build/src/utils/environment-options.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/utils/environment-options.ts @ bdda8bbf1b
function parseTristate(variable: string | undefined): boolean | undefined {
if (!isPresent(variable)) {
return undefined;
Expand All @@ -125,14 +125,14 @@ function parseTristate(variable: string | undefined): boolean | undefined {
return undefined;
}

// upstream: angular/angular-cli packages/angular/build/src/utils/environment-options.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/utils/environment-options.ts @ bdda8bbf1b
export function readAllowMangle(env: NodeJS.ProcessEnv): boolean {
return (
parseTristate(env['NG_BUILD_MANGLE']) ?? debugOptimizeMangle(env['NG_BUILD_DEBUG_OPTIMIZE'])
);
}

// Only the `mangle` part of Angular's `debugOptimize`: `minify` and `beautify` are unused in 22.2.
// Only the `mangle` part of Angular's `debugOptimize`: `minify` and `beautify` are unused in 22.3.
function debugOptimizeMangle(debugOptimizeVariable: string | undefined): boolean {
if (!isPresent(debugOptimizeVariable) || parseTristate(debugOptimizeVariable) === false) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/esbuild/sourcemap-ignorelist-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin.ts @ 5a0d226b7c
// upstream: angular/angular-cli packages/angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin.ts @ bdda8bbf1b

import * as path from 'path';
import type { Plugin } from 'esbuild';
Expand Down
4 changes: 2 additions & 2 deletions src/utils/normalize-build-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type NormalizedOptimization = Required<Omit<OptimizationObject, 'fonts' | 'style
type SourceMap = NonNullable<ApplicationBuilderOptions['sourceMap']>;
type NormalizedSourceMap = Extract<SourceMap, object>;

// upstream: angular/angular-cli packages/angular/build/src/utils/normalize-optimization.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/utils/normalize-optimization.ts @ bdda8bbf1b
export function normalizeOptimization(optimization: Optimization = true): NormalizedOptimization {
if (typeof optimization === 'object') {
const styleOptimization = !!optimization.styles;
Expand Down Expand Up @@ -55,7 +55,7 @@ export function normalizeOptimization(optimization: Optimization = true): Normal
};
}

// upstream: angular/angular-cli packages/angular/build/src/utils/normalize-source-maps.ts @ 11dbe297f8
// upstream: angular/angular-cli packages/angular/build/src/utils/normalize-source-maps.ts @ bdda8bbf1b
export function normalizeSourceMaps(sourceMap: SourceMap): NormalizedSourceMap {
const scripts = typeof sourceMap === 'object' ? sourceMap.scripts : sourceMap;
const styles = typeof sourceMap === 'object' ? sourceMap.styles : sourceMap;
Expand Down
Loading