-
Notifications
You must be signed in to change notification settings - Fork 64
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
Injecting additional values into an existing env #88
Comments
I think I'd merge the specifications (that is, export Thoughts? |
I had that in mind as well, so that solution would be something like: // config.ts
import * as envalid from "envalid";
export const sharedValidators = {
SHARED_THING: envalid.str({
default: "this variable needs to present in all scripts",
}),
}; // peculiarTask.ts
import * as envalid from "envalid";
import { sharedValidators } from "./config";
const env = envalid.cleanEnv(process.env, {
...sharedValidators,
EXTRA_THING: envalid.str({
default: "this variable should only be cleaned inside peculiarTask.ts",
}),
}); This looks rather clean so far, but has two issues:
// config.ts
import * as envalid from "envalid";
import SharedThingManager from "things";
import * as path from "path";
export const env = envalid.cleanEnv(process.env, {
SHARED_THING: envalid.str({
default: "this variable needs to present in all scripts",
}),
}, { strict: true });
// example 1
export const sharedThingManager = new SharedThingManager(env.SHARED_THING);
// example 2
export const resolvedSharedThing = path.resolve(__dirname, env.SHARED_THING); |
This has been open for a long while and I think the solution of sharing the config (like below) is the best way to go. If there's a more actionable proposal, please open a new issue, going to close this one now const env = envalid.cleanEnv(process.env, {
...sharedValidators,
EXTRA_THING: envalid.str({
default: "this variable should only be cleaned inside peculiarTask.ts",
}),
}); |
Hi 👋
I have a Node.js project with a few scripts (entrypoints). Some of them require additional parameters like auth tokens etc. and I would like to extend my env object inside some of the actions. This is not the same as #78 because the presence of extra values depends on the code logic rather than the values certain env variables have. An example:
There are a couple of problems at the moment:
{ strict: true }
to getextendedEnv
clears out all variables that used to exist in env.{ strict: true }
in the second case, TypeScript autocompletion forextendedEnv.SHARED_THING
does not work.What improvements could we make here? What do others do in similar cases?
The text was updated successfully, but these errors were encountered: