@karmaniverous/get-dotenv 0.3.2 → 0.3.4-0

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
@@ -44,6 +44,8 @@ See [OptionsType](#optionstype--object) below for configuration options.
44
44
 
45
45
  ## Dynamic Processing
46
46
 
47
+ This package supports the full [`dotenv-expand`](https://www.npmjs.com/package/dotenv-expand) syntax.
48
+
47
49
  For the async form only (`getDotenv`, not `getDotenvSync), use the `dynamicPath` option to add a relative path to a module with a default export like this:
48
50
 
49
51
  ```js
@@ -96,7 +98,7 @@ Options:
96
98
  ## Functions
97
99
 
98
100
  <dl>
99
- <dt><a href="#getDotenv">getDotenv([options])</a> ⇒ <code>Object</code></dt>
101
+ <dt><a href="#getDotenv">getDotenv([options])</a> ⇒ <code>Promise.&lt;object&gt;</code></dt>
100
102
  <dd><p>Asynchronously process dotenv files of the form .env[.<ENV>][.<PRIVATE_TOKEN>]</p>
101
103
  </dd>
102
104
  <dt><a href="#getDotenvSync">getDotenvSync([options])</a> ⇒ <code>Object</code></dt>
@@ -114,11 +116,11 @@ Options:
114
116
 
115
117
  <a name="getDotenv"></a>
116
118
 
117
- ## getDotenv([options]) ⇒ <code>Object</code>
119
+ ## getDotenv([options]) ⇒ <code>Promise.&lt;object&gt;</code>
118
120
  Asynchronously process dotenv files of the form .env[.<ENV>][.<PRIVATE_TOKEN>]
119
121
 
120
122
  **Kind**: global function
121
- **Returns**: <code>Object</code> - The combined parsed dotenv object.
123
+ **Returns**: <code>Promise.&lt;object&gt;</code> - The combined parsed dotenv object.
122
124
 
123
125
  | Param | Type | Description |
124
126
  | --- | --- | --- |
@@ -37,7 +37,7 @@ const _dirname = (0, _url.fileURLToPath)(new _url.URL('.', import.meta.url));
37
37
  *
38
38
  * @param {OptionsType} [options] - options object
39
39
  *
40
- * @returns {Object} The combined parsed dotenv object.
40
+ * @returns {Promise<object>} The combined parsed dotenv object.
41
41
  */
42
42
  const getDotenv = async function () {
43
43
  let {
@@ -52,7 +52,7 @@ const getDotenv = async function () {
52
52
  privateToken = 'local'
53
53
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
54
54
  // Read .env files.
55
- const dotenv = (0, _dotenvExpand.expand)(await paths.reduce(async (e, p) => ({
55
+ const parsed = await paths.reduce(async (e, p) => ({
56
56
  ...(await e),
57
57
  ...(excludePublic ? {} : {
58
58
  ...(await (0, _readDotenv.readDotenv)(_path.default.resolve(p, dotenvToken))),
@@ -62,7 +62,15 @@ const getDotenv = async function () {
62
62
  ...(await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`))),
63
63
  ...(env ? await (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
64
64
  })
65
- }), []));
65
+ }), []);
66
+ const {
67
+ error,
68
+ parsed: dotenv
69
+ } = (0, _dotenvExpand.expand)({
70
+ ignoreProcessEnv: true,
71
+ parsed
72
+ });
73
+ if (error) throw new Error(error);
66
74
 
67
75
  // Process dynamic variables.
68
76
  if (dynamicPath) {
@@ -107,7 +115,7 @@ const getDotenvSync = function () {
107
115
  privateToken = 'local'
108
116
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
109
117
  // Read .env files.
110
- const dotenv = (0, _dotenvExpand.expand)(paths.reduce((e, p) => ({
118
+ const parsed = paths.reduce((e, p) => ({
111
119
  ...e,
112
120
  ...(excludePublic ? {} : {
113
121
  ...(0, _readDotenv.readDotenvSync)(_path.default.resolve(p, dotenvToken)),
@@ -117,7 +125,15 @@ const getDotenvSync = function () {
117
125
  ...(0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`)),
118
126
  ...(env ? (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env}.${privateToken}`)) : {})
119
127
  })
120
- }), []));
128
+ }), []);
129
+ const {
130
+ error,
131
+ parsed: dotenv
132
+ } = (0, _dotenvExpand.expand)({
133
+ ignoreProcessEnv: true,
134
+ parsed
135
+ });
136
+ if (error) throw new Error(error);
121
137
 
122
138
  // Throw error if dynamicPath is set.
123
139
  if (dynamicPath) throw new Error('dynamicPath not supported in sync mode');
@@ -28,7 +28,7 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
28
28
  *
29
29
  * @param {OptionsType} [options] - options object
30
30
  *
31
- * @returns {Object} The combined parsed dotenv object.
31
+ * @returns {Promise<object>} The combined parsed dotenv object.
32
32
  */
33
33
  export const getDotenv = async ({
34
34
  dotenvToken = '.env',
@@ -42,35 +42,40 @@ export const getDotenv = async ({
42
42
  privateToken = 'local',
43
43
  } = {}) => {
44
44
  // Read .env files.
45
- const dotenv = expand(
46
- await paths.reduce(
47
- async (e, p) => ({
48
- ...(await e),
49
- ...(excludePublic
50
- ? {}
51
- : {
52
- ...(await readDotenv(path.resolve(p, dotenvToken))),
53
- ...(env
54
- ? await readDotenv(path.resolve(p, `${dotenvToken}.${env}`))
55
- : {}),
56
- }),
57
- ...(excludePrivate
58
- ? {}
59
- : {
60
- ...(await readDotenv(
61
- path.resolve(p, `${dotenvToken}.${privateToken}`)
62
- )),
63
- ...(env
64
- ? await readDotenv(
65
- path.resolve(p, `${dotenvToken}.${env}.${privateToken}`)
66
- )
67
- : {}),
68
- }),
69
- }),
70
- []
71
- )
45
+ const parsed = await paths.reduce(
46
+ async (e, p) => ({
47
+ ...(await e),
48
+ ...(excludePublic
49
+ ? {}
50
+ : {
51
+ ...(await readDotenv(path.resolve(p, dotenvToken))),
52
+ ...(env
53
+ ? await readDotenv(path.resolve(p, `${dotenvToken}.${env}`))
54
+ : {}),
55
+ }),
56
+ ...(excludePrivate
57
+ ? {}
58
+ : {
59
+ ...(await readDotenv(
60
+ path.resolve(p, `${dotenvToken}.${privateToken}`)
61
+ )),
62
+ ...(env
63
+ ? await readDotenv(
64
+ path.resolve(p, `${dotenvToken}.${env}.${privateToken}`)
65
+ )
66
+ : {}),
67
+ }),
68
+ }),
69
+ []
72
70
  );
73
71
 
72
+ const { error, parsed: dotenv } = expand({
73
+ ignoreProcessEnv: true,
74
+ parsed,
75
+ });
76
+
77
+ if (error) throw new Error(error);
78
+
74
79
  // Process dynamic variables.
75
80
  if (dynamicPath) {
76
81
  const { default: dynamic } = await import(
@@ -112,35 +117,40 @@ export const getDotenvSync = ({
112
117
  privateToken = 'local',
113
118
  } = {}) => {
114
119
  // Read .env files.
115
- const dotenv = expand(
116
- paths.reduce(
117
- (e, p) => ({
118
- ...e,
119
- ...(excludePublic
120
- ? {}
121
- : {
122
- ...readDotenvSync(path.resolve(p, dotenvToken)),
123
- ...(env
124
- ? readDotenvSync(path.resolve(p, `${dotenvToken}.${env}`))
125
- : {}),
126
- }),
127
- ...(excludePrivate
128
- ? {}
129
- : {
130
- ...readDotenvSync(
131
- path.resolve(p, `${dotenvToken}.${privateToken}`)
132
- ),
133
- ...(env
134
- ? readDotenvSync(
135
- path.resolve(p, `${dotenvToken}.${env}.${privateToken}`)
136
- )
137
- : {}),
138
- }),
139
- }),
140
- []
141
- )
120
+ const parsed = paths.reduce(
121
+ (e, p) => ({
122
+ ...e,
123
+ ...(excludePublic
124
+ ? {}
125
+ : {
126
+ ...readDotenvSync(path.resolve(p, dotenvToken)),
127
+ ...(env
128
+ ? readDotenvSync(path.resolve(p, `${dotenvToken}.${env}`))
129
+ : {}),
130
+ }),
131
+ ...(excludePrivate
132
+ ? {}
133
+ : {
134
+ ...readDotenvSync(
135
+ path.resolve(p, `${dotenvToken}.${privateToken}`)
136
+ ),
137
+ ...(env
138
+ ? readDotenvSync(
139
+ path.resolve(p, `${dotenvToken}.${env}.${privateToken}`)
140
+ )
141
+ : {}),
142
+ }),
143
+ }),
144
+ []
142
145
  );
143
146
 
147
+ const { error, parsed: dotenv } = expand({
148
+ ignoreProcessEnv: true,
149
+ parsed,
150
+ });
151
+
152
+ if (error) throw new Error(error);
153
+
144
154
  // Throw error if dynamicPath is set.
145
155
  if (dynamicPath) throw new Error('dynamicPath not supported in sync mode');
146
156
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bin": {
4
4
  "getdotenv": "bin/getdotenv/index.js"
5
5
  },
6
- "version": "0.3.2",
6
+ "version": "0.3.4-0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -31,7 +31,7 @@
31
31
  ],
32
32
  "license": "BSD-3-Clause",
33
33
  "dependencies": {
34
- "commander": "^9.4.1",
34
+ "commander": "^10.0.0",
35
35
  "cross-spawn": "^7.0.3",
36
36
  "dotenv": "^16.0.3",
37
37
  "dotenv-expand": "^10.0.0",
@@ -39,22 +39,22 @@
39
39
  "string-argv": "^0.3.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@babel/cli": "^7.20.7",
43
- "@babel/core": "^7.20.7",
42
+ "@babel/cli": "^7.21.0",
43
+ "@babel/core": "^7.21.0",
44
44
  "@babel/eslint-parser": "^7.19.1",
45
45
  "@babel/plugin-syntax-import-assertions": "^7.20.0",
46
46
  "@babel/preset-env": "^7.20.2",
47
- "@babel/register": "^7.18.9",
48
- "@types/node": "^18.11.18",
47
+ "@babel/register": "^7.21.0",
48
+ "@types/node": "^18.15.3",
49
49
  "chai": "^4.3.7",
50
- "concat-md": "^0.5.0",
51
- "eslint": "^8.31.0",
50
+ "concat-md": "^0.5.1",
51
+ "eslint": "^8.36.0",
52
52
  "eslint-config-standard": "^17.0.0",
53
53
  "eslint-plugin-mocha": "^10.1.0",
54
54
  "jsdoc-to-markdown": "^8.0.0",
55
55
  "mocha": "^10.2.0",
56
- "prettier": "^2.8.1",
57
- "release-it": "^15.6.0"
56
+ "prettier": "^2.8.4",
57
+ "release-it": "^15.8.0"
58
58
  },
59
59
  "exports": {
60
60
  ".": {