-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fine-grained npm_install & yarn_install deps #302
Conversation
a8e8d99
to
2aff2b5
Compare
internal/node/node.bzl
Outdated
must now declare either an explicit node_modules attribute, or | ||
list explicit deps[] or data[] dependencies on npm labels. | ||
|
||
See http://FIXME""" % ctx.label) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexeagle Would be good not to introduce this breaking change. Could we detect if the node_modules was not set and there were no fine grained deps and use the default of @//:node_modules
in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. I think I see what the reasoning is. We don't want to force users to define a //:node_modules
filegroup if they move to fine grained deps. rollup_bundle will also need to be updated to removed the @//:node_modules
default:
"node_modules": attr.label(
doc = """Dependencies from npm that provide some modules that must be resolved by rollup.""",
default = Label("@//:node_modules")),
Where were you thinking the http://FIXME
would point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the fixme should be a page on the wiki that explains the change and walk through how to do the upgrade
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const DEBUG = console.error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be const DEBUG = false;
like in node_loader.js
? It doesn't seem to be used here though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
internal/npm_install/test/check.js
Outdated
function check(updateGolden = false) { | ||
// We must change the directory to the BUILD file path | ||
// so the generator is able to run | ||
process.chdir('internal/npm_install/test') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change this to process.chdir(path.dirname(__filename))
you can remove the no_windows
tag from //internal/npm_install/test:test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant. Thanks!
NOTE: This can't be released until we have a bazel release that supports EDIT: This should be included in the 0.18.0 Bazel release scheduled for September ((bazelbuild/bazel#5963). |
.reduce((a, b) => a.concat(b), []) | ||
]; | ||
let nestedPkgDirs = []; | ||
pkgDirs.forEach(d => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking for nested packages is necessary but the way you've done it here isn't enough.
node modules can be arbitrarily nested, for example you could have:
node_modules/
bar/
baz/
foo/
node_modules/
bar/
node_modules/
baz/
It is important to traverse all the way down because the baz
that resides three levels deep may have different dependencies than the baz
that resides at the top-level node_modules (due to version differences). In this case, the transitive dependencies listed in the generated build file will not be accurate, since the baz
found in pkgDirs will be the top-level one and not contain the correct dependencies.
I think you can just continue recursing down the found packages until none of them add any packages. Eventually the leaf packages will not have a nested node_modules directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kitofans Thats a good point. I'll update the logic to handle arbitrary nested node_modules depth. Thanks!
w.r.t the label names including |
2aff2b5
to
0d6f095
Compare
@gregmagolan @alexeagle This work is really interesting for me, since I just spent some time writing similar internal rules to track NPM dependencies at this fine-grained level as opposed to the whole node_modules. Originally I was generated a node_modules folder to pass into the rules, but realised that involved a lot of copying etc... since I couldn't figure out how to symlink directories easily. See https://groups.google.com/d/topic/bazel-discuss/JbA19d3vBis/discussion Our main motivation was to be able to generate NPM packages directly from ts_library-like targets. By tracking every NPM dependency, we can generate the dependencies stanza of the package.json file. Rather than parsing the package.json file to figure out the transitive dependencies, I decided to just ignore hoisting with I'm also curious about the default global @//:node_modules target, since that was used in the TypeScript rules which meant it kept rebuilding everything anytime those dependencies changed. To fix this, and another issue, I extracted a slimmed down version of your TypeScript rules in-order to avoid depending on the default Any chance I can get access to the design document to understand if I can reuse more of this work? Interestingly enough, I also introduce a NodeModuleInfo provider with the exact same name :) Do you have some roadmap regarding these and the TypeScript rules? |
e4ff04c
to
027603f
Compare
@an-kumar I'd rather not introduce the |
9e5de42
to
aebfc38
Compare
@nimerritt The design doc should be publicly accessible here, https://docs.google.com/document/d/1AfjHMLVyE_vYwlHSK7k7yW_IIGppSxsQtPm9PTr1xEo/edit. I'll be updating the typescript rules next to support idiomatic JS-only npm distributions for rules_typescript (also in this design doc). |
Fixes #18 |
Eh. Labels names can't have colons, but we've figured out how to do Maven dependencies.
Bazel must be releasing on quicker schedule than in the past, since 0.17.0 isn't even out yet. |
46d7daf
to
6e180fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yum, really close!
.bazelci/presubmit.yml
Outdated
@@ -24,13 +24,14 @@ platforms: | |||
windows: | |||
run_targets: | |||
- "@nodejs//:yarn" | |||
build_flags: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like one of these is not used?
maybe just go back to the old content of this file, we should avoid a general mechanism for allowing things to be broken on windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was used but Filippe helped fix that windows test. will revert to old contents
docs/BUILD.bazel
Outdated
@@ -30,4 +30,7 @@ skylark_doc( | |||
format = "html", | |||
site_root = "/rules_nodejs", | |||
strip_prefix = "internal/", | |||
# Cannot build the docsite on Windows, see | |||
# https://github.com/bazelbuild/skydoc/issues/58 | |||
tags = ["no_windows"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
internal/npm_install/test/check.js
Outdated
|
||
Update the golden file: | ||
|
||
bazel run ${process.env['BAZEL_TARGET']}-accept`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to .accept
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
# Provide a lite version of the node_modules filegroup that includes | ||
# only js, d.ts and json files as well as the .bin folder. This can | ||
# be used in some cases to improve performance by reducing the number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might want to note bazelbuild/bazel#5769 here
since including files with no extension would fix the cases we know of where the "lite" group doesn't give all the files you need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
628ba03
to
34a9674
Compare
34a9674
to
9c4be2d
Compare
bcd45fc
to
b8955e8
Compare
Note to anyone who is going to try this out before it makes it into the next tagged release: You'll need use the following rules_typescript commit: bazelbuild/rules_typescript#267 which should land soon but for now its on my fork of rules_typescript. EDIT: bazelbuild/rules_typescript#267 landed so you can now use bazelbuild/rules_typescript HEAD |
Bazel 0.18 warns about the tools/bazel.rc file Closes bazel-contrib#302 PiperOrigin-RevId: 217397650
Bazel 0.18 warns about the tools/bazel.rc file Closes bazel-contrib#302 PiperOrigin-RevId: 217397650
No description provided.