Skip to content

Commit f4be831

Browse files
committed
feat(@angular/build): Support Sass package importers
Enhanced Sass integration by adding support for package importers. See: https://sass-lang.com/blog/announcing-pkg-importers/ Closes: #29854
1 parent 27fe5da commit f4be831

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

Diff for: packages/angular/build/src/tools/esbuild/stylesheets/sass-language.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export const SassStylesheetLanguage = Object.freeze<StylesheetLanguage>({
4343
resolveDir = dirname(fileURLToPath(options.containingUrl));
4444
}
4545

46-
const result = await build.resolve(url, {
46+
const path = url.startsWith('pkg:') ? url.slice(4) : url;
47+
const result = await build.resolve(path, {
4748
kind: 'import-rule',
4849
resolveDir,
4950
});
@@ -56,8 +57,8 @@ export const SassStylesheetLanguage = Object.freeze<StylesheetLanguage>({
5657
});
5758

5859
function parsePackageName(url: string): { packageName: string; readonly pathSegments: string[] } {
59-
const parts = url.split('/');
60-
const hasScope = parts.length >= 2 && parts[0].startsWith('@');
60+
const parts = (url.startsWith('pkg:') ? url.slice(4) : url).split('/');
61+
const hasScope = parts.length >= 2 && parts[0][0] === '@';
6162
const [nameOrScope, nameOrFirstPath, ...pathPart] = parts;
6263
const packageName = hasScope ? `${nameOrScope}/${nameOrFirstPath}` : nameOrScope;
6364

Diff for: tests/legacy-cli/e2e.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ WEBPACK_IGNORE_TESTS = [
4646
"tests/i18n/ivy-localize-app-shell.js",
4747
"tests/i18n/ivy-localize-app-shell-service-worker.js",
4848
"tests/commands/serve/ssr-http-requests-assets.js",
49+
"tests/build/styles/sass-pkg-importer.js",
4950
"tests/build/prerender/http-requests-assets.js",
5051
"tests/build/prerender/error-with-sourcemaps.js",
5152
"tests/build/server-rendering/server-routes-*",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import assert from 'node:assert';
2+
import { writeFile } from '../../../utils/fs';
3+
import { getActivePackageManager, uninstallPackage } from '../../../utils/packages';
4+
import { ng } from '../../../utils/process';
5+
import { isPrereleaseCli, updateJsonFile } from '../../../utils/project';
6+
import { appendFile } from 'node:fs/promises';
7+
import { getGlobalVariable } from '../../../utils/env';
8+
9+
export default async function () {
10+
assert(
11+
getGlobalVariable('argv')['esbuild'],
12+
'This test should not be called in the Webpack suite.',
13+
);
14+
15+
// forcibly remove in case another test doesn't clean itself up
16+
await uninstallPackage('@angular/material');
17+
18+
const isPrerelease = await isPrereleaseCli();
19+
const tag = isPrerelease ? '@next' : '';
20+
if (getActivePackageManager() === 'npm') {
21+
await appendFile('.npmrc', '\nlegacy-peer-deps=true');
22+
}
23+
24+
await ng('add', `@angular/material${tag}`, '--skip-confirmation');
25+
await Promise.all([
26+
updateJsonFile('angular.json', (workspaceJson) => {
27+
const appArchitect = workspaceJson.projects['test-project'].architect;
28+
appArchitect.build.options.styles = ['src/styles.scss'];
29+
}),
30+
writeFile('src/styles.scss', `@use 'pkg:@angular/material' as mat;`),
31+
]);
32+
33+
await ng('build');
34+
}

0 commit comments

Comments
 (0)