From f4f20daee3040f13f7bcec98945323a4fc86e3db Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Wed, 6 Mar 2019 17:50:57 -0800 Subject: [PATCH] refactor(bazel): Remove bazel-workspace schematics (#29148) `bazel-workspace` schematics is no longer needed now that the Bazel files are injected into the project by the Bazel builder. PR Close #29148 --- integration/bazel-schematics/test.sh | 4 + integration/bazel-schematics/yarn.lock | 34 +++- package.json | 4 +- packages/bazel/BUILD.bazel | 1 - packages/bazel/package.json | 2 +- packages/bazel/src/schematics/BUILD.bazel | 1 - .../schematics/bazel-workspace/BUILD.bazel | 34 ---- .../files/BUILD.bazel.template | 7 - .../bazel-workspace/files/WORKSPACE.template | 63 -------- .../files/__dot__bazelignore.template | 2 - .../files/__dot__bazelrc.template | 29 ---- .../files/e2e/BUILD.bazel.template | 50 ------ .../files/src/BUILD.bazel.template | 153 ------------------ .../src/schematics/bazel-workspace/index.ts | 76 --------- .../schematics/bazel-workspace/index_spec.ts | 120 -------------- .../schematics/bazel-workspace/schema.d.ts | 13 -- .../schematics/bazel-workspace/schema.json | 19 --- packages/bazel/src/schematics/collection.json | 6 - .../bazel/src/schematics/ng-add/BUILD.bazel | 1 - .../angular-metadata.tsconfig.json.template | 0 .../e2e/protractor.on-prepare.js.template | 0 .../files/src/initialize_testbed.ts.template | 0 .../files/{ => src}/main.dev.ts.template | 0 .../files/{ => src}/main.prod.ts.template | 0 .../files/src/rxjs_shims.js.template | 0 packages/bazel/src/schematics/ng-add/index.ts | 18 +-- .../bazel/src/schematics/ng-add/index_spec.ts | 116 ++++++------- .../bazel/src/schematics/ng-new/index_spec.ts | 7 +- yarn.lock | 30 +++- 29 files changed, 127 insertions(+), 663 deletions(-) delete mode 100644 packages/bazel/src/schematics/bazel-workspace/BUILD.bazel delete mode 100644 packages/bazel/src/schematics/bazel-workspace/files/BUILD.bazel.template delete mode 100644 packages/bazel/src/schematics/bazel-workspace/files/WORKSPACE.template delete mode 100644 packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelignore.template delete mode 100644 packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelrc.template delete mode 100644 packages/bazel/src/schematics/bazel-workspace/files/e2e/BUILD.bazel.template delete mode 100644 packages/bazel/src/schematics/bazel-workspace/files/src/BUILD.bazel.template delete mode 100644 packages/bazel/src/schematics/bazel-workspace/index.ts delete mode 100644 packages/bazel/src/schematics/bazel-workspace/index_spec.ts delete mode 100644 packages/bazel/src/schematics/bazel-workspace/schema.d.ts delete mode 100644 packages/bazel/src/schematics/bazel-workspace/schema.json rename packages/bazel/src/schematics/{bazel-workspace => ng-add}/files/angular-metadata.tsconfig.json.template (100%) rename packages/bazel/src/schematics/{bazel-workspace => ng-add}/files/e2e/protractor.on-prepare.js.template (100%) rename packages/bazel/src/schematics/{bazel-workspace => ng-add}/files/src/initialize_testbed.ts.template (100%) rename packages/bazel/src/schematics/ng-add/files/{ => src}/main.dev.ts.template (100%) rename packages/bazel/src/schematics/ng-add/files/{ => src}/main.prod.ts.template (100%) rename packages/bazel/src/schematics/{bazel-workspace => ng-add}/files/src/rxjs_shims.js.template (100%) diff --git a/integration/bazel-schematics/test.sh b/integration/bazel-schematics/test.sh index 12485d5fb0..d61b582a51 100755 --- a/integration/bazel-schematics/test.sh +++ b/integration/bazel-schematics/test.sh @@ -32,6 +32,10 @@ function testBazel() { ng build ng test ng e2e + if [ -e 'WORKSPACE' ] || [ -e 'BUILD.bazel' ]; then + echo 'WORKSPACE / BUILD.bazel file should not exist in project' + exit 1 + fi } function testNonBazel() { diff --git a/integration/bazel-schematics/yarn.lock b/integration/bazel-schematics/yarn.lock index b6b57e7865..65378ca9ca 100644 --- a/integration/bazel-schematics/yarn.lock +++ b/integration/bazel-schematics/yarn.lock @@ -40,6 +40,17 @@ rxjs "6.3.3" source-map "0.7.3" +"@angular-devkit/core@7.3.5": + version "7.3.5" + resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-7.3.5.tgz#2a59a913eab358e2385f52ba28132b81435e63b3" + integrity sha512-J/Tztq2BZ3tpwUsbiz8N61rf9lwqn85UvJsDui2SPIdzDR9KmPr5ESI2Irc/PEb9i+CBXtVuhr8AIqo7rR6ZTg== + dependencies: + ajv "6.9.1" + chokidar "2.0.4" + fast-json-stable-stringify "2.0.0" + rxjs "6.3.3" + source-map "0.7.3" + "@angular-devkit/schematics@7.3.2", "@angular-devkit/schematics@^7.3.0-rc.0": version "7.3.2" resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.2.tgz#e9d3c1f2128a56f66ea846ce3f80c69d4c3a9ae9" @@ -48,15 +59,23 @@ "@angular-devkit/core" "7.3.2" rxjs "6.3.3" +"@angular-devkit/schematics@7.3.5": + version "7.3.5" + resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.5.tgz#7b007f8a86dea76e93eef007d4fb6e7d8324b7bb" + integrity sha512-BFCCkwRMBC4aFlngaloi1avCTgGrl1MFc/0Av2sCpBh/fdm1FqSVzmOiTfu93dehRVVL/bTrA2qj+xpNsXCxzA== + dependencies: + "@angular-devkit/core" "7.3.5" + rxjs "6.3.3" + "@angular/bazel@file:../../dist/packages-dist/bazel": - version "8.0.0-beta.6" + version "8.0.0-beta.7" dependencies: "@angular-devkit/architect" "^0.13.4" "@angular-devkit/core" "^7.0.4" "@angular-devkit/schematics" "^7.3.0-rc.0" "@bazel/typescript" "^0.26.0" "@microsoft/api-extractor" "^7.0.21" - "@schematics/angular" "^7.0.4" + "@schematics/angular" "^7.3.5" "@types/node" "6.0.84" semver "^5.6.0" shelljs "0.8.2" @@ -158,7 +177,7 @@ resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.7.tgz#8fb4a9f4fdf01f1469c9fc54b0ad2d36ec57c25d" integrity sha512-0bqNlQT8aR4Iq9xx/OsY579Zeqon9uTZDIuvl+XXu16TPPN2sASeKojwm366jA2MjgXd9iyTWpJM5/P1QJ4Dxg== -"@schematics/angular@7.3.2", "@schematics/angular@^7.0.4": +"@schematics/angular@7.3.2": version "7.3.2" resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.2.tgz#470f972a9d80ab8af9900e33972bce44aa567718" integrity sha512-ClqG1qA919QqsikIXIP/jKl2Boj70lihCbpXhZgjsahLY8UJgq9oh8K1QuvYJtz4AI4GADfG1fGzPdYfy94+kg== @@ -167,6 +186,15 @@ "@angular-devkit/schematics" "7.3.2" typescript "3.2.4" +"@schematics/angular@^7.3.5": + version "7.3.5" + resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.5.tgz#7af1cd446b051b2be3fbe59cb4ba140ec06e2d87" + integrity sha512-fKNZccf1l2OcDwtDupYj54N/YuiMLCWeaXNxcJNUYvGnBtzxQJ4P2LtSCjB4HDvYCtseQM7iyc7D1Xrr5gI8nw== + dependencies: + "@angular-devkit/core" "7.3.5" + "@angular-devkit/schematics" "7.3.5" + typescript "3.2.4" + "@schematics/update@0.13.2": version "0.13.2" resolved "https://registry.yarnpkg.com/@schematics/update/-/update-0.13.2.tgz#14ba82076b435814896ac141ba4dfad0dd3dadcd" diff --git a/package.json b/package.json index 3053a1c2bb..a28da5f656 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@bazel/karma": "0.26.0", "@bazel/typescript": "0.26.0", "@microsoft/api-extractor": "^7.0.21", - "@schematics/angular": "^7.3.2", + "@schematics/angular": "^7.3.5", "@types/angular": "^1.6.47", "@types/base64-js": "1.2.5", "@types/chokidar": "^1.7.5", @@ -157,4 +157,4 @@ "resolutions": { "natives": "1.1.6" } -} \ No newline at end of file +} diff --git a/packages/bazel/BUILD.bazel b/packages/bazel/BUILD.bazel index 1b7410dbb8..5deeaae06f 100644 --- a/packages/bazel/BUILD.bazel +++ b/packages/bazel/BUILD.bazel @@ -33,7 +33,6 @@ npm_package( "//packages/bazel/src/ng_package:lib", "//packages/bazel/src/ngc-wrapped:ngc_lib", "//packages/bazel/src/protractor/utils", - "//packages/bazel/src/schematics/bazel-workspace", "//packages/bazel/src/schematics/ng-add", "//packages/bazel/src/schematics/ng-new", ], diff --git a/packages/bazel/package.json b/packages/bazel/package.json index 67c794cb93..038687cc18 100644 --- a/packages/bazel/package.json +++ b/packages/bazel/package.json @@ -23,7 +23,7 @@ "@angular-devkit/schematics": "^7.3.0-rc.0", "@bazel/typescript": "^0.26.0", "@microsoft/api-extractor": "^7.0.21", - "@schematics/angular": "^7.0.4", + "@schematics/angular": "^7.3.5", "@types/node": "6.0.84", "semver": "^5.6.0", "shelljs": "0.8.2", diff --git a/packages/bazel/src/schematics/BUILD.bazel b/packages/bazel/src/schematics/BUILD.bazel index 16e9cf968e..a51a76767d 100644 --- a/packages/bazel/src/schematics/BUILD.bazel +++ b/packages/bazel/src/schematics/BUILD.bazel @@ -14,7 +14,6 @@ jasmine_node_test( name = "test", bootstrap = ["angular/tools/testing/init_node_spec.js"], deps = [ - "//packages/bazel/src/schematics/bazel-workspace:test", "//packages/bazel/src/schematics/ng-add:test", "//packages/bazel/src/schematics/ng-new:test", "//packages/bazel/src/schematics/utility:test", diff --git a/packages/bazel/src/schematics/bazel-workspace/BUILD.bazel b/packages/bazel/src/schematics/bazel-workspace/BUILD.bazel deleted file mode 100644 index a59b2da406..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/BUILD.bazel +++ /dev/null @@ -1,34 +0,0 @@ -load("//tools:defaults.bzl", "ts_library") - -package(default_visibility = ["//visibility:public"]) - -ts_library( - name = "bazel-workspace", - srcs = [ - "index.ts", - "schema.d.ts", - ], - data = glob(["files/**/*"]) + [ - "schema.json", - ], - deps = [ - "@npm//@angular-devkit/core", - "@npm//@angular-devkit/schematics", - "@npm//@schematics/angular", - ], -) - -ts_library( - name = "test", - testonly = True, - srcs = [ - "index_spec.ts", - ], - data = [ - "//packages/bazel/src/schematics:package_assets", - ], - deps = [ - ":bazel-workspace", - "@npm//@angular-devkit/schematics", - ], -) diff --git a/packages/bazel/src/schematics/bazel-workspace/files/BUILD.bazel.template b/packages/bazel/src/schematics/bazel-workspace/files/BUILD.bazel.template deleted file mode 100644 index 27b2fa1432..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/files/BUILD.bazel.template +++ /dev/null @@ -1,7 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -# This export allows targets in other packages to reference files that live -# in this package. -exports_files([ - "tsconfig.json", -]) diff --git a/packages/bazel/src/schematics/bazel-workspace/files/WORKSPACE.template b/packages/bazel/src/schematics/bazel-workspace/files/WORKSPACE.template deleted file mode 100644 index 5b4d987081..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/files/WORKSPACE.template +++ /dev/null @@ -1,63 +0,0 @@ -# WARNING: This file is generated and it's not meant to be edited. -# Before making any changes, please read Bazel documentation. -# https://docs.bazel.build/versions/master/be/workspace.html -# The WORKSPACE file tells Bazel that this directory is a "workspace", which is like a project root. -# The content of this file specifies all the external dependencies Bazel needs to perform a build. - -#################################### -# ESModule imports (and TypeScript imports) can be absolute starting with the workspace name. -# The name of the workspace should match the npm package where we publish, so that these -# imports also make sense when referencing the published package. -workspace(name = "<%= utils.underscore(name) %>") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -RULES_NODEJS_VERSION = "<%= RULES_NODEJS_VERSION %>" -http_archive( - name = "build_bazel_rules_nodejs", - sha256 = "<%= RULES_NODEJS_SHA256 %>", - url = "https://github.com/bazelbuild/rules_nodejs/releases/download/%s/rules_nodejs-%s.tar.gz" % (RULES_NODEJS_VERSION, RULES_NODEJS_VERSION), -) - -<% if (sass) { %> -# Rules for compiling sass -RULES_SASS_VERSION = "<%= RULES_SASS_VERSION %>" -http_archive( - name = "io_bazel_rules_sass", - sha256 = "<%= RULES_SASS_SHA256 %>", - url = "https://github.com/bazelbuild/rules_sass/archive/%s.zip" % RULES_SASS_VERSION, - strip_prefix = "rules_sass-%s" % RULES_SASS_VERSION, -) -<% } %> -#################################### -# Load and install our dependencies downloaded above. - -load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install") -# 0.18.0 is needed for .bazelignore -check_bazel_version("0.18.0") -node_repositories() -yarn_install( - name = "npm", - data = ["//:angular-metadata.tsconfig.json"], - package_json = "//:package.json", - yarn_lock = "//:yarn.lock", -) - -load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies") -install_bazel_dependencies() - -load("@npm_bazel_karma//:package.bzl", "rules_karma_dependencies") -rules_karma_dependencies() - -load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") -web_test_repositories() - -load("@npm_bazel_karma//:browser_repositories.bzl", "browser_repositories") -browser_repositories() - -load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace") -ts_setup_workspace() -<% if (sass) { %> -load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories") -sass_repositories() -<% } %> diff --git a/packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelignore.template b/packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelignore.template deleted file mode 100644 index de4d1f007d..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelignore.template +++ /dev/null @@ -1,2 +0,0 @@ -dist -node_modules diff --git a/packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelrc.template b/packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelrc.template deleted file mode 100644 index 1b544399da..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelrc.template +++ /dev/null @@ -1,29 +0,0 @@ -# Make TypeScript and Angular compilation fast, by keeping a few copies of the -# compiler running as daemons, and cache SourceFile AST's to reduce parse time. -build --strategy=TypeScriptCompile=worker -build --strategy=AngularTemplateCompile=worker - -# Don't create bazel-* symlinks in the WORKSPACE directory, except `bazel-out`, -# which is mandatory. -# These require .gitignore and may scare users. -# Also, it's a workaround for https://github.com/bazelbuild/rules_typescript/issues/12 -# which affects the common case of having `tsconfig.json` in the WORKSPACE directory. -# -# Instead, the output will appear in `dist/bin`. You'll need to ignore the -# `bazel-out` directory that is created in the workspace root. -build --symlink_prefix=dist/ - -# Turn on --incompatible_strict_action_env which was on by default -# in Bazel 0.21.0 but turned off again in 0.22.0. Follow -# https://github.com/bazelbuild/bazel/issues/7026 for more details. -# This flag is needed to so that the bazel cache is not invalidated -# when running bazel via `yarn bazel`. -# See https://github.com/angular/angular/issues/27514. -build --incompatible_strict_action_env -run --incompatible_strict_action_env -test --incompatible_strict_action_env - -test --test_output=errors - -# Use the Angular 6 compiler -build --define=compile=legacy diff --git a/packages/bazel/src/schematics/bazel-workspace/files/e2e/BUILD.bazel.template b/packages/bazel/src/schematics/bazel-workspace/files/e2e/BUILD.bazel.template deleted file mode 100644 index b38c34575f..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/files/e2e/BUILD.bazel.template +++ /dev/null @@ -1,50 +0,0 @@ -load("@npm_bazel_typescript//:index.bzl", "ts_library") -load("@npm_angular_bazel//:index.bzl", "protractor_web_test_suite") - -ts_library( - name = "e2e_lib", - testonly = 1, - srcs = glob(["src/**/*.ts"]), - tsconfig = ":tsconfig.e2e.json", - deps = [ - "@npm//@types/jasmine", - "@npm//@types/jasminewd2", - "@npm//@types/node", - "@npm//jasmine", - "@npm//protractor", - "@npm//tslib", - ], - data = [ - "//:tsconfig.json", - ], -) - -protractor_web_test_suite( - name = "prodserver_test", - data = [ - "@npm//@angular/bazel", - "@npm//protractor", - ], - on_prepare = ":protractor.on-prepare.js", - server = "//src:prodserver", - deps = [":e2e_lib"], -) - -protractor_web_test_suite( - name = "devserver_test", - data = [ - "@npm//@angular/bazel", - "@npm//protractor", - ], - on_prepare = ":protractor.on-prepare.js", - server = "//src:devserver", - deps = [":e2e_lib"], -) - -# Default target in this package is to run the e2e tests on the devserver. -# This is a faster round-trip but doesn't exercise production optimizations like -# code-splitting and lazy loading. -alias( - name = "e2e", - actual = "devserver_test", -) diff --git a/packages/bazel/src/schematics/bazel-workspace/files/src/BUILD.bazel.template b/packages/bazel/src/schematics/bazel-workspace/files/src/BUILD.bazel.template deleted file mode 100644 index 237f039881..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/files/src/BUILD.bazel.template +++ /dev/null @@ -1,153 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("@npm_angular_bazel//:index.bzl", "ng_module") -load("@npm_bazel_karma//:index.bzl", "ts_web_test_suite") -load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle", "history_server") -load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package") -load("@npm_bazel_typescript//:index.bzl", "ts_devserver", "ts_library") -<% if (sass) { %>load("@io_bazel_rules_sass//:defs.bzl", "multi_sass_binary") - -multi_sass_binary( - name = "styles", - srcs = glob(["**/*.scss"]), -) -<% } %> -ng_module( - name = "src", - srcs = glob( - include = ["**/*.ts"], - exclude = [ - "**/*.spec.ts", - "main.ts", - "test.ts", - "initialize_testbed.ts", - ], - ), - assets = glob([ - "**/*.css", - "**/*.html", - ])<% if (sass) { %> + [":styles"]<% } %>, - deps = [ - "@npm//@angular/core", - "@npm//@angular/platform-browser",<% if (routing) { %> - "@npm//@angular/router",<% } %> - "@npm//@types", - "@npm//rxjs", - ], -) - -rollup_bundle( - name = "bundle", - entry_point = "src/main.prod", - deps = [ - "//src", - "@npm//rxjs", - ], -) - -web_package( - name = "prodapp", - assets = [ - # do not sort - "@npm//node_modules/zone.js:dist/zone.min.js", - ":bundle.min.js", - ], - data = [ - "favicon.ico", - ], - index_html = "index.html", -) - -history_server( - name = "prodserver", - data = [":prodapp"], - templated_args = ["src/prodapp"], -) - -filegroup( - name = "rxjs_umd_modules", - srcs = [ - # do not sort - "@npm//node_modules/rxjs:bundles/rxjs.umd.js", - ":rxjs_shims.js", - ], -) - -ts_devserver( - name = "devserver", - port = 4200, - entry_module = "<%= utils.underscore(name) %>/src/main.dev", - serving_path = "/bundle.min.js", - scripts = [ - "@npm//node_modules/@angular/common:bundles/common.umd.js", - "@npm//node_modules/@angular/common:bundles/common-http.umd.js", - "@npm//node_modules/@angular/core:bundles/core.umd.js", - "@npm//node_modules/@angular/platform-browser:bundles/platform-browser.umd.js", - "@npm//node_modules/tslib:tslib.js", - ":rxjs_umd_modules", - ], - static_files = [ - "@npm//node_modules/zone.js:dist/zone.min.js", - ], - data = [ - "favicon.ico", - ], - index_html = "index.html", - deps = [":src"], -) - -ts_library( - name = "test_lib", - testonly = 1, - srcs = glob(["**/*.spec.ts"]), - deps = [ - ":src", - "@npm//@angular/core", - "@npm//@types", - ], -) - -ts_library( - name = "initialize_testbed", - testonly = 1, - srcs = [ - "initialize_testbed.ts", - ], - deps = [ - "@npm//@angular/core", - "@npm//@angular/platform-browser-dynamic", - "@npm//@types", - ], -) - -ts_web_test_suite( - name = "test", - srcs = [ - "@npm//node_modules/@angular/common:bundles/common.umd.js", - "@npm//node_modules/@angular/compiler:bundles/compiler.umd.js", - "@npm//node_modules/@angular/compiler:bundles/compiler-testing.umd.js", - "@npm//node_modules/@angular/core:bundles/core.umd.js", - "@npm//node_modules/@angular/core:bundles/core-testing.umd.js", - "@npm//node_modules/@angular/platform-browser:bundles/platform-browser.umd.js", - "@npm//node_modules/@angular/platform-browser:bundles/platform-browser-testing.umd.js", - "@npm//node_modules/@angular/platform-browser-dynamic:bundles/platform-browser-dynamic.umd.js", - "@npm//node_modules/@angular/platform-browser-dynamic:bundles/platform-browser-dynamic-testing.umd.js", - "@npm//node_modules/tslib:tslib.js", - ], - runtime_deps = [ - ":initialize_testbed", - ], - # do not sort - bootstrap = [ - "@npm//node_modules/zone.js:dist/zone-testing-bundle.js", - "@npm//node_modules/reflect-metadata:Reflect.js", - ], - browsers = [ - "@io_bazel_rules_webtesting//browsers:chromium-local", - ], - deps = [ - ":rxjs_umd_modules", - ":test_lib", - "@npm//karma-jasmine", - ], -) diff --git a/packages/bazel/src/schematics/bazel-workspace/index.ts b/packages/bazel/src/schematics/bazel-workspace/index.ts deleted file mode 100644 index 0fbdf9beb6..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/index.ts +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - * - * @fileoverview Schematics for bazel-workspace - */ - -import {strings} from '@angular-devkit/core'; -import {Rule, SchematicContext, Tree, apply, applyTemplates, mergeWith, url} from '@angular-devkit/schematics'; -import {getWorkspace} from '@schematics/angular/utility/config'; -import {validateProjectName} from '@schematics/angular/utility/validation'; - -import {Schema as BazelWorkspaceOptions} from './schema'; - -/** - * Clean the version string and return version in the form "1.2.3". Return - * null if version string is invalid. This is similar to semver.clean() but - * takes characters like '^' and '~' into account. - */ -export function clean(version: string): string|null { - const matches = version.match(/(\d+\.\d+\.\d+)/); - 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; -} - -/** - * Returns true if project uses SASS stylesheets, false otherwise. - */ -function hasSassStylesheet(host: Tree) { - let hasSass = false; - // The proper extension for SASS is .scss - host.visit((file: string) => { hasSass = hasSass || file.endsWith('.scss'); }); - return hasSass; -} - -export default function(options: BazelWorkspaceOptions): Rule { - return (host: Tree, context: SchematicContext) => { - const name = options.name || getWorkspace(host).defaultProject; - if (!name) { - throw new Error('Please provide a name for Bazel workspace'); - } - validateProjectName(name); - - if (!host.exists('yarn.lock')) { - host.create('yarn.lock', ''); - } - - const workspaceVersions = { - 'RULES_NODEJS_VERSION': '0.26.0', - 'RULES_NODEJS_SHA256': '5c86b055c57e15bf32d9009a15bcd6d8e190c41b1ff2fb18037b75e0012e4e7c', - 'RULES_SASS_VERSION': '1.17.2', - 'RULES_SASS_SHA256': 'e5316ee8a09d1cbb732d3938b400836bf94dba91a27476e9e27706c4c0edae1f', - }; - - return mergeWith(apply(url('./files'), [ - applyTemplates({ - utils: strings, - name, - 'dot': '.', ...workspaceVersions, - routing: hasRoutingModule(host), - sass: hasSassStylesheet(host), - }), - ])); - }; -} diff --git a/packages/bazel/src/schematics/bazel-workspace/index_spec.ts b/packages/bazel/src/schematics/bazel-workspace/index_spec.ts deleted file mode 100644 index af39661f61..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/index_spec.ts +++ /dev/null @@ -1,120 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {HostTree} from '@angular-devkit/schematics'; -import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; -import {clean} from './index'; - -describe('Bazel-workspace Schematic', () => { - const schematicRunner = - new SchematicTestRunner('@angular/bazel', require.resolve('../collection.json')); - const defaultOptions = { - name: 'demo', - }; - - it('should generate Bazel workspace files', () => { - const options = {...defaultOptions}; - const host = schematicRunner.runSchematic('bazel-workspace', options); - const files = host.files; - expect(files).toContain('/.bazelignore'); - expect(files).toContain('/.bazelrc'); - expect(files).toContain('/BUILD.bazel'); - expect(files).toContain('/src/BUILD.bazel'); - expect(files).toContain('/WORKSPACE'); - expect(files).toContain('/yarn.lock'); - }); - - it('should generate empty yarn.lock file', () => { - const host = schematicRunner.runSchematic('bazel-workspace', defaultOptions); - expect(host.files).toContain('/yarn.lock'); - expect(host.readContent('/yarn.lock')).toBe(''); - }); - - it('should not replace yarn.lock if it exists', () => { - let host = new UnitTestTree(new HostTree()); - host.create('yarn.lock', 'some content'); - expect(host.files).toContain('/yarn.lock'); - host = schematicRunner.runSchematic('bazel-workspace', defaultOptions, host); - expect(host.files).toContain('/yarn.lock'); - expect(host.readContent('/yarn.lock')).toBe('some content'); - }); - - it('should have the correct entry_module for devserver', () => { - const options = {...defaultOptions, name: 'demo-app'}; - const host = schematicRunner.runSchematic('bazel-workspace', options); - const {files} = host; - expect(files).toContain('/src/BUILD.bazel'); - const content = host.readContent('/src/BUILD.bazel'); - 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('/src/app/app-routing.module.ts', ''); - expect(host.files).toContain('/src/app/app-routing.module.ts'); - const options = {...defaultOptions}; - host = schematicRunner.runSchematic('bazel-workspace', options, host); - expect(host.files).toContain('/src/BUILD.bazel'); - const content = host.readContent('/src/BUILD.bazel'); - expect(content).toContain('@npm//@angular/router'); - }); - - describe('WORKSPACE', () => { - it('should contain project name', () => { - const options = {...defaultOptions}; - const host = schematicRunner.runSchematic('bazel-workspace', options); - expect(host.files).toContain('/WORKSPACE'); - const content = host.readContent('/WORKSPACE'); - expect(content).toContain('workspace(name = "demo")'); - }); - - it('should convert dashes in name to underscore', () => { - const options = {...defaultOptions, name: 'demo-project'}; - const host = schematicRunner.runSchematic('bazel-workspace', options); - expect(host.files).toContain('/WORKSPACE'); - const content = host.readContent('/WORKSPACE'); - expect(content).toContain('workspace(name = "demo_project"'); - }); - }); - - describe('SASS', () => { - let host = new UnitTestTree(new HostTree); - beforeAll(() => { - host.create('/src/app/app.component.scss', ''); - expect(host.files).toContain('/src/app/app.component.scss'); - const options = {...defaultOptions}; - host = schematicRunner.runSchematic('bazel-workspace', options, host); - expect(host.files).toContain('/WORKSPACE'); - expect(host.files).toContain('/src/BUILD.bazel'); - }); - - it('should download and load rules_sass in WORKSPACE', () => { - const content = host.readContent('/WORKSPACE'); - expect(content).toContain('RULES_SASS_VERSION'); - expect(content).toContain( - 'load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")'); - }); - - it('should add multi_sass_binary rule in src/BUILD', () => { - const content = host.readContent('/src/BUILD.bazel'); - expect(content).toContain('load("@io_bazel_rules_sass//:defs.bzl", "multi_sass_binary")'); - expect(content).toContain('glob(["**/*.scss"])'); - }); - }); -}); - -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]: [string, string]) => { - it(`should match ${version} with ${want}`, () => { - const got = clean(version); - expect(got).toBe(want); - }); - }); -}); diff --git a/packages/bazel/src/schematics/bazel-workspace/schema.d.ts b/packages/bazel/src/schematics/bazel-workspace/schema.d.ts deleted file mode 100644 index 4006879eb3..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/schema.d.ts +++ /dev/null @@ -1,13 +0,0 @@ - -// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE -// THE CORRESPONDING JSON SCHEMA FILE. See README.md. - -// tslint:disable:no-global-tslint-disable -// tslint:disable - -export interface Schema { - /** - * The name of the project. - */ - name?: string; -} diff --git a/packages/bazel/src/schematics/bazel-workspace/schema.json b/packages/bazel/src/schematics/bazel-workspace/schema.json deleted file mode 100644 index 173e464b2d..0000000000 --- a/packages/bazel/src/schematics/bazel-workspace/schema.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "id": "SchematicsAngularBazelWorkspace", - "title": "Angular Bazel Workspace Schema", - "type": "object", - "properties": { - "name": { - "description": "The name of the project.", - "type": "string", - "format": "html-selector", - "$default": { - "$source": "argv", - "index": 0 - } - } - }, - "required": [ - ] -} diff --git a/packages/bazel/src/schematics/collection.json b/packages/bazel/src/schematics/collection.json index 534f02cd62..b237962c63 100644 --- a/packages/bazel/src/schematics/collection.json +++ b/packages/bazel/src/schematics/collection.json @@ -11,12 +11,6 @@ "factory": "./ng-new", "schema": "./ng-new/schema.json", "description": "Create an Angular project that builds with Bazel." - }, - "bazel-workspace": { - "factory": "./bazel-workspace", - "schema": "./bazel-workspace/schema.json", - "description": "Setup Bazel workspace", - "hidden": true } } } diff --git a/packages/bazel/src/schematics/ng-add/BUILD.bazel b/packages/bazel/src/schematics/ng-add/BUILD.bazel index 1a67bbc1c0..c3b6070dcb 100644 --- a/packages/bazel/src/schematics/ng-add/BUILD.bazel +++ b/packages/bazel/src/schematics/ng-add/BUILD.bazel @@ -12,7 +12,6 @@ ts_library( "schema.json", ], deps = [ - "//packages/bazel/src/schematics/bazel-workspace", "//packages/bazel/src/schematics/utility", "@npm//@angular-devkit/core", "@npm//@angular-devkit/schematics", diff --git a/packages/bazel/src/schematics/bazel-workspace/files/angular-metadata.tsconfig.json.template b/packages/bazel/src/schematics/ng-add/files/angular-metadata.tsconfig.json.template similarity index 100% rename from packages/bazel/src/schematics/bazel-workspace/files/angular-metadata.tsconfig.json.template rename to packages/bazel/src/schematics/ng-add/files/angular-metadata.tsconfig.json.template diff --git a/packages/bazel/src/schematics/bazel-workspace/files/e2e/protractor.on-prepare.js.template b/packages/bazel/src/schematics/ng-add/files/e2e/protractor.on-prepare.js.template similarity index 100% rename from packages/bazel/src/schematics/bazel-workspace/files/e2e/protractor.on-prepare.js.template rename to packages/bazel/src/schematics/ng-add/files/e2e/protractor.on-prepare.js.template diff --git a/packages/bazel/src/schematics/bazel-workspace/files/src/initialize_testbed.ts.template b/packages/bazel/src/schematics/ng-add/files/src/initialize_testbed.ts.template similarity index 100% rename from packages/bazel/src/schematics/bazel-workspace/files/src/initialize_testbed.ts.template rename to packages/bazel/src/schematics/ng-add/files/src/initialize_testbed.ts.template diff --git a/packages/bazel/src/schematics/ng-add/files/main.dev.ts.template b/packages/bazel/src/schematics/ng-add/files/src/main.dev.ts.template similarity index 100% rename from packages/bazel/src/schematics/ng-add/files/main.dev.ts.template rename to packages/bazel/src/schematics/ng-add/files/src/main.dev.ts.template diff --git a/packages/bazel/src/schematics/ng-add/files/main.prod.ts.template b/packages/bazel/src/schematics/ng-add/files/src/main.prod.ts.template similarity index 100% rename from packages/bazel/src/schematics/ng-add/files/main.prod.ts.template rename to packages/bazel/src/schematics/ng-add/files/src/main.prod.ts.template diff --git a/packages/bazel/src/schematics/bazel-workspace/files/src/rxjs_shims.js.template b/packages/bazel/src/schematics/ng-add/files/src/rxjs_shims.js.template similarity index 100% rename from packages/bazel/src/schematics/bazel-workspace/files/src/rxjs_shims.js.template rename to packages/bazel/src/schematics/ng-add/files/src/rxjs_shims.js.template diff --git a/packages/bazel/src/schematics/ng-add/index.ts b/packages/bazel/src/schematics/ng-add/index.ts index 9bb354900d..5b76c2eda4 100755 --- a/packages/bazel/src/schematics/ng-add/index.ts +++ b/packages/bazel/src/schematics/ng-add/index.ts @@ -61,20 +61,13 @@ function addDevDependenciesToPackageJson(options: Schema) { } /** - * Append main.dev.ts and main.prod.ts to src directory. These files are needed - * by Bazel for devserver and prodserver, respectively. They are different from - * main.ts generated by CLI because they use platformBrowser (AOT) instead of - * platformBrowserDynamic (JIT). + * Append additional Javascript / Typescript files needed to compile an Angular + * project under Bazel. */ -function addDevAndProdMainForAot(options: Schema) { +function addFilesRequiredByBazel(options: Schema) { return (host: Tree) => { return mergeWith(apply(url('./files'), [ - applyTemplates({ - utils: strings, - ...options, - 'dot': '.', - }), - move('/src'), + applyTemplates({}), ])); }; } @@ -331,8 +324,7 @@ export default function(options: Schema): Rule { validateProjectName(options.name); return chain([ - schematic('bazel-workspace', options), - addDevAndProdMainForAot(options), + addFilesRequiredByBazel(options), addDevDependenciesToPackageJson(options), addPostinstallToGenerateNgSummaries(), backupAngularJson(), diff --git a/packages/bazel/src/schematics/ng-add/index_spec.ts b/packages/bazel/src/schematics/ng-add/index_spec.ts index 4e5d62d5e4..efc4610d19 100644 --- a/packages/bazel/src/schematics/ng-add/index_spec.ts +++ b/packages/bazel/src/schematics/ng-add/index_spec.ts @@ -17,54 +17,45 @@ describe('ng-add schematic', () => { beforeEach(() => { host = new UnitTestTree(new HostTree()); - host.create( - 'package.json', JSON.stringify( - { - name: 'demo', - dependencies: { - '@angular/core': '1.2.3', - 'rxjs': '~6.3.3', - }, - devDependencies: { - 'typescript': '3.2.2', - }, - }, - null, 2)); - host.create( - 'tsconfig.json', JSON.stringify( - { - compileOnSave: false, - compilerOptions: { - baseUrl: './', - outDir: './dist/out-tsc', - } - }, - null, 2)); - host.create( - 'angular.json', JSON.stringify( - { - projects: { - 'demo': { - architect: { - build: {}, - serve: {}, - test: {}, - 'extract-i18n': { - builder: '@angular-devkit/build-angular:extract-i18n', - }, - }, - }, - 'demo-e2e': { - architect: { - e2e: {}, - lint: { - builder: '@angular-devkit/build-angular:tslint', - }, - }, - }, - }, - }, - null, 2)); + host.create('package.json', JSON.stringify({ + name: 'demo', + dependencies: { + '@angular/core': '1.2.3', + 'rxjs': '~6.3.3', + }, + devDependencies: { + 'typescript': '3.2.2', + }, + })); + host.create('tsconfig.json', JSON.stringify({ + compileOnSave: false, + compilerOptions: { + baseUrl: './', + outDir: './dist/out-tsc', + } + })); + host.create('angular.json', JSON.stringify({ + projects: { + 'demo': { + architect: { + build: {}, + serve: {}, + test: {}, + 'extract-i18n': { + builder: '@angular-devkit/build-angular:extract-i18n', + }, + }, + }, + 'demo-e2e': { + architect: { + e2e: {}, + lint: { + builder: '@angular-devkit/build-angular:tslint', + }, + }, + }, + }, + })); schematicRunner = new SchematicTestRunner('@angular/bazel', require.resolve('../collection.json')); }); @@ -109,11 +100,11 @@ describe('ng-add schematic', () => { expect(devDeps).toContain('@bazel/karma'); }); - it('should create Bazel workspace file', () => { + it('should not create Bazel workspace file', () => { host = schematicRunner.runSchematic('ng-add', defaultOptions, host); const {files} = host; - expect(files).toContain('/WORKSPACE'); - expect(files).toContain('/BUILD.bazel'); + expect(files).not.toContain('/WORKSPACE'); + expect(files).not.toContain('/BUILD.bazel'); }); it('should produce main.dev.ts and main.prod.ts for AOT', () => { @@ -225,19 +216,16 @@ describe('ng-add schematic', () => { ]; for (const [version, upgrade] of cases) { it(`should ${upgrade ? '' : 'not '}upgrade v${version}')`, () => { - host.overwrite( - 'package.json', JSON.stringify( - { - name: 'demo', - dependencies: { - '@angular/core': '1.2.3', - 'rxjs': version, - }, - devDependencies: { - 'typescript': '3.2.2', - }, - }, - null, 2)); + host.overwrite('package.json', JSON.stringify({ + name: 'demo', + dependencies: { + '@angular/core': '1.2.3', + 'rxjs': version, + }, + devDependencies: { + 'typescript': '3.2.2', + }, + })); host = schematicRunner.runSchematic('ng-add', defaultOptions, host); expect(host.files).toContain('/package.json'); const content = host.readContent('/package.json'); diff --git a/packages/bazel/src/schematics/ng-new/index_spec.ts b/packages/bazel/src/schematics/ng-new/index_spec.ts index 66177ea67c..3c33b3fb95 100644 --- a/packages/bazel/src/schematics/ng-new/index_spec.ts +++ b/packages/bazel/src/schematics/ng-new/index_spec.ts @@ -25,12 +25,11 @@ describe('ng-new schematic', () => { expect(files).toContain('/demo/package.json'); }); - it('should call ng-add to generate Bazel files', () => { + it('should call ng-add to generate additional files needed by Bazel', () => { const options = {...defaultOptions}; const host = schematicRunner.runSchematic('ng-new', options); const {files} = host; - expect(files).toContain('/demo/WORKSPACE'); - expect(files).toContain('/demo/BUILD.bazel'); - expect(files).toContain('/demo/src/BUILD.bazel'); + expect(files).toContain('/demo/src/main.dev.ts'); + expect(files).toContain('/demo/src/main.prod.ts'); }); }); diff --git a/yarn.lock b/yarn.lock index f5a868ae11..89e3901369 100644 --- a/yarn.lock +++ b/yarn.lock @@ -31,6 +31,17 @@ rxjs "6.3.3" source-map "0.7.3" +"@angular-devkit/core@7.3.5": + version "7.3.5" + resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-7.3.5.tgz#2a59a913eab358e2385f52ba28132b81435e63b3" + integrity sha512-J/Tztq2BZ3tpwUsbiz8N61rf9lwqn85UvJsDui2SPIdzDR9KmPr5ESI2Irc/PEb9i+CBXtVuhr8AIqo7rR6ZTg== + dependencies: + ajv "6.9.1" + chokidar "2.0.4" + fast-json-stable-stringify "2.0.0" + rxjs "6.3.3" + source-map "0.7.3" + "@angular-devkit/schematics@7.3.2", "@angular-devkit/schematics@^7.3.2": version "7.3.2" resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.2.tgz#e9d3c1f2128a56f66ea846ce3f80c69d4c3a9ae9" @@ -39,6 +50,14 @@ "@angular-devkit/core" "7.3.2" rxjs "6.3.3" +"@angular-devkit/schematics@7.3.5": + version "7.3.5" + resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.5.tgz#7b007f8a86dea76e93eef007d4fb6e7d8324b7bb" + integrity sha512-BFCCkwRMBC4aFlngaloi1avCTgGrl1MFc/0Av2sCpBh/fdm1FqSVzmOiTfu93dehRVVL/bTrA2qj+xpNsXCxzA== + dependencies: + "@angular-devkit/core" "7.3.5" + rxjs "6.3.3" + "@angular/bazel@file:./tools/npm/@angular_bazel": version "0.0.0" @@ -265,7 +284,7 @@ resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.5.tgz#c448a38902ccb5601c1b2ef3b1a105012ef7712c" integrity sha512-xEAyvLXo4Cter/b0EMCWUZTgXOfLOPJ/Xr52WdjVclPx9eDmNTGFtZl8Pn/nqSnZsQBNcHL0eHk/YyRyyXXpiQ== -"@schematics/angular@7.3.2", "@schematics/angular@^7.3.2": +"@schematics/angular@7.3.2": version "7.3.2" resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.2.tgz#470f972a9d80ab8af9900e33972bce44aa567718" integrity sha512-ClqG1qA919QqsikIXIP/jKl2Boj70lihCbpXhZgjsahLY8UJgq9oh8K1QuvYJtz4AI4GADfG1fGzPdYfy94+kg== @@ -274,6 +293,15 @@ "@angular-devkit/schematics" "7.3.2" typescript "3.2.4" +"@schematics/angular@^7.3.5": + version "7.3.5" + resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.5.tgz#7af1cd446b051b2be3fbe59cb4ba140ec06e2d87" + integrity sha512-fKNZccf1l2OcDwtDupYj54N/YuiMLCWeaXNxcJNUYvGnBtzxQJ4P2LtSCjB4HDvYCtseQM7iyc7D1Xrr5gI8nw== + dependencies: + "@angular-devkit/core" "7.3.5" + "@angular-devkit/schematics" "7.3.5" + typescript "3.2.4" + "@schematics/update@0.13.2": version "0.13.2" resolved "https://registry.yarnpkg.com/@schematics/update/-/update-0.13.2.tgz#14ba82076b435814896ac141ba4dfad0dd3dadcd"