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

[Bug]: Not Checking Transitive Dependencies Package.json "types" field #429

Open
mstier-nflx opened this issue Aug 28, 2023 · 4 comments
Open
Labels
bug Something isn't working more info needed More info needed to proceed further

Comments

@mstier-nflx
Copy link

mstier-nflx commented Aug 28, 2023

What happened?

I am have been having build issues related to incorrect types being produced by my Bazel builds. I have a package where it has a "types" field defined in its package json as "types" : "dist/types/lib/index.d.ts". I am seeing the package build correctly with the index.d.ts files placed correctly.

However when I pull the package into another project and build using Bazel, I produce a new index.d.ts file with the transitive type set to "any". When I build using a different tool (razzle), it is correctly generating the new index.d.ts file with the transitive type set correctly.

I noticed when I go back to the original package and rebuild it using no "declarationDir" in the tsconfig.json, it produces the "index.d.ts" in the root (as expected). Then when I pull the package into my other project, Bazel starts to produce the new index.d.ts with transitive types correctly. This looks like its related to bazelbuild/rules_nodejs/issues/2044

Version

Development (host) and target OS/architectures: MacOs

Output of bazel --version: 6.3

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: aspect_rules_ts@1.4.5

Language(s) and/or frameworks involved: Typescript

How to reproduce

Create a subpackage (call it foo) with a types file located at a non standard location.  Example: "dist/types/lib/index.d.ts".

Pull package into project (call it bar) and have it export its type.  Example: import {stuff} from  "foo" 

export const new_stuff = {
  ...stuff,
  //I add more fields here typically
}

After building bar, bar's index.d.ts reads "export declare const new_stuff: any;"  Which is incorrect.  

bar's index.d.ts should read "export declare const new_stuff: {
    field1: string;
    field2: string;
    ... etc.
}"

Any other information?

No response

@mstier-nflx mstier-nflx added the bug Something isn't working label Aug 28, 2023
@github-actions github-actions bot added the untriaged Requires traige label Aug 28, 2023
@alexeagle
Copy link
Member

Could you describe more what you mean by "Pull package into project (call it bar) " - are you doing an npm publish to a registry and then fetching it back from the registry again? Using git submodule or npm_package or some other way?

@alexeagle alexeagle added more info needed More info needed to proceed further and removed untriaged Requires traige labels Aug 31, 2023
@mstier-nflx
Copy link
Author

We have workspaces configured. Bar and foo live under the same root project. https://docs.npmjs.com/cli/v7/using-npm/workspaces

@mstier-nflx
Copy link
Author

We have a configuration for foo setup in our BUILD.bzl at the root. npm_link_package( name = "node_modules/@rule-ts-transitive-dep-issues-example/foo-package", src = "//foo:dist", )

Our foo project has a ts_project setup like ts_project( name = "src_ts", srcs = SRCS, composite = True, declaration = True, declaration_dir = "types", resolve_json_module = True, tsconfig = ":ts_config", supports_workers = False, visibility = ["//visibility:public"], deps = [ "//:node_modules/@rule-ts-transitive-dep-issues-example/foo-package", ] , ) SRCS = glob(include = [ "index.ts", "package.json", ])

@mstier-nflx
Copy link
Author

I created a test repo based on what I was using, (not the cleanest) but the instructions are in the README.md Test Repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working more info needed More info needed to proceed further
Projects
Status: No status
Development

No branches or pull requests

2 participants