varlock 0.0.12 → 0.0.14

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.
Files changed (58) hide show
  1. package/dist/auto-load.js +3 -3
  2. package/dist/{chunk-23GW4X5J.js → chunk-4QTFFYV6.js} +16 -5
  3. package/dist/chunk-4QTFFYV6.js.map +1 -0
  4. package/dist/{chunk-POJECYSY.js → chunk-7JMYT62X.js} +3 -3
  5. package/dist/chunk-7JMYT62X.js.map +1 -0
  6. package/dist/{chunk-UPKIHHPE.js → chunk-C5BEZMSO.js} +2 -2
  7. package/dist/{chunk-UPKIHHPE.js.map → chunk-C5BEZMSO.js.map} +1 -1
  8. package/dist/{chunk-MHDV65DI.js → chunk-EQQCW3OI.js} +98 -66
  9. package/dist/chunk-EQQCW3OI.js.map +1 -0
  10. package/dist/{chunk-NXAXPMO5.js → chunk-FCVBOYES.js} +484 -244
  11. package/dist/chunk-FCVBOYES.js.map +1 -0
  12. package/dist/{chunk-2GR4YQFJ.js → chunk-HGJF2DUO.js} +4 -5
  13. package/dist/chunk-HGJF2DUO.js.map +1 -0
  14. package/dist/{chunk-LBVGWRPL.js → chunk-J5SIYSJV.js} +4 -4
  15. package/dist/{chunk-LBVGWRPL.js.map → chunk-J5SIYSJV.js.map} +1 -1
  16. package/dist/{chunk-52FLZJCQ.js → chunk-OJFTFBQG.js} +5 -24
  17. package/dist/chunk-OJFTFBQG.js.map +1 -0
  18. package/dist/{chunk-IBMSAOL6.js → chunk-QCKADJNV.js} +21 -15
  19. package/dist/chunk-QCKADJNV.js.map +1 -0
  20. package/dist/{chunk-AMAUWR7O.js → chunk-UPOIK25P.js} +4 -4
  21. package/dist/{chunk-AMAUWR7O.js.map → chunk-UPOIK25P.js.map} +1 -1
  22. package/dist/{chunk-TWKAUCTT.js → chunk-ZYL5D2UA.js} +4 -4
  23. package/dist/{chunk-TWKAUCTT.js.map → chunk-ZYL5D2UA.js.map} +1 -1
  24. package/dist/cli/cli-executable.js +14 -15
  25. package/dist/cli/cli-executable.js.map +1 -1
  26. package/dist/dotenv-compat.js +3 -3
  27. package/dist/{env-DxiD5Ylz.d.ts → env-DLUhFCnC.d.ts} +97 -63
  28. package/dist/index.d.ts +2 -3
  29. package/dist/index.js +4 -6
  30. package/dist/index.js.map +1 -1
  31. package/dist/init.command-VK4OGIYP.js +8 -0
  32. package/dist/{init.command-ZSH7NCV7.js.map → init.command-VK4OGIYP.js.map} +1 -1
  33. package/dist/load.command-N7FMBREX.js +8 -0
  34. package/dist/{load.command-U2GASZRB.js.map → load.command-N7FMBREX.js.map} +1 -1
  35. package/dist/login.command-GQCJY4NK.js +8 -0
  36. package/dist/{login.command-2WG4GZV4.js.map → login.command-GQCJY4NK.js.map} +1 -1
  37. package/dist/run.command-LYY2M5AP.js +8 -0
  38. package/dist/{run.command-IETNJ6UU.js.map → run.command-LYY2M5AP.js.map} +1 -1
  39. package/dist/runtime/env.d.ts +1 -1
  40. package/dist/runtime/patch-console.js +1 -1
  41. package/dist/runtime/patch-server-response.js +1 -1
  42. package/dist/telemetry.command-QTEDXKIG.js +8 -0
  43. package/dist/{telemetry.command-US72HXMS.js.map → telemetry.command-QTEDXKIG.js.map} +1 -1
  44. package/package.json +2 -2
  45. package/dist/chunk-23GW4X5J.js.map +0 -1
  46. package/dist/chunk-2GR4YQFJ.js.map +0 -1
  47. package/dist/chunk-52FLZJCQ.js.map +0 -1
  48. package/dist/chunk-IBMSAOL6.js.map +0 -1
  49. package/dist/chunk-MHDV65DI.js.map +0 -1
  50. package/dist/chunk-NXAXPMO5.js.map +0 -1
  51. package/dist/chunk-POJECYSY.js.map +0 -1
  52. package/dist/chunk-Y2EGAWAH.js +0 -17
  53. package/dist/chunk-Y2EGAWAH.js.map +0 -1
  54. package/dist/init.command-ZSH7NCV7.js +0 -9
  55. package/dist/load.command-U2GASZRB.js +0 -9
  56. package/dist/login.command-2WG4GZV4.js +0 -8
  57. package/dist/run.command-IETNJ6UU.js +0 -9
  58. package/dist/telemetry.command-US72HXMS.js +0 -8
@@ -2,10 +2,10 @@ import { redactString } from './chunk-FGMXIEFA.js';
2
2
  import { __commonJS, __name, __toESM } from './chunk-XN24GZXQ.js';
3
3
  import { exec } from 'child_process';
4
4
  import { promisify } from 'util';
5
- import fs2 from 'fs/promises';
6
- import path from 'path';
5
+ import fs, { accessSync } from 'fs';
6
+ import fs2, { access } from 'fs/promises';
7
+ import path2 from 'path';
7
8
  import { ParsedEnvSpecStaticValue, ParsedEnvSpecFunctionCall, ParsedEnvSpecKeyValuePair, parseEnvSpecDotEnvFile } from '@env-spec/parser';
8
- import fs from 'fs';
9
9
  import process2 from 'process';
10
10
 
11
11
  // ../../node_modules/.pnpm/ansis@4.1.0/node_modules/ansis/index.cjs
@@ -780,7 +780,7 @@ function mapValues(obj, fn) {
780
780
  }
781
781
  __name(mapValues, "mapValues");
782
782
  function times(count, fn) {
783
- return Array.from({ length: count }, (_4, i) => fn(i));
783
+ return Array.from({ length: count }, (_3, i) => fn(i));
784
784
  }
785
785
  __name(times, "times");
786
786
  function map(array, fn) {
@@ -791,6 +791,14 @@ function flatMap(array, fn) {
791
791
  return array.flatMap(fn);
792
792
  }
793
793
  __name(flatMap, "flatMap");
794
+ function intersection(...arrays) {
795
+ return arrays.reduce((a2, b) => a2.filter((value) => b.includes(value)));
796
+ }
797
+ __name(intersection, "intersection");
798
+ function pick(obj, keys) {
799
+ return Object.fromEntries(Object.entries(obj).filter(([key]) => keys.includes(key)));
800
+ }
801
+ __name(pick, "pick");
794
802
  var _ = {
795
803
  keyBy,
796
804
  sortBy,
@@ -805,6 +813,8 @@ var _ = {
805
813
  times,
806
814
  map,
807
815
  flatMap,
816
+ intersection,
817
+ pick,
808
818
  // type checks
809
819
  isString,
810
820
  isBoolean,
@@ -945,12 +955,29 @@ var EmptyRequiredValueError = class extends ValidationError {
945
955
  super("Value is required but is currently empty");
946
956
  }
947
957
  };
958
+
959
+ // ../utils/src/try-catch.ts
960
+ function isPromise2(obj) {
961
+ return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
962
+ }
963
+ __name(isPromise2, "isPromise");
964
+ async function tryCatch(tryFn, catchFn) {
965
+ try {
966
+ return await tryFn();
967
+ } catch (err) {
968
+ const catchResult = catchFn(err);
969
+ if (isPromise2(catchResult)) {
970
+ await catchResult;
971
+ }
972
+ }
973
+ }
974
+ __name(tryCatch, "tryCatch");
948
975
  var asyncExec = promisify(exec);
949
976
 
950
977
  // ../utils/src/git-utils.ts
951
- async function checkIsFileGitIgnored(path5, warnIfNotGitRepo = false) {
978
+ async function checkIsFileGitIgnored(path3, warnIfNotGitRepo = false) {
952
979
  try {
953
- await asyncExec(`git check-ignore ${path5} -q`);
980
+ await asyncExec(`git check-ignore ${path3} -q`);
954
981
  return true;
955
982
  } catch (err) {
956
983
  const stderr = err.stderr;
@@ -967,23 +994,24 @@ async function checkIsFileGitIgnored(path5, warnIfNotGitRepo = false) {
967
994
  }
968
995
  }
969
996
  __name(checkIsFileGitIgnored, "checkIsFileGitIgnored");
970
-
971
- // ../utils/src/try-catch.ts
972
- function isPromise2(obj) {
973
- return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
997
+ async function pathExists(p) {
998
+ try {
999
+ await access(p);
1000
+ return true;
1001
+ } catch {
1002
+ return false;
1003
+ }
974
1004
  }
975
- __name(isPromise2, "isPromise");
976
- async function tryCatch(tryFn, catchFn) {
1005
+ __name(pathExists, "pathExists");
1006
+ function pathExistsSync(p) {
977
1007
  try {
978
- return await tryFn();
979
- } catch (err) {
980
- const catchResult = catchFn(err);
981
- if (isPromise2(catchResult)) {
982
- await catchResult;
983
- }
1008
+ accessSync(p);
1009
+ return true;
1010
+ } catch {
1011
+ return false;
984
1012
  }
985
1013
  }
986
- __name(tryCatch, "tryCatch");
1014
+ __name(pathExistsSync, "pathExistsSync");
987
1015
 
988
1016
  // env-graph/lib/data-types.ts
989
1017
  var EnvGraphDataType = class {
@@ -1157,7 +1185,12 @@ var UrlDataType = createEnvGraphDataType(
1157
1185
  return val;
1158
1186
  },
1159
1187
  validate(val) {
1160
- const url = new URL(val);
1188
+ let url;
1189
+ try {
1190
+ url = new URL(val);
1191
+ } catch (err) {
1192
+ throw new ValidationError("Invalid URL");
1193
+ }
1161
1194
  if (settings?.allowedDomains && !settings.allowedDomains.includes(url.host.toLowerCase())) {
1162
1195
  return new ValidationError(`Domain (${url.host}) is not in allowed list: ${settings.allowedDomains.join(",")}`);
1163
1196
  }
@@ -1833,16 +1866,16 @@ export type EnvSchemaAsStrings = {
1833
1866
  return tsSrc.join("\n");
1834
1867
  }
1835
1868
  __name(generateTsTypesSrc, "generateTsTypesSrc");
1836
- async function generateTypes(graph, lang, outputPath) {
1869
+ async function generateTypes(graph, lang, typesPath) {
1837
1870
  if (lang !== "ts") throw new Error(`Unsupported @generateTypes lang: ${lang}`);
1838
1871
  const tsSrc = await generateTsTypesSrc(graph);
1839
- if (!graph.basePath) return;
1840
- const typesPath = path.join(graph.basePath, outputPath);
1841
1872
  await fs.promises.writeFile(typesPath, tsSrc, "utf-8");
1842
1873
  }
1843
1874
  __name(generateTypes, "generateTypes");
1844
1875
 
1845
1876
  // env-graph/lib/env-graph.ts
1877
+ var processExists = !!globalThis.process;
1878
+ var originalProcessEnv = { ...processExists && process.env };
1846
1879
  var EnvGraph2 = class {
1847
1880
  static {
1848
1881
  __name(this, "EnvGraph");
@@ -1851,26 +1884,29 @@ var EnvGraph2 = class {
1851
1884
  // or just the files that are relevant to the current resolution attempt
1852
1885
  // (which would mean it's always through the lens of the current directory/package)
1853
1886
  basePath;
1854
- /** array of data sources */
1855
- dataSources = [];
1856
- finalOverridesDataSource;
1887
+ /** root data source (.env.schema) */
1888
+ rootDataSource;
1889
+ /** place to store process.env overrides */
1890
+ overrideValues = {};
1857
1891
  /** config item key of env flag (toggles env-specific data sources enabled) */
1858
1892
  envFlagKey;
1859
- /** current value of the environment flag */
1860
- envFlagValue;
1893
+ /** graph-level fallback value for environment flag */
1894
+ envFlagFallback;
1861
1895
  configSchema = {};
1862
- addDataSource(dataSource) {
1863
- dataSource.graph = this;
1864
- this.dataSources.push(dataSource);
1865
- }
1866
- get schemaDataSource() {
1867
- const schemas = this.dataSources.filter((f) => f.type === "schema");
1868
- if (schemas.length > 1) throw new Error("Multiple schema data sources found");
1869
- if (schemas.length === 0) return void 0;
1870
- return schemas[0];
1896
+ /** virtual imports for testing */
1897
+ virtualImports;
1898
+ setVirtualImports(basePath, files) {
1899
+ this.virtualImports = {};
1900
+ for (const [fileName, fileContents] of Object.entries(files)) {
1901
+ this.virtualImports[path2.join(basePath, fileName)] = fileContents;
1902
+ }
1871
1903
  }
1872
1904
  get sortedDataSources() {
1873
- return my_dash_default.sortBy(this.dataSources, (f) => 10 * EnvGraphDataSource.DATA_SOURCE_TYPES[f.type].precedence + (f.applyForEnv ? 1 : 0));
1905
+ function getSourceAndChildren(s) {
1906
+ return [s, ...s.children ? s.children.flatMap(getSourceAndChildren) : []];
1907
+ }
1908
+ __name(getSourceAndChildren, "getSourceAndChildren");
1909
+ return this.rootDataSource ? getSourceAndChildren(this.rootDataSource) : [];
1874
1910
  }
1875
1911
  registeredResolverFunctions = {};
1876
1912
  registerResolver(resolverClass) {
@@ -1891,78 +1927,15 @@ var EnvGraph2 = class {
1891
1927
  for (const resolverClass of BaseResolvers) {
1892
1928
  this.registerResolver(resolverClass);
1893
1929
  }
1930
+ this.overrideValues = originalProcessEnv;
1931
+ }
1932
+ async setRootDataSource(source) {
1933
+ if (this.rootDataSource) throw new Error("root data source already set");
1934
+ this.rootDataSource = source;
1935
+ source.graph = this;
1936
+ await source.finishInit();
1894
1937
  }
1895
1938
  async finishLoad() {
1896
- const sortedDataSources = this.sortedDataSources;
1897
- for (const source of sortedDataSources) {
1898
- if (source.loadingError) {
1899
- throw source.loadingError;
1900
- }
1901
- if (source.type === "example") {
1902
- source.disabled = true;
1903
- continue;
1904
- }
1905
- if (source.decorators?.envFlag) {
1906
- if (source.type !== "schema") {
1907
- throw new Error(`@envFlag must only be used in .env.schema, but was found in ${source.label}`);
1908
- } else if (this.envFlagKey) {
1909
- throw new Error("only a single @envFlag setting is allowed");
1910
- } else {
1911
- const envFlagKey = source.decorators.envFlag.simplifiedValue;
1912
- if (!my_dash_default.isString(envFlagKey)) {
1913
- throw new Error("@envFlag must be a string");
1914
- } else {
1915
- this.envFlagKey = envFlagKey;
1916
- }
1917
- }
1918
- }
1919
- if (source.applyForEnv) {
1920
- if (source.applyForEnv && this.envFlagValue !== source.applyForEnv) {
1921
- source.disabled = true;
1922
- continue;
1923
- }
1924
- }
1925
- if (source.decorators?.disable && source.decorators.disable.simplifiedValue) {
1926
- source.disabled = true;
1927
- continue;
1928
- }
1929
- for (const itemKey in source.configItemDefs) {
1930
- if (source.ignoreNewDefs && !this.configSchema[itemKey]) continue;
1931
- const itemDef = source.configItemDefs[itemKey];
1932
- this.configSchema[itemKey] ??= new ConfigItem3(this, itemKey);
1933
- this.configSchema[itemKey].addDef(itemDef, source);
1934
- }
1935
- if (source.type === "schema" && this.envFlagKey) {
1936
- if (!this.configSchema[this.envFlagKey]) {
1937
- throw new Error(`@envFlag key ${this.envFlagKey} not found in schema`);
1938
- }
1939
- const envFlagItem = this.configSchema[this.envFlagKey];
1940
- await envFlagItem.process();
1941
- for (const depKey of envFlagItem.valueResolver?.deps || []) {
1942
- const depItem = this.configSchema[depKey];
1943
- if (!depItem) {
1944
- throw new Error(`envFlag resolver is using non-existant dependency: ${depKey}`);
1945
- }
1946
- await depItem.process();
1947
- if (depItem.valueResolver?.deps.length) {
1948
- throw new Error("envFlag cannot follow a chain of dependencies");
1949
- }
1950
- await depItem.resolve();
1951
- }
1952
- await envFlagItem.resolve();
1953
- if (!envFlagItem.isValid) {
1954
- const err = new Error("resolved @envFlag value is not valid");
1955
- err.cause = envFlagItem.errors[0];
1956
- throw err;
1957
- }
1958
- if (envFlagItem.resolvedValue) {
1959
- if (!my_dash_default.isString(envFlagItem.resolvedValue)) {
1960
- throw new Error("expected resolved @envFlag value to be a string");
1961
- }
1962
- this.envFlagValue = envFlagItem.resolvedValue;
1963
- }
1964
- }
1965
- }
1966
1939
  for (const itemKey in this.configSchema) {
1967
1940
  const item = this.configSchema[itemKey];
1968
1941
  await item.process();
@@ -1988,6 +1961,7 @@ var EnvGraph2 = class {
1988
1961
  return adjList;
1989
1962
  }
1990
1963
  async resolveEnvValues() {
1964
+ if (my_dash_default.keys(this.configSchema).length === 0) return;
1991
1965
  const adjList = this.graphAdjacencyList;
1992
1966
  const reverseAdjList = {};
1993
1967
  for (const itemKey in adjList) {
@@ -2052,7 +2026,7 @@ var EnvGraph2 = class {
2052
2026
  serializedGraph.sources.push({
2053
2027
  label: source.label,
2054
2028
  enabled: !source.disabled,
2055
- path: source instanceof FileBasedDataSource ? path.relative(this.basePath ?? "", source.fullPath) : void 0
2029
+ path: source instanceof FileBasedDataSource ? path2.relative(this.basePath ?? "", source.fullPath) : void 0
2056
2030
  });
2057
2031
  }
2058
2032
  for (const itemKey in this.configSchema) {
@@ -2073,13 +2047,30 @@ var EnvGraph2 = class {
2073
2047
  await generateTypes(this, lang, outputPath);
2074
2048
  }
2075
2049
  getRootDecoratorValue(decoratorName) {
2076
- const dec = this.schemaDataSource?.decorators?.[decoratorName];
2077
- return dec?.simplifiedValue;
2050
+ const sources = Array.from(this.sortedDataSources).reverse();
2051
+ for (const s of sources) {
2052
+ if (s.disabled) continue;
2053
+ if (s.isPartialImport) continue;
2054
+ const decs = s.getRootDecorators(decoratorName);
2055
+ if (decs.length) return decs[0].simplifiedValue;
2056
+ }
2057
+ return void 0;
2058
+ }
2059
+ getRootDecorators(decoratorName) {
2060
+ const sources = Array.from(this.sortedDataSources).reverse();
2061
+ const combinedDecsWithSources = [];
2062
+ for (const source of sources) {
2063
+ if (source.disabled) continue;
2064
+ if (source.isPartialImport) continue;
2065
+ const decs = source.getRootDecorators(decoratorName);
2066
+ combinedDecsWithSources.push([source, decs]);
2067
+ }
2068
+ return combinedDecsWithSources;
2078
2069
  }
2079
2070
  };
2080
2071
 
2081
2072
  // env-graph/lib/config-item.ts
2082
- var ConfigItem3 = class {
2073
+ var ConfigItem4 = class {
2083
2074
  static {
2084
2075
  __name(this, "ConfigItem");
2085
2076
  }
@@ -2096,9 +2087,19 @@ var ConfigItem3 = class {
2096
2087
  get key() {
2097
2088
  return this.#key;
2098
2089
  }
2099
- defs = [];
2100
- addDef(itemDef, source) {
2101
- this.defs.unshift({ itemDef, source });
2090
+ /**
2091
+ * fetch ordered list of definitions for this item, by following up sorted data sources list
2092
+ */
2093
+ get defs() {
2094
+ const defs = [];
2095
+ for (const source of this.#envGraph.sortedDataSources) {
2096
+ if (!source.configItemDefs[this.#key]) continue;
2097
+ if (source.disabled) continue;
2098
+ if (source.importKeys && !source.importKeys.includes(this.#key)) continue;
2099
+ const itemDef = source.configItemDefs[this.#key];
2100
+ if (itemDef) defs.push({ itemDef, source });
2101
+ }
2102
+ return defs;
2102
2103
  }
2103
2104
  get description() {
2104
2105
  for (const def of this.defs) {
@@ -2117,6 +2118,9 @@ var ConfigItem3 = class {
2117
2118
  return links;
2118
2119
  }
2119
2120
  get valueResolver() {
2121
+ if (this.key in this.envGraph.overrideValues) {
2122
+ return new StaticValueResolver(this.envGraph.overrideValues[this.key]);
2123
+ }
2120
2124
  for (const def of this.defs) {
2121
2125
  if (def.itemDef.resolver) return def.itemDef.resolver;
2122
2126
  }
@@ -2147,10 +2151,6 @@ var ConfigItem3 = class {
2147
2151
  return this.valueResolver?.schemaErrors || [];
2148
2152
  }
2149
2153
  async process() {
2150
- const finalOverrideDef = this.envGraph.finalOverridesDataSource?.configItemDefs[this.key];
2151
- if (finalOverrideDef) {
2152
- this.defs.unshift({ itemDef: finalOverrideDef, source: this.envGraph.finalOverridesDataSource });
2153
- }
2154
2154
  for (const def of this.defs) {
2155
2155
  await def.itemDef.resolver?.process(this);
2156
2156
  }
@@ -2178,6 +2178,25 @@ var ConfigItem3 = class {
2178
2178
  }
2179
2179
  this.processRequired();
2180
2180
  }
2181
+ /**
2182
+ * special early resolution helper
2183
+ * currently used to resolve the envFlag before everything else has been loaded
2184
+ * */
2185
+ async earlyResolve() {
2186
+ await this.process();
2187
+ for (const depKey of this.valueResolver?.deps || []) {
2188
+ const depItem = this.envGraph.configSchema[depKey];
2189
+ if (!depItem) {
2190
+ throw new Error(`eager resolution eror - non-existant dependency: ${depKey}`);
2191
+ }
2192
+ await depItem.process();
2193
+ if (depItem.valueResolver?.deps.length) {
2194
+ throw new Error("eager resolution cannot follow a chain of dependencies");
2195
+ }
2196
+ await depItem.resolve(true);
2197
+ }
2198
+ await this.resolve(true);
2199
+ }
2181
2200
  _isRequired = true;
2182
2201
  /**
2183
2202
  * need to track if required-ness is dynamic, e.g. based on current env
@@ -2206,7 +2225,7 @@ var ConfigItem3 = class {
2206
2225
  const requiredFnName = requiredDecoratorVal.name;
2207
2226
  const requiredFnArgs = requiredDecoratorVal.simplifiedArgs;
2208
2227
  if (requiredFnName === "forEnv") {
2209
- const currentEnv = this.#envGraph.envFlagValue;
2228
+ const currentEnv = def.source.envFlagValue;
2210
2229
  if (!currentEnv) {
2211
2230
  throw new SchemaError("Cannot set @required using forEnv() because environment flag is not set");
2212
2231
  }
@@ -2216,12 +2235,14 @@ var ConfigItem3 = class {
2216
2235
  }
2217
2236
  return;
2218
2237
  }
2219
- if ("defaultRequired" in def.source.decorators) {
2220
- const val = def.source.decorators.defaultRequired.simplifiedValue;
2221
- if (val === "infer") {
2238
+ const defaultRequiredValue = def.source.getRootDecoratorSimpleValue("defaultRequired");
2239
+ if (defaultRequiredValue !== void 0) {
2240
+ if (defaultRequiredValue === "infer") {
2222
2241
  if (def.source.type === "schema") {
2223
2242
  const resolver = def.itemDef.resolver;
2224
- if (resolver instanceof StaticValueResolver) {
2243
+ if (resolver === void 0) {
2244
+ this._isRequired = false;
2245
+ } else if (resolver instanceof StaticValueResolver) {
2225
2246
  this._isRequired = resolver.staticValue !== void 0 && resolver.staticValue !== "";
2226
2247
  } else {
2227
2248
  this._isRequired = true;
@@ -2231,7 +2252,7 @@ var ConfigItem3 = class {
2231
2252
  continue;
2232
2253
  }
2233
2254
  }
2234
- this._isRequired = val;
2255
+ this._isRequired = defaultRequiredValue;
2235
2256
  return;
2236
2257
  }
2237
2258
  }
@@ -2250,17 +2271,18 @@ var ConfigItem3 = class {
2250
2271
  const defDecorators = def.itemDef.decorators || {};
2251
2272
  if ("sensitive" in defDecorators) {
2252
2273
  return defDecorators.sensitive.simplifiedValue;
2253
- } else if ("defaultSensitive" in def.source.decorators) {
2254
- const dec = def.source.decorators.defaultSensitive;
2255
- if (dec.value instanceof ParsedEnvSpecFunctionCall && dec.value.name === "inferFromPrefix") {
2256
- const args = dec.value.simplifiedArgs;
2274
+ }
2275
+ const defaultSensitiveDec = def.source.getRootDecorators("defaultSensitive")[0];
2276
+ if (defaultSensitiveDec) {
2277
+ if (defaultSensitiveDec.value instanceof ParsedEnvSpecFunctionCall && defaultSensitiveDec.value.name === "inferFromPrefix") {
2278
+ const args = defaultSensitiveDec.value.simplifiedArgs;
2257
2279
  const prefix = Array.isArray(args) && args.length > 0 ? args[0] : void 0;
2258
2280
  if (typeof prefix === "string" && this.key.startsWith(prefix)) {
2259
2281
  return false;
2260
2282
  }
2261
2283
  return true;
2262
2284
  }
2263
- return dec.simplifiedValue;
2285
+ return defaultSensitiveDec.simplifiedValue;
2264
2286
  }
2265
2287
  }
2266
2288
  return true;
@@ -2291,18 +2313,31 @@ var ConfigItem3 = class {
2291
2313
  get isCoerced() {
2292
2314
  return this.resolvedRawValue !== this.resolvedValue;
2293
2315
  }
2294
- async resolve() {
2316
+ async resolve(reset2 = false) {
2295
2317
  if (this.schemaErrors.length) return;
2296
2318
  if (this.resolverSchemaErrors.length) return;
2297
- if (!this.valueResolver) throw new Error("Expected a resolver to be set");
2319
+ if (reset2) {
2320
+ this.isResolved = false;
2321
+ this.isValidated = false;
2322
+ this.resolutionError = void 0;
2323
+ this.coercionError = void 0;
2324
+ this.validationErrors = void 0;
2325
+ this.resolvedRawValue = void 0;
2326
+ this.resolvedValue = void 0;
2327
+ }
2298
2328
  if (this.isResolved) {
2299
2329
  return;
2300
2330
  }
2301
- try {
2302
- this.resolvedRawValue = await this.valueResolver.resolve();
2303
- } catch (err) {
2304
- this.resolutionError = new ResolutionError(`error resolving value: ${err}`);
2305
- this.resolutionError.cause = err;
2331
+ if (!this.valueResolver) {
2332
+ this.isResolved = true;
2333
+ this.resolvedRawValue = void 0;
2334
+ } else {
2335
+ try {
2336
+ this.resolvedRawValue = await this.valueResolver.resolve();
2337
+ } catch (err) {
2338
+ this.resolutionError = new ResolutionError(`error resolving value: ${err}`);
2339
+ this.resolutionError.cause = err;
2340
+ }
2306
2341
  }
2307
2342
  if (this.resolvedRawValue instanceof RegExp) {
2308
2343
  this.resolutionError = new ResolutionError("regex() is meant to be used within function args, not as a final resolved value");
@@ -2365,78 +2400,253 @@ var ConfigItem3 = class {
2365
2400
  // env-graph/lib/data-source.ts
2366
2401
  var DATA_SOURCE_TYPES = Object.freeze({
2367
2402
  schema: {
2368
- fileSuffixes: ["schema"],
2369
- precedence: 0
2403
+ fileSuffixes: ["schema"]
2370
2404
  },
2371
2405
  example: {
2372
- fileSuffixes: ["sample", "example"],
2373
- precedence: 1
2406
+ fileSuffixes: ["sample", "example"]
2374
2407
  },
2375
2408
  defaults: {
2376
- fileSuffixes: ["default", "defaults"],
2377
- precedence: 2
2409
+ fileSuffixes: ["default", "defaults"]
2378
2410
  },
2379
2411
  values: {
2380
- fileSuffixes: [],
2381
- precedence: 3
2412
+ fileSuffixes: []
2382
2413
  },
2383
2414
  overrides: {
2384
- fileSuffixes: ["local", "override"],
2385
- precedence: 4
2386
- }
2415
+ fileSuffixes: ["local", "override"]
2416
+ },
2417
+ container: {}
2387
2418
  });
2388
- var EnvGraphDataSource = class {
2419
+ var EnvGraphDataSource3 = class {
2389
2420
  static {
2390
2421
  __name(this, "EnvGraphDataSource");
2391
2422
  }
2392
2423
  static DATA_SOURCE_TYPES = DATA_SOURCE_TYPES;
2393
- // reference back to the graph
2424
+ /** reference back to the graph */
2394
2425
  graph;
2426
+ /** parent data source - everything except the root will have a parent */
2427
+ parent;
2428
+ /** child data sources */
2429
+ children = [];
2430
+ /**
2431
+ * tracks if this data source was imported, and additional settings about the import (restricting keys)
2432
+ * */
2433
+ importMeta;
2434
+ get isImport() {
2435
+ return !!this.importMeta?.isImport || !!this.parent?.isImport;
2436
+ }
2437
+ get isPartialImport() {
2438
+ return (this.importMeta?.importKeys || []).length > 0;
2439
+ }
2440
+ get importKeys() {
2441
+ const importKeysArrays = [];
2442
+ let currentSource = this;
2443
+ while (currentSource) {
2444
+ if (currentSource.importMeta?.importKeys && currentSource.importMeta.importKeys.length) {
2445
+ importKeysArrays.push(currentSource.importMeta.importKeys);
2446
+ }
2447
+ currentSource = currentSource.parent;
2448
+ }
2449
+ if (importKeysArrays.length) {
2450
+ const keysToImport = my_dash_default.intersection(...importKeysArrays);
2451
+ return keysToImport;
2452
+ }
2453
+ }
2454
+ /** adds a child data source and sets up the correct references in both directions */
2455
+ async addChild(child, importMeta) {
2456
+ if (!this.graph) throw new Error("expected graph to be set");
2457
+ this.children.unshift(child);
2458
+ child.parent = this;
2459
+ child.graph = this.graph;
2460
+ if (importMeta) child.importMeta = importMeta;
2461
+ await child.finishInit();
2462
+ }
2463
+ /** environment flag key (as set by @envFlag decorator) - only if set within this source */
2464
+ _envFlagKey;
2465
+ /** environment flag key getter that will follow up the parent chain */
2466
+ get envFlagKey() {
2467
+ return this._envFlagKey || this.parent?.envFlagKey;
2468
+ }
2469
+ /** helper to set the current envFlag key, also propogating upwards */
2470
+ setEnvFlag(key) {
2471
+ this._envFlagKey = key;
2472
+ if (this.parent && !this.isPartialImport && !this.parent._envFlagKey) {
2473
+ this.parent.setEnvFlag(key);
2474
+ }
2475
+ }
2476
+ /** environment flag config item getter (follows up the parent chain) */
2477
+ get envFlagConfigItem() {
2478
+ const envFlagKey = this.envFlagKey;
2479
+ return envFlagKey ? this.graph?.configSchema[envFlagKey] : void 0;
2480
+ }
2481
+ /** environment flag value getter (follows up the parent chain), and checks the graph-level fallback */
2482
+ get envFlagValue() {
2483
+ const envFlagItem = this.envFlagConfigItem;
2484
+ if (envFlagItem) return envFlagItem.resolvedValue;
2485
+ return this.graph.envFlagFallback;
2486
+ }
2487
+ /** helper to resolve the envFlag value */
2488
+ async resolveCurrentEnv() {
2489
+ const envFlagItem = this.envFlagConfigItem;
2490
+ if (envFlagItem) {
2491
+ await envFlagItem.earlyResolve();
2492
+ return envFlagItem.resolvedValue;
2493
+ }
2494
+ return this.graph.envFlagFallback;
2495
+ }
2496
+ /** finish init process for this data source */
2497
+ async finishInit() {
2498
+ if (!this.graph) throw new Error("expected graph to be set");
2499
+ await this._finishInit();
2500
+ if (this.loadingError) {
2501
+ return;
2502
+ }
2503
+ const disableDecorator = this.getRootDecorators("disable")?.[0];
2504
+ if (disableDecorator) {
2505
+ if (disableDecorator.value instanceof ParsedEnvSpecFunctionCall) {
2506
+ if (disableDecorator.value.name === "forEnv") {
2507
+ const disableForEnvs = disableDecorator.value.simplifiedArgs;
2508
+ if (!my_dash_default.isArray(disableForEnvs)) {
2509
+ this._loadingError = new Error("expected disable decorator args to be array");
2510
+ return;
2511
+ }
2512
+ const currentEnv = await this.resolveCurrentEnv();
2513
+ if (disableForEnvs.includes(currentEnv)) {
2514
+ this._disabled = true;
2515
+ }
2516
+ } else {
2517
+ this._loadingError = new Error(`unknown disable decorator function: ${disableDecorator.name}`);
2518
+ return;
2519
+ }
2520
+ } else if (disableDecorator.simplifiedValue) {
2521
+ this._disabled = true;
2522
+ }
2523
+ }
2524
+ if (this.disabled) return;
2525
+ const envFlagDecoratorValue = this.getRootDecoratorSimpleValue("envFlag");
2526
+ if (envFlagDecoratorValue) {
2527
+ if (!this.configItemDefs[envFlagDecoratorValue]) {
2528
+ this._loadingError = new Error(`@envFlag key ${envFlagDecoratorValue} must be an item within this schema`);
2529
+ return;
2530
+ }
2531
+ this.setEnvFlag(envFlagDecoratorValue);
2532
+ }
2533
+ for (const itemKey of this.importKeys || my_dash_default.keys(this.configItemDefs)) {
2534
+ const itemDef = this.configItemDefs[itemKey];
2535
+ if (!itemDef) continue;
2536
+ this.graph.configSchema[itemKey] ??= new ConfigItem4(this.graph, itemKey);
2537
+ }
2538
+ const importDecorators = this.getRootDecorators("import");
2539
+ if (importDecorators.length) {
2540
+ for (const importDecorator of importDecorators) {
2541
+ const importArgs = importDecorator.bareFnArgs?.simplifiedValues;
2542
+ if (!my_dash_default.isArray(importArgs)) {
2543
+ throw new Error("expected @import args to be array");
2544
+ }
2545
+ const importPath = importArgs[0];
2546
+ if (!importPath) throw new Error("@import decorator must have a value");
2547
+ if (!my_dash_default.isString(importPath)) throw new Error("expected @import path to be string");
2548
+ const importKeys = importArgs.slice(1);
2549
+ if (!importKeys.every(my_dash_default.isString)) {
2550
+ throw new Error("expected @import keys to all be strings");
2551
+ }
2552
+ if (importPath.startsWith("./") || importPath.startsWith("../")) {
2553
+ if (!(this instanceof FileBasedDataSource)) {
2554
+ throw new Error("@import of files can only be used from a file-based data source");
2555
+ }
2556
+ const fullImportPath = path2.resolve(this.fullPath, "..", importPath);
2557
+ const fileName = path2.basename(fullImportPath);
2558
+ if (this.graph.virtualImports) {
2559
+ if (importPath.endsWith("/")) {
2560
+ if (!Object.keys(this.graph.virtualImports).some((p) => p.startsWith(fullImportPath))) {
2561
+ this._loadingError = new Error(`Virtual directory import ${fullImportPath} not found`);
2562
+ return;
2563
+ }
2564
+ await this.addChild(new DirectoryDataSource(fullImportPath), {
2565
+ isImport: true,
2566
+ importKeys
2567
+ });
2568
+ } else {
2569
+ if (!this.graph.virtualImports[fullImportPath]) {
2570
+ this._loadingError = new Error(`Virtual import ${fullImportPath} not found`);
2571
+ return;
2572
+ }
2573
+ const source = new DotEnvFileDataSource(fullImportPath, {
2574
+ overrideContents: this.graph.virtualImports[fullImportPath]
2575
+ });
2576
+ await this.addChild(source, { isImport: true, importKeys });
2577
+ }
2578
+ } else {
2579
+ const fsStat = await tryCatch(async () => fs2.stat(importPath), (_err) => {
2580
+ });
2581
+ if (!fsStat) {
2582
+ this._loadingError = new Error(`Import path does not exist: ${fullImportPath}`);
2583
+ return;
2584
+ }
2585
+ if (importPath.endsWith("/")) {
2586
+ if (fsStat.isDirectory()) {
2587
+ await this.addChild(new DirectoryDataSource(fullImportPath), {
2588
+ isImport: true,
2589
+ importKeys
2590
+ });
2591
+ } else {
2592
+ this._loadingError = new Error(`Imported path ending with "/" is not a directory: ${fullImportPath}`);
2593
+ return;
2594
+ }
2595
+ } else {
2596
+ if (fsStat.isDirectory()) {
2597
+ this._loadingError = new Error('Imported path is a directory, add trailing "/" to import');
2598
+ return;
2599
+ } else if (!fileName.startsWith(".env.")) {
2600
+ this._loadingError = new Error("imported file must be a .env.* file");
2601
+ return;
2602
+ }
2603
+ await this.addChild(new DotEnvFileDataSource(fullImportPath), { isImport: true, importKeys });
2604
+ }
2605
+ }
2606
+ } else if (importPath.startsWith("http://") || importPath.startsWith("https://")) {
2607
+ this._loadingError = new Error("http imports not supported yet");
2608
+ return;
2609
+ } else if (importPath.startsWith("npm:")) {
2610
+ this._loadingError = new Error("npm imports not supported yet");
2611
+ return;
2612
+ } else {
2613
+ this._loadingError = new Error("unsupported import type");
2614
+ return;
2615
+ }
2616
+ }
2617
+ }
2618
+ }
2619
+ /**
2620
+ * called by the finishInit - meant to be overridden by subclasses
2621
+ * to add specific behaviour for that data source type
2622
+ * @internal
2623
+ * */
2624
+ async _finishInit() {
2625
+ }
2395
2626
  type = "values";
2396
2627
  applyForEnv;
2397
- disabled = false;
2398
- ignoreNewDefs = false;
2628
+ _disabled = false;
2629
+ get disabled() {
2630
+ return this._disabled || this.parent?._disabled;
2631
+ }
2399
2632
  /** an error encountered while loading/parsing the data source */
2400
- loadingError;
2633
+ _loadingError;
2634
+ get loadingError() {
2635
+ return this._loadingError;
2636
+ }
2401
2637
  get isValid() {
2402
2638
  return !this.loadingError;
2403
2639
  }
2404
2640
  configItemDefs = {};
2405
- decorators = {};
2406
- getStaticValues() {
2407
- const obj = {};
2408
- for (const [key, def] of Object.entries(this.configItemDefs)) {
2409
- if (def.resolver instanceof StaticValueResolver) {
2410
- obj[key] = String(def.resolver.staticValue ?? "");
2411
- }
2412
- }
2413
- return obj;
2641
+ decorators = [];
2642
+ getRootDecorators(decName) {
2643
+ return this.decorators.filter((d) => d.name === decName);
2414
2644
  }
2415
- };
2416
- var ProcessEnvDataSource = class _ProcessEnvDataSource extends EnvGraphDataSource {
2417
- static {
2418
- __name(this, "ProcessEnvDataSource");
2419
- }
2420
- type = "overrides";
2421
- typeLabel = "process";
2422
- label = "process.env";
2423
- ignoreNewDefs = true;
2424
- static processEnvValues;
2425
- // ? do we want to set decorator values from env vars here? -- ex: _ENV_FLAG_KEY
2426
- // depends if we want those to work only within process.env
2427
- constructor() {
2428
- super();
2429
- if (!_ProcessEnvDataSource.processEnvValues) {
2430
- _ProcessEnvDataSource.processEnvValues = {};
2431
- for (const itemKey of Object.keys(process.env)) {
2432
- _ProcessEnvDataSource.processEnvValues[itemKey] = process.env[itemKey];
2433
- }
2434
- }
2435
- for (const itemKey of Object.keys(_ProcessEnvDataSource.processEnvValues)) {
2436
- this.configItemDefs[itemKey] = {
2437
- resolver: new StaticValueResolver(_ProcessEnvDataSource.processEnvValues[itemKey])
2438
- };
2439
- }
2645
+ getRootDecoratorSimpleValue(decName) {
2646
+ const decorators = this.getRootDecorators(decName);
2647
+ if (decorators.length === 0) return void 0;
2648
+ if (decorators.length > 1) throw new Error(`Multiple ${decName} decorators found`);
2649
+ return decorators[0].simplifiedValue;
2440
2650
  }
2441
2651
  };
2442
2652
  var EnvSourceParseError = class extends Error {
@@ -2449,7 +2659,7 @@ var EnvSourceParseError = class extends Error {
2449
2659
  this.location = _location;
2450
2660
  }
2451
2661
  };
2452
- var FileBasedDataSource = class extends EnvGraphDataSource {
2662
+ var FileBasedDataSource = class extends EnvGraphDataSource3 {
2453
2663
  static {
2454
2664
  __name(this, "FileBasedDataSource");
2455
2665
  }
@@ -2472,40 +2682,44 @@ var FileBasedDataSource = class extends EnvGraphDataSource {
2472
2682
  constructor(fullPath, opts) {
2473
2683
  super();
2474
2684
  this.fullPath = fullPath;
2475
- this.fileName = path.basename(fullPath);
2685
+ this.fileName = path2.basename(fullPath);
2476
2686
  if (opts?.overrideContents) {
2477
2687
  this.rawContents = opts.overrideContents;
2478
2688
  this.isGitIgnored = opts.overrideGitIgnored;
2479
2689
  }
2480
- if (!this.fileName.startsWith(".env")) {
2481
- throw new Error('file name must start with ".env"');
2482
- }
2483
- const fileNameParts = this.fileName.substring(1).split(".");
2484
- const maybeExtension = fileNameParts[fileNameParts.length - 1];
2485
- if (this.validFileExtensions.includes(maybeExtension)) {
2486
- fileNameParts.pop();
2487
- }
2488
- const maybeFileType = fileNameParts[fileNameParts.length - 1];
2489
- for (const [possibleSourceType, possibleSourceSpec] of Object.entries(DATA_SOURCE_TYPES)) {
2490
- if (possibleSourceSpec.fileSuffixes.includes(maybeFileType)) {
2491
- this.type = possibleSourceType;
2492
- break;
2690
+ if (this.fileName.startsWith(".env")) {
2691
+ const fileNameParts = this.fileName.substring(1).split(".");
2692
+ const maybeExtension = fileNameParts[fileNameParts.length - 1];
2693
+ if (this.validFileExtensions.includes(maybeExtension)) {
2694
+ fileNameParts.pop();
2695
+ }
2696
+ const maybeFileType = fileNameParts[fileNameParts.length - 1];
2697
+ for (const [possibleSourceType, possibleSourceSpec] of Object.entries(DATA_SOURCE_TYPES)) {
2698
+ if (!("fileSuffixes" in possibleSourceSpec)) continue;
2699
+ if (possibleSourceSpec.fileSuffixes.includes(maybeFileType)) {
2700
+ this.type = possibleSourceType;
2701
+ break;
2702
+ }
2703
+ }
2704
+ if (this.type !== "values") fileNameParts.pop();
2705
+ if (fileNameParts.length > 2) {
2706
+ throw Error(`Unsure how to interpret filename - ${this.fileName}`);
2707
+ } else if (fileNameParts.length === 2) {
2708
+ this.applyForEnv = fileNameParts[1];
2493
2709
  }
2494
- }
2495
- if (this.type !== "values") fileNameParts.pop();
2496
- if (fileNameParts.length > 2) {
2497
- throw Error(`Unsure how to interpret filename - ${this.fileName}`);
2498
- } else if (fileNameParts.length === 2) {
2499
- this.applyForEnv = fileNameParts[1];
2500
2710
  }
2501
2711
  }
2502
2712
  // no async constructors... :(
2503
- async finishInit() {
2713
+ async _finishInit() {
2504
2714
  if (!this.rawContents) {
2715
+ if (!await pathExists(this.fullPath)) {
2716
+ this._loadingError = new Error(`File does not exist: ${this.fullPath}`);
2717
+ return;
2718
+ }
2505
2719
  this.isGitIgnored = await checkIsFileGitIgnored(this.fullPath);
2506
2720
  this.rawContents = await fs2.readFile(this.fullPath, "utf8");
2507
2721
  }
2508
- await this._parseContents();
2722
+ if (this.rawContents) await this._parseContents();
2509
2723
  }
2510
2724
  };
2511
2725
  var DotEnvFileDataSource = class extends FileBasedDataSource {
@@ -2519,7 +2733,7 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
2519
2733
  convertParserValueToResolvers(value) {
2520
2734
  if (!this.graph) throw new Error("expected graph to be set");
2521
2735
  if (value === void 0) {
2522
- return new StaticValueResolver(void 0);
2736
+ return void 0;
2523
2737
  } else if (value instanceof ParsedEnvSpecStaticValue) {
2524
2738
  return new StaticValueResolver(value.unescapedValue);
2525
2739
  } else if (value instanceof ParsedEnvSpecFunctionCall) {
@@ -2533,12 +2747,16 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
2533
2747
  for (const arg of argsFromParser) {
2534
2748
  if (arg instanceof ParsedEnvSpecKeyValuePair) {
2535
2749
  keyValueArgs ??= {};
2536
- keyValueArgs[arg.key] = this.convertParserValueToResolvers(arg.value);
2750
+ const valResolver = this.convertParserValueToResolvers(arg.value);
2751
+ if (!valResolver) throw new Error("Did not expect to find undefined resolver in key-value arg");
2752
+ keyValueArgs[arg.key] = valResolver;
2537
2753
  } else {
2538
2754
  if (keyValueArgs) {
2539
2755
  return new ErrorResolver(new SchemaError("After switching to key-value function args, cannot switch back"));
2540
2756
  }
2541
- argsAsResolversArray.push(this.convertParserValueToResolvers(arg));
2757
+ const argResolver = this.convertParserValueToResolvers(arg);
2758
+ if (!argResolver) throw new Error("Did not expect to find undefined resolver in array arg");
2759
+ argsAsResolversArray.push(argResolver);
2542
2760
  }
2543
2761
  }
2544
2762
  if (keyValueArgs) argsAsResolversArray.push(keyValueArgs);
@@ -2552,19 +2770,19 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
2552
2770
  this.parsedFile = await tryCatch(
2553
2771
  () => parseEnvSpecDotEnvFile(rawContents),
2554
2772
  (error) => {
2555
- this.loadingError = new EnvSourceParseError(error.message, {
2773
+ this._loadingError = new EnvSourceParseError(error.message, {
2556
2774
  path: this.fullPath,
2557
2775
  lineNumber: error.location.start.line,
2558
2776
  colNumber: error.location.start.column,
2559
2777
  lineStr: rawContents.split("\n")[error.location.start.line - 1]
2560
2778
  });
2561
- this.loadingError.cause = error;
2779
+ this._loadingError.cause = error;
2562
2780
  }
2563
2781
  );
2564
2782
  if (this.loadingError) return;
2565
2783
  if (!this.parsedFile) throw new Error("Failed to parse .env file");
2566
- this.decorators = this.parsedFile.decoratorsObject;
2567
2784
  if (!this.graph) throw new Error("expected graph to be set");
2785
+ this.decorators = this.parsedFile.decoratorsArray;
2568
2786
  for (const item of this.parsedFile.configItems) {
2569
2787
  item.processExpansion();
2570
2788
  this.configItemDefs[item.key] = {
@@ -2575,24 +2793,54 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
2575
2793
  }
2576
2794
  }
2577
2795
  };
2578
- var SKIP_FILE_TYPES = [".md", ".d.ts"];
2579
- async function findEnvFiles(opts) {
2580
- const cwd = opts?.cwd || process.cwd();
2581
- const envFiles = [];
2582
- const filesWithinDir = await fs2.readdir(cwd);
2583
- for (const fileName of filesWithinDir) {
2584
- if (fileName === ".env" || fileName.startsWith(".env.")) {
2585
- let skip = false;
2586
- for (const fileType of SKIP_FILE_TYPES) {
2587
- if (fileName.endsWith(fileType)) skip = true;
2796
+ var DirectoryDataSource = class extends EnvGraphDataSource3 {
2797
+ constructor(basePath) {
2798
+ super();
2799
+ this.basePath = basePath;
2800
+ }
2801
+ static {
2802
+ __name(this, "DirectoryDataSource");
2803
+ }
2804
+ type = "container";
2805
+ typeLabel = "directory";
2806
+ get label() {
2807
+ return `directory - ${this.basePath}`;
2808
+ }
2809
+ schemaDataSource;
2810
+ get loadingError() {
2811
+ return this._loadingError || this.schemaDataSource?.loadingError;
2812
+ }
2813
+ async addAutoLoadedFile(fileName) {
2814
+ if (!this.graph) throw new Error("expected graph to be set");
2815
+ const filePath = path2.join(this.basePath, fileName);
2816
+ if (this.graph.virtualImports) {
2817
+ if (this.graph.virtualImports[filePath]) {
2818
+ const source2 = new DotEnvFileDataSource(filePath, { overrideContents: this.graph.virtualImports[filePath] });
2819
+ await this.addChild(source2);
2820
+ return source2;
2588
2821
  }
2589
- if (skip) continue;
2590
- envFiles.push(path.join(cwd, fileName));
2822
+ return;
2591
2823
  }
2824
+ if (!await pathExists(filePath)) return;
2825
+ const source = new DotEnvFileDataSource(filePath);
2826
+ await this.addChild(source);
2827
+ return source;
2592
2828
  }
2593
- return envFiles;
2594
- }
2595
- __name(findEnvFiles, "findEnvFiles");
2829
+ async _finishInit() {
2830
+ if (!this.graph) throw new Error("expected graph to be set");
2831
+ await this.addAutoLoadedFile(".env.schema");
2832
+ await this.addAutoLoadedFile(".env");
2833
+ if (this.children.length) {
2834
+ this.schemaDataSource = this.children[this.children.length - 1];
2835
+ }
2836
+ await this.addAutoLoadedFile(".env.local");
2837
+ const currentEnv = await this.resolveCurrentEnv() || this.envFlagValue;
2838
+ if (currentEnv) {
2839
+ await this.addAutoLoadedFile(`.env.${currentEnv}`);
2840
+ await this.addAutoLoadedFile(`.env.${currentEnv}.local`);
2841
+ }
2842
+ }
2843
+ };
2596
2844
 
2597
2845
  // env-graph/lib/loader.ts
2598
2846
  function autoDetectBasePath() {
@@ -2610,17 +2858,9 @@ async function loadEnvGraph(opts) {
2610
2858
  await opts.afterInit(graph);
2611
2859
  }
2612
2860
  if (opts?.currentEnvFallback) {
2613
- graph.envFlagValue = opts.currentEnvFallback;
2614
- }
2615
- const envFilePaths = await findEnvFiles({
2616
- cwd: graph.basePath
2617
- });
2618
- for (const envFilePath of envFilePaths) {
2619
- const fileDataSource = new DotEnvFileDataSource(envFilePath);
2620
- graph.addDataSource(fileDataSource);
2621
- await fileDataSource.finishInit();
2861
+ graph.envFlagFallback = opts.currentEnvFallback;
2622
2862
  }
2623
- graph.finalOverridesDataSource = new ProcessEnvDataSource();
2863
+ await graph.setRootDataSource(new DirectoryDataSource(graph.basePath));
2624
2864
  await graph.finishLoad();
2625
2865
  return graph;
2626
2866
  }
@@ -2807,6 +3047,6 @@ function gracefulExit(signal = 0) {
2807
3047
  __name(gracefulExit, "gracefulExit");
2808
3048
  //! these are probably not relevant anymore, or needs to move to a plugin layer?
2809
3049
 
2810
- export { CoercionError, ConfigLoadError, DotEnvFileDataSource, EnvGraph2 as EnvGraph, EnvSourceParseError, ProcessEnvDataSource, ResolutionError, SchemaError, StaticValueResolver, ValidationError, ansis_default, asyncExitHook, checkIsFileGitIgnored, getItemSummary, gracefulExit, joinAndCompact, loadEnvGraph, my_dash_default };
2811
- //# sourceMappingURL=chunk-NXAXPMO5.js.map
2812
- //# sourceMappingURL=chunk-NXAXPMO5.js.map
3050
+ export { CoercionError, ConfigLoadError, DotEnvFileDataSource, EnvGraph2 as EnvGraph, EnvSourceParseError, FileBasedDataSource, ResolutionError, SchemaError, ValidationError, ansis_default, asyncExitHook, checkIsFileGitIgnored, getItemSummary, gracefulExit, joinAndCompact, loadEnvGraph, my_dash_default, pathExists, pathExistsSync, tryCatch };
3051
+ //# sourceMappingURL=chunk-FCVBOYES.js.map
3052
+ //# sourceMappingURL=chunk-FCVBOYES.js.map