Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): show error note for CSS url() til…
Browse files Browse the repository at this point in the history
…de 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.

(cherry picked from commit ca8e508)
  • Loading branch information
clydin committed May 9, 2023
1 parent 2967705 commit cb31610
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@ export function createCssResourcePlugin(): Plugin {
resolveDir,
});

if (result.errors.length && args.path[0] === '~') {
result.errors[0].notes = [
{
location: null,
text: 'You can remove the tilde and use a relative path to reference it, which should remove this error.',
},
];
}

// Return results that are not files since these are most likely specific to another plugin
// and cannot be loaded by this plugin.
if (result.namespace !== 'file' || !result.path) {
if (result.namespace !== 'file') {
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import { buildEsbuildBrowser } from '../../index';
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';

describeBuilder(buildEsbuildBrowser, BROWSER_BUILDER_INFO, (harness) => {
describe('Behavior: "Stylesheet url() Resolution"', () => {
it('should show a note when using tilde prefix', async () => {
await harness.writeFile(
'src/styles.css',
`
.a {
background-image: url("~/image.jpg")
}
`,
);

harness.useTarget('build', {
...BASE_OPTIONS,
styles: ['src/styles.css'],
});

const { result, logs } = await harness.executeOnce();
expect(result?.success).toBe(false);

expect(logs).toContain(
jasmine.objectContaining({
message: jasmine.stringMatching('You can remove the tilde and'),
}),
);
});
});
});

0 comments on commit cb31610

Please sign in to comment.