Skip to content

sourceTypes doesn't work with module entrypoints. #797

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

Open
MattGson opened this issue Jan 25, 2021 · 3 comments
Open

sourceTypes doesn't work with module entrypoints. #797

MattGson opened this issue Jan 25, 2021 · 3 comments

Comments

@MattGson
Copy link

sourceTypes fails to find any types unless the exact file that contains the type declaration is specified.

i.e.

Structure:

 moduleOne/
     index.ts -> exports from modelOne and modelTwo
     modelOne.ts
     modelTwo.ts
    ...

Config:

sourceTypes: {
        modules: [
            {
                module: path.join(__dirname, 'moduleOne/index.ts'),
                alias: 'moduleOne',
            },
           ...
        ],
    },

This fails to recognise any source types.
But if index.ts is changed to modelOne.ts then the types from modelOne work as expected.

This means that unless all types/models are stored in a single file (who does that???) then we have to manually specify every model file. This gets very laborious when we have hundreds of files.

@Sytten
Copy link
Collaborator

Sytten commented Feb 10, 2021

Try:

{
        alias: 'models',
        module: path.join(__dirname.replace(/\/dist$/, '/src'), './moduleOne/index.ts'),
        typeMatch: type => [new RegExp(`(${type.name}[ ,]+)`)], // Note: This will match any declared type in models if the name matches
      },

That is what I do for my projects and it works well.

@MattGson
Copy link
Author

MattGson commented Feb 14, 2021

@Sytten I am doing something similar but unless I misunderstand, the type name must still exist in index.ts?

As in:

// index.ts
 export * from './modeOne.ts'

will not work but:

// index.ts
 export { modelOne } from './modeOne.ts'

works fine.

Ideally I would be able to use barrels like the first example.

@Sytten
Copy link
Collaborator

Sytten commented Feb 14, 2021

Its a dumb text regex search so no, the star export won't work :s

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

No branches or pull requests

2 participants