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

Top level type declaration is not created #7

Closed
dgpt opened this issue Nov 5, 2021 · 2 comments
Closed

Top level type declaration is not created #7

dgpt opened this issue Nov 5, 2021 · 2 comments

Comments

@dgpt
Copy link

dgpt commented Nov 5, 2021

Hiya, first off - thanks for making this plugin! It's super helpful.

I spent the last 12 hours banging my head against the wall trying to figure out how to get this loader to work correctly. All of the types were being generated and I was successfully copying them over to my other services using webpack-remote-types-plugin and tar-webpack-plugin to generate the tgz archives. However, my TSServer could not find the type declarations.

It turns out, the top-level type declaration file that should be a sibling to the dts file in the generated types directory was not being generated. So I added some logging to the code to figure out what was going wrong. I realized that my exposes config looked like this:

  exposes: {
    './theme': './src/themes',
    './helpers': './src/helpers',
    './constants': './src/constants',
    './sentry': './src/sentry'
  },

while your logic expects explicit module paths like:

  exposes: {
    './theme': './src/themes/index.ts',
    './helpers': './src/helpers/index.ts',
    './constants': './src/constants/index.ts',
    './sentry': './src/sentry/index.ts'
  },

Easy enough to workaround, but Module Federation works with the implicit index paths. It would save a lot of future headaches to add some support for implicit paths out of the box (also I generally prefer using the implicit paths because it looks neater).

@ruanyl
Copy link
Owner

ruanyl commented Nov 5, 2021

Hey @dgpt Thanks for the feedback, I will take a look soon, but PR is welcome if you already came up with a fix :)

@dgpt
Copy link
Author

dgpt commented Nov 5, 2021

I spent some time digging into this a bit. Ideally we'd use Typescript's module resolution logic directly (to avoid re-implementing the resolution logic), but I can't seem to figure out a good way to do this. I'm thinking it might be possible to do this with the typescript object, but A) trying to find documentation for this is proving to be impossible and B) there's a lot of stuff to sift through. Since you've been using the typescript object in the plugin already, you might have some more insight into this :)

I've also tried using node's require.resolve, but that doesn't seem to like the absolute paths we have in emitFile.

If we just put inputFilePath into the resolver function (wherever it may be) on line 119 in emitFile, I think we'd be in business.

                const inputFilePath = path.resolve(cwd, value)
                if (inputFilePath === fileName) {

@ruanyl ruanyl closed this as completed in e8d1174 Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants