Skip to content

Commit

Permalink
refactor: rename config => loaders
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `config` option is deprecated, use `loaders` to instead
  • Loading branch information
Val-istar-Guo committed Jun 14, 2024
1 parent c3d6b98 commit 033987c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import { AppConfig } from "./app.config";
ConfigModule.register({
isGlobal: true,
providers: [AppConfig],
config: [
loaders: [
processEnvLoader,
// transform DATABASE__HOST="0.0.0.0"
// to DATABASE = { HOST: "0.0.0.0" }
Expand Down Expand Up @@ -167,7 +167,7 @@ import { yamlConfigLoader } from "./yamlConfigLoader";
ConfigModule.register({
isGlobal: true,
providers: [AppConfig],
config: [yamlConfigLoader("my-yaml-config.yaml")],
loaders: [yamlConfigLoader("my-yaml-config.yaml")],
}),
],
})
Expand Down
4 changes: 2 additions & 2 deletions src/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class ConfigModule extends ConfigurableModuleClass {
provide: MODULE_LOADED_CONFIG_TOKEN,
inject: [MODULE_OPTIONS_TOKEN],
useFactory: async (options: typeof OPTIONS_TYPE) => {
const configLoaders = (options.config || [processEnvLoader(), '.env'])
const configLoaders = (options.loaders || [processEnvLoader(), '.env'])
.map((c) => (typeof c === 'string' ? dotenvLoader(c) : c))

const configs = await Promise.all(configLoaders.map((loader) => loader(options)))
Expand All @@ -82,7 +82,7 @@ export class ConfigModule extends ConfigurableModuleClass {
* Load config and provider before registering the module
*/
static async preload(options: ConfigModuleOptions): Promise<void> {
const configLoaders = (options.config || [processEnvLoader(), '.env'])
const configLoaders = (options.loaders || [processEnvLoader(), '.env'])
.map((c) => (typeof c === 'string' ? dotenvLoader(c) : c))

const configs = await Promise.all(configLoaders.map((loader) => loader(options)))
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/config-module-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ConfigModuleOptions {
/**
* @default ".env"
*/
config?: (string | ConfigLoader)[]
loaders?: (string | ConfigLoader)[]

providers: Type[]

Expand Down

0 comments on commit 033987c

Please sign in to comment.