You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
promote the js_library rule to the public API #149
I looked through the definitions file and couldn't find any nodejs_library definition, does that means that I can only have exactly one global BUILD and have a monolithic building process?
I think the point would be to have multiple nodejs packages that reference one another in the same repository. e.g:
/path/to/first/package
/path/to/second/package (dependent on first package)
/path/to/some/binary (dependent on second package; transitively dependent on first package)
/path/to/first/package
BUILD.bazel
ts_library(name = "first", module_name = "first", srcs =["first.ts"])
/path/to/second/package
BUILD.bazel
ts_library(name = "second" module_name = "second", srcs = ["second.ts"], deps = ["//path/to/first/package:first"])
second.ts
import * as f from 'first';
/path/to/some/binary
BUILD.bazel
ts_library(name = "program", deps = ["//path/to/second/package:second"], srcs = ["program.ts"])
nodejs_binary(name = "bin", deps = [":program"], ...)
program.ts
import * as s from 'second';
If you don't use TypeScript, this is still supported, but not yet documented because we aren't sure we understand the use case (why use Bazel if you're not running any compilers?)
@alexeagle Our use case would be to have shared code between different rollup bundles. Both would then just define that common js_library as a dep. Or would you there just directly depend on the files?
Edit: To be more precise, that particular use-case I am describing is in a monorepository structure, so it would be something like:
/WORKSPACE
/common # shared es6 modules
/app1 # rollup_bundle depending on some libraries in common
/app2 # rollup_bundle depending on some libraries in common
...
Edit 2:
Also something like a babel_library could be interesting to allow incremental babel transpilation.
@Globegitter we would also benefit from a babel rule as we are migrating a large service to TypeScript and it's nice to use Bazel to mix between the two as we move forward, especially given that the TypeScript rules don't take .js files.
@alexeagle well, similar to how in second.ts you can import from 'first', it would be nice if in a second.js you could require('first'). In this sense, the compilation is happening in the nodejs_binary rule, where the modules are being used -- creating a runnable nodejs binary with it's declared dependencies and transitive dependencies correctly in the node_modules path with the correct names.
Yeah also the one thing about no nodejs_library because it does not compile - isn't it the same as python_library? Not sure if that is doing much either. But yeah happy to try filegroup for now and can hopefully get around to PRing a babel_library.
@an-kumar nodejs_binary has no compile-time deps, only runtime deps. Bazel typically uses data[] for the latter, so that's where your .js files should end up to be require-able at runtime.
Is there any change needed for this issue, or can I close it?
For this issue, I still suspect the .js files can be a filegroup in the data of a ts_library - you wouldn't type-check your usage of the JS code from TypeScript, just need it to be present to require it at runtime.
I'm still looking for a concrete use case that requires some change here...
Now that I have had some time to evaluate things more and after the insights gainedin #200, I think what I would expect from bazel for our use-case is to provide a js_library which can create the AMD output as expected by ts_devserver (better even js_devserver in the future) then other rules could be easily written on top of that, such as babel_library or json_to_js_library producing the same amd output for dev and es6 module output for prod/rollup. Does that make sense?
we ran into the issue that pkg_npm produces a TreeArtifact (output directory) which means it can't also supply individual file outputs to satisfy providers like DeclarationInfo. So it needs to have a non-directory output mode.
This would be a non-breaking change so we'll put it off until 2.x after 2.0
Activity
alexeagle commentedon Mar 12, 2018
what would you expect such a
nodejs_libraryrule to do?If you want to compile libraries in isolation, use a compile-to-JS rule like
ts_libraryIf you want to publish a package to npm, use
npm_packagean-kumar commentedon Mar 20, 2018
I think the point would be to have multiple nodejs packages that reference one another in the same repository. e.g:
/path/to/first/package
/path/to/second/package (dependent on first package)
/path/to/some/binary (dependent on second package; transitively dependent on first package)
alexeagle commentedon Mar 23, 2018
@an-kumar yes, this is supported already
For TypeScript, you have
If you don't use TypeScript, this is still supported, but not yet documented because we aren't sure we understand the use case (why use Bazel if you're not running any compilers?)
https://github.com/bazelbuild/rules_nodejs/blob/befbd8961c18de98e254bea94db08ede78889f86/internal/js_library/js_library.bzl
lets you assign the
module_namejust like above TS exampleGlobegitter commentedon Mar 25, 2018
@alexeagle Our use case would be to have shared code between different rollup bundles. Both would then just define that common js_library as a dep. Or would you there just directly depend on the files?
Edit: To be more precise, that particular use-case I am describing is in a monorepository structure, so it would be something like:
Edit 2:
Also something like a babel_library could be interesting to allow incremental babel transpilation.
alexeagle commentedon Apr 3, 2018
you can just use a plain
filegrouprule if you want to be able to reference the same group of.jsinputs in several different bundling rules.babel_librarysounds like a great addition, want to try a PR for that?nimerritt commentedon Apr 6, 2018
@Globegitter we would also benefit from a babel rule as we are migrating a large service to TypeScript and it's nice to use Bazel to mix between the two as we move forward, especially given that the TypeScript rules don't take .js files.
an-kumar commentedon Apr 21, 2018
@alexeagle well, similar to how in second.ts you can import from 'first', it would be nice if in a second.js you could require('first'). In this sense, the compilation is happening in the nodejs_binary rule, where the modules are being used -- creating a runnable nodejs binary with it's declared dependencies and transitive dependencies correctly in the node_modules path with the correct names.
this doesn't seem doable with plain filegroups.
an-kumar commentedon Apr 21, 2018
@alexeagle it also doesnt seem like nodejs_binary has a deps attribute, am i missing something about your ts example?
Globegitter commentedon Apr 25, 2018
Yeah also the one thing about no nodejs_library because it does not compile - isn't it the same as
python_library? Not sure if that is doing much either. But yeah happy to tryfilegroupfor now and can hopefully get around to PRing ababel_library.alexeagle commentedon Apr 27, 2018
@an-kumar nodejs_binary has no compile-time deps, only runtime deps. Bazel typically uses
data[]for the latter, so that's where your .js files should end up to berequire-able at runtime.Is there any change needed for this issue, or can I close it?
prestonvanloon commentedon May 11, 2018
You can't use a filegroup as a dep of
ts_librarybecause it doesn't have a "JS" attribute.+1 to implement js_library.
Also see bazelbuild/rules_typescript#201
alexeagle commentedon May 11, 2018
There actually is
js_libraryalready. It's undocumented because I'm not sure about all the use cases.https://github.com/bazelbuild/rules_typescript/blob/63bb1a33f5231c72d7d503454e986e10139ed2ff/BUILD.bazel#L64 is an example where we use it - not because it produces outputs that a filegroup wouldn't, but because we want a place to mark some extra info (in this case the AMD module name mapping, but it can also be useful for ESModule name mapping)
For this issue, I still suspect the
.jsfiles can be a filegroup in thedataof a ts_library - you wouldn't type-check your usage of the JS code from TypeScript, just need it to be present torequireit at runtime.I'm still looking for a concrete use case that requires some change here...
[-]no nodejs_library definition[/-][+]promote the js_library rule to the public API[/+]Globegitter commentedon May 15, 2018
Now that I have had some time to evaluate things more and after the insights gainedin #200, I think what I would expect from bazel for our use-case is to provide a
js_librarywhich can create the AMD output as expected byts_devserver(better evenjs_devserverin the future) then other rules could be easily written on top of that, such asbabel_libraryorjson_to_js_libraryproducing the same amd output for dev and es6 module output for prod/rollup. Does that make sense?18 remaining items
pward123 commentedon Feb 28, 2020
This looks great!
Would it be possible to support rollup_bundle so that @rollup/plugin-node-resolve automatically bundles monorepo dependencies?
alexeagle commentedon Jun 15, 2020
we ran into the issue that pkg_npm produces a TreeArtifact (output directory) which means it can't also supply individual file outputs to satisfy providers like DeclarationInfo. So it needs to have a non-directory output mode.
This would be a non-breaking change so we'll put it off until 2.x after 2.0
feat: promote js_library to public API
feat: promote js_library to public API
feat: promote js_library to public API
feat: promote js_library to public API
feat: promote js_library to public API
feat: promote js_library to public API
feat: promote js_library to public API
Produce a nodejs profile together with a perf_trace. (bazel-contrib#149)
Produce a nodejs profile together with a perf_trace. (bazel-contrib#149)
fix: test file pattern (bazel-contrib#2089)