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

Generated import paths strips anything preceded by a dot (file.dto.ts ...) #306

Closed
ChronicStone opened this issue Dec 18, 2023 · 11 comments
Closed

Comments

@ChronicStone
Copy link

Environment


  • Operating System: Darwin
  • Node Version: v18.16.0
  • Nuxt Version: 3.8.2
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: bun@1.0.7
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Here's a stackblitz minimal reproduction :
https://stackblitz.com/edit/nuxt-starter-jxv1vc?file=.nuxt%2Ftypes%2Fimports.d.ts

Describe the bug

  1. A folder 'services' contains a file 'demo.service.ts
  2. services forlder is flagged for auto import on config

Produced entry on imports.d.ts :

  const someDemoFunction: typeof import('../../services/demo')['someDemoFunction']

The '.service' part of the file name have been stripped away

Additional context

No response

Logs

No response

@niko-chaffinchicas
Copy link

Seeing this issue as well, specifically stripping the .store from files being auto-imported in Nuxt 3.8.2.

@nathanchase
Copy link

nathanchase commented Dec 20, 2023

I also name my Pinia stores [x].store.ts and this import bug causes all of the Pinia stores to be untyped as a result.

@niko-chaffinchicas
Copy link

@ChronicStone @nathanchase Looks like this is a complication from the resolvePath function that Nuxt sets in the options when it calls generateTypeDeclarations. It may be best to open an issue on Nuxt itself or move this issue there.

I'm gonna take a stab at making a PR that could address this there. 🤞

@niko-chaffinchicas
Copy link

Still going to open a PR on the Nuxt repo itself, but it doesn't look like I can 100% do what we want. It would be beneficial if an option could be set when calling toTypeDeclarationItems that allows you to disable the default extension stripping logic in favor of your own.

The issue Nuxt runs into is that the addon for vue-templates calls options.resolvePath, but doesn't strip the file extension from the result like toTypeDeclaration is noted to do above.

@niko-chaffinchicas
Copy link

Alternatively, being able to specify option overrides for addons specifically as opposed addons always inheriting the general options would work, as it would allow Nuxt to alter the resolvePath method based on whether or not it knows that unimport will strip the file extension.

@antfu
Copy link
Member

antfu commented Dec 28, 2023

Fixed in 1d31ff2, thanks

@kiki-kanri
Copy link

kiki-kanri commented Dec 28, 2023

Sorry, the problem is actually related to the pr, but after fixing this problem, the original problem reappeared again, all types imported with addServerImportsDir become any.

You can refer to the reproduction in the issue mentioned above.

It may be a problem with nuxt or nitro, if I want to open issue in one of them, I will try to open it, thank you.

@niko-chaffinchicas
Copy link

@kiki-kanri It looks like your issue may have resurfaced because of this line in Nitro?

https://github.com/unjs/nitro/blob/78b3e77b978b51195f313c793cb1cfb1bf594f27/src/build.ts#L178

The most recent change to unimport would disable unimport's stripping of the file extension, since there's a custom resolvePath option being set.

@antfu
Copy link
Member

antfu commented Dec 29, 2023

The extension should be handled by resolvePath if provided. Because the previous behavior of always stripping the extension is an implicit mandatory convention that caused the issue described in this PR and there is no way to workaround it. For nitro, it should be fixed on nitro side.

@productdevbook
Copy link
Contributor

productdevbook commented Jan 22, 2024

yes I had this problem again, it adds it again at the end of mjs coming from node_modules. I will take a look at this. v3.7.1. v3.7.0 dont problem

@productdevbook
Copy link
Contributor

@kiki-kanriNitro'daki bu çizgi nedeniyle sorununuz yeniden ortaya çıkmış gibi mi görünüyor?

https://github.com/unjs/nitro/blob/78b3e77b978b51195f313c793cb1cfb1bf594f27/src/build.ts#L178

İçe aktarma işleminde yapılan en son değişiklik, özel bir seçenek ayarlandığından, içe aktarma işleminin dosya uzantısını kaldırmasını devre dışı bırakacaktır resolvePath.

i am send fix pr unjs/nitro#2139

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

6 participants