Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 021a826

Browse files
committedMar 27, 2025·
refactor(@angular/cli): avoid implicit undefined defaults for @angular/build builders
Previously, all builder options that were of type array or object were set to a default empty value even if there was no explicit default defined within the schema. This can be problematic for options that have differing behavior based on their presence such as runtime calculated defaults. The implicit defaulting behavior was also not aligned with the generated schema types which resulted in additional type safety and initialization regardless. As a result, the implicit behavior was effectively redundant in most cases. Since this change could be breaking for third-party builders, the removal of this behavior is currently limited to the `@angular/build` package.
1 parent a5ace27 commit 021a826

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed
 

‎modules/testing/builder/src/builder-harness.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ export class BuilderHarness<T> {
104104
...builderInfo,
105105
};
106106

107-
this.schemaRegistry.addPostTransform(json.schema.transforms.addUndefinedDefaults);
107+
if (!builderInfo?.builderName?.startsWith('@angular/build:')) {
108+
this.schemaRegistry.addPostTransform(json.schema.transforms.addUndefinedDefaults);
109+
}
108110
}
109111

110112
private resolvePath(path: string): string {

‎packages/angular/build/src/builders/application/tests/setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Schema } from '../schema';
1313
export * from '../../../../../../../modules/testing/builder/src';
1414

1515
export const APPLICATION_BUILDER_INFO = Object.freeze({
16-
name: '@angular-devkit/build-angular:application',
16+
name: '@angular/build:application',
1717
schemaPath: __dirname + '/../schema.json',
1818
});
1919

‎packages/angular/cli/src/command-builder/architect-base-command-module.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ export abstract class ArchitectBaseCommandModule<T extends object>
5252
return this.onMissingTarget(e.message);
5353
}
5454

55+
const isAngularBuild = builderName.startsWith('@angular/build:');
56+
5557
const { logger } = this.context;
56-
const run = await this.getArchitect().scheduleTarget(target, options as json.JsonObject, {
57-
logger,
58-
});
58+
const run = await this.getArchitect(isAngularBuild).scheduleTarget(
59+
target,
60+
options as json.JsonObject,
61+
{
62+
logger,
63+
},
64+
);
5965

6066
const analytics = isPackageNameSafeForAnalytics(builderName)
6167
? await this.getAnalytics()
@@ -150,13 +156,15 @@ export abstract class ArchitectBaseCommandModule<T extends object>
150156
}
151157

152158
private _architect: Architect | undefined;
153-
protected getArchitect(): Architect {
159+
protected getArchitect(skipUndefinedTransform: boolean): Architect {
154160
if (this._architect) {
155161
return this._architect;
156162
}
157163

158164
const registry = new json.schema.CoreSchemaRegistry();
159-
registry.addPostTransform(json.schema.transforms.addUndefinedDefaults);
165+
if (!skipUndefinedTransform) {
166+
registry.addPostTransform(json.schema.transforms.addUndefinedDefaults);
167+
}
160168
registry.useXDeprecatedProvider((msg) => this.context.logger.warn(msg));
161169

162170
const architectHost = this.getArchitectHost();

0 commit comments

Comments
 (0)
Please sign in to comment.