Skip to content

Commit 011278e

Browse files
Fabian Wilesalexeagle
authored andcommitted
feat(builtin): export version to npm/yarn install
1 parent 9d91154 commit 011278e

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

index.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Users should not load files under "/internal"
1818
"""
1919

20+
load("//internal:version.bzl", "VERSION")
2021
load("//internal/common:check_bazel_version.bzl", _check_bazel_version = "check_bazel_version")
2122
load("//internal/common:check_version.bzl", "check_version")
2223
load("//internal/common:copy_to_bin.bzl", _copy_to_bin = "copy_to_bin")

internal/npm_install/npm_install.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ as the package manager.
2121
See discussion in the README.
2222
"""
2323

24+
load("//internal:version.bzl", "VERSION")
2425
load("//internal/common:check_bazel_version.bzl", "check_bazel_version")
2526
load("//internal/common:os_name.bzl", "is_windows_os")
2627
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}
275276
env_key = "BAZEL_NPM_INSTALL"
276277
if env_key not in env.keys():
277278
env[env_key] = "1"
279+
env["build_bazel_rules_nodejs_version"] = VERSION
278280

279281
repository_ctx.report_progress("Running npm install on %s" % repository_ctx.attr.package_json)
280282
result = repository_ctx.execute(
@@ -412,6 +414,7 @@ cd /D "{root}" && "{yarn}" {yarn_args}
412414
env_key = "BAZEL_YARN_INSTALL"
413415
if env_key not in env.keys():
414416
env[env_key] = "1"
417+
env["build_bazel_rules_nodejs_version"] = VERSION
415418

416419
repository_ctx.report_progress("Running yarn install on %s" % repository_ctx.attr.package_json)
417420
result = repository_ctx.execute(

internal/version.bzl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2017 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Version for the rules_nodejs repository
16+
"""
17+
18+
# This version is synced with the version in package.json.
19+
# It will be automatically synced via the npm "version" script
20+
# that is run when running `npm version` during the release
21+
# process. See `Releasing` section in README.md.
22+
VERSION = "1.0.0"

scripts/on-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
const shell = require('shelljs');
55
const version = require('../package.json').version;
66

7-
shell.sed('-i', /^VERSION \= \"[0-9\.]*\"/, `VERSION = "${version}"`, 'index.bzl');
7+
shell.sed('-i', /^VERSION \= \"[0-9\.]*\"/, `VERSION = "${version}"`, 'internal/version.bzl');

0 commit comments

Comments
 (0)