Skip to content

Commit 02a852a

Browse files
kyliauAndrewKushnir
authored andcommittedJan 16, 2019
fix(bazel): Bazel schematics should add router package (#28141)
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
1 parent 531f940 commit 02a852a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
 

‎packages/bazel/src/schematics/bazel-workspace/files/src/BUILD.bazel.template

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ ng_module(
2323
]),
2424
deps = [
2525
"@angular//packages/core",
26-
"@angular//packages/platform-browser",
26+
"@angular//packages/platform-browser",<% if (routing) { %>
27+
"@angular//packages/router",<% } %>
2728
"@npm//@types",
2829
],
2930
)

‎packages/bazel/src/schematics/bazel-workspace/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ export function clean(version: string): string|null {
5151
return matches && matches.pop() || null;
5252
}
5353

54+
/**
55+
* Returns true if project contains routing module, false otherwise.
56+
*/
57+
function hasRoutingModule(host: Tree) {
58+
let hasRouting = false;
59+
host.visit((file: string) => { hasRouting = hasRouting || file.endsWith('-routing.module.ts'); });
60+
return hasRouting;
61+
}
62+
5463
export default function(options: BazelWorkspaceOptions): Rule {
5564
return (host: Tree, context: SchematicContext) => {
5665
if (!options.name) {
@@ -93,6 +102,7 @@ export default function(options: BazelWorkspaceOptions): Rule {
93102
utils: strings,
94103
...options,
95104
'dot': '.', ...workspaceVersions,
105+
routing: hasRoutingModule(host),
96106
}),
97107
move(appDir),
98108
]));

‎packages/bazel/src/schematics/bazel-workspace/index_spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ describe('Bazel-workspace Schematic', () => {
5151
expect(content).toContain('entry_module = "demo_app/src/main.dev"');
5252
});
5353

54+
it('should add router if project contains routing module', () => {
55+
let host = new UnitTestTree(new HostTree);
56+
host.create('/demo/src/app/app-routing.module.ts', '');
57+
expect(host.files).toContain('/demo/src/app/app-routing.module.ts');
58+
const options = {...defaultOptions};
59+
host = schematicRunner.runSchematic('bazel-workspace', options, host);
60+
expect(host.files).toContain('/demo/src/BUILD.bazel');
61+
const content = host.readContent('/demo/src/BUILD.bazel');
62+
expect(content).toContain('@angular//packages/router');
63+
});
64+
5465
describe('WORKSPACE', () => {
5566
it('should contain project name', () => {
5667
const options = {...defaultOptions};

0 commit comments

Comments
 (0)
Please sign in to comment.