Skip to content

Commit 4d4d118

Browse files
alan-agius4kyliau
authored andcommitted
fix(@angular-devkit/schematics-cli): inconsistency in referencing collection
Fixes #12600
1 parent 22d01a8 commit 4d4d118

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

packages/angular_devkit/schematics_cli/bin/schematics.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ import {
2323
SchematicEngine,
2424
UnsuccessfulWorkflowExecution,
2525
} from '@angular-devkit/schematics';
26-
import {
27-
FileSystemEngineHost,
28-
NodeModulesEngineHost,
29-
NodeWorkflow,
30-
} from '@angular-devkit/schematics/tools';
26+
import { NodeModulesEngineHost, NodeWorkflow } from '@angular-devkit/schematics/tools';
3127
import * as minimist from 'minimist';
3228

3329

@@ -90,7 +86,6 @@ export async function main({
9086

9187
/** Create the DevKit Logger used through the CLI. */
9288
const logger = createConsoleLogger(argv['verbose'], stdout, stderr);
93-
9489
if (argv.help) {
9590
logger.info(getUsage());
9691

@@ -104,16 +99,18 @@ export async function main({
10499
} = parseSchematicName(argv._.shift() || null);
105100
const isLocalCollection = collectionName.startsWith('.') || collectionName.startsWith('/');
106101

107-
108102
/** If the user wants to list schematics, we simply show all the schematic names. */
109103
if (argv['list-schematics']) {
110-
const engineHost = isLocalCollection
111-
? new FileSystemEngineHost(normalize(process.cwd()))
112-
: new NodeModulesEngineHost();
113-
114-
const engine = new SchematicEngine(engineHost);
115-
const collection = engine.createCollection(collectionName);
116-
logger.info(engine.listSchematicNames(collection).join('\n'));
104+
try {
105+
const engineHost = new NodeModulesEngineHost();
106+
const engine = new SchematicEngine(engineHost);
107+
const collection = engine.createCollection(collectionName);
108+
logger.info(engine.listSchematicNames(collection).join('\n'));
109+
} catch (error) {
110+
logger.fatal(error.message);
111+
112+
return 1;
113+
}
117114

118115
return 0;
119116
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as path from 'path';
2+
import { getGlobalVariable } from '../../utils/env';
3+
import { exec, execAndWaitForOutputToMatch, silentNpm } from '../../utils/process';
4+
5+
const packages = require('../../../../../lib/packages').packages;
6+
7+
export default async function () {
8+
// setup
9+
const argv = getGlobalVariable('argv');
10+
if (argv.noglobal) {
11+
return;
12+
}
13+
14+
const startCwd = process.cwd();
15+
await silentNpm('install', '-g', packages['@angular-devkit/schematics-cli'].tar, '--unsafe-perm');
16+
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');
17+
18+
// create blank schematic
19+
await exec('schematics', 'schematic', '--name', 'test-schematic');
20+
21+
process.chdir(path.join(startCwd, 'test-schematic'));
22+
await execAndWaitForOutputToMatch(
23+
'schematics',
24+
['.:', '--list-schematics'],
25+
/my-full-schematic/,
26+
);
27+
28+
// restore path
29+
process.chdir(startCwd);
30+
31+
}

0 commit comments

Comments
 (0)