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
This commit is contained in:
parent
60fecc1284
commit
06e5bf1661
|
@ -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",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -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) {
|
||||
|
@ -93,6 +102,7 @@ export default function(options: BazelWorkspaceOptions): Rule {
|
|||
utils: strings,
|
||||
...options,
|
||||
'dot': '.', ...workspaceVersions,
|
||||
routing: hasRoutingModule(host),
|
||||
}),
|
||||
move(appDir),
|
||||
]));
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Reference in New Issue