Skip to content

Commit ca8e508

Browse files
clydinangular-robot[bot]
authored andcommitted
fix(@angular-devkit/build-angular): show error note for CSS url() tilde usage in esbuild builder
When using the esbuild-based browser application builder with a `url()` in a stylesheet that uses that Webpack-specific tilde prefix, a note will be added to the resolution error providing additional information regarding the removal of the tilde.
1 parent 9d8f628 commit ca8e508

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,18 @@ export function createCssResourcePlugin(): Plugin {
5555
resolveDir,
5656
});
5757

58+
if (result.errors.length && args.path[0] === '~') {
59+
result.errors[0].notes = [
60+
{
61+
location: null,
62+
text: 'You can remove the tilde and use a relative path to reference it, which should remove this error.',
63+
},
64+
];
65+
}
66+
5867
// Return results that are not files since these are most likely specific to another plugin
5968
// and cannot be loaded by this plugin.
60-
if (result.namespace !== 'file' || !result.path) {
69+
if (result.namespace !== 'file') {
6170
return result;
6271
}
6372

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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: "Stylesheet url() Resolution"', () => {
14+
it('should show a note when using tilde prefix', async () => {
15+
await harness.writeFile(
16+
'src/styles.css',
17+
`
18+
.a {
19+
background-image: url("~/image.jpg")
20+
}
21+
`,
22+
);
23+
24+
harness.useTarget('build', {
25+
...BASE_OPTIONS,
26+
styles: ['src/styles.css'],
27+
});
28+
29+
const { result, logs } = await harness.executeOnce();
30+
expect(result?.success).toBe(false);
31+
32+
expect(logs).toContain(
33+
jasmine.objectContaining({
34+
message: jasmine.stringMatching('You can remove the tilde and'),
35+
}),
36+
);
37+
});
38+
});
39+
});

0 commit comments

Comments
 (0)