Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(schematics): exclude environment imports for libraries #1213

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/effects/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export {
omit,
} from './utility/ngrx-utils';

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

export const stringUtils = {
Expand Down
4 changes: 2 additions & 2 deletions modules/effects/schematics-core/utility/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ function _addSymbolToNgModuleMetadata(
return [];
}

node = node[node.length - 1];

const effectsModule = nodeArray.find(
node =>
(node.getText().includes('EffectsModule.forRoot') &&
Expand Down Expand Up @@ -398,8 +400,6 @@ function _addSymbolToNgModuleMetadata(
}
}

node = node[node.length - 1];

let toInsert: string;
let position = node.getEnd();
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
Expand Down
27 changes: 24 additions & 3 deletions modules/effects/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { getWorkspace } from './config';
import { Tree } from '@angular-devkit/schematics';

export function getProjectPath(
export interface WorkspaceProject {
root: string;
projectType: string;
}

export function getProject(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
): WorkspaceProject {
const workspace = getWorkspace(host);

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

const project = workspace.projects[options.project];
return workspace.projects[options.project];
}

export function getProjectPath(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

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

return options.path;
}

export function isLib(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

return project.projectType === 'library';
}
2 changes: 1 addition & 1 deletion modules/entity/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export {
omit,
} from './utility/ngrx-utils';

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

export const stringUtils = {
Expand Down
4 changes: 2 additions & 2 deletions modules/entity/schematics-core/utility/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ function _addSymbolToNgModuleMetadata(
return [];
}

node = node[node.length - 1];

const effectsModule = nodeArray.find(
node =>
(node.getText().includes('EffectsModule.forRoot') &&
Expand Down Expand Up @@ -398,8 +400,6 @@ function _addSymbolToNgModuleMetadata(
}
}

node = node[node.length - 1];

let toInsert: string;
let position = node.getEnd();
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
Expand Down
27 changes: 24 additions & 3 deletions modules/entity/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { getWorkspace } from './config';
import { Tree } from '@angular-devkit/schematics';

export function getProjectPath(
export interface WorkspaceProject {
root: string;
projectType: string;
}

export function getProject(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
): WorkspaceProject {
const workspace = getWorkspace(host);

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

const project = workspace.projects[options.project];
return workspace.projects[options.project];
}

export function getProjectPath(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

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

return options.path;
}

export function isLib(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

return project.projectType === 'library';
}
2 changes: 1 addition & 1 deletion modules/router-store/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export {
omit,
} from './utility/ngrx-utils';

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

export const stringUtils = {
Expand Down
4 changes: 2 additions & 2 deletions modules/router-store/schematics-core/utility/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ function _addSymbolToNgModuleMetadata(
return [];
}

node = node[node.length - 1];

const effectsModule = nodeArray.find(
node =>
(node.getText().includes('EffectsModule.forRoot') &&
Expand Down Expand Up @@ -398,8 +400,6 @@ function _addSymbolToNgModuleMetadata(
}
}

node = node[node.length - 1];

let toInsert: string;
let position = node.getEnd();
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
Expand Down
27 changes: 24 additions & 3 deletions modules/router-store/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { getWorkspace } from './config';
import { Tree } from '@angular-devkit/schematics';

export function getProjectPath(
export interface WorkspaceProject {
root: string;
projectType: string;
}

export function getProject(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
): WorkspaceProject {
const workspace = getWorkspace(host);

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

const project = workspace.projects[options.project];
return workspace.projects[options.project];
}

export function getProjectPath(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

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

return options.path;
}

export function isLib(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

return project.projectType === 'library';
}
2 changes: 1 addition & 1 deletion modules/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export {
omit,
} from './utility/ngrx-utils';

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

export const stringUtils = {
Expand Down
13 changes: 12 additions & 1 deletion modules/schematics-core/testing/create-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const defaultModuleOptions = {
flat: false,
};

const defaultLibOptions = {
name: 'baz',
};

export function getTestProjectPath(
workspaceOptions: any = defaultWorkspaceOptions,
appOptions: any = defaultAppOptions
Expand All @@ -37,7 +41,8 @@ export function createWorkspace(
schematicRunner: SchematicTestRunner,
appTree: UnitTestTree,
workspaceOptions = defaultWorkspaceOptions,
appOptions = defaultAppOptions
appOptions = defaultAppOptions,
libOptions = defaultLibOptions
) {
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
Expand All @@ -50,6 +55,12 @@ export function createWorkspace(
appOptions,
appTree
);
appTree = schematicRunner.runExternalSchematic(
'@schematics/angular',
'library',
libOptions,
appTree
);

return appTree;
}
4 changes: 2 additions & 2 deletions modules/schematics-core/utility/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ function _addSymbolToNgModuleMetadata(
return [];
}

node = node[node.length - 1];

const effectsModule = nodeArray.find(
node =>
(node.getText().includes('EffectsModule.forRoot') &&
Expand Down Expand Up @@ -398,8 +400,6 @@ function _addSymbolToNgModuleMetadata(
}
}

node = node[node.length - 1];

let toInsert: string;
let position = node.getEnd();
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
Expand Down
27 changes: 24 additions & 3 deletions modules/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { getWorkspace } from './config';
import { Tree } from '@angular-devkit/schematics';

export function getProjectPath(
export interface WorkspaceProject {
root: string;
projectType: string;
}

export function getProject(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
): WorkspaceProject {
const workspace = getWorkspace(host);

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

const project = workspace.projects[options.project];
return workspace.projects[options.project];
}

export function getProjectPath(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

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

return options.path;
}

export function isLib(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

return project.projectType === 'library';
}
2 changes: 1 addition & 1 deletion modules/schematics/schematics-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export {
omit,
} from './utility/ngrx-utils';

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

export const stringUtils = {
Expand Down
4 changes: 2 additions & 2 deletions modules/schematics/schematics-core/utility/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ function _addSymbolToNgModuleMetadata(
return [];
}

node = node[node.length - 1];

const effectsModule = nodeArray.find(
node =>
(node.getText().includes('EffectsModule.forRoot') &&
Expand Down Expand Up @@ -398,8 +400,6 @@ function _addSymbolToNgModuleMetadata(
}
}

node = node[node.length - 1];

let toInsert: string;
let position = node.getEnd();
if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {
Expand Down
27 changes: 24 additions & 3 deletions modules/schematics/schematics-core/utility/project.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { getWorkspace } from './config';
import { Tree } from '@angular-devkit/schematics';

export function getProjectPath(
export interface WorkspaceProject {
root: string;
projectType: string;
}

export function getProject(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
): WorkspaceProject {
const workspace = getWorkspace(host);

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

const project = workspace.projects[options.project];
return workspace.projects[options.project];
}

export function getProjectPath(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

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

return options.path;
}

export function isLib(
host: Tree,
options: { project?: string | undefined; path?: string | undefined }
) {
const project = getProject(host, options);

return project.projectType === 'library';
}
Loading