Skip to content

Commit 0fa1e34

Browse files
clydinalan-agius4
authored andcommittedDec 13, 2023
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.
1 parent e9a51a3 commit 0fa1e34

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
@@ -74,7 +74,7 @@ export function createAngularCompilerHost(
7474
context.resourceFile ?? undefined,
7575
);
7676

77-
return result ? { content: result } : null;
77+
return typeof result === 'string' ? { content: result } : null;
7878
};
7979

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

0 commit comments

Comments
 (0)
Please sign in to comment.