Skip to content

Commit 4a3ec42

Browse files
committed
fix(@schematics/angular): Remove module option from service schematic
fixes angular/angular-cli#10170
1 parent 7e916a6 commit 4a3ec42

File tree

5 files changed

+2
-58
lines changed

5 files changed

+2
-58
lines changed

packages/schematics/angular/service/files/__name@dasherize@if-flat__/__name@dasherize__.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Injectable } from '@angular/core';<% if (providedIn) { %>
2-
import { <%= providedIn %> } from '<%= providedInPath %>';<% } %>
1+
import { Injectable } from '@angular/core';
32

43
@Injectable({
5-
providedIn: <%= providedIn || "'root'" %>
4+
providedIn: 'root'
65
})
76
export class <%= classify(name) %>Service {
87

packages/schematics/angular/service/index.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ function stripTsExtension(path: string): string {
5151

5252
export default function (options: ServiceOptions): Rule {
5353
return (host: Tree, context: SchematicContext) => {
54-
let providedByModule = '';
55-
let providedInPath = '';
56-
5754
const workspace = getWorkspace(host);
5855
if (!options.project) {
5956
options.project = Object.keys(workspace.projects)[0];
@@ -64,25 +61,6 @@ export default function (options: ServiceOptions): Rule {
6461
options.path = `/${project.root}/src/app`;
6562
}
6663

67-
if (options.module) {
68-
const modulePath = findModuleFromOptions(host, options);
69-
if (!modulePath || !host.exists(modulePath)) {
70-
throw new Error('Specified module does not exist');
71-
}
72-
providedByModule = getModuleNameFromPath(host, modulePath) || '';
73-
74-
if (!providedByModule) {
75-
throw new SchematicsException(`module option did not point to an @NgModule.`);
76-
}
77-
78-
const servicePath = `/${options.path}/`
79-
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
80-
+ strings.dasherize(options.name)
81-
+ '.service';
82-
83-
providedInPath = stripTsExtension(buildRelativePath(servicePath, modulePath));
84-
}
85-
8664
const parsedPath = parseName(options.path, options.name);
8765
options.name = parsedPath.name;
8866
options.path = parsedPath.path;
@@ -93,8 +71,6 @@ export default function (options: ServiceOptions): Rule {
9371
...strings,
9472
'if-flat': (s: string) => options.flat ? '' : s,
9573
...options,
96-
providedIn: providedByModule,
97-
providedInPath: providedInPath,
9874
}),
9975
move(parsedPath.path),
10076
]);

packages/schematics/angular/service/index_spec.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ describe('Service Schematic', () => {
2020
const defaultOptions: ServiceOptions = {
2121
name: 'foo',
2222
spec: true,
23-
module: undefined,
2423
flat: false,
2524
};
2625

@@ -62,26 +61,6 @@ describe('Service Schematic', () => {
6261
expect(content).toMatch(/providedIn: 'root'/);
6362
});
6463

65-
it('should import a specified module', () => {
66-
const options = { ...defaultOptions, module: 'app.module.ts' };
67-
68-
const tree = schematicRunner.runSchematic('service', options, appTree);
69-
const content = tree.readContent('/projects/bar/src/app/foo/foo.service.ts');
70-
expect(content).toMatch(/import { AppModule } from '..\/app.module'/);
71-
expect(content).toMatch(/providedIn: AppModule/);
72-
});
73-
74-
it('should fail if specified module does not exist', () => {
75-
const options = { ...defaultOptions, module: '/projects/bar/src/app/app.moduleXXX.ts' };
76-
let thrownError: Error | null = null;
77-
try {
78-
schematicRunner.runSchematic('service', options, appTree);
79-
} catch (err) {
80-
thrownError = err;
81-
}
82-
expect(thrownError).toBeDefined();
83-
});
84-
8564
it('should respect the spec flag', () => {
8665
const options = { ...defaultOptions, spec: false };
8766

packages/schematics/angular/service/schema.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,4 @@ export interface Schema {
2727
* Specifies if a spec file is generated.
2828
*/
2929
spec?: boolean;
30-
/**
31-
* Allows specification of the providing module.
32-
*/
33-
module?: string;
3430
}

packages/schematics/angular/service/schema.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
"type": "boolean",
3333
"default": true,
3434
"description": "Specifies if a spec file is generated."
35-
},
36-
"module": {
37-
"type": "string",
38-
"default": "",
39-
"description": "Allows specification of the providing module.",
40-
"alias": "m"
4135
}
4236
},
4337
"required": []

0 commit comments

Comments
 (0)