Giter Club home page Giter Club logo

Comments (6)

alexeagle avatar alexeagle commented on June 15, 2024

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.

bazaglia avatar bazaglia commented on June 15, 2024

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.

alexeagle avatar alexeagle commented on June 15, 2024

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.

bazaglia avatar bazaglia commented on June 15, 2024

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.

bazaglia avatar bazaglia commented on June 15, 2024

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.

alexeagle avatar alexeagle commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.