Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts_project doesn't include package.json in transitive typings #2044

Closed
noveyak opened this issue Jul 16, 2020 · 3 comments
Closed

ts_project doesn't include package.json in transitive typings #2044

noveyak opened this issue Jul 16, 2020 · 3 comments
Labels

Comments

@noveyak
Copy link
Contributor

noveyak commented Jul 16, 2020

🚀 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 #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

@alexeagle
Copy link
Collaborator

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 alexeagle changed the title Improved ts_project transitive node_module interop ts_project doesn't include package.json in transitive typings Jul 19, 2020
alexeagle pushed a commit to alexeagle/rules_nodejs that referenced this issue Jul 19, 2020
Error now is:
ERROR: /Users/alex.eagle/Projects/rules_nodejs/packages/typescript/test/ts_project/b/BUILD.bazel:6:1: Compiling TypeScript project //packages/typescript/test/ts_project/b:tsconfig [tsc -p packages/typescript/test/ts_project/b/tsconfig.json] failed (Exit 2) tsc.sh failed: error executing command bazel-out/host/bin/external/npm/typescript/bin/tsc.sh --emitBOM --project packages/typescript/test/ts_project/b/tsconfig.json --outDir ... (remaining 7 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/darwin-fastbuild/bin/packages/typescript/test/ts_project/a/a.d.ts(2,41): error TS2307: Cannot find module '@babel/parser'.
alexeagle pushed a commit to alexeagle/rules_nodejs that referenced this issue Jul 19, 2020
It may be needed in transitive compilations to resolve the "typings" key

Fixes bazel-contrib#2044
alexeagle pushed a commit that referenced this issue Jul 20, 2020
Error now is:
ERROR: /Users/alex.eagle/Projects/rules_nodejs/packages/typescript/test/ts_project/b/BUILD.bazel:6:1: Compiling TypeScript project //packages/typescript/test/ts_project/b:tsconfig [tsc -p packages/typescript/test/ts_project/b/tsconfig.json] failed (Exit 2) tsc.sh failed: error executing command bazel-out/host/bin/external/npm/typescript/bin/tsc.sh --emitBOM --project packages/typescript/test/ts_project/b/tsconfig.json --outDir ... (remaining 7 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/darwin-fastbuild/bin/packages/typescript/test/ts_project/a/a.d.ts(2,41): error TS2307: Cannot find module '@babel/parser'.
@alexeagle
Copy link
Collaborator

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

@noveyak
Copy link
Contributor Author

noveyak commented Jul 21, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants