diff --git a/examples/vendored_node/BUILD.bazel b/examples/vendored_node/BUILD.bazel index 0a109d3467..823eb41dc6 100644 --- a/examples/vendored_node/BUILD.bazel +++ b/examples/vendored_node/BUILD.bazel @@ -1,5 +1,7 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") +exports_files(["node-v10.12.0-linux-x64/bin/node"]) + jasmine_node_test( name = "yarn_test", srcs = glob(["*.spec.js"]), diff --git a/internal/node/generate_build_file.js b/internal/node/generate_build_file.js index aef3b2bc77..aea6746f00 100644 --- a/internal/node/generate_build_file.js +++ b/internal/node/generate_build_file.js @@ -26,6 +26,7 @@ const IS_WINDOWS = TEMPLATED_is_windows; const NODE_DIR = 'TEMPLATED_node_dir'; const YARN_DIR = 'TEMPLATED_yarn_dir'; const NODE_ACTUAL = 'TEMPLATED_node_actual'; +const NODE_BIN_ACTUAL = 'TEMPLATED_node_bin_actual'; const NPM_ACTUAL = 'TEMPLATED_npm_actual'; const YARN_ACTUAL = 'TEMPLATED_yarn_actual'; @@ -84,6 +85,7 @@ exports_files([ "bin/yarn${binaryExt}", "bin/yarn_node_repositories${binaryExt}", ]) +alias(name = "node_bin", actual = "${NODE_BIN_ACTUAL}") alias(name = "node", actual = "${NODE_ACTUAL}") alias(name = "npm", actual = "${NPM_ACTUAL}") alias(name = "yarn", actual = "${YARN_ACTUAL}") diff --git a/internal/node/node.bzl b/internal/node/node.bzl index 7282dc510a..548e5e16be 100644 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -169,7 +169,7 @@ def _nodejs_binary_impl(ctx): is_executable = True, ) - runfiles = depset([node, ctx.outputs.loader, ctx.file._repository_args] + ctx.files._node_runfiles, transitive = [sources, node_modules]) + runfiles = depset([node, ctx.outputs.loader, ctx.file._repository_args], transitive = [sources, node_modules]) return [DefaultInfo( executable = ctx.outputs.script, @@ -224,7 +224,7 @@ _NODEJS_EXECUTABLE_ATTRS = { ), "node": attr.label( doc = """The node entry point target.""", - default = Label("@nodejs//:node"), + default = Label("@nodejs//:node_bin"), allow_single_file = True, ), "node_modules": attr.label( @@ -308,10 +308,6 @@ _NODEJS_EXECUTABLE_ATTRS = { default = Label("//internal/node:node_loader.js"), allow_single_file = True, ), - "_node_runfiles": attr.label( - default = Label("@nodejs//:node_runfiles"), - allow_files = True, - ), "_repository_args": attr.label( default = Label("@nodejs//:bin/node_repo_args.sh"), allow_single_file = True, diff --git a/internal/node/node_loader.js b/internal/node/node_loader.js index 467ee3d270..65a47cebc1 100644 --- a/internal/node/node_loader.js +++ b/internal/node/node_loader.js @@ -25,6 +25,10 @@ var path = require('path'); var fs = require('fs'); +const isWindows = /^win/i.test(process.platform); +// Ensure that node is added to the path for any subprocess calls +process.env.PATH = [path.dirname(process.execPath), process.env.PATH].join(isWindows ? ';' : ':'); + const DEBUG = false; /** diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index e785a6cb14..4021d29f06 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -197,6 +197,12 @@ def _prepare_node(repository_ctx): repository_ctx.attr.vendored_node.name, "bin/node" if not is_windows else "node.exe", ] if f]) + node_exec_label = "@%s//%s:%s/%s" % ( + repository_ctx.attr.vendored_node.workspace_name, + repository_ctx.attr.vendored_node.package, + repository_ctx.attr.vendored_node.name, + "bin/node" if not is_windows else "node.exe", + ) npm_script = "/".join([f for f in [ "../../..", repository_ctx.attr.vendored_node.workspace_root, @@ -207,6 +213,7 @@ def _prepare_node(repository_ctx): else: node_exec = "{}/bin/node".format(NODE_DIR) if not is_windows else "{}/node.exe".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) + node_exec_label = node_exec if repository_ctx.attr.vendored_yarn: yarn_script = "/".join([f for f in [ "../../..", @@ -428,6 +435,7 @@ if %errorlevel% neq 0 exit /b %errorlevel% { "TEMPLATED_is_windows": "true" if is_windows else "false", "TEMPLATED_node_actual": node_entry, + "TEMPLATED_node_bin_actual": node_exec_label, "TEMPLATED_node_dir": NODE_DIR, "TEMPLATED_npm_actual": npm_node_repositories_entry, "TEMPLATED_yarn_actual": yarn_node_repositories_entry, diff --git a/internal/npm_install/browserify-wrapped.js b/internal/npm_install/browserify-wrapped.js index 6c5e0c6820..c8f6f9df71 100644 --- a/internal/npm_install/browserify-wrapped.js +++ b/internal/npm_install/browserify-wrapped.js @@ -57,6 +57,6 @@ browserify-wrapped: running with const isWindows = /^win/i.test(process.platform); child_process.execFileSync( - isWindows ? 'node.cmd' : 'node', args, + isWindows ? 'node.exe' : 'node', args, {stdio: [process.stdin, process.stdout, process.stderr]}); } diff --git a/internal/rollup/terser-wrapped.js b/internal/rollup/terser-wrapped.js index 3ab8a33f06..fc4fffe0a1 100644 --- a/internal/rollup/terser-wrapped.js +++ b/internal/rollup/terser-wrapped.js @@ -100,7 +100,7 @@ function runterser(inputFile, outputFile, sourceMapFile) { const isWindows = /^win/i.test(process.platform); child_process.execFileSync( - isWindows ? 'node.cmd' : 'node', args, + isWindows ? 'node.exe' : 'node', args, {stdio: [process.stdin, process.stdout, process.stderr]}); } diff --git a/internal/rollup/tsc-directory.js b/internal/rollup/tsc-directory.js index b10c97e0dc..3e0b03e22a 100644 --- a/internal/rollup/tsc-directory.js +++ b/internal/rollup/tsc-directory.js @@ -71,7 +71,7 @@ function runTsc(inputDir, outputDir, projectFile) { const isWindows = /^win/i.test(process.platform); child_process.execFileSync( - isWindows ? 'node.cmd' : 'node', args, + isWindows ? 'node.exe' : 'node', args, {stdio: [process.stdin, process.stdout, process.stderr]}); }