Skip to content

Commit 37693c4

Browse files
sidhanshamilclydin
authored andcommitted
feat(@angular-devkit/schematics-cli): add package manager option to blank schematic
1 parent 7af63b4 commit 37693c4

File tree

8 files changed

+46
-17
lines changed

8 files changed

+46
-17
lines changed

packages/angular_devkit/schematics_cli/bin/schematics.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// symbol polyfill must go first
1111
import 'symbol-observable';
12-
import type { JsonValue, logging, schema } from '@angular-devkit/core';
12+
import { JsonValue, logging, schema } from '@angular-devkit/core';
1313
import { ProcessOutput, createConsoleLogger } from '@angular-devkit/core/node';
1414
import { UnsuccessfulWorkflowExecution } from '@angular-devkit/schematics';
1515
import { NodeWorkflow } from '@angular-devkit/schematics/tools';
@@ -338,6 +338,8 @@ export async function main({
338338
}
339339
});
340340

341+
workflow.registry.addPostTransform(schema.transforms.addUndefinedDefaults);
342+
341343
// Show usage of deprecated options
342344
workflow.registry.useXDeprecatedProvider((msg) => logger.warn(msg));
343345

packages/angular_devkit/schematics_cli/blank/factory.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ export default function (options: Schema): Rule {
9090
move(options.name),
9191
]);
9292

93-
context.addTask(new NodePackageInstallTask(options.name));
93+
context.addTask(
94+
new NodePackageInstallTask({
95+
workingDirectory: options.name,
96+
packageManager: options.packageManager,
97+
}),
98+
);
9499
}
95100

96101
return chain([

packages/angular_devkit/schematics_cli/blank/schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"index": 0
1313
}
1414
},
15+
"packageManager": {
16+
"description": "The package manager used to install dependencies.",
17+
"type": "string",
18+
"enum": ["npm", "yarn", "pnpm", "cnpm", "bun"],
19+
"default": "npm"
20+
},
1521
"author": {
1622
"type": "string",
1723
"description": "Author for the new schematic."

packages/angular_devkit/schematics_cli/schematic/factory.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ export default function (options: Schema): Rule {
2424
const coreVersion = require('@angular-devkit/core/package.json').version;
2525

2626
return (_, context) => {
27-
context.addTask(new NodePackageInstallTask(options.name));
27+
context.addTask(
28+
new NodePackageInstallTask({
29+
workingDirectory: options.name,
30+
packageManager: options.packageManager,
31+
}),
32+
);
2833

2934
return mergeWith(
3035
apply(url('./files'), [

packages/angular_devkit/schematics_cli/schematic/schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"author": {
1212
"type": "string",
1313
"description": "Author for the new schematic."
14+
},
15+
"packageManager": {
16+
"description": "The package manager used to install dependencies.",
17+
"type": "string",
18+
"enum": ["npm", "yarn", "pnpm", "cnpm", "bun"],
19+
"default": "npm"
1420
}
1521
},
1622
"required": ["name"]

tests/legacy-cli/e2e/tests/schematics_cli/basic.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as path from 'path';
1+
import { join } from 'node:path';
22
import { getGlobalVariable } from '../../utils/env';
33
import { exec, execAndWaitForOutputToMatch, silentNpm } from '../../utils/process';
44
import { rimraf } from '../../utils/fs';
@@ -14,13 +14,13 @@ export default async function () {
1414
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');
1515

1616
const startCwd = process.cwd();
17-
const schematicPath = path.join(startCwd, 'test-schematic');
17+
const schematicPath = join(startCwd, 'test-schematic');
1818

1919
try {
2020
// create blank schematic
2121
await exec('schematics', 'schematic', '--name', 'test-schematic');
2222

23-
process.chdir(path.join(startCwd, 'test-schematic'));
23+
process.chdir(join(startCwd, 'test-schematic'));
2424
await execAndWaitForOutputToMatch(
2525
'schematics',
2626
['.:', '--list-schematics'],
@@ -29,6 +29,9 @@ export default async function () {
2929
} finally {
3030
// restore path
3131
process.chdir(startCwd);
32-
await rimraf(schematicPath);
32+
await Promise.all([
33+
rimraf(schematicPath),
34+
silentNpm('uninstall', '-g', '@angular-devkit/schematics-cli'),
35+
]);
3336
}
3437
}

tests/legacy-cli/e2e/tests/schematics_cli/blank-test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as fs from 'fs';
2-
import * as path from 'path';
1+
import { join } from 'node:path';
32
import { getGlobalVariable } from '../../utils/env';
43
import { exec, silentNpm } from '../../utils/process';
54
import { rimraf } from '../../utils/fs';
@@ -15,19 +14,21 @@ export default async function () {
1514
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');
1615

1716
const startCwd = process.cwd();
18-
const schematicPath = path.join(startCwd, 'test-schematic');
17+
const schematicPath = join(startCwd, 'test-schematic');
1918

2019
try {
2120
// create schematic
2221
await exec('schematics', 'blank', '--name', 'test-schematic');
2322

2423
process.chdir(schematicPath);
2524

26-
await silentNpm('install');
2725
await silentNpm('test');
2826
} finally {
2927
// restore path
3028
process.chdir(startCwd);
31-
await rimraf(schematicPath);
29+
await Promise.all([
30+
rimraf(schematicPath),
31+
silentNpm('uninstall', '-g', '@angular-devkit/schematics-cli'),
32+
]);
3233
}
3334
}

tests/legacy-cli/e2e/tests/schematics_cli/schematic-test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as fs from 'fs';
2-
import * as path from 'path';
1+
import { join } from 'node:path';
32
import { getGlobalVariable } from '../../utils/env';
43
import { exec, silentNpm } from '../../utils/process';
54
import { rimraf } from '../../utils/fs';
@@ -15,19 +14,21 @@ export default async function () {
1514
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');
1615

1716
const startCwd = process.cwd();
18-
const schematicPath = path.join(startCwd, 'test-schematic');
17+
const schematicPath = join(startCwd, 'test-schematic');
1918

2019
try {
2120
// create schematic
2221
await exec('schematics', 'schematic', '--name', 'test-schematic');
2322

2423
process.chdir(schematicPath);
2524

26-
await silentNpm('install');
2725
await silentNpm('test');
2826
} finally {
2927
// restore path
3028
process.chdir(startCwd);
31-
await rimraf(schematicPath);
29+
await Promise.all([
30+
rimraf(schematicPath),
31+
silentNpm('uninstall', '-g', '@angular-devkit/schematics-cli'),
32+
]);
3233
}
3334
}

0 commit comments

Comments
 (0)