Skip to content

Commit fbefffb

Browse files
authored
Update node version (#79)
- Fix dependency referrer null pointer - s/module/mod/g for variable names - include yallist in webpack example (needed to avoid this bug) - update .travis.yml to current version 0.24.0 - Upgrade node to 8.15.1 - Upgrade yarn to 1.15.2 - Fix a bug in generated node_binary rules (for labels with special characters) - Remove polymer-cli example from CI unit tests (not working ATM)
1 parent 5e4d6b3 commit fbefffb

File tree

11 files changed

+88
-83
lines changed

11 files changed

+88
-83
lines changed

.travis.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
1+
# trusty beta image has jdk8, gcc4.8.4
12
dist: trusty
23
sudo: required
4+
# xcode8 has jdk8
35
osx_image: xcode8
6+
# Not technically required but suppresses 'Ruby' in Job status message.
47
language: java
58

69
os:
710
- linux
811
- osx
912

1013
env:
11-
- V=0.20.0
12-
- V=0.21.0
13-
- V=0.22.0
14-
- V=0.23.2
15-
- V=0.24.0
14+
- BAZEL=0.20.0
15+
- BAZEL=0.24.0
1616

1717
before_install:
18-
- OS=linux
19-
- ARCH=x86_64
20-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then OS=darwin; fi
21-
- GH_BASE="https://github.com/bazelbuild/bazel/releases/download/$V"
22-
- GH_ARTIFACT="bazel-$V-installer-$OS-$ARCH.sh"
23-
- CI_BASE="http://ci.bazel.io/job/Bazel/JAVA_VERSION=1.8,PLATFORM_NAME=$OS-$ARCH/lastSuccessfulBuild/artifact/output/ci"
24-
- CI_ARTIFACT="bazel--installer.sh"
25-
- URL="$GH_BASE/$GH_ARTIFACT"
26-
- if [[ "$V" == "HEAD" ]]; then CI_ARTIFACT="`wget -qO- $CI_BASE | grep -o 'bazel-[-_a-zA-Z0-9\.]*-installer.sh' | uniq`"; fi
27-
- if [[ "$V" == "HEAD" ]]; then URL="$CI_BASE/$CI_ARTIFACT"; fi
28-
- echo $URL
29-
- wget -O install.sh $URL
30-
- chmod +x install.sh
31-
- ./install.sh --user
32-
- rm -f install.sh
18+
- |
19+
if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
20+
OS=darwin
21+
else
22+
sysctl kernel.unprivileged_userns_clone=1
23+
OS=linux
24+
fi
25+
wget -O install.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL}/bazel-${BAZEL}-installer-${OS}-x86_64.sh"
26+
chmod +x install.sh
27+
./install.sh --user
28+
rm -f install.sh
3329
3430
script:
3531
- make test_all

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ test_polymer-cli:
2525
test_mocha:
2626
(cd tests/mocha && bazel test //...)
2727

28-
test_all: test_helloworld test_lyrics test_express test_namespace test_typescript test_webpack test_polymer-cli test_mocha test_rollup
28+
# polymer cli not included as it appears to still be a WIP
29+
test_all: test_helloworld test_lyrics test_express test_namespace test_typescript test_webpack test_mocha test_rollup

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
## node_repositories
3131

3232
WORKSPACE rule that downloads and configures node based on your
33-
operating system. Includes `node` (7.10.1) and `yarn` (1.0.1).
33+
operating system. Includes `node` (8.15.1) and `yarn` (1.0.1).
3434

3535
```python
3636
RULES_NODE_COMMIT = '...' # Update to current HEAD

node/internal/node_repositories.bzl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,23 @@ _node_repository = repository_rule(
8888
_node_repository_impl,
8989
attrs = {
9090
"node_version": attr.string(
91-
default = "7.10.1",
91+
default = "8.15.1",
9292
),
9393
"linux_sha256": attr.string(
94-
default = "7b0e9d1af945671a0365a64ee58a2b0d72b3632a1cebe6b5bd75094b93627bf3",
94+
default = "5643b54c583eebaa40c1623b16cba4e3955ff5dfdd44036f6bafd761160c993d",
9595
),
9696
"darwin_sha256": attr.string(
97-
default = "d67d2eb9456aab925416ad58aa18b9680e66a4bcc243a89b22e646f7fffc4ff9",
97+
default = "aacdc9d5d8bbeaf47c398815147e052aac53cf19319f4c140c1798a82d419e65",
9898
),
9999
"windows_sha256": attr.string(
100-
default = "617590f06f9a0266ceecb3fd17120fc2fbf8669980974f339a83f3b56ed05f7b",
100+
default = "f636fa578dc079bacc6c4bef13284ddb893c99f7640b96701c2690bd9c1431f5",
101101
),
102102
},
103103
)
104104

105105

106-
def node_repositories(yarn_version="v1.0.1",
107-
yarn_sha256="6b00b5e0a7074a512d39d2d91ba6262dde911d452617939ca4be4a700dd77cf1",
106+
def node_repositories(yarn_version="v1.15.2",
107+
yarn_sha256="c4feca9ba5d6bf1e820e8828609d3de733edf0e4722d17ed7ce493ed39f61abd",
108108
**kwargs):
109109

110110
http_archive(
@@ -117,13 +117,13 @@ def node_repositories(yarn_version="v1.0.1",
117117
build_file_content = YARN_BUILD_FILE_CONTENT,
118118
)
119119

120-
http_archive(
121-
name = "yarnpkg_lockfile",
122-
url = "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.0.0.tgz",
123-
sha256 = "472add7ad141c75811f93dca421e2b7456045504afacec814b0565f092156250",
124-
strip_prefix="package",
125-
build_file_content = YARN_LOCKFILE_BUILD_FILE_CONTENT,
126-
)
120+
# http_archive(
121+
# name = "yarnpkg_lockfile",
122+
# url = "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.1.tgz",
123+
# sha256 = "472add7ad141c75811f93dca421e2b7456045504afacec814b0565f092156251",
124+
# strip_prefix="package",
125+
# build_file_content = YARN_LOCKFILE_BUILD_FILE_CONTENT,
126+
# )
127127

128128
_node_repository(
129129
name = "node",

node/internal/parse_yarn_lock.js

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function main() {
3939
const modules = moduleDirs.map(dir => parseNodeModulePackageJson(dir));
4040

4141
// Iterate all the modules and merge the information from yarn into the module
42-
modules.forEach(module => mergePackageJsonWithYarnEntry(entries, module));
42+
modules.forEach(mod => mergePackageJsonWithYarnEntry(entries, mod));
4343

4444
// Didn't realize that the nodejs module ecosystem can contain
4545
// circular references, but apparently it can.
@@ -51,15 +51,15 @@ function main() {
5151
print("package(default_visibility = ['//visibility:public'])");
5252
print("load('@org_pubref_rules_node//node:rules.bzl', 'node_module', 'node_binary')");
5353

54-
modules.forEach(module => printNodeModule(module));
54+
modules.forEach(mod => printNodeModule(mod));
5555

5656
printNodeModuleAll(modules);
5757

5858
// Create an executable rule all executable entryies in the modules
59-
modules.forEach(module => {
60-
if (module.executables) {
61-
for (const [name, path] of module.executables.entries()) {
62-
printNodeBinary(module, name, path);
59+
modules.forEach(mod => {
60+
if (mod.executables) {
61+
for (const [name, path] of mod.executables.entries()) {
62+
printNodeBinary(mod, name, path);
6363
}
6464
}
6565
});
@@ -94,17 +94,17 @@ function findMatchingYarnEntryByNameAndVersion(entries, module) {
9494
* Actually, this is pretty simple as the yarn entry is simply
9595
* attached to the module.
9696
*/
97-
function mergePackageJsonWithYarnEntry(entries, module) {
98-
const entry = findMatchingYarnEntryByNameAndVersion(entries, module);
97+
function mergePackageJsonWithYarnEntry(entries, mod) {
98+
const entry = findMatchingYarnEntryByNameAndVersion(entries, mod);
9999
if (!entry) {
100-
throw new Error("No matching node_module found for " + module.name);
100+
throw new Error("No matching node_module found for this module", mod);
101101
}
102102

103103
// Use the bazelified name as the module name
104-
module.original_name = module.name
105-
module.name = entry.name
104+
mod.original_name = mod.name
105+
mod.name = entry.name
106106
// Store everything else here
107-
module.yarn = entry;
107+
mod.yarn = entry;
108108
}
109109

110110
/**
@@ -117,30 +117,31 @@ function mergePackageJsonWithYarnEntry(entries, module) {
117117
function breakCircularDependencies(modules) {
118118

119119
const byName = new Map();
120-
modules.forEach(module => byName.set(module.name, module));
120+
modules.forEach(mod => byName.set(mod.name, mod));
121121

122122
// Make a list of nodes
123123
const nodes = Array.from(byName.keys());
124124
// An Array<Array<number>> array for the edges
125125
const edges = [];
126-
// And a mapping for backreferences mapped by name
127-
const backrefs = new Map();
128126

129127
// Build the adjacencyList
130128
nodes.forEach((node, index) => {
131129
const list = [];
132130
edges[index] = list;
133-
const entry = byName.get(node);
131+
const entry = byName.get(node); // get the module by name
134132
// Make a set of deps rather than using the entry.dependencies
135133
// mapping.
136134
entry.deps = new Set();
137135

138136
if (entry.dependencies) {
139-
137+
140138
Object.keys(entry.dependencies).forEach(name => {
141139

142140
// Save this in the deps set
143141
const dependency = byName.get(name);
142+
if (!dependency) {
143+
throw new ReferenceError(`# For module ${entry.name} ${entry.version}: for some reason the module for transitive dependency ${name} was not included. Please add it manually to your list of top-level dependencies (rule yarn_modules.deps attribute) .`);
144+
}
144145
entry.deps.add(dependency);
145146

146147
// Populate the adjacency list
@@ -246,8 +247,7 @@ function parseName(key, entry) {
246247
const at = key.indexOf("@", 1);
247248
entry.name = key.slice(0, at);
248249

249-
const label = entry.name.replace('@', 'at-');
250-
entry.label = label;
250+
entry.label = entry.name.replace('@', 'at-');
251251
}
252252

253253

@@ -283,26 +283,26 @@ function printJson(entry) {
283283
/**
284284
* Given a module, print a skylark `node_module` rule.
285285
*/
286-
function printNodeModule(module) {
287-
const deps = module.deps;
286+
function printNodeModule(mod) {
287+
const deps = mod.deps;
288288

289289
print(``);
290-
printJson(module);
290+
printJson(mod);
291291
print(`node_module(`);
292-
print(` name = "${module.yarn ? module.yarn.label : module.name}",`);
292+
print(` name = "${mod.yarn ? mod.yarn.label : mod.name}",`);
293293

294294
// SCC pseudomodule wont have 'yarn' property
295-
if (module.yarn) {
296-
const url = module.yarn.url || module.url;
297-
const sha1 = module.yarn.sha1;
298-
const executables = module.executables;
299-
300-
print(` module_name = "${module.name}",`);
301-
print(` version = "${module.version}",`);
302-
print(` package_json = "node_modules/${module.name}/package.json",`);
295+
if (mod.yarn) {
296+
const url = mod.yarn.url || mod.url;
297+
const sha1 = mod.yarn.sha1;
298+
const executables = mod.executables;
299+
300+
print(` module_name = "${mod.name}",`);
301+
print(` version = "${mod.version}",`);
302+
print(` package_json = "node_modules/${mod.name}/package.json",`);
303303
// Exclude filenames with spaces: Bazel can't cope with them (we just have to hope they aren't needed later...)
304-
print(` srcs = glob(["node_modules/${module.name}/**/*"], exclude = [
305-
"node_modules/${module.name}/package.json",
304+
print(` srcs = glob(["node_modules/${mod.name}/**/*"], exclude = [
305+
"node_modules/${mod.name}/package.json",
306306
"**/* *",
307307
]),`);
308308
if (url) {
@@ -355,7 +355,9 @@ function printNodeModuleAll(modules) {
355355
* property, print a skylark `node_binary` rule.
356356
*/
357357
function printNodeBinary(module, key, path) {
358-
const name = module.name === key ? key : `${module.name}_${key}`;
358+
let name = module.name === key ? key : `${module.name}_${key}`;
359+
// escape special characters like '@' and '/'
360+
name = name.replace('@', '').replace('/', '_')
359361
print(``);
360362
print(`node_binary(`);
361363
print(` name = "${name}_bin",`);
@@ -370,23 +372,23 @@ function printNodeBinary(module, key, path) {
370372
* package json and return it as an object.
371373
*/
372374
function parseNodeModulePackageJson(name) {
373-
const module = require(`../node_modules/${name}/package.json`);
375+
const mod = require(`../node_modules/${name}/package.json`);
374376

375377
// Take this opportunity to cleanup the module.bin entries
376378
// into a new Map called 'executables'
377-
const executables = module.executables = new Map();
378-
379-
if (Array.isArray(module.bin)) {
379+
const executables = mod.executables = new Map();
380+
381+
if (Array.isArray(mod.bin)) {
380382
// should not happen, but ignore it if present
381-
} else if (typeof module.bin === 'string') {
382-
executables.set(name, stripBinPrefix(module.bin));
383-
} else if (typeof module.bin === 'object') {
384-
for (let key in module.bin) {
385-
executables.set(key, stripBinPrefix(module.bin[key]));
383+
} else if (typeof mod.bin === 'string') {
384+
executables.set(name, stripBinPrefix(mod.bin));
385+
} else if (typeof mod.bin === 'object') {
386+
for (let key in mod.bin) {
387+
executables.set(key, stripBinPrefix(mod.bin[key]));
386388
}
387389
}
388390

389-
return module;
391+
return mod;
390392
}
391393

392394
/**

tests/helloworld/gen/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ genrule(
3131
# If the test passes, we probably emitted hello world
3232
node_test(
3333
name = "helloworld_test",
34+
size = "small",
3435
main = "helloworld.js",
3536
visibility = ["//visibility:public"],
3637
)

tests/polymer-cli/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ $ bazel build @yarn_modules//:polymer-cli_polymer_bin -- --help
1515
# Should be able to invoke polymer-cli as standalone script
1616
$ ./bazel-bin/external/yarn_modules/polymer-cli_polymer_bin --help
1717
```
18+
19+
> NOTE: currently this example is not working. When invoked,
20+
> polymer-cli_polymer_bin fails due to a missing module dependency `cycle`. It
21+
> is currently unclear why 'cycle' is being included but not linked in the
22+
> dependency tree.

tests/typescript/ts_module.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ _ts_module = rule(
134134
implementation = _ts_module_impl,
135135
attrs = {
136136
"srcs": attr.label_list(
137-
allow_files = FileType([".ts", ".tsx"]),
137+
allow_files = [".ts", ".tsx"],
138138
mandatory = True,
139139
),
140140
"deps": attr.label_list(

tests/webpack/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ sh_test(
3737
# file output implicitly invokes
3838
# webback to generate it
3939
)
40-

tests/webpack/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ breaks this strongly connected component into a separate pseudo
1212

1313
```sh
1414
# Should be able to run webpack directly
15-
$ bazel build @yarn_modules//:webback_bin -- --help
15+
$ bazel run @yarn_modules//:webpack_bin -- --help
1616

1717
# Should be able to invoke webpack as standalone script
1818
$ ./bazel-bin/external/yarn_modules/webpack_bin --help
@@ -22,4 +22,4 @@ $ bazel build :webpack_compile
2222

2323
# Should be able to invoke another (contrived) genrule
2424
$ bazel build :compile
25-
```
25+
```

0 commit comments

Comments
 (0)