Skip to content

feat(@schematics/angular): directly use @angular/build in new projects #29652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2025
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 @@ -46,6 +46,9 @@ export async function extractMessages(
buildOptions.index = false;
buildOptions.serviceWorker = false;
buildOptions.outputMode = OutputMode.Static;
buildOptions.appShell = undefined;
buildOptions.ssr = undefined;
buildOptions.prerender = undefined;
buildOptions.server = undefined;

// Build the application with the build options
Expand Down
12 changes: 6 additions & 6 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function addDependenciesToPackageJson(options: ApplicationOptions) {
},
{
type: NodeDependencyType.Dev,
name: '@angular-devkit/build-angular',
version: latestVersions.DevkitBuildAngular,
name: '@angular/build',
version: latestVersions.AngularBuild,
},
{
type: NodeDependencyType.Dev,
Expand Down Expand Up @@ -234,7 +234,7 @@ function addAppToWorkspaceFile(
schematics,
targets: {
build: {
builder: Builders.Application,
builder: Builders.BuildApplication,
defaultConfiguration: 'production',
options: {
outputPath: `dist/${folderName}`,
Expand All @@ -260,7 +260,7 @@ function addAppToWorkspaceFile(
},
},
serve: {
builder: Builders.DevServer,
builder: Builders.BuildDevServer,
defaultConfiguration: 'development',
options: {},
configurations: {
Expand All @@ -273,12 +273,12 @@ function addAppToWorkspaceFile(
},
},
'extract-i18n': {
builder: Builders.ExtractI18n,
builder: Builders.BuildExtractI18n,
},
test: options.minimal
? undefined
: {
builder: Builders.Karma,
builder: Builders.BuildKarma,
options: {
polyfills: options.experimentalZoneless ? [] : ['zone.js', 'zone.js/testing'],
tsConfig: `${projectRoot}tsconfig.spec.json`,
Expand Down
6 changes: 2 additions & 4 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,11 @@ describe('Application Schematic', () => {
});

describe(`update package.json`, () => {
it(`should add build-angular to devDependencies`, async () => {
it(`should add @angular/build to devDependencies`, async () => {
const tree = await schematicRunner.runSchematic('application', defaultOptions, workspaceTree);

const packageJson = JSON.parse(tree.readContent('package.json'));
expect(packageJson.devDependencies['@angular-devkit/build-angular']).toEqual(
latestVersions.DevkitBuildAngular,
);
expect(packageJson.devDependencies['@angular/build']).toEqual(latestVersions.AngularBuild);
});

it('should use the latest known versions in package.json', async () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/schematics/angular/config/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ describe('Config Schematic', () => {
expect(tree.exists('projects/foo/karma.conf.js')).toBeTrue();
});

it('should include devkit karma plugin by default', async () => {
it('should not include devkit karma plugin by default', async () => {
const tree = await runConfigSchematic(ConfigType.Karma);
const karmaConf = tree.readText('projects/foo/karma.conf.js');
expect(karmaConf).toContain(`'@angular-devkit/build-angular'`);
expect(karmaConf).not.toContain(`'@angular-devkit/build-angular'`);
});

it('should not include devkit karma plugin with angular/build:karma is used', async () => {
it('should include devkit karma plugin when angular-devkit/build-angular:karma is used', async () => {
applicationTree.overwrite(
'angular.json',
applicationTree
.readText('angular.json')
.replace('@angular-devkit/build-angular:karma', '@angular/build:karma'),
.replace('@angular/build:karma', '@angular-devkit/build-angular:karma'),
);
const tree = await runConfigSchematic(ConfigType.Karma);
const karmaConf = tree.readText('projects/foo/karma.conf.js');
expect(karmaConf).not.toContain(`'@angular-devkit/build-angular'`);
expect(karmaConf).toContain(`'@angular-devkit/build-angular'`);
});

it('should set the right coverage folder', async () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/schematics/angular/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ function addDependenciesToPackageJson() {
},
{
type: NodeDependencyType.Dev,
name: '@angular-devkit/build-angular',
version: latestVersions.DevkitBuildAngular,
name: '@angular/build',
version: latestVersions.AngularBuild,
},
{
type: NodeDependencyType.Dev,
Expand Down Expand Up @@ -91,7 +91,7 @@ function addLibToWorkspaceFile(
prefix: options.prefix,
targets: {
build: {
builder: Builders.NgPackagr,
builder: Builders.BuildNgPackagr,
defaultConfiguration: 'production',
options: {
project: `${projectRoot}/ng-package.json`,
Expand All @@ -106,7 +106,7 @@ function addLibToWorkspaceFile(
},
},
test: {
builder: Builders.Karma,
builder: Builders.BuildKarma,
options: {
tsConfig: `${projectRoot}/tsconfig.spec.json`,
polyfills: ['zone.js', 'zone.js/testing'],
Expand Down
11 changes: 8 additions & 3 deletions packages/schematics/angular/library/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,14 @@ describe('Library Schematic', () => {
const tree = await schematicRunner.runSchematic('library', defaultOptions, workspaceTree);

const workspace = JSON.parse(tree.readContent('/angular.json'));
expect(workspace.projects.foo.architect.build.builder).toBe(
'@angular-devkit/build-angular:ng-packagr',
);
expect(workspace.projects.foo.architect.build.builder).toBe('@angular/build:ng-packagr');
});

it(`should add 'karma' test builder`, async () => {
const tree = await schematicRunner.runSchematic('library', defaultOptions, workspaceTree);

const workspace = JSON.parse(tree.readContent('/angular.json'));
expect(workspace.projects.foo.architect.test.builder).toBe('@angular/build:karma');
});

describe('standalone=false', () => {
Expand Down
6 changes: 6 additions & 0 deletions tests/legacy-cli/e2e/initialize/500-create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export default async function () {
tsconfig.compilerOptions.allowSyntheticDefaultImports = true;
});
}

// Always need `@angular-devkit/build-angular` due to the use of protractor
await updateJsonFile('package.json', (packageJson) => {
packageJson.devDependencies['@angular-devkit/build-angular'] =
packageJson.devDependencies['@angular/build'];
});
}

await prepareProjectForE2e('test-project');
Expand Down
3 changes: 0 additions & 3 deletions tests/legacy-cli/e2e/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ export async function useCIChrome(projectName: string, projectDir = ''): Promise
const project = workspaceJson.projects[projectName];
const appTargets = project.targets || project.architect;
appTargets.test.options.browsers = 'ChromeHeadlessNoSandbox';
appTargets.test.options.builderMode = getGlobalVariable('argv')['esbuild']
? 'application'
: 'browser';
});
}

Expand Down