Skip to content

Commit db09bfb

Browse files
author
Angular Builds
committedMar 18, 2025
bc0f07b fix(@schematics/angular): generate services without a .service extension/type
1 parent e23b622 commit db09bfb

13 files changed

+46
-31
lines changed
 

‎library/files/src/__entryFile__.ts.template

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
* Public API Surface of <%= dasherize(name) %>
33
*/
44

5-
export * from './lib/<%= dasherize(name) %>.service';
65
export * from './lib/<%= dasherize(name) %>';<% if (!standalone) { %>
76
export * from './lib/<%= dasherize(name) %>.module';<% } %>

‎library/index.js

-6
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,6 @@ function default_1(options) {
155155
standalone: options.standalone,
156156
project: packageName,
157157
}),
158-
(0, schematics_1.schematic)('service', {
159-
name: options.name,
160-
flat: true,
161-
path: sourceDir,
162-
project: packageName,
163-
}),
164158
(_tree, context) => {
165159
if (!options.skipPackageJson && !options.skipInstall) {
166160
context.addTask(new tasks_1.NodePackageInstallTask());

‎package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@schematics/angular",
3-
"version": "20.0.0-next.1+sha-e07491e",
3+
"version": "20.0.0-next.1+sha-bc0f07b",
44
"description": "Schematics specific to Angular",
55
"homepage": "https://github.com/angular/angular-cli",
66
"keywords": [
@@ -22,8 +22,8 @@
2222
},
2323
"schematics": "./collection.json",
2424
"dependencies": {
25-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#e07491e",
26-
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds#e07491e",
25+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#bc0f07b",
26+
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds#bc0f07b",
2727
"jsonc-parser": "3.3.1"
2828
},
2929
"repository": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { <%= classify(name) %><%= classify(type) %> } from './<%= dasherize(name) %><%= type ? '.' + dasherize(type) : '' %>';
4+
5+
describe('<%= classify(name) %><%= classify(type) %>', () => {
6+
let service: <%= classify(name) %><%= classify(type) %>;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(<%= classify(name) %><%= classify(type) %>);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});

‎service/files/__name@dasherize@if-flat__/__name@dasherize__.service.ts.template renamed to ‎service/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
33
@Injectable({
44
providedIn: 'root'
55
})
6-
export class <%= classify(name) %>Service {
6+
export class <%= classify(name) %><%= classify(type) %> {
77

88
constructor() { }
99
}

‎service/files/__name@dasherize@if-flat__/__name@dasherize__.service.spec.ts.template

-16
This file was deleted.

‎service/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function default_1(options) {
1313
// This schematic uses an older method to implement the flat option
1414
const flat = options.flat;
1515
options.flat = true;
16+
// Schematic templates require a defined type value
17+
options.type ??= '';
1618
return (0, generate_from_files_1.generateFromFiles)(options, {
1719
'if-flat': (s) => (flat ? '' : s),
1820
});

‎service/schema.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ export type Schema = {
2828
* Skip the generation of a unit test file `spec.ts` for the service.
2929
*/
3030
skipTests?: boolean;
31+
/**
32+
* Append a custom type to the service's filename. For example, if you set the type to
33+
* `service`, the file will be named `my-service.service.ts`.
34+
*/
35+
type?: string;
3136
};

‎service/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
"type": "boolean",
4040
"description": "Skip the generation of a unit test file `spec.ts` for the service.",
4141
"default": false
42+
},
43+
"type": {
44+
"type": "string",
45+
"description": "Append a custom type to the service's filename. For example, if you set the type to `service`, the file will be named `my-service.service.ts`."
4246
}
4347
},
4448
"required": ["name", "project"]

‎uniqueId

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Mon Mar 17 2025 21:25:26 GMT+0000 (Coordinated Universal Time)
1+
Tue Mar 18 2025 11:32:47 GMT+0000 (Coordinated Universal Time)

‎utility/generate-from-files.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export interface GenerateFromFilesOptions {
1414
project: string;
1515
skipTests?: boolean;
1616
templateFilesDirectory?: string;
17+
type?: string;
1718
}
1819
export declare function generateFromFiles(options: GenerateFromFilesOptions, extraTemplateValues?: Record<string, string | ((v: string) => string)>): Rule;

‎utility/generate-from-files.js

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ function generateFromFiles(options, extraTemplateValues = {}) {
2929
...options,
3030
...extraTemplateValues,
3131
}),
32+
!options.type
33+
? (0, schematics_1.forEach)(((file) => {
34+
return file.path.includes('..')
35+
? {
36+
content: file.content,
37+
path: file.path.replace('..', '.'),
38+
}
39+
: file;
40+
}))
41+
: (0, schematics_1.noop)(),
3242
(0, schematics_1.move)(parsedPath.path + (options.flat ? '' : '/' + schematics_1.strings.dasherize(options.name))),
3343
]);
3444
return (0, schematics_1.chain)([(0, schematics_1.mergeWith)(templateSource)]);

‎utility/latest-versions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports.latestVersions = {
1616
// As Angular CLI works with same minor versions of Angular Framework, a tilde match for the current
1717
Angular: '^20.0.0-next.0',
1818
NgPackagr: '^20.0.0-next.0',
19-
DevkitBuildAngular: '^20.0.0-next.1+sha-e07491e',
20-
AngularBuild: '^20.0.0-next.1+sha-e07491e',
21-
AngularSSR: '^20.0.0-next.1+sha-e07491e',
19+
DevkitBuildAngular: '^20.0.0-next.1+sha-bc0f07b',
20+
AngularBuild: '^20.0.0-next.1+sha-bc0f07b',
21+
AngularSSR: '^20.0.0-next.1+sha-bc0f07b',
2222
};

0 commit comments

Comments
 (0)
Please sign in to comment.