nitro icon indicating copy to clipboard operation
nitro copied to clipboard

feat: add hook before prepare:types

Open Barbapapazes opened this issue 1 year ago โ€ข 2 comments

๐Ÿ”— Linked issue

related to #1710

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • [ ] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [x] ๐Ÿ‘Œ Enhancement (improving an existing functionality like performance)
  • [ ] โœจ New feature (a non-breaking change that adds functionality)
  • [ ] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

Hello ๐Ÿ‘‹,

This PR allows modules developers to add references or tweak the tsconfig file before saving it.

I also refactor how references are build to easily add a new one (just a path).

This hook is similar to the one in Nuxt.

๐Ÿ“ Checklist

  • [ ] I have linked an issue or discussion.
  • [ ] I have updated the documentation accordingly.

Barbapapazes avatar Jun 10 '24 17:06 Barbapapazes

types:extend hook was added via #1715 to allow extending types via a hook (#1710)

Allow extending more items like declarations is good idea, thinking to do few structure changes to allow it (we don't need a new hook, i hope)

pi0 avatar Jun 11 '24 12:06 pi0

types:extend hook was added via #1715 to allow extending types via a hook (#1710)

Allow extending more items like declarations is good idea, thinking to do few structure changes to allow it (we don't need a new hook, i hope)

Still in my module, explained here https://github.com/unjs/nitro/pull/2506#issuecomment-2159167362

Yes! My TypeScript knowledge led me updating what I thought was the main file .nuxt/nuxt.d.ts to augment Nuxt and Vue types. After, I tried to do the same to Nitro but it was not possible so I propose this change, similar to the current behavior of Nuxt.

But, after deep diving into the tsconfig file and the files created by Nuxt, it seems that Nuxt automatically add a path to the current module and because it's a directory, it's possible to add .d.ts file which is way more elegant than a template file since it's not dynamic.

The Nuxt module author guide, https://nuxt.com/docs/guide/going-further/modules#adding-type-declarations, is very misleading about the usage of template so typescript and I will open an issue.

While writing these lines, I haven't check if Nitro add a similar line, a reference to the module to allow .d.ts, or if it's come from Nuxt but it could help to have the same (well documented) in Nitro. But there is still the question for dynamic .d.ts file, like the one Nitro generate for the app.config or the routes definitions.

Barbapapazes avatar Jun 11 '24 12:06 Barbapapazes

Thank you for initially working on this PR โค๏ธ It should be adressed with #3399

pi0 avatar Jun 25 '25 13:06 pi0