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

Commit 20aeee5

Browse files
committed
fix(@schematics/angular): fix module discovery
When creating schematics with names that are paths, the path option is the path to create the schematic into. we need to app root to discover the module.
1 parent 76a4296 commit 20aeee5

File tree

19 files changed

+48
-1
lines changed

19 files changed

+48
-1
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
export interface Schema {
1010
name: string;
11+
appRoot?: string;
1112
path?: string;
1213
sourceDir?: string;
1314
/**

packages/schematics/angular/class/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"name": {
88
"type": "string"
99
},
10+
"appRoot": {
11+
"type": "string",
12+
"default": "app"
13+
},
1014
"path": {
1115
"type": "string",
1216
"default": "app"

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

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
export interface Schema {
1010
path?: string;
11+
appRoot?: string;
1112
sourceDir?: string;
1213
name: string;
1314
/**

packages/schematics/angular/component/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"type": "string",
99
"default": "app"
1010
},
11+
"appRoot": {
12+
"type": "string",
13+
"default": "app"
14+
},
1115
"sourceDir": {
1216
"type": "string",
1317
"default": "src",

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

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
export interface Schema {
1010
name: string;
1111
path?: string;
12+
appRoot?: string;
1213
/**
1314
* The prefix to apply to generated selectors.
1415
*/

packages/schematics/angular/directive/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "string",
1212
"default": "app"
1313
},
14+
"appRoot": {
15+
"type": "string",
16+
"default": "app"
17+
},
1418
"prefix": {
1519
"type": "string",
1620
"description": "The prefix to apply to generated selectors.",

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

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
export interface Schema {
1010
name: string;
1111
path?: string;
12+
appRoot?: string;
1213
sourceDir?: string;
1314
}

packages/schematics/angular/enum/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "string",
1212
"default": "app"
1313
},
14+
"appRoot": {
15+
"type": "string",
16+
"default": "app"
17+
},
1418
"sourceDir": {
1519
"type": "string",
1620
"default": "src"

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ export interface Schema {
1515
*/
1616
module?: string;
1717
path?: string;
18+
appRoot?: string;
1819
sourceDir?: string;
1920
}

packages/schematics/angular/guard/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
"type": "string",
2626
"default": "app"
2727
},
28+
"appRoot": {
29+
"type": "string",
30+
"default": "app"
31+
},
2832
"sourceDir": {
2933
"type": "string",
3034
"default": "src"

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

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
export interface Schema {
1010
name: string;
1111
path?: string;
12+
appRoot?: string;
1213
sourceDir?: string;
1314
/**
1415
* Specifies the prefix to use.

packages/schematics/angular/interface/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "string",
1212
"default": "app"
1313
},
14+
"appRoot": {
15+
"type": "string",
16+
"default": "app"
17+
},
1418
"sourceDir": {
1519
"type": "string",
1620
"default": "src"

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

+2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
export interface Schema {
1010
name: string;
1111
path?: string;
12+
appRoot?: string;
1213
sourceDir?: string;
1314
routing?: boolean;
15+
routingScope?: ('Child' | 'Root');
1416
spec?: boolean;
1517
flat?: boolean;
1618
commonModule?: boolean;

packages/schematics/angular/module/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "string",
1212
"default": "app"
1313
},
14+
"appRoot": {
15+
"type": "string",
16+
"default": "app"
17+
},
1418
"sourceDir": {
1519
"type": "string",
1620
"default": "src"

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

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
export interface Schema {
1010
name: string;
1111
path?: string;
12+
appRoot?: string;
1213
sourceDir?: string;
1314
/**
1415
* Flag to indicate if a dir is created.

packages/schematics/angular/pipe/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "string",
1212
"default": "app"
1313
},
14+
"appRoot": {
15+
"type": "string",
16+
"default": "app"
17+
},
1418
"sourceDir": {
1519
"type": "string",
1620
"default": "src"

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

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
export interface Schema {
1010
name: string;
1111
path?: string;
12+
appRoot?: string;
1213
sourceDir?: string;
1314
/**
1415
* Flag to indicate if a dir is created.

packages/schematics/angular/service/schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"type": "string",
1212
"default": "app"
1313
},
14+
"appRoot": {
15+
"type": "string",
16+
"default": "app"
17+
},
1418
"sourceDir": {
1519
"type": "string",
1620
"default": "src"

packages/schematics/angular/utility/find-module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ModuleOptions {
1616
sourceDir?: string;
1717
path?: string;
1818
skipImport?: boolean;
19+
appRoot?: string;
1920
}
2021

2122

@@ -35,7 +36,7 @@ export function findModuleFromOptions(host: Tree,
3536
return normalizePath(findModule(host, pathToCheck));
3637
} else {
3738
const modulePath = normalizePath(
38-
options.sourceDir + '/' + options.path + '/' + options.module);
39+
options.sourceDir + '/' + (options.appRoot || options.path) + '/' + options.module);
3940
const moduleBaseName = normalizePath(modulePath).split('/').pop();
4041

4142
if (host.exists(modulePath)) {

0 commit comments

Comments
 (0)