nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Automatically generate runtime config types from nitro.config the same as Nuxt

Open OmarMcAdam opened this issue 2 years ago • 14 comments

Describe the feature

In Nuxt runtimeConfig keys/values are typed. This improves DX considerably when accessing vis useRuntimeConfig()

Nitro has not yet implemented this, which can cause some confusion for users coming over from Nuxt

Result: useRuntimeConfig() should be aware of the keys that exist in nitro.config.ts, and provide correct types

Additional information

  • [ ] Would you be willing to help implement this feature?

OmarMcAdam avatar Sep 08 '23 12:09 OmarMcAdam

💎 $20 bounty created by @McPizza0 👉 To claim this bounty, submit your pull request on Algora 📝 Before proceeding, please make sure you can receive payouts in your country 💵 Payment arrives in your account 2-5 days after the bounty is rewarded 💯 You keep 100% of the bounty award 🙏 Thank you for contributing to unjs/nitro!

algora-pbc avatar Sep 08 '23 12:09 algora-pbc

This is a good idea. As part of the implementation notes, I think we should enable it only by nuxi CLI as an opt-in flag to avoid conflicting with Nuxt types. /cc @danielroe

pi0 avatar Sep 08 '23 12:09 pi0

I would like to take a look at this.

mnmt7 avatar Sep 08 '23 13:09 mnmt7

This would also help in nuxt when accessing runtime config from server side utils.

Currently when using useRuntimeConfig in a tRPC route, nothing is typed.

OmarMcAdam avatar Sep 08 '23 13:09 OmarMcAdam

@McPizza0 @pi0 Can you help me point into the right direction?

rishi-raj-jain avatar Sep 08 '23 17:09 rishi-raj-jain

/attempt #1706

rishi-raj-jain avatar Sep 08 '23 17:09 rishi-raj-jain

@rishi-raj-jain this may need input from @pi0 and @danielroe

I'm not sure how it was implemented in nuxt, but I would assume the solution will be fairly similar

Need to make sure it doesn't conflict with nuxt

OmarMcAdam avatar Sep 08 '23 18:09 OmarMcAdam

@pi0 @McPizza0 @danielroe @rishi-raj-jain

Maybe we can use the TypeScript Compiler API to parse the configuration file and extract the types and then generate TypeScript definition files (.d.ts) based on the extracted types and apply the generated types.

mnmt7 avatar Sep 08 '23 19:09 mnmt7

We use unjs/untyped to do inference in Nuxt.

See this for reference: https://github.com/nuxt/nuxt/blob/dfdebf29191b7ef2c00873b1201bf48a206bf95e/packages/nuxt/src/core/templates.ts#L140

pi0 avatar Sep 08 '23 22:09 pi0

@McPizza0 is this issue still open? @rishi-raj-jain are you still attempting this? I'd like to give it a try if you're not.

ap172x avatar Sep 26 '23 14:09 ap172x

@ap172x sure go ahead.

rishi-raj-jain avatar Sep 26 '23 14:09 rishi-raj-jain

i'll try it

karthiknadar1204 avatar Nov 23 '23 12:11 karthiknadar1204

@ap172x @rishi-raj-jain @karthiknadar1204 can I take this?

/attempt #1706

oleksandr-shvets avatar Feb 28 '24 14:02 oleksandr-shvets

Sure go ahead.

On Wed, Feb 28, 2024, 19:47 Sashko @.***> wrote:

@ap172x https://github.com/ap172x @rishi-raj-jain https://github.com/rishi-raj-jain @karthiknadar1204 https://github.com/karthiknadar1204 can I take this?

/attempt #1706 https://github.com/unjs/nitro/issues/1706

— Reply to this email directly, view it on GitHub https://github.com/unjs/nitro/issues/1706#issuecomment-1969079036, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALBHXORLWSY2WRQVB3DGYH3YV44ABAVCNFSM6AAAAAA4QKCMG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRZGA3TSMBTGY . You are receiving this because you were mentioned.Message ID: @.***>

rishi-raj-jain avatar Feb 28 '24 14:02 rishi-raj-jain