gravity-ui / nodekit

Simple toolkit for Node.js applications and scripts
https://github.com/orgs/gravity-ui/projects/2
MIT License
5 stars 1 forks source link

Remove env magic #12

Open 3y3 opened 1 year ago

3y3 commented 1 year ago

At current time env is accessible everywhere in project (but used only in main module).

Proposal:

Proposal+:

Looks like options.config is a flat object. Maybe it should be top level param

constructor(options: InitOptions = {}) {}

constructor(options: InitOptions & AppConfig = {}) {}

So most part of configuration will be accessible from env

# appTracingEnabled
APP_TRACING_ENABLED=false

But I understand problems with appSensitiveKeys in this keys.

Most interested api looks like:

import {NodeKit, configure} from 'nodekit';

const nodekit = new NodeKit(configure({
  env: true,
  file: require.resolve('./config')
}));
resure commented 1 year ago

First part of proposal sounds good, except for this:

Reverse default behavior for disableDotEnv

I understand where it's coming from, but in real-life usage that would be an option that almost always would be passed with true value. Maybe we should think about some kind of different NodeKit modes:

  1. One without any side-effects (including dotenv, shutdown handlers, etc.)
  2. Another for applications, with side-effects enabled

Proposal+: Looks like options.config is a flat object

It's not, it can contain any type of values, including nested objects.

But I understand problems with appSensitiveKeys in this keys.

Yeah, that's too