Skip to content

Commit

Permalink
Remove node_runfiles dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Globegitter authored and alexeagle committed Jun 4, 2019
1 parent 17ce697 commit 5454dd4
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions examples/vendored_node/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"]),
Expand Down
2 changes: 2 additions & 0 deletions internal/node/generate_build_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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}")
Expand Down
8 changes: 2 additions & 6 deletions internal/node/node.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions internal/node/node_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
8 changes: 8 additions & 0 deletions internal/node/node_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 [
"../../..",
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/npm_install/browserify-wrapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]});
}
2 changes: 1 addition & 1 deletion internal/rollup/terser-wrapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]});
}

Expand Down
2 changes: 1 addition & 1 deletion internal/rollup/tsc-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]});
}

Expand Down

0 comments on commit 5454dd4

Please sign in to comment.