@karmaniverous/get-dotenv 5.0.0-0 → 5.0.0-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/dist/cliHost.cjs CHANGED
@@ -100,10 +100,7 @@ const defaultsDeep = (...layers) => {
100
100
  };
101
101
 
102
102
  // src/GetDotenvOptions.ts
103
- const getDotenvOptionsFilename = 'getdotenv.config.json'; /**
104
- * A minimal representation of an environment key/value mapping.
105
- * Values may be `undefined` to represent "unset".
106
- */
103
+ const getDotenvOptionsFilename = 'getdotenv.config.json';
107
104
  /**
108
105
  * Converts programmatic CLI options to `getDotenv` options. *
109
106
  * @param cliOptions - CLI options. Defaults to `{}`.
@@ -114,8 +111,7 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
114
111
  /**
115
112
  * Convert CLI-facing string options into {@link GetDotenvOptions}.
116
113
  *
117
- * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter
118
- * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
114
+ * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
119
115
  * pairs (configurable delimiters) into a {@link ProcessEnv}.
120
116
  * - Drops CLI-only keys that have no programmatic equivalent.
121
117
  *
@@ -128,21 +124,36 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
128
124
  delete restObj.debug;
129
125
  delete restObj.scripts;
130
126
  const splitBy = (value, delim, pattern) => (value ? value.split(pattern ? RegExp(pattern) : (delim ?? ' ')) : []);
131
- const kvPairs = (vars
132
- ? splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
127
+ // Tolerate vars as either a CLI string ("A=1 B=2") or an object map.
128
+ let parsedVars;
129
+ if (typeof vars === 'string') {
130
+ const kvPairs = splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
133
131
  ? RegExp(varsAssignorPattern)
134
- : (varsAssignor ?? '=')))
135
- : []);
136
- const parsedVars = Object.fromEntries(kvPairs);
132
+ : (varsAssignor ?? '=')));
133
+ parsedVars = Object.fromEntries(kvPairs);
134
+ }
135
+ else if (vars && typeof vars === 'object' && !Array.isArray(vars)) {
136
+ // Keep only string or undefined values to match ProcessEnv.
137
+ const entries = Object.entries(vars).filter(([k, v]) => typeof k === 'string' && (typeof v === 'string' || v === undefined));
138
+ parsedVars = Object.fromEntries(entries);
139
+ }
140
+ // Drop undefined-valued entries at the converter stage to match ProcessEnv
141
+ // expectations and the compat test assertions.
142
+ if (parsedVars) {
143
+ parsedVars = Object.fromEntries(Object.entries(parsedVars).filter(([, v]) => v !== undefined));
144
+ }
145
+ // Tolerate paths as either a delimited string or string[]
146
+ // Use a locally cast union type to avoid lint warnings about always-falsy conditions
147
+ // under the RootOptionsShape (which declares paths as string | undefined).
148
+ const pathsAny = paths;
149
+ const pathsOut = Array.isArray(pathsAny)
150
+ ? pathsAny.filter((p) => typeof p === 'string')
151
+ : splitBy(pathsAny, pathsDelimiter, pathsDelimiterPattern);
137
152
  // Preserve exactOptionalPropertyTypes: only include keys when defined.
138
153
  return {
139
154
  ...restObj,
140
- ...(paths !== undefined
141
- ? {
142
- paths: splitBy(paths, pathsDelimiter, pathsDelimiterPattern),
143
- }
144
- : {}),
145
- ...(vars !== undefined ? { vars: parsedVars } : {}),
155
+ ...(pathsOut.length > 0 ? { paths: pathsOut } : {}),
156
+ ...(parsedVars !== undefined ? { vars: parsedVars } : {}),
146
157
  };
147
158
  };
148
159
  const resolveGetDotenvOptions = async (customOptions) => {
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
package/dist/cliHost.d.ts CHANGED
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
package/dist/cliHost.mjs CHANGED
@@ -97,10 +97,7 @@ const defaultsDeep = (...layers) => {
97
97
  };
98
98
 
99
99
  // src/GetDotenvOptions.ts
100
- const getDotenvOptionsFilename = 'getdotenv.config.json'; /**
101
- * A minimal representation of an environment key/value mapping.
102
- * Values may be `undefined` to represent "unset".
103
- */
100
+ const getDotenvOptionsFilename = 'getdotenv.config.json';
104
101
  /**
105
102
  * Converts programmatic CLI options to `getDotenv` options. *
106
103
  * @param cliOptions - CLI options. Defaults to `{}`.
@@ -111,8 +108,7 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
111
108
  /**
112
109
  * Convert CLI-facing string options into {@link GetDotenvOptions}.
113
110
  *
114
- * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter
115
- * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
111
+ * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
116
112
  * pairs (configurable delimiters) into a {@link ProcessEnv}.
117
113
  * - Drops CLI-only keys that have no programmatic equivalent.
118
114
  *
@@ -125,21 +121,36 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
125
121
  delete restObj.debug;
126
122
  delete restObj.scripts;
127
123
  const splitBy = (value, delim, pattern) => (value ? value.split(pattern ? RegExp(pattern) : (delim ?? ' ')) : []);
128
- const kvPairs = (vars
129
- ? splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
124
+ // Tolerate vars as either a CLI string ("A=1 B=2") or an object map.
125
+ let parsedVars;
126
+ if (typeof vars === 'string') {
127
+ const kvPairs = splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
130
128
  ? RegExp(varsAssignorPattern)
131
- : (varsAssignor ?? '=')))
132
- : []);
133
- const parsedVars = Object.fromEntries(kvPairs);
129
+ : (varsAssignor ?? '=')));
130
+ parsedVars = Object.fromEntries(kvPairs);
131
+ }
132
+ else if (vars && typeof vars === 'object' && !Array.isArray(vars)) {
133
+ // Keep only string or undefined values to match ProcessEnv.
134
+ const entries = Object.entries(vars).filter(([k, v]) => typeof k === 'string' && (typeof v === 'string' || v === undefined));
135
+ parsedVars = Object.fromEntries(entries);
136
+ }
137
+ // Drop undefined-valued entries at the converter stage to match ProcessEnv
138
+ // expectations and the compat test assertions.
139
+ if (parsedVars) {
140
+ parsedVars = Object.fromEntries(Object.entries(parsedVars).filter(([, v]) => v !== undefined));
141
+ }
142
+ // Tolerate paths as either a delimited string or string[]
143
+ // Use a locally cast union type to avoid lint warnings about always-falsy conditions
144
+ // under the RootOptionsShape (which declares paths as string | undefined).
145
+ const pathsAny = paths;
146
+ const pathsOut = Array.isArray(pathsAny)
147
+ ? pathsAny.filter((p) => typeof p === 'string')
148
+ : splitBy(pathsAny, pathsDelimiter, pathsDelimiterPattern);
134
149
  // Preserve exactOptionalPropertyTypes: only include keys when defined.
135
150
  return {
136
151
  ...restObj,
137
- ...(paths !== undefined
138
- ? {
139
- paths: splitBy(paths, pathsDelimiter, pathsDelimiterPattern),
140
- }
141
- : {}),
142
- ...(vars !== undefined ? { vars: parsedVars } : {}),
152
+ ...(pathsOut.length > 0 ? { paths: pathsOut } : {}),
153
+ ...(parsedVars !== undefined ? { vars: parsedVars } : {}),
143
154
  };
144
155
  };
145
156
  const resolveGetDotenvOptions = async (customOptions) => {
@@ -1,8 +1,6 @@
1
1
  /**
2
2
  * A minimal representation of an environment key/value mapping.
3
- * Values may be `undefined` to represent "unset".
4
- */
5
- type ProcessEnv = Record<string, string | undefined>;
3
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
6
4
 
7
5
  type Scripts = Record<string, string | {
8
6
  cmd: string;
@@ -1,8 +1,6 @@
1
1
  /**
2
2
  * A minimal representation of an environment key/value mapping.
3
- * Values may be `undefined` to represent "unset".
4
- */
5
- type ProcessEnv = Record<string, string | undefined>;
3
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
6
4
 
7
5
  type Scripts = Record<string, string | {
8
6
  cmd: string;
@@ -1,8 +1,6 @@
1
1
  /**
2
2
  * A minimal representation of an environment key/value mapping.
3
- * Values may be `undefined` to represent "unset".
4
- */
5
- type ProcessEnv = Record<string, string | undefined>;
3
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
6
4
 
7
5
  type Scripts = Record<string, string | {
8
6
  cmd: string;
@@ -81,10 +81,7 @@ const defaultsDeep = (...layers) => {
81
81
  };
82
82
 
83
83
  // src/GetDotenvOptions.ts
84
- const getDotenvOptionsFilename = 'getdotenv.config.json'; /**
85
- * A minimal representation of an environment key/value mapping.
86
- * Values may be `undefined` to represent "unset".
87
- */
84
+ const getDotenvOptionsFilename = 'getdotenv.config.json';
88
85
  /**
89
86
  * Converts programmatic CLI options to `getDotenv` options. *
90
87
  * @param cliOptions - CLI options. Defaults to `{}`.
@@ -95,8 +92,7 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
95
92
  /**
96
93
  * Convert CLI-facing string options into {@link GetDotenvOptions}.
97
94
  *
98
- * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter
99
- * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
95
+ * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
100
96
  * pairs (configurable delimiters) into a {@link ProcessEnv}.
101
97
  * - Drops CLI-only keys that have no programmatic equivalent.
102
98
  *
@@ -109,21 +105,36 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
109
105
  delete restObj.debug;
110
106
  delete restObj.scripts;
111
107
  const splitBy = (value, delim, pattern) => (value ? value.split(pattern ? RegExp(pattern) : (delim ?? ' ')) : []);
112
- const kvPairs = (vars
113
- ? splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
108
+ // Tolerate vars as either a CLI string ("A=1 B=2") or an object map.
109
+ let parsedVars;
110
+ if (typeof vars === 'string') {
111
+ const kvPairs = splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
114
112
  ? RegExp(varsAssignorPattern)
115
- : (varsAssignor ?? '=')))
116
- : []);
117
- const parsedVars = Object.fromEntries(kvPairs);
113
+ : (varsAssignor ?? '=')));
114
+ parsedVars = Object.fromEntries(kvPairs);
115
+ }
116
+ else if (vars && typeof vars === 'object' && !Array.isArray(vars)) {
117
+ // Keep only string or undefined values to match ProcessEnv.
118
+ const entries = Object.entries(vars).filter(([k, v]) => typeof k === 'string' && (typeof v === 'string' || v === undefined));
119
+ parsedVars = Object.fromEntries(entries);
120
+ }
121
+ // Drop undefined-valued entries at the converter stage to match ProcessEnv
122
+ // expectations and the compat test assertions.
123
+ if (parsedVars) {
124
+ parsedVars = Object.fromEntries(Object.entries(parsedVars).filter(([, v]) => v !== undefined));
125
+ }
126
+ // Tolerate paths as either a delimited string or string[]
127
+ // Use a locally cast union type to avoid lint warnings about always-falsy conditions
128
+ // under the RootOptionsShape (which declares paths as string | undefined).
129
+ const pathsAny = paths;
130
+ const pathsOut = Array.isArray(pathsAny)
131
+ ? pathsAny.filter((p) => typeof p === 'string')
132
+ : splitBy(pathsAny, pathsDelimiter, pathsDelimiterPattern);
118
133
  // Preserve exactOptionalPropertyTypes: only include keys when defined.
119
134
  return {
120
135
  ...restObj,
121
- ...(paths !== undefined
122
- ? {
123
- paths: splitBy(paths, pathsDelimiter, pathsDelimiterPattern),
124
- }
125
- : {}),
126
- ...(vars !== undefined ? { vars: parsedVars } : {}),
136
+ ...(pathsOut.length > 0 ? { paths: pathsOut } : {}),
137
+ ...(parsedVars !== undefined ? { vars: parsedVars } : {}),
127
138
  };
128
139
  };
129
140
  const resolveGetDotenvOptions = async (customOptions) => {
package/dist/index.cjs CHANGED
@@ -682,10 +682,7 @@ const defaultsDeep = (...layers) => {
682
682
  };
683
683
 
684
684
  // src/GetDotenvOptions.ts
685
- const getDotenvOptionsFilename = 'getdotenv.config.json'; /**
686
- * A minimal representation of an environment key/value mapping.
687
- * Values may be `undefined` to represent "unset".
688
- */
685
+ const getDotenvOptionsFilename = 'getdotenv.config.json';
689
686
  /**
690
687
  * Helper to define a dynamic map with strong inference.
691
688
  *
@@ -703,8 +700,7 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
703
700
  /**
704
701
  * Convert CLI-facing string options into {@link GetDotenvOptions}.
705
702
  *
706
- * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter
707
- * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
703
+ * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
708
704
  * pairs (configurable delimiters) into a {@link ProcessEnv}.
709
705
  * - Drops CLI-only keys that have no programmatic equivalent.
710
706
  *
@@ -717,21 +713,36 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
717
713
  delete restObj.debug;
718
714
  delete restObj.scripts;
719
715
  const splitBy = (value, delim, pattern) => (value ? value.split(pattern ? RegExp(pattern) : (delim ?? ' ')) : []);
720
- const kvPairs = (vars
721
- ? splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
716
+ // Tolerate vars as either a CLI string ("A=1 B=2") or an object map.
717
+ let parsedVars;
718
+ if (typeof vars === 'string') {
719
+ const kvPairs = splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
722
720
  ? RegExp(varsAssignorPattern)
723
- : (varsAssignor ?? '=')))
724
- : []);
725
- const parsedVars = Object.fromEntries(kvPairs);
721
+ : (varsAssignor ?? '=')));
722
+ parsedVars = Object.fromEntries(kvPairs);
723
+ }
724
+ else if (vars && typeof vars === 'object' && !Array.isArray(vars)) {
725
+ // Keep only string or undefined values to match ProcessEnv.
726
+ const entries = Object.entries(vars).filter(([k, v]) => typeof k === 'string' && (typeof v === 'string' || v === undefined));
727
+ parsedVars = Object.fromEntries(entries);
728
+ }
729
+ // Drop undefined-valued entries at the converter stage to match ProcessEnv
730
+ // expectations and the compat test assertions.
731
+ if (parsedVars) {
732
+ parsedVars = Object.fromEntries(Object.entries(parsedVars).filter(([, v]) => v !== undefined));
733
+ }
734
+ // Tolerate paths as either a delimited string or string[]
735
+ // Use a locally cast union type to avoid lint warnings about always-falsy conditions
736
+ // under the RootOptionsShape (which declares paths as string | undefined).
737
+ const pathsAny = paths;
738
+ const pathsOut = Array.isArray(pathsAny)
739
+ ? pathsAny.filter((p) => typeof p === 'string')
740
+ : splitBy(pathsAny, pathsDelimiter, pathsDelimiterPattern);
726
741
  // Preserve exactOptionalPropertyTypes: only include keys when defined.
727
742
  return {
728
743
  ...restObj,
729
- ...(paths !== undefined
730
- ? {
731
- paths: splitBy(paths, pathsDelimiter, pathsDelimiterPattern),
732
- }
733
- : {}),
734
- ...(vars !== undefined ? { vars: parsedVars } : {}),
744
+ ...(pathsOut.length > 0 ? { paths: pathsOut } : {}),
745
+ ...(parsedVars !== undefined ? { vars: parsedVars } : {}),
735
746
  };
736
747
  };
737
748
  const resolveGetDotenvOptions = async (customOptions) => {
package/dist/index.d.cts CHANGED
@@ -42,11 +42,13 @@ type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<s
42
42
  shell?: TShell;
43
43
  }>;
44
44
 
45
+ type RootOptionsShapeCompat = Omit<RootOptionsShape, 'vars' | 'paths'> & {
46
+ vars?: string | Record<string, string | undefined>;
47
+ paths?: string | string[];
48
+ };
45
49
  /**
46
50
  * A minimal representation of an environment key/value mapping.
47
- * Values may be `undefined` to represent "unset".
48
- */
49
- type ProcessEnv = Record<string, string | undefined>;
51
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
50
52
  /**
51
53
  * Dynamic variable function signature. Receives the current expanded variables
52
54
  * and the selected environment (if any), and returns either a string to set
@@ -150,7 +152,7 @@ interface GetDotenvOptions {
150
152
  *
151
153
  * @returns `getDotenv` options.
152
154
  */
153
- declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShape) => GetDotenvOptions;
155
+ declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShapeCompat) => GetDotenvOptions;
154
156
 
155
157
  /**
156
158
  * Recursively expands environment variables in a string. Variables may be
package/dist/index.d.mts CHANGED
@@ -42,11 +42,13 @@ type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<s
42
42
  shell?: TShell;
43
43
  }>;
44
44
 
45
+ type RootOptionsShapeCompat = Omit<RootOptionsShape, 'vars' | 'paths'> & {
46
+ vars?: string | Record<string, string | undefined>;
47
+ paths?: string | string[];
48
+ };
45
49
  /**
46
50
  * A minimal representation of an environment key/value mapping.
47
- * Values may be `undefined` to represent "unset".
48
- */
49
- type ProcessEnv = Record<string, string | undefined>;
51
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
50
52
  /**
51
53
  * Dynamic variable function signature. Receives the current expanded variables
52
54
  * and the selected environment (if any), and returns either a string to set
@@ -150,7 +152,7 @@ interface GetDotenvOptions {
150
152
  *
151
153
  * @returns `getDotenv` options.
152
154
  */
153
- declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShape) => GetDotenvOptions;
155
+ declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShapeCompat) => GetDotenvOptions;
154
156
 
155
157
  /**
156
158
  * Recursively expands environment variables in a string. Variables may be
package/dist/index.d.ts CHANGED
@@ -42,11 +42,13 @@ type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<s
42
42
  shell?: TShell;
43
43
  }>;
44
44
 
45
+ type RootOptionsShapeCompat = Omit<RootOptionsShape, 'vars' | 'paths'> & {
46
+ vars?: string | Record<string, string | undefined>;
47
+ paths?: string | string[];
48
+ };
45
49
  /**
46
50
  * A minimal representation of an environment key/value mapping.
47
- * Values may be `undefined` to represent "unset".
48
- */
49
- type ProcessEnv = Record<string, string | undefined>;
51
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
50
52
  /**
51
53
  * Dynamic variable function signature. Receives the current expanded variables
52
54
  * and the selected environment (if any), and returns either a string to set
@@ -150,7 +152,7 @@ interface GetDotenvOptions {
150
152
  *
151
153
  * @returns `getDotenv` options.
152
154
  */
153
- declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShape) => GetDotenvOptions;
155
+ declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShapeCompat) => GetDotenvOptions;
154
156
 
155
157
  /**
156
158
  * Recursively expands environment variables in a string. Variables may be
package/dist/index.mjs CHANGED
@@ -679,10 +679,7 @@ const defaultsDeep = (...layers) => {
679
679
  };
680
680
 
681
681
  // src/GetDotenvOptions.ts
682
- const getDotenvOptionsFilename = 'getdotenv.config.json'; /**
683
- * A minimal representation of an environment key/value mapping.
684
- * Values may be `undefined` to represent "unset".
685
- */
682
+ const getDotenvOptionsFilename = 'getdotenv.config.json';
686
683
  /**
687
684
  * Helper to define a dynamic map with strong inference.
688
685
  *
@@ -700,8 +697,7 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
700
697
  /**
701
698
  * Convert CLI-facing string options into {@link GetDotenvOptions}.
702
699
  *
703
- * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter
704
- * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
700
+ * - Splits {@link GetDotenvCliOptions.paths} using either a delimiter * or a regular expression pattern into a string array. * - Parses {@link GetDotenvCliOptions.vars} as space-separated `KEY=VALUE`
705
701
  * pairs (configurable delimiters) into a {@link ProcessEnv}.
706
702
  * - Drops CLI-only keys that have no programmatic equivalent.
707
703
  *
@@ -714,21 +710,36 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
714
710
  delete restObj.debug;
715
711
  delete restObj.scripts;
716
712
  const splitBy = (value, delim, pattern) => (value ? value.split(pattern ? RegExp(pattern) : (delim ?? ' ')) : []);
717
- const kvPairs = (vars
718
- ? splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
713
+ // Tolerate vars as either a CLI string ("A=1 B=2") or an object map.
714
+ let parsedVars;
715
+ if (typeof vars === 'string') {
716
+ const kvPairs = splitBy(vars, varsDelimiter, varsDelimiterPattern).map((v) => v.split(varsAssignorPattern
719
717
  ? RegExp(varsAssignorPattern)
720
- : (varsAssignor ?? '=')))
721
- : []);
722
- const parsedVars = Object.fromEntries(kvPairs);
718
+ : (varsAssignor ?? '=')));
719
+ parsedVars = Object.fromEntries(kvPairs);
720
+ }
721
+ else if (vars && typeof vars === 'object' && !Array.isArray(vars)) {
722
+ // Keep only string or undefined values to match ProcessEnv.
723
+ const entries = Object.entries(vars).filter(([k, v]) => typeof k === 'string' && (typeof v === 'string' || v === undefined));
724
+ parsedVars = Object.fromEntries(entries);
725
+ }
726
+ // Drop undefined-valued entries at the converter stage to match ProcessEnv
727
+ // expectations and the compat test assertions.
728
+ if (parsedVars) {
729
+ parsedVars = Object.fromEntries(Object.entries(parsedVars).filter(([, v]) => v !== undefined));
730
+ }
731
+ // Tolerate paths as either a delimited string or string[]
732
+ // Use a locally cast union type to avoid lint warnings about always-falsy conditions
733
+ // under the RootOptionsShape (which declares paths as string | undefined).
734
+ const pathsAny = paths;
735
+ const pathsOut = Array.isArray(pathsAny)
736
+ ? pathsAny.filter((p) => typeof p === 'string')
737
+ : splitBy(pathsAny, pathsDelimiter, pathsDelimiterPattern);
723
738
  // Preserve exactOptionalPropertyTypes: only include keys when defined.
724
739
  return {
725
740
  ...restObj,
726
- ...(paths !== undefined
727
- ? {
728
- paths: splitBy(paths, pathsDelimiter, pathsDelimiterPattern),
729
- }
730
- : {}),
731
- ...(vars !== undefined ? { vars: parsedVars } : {}),
741
+ ...(pathsOut.length > 0 ? { paths: pathsOut } : {}),
742
+ ...(parsedVars !== undefined ? { vars: parsedVars } : {}),
732
743
  };
733
744
  };
734
745
  const resolveGetDotenvOptions = async (customOptions) => {
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
@@ -3,9 +3,7 @@ import { Command } from 'commander';
3
3
 
4
4
  /**
5
5
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset".
7
- */
8
- type ProcessEnv = Record<string, string | undefined>;
6
+ * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
9
7
  /**
10
8
  * Dynamic variable function signature. Receives the current expanded variables
11
9
  * and the selected environment (if any), and returns either a string to set
package/package.json CHANGED
@@ -224,5 +224,5 @@
224
224
  },
225
225
  "type": "module",
226
226
  "types": "dist/index.d.ts",
227
- "version": "5.0.0-0"
227
+ "version": "5.0.0-1"
228
228
  }