From 011278e58fb7cacc94e606a0db2bd5db5b56494d Mon Sep 17 00:00:00 2001 From: Fabian Wiles Date: Tue, 31 Dec 2019 09:32:58 +1300 Subject: [PATCH] feat(builtin): export version to npm/yarn install --- index.bzl | 1 + internal/npm_install/npm_install.bzl | 3 +++ internal/version.bzl | 22 ++++++++++++++++++++++ scripts/on-version.js | 2 +- 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 internal/version.bzl diff --git a/index.bzl b/index.bzl index 3138de7aec..47b2ff1bed 100644 --- a/index.bzl +++ b/index.bzl @@ -17,6 +17,7 @@ Users should not load files under "/internal" """ +load("//internal:version.bzl", "VERSION") load("//internal/common:check_bazel_version.bzl", _check_bazel_version = "check_bazel_version") load("//internal/common:check_version.bzl", "check_version") load("//internal/common:copy_to_bin.bzl", _copy_to_bin = "copy_to_bin") diff --git a/internal/npm_install/npm_install.bzl b/internal/npm_install/npm_install.bzl index 4f0e9191f4..7f7bd4dae9 100644 --- a/internal/npm_install/npm_install.bzl +++ b/internal/npm_install/npm_install.bzl @@ -21,6 +21,7 @@ as the package manager. See discussion in the README. """ +load("//internal:version.bzl", "VERSION") load("//internal/common:check_bazel_version.bzl", "check_bazel_version") load("//internal/common:os_name.bzl", "is_windows_os") load("//internal/node:node_labels.bzl", "get_node_label", "get_npm_label", "get_yarn_label") @@ -275,6 +276,7 @@ cd /D "{root}" && "{npm}" {npm_args} env_key = "BAZEL_NPM_INSTALL" if env_key not in env.keys(): env[env_key] = "1" + env["build_bazel_rules_nodejs_version"] = VERSION repository_ctx.report_progress("Running npm install on %s" % repository_ctx.attr.package_json) result = repository_ctx.execute( @@ -412,6 +414,7 @@ cd /D "{root}" && "{yarn}" {yarn_args} env_key = "BAZEL_YARN_INSTALL" if env_key not in env.keys(): env[env_key] = "1" + env["build_bazel_rules_nodejs_version"] = VERSION repository_ctx.report_progress("Running yarn install on %s" % repository_ctx.attr.package_json) result = repository_ctx.execute( diff --git a/internal/version.bzl b/internal/version.bzl new file mode 100644 index 0000000000..4557d77135 --- /dev/null +++ b/internal/version.bzl @@ -0,0 +1,22 @@ +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Version for the rules_nodejs repository +""" + +# This version is synced with the version in package.json. +# It will be automatically synced via the npm "version" script +# that is run when running `npm version` during the release +# process. See `Releasing` section in README.md. +VERSION = "1.0.0" diff --git a/scripts/on-version.js b/scripts/on-version.js index c3375a0d8c..f859bcb327 100644 --- a/scripts/on-version.js +++ b/scripts/on-version.js @@ -4,4 +4,4 @@ const shell = require('shelljs'); const version = require('../package.json').version; -shell.sed('-i', /^VERSION \= \"[0-9\.]*\"/, `VERSION = "${version}"`, 'index.bzl'); +shell.sed('-i', /^VERSION \= \"[0-9\.]*\"/, `VERSION = "${version}"`, 'internal/version.bzl');