bazel-contrib/rules_nodejs

Inquiry - How to build ts_project with rules_docker?

twheys opened this issue · 4 comments

Hello, I am trying to build my Bazel typescript project into a docker container using the container_image rule from rules_docker. Is there any recommended solution for setting the rootDirs?

"compilerOptions": {
    "rootDirs": [
        ".",
        "../../bazel-out/host/bin/path/to",
        "../../bazel-out/darwin-fastbuild/bin/path/to",
        "../../bazel-out/darwin_arm64-fastbuild/bin/path/to",
        "../../bazel-out/k8-fastbuild/bin/path/to",
        "../../bazel-out/x64_windows-fastbuild/bin/path/to",
        "../../bazel-out/darwin-dbg/bin/path/to",
        "../../bazel-out/k8-dbg/bin/path/to",
        "../../bazel-out/x64_windows-dbg/bin/path/to",
    ]
}

The issue with rules_docker is that it uses a Bazel transition which builds all of the ts_project targets in a different Bazel output dir which is suffixed with some hash that appears to change based on some factors unbeknownst to me (ie darwin_arm64-fastbuild-ST-4a519fd6d3e4), which makes it impossible to use the rootDirs workaround.

Is there any known solution to overcome this?

microsoft/TypeScript#37378 is the root cause bug.

https://github.com/bazelbuild/rules_nodejs/wiki/Migrating-to-5.0#nodejs_image-from-rules_docker documents this

You may also need to add more rootDirs entries to tsconfig since there is another output directory, see bazelbuild/rules_docker#1963 (comment)

Oh, and since I doubt the TypeScript team will ever resolve that issue or accept our PR, ultimately the likely fix seems to be our new approach in rules_js where we give up on teaching NodeJS about a "source tree and an output tree" and just run all node programs exclusively in the output tree.

Thanks for the feedback. Too bad we can't just write a glob pattern for root patterns and paths with typescript, that would solve this. On the other hand, it's quite annoying how bazel maintains the output directory structure inside the sandboxes but I guess that is necessary for a local strategy.

On the plus side, it seems like the transition output dirs are deterministic, I'm just not sure what parameters go into them. I know it uses at least the os, cpu, and bazel version.