Skip to content

Commit

Permalink
feat(jasmine): check pkg version to rules_nodejs
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 011278e commit 22bebbc
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 16 deletions.
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports_files([
"tsconfig.json",
"package.json",
"bootstrap.js",
"tools/npm_version_check.js",
])

bzl_library(
Expand All @@ -33,6 +34,7 @@ bzl_library(
"index.bzl",
"index.for_docs.bzl",
"providers.bzl",
"version.bzl",
],
visibility = ["//visibility:public"],
deps = [
Expand Down
8 changes: 1 addition & 7 deletions index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Users should not load files under "/internal"
"""

load("//internal:version.bzl", "VERSION")
load("//: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 Expand Up @@ -84,12 +84,6 @@ def yarn_install(**kwargs):
_node_repositories()
_yarn_install(**kwargs)

# 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.5.0"

# Currently used Bazel version. This version is what the rules here are tested
# against.
# This version should be updated together with the version of the Bazel
Expand Down
6 changes: 3 additions & 3 deletions internal/npm_install/npm_install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ as the package manager.
See discussion in the README.
"""

load("//internal:version.bzl", "VERSION")
load("//: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 @@ -276,7 +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
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 @@ -414,7 +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
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
11 changes: 10 additions & 1 deletion packages/jasmine/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ genrule(
visibility = ["//docs:__pkg__"],
)

genrule(
name = "npm_version_check",
srcs = ["//:tools/npm_version_check.js"],
outs = [":npm_version_check.js"],
cmd = "cp $< $@",
)

pkg_npm(
name = "npm_package",
srcs = [
Expand All @@ -38,7 +45,9 @@ pkg_npm(
vendor_external = [
"npm_bazel_jasmine",
],
deps = select({
deps = [
":npm_version_check",
] + select({
# FIXME: fix stardoc on Windows; @npm_bazel_jasmine//:index.md generation fails with:
# ERROR: D:/b/62unjjin/external/npm_bazel_jasmine/BUILD.bazel:34:1: Couldn't build file
# external/npm_bazel_jasmine/docs.raw: Generating proto for Starlark doc for docs failed (Exit 1)
Expand Down
3 changes: 3 additions & 0 deletions packages/jasmine/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"npm_bazel_jasmine": {
"rootPath": "."
}
},
"scripts": {
"postinstall": "node npm_version_check.js"
}
}
8 changes: 8 additions & 0 deletions packages/karma/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ genrule(
visibility = ["//docs:__pkg__"],
)

genrule(
name = "npm_version_check",
srcs = ["//:tools/npm_version_check.js"],
outs = [":npm_version_check.js"],
cmd = "cp $< $@",
)

pkg_npm(
name = "npm_package",
srcs = [
Expand All @@ -40,6 +47,7 @@ pkg_npm(
],
deps = [
"@npm_bazel_karma//:bazel_karma_lib",
":npm_version_check",
] + select({
# FIXME: fix stardoc on Windows; @npm_bazel_karma//:index.md generation fails with:
# ERROR: D:/b/62unjjin/external/npm_bazel_karma/BUILD.bazel:65:1: Couldn't build file
Expand Down
3 changes: 3 additions & 0 deletions packages/karma/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
"npm_bazel_karma": {
"rootPath": "."
}
},
"scripts": {
"postinstall": "node npm_version_check.js"
}
}
8 changes: 8 additions & 0 deletions packages/protractor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ genrule(
visibility = ["//docs:__pkg__"],
)

genrule(
name = "npm_version_check",
srcs = ["//:tools/npm_version_check.js"],
outs = [":npm_version_check.js"],
cmd = "cp $< $@",
)

pkg_npm(
name = "npm_package",
srcs = [
Expand All @@ -39,6 +46,7 @@ pkg_npm(
"npm_bazel_protractor",
],
deps = [
":npm_version_check",
"@npm_bazel_protractor//:utils_lib",
] + select({
# FIXME: fix stardoc on Windows; @npm_bazel_protractor//:index.md generation fails with:
Expand Down
3 changes: 3 additions & 0 deletions packages/protractor/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"npm_bazel_protractor": {
"rootPath": "."
}
},
"scripts": {
"postinstall": "node npm_version_check.js"
}
}
11 changes: 10 additions & 1 deletion packages/rollup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ copy_file(
visibility = ["//visibility:public"],
)

genrule(
name = "npm_version_check",
srcs = ["//:tools/npm_version_check.js"],
outs = [":npm_version_check.js"],
cmd = "cp $< $@",
)

pkg_npm(
name = "npm_package",
srcs = [
Expand All @@ -65,7 +72,9 @@ pkg_npm(
vendor_external = [
"npm_bazel_rollup",
],
deps = select({
deps = [
":npm_version_check",
] + select({
# FIXME: fix stardoc on Windows; @npm_bazel_rollup//:index.md generation fails with:
# ERROR: D:/b/62unjjin/external/npm_bazel_rollup/BUILD.bazel:32:1: Couldn't build file
# external/npm_bazel_rollup/docs.raw: Generating proto for Starlark doc for docs failed (Exit 1)
Expand Down
3 changes: 3 additions & 0 deletions packages/rollup/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"npm_bazel_rollup": {
"rootPath": "."
}
},
"scripts": {
"postinstall": "node npm_version_check.js"
}
}
11 changes: 10 additions & 1 deletion packages/terser/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ genrule(
visibility = ["//docs:__pkg__"],
)

genrule(
name = "npm_version_check",
srcs = ["//:tools/npm_version_check.js"],
outs = [":npm_version_check.js"],
cmd = "cp $< $@",
)

pkg_npm(
name = "npm_package",
srcs = [
Expand All @@ -41,7 +48,9 @@ pkg_npm(
vendor_external = [
"npm_bazel_terser",
],
deps = select({
deps = [
":npm_version_check",
] + select({
# FIXME: fix stardoc on Windows; @npm_bazel_terser//:index.md generation fails with:
# ERROR: D:/b/62unjjin/external/npm_bazel_terser/BUILD.bazel:32:1: Couldn't build file
# external/npm_bazel_terser/docs.raw: Generating proto for Starlark doc for docs failed (Exit 1)
Expand Down
3 changes: 3 additions & 0 deletions packages/terser/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"npm_bazel_terser": {
"rootPath": "."
}
},
"scripts": {
"postinstall": "node npm_version_check.js"
}
}
8 changes: 8 additions & 0 deletions packages/typescript/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ genrule(
visibility = ["//docs:__pkg__"],
)

genrule(
name = "npm_version_check",
srcs = ["//:tools/npm_version_check.js"],
outs = [":npm_version_check.js"],
cmd = "cp $< $@",
)

pkg_npm(
name = "npm_package",
srcs = [
Expand All @@ -45,6 +52,7 @@ pkg_npm(
"build_bazel_rules_typescript",
],
deps = [
":npm_version_check",
"@npm_bazel_typescript//internal:BUILD",
"@npm_bazel_typescript//internal:ts_project_options_validator.js",
] + select({
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
"npm_bazel_typescript": {
"rootPath": "."
}
},
"scripts": {
"postinstall": "node npm_version_check.js"
}
}
8 changes: 8 additions & 0 deletions packages/worker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ copy_file(
out = "%s/worker_protocol.proto" % _worker_proto_dir,
)

genrule(
name = "npm_version_check",
srcs = ["//:tools/npm_version_check.js"],
outs = [":npm_version_check.js"],
cmd = "cp $< $@",
)

pkg_npm(
name = "npm_package",
srcs = [
Expand All @@ -64,5 +71,6 @@ pkg_npm(
":copy_worker_dts",
":copy_worker_js",
":copy_worker_proto",
":npm_version_check",
],
)
5 changes: 4 additions & 1 deletion packages/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
},
"keywords": [
"bazel"
]
],
"scripts": {
"postinstall": "node npm_version_check.js"
}
}
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}"`, 'internal/version.bzl');
shell.sed('-i', /^VERSION \= \"[0-9\.]*\"/, `VERSION = "${version}"`, 'version.bzl');
14 changes: 14 additions & 0 deletions tools/npm_version_check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node
const pkg = require('./package.json');
const pkgVersion = pkg.version;
const rules_nodejsVersion = process.env['BUILD_BAZEL_RULES_NODEJS_VERSION'];

const getMajor = versionString => versionString.split('.')[0];

// special case the version 0.0.0 so that we don't have to stamp builds
// for dev and testing
if (pkgVersion !== '0.0.0' && getMajor(pkgVersion) !== getMajor(rules_nodejsVersion)) {
throw new Error(`Expected package major version to equal @build_bazel_rules_nodejs major version
${pkg.name} - ${pkgVersion}
@build_bazel_rules_nodejs - ${rules_nodejsVersion}`)
}
2 changes: 1 addition & 1 deletion internal/version.bzl → version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
# 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"
VERSION = "1.5.0"

0 comments on commit 22bebbc

Please sign in to comment.