Skip to content

Commit 005ba42

Browse files
clydinangular-robot[bot]
authored andcommitted
fix(@angular-devkit/build-angular): ensure empty component styles compile with esbuild
Previously when using the esbuild-based browser application builder, an empty inline component style (`styles: ['']`) would cause the build to fail. This was due to a bad assertion condition that has now been corrected.
1 parent ee8013f commit 005ba42

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/css-plugin.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ export function createCssPlugin(options: CssPluginOptions): Plugin {
8080
// Add a load callback to support inline Component styles
8181
build.onLoad({ filter: /^css;/, namespace: 'angular:styles/component' }, async (args) => {
8282
const data = options.inlineComponentData?.[args.path];
83-
assert(data, `component style name should always be found [${args.path}]`);
83+
assert(
84+
typeof data === 'string',
85+
`component style name should always be found [${args.path}]`,
86+
);
8487

8588
const [, , filePath] = args.path.split(';', 3);
8689

packages/angular_devkit/build_angular/src/builders/browser-esbuild/less-plugin.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export function createLessPlugin(options: LessPluginOptions): Plugin {
4040
// Add a load callback to support inline Component styles
4141
build.onLoad({ filter: /^less;/, namespace: 'angular:styles/component' }, async (args) => {
4242
const data = options.inlineComponentData?.[args.path];
43-
assert(data, `component style name should always be found [${args.path}]`);
43+
assert(
44+
typeof data === 'string',
45+
`component style name should always be found [${args.path}]`,
46+
);
4447

4548
const [, , filePath] = args.path.split(';', 3);
4649

packages/angular_devkit/build_angular/src/builders/browser-esbuild/sass-plugin.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ export function createSassPlugin(options: SassPluginOptions): Plugin {
6464

6565
build.onLoad({ filter: /^s[ac]ss;/, namespace: 'angular:styles/component' }, async (args) => {
6666
const data = options.inlineComponentData?.[args.path];
67-
assert(data, `component style name should always be found [${args.path}]`);
67+
assert(
68+
typeof data === 'string',
69+
`component style name should always be found [${args.path}]`,
70+
);
6871

6972
const [language, , filePath] = args.path.split(';', 3);
7073
const syntax = language === 'sass' ? 'indented' : 'scss';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { buildEsbuildBrowser } from '../../index';
10+
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';
11+
12+
describeBuilder(buildEsbuildBrowser, BROWSER_BUILDER_INFO, (harness) => {
13+
describe('Behavior: "Component Stylesheets"', () => {
14+
it('should successfuly compile with an empty inline style', async () => {
15+
await harness.modifyFile('src/app/app.component.ts', (content) => {
16+
return content.replace('styleUrls', 'styles').replace('./app.component.css', '');
17+
});
18+
19+
harness.useTarget('build', {
20+
...BASE_OPTIONS,
21+
});
22+
23+
const { result } = await harness.executeOnce();
24+
expect(result?.success).toBeTrue();
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)