Skip to content

Commit d93a80a

Browse files
committed
Adds --nodedir option for better node-gyp interoperability.
- Removes unused old rule node_repository.
1 parent 2b9d102 commit d93a80a

File tree

5 files changed

+11
-64
lines changed

5 files changed

+11
-64
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ node_library(
127127
srcs = [
128128
"qux.js",
129129
],
130-
use_prefix = False,
131130
)
132131
```
133132

node/internal/node_binary.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def _get_node_modules_dir_from_sourcefile(file):
3939
def node_binary_impl(ctx):
4040
inputs = []
4141
srcs = []
42-
node_paths = []
4342
script = ctx.file.main
43+
node = ctx.file._node
44+
node_paths = []
4445

4546
for file in ctx.files.modules:
4647
if not file.basename.endswith("node_modules"):
@@ -55,7 +56,6 @@ def node_binary_impl(ctx):
5556
node_paths += [_get_node_modules_dir_from_package_json(lib.package_json)]
5657

5758
node_paths = list(set(node_paths))
58-
node = ctx.file._node
5959

6060
ctx.file_action(
6161
output = ctx.outputs.executable,

node/internal/node_repositories.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
load("//node:internal/node_repository.bzl", "node_repository")
2-
31
NODE_TOOLCHAIN_BUILD_FILE = """
42
package(default_visibility = [ "//visibility:public" ])
53
exports_files([

node/internal/node_repository.bzl

Lines changed: 0 additions & 53 deletions
This file was deleted.

node/internal/npm_repository.bzl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def _execute(ctx, cmds):
1010
result = ctx.execute(cmds)
1111
if result.return_code:
1212
fail(" ".join(cmds) + "failed: %s" %(result.stderr))
13-
return result.stdout
13+
return result
1414

1515

1616
def _dnode_modules(ctx, node_modules_path):
@@ -30,8 +30,7 @@ def _dnode_modules(ctx, node_modules_path):
3030
cmd.append("--exclude")
3131
cmd += ctx.attr.exclude_package_json_keys
3232

33-
output = _execute(ctx, cmd)
34-
print(output)
33+
output = _execute(ctx, cmd).stdout
3534

3635

3736
def _check_sha256(ctx, node_modules_path):
@@ -66,16 +65,17 @@ def _check_sha256(ctx, node_modules_path):
6665
])
6766

6867
expected = ctx.attr.sha256
69-
actual = _execute(ctx, sha256 + [tarfile]).split(" ")[0]
68+
actual = _execute(ctx, sha256 + [tarfile]).stdout.split(" ")[0]
7069
if actual != expected:
7170
fail(ctx.name + " node_modules archive sha256 [%s] does not match expected value [%s]" %(actual, expected))
7271

72+
ctx.file("node_modules.sha256", actual)
7373

7474
def _npm_repository_impl(ctx):
7575
node = ctx.path(ctx.attr.node)
76+
nodedir = node.dirname.dirname
7677
npm = ctx.path(ctx.attr.npm)
7778
node_modules_path = ctx.attr.node_modules_path
78-
7979
modules = []
8080
for k, v in ctx.attr.deps.items():
8181
if v:
@@ -87,7 +87,9 @@ def _npm_repository_impl(ctx):
8787
node,
8888
npm,
8989
"install",
90+
#"--loglevel", "silly", # info
9091
"--prefix", ctx.path(""),
92+
"--nodedir=%s" % nodedir,
9193
"--global"
9294
]
9395

@@ -96,7 +98,8 @@ def _npm_repository_impl(ctx):
9698

9799
cmd += modules
98100

99-
_execute(ctx, cmd)
101+
output = _execute(ctx, cmd).stdout
102+
#print("npm install output: %s" % output)
100103

101104
if ctx.attr.sha256:
102105
_dnode_modules(ctx, node_modules_path)

0 commit comments

Comments
 (0)