Skip to content

Commit fe752ad

Browse files
clydindgp1130
authored andcommitted
fix(@angular-devkit/build-angular): encode Sass package resolve directories in importer URLs
When using the new developer preview application build system, Sass import/use usage that specifies a package is adjusted to contain the resolve directory to workaround Sass import plugin limitations. This resolve directory is now encoded to prevent the new specifier from looking like a URL with a scheme to the Sass compiler. This can occur on Windows when a drive letter is present (`C:\`). (cherry picked from commit 8b74a50)
1 parent 221ab24 commit fe752ad

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

Diff for: packages/angular_devkit/build_angular/src/tools/sass/rebasing-importer.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,20 @@ export interface DirectoryEntry {
3333
const MODULE_RESOLUTION_PREFIX = '__NG_PACKAGE__';
3434

3535
function packModuleSpecifier(specifier: string, resolveDir: string): string {
36-
const packed = MODULE_RESOLUTION_PREFIX + ';' + resolveDir + ';' + specifier;
37-
38-
// Normalize path separators and escape characters
39-
// https://developer.mozilla.org/en-US/docs/Web/CSS/url#syntax
40-
const normalizedPacked = packed.replace(/\\/g, '/').replace(/[()\s'"]/g, '\\$&');
41-
42-
return normalizedPacked;
36+
const packed =
37+
MODULE_RESOLUTION_PREFIX +
38+
';' +
39+
// Encode the resolve directory to prevent unsupported characters from being present when
40+
// Sass processes the URL. This is important on Windows which can contain drive letters
41+
// and colons which would otherwise be interpreted as a URL scheme.
42+
encodeURIComponent(resolveDir) +
43+
';' +
44+
// Escape characters instead of encoding to provide more friendly not found error messages.
45+
// Unescaping is automatically handled by Sass.
46+
// https://developer.mozilla.org/en-US/docs/Web/CSS/url#syntax
47+
specifier.replace(/[()\s'"]/g, '\\$&');
48+
49+
return packed;
4350
}
4451

4552
function unpackModuleSpecifier(specifier: string): { specifier: string; resolveDir?: string } {
@@ -51,7 +58,7 @@ function unpackModuleSpecifier(specifier: string): { specifier: string; resolveD
5158

5259
return {
5360
specifier: values[2],
54-
resolveDir: values[1],
61+
resolveDir: decodeURIComponent(values[1]),
5562
};
5663
}
5764

Diff for: tests/legacy-cli/e2e/tests/build/styles/scss-partial-resolution.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ export default async function () {
1212

1313
await writeMultipleFiles({
1414
'src/styles.scss': `
15-
@use '@material/button/button' as mat;
15+
@use '@material/button/button';
16+
17+
@include button.core-styles;
1618
`,
1719
'src/app/app.component.scss': `
18-
@use '@material/button/button' as mat;
20+
@use '@material/button/button';
21+
22+
@include button.core-styles;
1923
`,
2024
});
2125

0 commit comments

Comments
 (0)