Skip to content

fix(@schematics/angular): add less as a devDependency when selected as the style preprocessor #30504

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
Jun 10, 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
18 changes: 11 additions & 7 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ function addTsProjectReference(...paths: string[]) {
}

export default function (options: ApplicationOptions): Rule {
return async (host: Tree, context: SchematicContext) => {
return async (host: Tree) => {
const { appDir, appRootSelector, componentOptions, folderName, sourceDir } =
await getAppOptions(host, options);

return chain([
addAppToWorkspaceFile(options, appDir, folderName),
addAppToWorkspaceFile(options, appDir),
addTsProjectReference('./' + join(normalize(appDir), 'tsconfig.app.json')),
options.skipTests || options.minimal
? noop()
Expand Down Expand Up @@ -157,6 +157,14 @@ function addDependenciesToPackageJson(options: ApplicationOptions) {
});
}

if (options.style === Style.Less) {
addPackageJsonDependency(host, {
type: NodeDependencyType.Dev,
name: 'less',
version: latestVersions['less'],
});
}

if (!options.skipInstall) {
context.addTask(new NodePackageInstallTask());
}
Expand All @@ -165,11 +173,7 @@ function addDependenciesToPackageJson(options: ApplicationOptions) {
};
}

function addAppToWorkspaceFile(
options: ApplicationOptions,
appDir: string,
folderName: string,
): Rule {
function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rule {
let projectRoot = appDir;
if (projectRoot) {
projectRoot += '/';
Expand Down
14 changes: 14 additions & 0 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,20 @@ describe('Application Schematic', () => {
expect(pkg.dependencies['zone.js']).toEqual(latestVersions['zone.js']);
});

it('should add "less" to devDependencies when Less is selected as the style option', async () => {
const tree = await schematicRunner.runSchematic(
'application',
{
...defaultOptions,
style: Style.Less,
},
workspaceTree,
);

const pkg = JSON.parse(tree.readContent('/package.json'));
expect(pkg.devDependencies['less']).toEqual(latestVersions['less']);
});

it('should include zone.js if "zoneless" option is not present', async () => {
const tree = await schematicRunner.runSchematic(
'application',
Expand Down