Skip to content

Commit 541de02

Browse files
fix(schematics): exclude environment imports for libraries (#1213)
Closes #1205, #1197
1 parent b1f9b34 commit 541de02

File tree

25 files changed

+218
-45
lines changed

25 files changed

+218
-45
lines changed

modules/effects/schematics-core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export {
4848
omit,
4949
} from './utility/ngrx-utils';
5050

51-
export { getProjectPath } from './utility/project';
51+
export { getProjectPath, getProject, isLib } from './utility/project';
5252
export { insertImport } from './utility/route-utils';
5353

5454
export const stringUtils = {

modules/effects/schematics-core/utility/ast-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ function _addSymbolToNgModuleMetadata(
352352
return [];
353353
}
354354

355+
node = node[node.length - 1];
356+
355357
const effectsModule = nodeArray.find(
356358
node =>
357359
(node.getText().includes('EffectsModule.forRoot') &&
@@ -398,8 +400,6 @@ function _addSymbolToNgModuleMetadata(
398400
}
399401
}
400402

401-
node = node[node.length - 1];
402-
403403
let toInsert: string;
404404
let position = node.getEnd();
405405
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {

modules/effects/schematics-core/utility/project.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
import { getWorkspace } from './config';
22
import { Tree } from '@angular-devkit/schematics';
33

4-
export function getProjectPath(
4+
export interface WorkspaceProject {
5+
root: string;
6+
projectType: string;
7+
}
8+
9+
export function getProject(
510
host: Tree,
611
options: { project?: string | undefined; path?: string | undefined }
7-
) {
12+
): WorkspaceProject {
813
const workspace = getWorkspace(host);
914

1015
if (!options.project) {
1116
options.project = Object.keys(workspace.projects)[0];
1217
}
1318

14-
const project = workspace.projects[options.project];
19+
return workspace.projects[options.project];
20+
}
21+
22+
export function getProjectPath(
23+
host: Tree,
24+
options: { project?: string | undefined; path?: string | undefined }
25+
) {
26+
const project = getProject(host, options);
1527

1628
if (project.root.substr(-1) === '/') {
1729
project.root = project.root.substr(0, project.root.length - 1);
@@ -26,3 +38,12 @@ export function getProjectPath(
2638

2739
return options.path;
2840
}
41+
42+
export function isLib(
43+
host: Tree,
44+
options: { project?: string | undefined; path?: string | undefined }
45+
) {
46+
const project = getProject(host, options);
47+
48+
return project.projectType === 'library';
49+
}

modules/entity/schematics-core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export {
4848
omit,
4949
} from './utility/ngrx-utils';
5050

51-
export { getProjectPath } from './utility/project';
51+
export { getProjectPath, getProject, isLib } from './utility/project';
5252
export { insertImport } from './utility/route-utils';
5353

5454
export const stringUtils = {

modules/entity/schematics-core/utility/ast-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ function _addSymbolToNgModuleMetadata(
352352
return [];
353353
}
354354

355+
node = node[node.length - 1];
356+
355357
const effectsModule = nodeArray.find(
356358
node =>
357359
(node.getText().includes('EffectsModule.forRoot') &&
@@ -398,8 +400,6 @@ function _addSymbolToNgModuleMetadata(
398400
}
399401
}
400402

401-
node = node[node.length - 1];
402-
403403
let toInsert: string;
404404
let position = node.getEnd();
405405
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {

modules/entity/schematics-core/utility/project.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
import { getWorkspace } from './config';
22
import { Tree } from '@angular-devkit/schematics';
33

4-
export function getProjectPath(
4+
export interface WorkspaceProject {
5+
root: string;
6+
projectType: string;
7+
}
8+
9+
export function getProject(
510
host: Tree,
611
options: { project?: string | undefined; path?: string | undefined }
7-
) {
12+
): WorkspaceProject {
813
const workspace = getWorkspace(host);
914

1015
if (!options.project) {
1116
options.project = Object.keys(workspace.projects)[0];
1217
}
1318

14-
const project = workspace.projects[options.project];
19+
return workspace.projects[options.project];
20+
}
21+
22+
export function getProjectPath(
23+
host: Tree,
24+
options: { project?: string | undefined; path?: string | undefined }
25+
) {
26+
const project = getProject(host, options);
1527

1628
if (project.root.substr(-1) === '/') {
1729
project.root = project.root.substr(0, project.root.length - 1);
@@ -26,3 +38,12 @@ export function getProjectPath(
2638

2739
return options.path;
2840
}
41+
42+
export function isLib(
43+
host: Tree,
44+
options: { project?: string | undefined; path?: string | undefined }
45+
) {
46+
const project = getProject(host, options);
47+
48+
return project.projectType === 'library';
49+
}

modules/router-store/schematics-core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export {
4848
omit,
4949
} from './utility/ngrx-utils';
5050

51-
export { getProjectPath } from './utility/project';
51+
export { getProjectPath, getProject, isLib } from './utility/project';
5252
export { insertImport } from './utility/route-utils';
5353

5454
export const stringUtils = {

modules/router-store/schematics-core/utility/ast-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ function _addSymbolToNgModuleMetadata(
352352
return [];
353353
}
354354

355+
node = node[node.length - 1];
356+
355357
const effectsModule = nodeArray.find(
356358
node =>
357359
(node.getText().includes('EffectsModule.forRoot') &&
@@ -398,8 +400,6 @@ function _addSymbolToNgModuleMetadata(
398400
}
399401
}
400402

401-
node = node[node.length - 1];
402-
403403
let toInsert: string;
404404
let position = node.getEnd();
405405
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {

modules/router-store/schematics-core/utility/project.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
import { getWorkspace } from './config';
22
import { Tree } from '@angular-devkit/schematics';
33

4-
export function getProjectPath(
4+
export interface WorkspaceProject {
5+
root: string;
6+
projectType: string;
7+
}
8+
9+
export function getProject(
510
host: Tree,
611
options: { project?: string | undefined; path?: string | undefined }
7-
) {
12+
): WorkspaceProject {
813
const workspace = getWorkspace(host);
914

1015
if (!options.project) {
1116
options.project = Object.keys(workspace.projects)[0];
1217
}
1318

14-
const project = workspace.projects[options.project];
19+
return workspace.projects[options.project];
20+
}
21+
22+
export function getProjectPath(
23+
host: Tree,
24+
options: { project?: string | undefined; path?: string | undefined }
25+
) {
26+
const project = getProject(host, options);
1527

1628
if (project.root.substr(-1) === '/') {
1729
project.root = project.root.substr(0, project.root.length - 1);
@@ -26,3 +38,12 @@ export function getProjectPath(
2638

2739
return options.path;
2840
}
41+
42+
export function isLib(
43+
host: Tree,
44+
options: { project?: string | undefined; path?: string | undefined }
45+
) {
46+
const project = getProject(host, options);
47+
48+
return project.projectType === 'library';
49+
}

modules/schematics-core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export {
4848
omit,
4949
} from './utility/ngrx-utils';
5050

51-
export { getProjectPath } from './utility/project';
51+
export { getProjectPath, getProject, isLib } from './utility/project';
5252
export { insertImport } from './utility/route-utils';
5353

5454
export const stringUtils = {

0 commit comments

Comments
 (0)