Repository navigation
Fine-grained npm_install & yarn_install deps - #302
Conversation
| 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.
@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.
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.
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.
Shouldn't this be const DEBUG = false; like in node_loader.js? It doesn't seem to be used here though.
| 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.
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.
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.
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.
@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 |
|
@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? |
|
@an-kumar I'd rather not introduce the |
|
@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. |
| windows: | ||
| run_targets: | ||
| - "@nodejs//:yarn" | ||
| build_flags: |
There was a problem hiding this comment.
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.
it was used but Filippe helped fix that windows test. will revert to old contents
| strip_prefix = "internal/", | ||
| # Cannot build the docsite on Windows, see | ||
| # https://github.com/bazelbuild/skydoc/issues/58 | ||
| tags = ["no_windows"], |
|
|
||
| Update the golden file: | ||
|
|
||
| bazel run ${process.env['BAZEL_TARGET']}-accept`); |
|
|
||
| # 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.
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
|
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.