Skip to content

Commit 7a42a5d

Browse files
committed
fix(material/schematics): account for browser-esbuild builder (#28025)
Fixes that the schematics would throw if the app is using the `browser-esbuild` builder from the CLI. (cherry picked from commit 311b8ae)
1 parent d6d0f80 commit 7a42a5d

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

src/cdk/schematics/utils/project-targets.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export function getProjectBuildTargets(
3333
project,
3434
builder =>
3535
builder === '@angular-devkit/build-angular:application' ||
36-
builder === '@angular-devkit/build-angular:browser',
36+
builder === '@angular-devkit/build-angular:browser' ||
37+
builder === '@angular-devkit/build-angular:browser-esbuild',
3738
);
3839
}
3940

src/material/schematics/ng-add/index.spec.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,75 @@ describe('ng-add schematic', () => {
668668
.toContain('BrowserAnimationsModule');
669669
});
670670
});
671+
672+
describe('using browser-esbuild builder', () => {
673+
beforeEach(() => {
674+
const config = {
675+
version: 1,
676+
projects: {
677+
material: {
678+
projectType: 'application',
679+
root: 'projects/material',
680+
sourceRoot: 'projects/material/src',
681+
prefix: 'app',
682+
architect: {
683+
build: {
684+
builder: '@angular-devkit/build-angular:browser-esbuild',
685+
options: {
686+
outputPath: 'dist/material',
687+
index: 'projects/material/src/index.html',
688+
main: 'projects/material/src/main.ts',
689+
styles: ['projects/material/src/styles.css'],
690+
},
691+
},
692+
test: {
693+
builder: '@angular-devkit/build-angular:karma',
694+
options: {
695+
outputPath: 'dist/material',
696+
index: 'projects/material/src/index.html',
697+
browser: 'projects/material/src/main.ts',
698+
styles: ['projects/material/src/styles.css'],
699+
},
700+
},
701+
},
702+
},
703+
},
704+
};
705+
706+
appTree.overwrite('/angular.json', JSON.stringify(config, null, 2));
707+
});
708+
709+
it('should add a theme', async () => {
710+
const tree = await runner.runSchematic('ng-add-setup-project', baseOptions, appTree);
711+
const workspace = await getWorkspace(tree);
712+
const project = getProjectFromWorkspace(workspace, baseOptions.project);
713+
714+
expectProjectStyleFile(project, '@angular/material/prebuilt-themes/indigo-pink.css');
715+
});
716+
717+
it('should add material app styles', async () => {
718+
const tree = await runner.runSchematic('ng-add-setup-project', baseOptions, appTree);
719+
const workspace = await getWorkspace(tree);
720+
const project = getProjectFromWorkspace(workspace, baseOptions.project);
721+
722+
const defaultStylesPath = getProjectStyleFile(project)!;
723+
const htmlContent = tree.read(defaultStylesPath)!.toString();
724+
725+
expect(htmlContent).toContain('html, body { height: 100%; }');
726+
expect(htmlContent).toContain(
727+
'body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }',
728+
);
729+
});
730+
731+
it('should add the BrowserAnimationsModule to the project module', async () => {
732+
const tree = await runner.runSchematic('ng-add-setup-project', baseOptions, appTree);
733+
const fileContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
734+
735+
expect(fileContent)
736+
.withContext('Expected the project app module to import the "BrowserAnimationsModule".')
737+
.toContain('BrowserAnimationsModule');
738+
});
739+
});
671740
});
672741

673742
describe('ng-add schematic - library project', () => {

0 commit comments

Comments
 (0)