From f75d5f2b2dd33dfd4ee3a5352e5469996be52a54 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 4 Feb 2020 12:31:49 -0800 Subject: [PATCH] chore: support Bazelisk and stop using @bazel/bazel This switches the behavior of @bazel/create to stop making users download Bazel. In a future cleanup I'll remove the mirror_bazel.sh and packages/bazel*.. (It's possible we still want those to publish Bazel 2.1 before we deprecate the package) --- .bazelversion | 1 + .circleci/config.yml | 4 +- BUILD.bazel | 1 + WORKSPACE | 20 +--------- docs/install.md | 9 +++-- examples/BUILD.bazel | 2 + examples/angular/README.md | 2 +- examples/angular/WORKSPACE | 15 +------- examples/angular/package.json | 3 +- examples/angular/yarn.lock | 37 ++++--------------- examples/angular_bazel_architect/package.json | 2 +- examples/angular_bazel_architect/yarn.lock | 34 ++--------------- examples/angular_view_engine/WORKSPACE | 15 +------- examples/angular_view_engine/package.json | 3 +- examples/angular_view_engine/yarn.lock | 37 ++++--------------- examples/nestjs/package.json | 2 +- examples/nestjs/yarn.lock | 34 ++--------------- examples/react_webpack/package.json | 2 +- examples/react_webpack/yarn.lock | 34 ++--------------- index.bzl | 4 +- internal/BUILD.bazel | 6 +-- ...package_json.js => check_bazel_version.js} | 16 ++++---- internal/common/check_bazel_version.bzl | 12 +++--- package.json | 2 +- packages/create/BUILD.bazel | 7 ++++ packages/create/README.md | 2 + packages/create/index.js | 9 +++-- packages/create/test.js | 5 ++- .../src/internal/ts_repositories.bzl | 5 +-- yarn.lock | 34 ++--------------- 30 files changed, 93 insertions(+), 266 deletions(-) create mode 100644 .bazelversion rename internal/{check_package_json.js => check_bazel_version.js} (67%) diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 0000000000..227cea2156 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +2.0.0 diff --git a/.circleci/config.yml b/.circleci/config.yml index 2c5a45aef6..3ba22ed6ac 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -58,8 +58,8 @@ var_6: &init_bazel run: name: Initializing Bazel command: | - # Symlink fetched bazel to /usr/local/bin/bazel - pathToBazel=$(ls $(realpath ./node_modules/@bazel/bazel-linux_x64)/bazel-*) + # Symlink fetched bazelisk to /usr/local/bin/bazel + pathToBazel=$(realpath ./node_modules/@bazel/bazelisk/bazelisk-linux_amd64) sudo ln -fs $pathToBazel /usr/local/bin/bazel echo "Bazel version:" bazel version diff --git a/BUILD.bazel b/BUILD.bazel index 44dc310538..eb94019cad 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -30,6 +30,7 @@ codeowners( # END-INTERNAL exports_files([ + ".bazelversion", "common.bazelrc", "tsconfig.json", "package.json", diff --git a/WORKSPACE b/WORKSPACE index be95dcab8a..0eec2953a6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -24,25 +24,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") load("//:index.bzl", "BAZEL_VERSION") # -# Check that build is using a minimum compatible bazel version -# - -load("//internal/common:check_bazel_version.bzl", "check_bazel_version") - -# 0.18.0: support for .bazelignore -# 0.23.0: required fix for pkg_tar strip_prefix -# 0.26.0: managed_directories feature added -check_bazel_version( - message = """ -You no longer need to install Bazel on your machine. -rules_nodejs has a dependency on the @bazel/bazel package which supplies it. -Try running `yarn bazel` instead. -""", - minimum_bazel_version = "0.26.0", -) - -# -# Nested package worksapces required to build packages & reference rules +# Nested package workspaces required to build packages & reference rules # load("//packages:index.bzl", "NESTED_PACKAGES") diff --git a/docs/install.md b/docs/install.md index 5578479e39..228cf08bf7 100644 --- a/docs/install.md +++ b/docs/install.md @@ -7,16 +7,17 @@ stylesheet: docs ## Custom installation First, you need Bazel. -We recommend fetching it from npm to keep your frontend workflow similar. +We recommend using Bazelisk, which is a version-selection wrapper, similar to +the `nvm` tool managing your version of Node. This is available on npm. ```sh -$ yarn add -D @bazel/bazel @bazel/ibazel +$ yarn add -D @bazel/bazelisk @bazel/ibazel # or -$ npm install --save-dev @bazel/bazel @bazel/ibazel +$ npm install --save-dev @bazel/bazelisk @bazel/ibazel ``` > You could install a current bazel distribution, following the [bazel instructions]. -> This has the advantage of setting up Bazel command-line completion. +> If you use Bazelisk, see [this workaround](https://github.com/bazelbuild/bazelisk/issues/29#issuecomment-478062147) to get working command-line completion. Next, create a `WORKSPACE` file in your project root (or edit the existing one) containing: diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 082596ef92..d922fbdc9b 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -18,6 +18,7 @@ example_integration_test( name = "examples_angular", timeout = "long", npm_packages = { + "//packages/hide-bazel-files:npm_package": "@bazel/hide-bazel-files", "//packages/karma:npm_package": "@bazel/karma", "//packages/protractor:npm_package": "@bazel/protractor", "//packages/rollup:npm_package": "@bazel/rollup", @@ -41,6 +42,7 @@ example_integration_test( name = "examples_angular_view_engine", timeout = "long", npm_packages = { + "//packages/hide-bazel-files:npm_package": "@bazel/hide-bazel-files", "//packages/karma:npm_package": "@bazel/karma", "//packages/protractor:npm_package": "@bazel/protractor", "//packages/rollup:npm_package": "@bazel/rollup", diff --git a/examples/angular/README.md b/examples/angular/README.md index 727e06ccdc..8a8c70de88 100644 --- a/examples/angular/README.md +++ b/examples/angular/README.md @@ -36,7 +36,7 @@ You simply run `yarn` commands shown below, and don't need to install Bazel or a If you're a full-stack developer, you might be using Bazel for your backend already. In this case, you should install Bazel following instructions at http://bazel.build. Also install `ibazel`, which is a watch mode for Bazel not included in the standard distribution. See https://github.com/bazelbuild/bazel-watcher#installation. -The `WORKSPACE` file has a `check_bazel_version` call which will print an error if your Bazel version is not in the supported range. +You should have a `.bazelversion` file which will ensure Bazel prints an error if your Bazel version is not in the supported range. You simply run `bazel` commands shown below, and don't need to install NodeJS, yarn, or any other dependencies. ## Development diff --git a/examples/angular/WORKSPACE b/examples/angular/WORKSPACE index 65c5053b17..d204fc710d 100644 --- a/examples/angular/WORKSPACE +++ b/examples/angular/WORKSPACE @@ -33,20 +33,7 @@ http_archive( ) # Check the bazel version and download npm dependencies -load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version", "yarn_install") - -# Bazel version must be at least the following version because: -# - 0.27.0 Adds managed directories support -check_bazel_version( - message = """ -You no longer need to install Bazel on your machine. -Angular has a dependency on the @bazel/bazel package which supplies it. -Try running `yarn bazel` instead. - (If you did run that, check that you've got a fresh `yarn install`) - -""", - minimum_bazel_version = "0.27.0", -) +load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install") # Setup the Node.js toolchain & install our npm dependencies into @npm yarn_install( diff --git a/examples/angular/package.json b/examples/angular/package.json index 3cafba0499..60289513a9 100644 --- a/examples/angular/package.json +++ b/examples/angular/package.json @@ -32,9 +32,10 @@ "@babel/cli": "^7.6.0", "@babel/core": "^7.6.0", "@babel/preset-env": "^7.6.0", - "@bazel/bazel": "^2.0.0", + "@bazel/bazelisk": "^1.3.0", "@bazel/benchmark-runner": "^0.1.0", "@bazel/buildifier": "^0.29.0", + "@bazel/hide-bazel-files": "^1.2.4", "@bazel/ibazel": "^0.11.1", "@bazel/karma": "^1.2.4", "@bazel/protractor": "^1.2.4", diff --git a/examples/angular/yarn.lock b/examples/angular/yarn.lock index 35bb7c3f6b..2e87343bb6 100644 --- a/examples/angular/yarn.lock +++ b/examples/angular/yarn.lock @@ -785,31 +785,10 @@ lodash "^4.17.13" to-fast-properties "^2.0.0" -"@bazel/bazel-darwin_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-2.0.0.tgz#bd678069216dd470c6816a22c405f21e7f048038" - integrity sha512-I/pP+B+2xfY0g+OEpEcVnk8rizuC761pAzBOQjP3b+gz3AzeRgm05CpcSY7tfPIppMSYoy3uTZJ1XlwgUg7IQQ== - -"@bazel/bazel-linux_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-2.0.0.tgz#2c76e3301e9178a90ec3ad00649e89b953eda0b7" - integrity sha512-iOr45G+511IbP7e+ISriG97WpfCAVXekTrTgL5mGg3NDBFCVNs350VquHAvmlXAoP5+IEug2pCOlkdEl4bLl8g== - -"@bazel/bazel-win32_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-2.0.0.tgz#f12ac0738d2eac0fd255f099776194807cedfe50" - integrity sha512-5qs2qoa/paG/YYEM0yvrwuJIShoPVK2FX+Oz9jEWAQJsmU4drHA9Aq+gbBOirEFLmvYhleZ9XORCwu/5uAo8vA== - -"@bazel/bazel@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel/-/bazel-2.0.0.tgz#feb8cf5a40ea6437ef69cac2a92072118b11c230" - integrity sha512-KQbv5dHNSfutbhXCc3KVMuBXPpUh6Af/hT9IRIaMTuiB6Nq2gEW9Z3aNqncopdZqV848V/qYxnqPnQ+S37fMyQ== - dependencies: - "@bazel/hide-bazel-files" latest - optionalDependencies: - "@bazel/bazel-darwin_x64" "2.0.0" - "@bazel/bazel-linux_x64" "2.0.0" - "@bazel/bazel-win32_x64" "2.0.0" +"@bazel/bazelisk@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.3.0.tgz#dc312dd30ad01e9af86e53b40795ab6e545fa55b" + integrity sha512-73H1nq3572tTf+dhDT86aWQN+LCyfxrh05jabqPXp6cpR8soxte3gS5oUqkN36fUe+J2HzNiV4CXZTz4Xytd3Q== "@bazel/benchmark-runner@^0.1.0": version "0.1.0" @@ -845,10 +824,10 @@ "@bazel/buildifier-linux_x64" "0.29.0" "@bazel/buildifier-win32_x64" "0.29.0" -"@bazel/hide-bazel-files@latest": - version "0.32.2" - resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-0.32.2.tgz#a482855eafbccb56b1fce0d92ff922c2c6e0a90c" - integrity sha512-585XY53mhMZaCjEQJ+aDqkmydWZbuXsKrZsSpoW9YeAVEH0poQY3YhdyCPmMVBo7/l1mkrqpFuOK5BpECfwdtA== +"@bazel/hide-bazel-files@^1.2.4": + version "1.2.4" + resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-1.2.4.tgz#fe00f2bbceb8e1a17bedde7616bef4810849c7f5" + integrity sha512-KZX4MkJOMtZT1DwFmjCWJNCUKcwbYBrv3Q++peoWkzJPcHGbt5nLFjt8Gzagi2GY7GRqp8WAut0E+eOGdhvkEg== "@bazel/ibazel@0.3.1": version "0.3.1" diff --git a/examples/angular_bazel_architect/package.json b/examples/angular_bazel_architect/package.json index 5eeb49f4ad..a84c464784 100644 --- a/examples/angular_bazel_architect/package.json +++ b/examples/angular_bazel_architect/package.json @@ -32,7 +32,7 @@ "@angular/cli": "9.0.0-rc.10", "@angular/compiler-cli": "9.0.0-rc.10", "@angular/language-service": "9.0.0-rc.11", - "@bazel/bazel": "^2.0.0", + "@bazel/bazelisk": "^1.3.0", "@bazel/buildifier": "^0.29.0", "@bazel/ibazel": "^0.11.1", "@types/jasmine": "~3.3.8", diff --git a/examples/angular_bazel_architect/yarn.lock b/examples/angular_bazel_architect/yarn.lock index 4a617a94cf..f46de21eb8 100644 --- a/examples/angular_bazel_architect/yarn.lock +++ b/examples/angular_bazel_architect/yarn.lock @@ -1020,31 +1020,10 @@ lodash "^4.17.13" to-fast-properties "^2.0.0" -"@bazel/bazel-darwin_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-2.0.0.tgz#bd678069216dd470c6816a22c405f21e7f048038" - integrity sha512-I/pP+B+2xfY0g+OEpEcVnk8rizuC761pAzBOQjP3b+gz3AzeRgm05CpcSY7tfPIppMSYoy3uTZJ1XlwgUg7IQQ== - -"@bazel/bazel-linux_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-2.0.0.tgz#2c76e3301e9178a90ec3ad00649e89b953eda0b7" - integrity sha512-iOr45G+511IbP7e+ISriG97WpfCAVXekTrTgL5mGg3NDBFCVNs350VquHAvmlXAoP5+IEug2pCOlkdEl4bLl8g== - -"@bazel/bazel-win32_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-2.0.0.tgz#f12ac0738d2eac0fd255f099776194807cedfe50" - integrity sha512-5qs2qoa/paG/YYEM0yvrwuJIShoPVK2FX+Oz9jEWAQJsmU4drHA9Aq+gbBOirEFLmvYhleZ9XORCwu/5uAo8vA== - -"@bazel/bazel@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel/-/bazel-2.0.0.tgz#feb8cf5a40ea6437ef69cac2a92072118b11c230" - integrity sha512-KQbv5dHNSfutbhXCc3KVMuBXPpUh6Af/hT9IRIaMTuiB6Nq2gEW9Z3aNqncopdZqV848V/qYxnqPnQ+S37fMyQ== - dependencies: - "@bazel/hide-bazel-files" latest - optionalDependencies: - "@bazel/bazel-darwin_x64" "2.0.0" - "@bazel/bazel-linux_x64" "2.0.0" - "@bazel/bazel-win32_x64" "2.0.0" +"@bazel/bazelisk@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.3.0.tgz#dc312dd30ad01e9af86e53b40795ab6e545fa55b" + integrity sha512-73H1nq3572tTf+dhDT86aWQN+LCyfxrh05jabqPXp6cpR8soxte3gS5oUqkN36fUe+J2HzNiV4CXZTz4Xytd3Q== "@bazel/buildifier-darwin_x64@0.29.0": version "0.29.0" @@ -1070,11 +1049,6 @@ "@bazel/buildifier-linux_x64" "0.29.0" "@bazel/buildifier-win32_x64" "0.29.0" -"@bazel/hide-bazel-files@latest": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-1.0.0.tgz#779070dcb5ae121ff6c72d73bf3fb7bf68285d75" - integrity sha512-dfw2W7xDUPlRMcDMVO8gDkX9Xb7Thy3sP4PDODv+eiHOvwIi116X/wwy7mQUZISkJdEJ1zWy9ydpzvfetpYh4w== - "@bazel/ibazel@^0.11.1": version "0.11.1" resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.11.1.tgz#c07ceaded388f1e39d6aa732953e0dd04f3dbdf0" diff --git a/examples/angular_view_engine/WORKSPACE b/examples/angular_view_engine/WORKSPACE index bc07670581..6b9916c64f 100644 --- a/examples/angular_view_engine/WORKSPACE +++ b/examples/angular_view_engine/WORKSPACE @@ -32,20 +32,7 @@ http_archive( ) # Check the bazel version and download npm dependencies -load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version", "yarn_install") - -# Bazel version must be at least the following version because: -# - 0.27.0 Adds managed directories support -check_bazel_version( - message = """ -You no longer need to install Bazel on your machine. -Angular has a dependency on the @bazel/bazel package which supplies it. -Try running `yarn bazel` instead. - (If you did run that, check that you've got a fresh `yarn install`) - -""", - minimum_bazel_version = "0.27.0", -) +load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install") # Setup the Node.js toolchain & install our npm dependencies into @npm yarn_install( diff --git a/examples/angular_view_engine/package.json b/examples/angular_view_engine/package.json index bc28d1b584..43b5a0d843 100644 --- a/examples/angular_view_engine/package.json +++ b/examples/angular_view_engine/package.json @@ -32,9 +32,10 @@ "@babel/cli": "^7.6.0", "@babel/core": "^7.6.0", "@babel/preset-env": "^7.6.0", - "@bazel/bazel": "^2.0.0", + "@bazel/bazelisk": "^1.3.0", "@bazel/benchmark-runner": "^0.1.0", "@bazel/buildifier": "^0.29.0", + "@bazel/hide-bazel-files": "^1.2.4", "@bazel/ibazel": "^0.11.1", "@bazel/karma": "^1.2.4", "@bazel/protractor": "^1.2.4", diff --git a/examples/angular_view_engine/yarn.lock b/examples/angular_view_engine/yarn.lock index 7a475f2c59..2ffab6f454 100644 --- a/examples/angular_view_engine/yarn.lock +++ b/examples/angular_view_engine/yarn.lock @@ -803,31 +803,10 @@ lodash "^4.17.13" to-fast-properties "^2.0.0" -"@bazel/bazel-darwin_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-2.0.0.tgz#bd678069216dd470c6816a22c405f21e7f048038" - integrity sha512-I/pP+B+2xfY0g+OEpEcVnk8rizuC761pAzBOQjP3b+gz3AzeRgm05CpcSY7tfPIppMSYoy3uTZJ1XlwgUg7IQQ== - -"@bazel/bazel-linux_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-2.0.0.tgz#2c76e3301e9178a90ec3ad00649e89b953eda0b7" - integrity sha512-iOr45G+511IbP7e+ISriG97WpfCAVXekTrTgL5mGg3NDBFCVNs350VquHAvmlXAoP5+IEug2pCOlkdEl4bLl8g== - -"@bazel/bazel-win32_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-2.0.0.tgz#f12ac0738d2eac0fd255f099776194807cedfe50" - integrity sha512-5qs2qoa/paG/YYEM0yvrwuJIShoPVK2FX+Oz9jEWAQJsmU4drHA9Aq+gbBOirEFLmvYhleZ9XORCwu/5uAo8vA== - -"@bazel/bazel@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel/-/bazel-2.0.0.tgz#feb8cf5a40ea6437ef69cac2a92072118b11c230" - integrity sha512-KQbv5dHNSfutbhXCc3KVMuBXPpUh6Af/hT9IRIaMTuiB6Nq2gEW9Z3aNqncopdZqV848V/qYxnqPnQ+S37fMyQ== - dependencies: - "@bazel/hide-bazel-files" latest - optionalDependencies: - "@bazel/bazel-darwin_x64" "2.0.0" - "@bazel/bazel-linux_x64" "2.0.0" - "@bazel/bazel-win32_x64" "2.0.0" +"@bazel/bazelisk@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.3.0.tgz#dc312dd30ad01e9af86e53b40795ab6e545fa55b" + integrity sha512-73H1nq3572tTf+dhDT86aWQN+LCyfxrh05jabqPXp6cpR8soxte3gS5oUqkN36fUe+J2HzNiV4CXZTz4Xytd3Q== "@bazel/benchmark-runner@^0.1.0": version "0.1.0" @@ -863,10 +842,10 @@ "@bazel/buildifier-linux_x64" "0.29.0" "@bazel/buildifier-win32_x64" "0.29.0" -"@bazel/hide-bazel-files@latest": - version "0.32.2" - resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-0.32.2.tgz#a482855eafbccb56b1fce0d92ff922c2c6e0a90c" - integrity sha512-585XY53mhMZaCjEQJ+aDqkmydWZbuXsKrZsSpoW9YeAVEH0poQY3YhdyCPmMVBo7/l1mkrqpFuOK5BpECfwdtA== +"@bazel/hide-bazel-files@^1.2.4": + version "1.2.4" + resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-1.2.4.tgz#fe00f2bbceb8e1a17bedde7616bef4810849c7f5" + integrity sha512-KZX4MkJOMtZT1DwFmjCWJNCUKcwbYBrv3Q++peoWkzJPcHGbt5nLFjt8Gzagi2GY7GRqp8WAut0E+eOGdhvkEg== "@bazel/ibazel@0.3.1": version "0.3.1" diff --git a/examples/nestjs/package.json b/examples/nestjs/package.json index d9b15bb1a3..e79079e8f2 100644 --- a/examples/nestjs/package.json +++ b/examples/nestjs/package.json @@ -1,7 +1,7 @@ { "private": true, "dependencies": { - "@bazel/bazel": "^2.0.0", + "@bazel/bazelisk": "^1.3.0", "@bazel/ibazel": "^0.11.1", "@bazel/jasmine": "^1.2.4", "@nestjs/common": "6.5.2", diff --git a/examples/nestjs/yarn.lock b/examples/nestjs/yarn.lock index 10a6b7def2..698db5cb03 100644 --- a/examples/nestjs/yarn.lock +++ b/examples/nestjs/yarn.lock @@ -2,36 +2,10 @@ # yarn lockfile v1 -"@bazel/bazel-darwin_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-2.0.0.tgz#bd678069216dd470c6816a22c405f21e7f048038" - integrity sha512-I/pP+B+2xfY0g+OEpEcVnk8rizuC761pAzBOQjP3b+gz3AzeRgm05CpcSY7tfPIppMSYoy3uTZJ1XlwgUg7IQQ== - -"@bazel/bazel-linux_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-2.0.0.tgz#2c76e3301e9178a90ec3ad00649e89b953eda0b7" - integrity sha512-iOr45G+511IbP7e+ISriG97WpfCAVXekTrTgL5mGg3NDBFCVNs350VquHAvmlXAoP5+IEug2pCOlkdEl4bLl8g== - -"@bazel/bazel-win32_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-2.0.0.tgz#f12ac0738d2eac0fd255f099776194807cedfe50" - integrity sha512-5qs2qoa/paG/YYEM0yvrwuJIShoPVK2FX+Oz9jEWAQJsmU4drHA9Aq+gbBOirEFLmvYhleZ9XORCwu/5uAo8vA== - -"@bazel/bazel@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel/-/bazel-2.0.0.tgz#feb8cf5a40ea6437ef69cac2a92072118b11c230" - integrity sha512-KQbv5dHNSfutbhXCc3KVMuBXPpUh6Af/hT9IRIaMTuiB6Nq2gEW9Z3aNqncopdZqV848V/qYxnqPnQ+S37fMyQ== - dependencies: - "@bazel/hide-bazel-files" latest - optionalDependencies: - "@bazel/bazel-darwin_x64" "2.0.0" - "@bazel/bazel-linux_x64" "2.0.0" - "@bazel/bazel-win32_x64" "2.0.0" - -"@bazel/hide-bazel-files@latest": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-1.0.1.tgz#bfba5c73f307cd69c25411084023f60cdd89ef01" - integrity sha512-3unoDYZIGxtePTa/bhsWZ0pxtI/G9LYr41Kkb1ZpSaSz27ZDvj6Aysbc0u9TNGTZhqkcr/w66OC9pvmeys4YnQ== +"@bazel/bazelisk@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.3.0.tgz#dc312dd30ad01e9af86e53b40795ab6e545fa55b" + integrity sha512-73H1nq3572tTf+dhDT86aWQN+LCyfxrh05jabqPXp6cpR8soxte3gS5oUqkN36fUe+J2HzNiV4CXZTz4Xytd3Q== "@bazel/ibazel@^0.11.1": version "0.11.1" diff --git a/examples/react_webpack/package.json b/examples/react_webpack/package.json index 622d2d7c99..d0faeba245 100644 --- a/examples/react_webpack/package.json +++ b/examples/react_webpack/package.json @@ -1,7 +1,7 @@ { "private": true, "devDependencies": { - "@bazel/bazel": "^2.0.0", + "@bazel/bazelisk": "^1.3.0", "@bazel/buildifier": "^0.29.0", "@bazel/ibazel": "^0.11.1", "@types/react": "^16.9.5", diff --git a/examples/react_webpack/yarn.lock b/examples/react_webpack/yarn.lock index e374222ee4..b38c152976 100644 --- a/examples/react_webpack/yarn.lock +++ b/examples/react_webpack/yarn.lock @@ -2,31 +2,10 @@ # yarn lockfile v1 -"@bazel/bazel-darwin_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-2.0.0.tgz#bd678069216dd470c6816a22c405f21e7f048038" - integrity sha512-I/pP+B+2xfY0g+OEpEcVnk8rizuC761pAzBOQjP3b+gz3AzeRgm05CpcSY7tfPIppMSYoy3uTZJ1XlwgUg7IQQ== - -"@bazel/bazel-linux_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-2.0.0.tgz#2c76e3301e9178a90ec3ad00649e89b953eda0b7" - integrity sha512-iOr45G+511IbP7e+ISriG97WpfCAVXekTrTgL5mGg3NDBFCVNs350VquHAvmlXAoP5+IEug2pCOlkdEl4bLl8g== - -"@bazel/bazel-win32_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-2.0.0.tgz#f12ac0738d2eac0fd255f099776194807cedfe50" - integrity sha512-5qs2qoa/paG/YYEM0yvrwuJIShoPVK2FX+Oz9jEWAQJsmU4drHA9Aq+gbBOirEFLmvYhleZ9XORCwu/5uAo8vA== - -"@bazel/bazel@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel/-/bazel-2.0.0.tgz#feb8cf5a40ea6437ef69cac2a92072118b11c230" - integrity sha512-KQbv5dHNSfutbhXCc3KVMuBXPpUh6Af/hT9IRIaMTuiB6Nq2gEW9Z3aNqncopdZqV848V/qYxnqPnQ+S37fMyQ== - dependencies: - "@bazel/hide-bazel-files" latest - optionalDependencies: - "@bazel/bazel-darwin_x64" "2.0.0" - "@bazel/bazel-linux_x64" "2.0.0" - "@bazel/bazel-win32_x64" "2.0.0" +"@bazel/bazelisk@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.3.0.tgz#dc312dd30ad01e9af86e53b40795ab6e545fa55b" + integrity sha512-73H1nq3572tTf+dhDT86aWQN+LCyfxrh05jabqPXp6cpR8soxte3gS5oUqkN36fUe+J2HzNiV4CXZTz4Xytd3Q== "@bazel/buildifier-darwin_x64@0.29.0": version "0.29.0" @@ -52,11 +31,6 @@ "@bazel/buildifier-linux_x64" "0.29.0" "@bazel/buildifier-win32_x64" "0.29.0" -"@bazel/hide-bazel-files@latest": - version "0.39.1" - resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-0.39.1.tgz#90b14d5031a903e78e1abfe740662c92292cc1c8" - integrity sha512-nmILMfF8wD3hR3+r0MUCqPahgBYszLKFBcrbnmYthG6Oujgy1NpYMjeWj7Hjt3pJMkT1MgQP/VipLu2gQyMc0Q== - "@bazel/ibazel@^0.11.1": version "0.11.1" resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.11.1.tgz#c07ceaded388f1e39d6aa732953e0dd04f3dbdf0" diff --git a/index.bzl b/index.bzl index 6572dced3b..c1ffe3549d 100644 --- a/index.bzl +++ b/index.bzl @@ -93,8 +93,8 @@ VERSION = "1.2.4" # against. It is also the version used when testing nested workspaces with # bazel_integration_test. In the future, after an LTS version of Bazel is released # we will test against multiple versions. -# This version should be updated together with the version of the @bazel/bazel -# package in package.json. This is asserted in //internal:package_json_test. +# This version should be updated together with the version of the Bazel +# in .bazelversion. This is asserted in //internal:bazel_version_test. BAZEL_VERSION = "2.0.0" def check_rules_nodejs_version(minimum_version_string): diff --git a/internal/BUILD.bazel b/internal/BUILD.bazel index 59d74cbdd4..db98434673 100644 --- a/internal/BUILD.bazel +++ b/internal/BUILD.bazel @@ -24,9 +24,9 @@ filegroup( ) nodejs_test( - name = "package_json_test", - data = ["//:package.json"], - entry_point = ":check_package_json.js", + name = "bazel_version_test", + data = ["//:.bazelversion"], + entry_point = ":check_bazel_version.js", templated_args = [BAZEL_VERSION], ) diff --git a/internal/check_package_json.js b/internal/check_bazel_version.js similarity index 67% rename from internal/check_package_json.js rename to internal/check_bazel_version.js index c6df2255f2..944d377054 100644 --- a/internal/check_package_json.js +++ b/internal/check_bazel_version.js @@ -20,14 +20,14 @@ const args = process.argv.slice(2); const BAZEL_VERSION = args[0]; -const packageJson = require('build_bazel_rules_nodejs/package.json'); +const version = + require('fs') + .readFileSync(require.resolve('build_bazel_rules_nodejs/.bazelversion'), 'utf-8') + .trim(); -// Test that the BAZEL_VERSION defined in //:index.bzl is in sync with the @bazel/bazel -// version in //:pacakge.json -if (packageJson['devDependencies']['@bazel/bazel'] !== `^${BAZEL_VERSION}`) { - console.error(`package.json @bazel/bazel '${ - packageJson['devDependencies'] - ['@bazel/bazel']}' does not match ^BAZEL_VERSION in //:index.bzl '^${ - BAZEL_VERSION}'`); +// Test that the BAZEL_VERSION defined in //:index.bzl is in sync with .bazelversion +if (version !== BAZEL_VERSION) { + console.error( + `.bazelversion '${version}' does not match BAZEL_VERSION in //:index.bzl '${BAZEL_VERSION}'`); process.exitCode = 1; } diff --git a/internal/common/check_bazel_version.bzl b/internal/common/check_bazel_version.bzl index 7e6cfd64e4..199ab4c810 100644 --- a/internal/common/check_bazel_version.bzl +++ b/internal/common/check_bazel_version.bzl @@ -29,14 +29,12 @@ def check_bazel_version(minimum_bazel_version, message = ""): """ Verify the users Bazel version is at least the given one. - This should be called from the `WORKSPACE` file so that the build fails as - early as possible. For example: + This can be used in rule implementations that depend on changes in Bazel, + to warn users about a mismatch between the rule and their installed Bazel + version. - ``` - # in WORKSPACE: - load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version") - check_bazel_version("0.26.0") - ``` + This should *not* be used in users WORKSPACE files. To locally pin your + Bazel version, just create the .bazelversion file in your workspace. Args: minimum_bazel_version: a string indicating the minimum version diff --git a/package.json b/package.json index 84e727a206..e5a06e4f76 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "@babel/cli": "^7.6.2", "@babel/core": "^7.6.2", "@babel/preset-env": "^7.6.2", - "@bazel/bazel": "^2.0.0", + "@bazel/bazelisk": "^1.3.0", "@bazel/buildifier": "^0.26.0", "@bazel/buildozer": "^0.29.0", "@bazel/hide-bazel-files": "file:./packages/hide-bazel-files", diff --git a/packages/create/BUILD.bazel b/packages/create/BUILD.bazel index 8c2d60cce6..67c1ba427d 100644 --- a/packages/create/BUILD.bazel +++ b/packages/create/BUILD.bazel @@ -8,6 +8,12 @@ copy_file( out = "common.bazelrc", ) +copy_file( + name = "copy_bazelversion", + src = "//:.bazelversion", + out = ".bazelversion", +) + pkg_npm( name = "npm_package", srcs = [ @@ -17,6 +23,7 @@ pkg_npm( ], deps = [ ":copy_bazelrc", + ":copy_bazelversion", ], ) diff --git a/packages/create/README.md b/packages/create/README.md index 558f120985..2434952443 100644 --- a/packages/create/README.md +++ b/packages/create/README.md @@ -3,6 +3,8 @@ This package allows users to have a very simple quickstart to get up and running with Bazel via npm or yarn. ```bash +$ npx @bazel/create +# or $ yarn create @bazel # or $ npm init @bazel diff --git a/packages/create/index.js b/packages/create/index.js index 61cb35a556..3c0c2c6135 100644 --- a/packages/create/index.js +++ b/packages/create/index.js @@ -98,7 +98,7 @@ function main(argv, error = console.error, log = console.log) { } const devDependencies = { - '@bazel/bazel': 'latest', + '@bazel/bazelisk': 'latest', '@bazel/ibazel': 'latest', '@bazel/buildifier': 'latest', }; @@ -184,8 +184,8 @@ ts_setup_workspace()`; private: true, devDependencies, scripts: { - 'build': 'bazel build //...', - 'test': 'bazel test //...', + 'build': 'bazelisk build //...', + 'test': 'bazelisk test //...', } }, null, 4)); @@ -197,6 +197,8 @@ node_modules`); try { const rc = require.resolve('./common.bazelrc'); write('.bazelrc', fs.readFileSync(rc)); + const version = require.resolve('./.bazelversion'); + write('.bazelversion', fs.readFileSync(version)); } catch (_) { // but running locally against sources, it's in the root of the repo two directories up if (fs.existsSync('../../common.bazelrc')) { @@ -204,6 +206,7 @@ node_modules`); } else { error('ERROR: missing common.bazelrc file, continuing with no bazel settings...'); } + write('.bazelversion', 'latest'); } log(`Successfully created new Bazel workspace at ${path.resolve(wkspDir)}`); diff --git a/packages/create/test.js b/packages/create/test.js index b2e151406d..4055d9c957 100644 --- a/packages/create/test.js +++ b/packages/create/test.js @@ -43,9 +43,12 @@ if (exitCode != 0) { fail('should exit 0 on success') } const projFiles = fs.readdirSync('some_project'); -if (!projFiles.indexOf('.bazelrc') < 0) { +if (projFiles.indexOf('.bazelrc') < 0) { fail('project should have .bazelrc'); } +if (projFiles.indexOf('.bazelversion') < 0) { + fail('project should have .bazelversion'); +} let wkspContent = read('some_project/WORKSPACE.bazel'); if (wkspContent.indexOf('npm_install(') < 0) { fail('should use npm by default'); diff --git a/packages/typescript/src/internal/ts_repositories.bzl b/packages/typescript/src/internal/ts_repositories.bzl index 82ab701e50..7c1519efbd 100644 --- a/packages/typescript/src/internal/ts_repositories.bzl +++ b/packages/typescript/src/internal/ts_repositories.bzl @@ -14,7 +14,7 @@ "Install toolchain dependencies" -load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version", "check_rules_nodejs_version") +load("@build_bazel_rules_nodejs//:index.bzl", "check_rules_nodejs_version") def ts_setup_workspace(): """This repository rule should be called from your WORKSPACE file. @@ -23,8 +23,5 @@ def ts_setup_workspace(): by the TypeScript rules. """ - # 0.18.0: support for .bazelignore - check_bazel_version("0.18.0") - # 0.16.8: ng_package fix for packaging binary files check_rules_nodejs_version("0.16.8") diff --git a/yarn.lock b/yarn.lock index 67b541cca3..59ac1c97f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -654,31 +654,10 @@ lodash "^4.17.13" to-fast-properties "^2.0.0" -"@bazel/bazel-darwin_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-2.0.0.tgz#bd678069216dd470c6816a22c405f21e7f048038" - integrity sha512-I/pP+B+2xfY0g+OEpEcVnk8rizuC761pAzBOQjP3b+gz3AzeRgm05CpcSY7tfPIppMSYoy3uTZJ1XlwgUg7IQQ== - -"@bazel/bazel-linux_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-2.0.0.tgz#2c76e3301e9178a90ec3ad00649e89b953eda0b7" - integrity sha512-iOr45G+511IbP7e+ISriG97WpfCAVXekTrTgL5mGg3NDBFCVNs350VquHAvmlXAoP5+IEug2pCOlkdEl4bLl8g== - -"@bazel/bazel-win32_x64@2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-2.0.0.tgz#f12ac0738d2eac0fd255f099776194807cedfe50" - integrity sha512-5qs2qoa/paG/YYEM0yvrwuJIShoPVK2FX+Oz9jEWAQJsmU4drHA9Aq+gbBOirEFLmvYhleZ9XORCwu/5uAo8vA== - -"@bazel/bazel@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@bazel/bazel/-/bazel-2.0.0.tgz#feb8cf5a40ea6437ef69cac2a92072118b11c230" - integrity sha512-KQbv5dHNSfutbhXCc3KVMuBXPpUh6Af/hT9IRIaMTuiB6Nq2gEW9Z3aNqncopdZqV848V/qYxnqPnQ+S37fMyQ== - dependencies: - "@bazel/hide-bazel-files" latest - optionalDependencies: - "@bazel/bazel-darwin_x64" "2.0.0" - "@bazel/bazel-linux_x64" "2.0.0" - "@bazel/bazel-win32_x64" "2.0.0" +"@bazel/bazelisk@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@bazel/bazelisk/-/bazelisk-1.3.0.tgz#dc312dd30ad01e9af86e53b40795ab6e545fa55b" + integrity sha512-73H1nq3572tTf+dhDT86aWQN+LCyfxrh05jabqPXp6cpR8soxte3gS5oUqkN36fUe+J2HzNiV4CXZTz4Xytd3Q== "@bazel/buildifier-darwin_x64@0.26.0": version "0.26.0" @@ -731,11 +710,6 @@ "@bazel/hide-bazel-files@file:./packages/hide-bazel-files": version "0.0.0-PLACEHOLDER" -"@bazel/hide-bazel-files@latest": - version "0.36.0" - resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-0.36.0.tgz#3fb7c7c5f579f46dd1efd1b3890f11351aa8e65c" - integrity sha512-RgJWR1rOgyU4smruUK3MFA06DKt3AFCcfi9L8u/h11EjOrfLJgnzBJIGDXvW2zzhgnEJ9RRafOUHKN6blDksGg== - "@bazel/ibazel@^0.10.3": version "0.10.3" resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.10.3.tgz#2e2b8a1d3e885946eac41db2b1aa6801fb319887"