From df2bc78e94c555a9882ba22a3858ff222cb17450 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Thu, 30 May 2019 22:14:07 -0700 Subject: [PATCH 1/2] Set --preserve-symlinks-main flag along with --preserve-symlinks flag when node version is 10.2.0 or greater (#806) --- internal/node/generate_build_file.js | 2 +- internal/node/node.bzl | 2 +- internal/node/node_repositories.bzl | 38 ++++++++++++++++++++-------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/internal/node/generate_build_file.js b/internal/node/generate_build_file.js index ba5a98ac69..aef3b2bc77 100644 --- a/internal/node/generate_build_file.js +++ b/internal/node/generate_build_file.js @@ -76,7 +76,7 @@ function generateBuildFile() { package(default_visibility = ["//visibility:public"]) exports_files([ "run_npm.sh.template", - "bin/node_args.sh", + "bin/node_repo_args.sh", "${NODE_DIR}/bin/node", "bin/node${binaryExt}", "bin/npm${binaryExt}", diff --git a/internal/node/node.bzl b/internal/node/node.bzl index 9a7831c262..7282dc510a 100644 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -313,7 +313,7 @@ _NODEJS_EXECUTABLE_ATTRS = { allow_files = True, ), "_repository_args": attr.label( - default = Label("@nodejs//:bin/node_args.sh"), + default = Label("@nodejs//:bin/node_repo_args.sh"), allow_single_file = True, ), "_source_map_support_files": attr.label_list( diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index 5708c621dc..e785a6cb14 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -19,6 +19,7 @@ See https://docs.bazel.build/versions/master/skylark/repository_rules.html """ load("//internal/common:check_bazel_version.bzl", "check_bazel_version") +load("//internal/common:check_version.bzl", "check_version") load("//internal/common:os_name.bzl", "os_name") load("//internal/npm_install:npm_install.bzl", "yarn_install") load("//third_party/github.com/bazelbuild/bazel-skylib:lib/paths.bzl", "paths") @@ -201,11 +202,11 @@ def _prepare_node(repository_ctx): repository_ctx.attr.vendored_node.workspace_root, repository_ctx.attr.vendored_node.package, repository_ctx.attr.vendored_node.name, - "bin/npm" if not is_windows else "node_modules/npm/bin/npm-cli.js", + "lib/node_modules/npm/bin/npm-cli.js" if not is_windows else "node_modules/npm/bin/npm-cli.js", ] if f]) else: node_exec = "{}/bin/node".format(NODE_DIR) if not is_windows else "{}/node.exe".format(NODE_DIR) - npm_script = "{}/bin/npm".format(NODE_DIR) if not is_windows else "{}/node_modules/npm/bin/npm-cli.js".format(NODE_DIR) + npm_script = "{}/lib/node_modules/npm/bin/npm-cli.js".format(NODE_DIR) if not is_windows else "{}/node_modules/npm/bin/npm-cli.js".format(NODE_DIR) if repository_ctx.attr.vendored_yarn: yarn_script = "/".join([f for f in [ "../../..", @@ -227,6 +228,20 @@ def _prepare_node(repository_ctx): if not repository_ctx.attr.preserve_symlinks: print("\nWARNING: The preserve_symlinks option is deprecated and will go away in the future.\n") + if repository_ctx.attr.preserve_symlinks: + # --preserve-symlinks-main flag added in node 10.2.0 + # See https://nodejs.org/api/cli.html#cli_preserve_symlinks_main + preserve_symlinks_main_support = check_version(repository_ctx.attr.node_version, "10.2.0") + if preserve_symlinks_main_support: + node_args = "--preserve-symlinks --preserve-symlinks-main" + node_repo_args = "\"--node_options=--preserve-symlinks --node_options=--preserve-symlinks-main\"" + else: + node_args = "--preserve-symlinks" + node_repo_args = "--node_options=--preserve-symlinks" + else: + node_args = "" + node_repo_args = "" + # The entry points for node for osx/linux and windows if not is_windows: # Sets PATH and runs the application @@ -236,10 +251,11 @@ def _prepare_node(repository_ctx): set -e {get_script_dir} export PATH="$SCRIPT_DIR":$PATH -exec "$SCRIPT_DIR/{node}" "$@" +exec "$SCRIPT_DIR/{node}" {args} "$@" """.format( get_script_dir = GET_SCRIPT_DIR, node = node_exec_relative, + args = node_args, )) else: # Sets PATH for node, npm & yarn and run user script @@ -247,18 +263,16 @@ exec "$SCRIPT_DIR/{node}" "$@" @echo off SET SCRIPT_DIR=%~dp0 SET PATH=%SCRIPT_DIR%;%PATH% -CALL "%SCRIPT_DIR%\\{node}" %* -""".format(node = node_exec_relative)) +CALL "%SCRIPT_DIR%\\{node}" {args} %* +""".format(node = node_exec_relative, args = node_args)) # Shell script to set repository arguments for node used by nodejs_binary & nodejs_test launcher - # TODO(gregmagolan): add --node_options=--preserve-symlinks-main as well if preserve_symlinks is True & - # node version >= 10.2.0 - repository_ctx.file("bin/node_args.sh", content = """#!/usr/bin/env bash + repository_ctx.file("bin/node_repo_args.sh", content = """#!/usr/bin/env bash # Immediately exit if any command fails. set -e # Generated by node_repositories.bzl export NODE_REPOSITORY_ARGS={} -""".format("--node_options=--preserve-symlinks" if repository_ctx.attr.preserve_symlinks else ""), executable = True) +""".format(node_repo_args), executable = True) # The entry points for npm for osx/linux and windows # Runs npm using appropriate node entry point @@ -515,9 +529,13 @@ def node_repositories( when you manually run the package manager, e.g. with `bazel run @nodejs//:yarn` or `bazel run @nodejs//:npm install`. If you use bazel-managed dependencies, you can omit this attribute. - node_version: optional; the specific version of NodeJS to install. + node_version: optional; the specific version of NodeJS to install or, if + vendored_node is specified, the vendored version of node. yarn_version: optional; the specific version of Yarn to install. vendored_node: optional; the local path to a pre-installed NodeJS runtime. + If set then also set node_version to the version that of node that is vendored. + Bazel will automatically turn on features such as --preserve-symlinks-main if they + are supported by the node version being used. vendored_yarn: optional; the local path to a pre-installed yarn tool. node_repositories: optional; custom list of node repositories to use. yarn_repositories: optional; custom list of yarn repositories to use. From 5cb37d2122b6fb7ba9b3e5ec252057a019bc822c Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Fri, 31 May 2019 00:14:34 -0700 Subject: [PATCH 2/2] Bust CircleCI node_modules cache (#806) --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 64da6c3ef0..623a3f2035 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,7 +11,7 @@ # If you change the `default_docker_image` version, also change the `cache_key` version var_1: &default_docker_image circleci/node:10.12 var_2: &browsers_docker_image circleci/node:10.12-browsers -var_3: &cache_key node-0.12-{{ checksum "yarn.lock" }}-{{ checksum "examples/program/yarn.lock" }}-{{ checksum "internal/npm_install/test/package/yarn.lock" }} +var_3: &cache_key node-0.12-{{ checksum "yarn.lock" }}-{{ checksum "examples/program/yarn.lock" }}-{{ checksum "internal/npm_install/test/package/yarn.lock" }}-2 var_4: &init_environment run: