Skip to content

feat(@angular/build): Support Sass package importers #29855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const SassStylesheetLanguage = Object.freeze<StylesheetLanguage>({
resolveDir = dirname(fileURLToPath(options.containingUrl));
}

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

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

Expand Down
1 change: 1 addition & 0 deletions tests/legacy-cli/e2e.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ WEBPACK_IGNORE_TESTS = [
"tests/i18n/ivy-localize-app-shell.js",
"tests/i18n/ivy-localize-app-shell-service-worker.js",
"tests/commands/serve/ssr-http-requests-assets.js",
"tests/build/styles/sass-pkg-importer.js",
"tests/build/prerender/http-requests-assets.js",
"tests/build/prerender/error-with-sourcemaps.js",
"tests/build/server-rendering/server-routes-*",
Expand Down
34 changes: 34 additions & 0 deletions tests/legacy-cli/e2e/tests/build/styles/sass-pkg-importer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import assert from 'node:assert';
import { writeFile } from '../../../utils/fs';
import { getActivePackageManager, uninstallPackage } from '../../../utils/packages';
import { ng } from '../../../utils/process';
import { isPrereleaseCli, updateJsonFile } from '../../../utils/project';
import { appendFile } from 'node:fs/promises';
import { getGlobalVariable } from '../../../utils/env';

export default async function () {
assert(
getGlobalVariable('argv')['esbuild'],
'This test should not be called in the Webpack suite.',
);

// forcibly remove in case another test doesn't clean itself up
await uninstallPackage('@angular/material');

const isPrerelease = await isPrereleaseCli();
const tag = isPrerelease ? '@next' : '';
if (getActivePackageManager() === 'npm') {
await appendFile('.npmrc', '\nlegacy-peer-deps=true');
}

await ng('add', `@angular/material${tag}`, '--skip-confirmation');
await Promise.all([
updateJsonFile('angular.json', (workspaceJson) => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect.build.options.styles = ['src/styles.scss'];
}),
writeFile('src/styles.scss', `@use 'pkg:@angular/material' as mat;`),
]);

await ng('build');
}