Skip to content

Commit 5c1cafe

Browse files
hanslclydin
authored andcommitted
fix(@angular-devkit/schematics): fix declaring multiple aliases
Fix #11389
1 parent 9e779af commit 5c1cafe

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

packages/angular_devkit/schematics/tools/file-system-engine-host-base.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ export abstract class FileSystemEngineHostBase implements
165165
if (allNames.indexOf(alias) != -1) {
166166
throw new SchematicNameCollisionException(alias);
167167
}
168-
allNames.push(...aliases);
169168
}
169+
170+
allNames.push(...aliases);
170171
}
171172

172173
return description;

packages/angular_devkit/schematics/tools/file-system-engine-host_spec.ts

+39
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,45 @@ describe('FileSystemEngineHost', () => {
4242
expect(schematic1.description.name).toBe('schematic1');
4343
});
4444

45+
it('understands multiple aliases for a single schematic', () => {
46+
const engineHost = new FileSystemEngineHost(root);
47+
const engine = new SchematicEngine(engineHost);
48+
49+
const testCollection = engine.createCollection('aliases-many');
50+
51+
const schematic1 = engine.createSchematic('alias1', testCollection);
52+
expect(schematic1).not.toBeNull();
53+
expect(schematic1.description.name).toBe('schematic1');
54+
55+
const schematic2 = engine.createSchematic('alias2', testCollection);
56+
expect(schematic2).not.toBeNull();
57+
expect(schematic2.description.name).toBe('schematic1');
58+
59+
const schematic3 = engine.createSchematic('alias3', testCollection);
60+
expect(schematic3).not.toBeNull();
61+
expect(schematic3.description.name).toBe('schematic1');
62+
});
63+
64+
65+
it('allows dupe aliases for a single schematic', () => {
66+
const engineHost = new FileSystemEngineHost(root);
67+
const engine = new SchematicEngine(engineHost);
68+
69+
const testCollection = engine.createCollection('aliases-dupe');
70+
71+
const schematic1 = engine.createSchematic('alias1', testCollection);
72+
expect(schematic1).not.toBeNull();
73+
expect(schematic1.description.name).toBe('schematic1');
74+
75+
const schematic2 = engine.createSchematic('alias2', testCollection);
76+
expect(schematic2).not.toBeNull();
77+
expect(schematic2.description.name).toBe('schematic1');
78+
79+
const schematic3 = engine.createSchematic('alias3', testCollection);
80+
expect(schematic3).not.toBeNull();
81+
expect(schematic3.description.name).toBe('schematic1');
82+
});
83+
4584
it('lists schematics but not aliases', () => {
4685
const engineHost = new FileSystemEngineHost(root);
4786
const engine = new SchematicEngine(engineHost);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "aliases-dupe",
3+
"schematics": {
4+
"schematic1": {
5+
"aliases": ["alias1", "alias2", "alias3", "alias1", "alias2"],
6+
"description": "1",
7+
"factory": "../null-factory"
8+
},
9+
"schematic2": {
10+
"description": "2",
11+
"factory": "../null-factory"
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "aliases-many",
3+
"schematics": {
4+
"schematic1": {
5+
"aliases": ["alias1", "alias2", "alias3"],
6+
"description": "1",
7+
"factory": "../null-factory"
8+
},
9+
"schematic2": {
10+
"description": "2",
11+
"factory": "../null-factory"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)