Skip to content

Commit

Permalink
fix(bazel): Bazel schematics should add router package (#28141)
Browse files Browse the repository at this point in the history
This commit fixes a bug whereby a Bazel project created by the
schematics would not compiled if project contains routing module.

It is missing a dependency on the router package.

PR Close #28141
  • Loading branch information
kyliau authored and AndrewKushnir committed Jan 15, 2019
1 parent 60fecc1 commit 06e5bf1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Expand Up @@ -23,7 +23,8 @@ ng_module(
]),
deps = [
"@angular//packages/core",
"@angular//packages/platform-browser",
"@angular//packages/platform-browser",<% if (routing) { %>
"@angular//packages/router",<% } %>
"@npm//@types",
],
)
Expand Down
10 changes: 10 additions & 0 deletions packages/bazel/src/schematics/bazel-workspace/index.ts
Expand Up @@ -51,6 +51,15 @@ export function clean(version: string): string|null {
return matches && matches.pop() || null;
}

/**
* Returns true if project contains routing module, false otherwise.
*/
function hasRoutingModule(host: Tree) {
let hasRouting = false;
host.visit((file: string) => { hasRouting = hasRouting || file.endsWith('-routing.module.ts'); });
return hasRouting;
}

export default function(options: BazelWorkspaceOptions): Rule {
return (host: Tree, context: SchematicContext) => {
if (!options.name) {
Expand Down Expand Up @@ -93,6 +102,7 @@ export default function(options: BazelWorkspaceOptions): Rule {
utils: strings,
...options,
'dot': '.', ...workspaceVersions,
routing: hasRoutingModule(host),
}),
move(appDir),
]));
Expand Down
11 changes: 11 additions & 0 deletions packages/bazel/src/schematics/bazel-workspace/index_spec.ts
Expand Up @@ -51,6 +51,17 @@ describe('Bazel-workspace Schematic', () => {
expect(content).toContain('entry_module = "demo_app/src/main.dev"');
});

it('should add router if project contains routing module', () => {
let host = new UnitTestTree(new HostTree);
host.create('/demo/src/app/app-routing.module.ts', '');
expect(host.files).toContain('/demo/src/app/app-routing.module.ts');
const options = {...defaultOptions};
host = schematicRunner.runSchematic('bazel-workspace', options, host);
expect(host.files).toContain('/demo/src/BUILD.bazel');
const content = host.readContent('/demo/src/BUILD.bazel');
expect(content).toContain('@angular//packages/router');
});

describe('WORKSPACE', () => {
it('should contain project name', () => {
const options = {...defaultOptions};
Expand Down

0 comments on commit 06e5bf1

Please sign in to comment.