Skip to content

Commit

Permalink
feat: add support for NodeJS 15.x
Browse files Browse the repository at this point in the history
Include support for NodeJS 15.x, updates some examples to use this
Switches bazel-in-bazel example tests to use a tar file for package.json replacements
  • Loading branch information
mattem committed Dec 23, 2020
1 parent b53e31c commit 006ded0
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 15 deletions.
14 changes: 7 additions & 7 deletions examples/vendored_node/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ http_archive(
)

http_archive(
name = "vendored_node_10_12_0",
build_file_content = """exports_files(["node-v10.12.0-linux-x64/bin/node"])""",
sha256 = "4eba2e9a6db95745b769915d58e57df6ca6724ec1f023f76556fce30ceca2367",
urls = ["https://nodejs.org/dist/v10.12.0/node-v10.12.0-linux-x64.tar.xz"],
name = "vendored_node_15_0_1",
build_file_content = """exports_files(["node-v15.0.1-linux-x64/bin/node"])""",
sha256 = "cc9c3eed21755b490e5333ccab208ce15b539c35f64a764eeeae77c58746a7ff",
urls = ["https://nodejs.org/dist/v15.0.1/node-v15.0.1-linux-x64.tar.xz"],
)

load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")

# This example only works on linux as it downloads the linux node distribution
# TODO(gregmagolan): make node_repositories acccept different archives for different platforms
node_repositories(
node_version = "10.12.0",
vendored_node = "@vendored_node_10_12_0//:node-v10.12.0-linux-x64",
node_version = "15.0.1",
vendored_node = "@vendored_node_15_0_1//:node-v15.0.1-linux-x64",
)

npm_install(
name = "npm",
data = [
"@vendored_node_10_12_0//:node-v10.12.0-linux-x64/bin/node",
"@vendored_node_15_0_1//:node-v15.0.1-linux-x64/bin/node",
],
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
Expand Down
4 changes: 2 additions & 2 deletions examples/vendored_node/vendored.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('vendored node', () => {
it('version should be 10.12.0', () => {
expect(process.version).toBe('v10.12.0');
it('version should be 15.0.1', () => {
expect(process.version).toBe('v15.0.1');
});
});
5 changes: 4 additions & 1 deletion examples/vue/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ http_archive(

load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")

node_repositories(package_json = ["//:package.json"])
node_repositories(
node_version = "15.0.1",
package_json = ["//:package.json"],
)

npm_install(
name = "npm",
Expand Down
7 changes: 7 additions & 0 deletions internal/bazel_integration_test/bazel_integration_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ def rules_nodejs_integration_test(name, **kwargs):
repositories = kwargs.pop("repositories", {})
repositories["//:release"] = "build_bazel_rules_nodejs"

# convert the npm packages into the tar output
npm_packages = kwargs.pop("npm_packages", {})
_tar_npm_packages = {}
for key in npm_packages:
_tar_npm_packages[key + ".tar"] = npm_packages[key]

bazel_integration_test(
name = name,
check_npm_packages = NPM_PACKAGES,
Expand All @@ -278,6 +284,7 @@ def rules_nodejs_integration_test(name, **kwargs):
bazelrc_imports = {
"//:common.bazelrc": "import %workspace%/../../common.bazelrc",
},
npm_packages = _tar_npm_packages,
tags = tags,
**kwargs
)
24 changes: 21 additions & 3 deletions internal/bazel_integration_test/test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@ function copyNpmPackage(packagePath) {
const to = tmp.dirSync({keep: DEBUG, unsafeCleanup: !DEBUG}).name;
const from = RUNFILES_MANIFEST ? RUNFILES_MANIFEST[packagePath] :
path.posix.join(process.cwd(), '..', packagePath);
if (!isDirectory(from)) {
if (!isFile(from)) {
throw new Error(`npm package ${packagePath} not found at ${from}`);
}
copyFolderSync(from, to);
return to;

const parsed = path.parse(from);
copyFolderSync(parsed.dir, to);
return path.join(to, parsed.base);
}

const workspacePath = config.workspaceRoot.startsWith('external/') ?
Expand Down Expand Up @@ -243,6 +245,11 @@ if (config.bazelrcAppend) {

// Handle package.json replacements
const packageJsonFile = path.posix.join(workspaceRoot, 'package.json');
const packageJsonLockFile = path.posix.join(workspaceRoot, 'package-lock.json');
const packageJsonLockContents = isFile(packageJsonLockFile) ?
JSON.parse(fs.readFileSync(packageJsonLockFile, {encoding: 'utf-8'})) :
undefined;

if (isFile(packageJsonFile)) {
let packageJsonContents = fs.readFileSync(packageJsonFile, {encoding: 'utf-8'});

Expand All @@ -259,8 +266,19 @@ if (isFile(packageJsonFile)) {
packageJsonKey} failed!`)
process.exit(1);
}

if (packageJsonLockContents && packageJsonLockContents.packages && packageJsonKey) {
// keeping the entry results in a npm error, but removing it solves it
// TODO(matt): regenerate the entry here when I understand the filepaths :/
delete packageJsonLockContents.packages[`node_modules/${packageJsonKey}`];
}
}

fs.writeFileSync(packageJsonFile, packageJsonContents);

if (packageJsonLockContents) {
fs.writeFileSync(packageJsonLockFile, JSON.stringify(packageJsonLockContents, null, 2));
}
}

const packageJsonReplacementKeys = Object.keys(config.packageJsonRepacements);
Expand Down
12 changes: 12 additions & 0 deletions internal/node/node_versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1090,4 +1090,16 @@ NODE_VERSIONS = {
"14.15.3-linux_s390x": ("node-v14.15.3-linux-s390x.tar.xz", "node-v14.15.3-linux-s390x", "eb976b0d14cc629be3b1d03516ec5516c27d3655f84f11d23af15f4f83d34e27"),
"14.15.3-linux_amd64": ("node-v14.15.3-linux-x64.tar.xz", "node-v14.15.3-linux-x64", "6715ecd8b5ab626b4de8454bd0da629a6194bf8f25db71545da64b78b95e4350"),
"14.15.3-windows_amd64": ("node-v14.15.3-win-x64.zip", "node-v14.15.3-win-x64", "621de473d22debc0ab1e9a336dc2112d6efca7f7daa769018153e4309e6da844"),
# 15.0.0
"15.0.0-darwin_amd64": ("node-v15.0.0-darwin-x64.tar.gz", "node-v15.0.0-darwin-x64", "f9eee1f659d96991bc629ec1cec986f504242fc0f046f4487d2fe13b9ab37c99"),
"15.0.0-linux_arm64": ("node-v15.0.0-linux-arm64.tar.xz", "node-v15.0.0-linux-arm64", "52aba1b117499680adea5fec43083fcb94a3483eda182ea82ca47f5d7c9eec97"),
"15.0.0-linux_s390x": ("node-v15.0.0-linux-s390x.tar.xz", "node-v15.0.0-linux-s390x", "7c916b1f3729a66701a0fc0ffe0afde05e401ccc3c53e7114db37cfbf4604f27"),
"15.0.0-linux_amd64": ("node-v15.0.0-linux-x64.tar.xz", "node-v15.0.0-linux-x64", "054c1c20ee237614e12ee2baab1ec96bfafc835a2d36fb2b860fdf10be0777b0"),
"15.0.0-windows_amd64": ("node-v15.0.0-win-x64.zip", "node-v15.0.0-win-x64", "fe8358e18a1f5a44849420d9d76c755e7489f92e0933c8d780107cd688e1d3d6"),
# 15.0.1
"15.0.1-darwin_amd64": ("node-v15.0.1-darwin-x64.tar.gz", "node-v15.0.1-darwin-x64", "8f7e2ddd44d2aef20d568489f2cf844383037725ce2fc04ad722a312ef08b2d0"),
"15.0.1-linux_arm64": ("node-v15.0.1-linux-arm64.tar.xz", "node-v15.0.1-linux-arm64", "403571f7e37dfefd7bd46411fff4ec7d81bf3d1a34feb37939ad35a06e61d855"),
"15.0.1-linux_s390x": ("node-v15.0.1-linux-s390x.tar.xz", "node-v15.0.1-linux-s390x", "537fec4b3e2c06459991d25641da83533fee551575326b36d54e44364a10678a"),
"15.0.1-linux_amd64": ("node-v15.0.1-linux-x64.tar.xz", "node-v15.0.1-linux-x64", "cc9c3eed21755b490e5333ccab208ce15b539c35f64a764eeeae77c58746a7ff"),
"15.0.1-windows_amd64": ("node-v15.0.1-win-x64.zip", "node-v15.0.1-win-x64", "efa7a74d91789a6e9f068f375e49f108ff87578fd88ff4b4e7fefd930c04db6c"),
}
2 changes: 1 addition & 1 deletion scripts/update-nodejs-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const https = require("https");

const MIN_VERSION = [8, 0, 0];
const MAX_VERSION = [14, 99, 99];
const MAX_VERSION = [15, 0, 1];

const REPOSITORY_TYPES = {
"darwin-x64.tar.gz": "darwin_amd64",
Expand Down
14 changes: 13 additions & 1 deletion tools/defaults.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def pkg_npm(**kwargs):
"0.0.0-PLACEHOLDER": "{STABLE_BUILD_SCM_VERSION}",
})

# Finally call through to the rule with our defaults set
# Call through to the rule with our defaults set
_pkg_npm(
deps = deps,
substitutions = select({
Expand All @@ -66,6 +66,18 @@ def pkg_npm(**kwargs):
**kwargs
)

# create a tar that can be used in an action, consumed by the examples
# tagged as manual so this doesn't case two actions for each input with builds for "host" (as used as a tool)
name = kwargs.get("name")
native.genrule(
name = "%s.tar" % name,
outs = ["%s.tgz" % pkg],
cmd = "$(location :%s.pack) | xargs -I {} cp {} $@" % name,
tools = [":%s.pack" % name],
tags = ["manual"],
visibility = visibility,
)

_GLOBAL_OWNERS = [
"@alexeagle",
"@gregmagolan",
Expand Down

0 comments on commit 006ded0

Please sign in to comment.