rules_nodejs icon indicating copy to clipboard operation
rules_nodejs copied to clipboard

npm_package doesn't handle siblings ts_library targets

Open nimerritt opened this issue 8 years ago • 6 comments

It's a bit tricky to describe but a minimal example is given here: https://github.com/Springworks/rules_nodejs_min_pub/tree/adbe6b964d60c7ccaa4704ed3f2d2df40f680c1e

In short if there are dependencies which are not children in the filesystem tree they seem to not get bundled.

Given the super_package/BUILD.bazel

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

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

I would have expected "another_library" and "some_library" to get pulled into the NPM package, but the resulting package tree looks like:

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

nimerritt avatar May 08 '18 14:05 nimerritt

We have to know what path these should have inside the resulting bundle, and we use the input filesystem to figure this out.

a/
  npm_package
  file1
  b/
    file2

it's clear the resulting package ought to contain

file1
b/file2

But if you bring in dependencies that are not in the same package with the npm_package rule, where should they be laid out in the output tree? Would they always be flattened into the root? It's hard to specify this.

alexeagle avatar May 08 '18 15:05 alexeagle

Probably the right solution here is to use the additional_root_dirs attribute from ts_devserver for consistency. Then we'd consult that list when copying files, and if an input is not in a subdirectory of the target, we'd normalize its path to the longest of the additional_root_dirs that it's a child of. @gregmagolan can I assign this one to you since you're looking at the root dirs loading for ts_devserver and ts_web_test_suite?

alexeagle avatar May 12 '18 16:05 alexeagle

@alexeagle Sounds good

gregmagolan avatar May 12 '18 19:05 gregmagolan

@alexeagle I don't agree with this approach What is being described is a peer dependency and should be expressed as one in the package.json just as angular/angular does when it publishes.

Toxicable avatar May 31 '19 21:05 Toxicable

This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

github-actions[bot] avatar Nov 19 '20 01:11 github-actions[bot]

This issue was automatically closed because it went two weeks without a reply since it was labeled "Can Close?"

github-actions[bot] avatar Dec 03 '20 01:12 github-actions[bot]