Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
This repository was archived by the owner on May 22, 2025. It is now read-only.

Resolving module's name within node_modules #1039

Open
@theseanl

Description

@theseanl

I'm trying to use tsickle to write externs from type declarations from DefinitelyTyped packages.

Although typescript does not transpile *.ts files in node_modules/@types by default, by manually providing them to the compiler, it was possible to trigger tsickle to generate externs for them.

However, for type packages that are using module name with relative paths (e.g. lodash), tsickle generates broken externs, because module names are resolved with resolveModuleName function and the resolved path is in a node_modules directory relative to the current typescript project root. Then tsickle does not resolve such names and writes externs on inconsistent namespaces.

Would there be any way to properly generate externs in such a use case?

It would have worked if resolveModuleName have discarded resolved path iff it is piercing node_modules package boundary, i.e.

  • For a file, its package boundary is its nearest ancestor node_module directory's child directory.
  • Discard resolved and return imported literally only if a package boundary of pathOfImportingFile and resolvedModule is different.

and it looks like to be a behavior that was intended from the beginning, if such a change would not break other projects using tsickle, would it be possible to adopt such changes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions