Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): ensure webpack tilde resolve beha…
Browse files Browse the repository at this point in the history
…vior for stylesheet resources
  • Loading branch information
clydin authored and mgechev committed Apr 27, 2020
1 parent c034477 commit 254994d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ export default postcss.plugin('postcss-cli-resources', (options: PostcssCliResou
return cachedUrl;
}

if (inputUrl.startsWith('~')) {
inputUrl = inputUrl.substr(1);
}

if (inputUrl.startsWith('/')) {
if (rebaseRootRelative && inputUrl.startsWith('/')) {
let outputUrl = '';
if (deployUrl.match(/:\/\//) || deployUrl.startsWith('/')) {
// If deployUrl is absolute or root relative, ignore baseHref & use deployUrl as is.
Expand All @@ -103,6 +99,10 @@ export default postcss.plugin('postcss-cli-resources', (options: PostcssCliResou
return outputUrl;
}

if (inputUrl.startsWith('~')) {
inputUrl = inputUrl.substr(1);
}

const { pathname, hash, search } = url.parse(inputUrl.replace(/\\/g, '/'));
const resolver = (file: string, base: string) => new Promise<string>((resolve, reject) => {
loader.resolve(base, decodeURI(file), (err, result) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,17 @@ describe('Browser Builder styles', () => {
});

it(`supports font-awesome imports`, async () => {
host.writeMultipleFiles({
'src/styles.scss': `
@import "font-awesome/scss/font-awesome";
`,
});

const overrides = { extractCss: true, styles: [`src/styles.scss`] };
await browserBuild(architect, host, target, overrides);
}, 30000);

it(`supports font-awesome imports (tilde)`, async () => {
host.writeMultipleFiles({
'src/styles.scss': `
$fa-font-path: "~font-awesome/fonts";
Expand Down Expand Up @@ -578,6 +589,31 @@ describe('Browser Builder styles', () => {
await browserBuild(architect, host, target, overrides);
});

it('causes equal failure for tilde and tilde-slash url()', async () => {
host.writeMultipleFiles({
'src/styles.css': `
body {
background-image: url('~/does-not-exist.jpg');
}
`,
});

const overrides = { extractCss: true, optimization: true };
const run = await architect.scheduleTarget(target, overrides);
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: false }));

host.writeMultipleFiles({
'src/styles.css': `
body {
background-image: url('~does-not-exist.jpg');
}
`,
});

const run2 = await architect.scheduleTarget(target, overrides);
await expectAsync(run2.result).toBeResolvedTo(jasmine.objectContaining({ success: false }));
});

it('supports Protocol-relative Url', async () => {
host.writeMultipleFiles({
'src/styles.css': `
Expand Down

0 comments on commit 254994d

Please sign in to comment.