woowabros / nestjs-library-config

A NestJS module for managing environment variables easily and securely.
https://www.npmjs.com/package/@nestjs-library/config
MIT License
65 stars 11 forks source link

Why some modules are not being exported in index.ts? #414

Closed JadenKim-dev closed 2 months ago

JadenKim-dev commented 3 months ago

Hi, there.

First of all, thanks for all your great works. This library resolved many inconveniences I experienced while using nest/config.

I wondered why source provider modules like DotenvSourceProvider are not exported in index.ts. It seems possible to specify the sourceProvider as an option in the ConfigModule.forFeature, but when I want to use DotenvSourceProvider, I can't import it.

I want to use as below.

// Module '"@nestjs-library/config"' has no exported member 'DotenvSourceProvider'.
import { ConfigModule, DotenvSourceProvider } from '@nestjs-library/config';

@Module({
    imports: [
        TypeOrmModule.forRootAsync({
            imports: [
                ConfigModule.forFeature(TypeOrmConfigService, {
                    sourceProvider: new DotenvSourceProvider(),
                }),
            ],
            useFactory: (typeORMConfigService: TypeOrmConfigService) => typeORMConfigService,
            inject: [TypeOrmConfigService],
        }),
    ],
    controllers: [AppController],
    providers: [AppService],
})
export class AppModule {}

Current index.ts is like below. It exports only ConfigModule, AbstractConfigService, OptionalBoolean, ConfigScanner

export * from './lib/config.module';
export * from './lib/abstract/abstract-config.service';

export * from './lib/type-transformer';
export * from './lib/config-scanner';
jiho-kr commented 3 months ago

Hi, @JadenKim-dev

As far as I know, there's no particular reason for this, it's simply missing.

The most likely reason is that my team doesn't use 'DotenvSourceProvider' and I didn't know about it. 😁

And as a background on providers, they expect you to create and utilize your own, not have it provided by config library.

A DotenvSourceProvider was created as a guide for creating providers.

Anyway, I'm not against adding it to inext.ts.

Can I look forward to your contribution?

JadenKim-dev commented 3 months ago

Thank you for your kind explanation, @jiho-kr!

Considering your points, it would be beneficial to also export the abstract class AbstractConfigSourceProvider to make it easier for users to implement their own provider.

I will proceed with this task and create a PR afterward! Thanks.

Pigrabbit commented 2 months ago

It has been resolved in https://github.com/woowabros/nestjs-library-config/pull/415.