@karmaniverous/get-dotenv 4.2.4 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -54,13 +54,15 @@ import { getDotenv } from '@karmaniverous/get-dotenv';
54
54
  const dotenv = await getDotenv(options);
55
55
  ```
56
56
 
57
- See the [GetDotenvOptions](./src/GetDotenvOptions.ts) type for descriptions of all the configuration options.
57
+ Options can be passed programmatically or set in a `getdotenv.config.json` file in your project root directory. The same file also sets default options for the `getdotenv` CLI or any child CLI you spawn from it.
58
+
59
+ See the [child CLI example repo](https://github.com/karmaniverous/get-dotenv-child#configuration) for an extensiive discussion of the various config options and how & where to set them.
58
60
 
59
61
  ## Dynamic Processing
60
62
 
61
63
  This package supports the full [`dotenv-expand`](https://www.npmjs.com/package/dotenv-expand) syntax, with some internal performance improvements.
62
64
 
63
- Use the `dynamicPath` option to add a relative path to a Javascript file with a default export like this:
65
+ Use the `dynamicPath` option to add a relative path to a Javascript module with a default export like this:
64
66
 
65
67
  ```js
66
68
  export default {
@@ -72,10 +74,29 @@ export default {
72
74
  };
73
75
  ```
74
76
 
75
- If the value corresponding to a key is a function, it will be executed with the current state of `dotenv` as its single argument and the result applied back to the `dotenv` object. Otherwise, the value will just be applied back to `dotenv`.
77
+ If the value corresponding to a key is a function, it will be executed with the current state of `dotenv` as its single argument and the result applied back to the `dotenv` object. Otherwise, the value will just be applied back to `dotenv`. (Although if you're going to do that then you might as well just create a public global variable in the first place.)
76
78
 
77
79
  Since keys will be evaluated progressively, each successive key function will have access to any previous ones. These keys can also override existing variables.
78
80
 
81
+ ### Dynamic Processing with TypeScript
82
+
83
+ Even though the rest of your project is in TypeScript, the dynamic processing module SHOULD be in JavasScript.
84
+
85
+ Think about it: the module is loaded via a dynamic import, with the file name determined at run time. You will have to jump through some hoops to get your bundler to compile this file, and you'll have to be careful to set `dynamicPath` to reference the compiled file. That's a lot of work for some very simple log.
86
+
87
+ BUT... if you must, then your dynamic module's default export should be of the `GetDotenvDynamic` type, which is defined [here](./src/GetDotenvOptions.ts) and looks like this:
88
+
89
+ ```ts
90
+ export type ProcessEnv = Record<string, string | undefined>;
91
+
92
+ export type GetDotenvDynamicFunction = (vars: ProcessEnv) => string | undefined;
93
+
94
+ export type GetDotenvDynamic = Record<
95
+ string,
96
+ GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>
97
+ >;
98
+ ```
99
+
79
100
  ## Command Line Interface
80
101
 
81
102
  You can also use `getdotenv` from the command line: