nitro icon indicating copy to clipboard operation
nitro copied to clipboard

feat(runtime-config): export `applyEnv` and `getEnv` from nitropack

Open danielroe opened this issue 2 months ago โ€ข 9 comments

๐Ÿ”— Linked issue

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • [ ] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [ ] ๐Ÿ‘Œ Enhancement (improving an existing functionality like performance)
  • [x] โœจ 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

This adds applyEnv and getEnv as exports, as well as allowing them to operate on a custom env object instead of reading from process.env.

This would be a useful feature for frameworks to provide more accurate runtimeConfig at the build time. For example, we already inline these utils in https://github.com/nuxt/test-utils/pull/655 and would need to do the same for https://github.com/nuxt/nuxt/issues/24224 and https://github.com/nuxt/nuxt/issues/26960.

Of course, that would be fine, but it would nicer to be able to simulate the runtime behaviour of Nitro with these utils, as suggested in https://github.com/nuxt/nuxt/issues/24224#issuecomment-1805495557.

I've included them in the core nitropack export but I would almost prefer nitropack/utils, perhaps, to allow space for other similar utilities?

๐Ÿ“ Checklist

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

danielroe avatar Apr 30 '24 15:04 danielroe