Skip to content

Commit

Permalink
build(bazel): use fine-grained npm deps (angular#26111) (angular#26488)
Browse files Browse the repository at this point in the history
PR Close angular#26488
  • Loading branch information
gregmagolan authored and IgorMinar committed Oct 20, 2018
1 parent b6c9678 commit 1f3331f
Show file tree
Hide file tree
Showing 104 changed files with 6,704 additions and 1,837 deletions.
46 changes: 31 additions & 15 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,47 @@ alias(
actual = "@nodejs//:yarn",
)

alias(
name = "node_modules",
actual = "@angular_deps//:node_modules",
)

filegroup(
name = "web_test_bootstrap_scripts",
# do not sort
srcs = [
"@angular_deps//:node_modules/reflect-metadata/Reflect.js",
"@angular_deps//:node_modules/zone.js/dist/zone.js",
"@angular_deps//:node_modules/zone.js/dist/zone-testing.js",
"@angular_deps//:node_modules/zone.js/dist/task-tracking.js",
"@ngdeps//node_modules/reflect-metadata:Reflect.js",
"@ngdeps//node_modules/zone.js:dist/zone.js",
"@ngdeps//node_modules/zone.js:dist/zone-testing.js",
"@ngdeps//node_modules/zone.js:dist/task-tracking.js",
"//:test-events.js",
],
)

filegroup(
name = "angularjs_scripts",
srcs = [
"@angular_deps//:node_modules/angular-1.5/angular.js",
"@angular_deps//:node_modules/angular-1.6/angular.js",
"@angular_deps//:node_modules/angular-mocks-1.5/angular-mocks.js",
"@angular_deps//:node_modules/angular-mocks-1.6/angular-mocks.js",
"@angular_deps//:node_modules/angular-mocks/angular-mocks.js",
"@angular_deps//:node_modules/angular/angular.js",
"@ngdeps//node_modules/angular:angular.js",
"@ngdeps//node_modules/angular-1.5:angular.js",
"@ngdeps//node_modules/angular-1.6:angular.js",
"@ngdeps//node_modules/angular-mocks:angular-mocks.js",
"@ngdeps//node_modules/angular-mocks-1.5:angular-mocks.js",
"@ngdeps//node_modules/angular-mocks-1.6:angular-mocks.js",
],
)

load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")

# Override for ts_web_test_suite to use @ngdeps instead of @npm
nodejs_binary(
name = "@bazel/karma/karma",
data = ["@ngdeps//@bazel/karma"],
entry_point = "@bazel/karma/karma.js",
install_source_map_support = False,
visibility = ["//visibility:public"],
)

# Override for ts_library to use @ngdeps instead of @npm
nodejs_binary(
name = "@bazel/typescript/tsc_wrapped",
data = ["@ngdeps//@bazel/typescript"],
entry_point = "@bazel/typescript/tsc_wrapped/tsc_wrapped.js",
install_source_map_support = False,
templated_args = ["--node_options=--expose-gc"],
visibility = ["//visibility:public"],
)
9 changes: 7 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ local_repository(
#
# Load and install our dependencies downloaded above.
#

load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")

check_bazel_version("0.17.0", """
If you are on a Mac and using Homebrew, there is a breaking change to the installation in Bazel 0.16
Expand All @@ -56,6 +55,12 @@ node_repositories(
yarn_version = "1.9.2",
)

yarn_install(
name = "npm",
package_json = "//tools:npm/package.json",
yarn_lock = "//tools:npm/yarn.lock",
)

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()
Expand Down
23 changes: 0 additions & 23 deletions integration/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,3 @@ alias(
name = "tsconfig.json",
actual = "//src:tsconfig.json",
)

filegroup(
name = "node_modules",
srcs = glob(
[
# Include only .js, .json & .d.ts files to reduce the number of
# files in the //:node_modules filegroup
"node_modules/**/*.js",
"node_modules/**/*.json",
"node_modules/**/*.d.ts",
# All the files in the http-server package are necesssary
"node_modules/http-server/**",
# All the files in the protractor package are necesssary
"node_modules/protractor/**",
# Also include all files in node_modules/.bin
"node_modules/.bin/*",
],
exclude = [
# Exclude files with spaces which are illegal bazel labels
"node_modules/**/* *",
],
),
)
31 changes: 12 additions & 19 deletions integration/bazel/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@ workspace(name = "bazel_integration_test")
#
# Download Bazel toolchain dependencies as needed by build actions
#
local_repository(
name = "build_bazel_rules_typescript",
path = "node_modules/@bazel/typescript",
)
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies")
rules_typescript_dependencies()

http_archive(
name = "io_bazel_rules_sass",
url = "https://github.com/bazelbuild/rules_sass/archive/1.11.0.zip",
strip_prefix = "rules_sass-1.11.0",
sha256 = "dbe9fb97d5a7833b2a733eebc78c9c1e3880f676ac8af16e58ccf2139cbcad03",
)

#
# Point Bazel to WORKSPACEs that live in subdirectories
#

local_repository(
name = "angular",
Expand All @@ -31,11 +14,15 @@ local_repository(
path = "node_modules/rxjs/src",
)

load("@angular//packages/bazel:package.bzl", "rules_angular_dependencies")

rules_angular_dependencies()

#
# Load and install our dependencies downloaded above.
# Setup dependencies loaded above
#

load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")

check_bazel_version("0.17.0")
node_repositories(
Expand All @@ -44,6 +31,12 @@ node_repositories(
yarn_version = "1.9.2",
)

yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()
Expand Down
21 changes: 12 additions & 9 deletions integration/bazel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"reflect-metadata": "file:../../node_modules/reflect-metadata",
"rxjs": "file:../../node_modules/rxjs",
"tslib": "file:../../node_modules/tslib",
"zone.js": "file:../../node_modules/zone.js"
"reflect-metadata": "0.1.12",
"rxjs": "6.0.0",
"tslib": "1.9.3",
"zone.js": "0.8.26"
},
"devDependencies": {
"@bazel/typescript": "0.17.0",
"@types/jasmine": "file:../../node_modules/@types/jasmine",
"@bazel/karma": "0.19.1",
"@bazel/typescript": "0.19.1",
"@types/jasmine": "2.8.8",
"@types/source-map": "0.5.1",
"protractor": "file:../../node_modules/protractor",
"tsickle": "file:../../node_modules/tsickle",
"typescript": "file:../../node_modules/typescript"
"protractor": "5.1.2",
"shelljs": "^0.8.2",
"tsickle": "0.32.0",
"typescript": "3.0.1"
},
"scripts": {
"//": "TODO(gmagolan): figure out how to keep dependencies here up to date with the root package.json",
"test": "bazel build ... --noshow_progress && bazel test ..."
}
}
12 changes: 6 additions & 6 deletions integration/bazel/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ng_module(
"@angular//packages/common/http",
"@angular//packages/core",
"@angular//packages/platform-browser",
"@npm//@types",
],
)

Expand All @@ -21,14 +22,14 @@ load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver")
ts_devserver(
name = "devserver",
additional_root_paths = [
"bazel_integration_test/node_modules/tslib",
"bazel_integration_test/node_modules/zone.js/dist",
"npm/node_modules/tslib",
"npm/node_modules/zone.js/dist",
],
entry_module = "bazel_integration_test/src/main",
serving_path = "/bundle.min.js",
static_files = [
"//:node_modules/tslib/tslib.js",
"//:node_modules/zone.js/dist/zone.min.js",
"@npm//node_modules/tslib:tslib.js",
"@npm//node_modules/zone.js:dist/zone.min.js",
"index.html",
],
deps = ["//src"],
Expand All @@ -39,15 +40,14 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "rollup_bundle")
rollup_bundle(
name = "bundle",
entry_point = "src/main",
node_modules = "//:node_modules",
deps = ["//src"],
)

# Needed because the prodserver only loads static files that appear under this
# package.
genrule(
name = "zone.js",
srcs = ["//:node_modules/zone.js/dist/zone.min.js"],
srcs = ["@npm//node_modules/zone.js:dist/zone.min.js"],
outs = ["zone.min.js"],
cmd = "cp $< $@",
)
Expand Down
14 changes: 9 additions & 5 deletions integration/bazel/src/hello-world/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ ng_module(
assets = [":hello-world-styles"],
deps = [
"@angular//packages/core",
"@npm//@types",
],
)

ng_package(
name = "npm_package",
entry_point = "src/hello-world/index.js",
node_modules = "//:node_modules",
deps = [":hello-world"],
)

Expand All @@ -38,19 +38,23 @@ ts_library(
"@angular//packages/core/testing",
"@angular//packages/platform-browser",
"@angular//packages/platform-browser-dynamic/testing",
"@npm//@types",
"@npm//jasmine",
],
)

ts_web_test_suite(
name = "test",
srcs = ["//:node_modules/tslib/tslib.js"],
srcs = ["@npm//node_modules/tslib:tslib.js"],
bootstrap = [
"//:node_modules/zone.js/dist/zone-testing-bundle.js",
"//:node_modules/reflect-metadata/Reflect.js",
"@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",
"@io_bazel_rules_webtesting//browsers:firefox-local",
# TODO(gregmagolan): re-enable firefox testing once fixed
# See https://github.com/bazelbuild/rules_typescript/issues/296
# "@io_bazel_rules_webtesting//browsers:firefox-local",
],
deps = [
":test_lib",
Expand Down
20 changes: 17 additions & 3 deletions integration/bazel/test/e2e/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,31 @@ ts_library(
testonly = 1,
srcs = ["app.spec.ts"],
tsconfig = ":tsconfig.json",
deps = [
"@npm//@types",
"@npm//protractor",
],
)

ts_library(
name = "ts_on_prepare",
testonly = 1,
srcs = ["on-prepare.ts"],
tsconfig = ":tsconfig.json",
deps = ["@angular//packages/bazel/src/protractor/utils"],
deps = [
"@angular//packages/bazel/src/protractor/utils",
"@npm//@types",
"@npm//protractor",
],
)

protractor_web_test_suite(
name = "devserver_test",
configuration = "//:protractor.conf.js",
data = ["@angular//packages/bazel/src/protractor/utils"],
data = [
"@angular//packages/bazel/src/protractor/utils",
"@npm//protractor",
],
on_prepare = ":ts_on_prepare",
server = "//src:devserver",
deps = [":e2e"],
Expand All @@ -28,7 +39,10 @@ protractor_web_test_suite(
protractor_web_test_suite(
name = "prodserver_test",
configuration = "//:protractor.conf.js",
data = ["@angular//packages/bazel/src/protractor/utils"],
data = [
"@angular//packages/bazel/src/protractor/utils",
"@npm//protractor",
],
on_prepare = ":ts_on_prepare",
server = "//src:prodserver",
deps = [":e2e"],
Expand Down
Loading

0 comments on commit 1f3331f

Please sign in to comment.