Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit fbcdb11

Browse files
Broccohansl
authored andcommitted
fix(@schematics/angular): Allow prefix to be an empty string
fixes angular/angular-cli#10659
1 parent fa1e740 commit fbcdb11

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

packages/schematics/angular/component/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function buildSelector(options: ComponentOptions, projectPrefix: string) {
9696
let selector = strings.dasherize(options.name);
9797
if (options.prefix) {
9898
selector = `${options.prefix}-${selector}`;
99-
} else if (projectPrefix) {
99+
} else if (options.prefix === undefined && projectPrefix) {
100100
selector = `${projectPrefix}-${selector}`;
101101
}
102102

packages/schematics/angular/component/index_spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ describe('Component Schematic', () => {
205205
expect(content).toMatch(/selector: 'app-foo'/);
206206
});
207207

208+
it('should use the supplied prefix if it is ""', () => {
209+
const options = { ...defaultOptions, prefix: '' };
210+
211+
const tree = schematicRunner.runSchematic('component', options, appTree);
212+
const content = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
213+
expect(content).toMatch(/selector: 'foo'/);
214+
});
215+
208216
it('should respect the inlineTemplate option', () => {
209217
const options = { ...defaultOptions, inlineTemplate: true };
210218
const tree = schematicRunner.runSchematic('component', options, appTree);

packages/schematics/angular/component/schema.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,17 @@
5252
},
5353
"prefix": {
5454
"type": "string",
55-
"format": "html-selector",
5655
"description": "The prefix to apply to generated selectors.",
57-
"alias": "p"
56+
"alias": "p",
57+
"oneOf": [
58+
{
59+
"maxLength": 0
60+
},
61+
{
62+
"minLength": 1,
63+
"format": "html-selector"
64+
}
65+
]
5866
},
5967
"styleext": {
6068
"description": "The file extension to be used for style files.",

packages/schematics/angular/directive/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function buildSelector(options: DirectiveOptions, projectPrefix: string) {
9494
let selector = options.name;
9595
if (options.prefix) {
9696
selector = `${options.prefix}-${selector}`;
97-
} else if (projectPrefix) {
97+
} else if (options.prefix === undefined && projectPrefix) {
9898
selector = `${projectPrefix}-${selector}`;
9999
}
100100

packages/schematics/angular/directive/index_spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,12 @@ describe('Directive Schematic', () => {
146146
const content = tree.readContent('/projects/bar/src/app/foo.directive.ts');
147147
expect(content).toMatch(/selector: '\[appFoo\]'/);
148148
});
149+
150+
it('should use the supplied prefix if it is ""', () => {
151+
const options = { ...defaultOptions, prefix: '' };
152+
const tree = schematicRunner.runSchematic('directive', options, appTree);
153+
154+
const content = tree.readContent('/projects/bar/src/app/foo.directive.ts');
155+
expect(content).toMatch(/selector: '\[foo\]'/);
156+
});
149157
});

packages/schematics/angular/directive/schema.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@
2727
},
2828
"prefix": {
2929
"type": "string",
30-
"format": "html-selector",
3130
"description": "The prefix to apply to generated selectors.",
32-
"default": "app",
33-
"alias": "p"
31+
"alias": "p",
32+
"oneOf": [
33+
{
34+
"maxLength": 0
35+
},
36+
{
37+
"minLength": 1,
38+
"format": "html-selector"
39+
}
40+
]
3441
},
3542
"spec": {
3643
"type": "boolean",

0 commit comments

Comments
 (0)