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

feat: add glob pattern matching for env files #1830

Closed

Conversation

sapenlei
Copy link

@sapenlei sapenlei commented Sep 28, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

The envFilePath only supports matching specific paths, which becomes cumbersome when trying to match multiple paths.

Issue Number: N/A

What is the new behavior?

Use glob pattern matching for paths. For example:
envFilePath: ".env*" can match .env, .env.local, .env.production, etc.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Copy link

@Papooch Papooch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to update the docstring in the options interface with a mention of supporting globs, too.

@@ -20,6 +20,7 @@
"dependencies": {
"dotenv": "16.4.5",
"dotenv-expand": "10.0.0",
"glob": "^11.0.0",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added a dependency to package.json, but did not commit the updated package-lock.json, so the tests are failing on CI. Please add the lock file.

@@ -19,6 +19,7 @@ import { ConfigFactoryKeyHost } from './utils';
import { createConfigProvider } from './utils/create-config-factory.util';
import { getRegistrationToken } from './utils/get-registration-token.util';
import { mergeConfigObject } from './utils/merge-configs.util';
import { globSync } from 'glob';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be sorted by scoped->unscoped->relative, and alphabetically. (in VSCode, there's a command called "Organize Imports" - Shift+Alt+O)

@kamilmysliwiec
Copy link
Member

You can just run glob in your app and pass the output string array to the ConfigModule options - no need for adding this dependency to the package

@nestjs nestjs locked and limited conversation to collaborators Sep 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants