feat: Add configDir to specify a directory for .env files#9000
Merged
feat: Add configDir to specify a directory for .env files#9000
configDir to specify a directory for .env files#9000Conversation
This change introduces a new property, `configDir`, to the `functions` configuration in `firebase.json`. This property allows users to specify a directory where `.env` files are located, providing more flexibility in project structure. The `configDir` property is supported for both deployment and the local functions emulator. - The `configDir` path is resolved relative to the `firebase.json` file. - If `configDir` is not specified, the behavior remains unchanged, and `.env` files are looked for in the functions source directory. Unit and emulator integration tests have been added to verify the new functionality.
Contributor
Author
|
/gemini review |
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces the configDir property, allowing users to specify a custom directory for .env files. This is a valuable feature for projects with non-standard structures. The implementation is solid across both deployment and the emulator, and it's great to see comprehensive unit and integration tests to validate the new functionality. I've also noticed some nice refactoring in the test suite and environment variable handling logic, which improves code clarity. I have one minor suggestion to simplify the code in getUserEnvs.
Remove unnecessary conditional check when assigning backend.configDir to projectInfo since the property is already optional.
963d1d4 to
131ba76
Compare
Reverted the unnecessary addition of configDir parameter to existing tests in env.spec.ts since the default behavior when configDir is undefined is backward compatible. Only kept configDir in the test that specifically tests the new configDir functionality.
inlined
approved these changes
Aug 20, 2025
- Use proto.copyIfPresent in prepare.ts and controller.ts to conditionally set configDir only when it has a value - Remove unnecessary fs.rmSync for temp directory in test cleanup
…se/firebase-tools into feat-functions-config-dir
convertIfPresent supports transformation functions, which is needed to convert configDir paths using options.config.path() and path.join()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change introduces a new property,
configDir, to thefunctionsconfiguration infirebase.json. This property allows users to specify a directory where.envfiles are located, providing more flexibility in project structure.The
configDirproperty is supported for both deployment and the local functions emulator.configDirpath is resolved relative to thefirebase.jsonfile.configDiris not specified, the behavior remains unchanged, and.envfiles are looked for in the functions source directory.Unit and emulator integration tests have been added to verify the new functionality.