Skip to content

Commit

Permalink
build(bazel): update to nodejs rules 0.30.1 & bazel 0.26.0 (angular#3…
Browse files Browse the repository at this point in the history
…0627)

nodejs rules 0.30.1 has new feature to symlink node_modules with yarn_install and bazel 0.26.0 includes new managed_directories feature which enables this

PR Close angular#30627
  • Loading branch information
gregmagolan authored and ayazhafiz committed Jun 12, 2019
1 parent 829be96 commit b358736
Show file tree
Hide file tree
Showing 19 changed files with 3,945 additions and 483 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ aio/content
aio/node_modules
aio/tools/examples/shared/node_modules
integration/bazel
integration/bazel-schematics/demo
packages/bazel/node_modules
10 changes: 10 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,13 @@ build:remote --remote_accept_cached=false
# Load any settings specific to the current user. Needs to be last statement in this
# config, as the user configuration should be able to overwrite flags from this file.
try-import .bazelrc.user

###############################
# NodeJS rules settings
# These settings are required for rules_nodejs
###############################

# Turn on managed directories feature in Bazel
# This allows us to avoid installing a second copy of node_modules
build --experimental_allow_incremental_repository_updates
query --experimental_allow_incremental_repository_updates
30 changes: 12 additions & 18 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
workspace(name = "angular")
workspace(
name = "angular",
managed_directories = {"@npm": ["node_modules"]},
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

Expand All @@ -15,16 +18,15 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Fetch rules_nodejs so we can install our npm dependencies
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "395b7568f20822c13fc5abc65b1eced637446389181fda3a108fdd6ff2cac1e9",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.29.2/rules_nodejs-0.29.2.tar.gz"],
sha256 = "abcf497e89cfc1d09132adfcd8c07526d026e162ae2cb681dcb896046417ce91",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.30.1/rules_nodejs-0.30.1.tar.gz"],
)

# Check the bazel version and download npm dependencies
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "check_rules_nodejs_version", "node_repositories", "yarn_install")

# Bazel version must be at least v0.21.0 because:
# - 0.21.0 Using --incompatible_strict_action_env flag fixes cache when running `yarn bazel`
# (see https://github.com/angular/angular/issues/27514#issuecomment-451438271)
# Bazel version must be at least the following version because:
# - 0.26.0 managed_directories feature added which is required for nodejs rules 0.30.0
check_bazel_version(
message = """
You no longer need to install Bazel on your machine.
Expand All @@ -33,22 +35,22 @@ Try running `yarn bazel` instead.
(If you did run that, check that you've got a fresh `yarn install`)
""",
minimum_bazel_version = "0.21.0",
minimum_bazel_version = "0.26.0",
)

# The NodeJS rules version must be at least v0.15.3 because:
# The NodeJS rules version must be at least the following version because:
# - 0.15.2 Re-introduced the prod_only attribute on yarn_install
# - 0.15.3 Includes a fix for the `jasmine_node_test` rule ignoring target tags
# - 0.16.8 Supports npm installed bazel workspaces
# - 0.26.0 Fix for data files in yarn_install and npm_install
# - 0.27.12 Adds NodeModuleSources provider for transtive npm deps support
check_rules_nodejs_version("0.27.12")
# - 0.30.0 yarn_install now uses symlinked node_modules with new managed directories Bazel 0.26.0 feature
check_rules_nodejs_version("0.30.0")

# Setup the Node.js toolchain
node_repositories(
node_version = "10.9.0",
package_json = ["//:package.json"],
preserve_symlinks = True,
# yarn 1.13.0 under Bazel has a regression on Windows that causes build errors on rebuilds:
# ```
# ERROR: Source forest creation failed: C:/.../fyuc5c3n/execroot/angular/external (Directory not empty)
Expand All @@ -62,15 +64,7 @@ node_repositories(

yarn_install(
name = "npm",
data = [
"//:tools/npm/@angular_bazel/index.js",
"//:tools/npm/@angular_bazel/package.json",
"//:tools/postinstall-patches.js",
"//:tools/yarn/check-yarn.js",
],
package_json = "//:package.json",
# Don't install devDependencies, they are large and not used under Bazel
prod_only = True,
yarn_lock = "//:yarn.lock",
)

Expand Down
2 changes: 1 addition & 1 deletion integration/bazel-schematics/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function testBazel() {
ng new demo --collection=@angular/bazel --routing --skip-git --skip-install --style=scss
cd demo
installLocalPackages
yarn webdriver-manager update --gecko=false --standalone=false ${CI_CHROMEDRIVER_VERSION_ARG:---versions.chrome 2.45}
ng generate component widget --style=css
ng build
ng test
Expand All @@ -44,6 +43,7 @@ function testNonBazel() {
mv ./angular.json.bak ./angular.json
mv ./tsconfig.json.bak ./tsconfig.json
rm -rf dist src/main.dev.ts src/main.prod.ts
yarn webdriver-manager update --gecko=false --standalone=false ${CI_CHROMEDRIVER_VERSION_ARG:---versions.chrome 2.45}
ng build --progress=false
ng test --progress=false --watch=false
ng e2e --configuration=production --webdriver-update=false
Expand Down
44 changes: 22 additions & 22 deletions integration/bazel-schematics/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
rxjs "6.4.0"

"@angular/bazel@file:../../dist/packages-dist/bazel":
version "8.0.0-beta.13"
version "8.0.0-rc.0"
dependencies:
"@angular-devkit/architect" "^0.800.0-beta.15"
"@angular-devkit/core" "^8.0.0-beta.15"
Expand All @@ -40,7 +40,7 @@
"@types/node" "6.0.84"
semver "^5.6.0"
shelljs "0.8.2"
tsickle "0.34.3"
tsickle "^0.35.0"

"@angular/cli@file:../../node_modules/@angular/cli":
version "8.0.0-beta.15"
Expand All @@ -62,27 +62,27 @@
universal-analytics "^0.4.20"
uuid "^3.3.2"

"@bazel/bazel-darwin_x64@0.24.0":
version "0.24.0"
resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-0.24.0.tgz#828ef298d8d542961df388f17b0244f4f4302a74"
integrity sha512-xly44vkcD/fauUb7Lm5Lme4qhEZdkuuyBKSVQUHPbYAGDdbj/W8dupI3bZREkJAgG/WrRU+WXUemMj4U8ZcLcw==
"@bazel/bazel-darwin_x64@0.26.0-rc13":
version "0.26.0-rc13"
resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-0.26.0-rc13.tgz#b580f470e2e221a3dd0e449c2b652ebfda661644"
integrity sha512-I1TvJuD49UtiE8yt8vRcejvG/ISX09MdFTXRIhHKnB+soRZF2zbUtqs0H4ugMK2fzb80T/QK3QmXbjSfcZbx2w==

"@bazel/bazel-linux_x64@0.24.0":
version "0.24.0"
resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-0.24.0.tgz#9ef2e7266833ad2221fe4af4ceb6763d2897e3ff"
integrity sha512-p5ylPLWnJZDGbaIFBrtD/tp3Su5rMdzeeNJKU24XyiWQTHVZ3OD3I2Fb0ILCgfBjY8AlA7EtCtOI4hYnAuIOtg==
"@bazel/bazel-linux_x64@0.26.0-rc13":
version "0.26.0-rc13"
resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-0.26.0-rc13.tgz#2b794b23b8954fe08b3c5f8a8b50c69e26ac08aa"
integrity sha512-VIyJMR18ItGZFwMSRxYU+5bTohsn45yfrpjFdVP+aVcIl2c4KuPAyM4dTKwjGUUeDDGUDMb809PjyTgsRe5x3w==

"@bazel/bazel-win32_x64@0.24.0":
version "0.24.0"
resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-0.24.0.tgz#02d83113a6c6ed99795a3e41bff5631aa141638d"
integrity sha512-/bcSEx+GoV/q7H4WM0jazfxTcurSiIIePhRv+d05mxRDcaWwhCO8KzmmZRWH1abW6npvq5tLkbSQi7G7nUBhgg==
"@bazel/bazel-win32_x64@0.26.0-rc13":
version "0.26.0-rc13"
resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-0.26.0-rc13.tgz#fe862c700c35a41d43ee3223f8dbe5f735395e68"
integrity sha512-8nAntbZTFp9xv504L5u4aLMKgkq2rhgqW+fJwcNmVz9Wg3cKVMxl+G49cYzImGxqrv9MFLe3lD1ldBYdoEvNqg==

"@bazel/bazel@file:../../node_modules/@bazel/bazel":
version "0.24.0"
version "0.26.0-rc13"
optionalDependencies:
"@bazel/bazel-darwin_x64" "0.24.0"
"@bazel/bazel-linux_x64" "0.24.0"
"@bazel/bazel-win32_x64" "0.24.0"
"@bazel/bazel-darwin_x64" "0.26.0-rc13"
"@bazel/bazel-linux_x64" "0.26.0-rc13"
"@bazel/bazel-win32_x64" "0.26.0-rc13"

"@microsoft/api-extractor@^7.0.21":
version "7.0.22"
Expand Down Expand Up @@ -1610,10 +1610,10 @@ tough-cookie@~2.4.3:
psl "^1.1.24"
punycode "^1.4.1"

tsickle@0.34.3:
version "0.34.3"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.34.3.tgz#8085067a26d7bff466ddadb2eba18849b49159b8"
integrity sha512-mb1v3nsr6rYaZky22xj0d6qv4ogAR40Bc6r37jwWOg3bEIO/ZppEFZiEADs/NNVLcWTPgmNmPZgaX5CfAH6oXA==
tsickle@^0.35.0:
version "0.35.0"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.35.0.tgz#59235df45937c0ec5d072c616c26d2d97fba54b9"
integrity sha512-irsZLX4293YUl9TuwNC5Fy020eLSc4bC3LfKnxnx1oq5wmZD9zSP8qvNNTiwRmf2/rxH+58JINcTARDjuvn+oQ==
dependencies:
minimist "^1.2.0"
mkdirp "^0.5.1"
Expand Down
1 change: 1 addition & 0 deletions integration/bazel/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions integration/bazel/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ build --define=compile=legacy

# Don't create symlinks
build --symlink_prefix=/

# Turn on managed directories feature in Bazel
# This allows us to avoid installing a second copy of node_modules
build --experimental_allow_incremental_repository_updates
query --experimental_allow_incremental_repository_updates
30 changes: 14 additions & 16 deletions integration/bazel/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
workspace(name = "bazel_integration_test")
workspace(
name = "bazel_integration_test",
managed_directories = {"@npm": ["node_modules"]},
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Fetch rules_nodejs so we can install our npm dependencies
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "395b7568f20822c13fc5abc65b1eced637446389181fda3a108fdd6ff2cac1e9",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.29.2/rules_nodejs-0.29.2.tar.gz"],
sha256 = "abcf497e89cfc1d09132adfcd8c07526d026e162ae2cb681dcb896046417ce91",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.30.1/rules_nodejs-0.30.1.tar.gz"],
)

# Fetch sass rules for compiling sass files
http_archive(
name = "io_bazel_rules_sass",
sha256 = "dbe9fb97d5a7833b2a733eebc78c9c1e3880f676ac8af16e58ccf2139cbcad03",
strip_prefix = "rules_sass-1.11.0",
url = "https://github.com/bazelbuild/rules_sass/archive/1.11.0.zip",
sha256 = "4c87befcb17282b039ba8341df9a6cc45f461bf05776dcf35c7e40c7e79ce374",
strip_prefix = "rules_sass-3a4f31c74513ccfacce3f955b5c006352f7e9587",
url = "https://github.com/bazelbuild/rules_sass/archive/3a4f31c74513ccfacce3f955b5c006352f7e9587.zip",
)

# Check the bazel version and download npm dependencies
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")

# Bazel version must be at least v0.21.0 because:
# - 0.21.0 Using --incompatible_strict_action_env flag fixes cache when running `yarn bazel`
# (see https://github.com/angular/angular/issues/27514#issuecomment-451438271)
# Bazel version must be at least the following version because:
# - 0.26.0 managed_directories feature added which is required for nodejs rules 0.30.0
check_bazel_version(
message = """
You no longer need to install Bazel on your machine.
Expand All @@ -31,7 +33,7 @@ Try running `yarn bazel` instead.
(If you did run that, check that you've got a fresh `yarn install`)
""",
minimum_bazel_version = "0.21.0",
minimum_bazel_version = "0.26.0",
)

# Setup the Node.js toolchain
Expand All @@ -43,12 +45,8 @@ node_repositories(
# Install our npm dependencies into @npm
yarn_install(
name = "npm",
data = [
# Needed because this tsconfig file is used in the "postinstall" script.
"//:angular-metadata.tsconfig.json",
],
package_json = "//src:package.json",
yarn_lock = "//src:yarn.lock",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)

# Install all bazel dependencies of our npm packages
Expand Down
30 changes: 24 additions & 6 deletions integration/bazel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,32 @@
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"@angular/animations": "file:../../dist/packages-dist/animations",
"@angular/common": "file:../../dist/packages-dist/common",
"@angular/core": "file:../../dist/packages-dist/core",
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
"@angular/router": "file:../../dist/packages-dist/router",
"reflect-metadata": "0.1.12",
"rxjs": "6.4.0",
"tslib": "1.9.3",
"zone.js": "0.9.1"
},
"devDependencies": {
"@bazel/bazel": "file:../../node_modules/@bazel/bazel"
"@angular/bazel": "file:../../dist/packages-dist/bazel",
"@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"@bazel/bazel": "file:../../node_modules/@bazel/bazel",
"@bazel/karma": "0.30.1",
"@bazel/typescript": "0.30.1",
"@types/jasmine": "2.8.8",
"@types/source-map": "0.5.1",
"protractor": "5.1.2",
"typescript": "3.4.2"
},
"scripts": {
"//": "deps are listed in src/package.json which is used by yarn_install",
"//": "this package.json file is only here so that `yarn test` can be called by /integration/run_tests.sh",
"pretest": "./pretest.sh",
"test": "bazel build ... --noshow_progress && bazel test ..."
"test": "bazel build ... --noshow_progress && bazel test ...",
"postinstall": "ngc -p ./angular-metadata.tsconfig.json",
"//": "TODO(gregmagolan): figure out how to keep dependencies here up to date with the root package.json"
}
}
}
20 changes: 0 additions & 20 deletions integration/bazel/pretest.sh

This file was deleted.

33 changes: 0 additions & 33 deletions integration/bazel/src/package.json

This file was deleted.

Loading

0 comments on commit b358736

Please sign in to comment.