Skip to content

Commit

Permalink
feat(builtin): export version to npm/yarn install
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Wiles authored and alexeagle committed Apr 7, 2020
1 parent 9d91154 commit 011278e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions internal/npm_install/npm_install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 22 additions & 0 deletions internal/version.bzl
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion scripts/on-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 011278e

Please sign in to comment.