Skip to content

Commit 42f45a3

Browse files
committed
fix(@schematics/angular): add less as a devDependency when selected as the style preprocessor
Ensure `less` is automatically added to `devDependencies` when users choose it as the style preprocessor during application generation. Closes #30503
1 parent e36cbba commit 42f45a3

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

packages/schematics/angular/application/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ function addTsProjectReference(...paths: string[]) {
4949
}
5050

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

5656
return chain([
57-
addAppToWorkspaceFile(options, appDir, folderName),
57+
addAppToWorkspaceFile(options, appDir),
5858
addTsProjectReference('./' + join(normalize(appDir), 'tsconfig.app.json')),
5959
options.skipTests || options.minimal
6060
? noop()
@@ -157,6 +157,14 @@ function addDependenciesToPackageJson(options: ApplicationOptions) {
157157
});
158158
}
159159

160+
if (options.style === Style.Less) {
161+
addPackageJsonDependency(host, {
162+
type: NodeDependencyType.Dev,
163+
name: 'less',
164+
version: latestVersions['less'],
165+
});
166+
}
167+
160168
if (!options.skipInstall) {
161169
context.addTask(new NodePackageInstallTask());
162170
}
@@ -165,11 +173,7 @@ function addDependenciesToPackageJson(options: ApplicationOptions) {
165173
};
166174
}
167175

168-
function addAppToWorkspaceFile(
169-
options: ApplicationOptions,
170-
appDir: string,
171-
folderName: string,
172-
): Rule {
176+
function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rule {
173177
let projectRoot = appDir;
174178
if (projectRoot) {
175179
projectRoot += '/';

packages/schematics/angular/application/index_spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,20 @@ describe('Application Schematic', () => {
282282
expect(pkg.dependencies['zone.js']).toEqual(latestVersions['zone.js']);
283283
});
284284

285+
it('should add "less" to devDependencies when Less is selected as the style option', async () => {
286+
const tree = await schematicRunner.runSchematic(
287+
'application',
288+
{
289+
...defaultOptions,
290+
style: Style.Less,
291+
},
292+
workspaceTree,
293+
);
294+
295+
const pkg = JSON.parse(tree.readContent('/package.json'));
296+
expect(pkg.devDependencies['less']).toEqual(latestVersions['less']);
297+
});
298+
285299
it('should include zone.js if "zoneless" option is not present', async () => {
286300
const tree = await schematicRunner.runSchematic(
287301
'application',

0 commit comments

Comments
 (0)