bazelbuild / rules_nodejs

NodeJS toolchain for Bazel.

Home Page:https://bazelbuild.github.io/rules_nodejs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add .json files to DeclarationInfo as they can be a part of the typescript types definition

Mivr opened this issue Β· comments

πŸš€ feature request

Relevant Rules

js_library rule

Description

Adding .json files (not just package.json, but all .json files) to the typing info produced by the js_library.

Example of how tsc generates .d.ts files depending on .json files: https://stackoverflow.com/a/63220835

Describe the solution you'd like

Current state starting here:

 # register typings
        if file.is_directory:
            # assume a directory contains typings since we can't know that it doesn't
            typings.append(file)
        elif (
            (
                file.path.endswith(".d.ts") or
                file.path.endswith(".d.ts.map") or
                # package.json may be required to resolve "typings" key
                file.path.endswith("/package.json")
            ) and

Proposed change:

 # register typings
        if file.is_directory:
            # assume a directory contains typings since we can't know that it doesn't
            typings.append(file)
        elif (
            (
                file.path.endswith(".d.ts") or
                file.path.endswith(".d.ts.map") or
                # all .json files can be used in .d.ts files using type inferring (https://stackoverflow.com/a/63220835)
                # package.json is also sometimes needed and is added by this check
                file.path.endswith(".json")
            ) and

Describe alternatives you've considered

For now, the alternative is to not use type inferring in your .d.ts files.

Thanks for the good bug report πŸ‘

It looks like you already proposed a solution, would you like to open a PR? Would just need a test reproducing the issue along with the fix.