Skip to content

Commit 0662048

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): ensure empty optimized Sass stylesheets stay empty
When an optimized Sass stylesheet becomes an empty string the AOT Angular host adapter was previously treating this as a falsy value and using the original content of the stylesheet. Empty strings are now considered valid values and will be passed to the AOT compiler as such. (cherry picked from commit 0fa1e34)
1 parent eeb5634 commit 0662048

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/angular_devkit/build_angular/src/builders/application/tests/behavior/component-stylesheets_spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,26 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
2323
const { result } = await harness.executeOnce();
2424
expect(result?.success).toBeTrue();
2525
});
26+
27+
it('should maintain optimized empty Sass stylesheet when original has content', async () => {
28+
await harness.modifyFile('src/app/app.component.ts', (content) => {
29+
return content.replace('./app.component.css', './app.component.scss');
30+
});
31+
await harness.removeFile('src/app/app.component.css');
32+
await harness.writeFile('src/app/app.component.scss', '@import "variables";');
33+
await harness.writeFile('src/app/_variables.scss', '$value: blue;');
34+
35+
harness.useTarget('build', {
36+
...BASE_OPTIONS,
37+
optimization: {
38+
styles: true,
39+
},
40+
});
41+
42+
const { result } = await harness.executeOnce();
43+
expect(result?.success).toBeTrue();
44+
45+
harness.expectFile('dist/browser/main.js').content.not.toContain('variables');
46+
});
2647
});
2748
});

packages/angular_devkit/build_angular/src/tools/esbuild/angular/angular-host.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function createAngularCompilerHost(
6868
context.resourceFile ?? undefined,
6969
);
7070

71-
return result ? { content: result } : null;
71+
return typeof result === 'string' ? { content: result } : null;
7272
};
7373

7474
// Allow the AOT compiler to request the set of changed templates and styles

0 commit comments

Comments
 (0)