Skip to content

Commit 92e193c

Browse files
committed
fix(@schematics/angular): generate resolvers with a dash type separator
To align with the updated style guide, Angular v20 will generate resolvers with file extension `resolver` type prefixed with a `-` separator instead of a `.` by default. Projects will automatically use this naming convention. Projects can however opt-out by setting the `typeSeparator` option to `.` for the resolver schematic. This can be done as a default in the `angular.json` or directly on the commandline via `--type-separator=.` when executing `ng generate`. As an example, `example.resolver.ts` will now be named `example-resolver.ts`. The TypeScript declaration will continue to contain `Resolver` such as with `ExampleResolver`.
1 parent 5fc5951 commit 92e193c

8 files changed

+43
-13
lines changed

packages/schematics/angular/guard/schema.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"typeSeparator": {
6363
"type": "string",
6464
"default": "-",
65-
"enum": ["-", "."]
65+
"enum": ["-", "."],
66+
"description": "The separator character to use before the type within the generated file's name. For example, if you set the option to `.`, the file will be named `example.guard.ts`."
6667
}
6768
},
6869
"required": ["name", "project"]

packages/schematics/angular/pipe/schema.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"typeSeparator": {
6666
"type": "string",
6767
"default": "-",
68-
"enum": ["-", "."]
68+
"enum": ["-", "."],
69+
"description": "The separator character to use before the type within the generated file's name. For example, if you set the option to `.`, the file will be named `example.pipe.ts`."
6970
}
7071
},
7172
"required": ["name", "project"]

packages/schematics/angular/resolver/class-files/__name@dasherize__.resolver.spec.ts.template renamed to packages/schematics/angular/resolver/class-files/__name@dasherize____typeSeparator__resolver.spec.ts.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TestBed } from '@angular/core/testing';
22

3-
import { <%= classify(name) %>Resolver } from './<%= dasherize(name) %>.resolver';
3+
import { <%= classify(name) %>Resolver } from './<%= dasherize(name) %><%= typeSeparator %>resolver';
44

55
describe('<%= classify(name) %>Resolver', () => {
66
let resolver: <%= classify(name) %>Resolver;

packages/schematics/angular/resolver/functional-files/__name@dasherize__.resolver.spec.ts.template renamed to packages/schematics/angular/resolver/functional-files/__name@dasherize____typeSeparator__resolver.spec.ts.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TestBed } from '@angular/core/testing';
22
import { ResolveFn } from '@angular/router';
33

4-
import { <%= camelize(name) %>Resolver } from './<%= dasherize(name) %>.resolver';
4+
import { <%= camelize(name) %>Resolver } from './<%= dasherize(name) %><%= typeSeparator %>resolver';
55

66
describe('<%= camelize(name) %>Resolver', () => {
77
const executeResolver: ResolveFn<boolean> = (...resolverParameters) =>

packages/schematics/angular/resolver/index_spec.ts

+31-9
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ describe('resolver Schematic', () => {
4848
appTree,
4949
);
5050
const files = tree.files;
51-
expect(files).toContain('/projects/bar/src/app/foo.resolver.spec.ts');
52-
expect(files).toContain('/projects/bar/src/app/foo.resolver.ts');
53-
const fileString = tree.readContent('/projects/bar/src/app/foo.resolver.ts');
51+
expect(files).toContain('/projects/bar/src/app/foo-resolver.spec.ts');
52+
expect(files).toContain('/projects/bar/src/app/foo-resolver.ts');
53+
const fileString = tree.readContent('/projects/bar/src/app/foo-resolver.ts');
5454
expect(fileString).toContain('export class FooResolver implements Resolve<boolean>');
5555
});
5656

@@ -59,38 +59,60 @@ describe('resolver Schematic', () => {
5959

6060
const tree = await schematicRunner.runSchematic('resolver', options, appTree);
6161
const files = tree.files;
62-
expect(files).not.toContain('/projects/bar/src/app/foo.resolver.spec.ts');
62+
expect(files).not.toContain('/projects/bar/src/app/foo-resolver.spec.ts');
63+
expect(files).toContain('/projects/bar/src/app/foo-resolver.ts');
64+
});
65+
66+
it('should use a `.` type separator when specified', async () => {
67+
const options = { ...defaultOptions, typeSeparator: '.' };
68+
69+
const tree = await schematicRunner.runSchematic('resolver', options, appTree);
70+
const files = tree.files;
71+
expect(files).toContain('/projects/bar/src/app/foo.resolver.spec.ts');
6372
expect(files).toContain('/projects/bar/src/app/foo.resolver.ts');
73+
const specContent = tree.readContent('/projects/bar/src/app/foo.resolver.spec.ts');
74+
expect(specContent).toContain(`'./foo.resolver'`);
75+
});
76+
77+
it('should use a `-` type separator when specified', async () => {
78+
const options = { ...defaultOptions, typeSeparator: '-' };
79+
80+
const tree = await schematicRunner.runSchematic('resolver', options, appTree);
81+
const files = tree.files;
82+
expect(files).toContain('/projects/bar/src/app/foo-resolver.spec.ts');
83+
expect(files).toContain('/projects/bar/src/app/foo-resolver.ts');
84+
const specContent = tree.readContent('/projects/bar/src/app/foo-resolver.spec.ts');
85+
expect(specContent).toContain(`'./foo-resolver'`);
6486
});
6587

6688
it('should respect the flat flag', async () => {
6789
const options = { ...defaultOptions, flat: false };
6890

6991
const tree = await schematicRunner.runSchematic('resolver', options, appTree);
7092
const files = tree.files;
71-
expect(files).toContain('/projects/bar/src/app/foo/foo.resolver.spec.ts');
72-
expect(files).toContain('/projects/bar/src/app/foo/foo.resolver.ts');
93+
expect(files).toContain('/projects/bar/src/app/foo/foo-resolver.spec.ts');
94+
expect(files).toContain('/projects/bar/src/app/foo/foo-resolver.ts');
7395
});
7496

7597
it('should respect the sourceRoot value', async () => {
7698
const config = JSON.parse(appTree.readContent('/angular.json'));
7799
config.projects.bar.sourceRoot = 'projects/bar/custom';
78100
appTree.overwrite('/angular.json', JSON.stringify(config, null, 2));
79101
appTree = await schematicRunner.runSchematic('resolver', defaultOptions, appTree);
80-
expect(appTree.files).toContain('/projects/bar/custom/app/foo.resolver.ts');
102+
expect(appTree.files).toContain('/projects/bar/custom/app/foo-resolver.ts');
81103
});
82104

83105
it('should create a functional resolver', async () => {
84106
const tree = await schematicRunner.runSchematic('resolver', defaultOptions, appTree);
85-
const fileString = tree.readContent('/projects/bar/src/app/foo.resolver.ts');
107+
const fileString = tree.readContent('/projects/bar/src/app/foo-resolver.ts');
86108
expect(fileString).toContain(
87109
'export const fooResolver: ResolveFn<boolean> = (route, state) => {',
88110
);
89111
});
90112

91113
it('should create a helper function to run a functional resolver in a test', async () => {
92114
const tree = await schematicRunner.runSchematic('resolver', defaultOptions, appTree);
93-
const fileString = tree.readContent('/projects/bar/src/app/foo.resolver.spec.ts');
115+
const fileString = tree.readContent('/projects/bar/src/app/foo-resolver.spec.ts');
94116
expect(fileString).toContain(
95117
'const executeResolver: ResolveFn<boolean> = (...resolverParameters) => ',
96118
);

packages/schematics/angular/resolver/schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
"$default": {
4646
"$source": "projectName"
4747
}
48+
},
49+
"typeSeparator": {
50+
"type": "string",
51+
"default": "-",
52+
"enum": ["-", "."],
53+
"description": "The separator character to use before the type within the generated file's name. For example, if you set the option to `.`, the file will be named `example.resolver.ts`."
4854
}
4955
},
5056
"required": ["name", "project"]

0 commit comments

Comments
 (0)