lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.54k stars 499 forks source link

Feature request: Support "exports" and "imports" in package.json #1659

Open JavaScriptBach opened 2 months ago

JavaScriptBach commented 2 months ago

Sorting

Expected Behavior

I work in a Typescript mono-repo, where all our imports are bare imports instead of relative imports. We define exports and imports in package.json to control what each package exports. It would be great if tsoa knew how to resolve these imports.

See https://github.com/JavaScriptBach/tsoa-repro for an example.

Current Behavior

tsoa does not know how to resolve these imports:

Generate routes error.
 GenerateMetadataError: No declarations found for referenced type User.
    at TypeResolver.getModelTypeDeclarations (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:871:62)
    at TypeResolver.calcRefTypeName (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:536:39)
    at TypeResolver.calcTypeReferenceTypeName (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:712:34)
    at TypeResolver.getReferenceType (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:721:35)
    at TypeResolver.resolveTypeReferenceNode (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:468:21)
    at TypeResolver.resolve (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:293:21)
    at TypeResolver.resolveTypeReferenceNode (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:458:93)
    at TypeResolver.resolve (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:293:21)
    at MethodGenerator.Generate (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:62:78)
    at /Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:46:41
error Command failed with exit code 1.

Steps to Reproduce

https://github.com/JavaScriptBach/tsoa-repro

Context (Environment)

Version of the library: 6.4.0 Version of NodeJS: 18.14.0

Detailed Description

It would be nice if tsoa understand how to resolve these fields:

These fields have been around since ~Node 12 and all major tooling (e.g. Typescript, bundlers) know how to understand them.

Currently, I can hack around this issue by passing custom tsconfig options to tsoa. But this is not ideal because I have to define the import paths in 2 different locations (package.json and in tsoa).

Breaking change?

This could break generation depending on what users have defined in their exports or imports in package.json.

github-actions[bot] commented 2 months ago

Hello there JavaScriptBach 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

JavaScriptBach commented 1 month ago

Bump

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

JavaScriptBach commented 2 weeks ago

Bump