diff --git a/packages/bazel/src/schematics/bazel-workspace/index.ts b/packages/bazel/src/schematics/bazel-workspace/index.ts index 902388af2464f4..e54126d0969d1d 100644 --- a/packages/bazel/src/schematics/bazel-workspace/index.ts +++ b/packages/bazel/src/schematics/bazel-workspace/index.ts @@ -48,7 +48,7 @@ function findVersion(projectName: string, packageName: string, host: Tree): stri */ export function clean(version: string): string|null { const matches = version.match(/(\d+\.\d+\.\d+)/); - return matches ? matches.pop() : null; + return matches && matches.pop() || null; } export default function(options: BazelWorkspaceOptions): Rule { @@ -72,12 +72,12 @@ export default function(options: BazelWorkspaceOptions): Rule { RxJs: findVersion(options.name, 'rxjs', host), }; - for (const name of Object.keys(existingVersions)) { - const version = existingVersions[name]; + Object.keys(existingVersions).forEach((name: 'Angular'|'RxJs') => { + const version = existingVersions[name] as string; if (version) { context.logger.info(`Bazel will reuse existing version for ${name}: ${version}`); } - } + }); const workspaceVersions = { 'ANGULAR_VERSION': existingVersions.Angular || clean(latestVersions.Angular), diff --git a/packages/bazel/src/schematics/bazel-workspace/index_spec.ts b/packages/bazel/src/schematics/bazel-workspace/index_spec.ts index ddedfc9463a8a7..211c75084915ef 100644 --- a/packages/bazel/src/schematics/bazel-workspace/index_spec.ts +++ b/packages/bazel/src/schematics/bazel-workspace/index_spec.ts @@ -64,7 +64,7 @@ describe('Bazel-workspace Schematic', () => { describe('clean', () => { [['1.2.3', '1.2.3'], [' 1.2.3', '1.2.3'], ['1.2.3 ', '1.2.3'], ['~1.2.3', '1.2.3'], ['^1.2.3', '1.2.3'], ['v1.2.3', '1.2.3'], ['1.2', null], ['a.b.c', null], - ].forEach(([version, want]) => { + ].forEach(([version, want]: [string, string]) => { it(`should match ${version} with ${want}`, () => { const got = clean(version); expect(got).toBe(want);