rules_nodejs icon indicating copy to clipboard operation
rules_nodejs copied to clipboard

npm_package does not bundle transitive type declarations

Open nimerritt opened this issue 8 years ago • 2 comments

When packaging a ts_library target using npm_package only the direct dependencies' declaration files are included. This can be seen by trying to run yarn build from within the super_app directory in the example here: https://github.com/Springworks/rules_nodejs_min_pub/tree/02c43b5690e1daccad15417455ecc322a65f2c8d

In short, given a BUILD.bazel file such as:

ts_library(
    name = "super_library",
    srcs = ["index.ts"],
    deps = ["//super_package/another_library", "//super_package/some_library"],
    tsconfig = "//:tsconfig.json",
)

npm_package(
    name = "super_package",
    srcs = ["package.json"],
    deps = [":super_library"],
    replacements = { "demo/super_package/": "" },
)

the resulting package is missing the transitive index.d.ts files for "another_library" and "some_library" which causes errors when trying to consumer the NPM package with the TypeScript compiler.

bazel-bin/super_package/super_package
├── another_library
│   └── index.js
├── index.d.ts
├── index.js
├── package.json
└── some_library
    └── index.js

nimerritt avatar May 08 '18 12:05 nimerritt

I tried to fix this unsuccessfully with this PR: https://github.com/bazelbuild/rules_nodejs/pull/195

nimerritt avatar May 08 '18 12:05 nimerritt

I had a look a the Angular repo and if I understood correctly you avoid this problem by basically having the ng_module targets 1-1 with the ng_package and only ever sharing types directly like https://github.com/angular/angular/blob/77ff72f93b86e57ba3fdc67a60a5b00c69c9a824/packages/core/BUILD.bazel#L15

The reason this is relevant is that we are using the rules_typescript internally to build parts of our code base but have a need to publish parts of the monorepo by re-exporting several ts_libraries as a single NPM package for our non-Bazel projects. Ideally we'd move everything to Bazel and avoid having to publish to NPM entirely but that currently isn't a possibility. It might be possible to restructure the code to match the Angular project format but it is unfortunate that we can't some how just bundle different ts_library targets under a single index.ts and publish that.

nimerritt avatar May 08 '18 12:05 nimerritt