Skip to content

Commit 1c60708

Browse files
erickjpcj
authored andcommitted
Fixes #63 (#64)
* Fixes #63 adds NODE_PATH to node_binary to allow scripts to require node_modules in the transitive deps. see tests/rollup for a repro. * adds test_rollup to Makefile
1 parent d484d31 commit 1c60708

File tree

7 files changed

+88
-1
lines changed

7 files changed

+88
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ test_express:
1010
test_namespace:
1111
(cd tests/namespace && bazel test //...)
1212

13+
test_rollup:
14+
(cd tests/rollup && bazel test //...)
15+
1316
test_typescript:
1417
(cd tests/typescript && bazel test //...)
1518

@@ -22,4 +25,4 @@ test_polymer-cli:
2225
test_mocha:
2326
(cd tests/mocha && bazel test //...)
2427

25-
test_all: test_helloworld test_lyrics test_express test_namespace test_typescript test_webpack test_polymer-cli test_mocha
28+
test_all: test_helloworld test_lyrics test_express test_namespace test_typescript test_webpack test_polymer-cli test_mocha test_rollup

node/internal/node_binary.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def create_launcher(ctx, output_dir, node, manifest):
8888

8989
'# Modify path such that embedded scripts with /usr/bin/env node shebangs',
9090
'# resolve to the bundled node executable',
91+
'export NODE_PATH="${TARGET_PATH}/node_modules"',
9192
'export PATH="${TARGET_PATH}:$PATH"',
9293

9394
' '.join(cmd)

tests/rollup/BUILD

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("@org_pubref_rules_node//node:rules.bzl", "node_binary")
4+
load("@bazel_tools//tools/build_rules:test_rules.bzl", "file_test")
5+
6+
#
7+
# Rollup bundling
8+
#
9+
node_binary(
10+
name = "rollup_with_plugins",
11+
entrypoint = "@yarn_modules//:rollup",
12+
executable = "rollup",
13+
deps = ["@yarn_modules//:_all_"],
14+
)
15+
16+
genrule(
17+
name = "genrule_target",
18+
tools = [
19+
":rollup_with_plugins",
20+
":rollup.config.js",
21+
],
22+
srcs = [
23+
"es6_src.js",
24+
],
25+
outs = [
26+
"genrule_target.js",
27+
],
28+
executable = 1,
29+
cmd = " ".join([
30+
"$(location :rollup_with_plugins)",
31+
"-c $(location :rollup.config.js)",
32+
"-i $(location :es6_src.js)",
33+
"-f cjs",
34+
"-o $(location :genrule_target.js)"
35+
])
36+
)
37+
38+
39+
file_test(
40+
name = "test",
41+
size = "small",
42+
file = ":genrule_target",
43+
content = """'use strict';
44+
45+
function es6_src () { return "if I build, then all's good"; }
46+
47+
module.exports = es6_src;
48+
"""
49+
)

tests/rollup/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Rollup Example
2+
3+
This test verifies that `NODE_PATH` is set to the node_modules directory while executing `node_binary` rules. The test uses a [rollup configuration file](https://rollupjs.org/guide/en#configuration-files) supplied to a genrule that includes `node_module` depenendencies supplied to a `node_binary` target.
4+
5+
```
6+
$ bazel test :test
7+
```
8+

tests/rollup/WORKSPACE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
local_repository(
2+
name = "org_pubref_rules_node",
3+
path = "../..",
4+
)
5+
6+
load("@org_pubref_rules_node//node:rules.bzl", "node_repositories", "yarn_modules")
7+
8+
node_repositories()
9+
10+
yarn_modules(
11+
name = "yarn_modules",
12+
deps = {
13+
"rollup": "0.56.5",
14+
# rollup-plugin-buble is simply an external node module to the
15+
# rollup binary that will be required at runtime.
16+
"rollup-plugin-buble": "0.19.2",
17+
}
18+
)

tests/rollup/es6_src.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => "if I build, then all's good";

tests/rollup/rollup.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import buble from 'rollup-plugin-buble';
2+
3+
export default {
4+
plugins: [
5+
buble()
6+
]
7+
};

0 commit comments

Comments
 (0)