rules_nodejs icon indicating copy to clipboard operation
rules_nodejs copied to clipboard

ts_project doesn't include package.json in transitive typings

Open noveyak opened this issue 6 years ago • 3 comments

🚀 feature request

ts_project rules should be able to depend on each other, without including their transitive npm deps

Relevant Rules

ts_project

Description

Not sure if I am using ts_project incorrectly, I tried searching and found a somewhat related issue about ts_project rules referencing other ts_project rules https://github.com/bazelbuild/rules_nodejs/issues/1896 so perhaps I should be using an intermediate rule? I've recently tried switching some ts_library rules over to ts_project because of the greater flexibility of the rule

ts_project(
    name = "inner_dep",
    srcs = ["inner_dep.ts"],
    deps = [
      "@npm//sequelize-typescript"
    ],
    tsconfig = "//ts:tsconfig.json",
    declaration = True,
)


ts_project(
    name = "test",
    srcs = ["test.ts"],
    deps = [
     ":inner_dep"
    ],
    tsconfig = "//ts:tsconfig.json",
    declaration = True,
)

Something I experienced was that if inside inner_dep, I have a class which extends something from sequelize-typescript, when building test, ts_project wouldn't be able to find methods on classes that extend sequelize-typescript. I noticed this only happens on some deps and found that this is because inside their package.json, there is an entry

"types": "dist/index.d.ts",

When using ts_library, the package.json would be in the input files when building test, but when using ts_project, only the typing files are available so tsc cannot find the file. If I change the test rule to use ts_library, it seems to build ok even when keeping inner_dep as ts_project. I did a bit of messing around and found that adding the node_modules_aspect that ts_library had in it's deps seemed to make ts_project behave ok but don't really have any idea if that's even the right way to approach this.

Describe the solution you'd like

Ideally I would just like ts_project to behave like ts_library in this case and be able to depend on each other without having to add @npm//sequelize-typescript to the deps of test

Describe alternatives you've considered

I know ts_library works and I hacked in node_modules_aspect but would like to see if there is a better way

noveyak avatar Jul 16 '20 10:07 noveyak

ts_project does forward all the typings to downstream projects https://github.com/bazelbuild/rules_nodejs/blob/master/packages/typescript/internal/ts_project.bzl#L162 but as you observe, the package.json file isn't included in the typings. Let me see if I can repro easily...

alexeagle avatar Jul 19 '20 17:07 alexeagle

Thanks for the clear issue report! last bugfix squeezing into the 2.0 release 😁

alexeagle avatar Jul 20 '20 19:07 alexeagle

yup, just tried 2.0 and it works for me now - thanks!

noveyak avatar Jul 21 '20 21:07 noveyak