Comments (6)
As you probably saw, there's a proposal likely to land to remove managed_directories
.
The recommended way to teach TS language service about mapping package names to locations in the monorepo is with the paths
property, aka. path mapping.
You can still run pnpm install
to get a local node_modules
folder for the IDE. How else is rules_js different from rules_nodejs without managed_directories?
from rules_js.
The only difference I can think of now is that the rules_nodejs's js_library links local packages to the node_modules. Wondering how to achieve the same behavior with rules_js?
Example based on my use case: I have a lot of protobuf definitions and a target that outputs interfaces for them. They're local js libraries that need to be available at the IDE.
from rules_js.
rules_js also links local packages into the node_modules. However the bazel-bin/path/to/package/node_modules
tree is created lazily as actions run that require populating it with symlinks to the pnpm store.
Protobufs are a problem across all languages. See recent chatter about this in #go on bazel slack like https://bazelbuild.slack.com/archives/CDBP88Z0D/p1652721846297049.
The practical answer, though not "bazel-idiomatic", is to output the generated proto stubs to the source tree for non-Bazel tooling to be able to locate them. Anything else is an uphill battle against the expectations of those tools.
from rules_js.
Maybe I've missed something or the docs don't state it yet, but I just realized not only the js_package targets aren't linked to node_modules, but my application doesn't find the package at all.
If I have my js_package
like:
js_package(
name = "my_package",
srcs = [":compile_ts"], # aspect swc rule that transpiles .ts to .js
package = "my-package-name",
replace_prefixes = {
"src/": "",
},
)
When I include the target to "my_package" in the data
array on the swc
or js_binary
targets, the build succeeds, but I can't see anything linked in the node_modules inside the bazel-bin and my application throws Error: Cannot find module 'my-package-name'
.
from rules_js.
Got it! I needed to use the link_js_package
rule:
load("@npm//:defs.bzl", "link_js_packages", "package")
load("@aspect_rules_js//js:defs.bzl", "link_js_package")
link_js_packages()
link_js_package(
name = package("my-package-name").name,
src = "//backend/packages/my-package:my_package",
deps = [package("protobufjs")],
)
Then instead of providing my package target in the data, I pass package("my-package-name")
:
swc(
name = "compile_ts",
srcs = glob(["src/**/*.ts"]),
data = [
package("my-package-name"),
"@npm//joi",
],
source_maps = True,
swcrc = ".swcrc",
)
I only noticed afterward that there was an example in this repo. My bad. Thank you for the nice discussion above. Like you said I'll use the paths
for mapping dependencies in the IDE. The node_modules in the bazel-bin indeed has it all linked.
from rules_js.
Ha, I was struggling with this too and your answer helped me in rules_ts. It's very new and needs more docs and better error messages.
Let me know if there's still something to fix (including where the error handling) could be more helpful)
from rules_js.
Related Issues (20)
- [BUG]: registry field without a scope should be respected
- [FR]: Allow to use targets without `JsInfo` in `js_run_binary.args` HOT 1
- [Bug]: ts-protoc-gen package isn't generating a package_json.bzl even though it looks like it should HOT 3
- [Bug]: `js_image_layer` does not play nice with external workspaces HOT 6
- [Bug]: failures with future config_setting visibility rules
- [FR]: Relative runfiles resolution
- [FR]: Support for other runtimes like Bun HOT 2
- [Bug]: changes to js_binary recreate both app and node_module in js_image_layer rule
- [Bug]: js_image_layer fails to build if js_binary contains an indirect cc_library data dependency
- [FR]: `npm_translate_lock` bins should be available when running custom_postinstalls
- [Documentation] npm_import and transitive dependencies HOT 1
- [Bug]: RUNFILES dir resolution sometimes wrong in "transitive" case
- Error message not helpful when virtual store not linked HOT 2
- [dev]: enable buildifier 'out-of-order-load' warning
- [Bug]: Bazel managed pnpm can't resolve pnpm-lock.yml file merge conflicts HOT 1
- [FR]: Consider hosting framework-specific "contrib" HOT 1
- [Bug]: pnpm 8.6.7 doesn't work when invoked through @pnpm//:pnpm js_binary HOT 6
- [FR]: Allow setting of use_default_shell_env in js_run_binary HOT 2
- [FR]: Native node:test support in js_test HOT 3
- [FR]: support env_inherit attr on js_test
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rules_js.