varlock 0.0.12 → 0.0.13
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/{chunk-52FLZJCQ.js → chunk-5EBVEGDW.js} +5 -24
- package/dist/chunk-5EBVEGDW.js.map +1 -0
- package/dist/{chunk-IBMSAOL6.js → chunk-AS4LIW7A.js} +21 -15
- package/dist/chunk-AS4LIW7A.js.map +1 -0
- package/dist/{chunk-2GR4YQFJ.js → chunk-IML4QZHB.js} +4 -5
- package/dist/chunk-IML4QZHB.js.map +1 -0
- package/dist/{chunk-MHDV65DI.js → chunk-LXJMZMID.js} +98 -66
- package/dist/chunk-LXJMZMID.js.map +1 -0
- package/dist/{chunk-NXAXPMO5.js → chunk-MV5ZAKN7.js} +483 -243
- package/dist/chunk-MV5ZAKN7.js.map +1 -0
- package/dist/{chunk-AMAUWR7O.js → chunk-MVYXWTAV.js} +4 -4
- package/dist/{chunk-AMAUWR7O.js.map → chunk-MVYXWTAV.js.map} +1 -1
- package/dist/{chunk-23GW4X5J.js → chunk-T3I4UFB2.js} +16 -5
- package/dist/chunk-T3I4UFB2.js.map +1 -0
- package/dist/{chunk-LBVGWRPL.js → chunk-UA3DMAAQ.js} +4 -4
- package/dist/{chunk-LBVGWRPL.js.map → chunk-UA3DMAAQ.js.map} +1 -1
- package/dist/cli/cli-executable.js +14 -15
- package/dist/cli/cli-executable.js.map +1 -1
- package/dist/{env-DxiD5Ylz.d.ts → env-B_LAqK4w.d.ts} +94 -63
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/init.command-CTO64XBL.js +8 -0
- package/dist/{init.command-ZSH7NCV7.js.map → init.command-CTO64XBL.js.map} +1 -1
- package/dist/load.command-EWIJDF55.js +8 -0
- package/dist/{load.command-U2GASZRB.js.map → load.command-EWIJDF55.js.map} +1 -1
- package/dist/login.command-UZJJ4XTV.js +8 -0
- package/dist/{login.command-2WG4GZV4.js.map → login.command-UZJJ4XTV.js.map} +1 -1
- package/dist/run.command-T44BAZ7X.js +8 -0
- package/dist/{run.command-IETNJ6UU.js.map → run.command-T44BAZ7X.js.map} +1 -1
- package/dist/runtime/env.d.ts +1 -1
- package/dist/telemetry.command-2C3MQA4K.js +8 -0
- package/dist/{telemetry.command-US72HXMS.js.map → telemetry.command-2C3MQA4K.js.map} +1 -1
- package/package.json +2 -2
- package/dist/chunk-23GW4X5J.js.map +0 -1
- package/dist/chunk-2GR4YQFJ.js.map +0 -1
- package/dist/chunk-52FLZJCQ.js.map +0 -1
- package/dist/chunk-IBMSAOL6.js.map +0 -1
- package/dist/chunk-MHDV65DI.js.map +0 -1
- package/dist/chunk-NXAXPMO5.js.map +0 -1
- package/dist/chunk-Y2EGAWAH.js +0 -17
- package/dist/chunk-Y2EGAWAH.js.map +0 -1
- package/dist/init.command-ZSH7NCV7.js +0 -9
- package/dist/load.command-U2GASZRB.js +0 -9
- package/dist/login.command-2WG4GZV4.js +0 -8
- package/dist/run.command-IETNJ6UU.js +0 -9
- 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
|
|
6
|
-
import
|
|
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 }, (
|
|
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(
|
|
978
|
+
async function checkIsFileGitIgnored(path3, warnIfNotGitRepo = false) {
|
|
952
979
|
try {
|
|
953
|
-
await asyncExec(`git check-ignore ${
|
|
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
|
-
|
|
972
|
-
|
|
973
|
-
|
|
997
|
+
async function pathExists(p) {
|
|
998
|
+
try {
|
|
999
|
+
await access(p);
|
|
1000
|
+
return true;
|
|
1001
|
+
} catch {
|
|
1002
|
+
return false;
|
|
1003
|
+
}
|
|
974
1004
|
}
|
|
975
|
-
__name(
|
|
976
|
-
|
|
1005
|
+
__name(pathExists, "pathExists");
|
|
1006
|
+
function pathExistsSync(p) {
|
|
977
1007
|
try {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
await catchResult;
|
|
983
|
-
}
|
|
1008
|
+
accessSync(p);
|
|
1009
|
+
return true;
|
|
1010
|
+
} catch {
|
|
1011
|
+
return false;
|
|
984
1012
|
}
|
|
985
1013
|
}
|
|
986
|
-
__name(
|
|
1014
|
+
__name(pathExistsSync, "pathExistsSync");
|
|
987
1015
|
|
|
988
1016
|
// env-graph/lib/data-types.ts
|
|
989
1017
|
var EnvGraphDataType = class {
|
|
@@ -1833,16 +1861,16 @@ export type EnvSchemaAsStrings = {
|
|
|
1833
1861
|
return tsSrc.join("\n");
|
|
1834
1862
|
}
|
|
1835
1863
|
__name(generateTsTypesSrc, "generateTsTypesSrc");
|
|
1836
|
-
async function generateTypes(graph, lang,
|
|
1864
|
+
async function generateTypes(graph, lang, typesPath) {
|
|
1837
1865
|
if (lang !== "ts") throw new Error(`Unsupported @generateTypes lang: ${lang}`);
|
|
1838
1866
|
const tsSrc = await generateTsTypesSrc(graph);
|
|
1839
|
-
if (!graph.basePath) return;
|
|
1840
|
-
const typesPath = path.join(graph.basePath, outputPath);
|
|
1841
1867
|
await fs.promises.writeFile(typesPath, tsSrc, "utf-8");
|
|
1842
1868
|
}
|
|
1843
1869
|
__name(generateTypes, "generateTypes");
|
|
1844
1870
|
|
|
1845
1871
|
// env-graph/lib/env-graph.ts
|
|
1872
|
+
var processExists = !!globalThis.process;
|
|
1873
|
+
var originalProcessEnv = { ...processExists && process.env };
|
|
1846
1874
|
var EnvGraph2 = class {
|
|
1847
1875
|
static {
|
|
1848
1876
|
__name(this, "EnvGraph");
|
|
@@ -1851,26 +1879,29 @@ var EnvGraph2 = class {
|
|
|
1851
1879
|
// or just the files that are relevant to the current resolution attempt
|
|
1852
1880
|
// (which would mean it's always through the lens of the current directory/package)
|
|
1853
1881
|
basePath;
|
|
1854
|
-
/**
|
|
1855
|
-
|
|
1856
|
-
|
|
1882
|
+
/** root data source (.env.schema) */
|
|
1883
|
+
rootDataSource;
|
|
1884
|
+
/** place to store process.env overrides */
|
|
1885
|
+
overrideValues = {};
|
|
1857
1886
|
/** config item key of env flag (toggles env-specific data sources enabled) */
|
|
1858
1887
|
envFlagKey;
|
|
1859
|
-
/**
|
|
1860
|
-
|
|
1888
|
+
/** graph-level fallback value for environment flag */
|
|
1889
|
+
envFlagFallback;
|
|
1861
1890
|
configSchema = {};
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
if (schemas.length === 0) return void 0;
|
|
1870
|
-
return schemas[0];
|
|
1891
|
+
/** virtual imports for testing */
|
|
1892
|
+
virtualImports;
|
|
1893
|
+
setVirtualImports(basePath, files) {
|
|
1894
|
+
this.virtualImports = {};
|
|
1895
|
+
for (const [fileName, fileContents] of Object.entries(files)) {
|
|
1896
|
+
this.virtualImports[path2.join(basePath, fileName)] = fileContents;
|
|
1897
|
+
}
|
|
1871
1898
|
}
|
|
1872
1899
|
get sortedDataSources() {
|
|
1873
|
-
|
|
1900
|
+
function getSourceAndChildren(s) {
|
|
1901
|
+
return [s, ...s.children ? s.children.flatMap(getSourceAndChildren) : []];
|
|
1902
|
+
}
|
|
1903
|
+
__name(getSourceAndChildren, "getSourceAndChildren");
|
|
1904
|
+
return this.rootDataSource ? getSourceAndChildren(this.rootDataSource) : [];
|
|
1874
1905
|
}
|
|
1875
1906
|
registeredResolverFunctions = {};
|
|
1876
1907
|
registerResolver(resolverClass) {
|
|
@@ -1891,78 +1922,15 @@ var EnvGraph2 = class {
|
|
|
1891
1922
|
for (const resolverClass of BaseResolvers) {
|
|
1892
1923
|
this.registerResolver(resolverClass);
|
|
1893
1924
|
}
|
|
1925
|
+
this.overrideValues = originalProcessEnv;
|
|
1926
|
+
}
|
|
1927
|
+
async setRootDataSource(source) {
|
|
1928
|
+
if (this.rootDataSource) throw new Error("root data source already set");
|
|
1929
|
+
this.rootDataSource = source;
|
|
1930
|
+
source.graph = this;
|
|
1931
|
+
await source.finishInit();
|
|
1894
1932
|
}
|
|
1895
1933
|
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
1934
|
for (const itemKey in this.configSchema) {
|
|
1967
1935
|
const item = this.configSchema[itemKey];
|
|
1968
1936
|
await item.process();
|
|
@@ -1988,6 +1956,7 @@ var EnvGraph2 = class {
|
|
|
1988
1956
|
return adjList;
|
|
1989
1957
|
}
|
|
1990
1958
|
async resolveEnvValues() {
|
|
1959
|
+
if (my_dash_default.keys(this.configSchema).length === 0) return;
|
|
1991
1960
|
const adjList = this.graphAdjacencyList;
|
|
1992
1961
|
const reverseAdjList = {};
|
|
1993
1962
|
for (const itemKey in adjList) {
|
|
@@ -2052,7 +2021,7 @@ var EnvGraph2 = class {
|
|
|
2052
2021
|
serializedGraph.sources.push({
|
|
2053
2022
|
label: source.label,
|
|
2054
2023
|
enabled: !source.disabled,
|
|
2055
|
-
path: source instanceof FileBasedDataSource ?
|
|
2024
|
+
path: source instanceof FileBasedDataSource ? path2.relative(this.basePath ?? "", source.fullPath) : void 0
|
|
2056
2025
|
});
|
|
2057
2026
|
}
|
|
2058
2027
|
for (const itemKey in this.configSchema) {
|
|
@@ -2073,13 +2042,30 @@ var EnvGraph2 = class {
|
|
|
2073
2042
|
await generateTypes(this, lang, outputPath);
|
|
2074
2043
|
}
|
|
2075
2044
|
getRootDecoratorValue(decoratorName) {
|
|
2076
|
-
const
|
|
2077
|
-
|
|
2045
|
+
const sources = Array.from(this.sortedDataSources).reverse();
|
|
2046
|
+
for (const s of sources) {
|
|
2047
|
+
if (s.disabled) continue;
|
|
2048
|
+
if (s.importKeys) continue;
|
|
2049
|
+
const decs = s.getRootDecorators(decoratorName);
|
|
2050
|
+
if (decs.length) return decs[0].simplifiedValue;
|
|
2051
|
+
}
|
|
2052
|
+
return void 0;
|
|
2053
|
+
}
|
|
2054
|
+
getRootDecorators(decoratorName) {
|
|
2055
|
+
const sources = Array.from(this.sortedDataSources).reverse();
|
|
2056
|
+
const combinedDecsWithSources = [];
|
|
2057
|
+
for (const source of sources) {
|
|
2058
|
+
if (source.disabled) continue;
|
|
2059
|
+
if (source.importKeys) continue;
|
|
2060
|
+
const decs = source.getRootDecorators(decoratorName);
|
|
2061
|
+
combinedDecsWithSources.push([source, decs]);
|
|
2062
|
+
}
|
|
2063
|
+
return combinedDecsWithSources;
|
|
2078
2064
|
}
|
|
2079
2065
|
};
|
|
2080
2066
|
|
|
2081
2067
|
// env-graph/lib/config-item.ts
|
|
2082
|
-
var
|
|
2068
|
+
var ConfigItem4 = class {
|
|
2083
2069
|
static {
|
|
2084
2070
|
__name(this, "ConfigItem");
|
|
2085
2071
|
}
|
|
@@ -2096,9 +2082,19 @@ var ConfigItem3 = class {
|
|
|
2096
2082
|
get key() {
|
|
2097
2083
|
return this.#key;
|
|
2098
2084
|
}
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2085
|
+
/**
|
|
2086
|
+
* fetch ordered list of definitions for this item, by following up sorted data sources list
|
|
2087
|
+
*/
|
|
2088
|
+
get defs() {
|
|
2089
|
+
const defs = [];
|
|
2090
|
+
for (const source of this.#envGraph.sortedDataSources) {
|
|
2091
|
+
if (!source.configItemDefs[this.#key]) continue;
|
|
2092
|
+
if (source.disabled) continue;
|
|
2093
|
+
if (source.importKeys && !source.importKeys.includes(this.#key)) continue;
|
|
2094
|
+
const itemDef = source.configItemDefs[this.#key];
|
|
2095
|
+
if (itemDef) defs.push({ itemDef, source });
|
|
2096
|
+
}
|
|
2097
|
+
return defs;
|
|
2102
2098
|
}
|
|
2103
2099
|
get description() {
|
|
2104
2100
|
for (const def of this.defs) {
|
|
@@ -2117,6 +2113,9 @@ var ConfigItem3 = class {
|
|
|
2117
2113
|
return links;
|
|
2118
2114
|
}
|
|
2119
2115
|
get valueResolver() {
|
|
2116
|
+
if (this.key in this.envGraph.overrideValues) {
|
|
2117
|
+
return new StaticValueResolver(this.envGraph.overrideValues[this.key]);
|
|
2118
|
+
}
|
|
2120
2119
|
for (const def of this.defs) {
|
|
2121
2120
|
if (def.itemDef.resolver) return def.itemDef.resolver;
|
|
2122
2121
|
}
|
|
@@ -2147,10 +2146,6 @@ var ConfigItem3 = class {
|
|
|
2147
2146
|
return this.valueResolver?.schemaErrors || [];
|
|
2148
2147
|
}
|
|
2149
2148
|
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
2149
|
for (const def of this.defs) {
|
|
2155
2150
|
await def.itemDef.resolver?.process(this);
|
|
2156
2151
|
}
|
|
@@ -2178,6 +2173,25 @@ var ConfigItem3 = class {
|
|
|
2178
2173
|
}
|
|
2179
2174
|
this.processRequired();
|
|
2180
2175
|
}
|
|
2176
|
+
/**
|
|
2177
|
+
* special early resolution helper
|
|
2178
|
+
* currently used to resolve the envFlag before everything else has been loaded
|
|
2179
|
+
* */
|
|
2180
|
+
async earlyResolve() {
|
|
2181
|
+
await this.process();
|
|
2182
|
+
for (const depKey of this.valueResolver?.deps || []) {
|
|
2183
|
+
const depItem = this.envGraph.configSchema[depKey];
|
|
2184
|
+
if (!depItem) {
|
|
2185
|
+
throw new Error(`eager resolution eror - non-existant dependency: ${depKey}`);
|
|
2186
|
+
}
|
|
2187
|
+
await depItem.process();
|
|
2188
|
+
if (depItem.valueResolver?.deps.length) {
|
|
2189
|
+
throw new Error("eager resolution cannot follow a chain of dependencies");
|
|
2190
|
+
}
|
|
2191
|
+
await depItem.resolve(true);
|
|
2192
|
+
}
|
|
2193
|
+
await this.resolve(true);
|
|
2194
|
+
}
|
|
2181
2195
|
_isRequired = true;
|
|
2182
2196
|
/**
|
|
2183
2197
|
* need to track if required-ness is dynamic, e.g. based on current env
|
|
@@ -2206,7 +2220,7 @@ var ConfigItem3 = class {
|
|
|
2206
2220
|
const requiredFnName = requiredDecoratorVal.name;
|
|
2207
2221
|
const requiredFnArgs = requiredDecoratorVal.simplifiedArgs;
|
|
2208
2222
|
if (requiredFnName === "forEnv") {
|
|
2209
|
-
const currentEnv =
|
|
2223
|
+
const currentEnv = def.source.envFlagValue;
|
|
2210
2224
|
if (!currentEnv) {
|
|
2211
2225
|
throw new SchemaError("Cannot set @required using forEnv() because environment flag is not set");
|
|
2212
2226
|
}
|
|
@@ -2216,12 +2230,14 @@ var ConfigItem3 = class {
|
|
|
2216
2230
|
}
|
|
2217
2231
|
return;
|
|
2218
2232
|
}
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
if (
|
|
2233
|
+
const defaultRequiredValue = def.source.getRootDecoratorSimpleValue("defaultRequired");
|
|
2234
|
+
if (defaultRequiredValue !== void 0) {
|
|
2235
|
+
if (defaultRequiredValue === "infer") {
|
|
2222
2236
|
if (def.source.type === "schema") {
|
|
2223
2237
|
const resolver = def.itemDef.resolver;
|
|
2224
|
-
if (resolver
|
|
2238
|
+
if (resolver === void 0) {
|
|
2239
|
+
this._isRequired = false;
|
|
2240
|
+
} else if (resolver instanceof StaticValueResolver) {
|
|
2225
2241
|
this._isRequired = resolver.staticValue !== void 0 && resolver.staticValue !== "";
|
|
2226
2242
|
} else {
|
|
2227
2243
|
this._isRequired = true;
|
|
@@ -2231,7 +2247,7 @@ var ConfigItem3 = class {
|
|
|
2231
2247
|
continue;
|
|
2232
2248
|
}
|
|
2233
2249
|
}
|
|
2234
|
-
this._isRequired =
|
|
2250
|
+
this._isRequired = defaultRequiredValue;
|
|
2235
2251
|
return;
|
|
2236
2252
|
}
|
|
2237
2253
|
}
|
|
@@ -2250,17 +2266,18 @@ var ConfigItem3 = class {
|
|
|
2250
2266
|
const defDecorators = def.itemDef.decorators || {};
|
|
2251
2267
|
if ("sensitive" in defDecorators) {
|
|
2252
2268
|
return defDecorators.sensitive.simplifiedValue;
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2269
|
+
}
|
|
2270
|
+
const defaultSensitiveDec = def.source.getRootDecorators("defaultSensitive")[0];
|
|
2271
|
+
if (defaultSensitiveDec) {
|
|
2272
|
+
if (defaultSensitiveDec.value instanceof ParsedEnvSpecFunctionCall && defaultSensitiveDec.value.name === "inferFromPrefix") {
|
|
2273
|
+
const args = defaultSensitiveDec.value.simplifiedArgs;
|
|
2257
2274
|
const prefix = Array.isArray(args) && args.length > 0 ? args[0] : void 0;
|
|
2258
2275
|
if (typeof prefix === "string" && this.key.startsWith(prefix)) {
|
|
2259
2276
|
return false;
|
|
2260
2277
|
}
|
|
2261
2278
|
return true;
|
|
2262
2279
|
}
|
|
2263
|
-
return
|
|
2280
|
+
return defaultSensitiveDec.simplifiedValue;
|
|
2264
2281
|
}
|
|
2265
2282
|
}
|
|
2266
2283
|
return true;
|
|
@@ -2291,18 +2308,31 @@ var ConfigItem3 = class {
|
|
|
2291
2308
|
get isCoerced() {
|
|
2292
2309
|
return this.resolvedRawValue !== this.resolvedValue;
|
|
2293
2310
|
}
|
|
2294
|
-
async resolve() {
|
|
2311
|
+
async resolve(reset2 = false) {
|
|
2295
2312
|
if (this.schemaErrors.length) return;
|
|
2296
2313
|
if (this.resolverSchemaErrors.length) return;
|
|
2297
|
-
if (
|
|
2314
|
+
if (reset2) {
|
|
2315
|
+
this.isResolved = false;
|
|
2316
|
+
this.isValidated = false;
|
|
2317
|
+
this.resolutionError = void 0;
|
|
2318
|
+
this.coercionError = void 0;
|
|
2319
|
+
this.validationErrors = void 0;
|
|
2320
|
+
this.resolvedRawValue = void 0;
|
|
2321
|
+
this.resolvedValue = void 0;
|
|
2322
|
+
}
|
|
2298
2323
|
if (this.isResolved) {
|
|
2299
2324
|
return;
|
|
2300
2325
|
}
|
|
2301
|
-
|
|
2302
|
-
this.
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2326
|
+
if (!this.valueResolver) {
|
|
2327
|
+
this.isResolved = true;
|
|
2328
|
+
this.resolvedRawValue = void 0;
|
|
2329
|
+
} else {
|
|
2330
|
+
try {
|
|
2331
|
+
this.resolvedRawValue = await this.valueResolver.resolve();
|
|
2332
|
+
} catch (err) {
|
|
2333
|
+
this.resolutionError = new ResolutionError(`error resolving value: ${err}`);
|
|
2334
|
+
this.resolutionError.cause = err;
|
|
2335
|
+
}
|
|
2306
2336
|
}
|
|
2307
2337
|
if (this.resolvedRawValue instanceof RegExp) {
|
|
2308
2338
|
this.resolutionError = new ResolutionError("regex() is meant to be used within function args, not as a final resolved value");
|
|
@@ -2365,78 +2395,255 @@ var ConfigItem3 = class {
|
|
|
2365
2395
|
// env-graph/lib/data-source.ts
|
|
2366
2396
|
var DATA_SOURCE_TYPES = Object.freeze({
|
|
2367
2397
|
schema: {
|
|
2368
|
-
fileSuffixes: ["schema"]
|
|
2369
|
-
precedence: 0
|
|
2398
|
+
fileSuffixes: ["schema"]
|
|
2370
2399
|
},
|
|
2371
2400
|
example: {
|
|
2372
|
-
fileSuffixes: ["sample", "example"]
|
|
2373
|
-
precedence: 1
|
|
2401
|
+
fileSuffixes: ["sample", "example"]
|
|
2374
2402
|
},
|
|
2375
2403
|
defaults: {
|
|
2376
|
-
fileSuffixes: ["default", "defaults"]
|
|
2377
|
-
precedence: 2
|
|
2404
|
+
fileSuffixes: ["default", "defaults"]
|
|
2378
2405
|
},
|
|
2379
2406
|
values: {
|
|
2380
|
-
fileSuffixes: []
|
|
2381
|
-
precedence: 3
|
|
2407
|
+
fileSuffixes: []
|
|
2382
2408
|
},
|
|
2383
2409
|
overrides: {
|
|
2384
|
-
fileSuffixes: ["local", "override"]
|
|
2385
|
-
|
|
2386
|
-
}
|
|
2410
|
+
fileSuffixes: ["local", "override"]
|
|
2411
|
+
},
|
|
2412
|
+
container: {}
|
|
2387
2413
|
});
|
|
2388
|
-
var
|
|
2414
|
+
var EnvGraphDataSource3 = class {
|
|
2389
2415
|
static {
|
|
2390
2416
|
__name(this, "EnvGraphDataSource");
|
|
2391
2417
|
}
|
|
2392
2418
|
static DATA_SOURCE_TYPES = DATA_SOURCE_TYPES;
|
|
2393
|
-
|
|
2419
|
+
/** reference back to the graph */
|
|
2394
2420
|
graph;
|
|
2421
|
+
/** parent data source - everything except the root will have a parent */
|
|
2422
|
+
parent;
|
|
2423
|
+
/** child data sources */
|
|
2424
|
+
children = [];
|
|
2425
|
+
/**
|
|
2426
|
+
* tracks if this data source was imported, and additional settings about the import (restricting keys)
|
|
2427
|
+
* */
|
|
2428
|
+
importMeta;
|
|
2429
|
+
get isImport() {
|
|
2430
|
+
return !!this.importMeta?.isImport || !!this.parent?.isImport;
|
|
2431
|
+
}
|
|
2432
|
+
get importKeys() {
|
|
2433
|
+
const importKeysArrays = [];
|
|
2434
|
+
let currentSource = this;
|
|
2435
|
+
while (currentSource) {
|
|
2436
|
+
if (currentSource.importMeta?.importKeys && currentSource.importMeta.importKeys.length) {
|
|
2437
|
+
importKeysArrays.push(currentSource.importMeta.importKeys);
|
|
2438
|
+
}
|
|
2439
|
+
currentSource = currentSource.parent;
|
|
2440
|
+
}
|
|
2441
|
+
if (importKeysArrays.length) {
|
|
2442
|
+
const keysToImport = my_dash_default.intersection(...importKeysArrays);
|
|
2443
|
+
return keysToImport;
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
/** adds a child data source and sets up the correct references in both directions */
|
|
2447
|
+
async addChild(child, importMeta) {
|
|
2448
|
+
if (!this.graph) throw new Error("expected graph to be set");
|
|
2449
|
+
this.children.unshift(child);
|
|
2450
|
+
child.parent = this;
|
|
2451
|
+
child.graph = this.graph;
|
|
2452
|
+
if (importMeta) child.importMeta = importMeta;
|
|
2453
|
+
await child.finishInit();
|
|
2454
|
+
}
|
|
2455
|
+
/** environment flag key (as set by @envFlag decorator) - only if set within this source */
|
|
2456
|
+
_envFlagKey;
|
|
2457
|
+
/** environment flag key getter that will follow up the parent chain */
|
|
2458
|
+
get envFlagKey() {
|
|
2459
|
+
return this._envFlagKey || this.parent?.envFlagKey;
|
|
2460
|
+
}
|
|
2461
|
+
/** environment flag config item getter (follows up the parent chain) */
|
|
2462
|
+
get envFlagConfigItem() {
|
|
2463
|
+
const envFlagKey = this.envFlagKey;
|
|
2464
|
+
return envFlagKey ? this.graph?.configSchema[envFlagKey] : void 0;
|
|
2465
|
+
}
|
|
2466
|
+
/** environment flag value getter (follows up the parent chain), and checks the graph-level fallback */
|
|
2467
|
+
get envFlagValue() {
|
|
2468
|
+
const envFlagItem = this.envFlagConfigItem;
|
|
2469
|
+
if (envFlagItem) return envFlagItem.resolvedValue;
|
|
2470
|
+
return this.graph.envFlagFallback;
|
|
2471
|
+
}
|
|
2472
|
+
/** helper to resolve the envFlag value */
|
|
2473
|
+
async resolveCurrentEnv() {
|
|
2474
|
+
const envFlagItem = this.envFlagConfigItem;
|
|
2475
|
+
if (envFlagItem) {
|
|
2476
|
+
await envFlagItem.earlyResolve();
|
|
2477
|
+
return envFlagItem.resolvedValue;
|
|
2478
|
+
}
|
|
2479
|
+
return this.graph.envFlagFallback;
|
|
2480
|
+
}
|
|
2481
|
+
/** finish init process for this data source */
|
|
2482
|
+
async finishInit() {
|
|
2483
|
+
if (!this.graph) throw new Error("expected graph to be set");
|
|
2484
|
+
await this._finishInit();
|
|
2485
|
+
if (this.loadingError) {
|
|
2486
|
+
return;
|
|
2487
|
+
}
|
|
2488
|
+
const disableDecorator = this.getRootDecorators("disable")?.[0];
|
|
2489
|
+
if (disableDecorator) {
|
|
2490
|
+
if (disableDecorator.value instanceof ParsedEnvSpecFunctionCall) {
|
|
2491
|
+
if (disableDecorator.value.name === "forEnv") {
|
|
2492
|
+
const disableForEnvs = disableDecorator.value.simplifiedArgs;
|
|
2493
|
+
if (!my_dash_default.isArray(disableForEnvs)) {
|
|
2494
|
+
this._loadingError = new Error("expected disable decorator args to be array");
|
|
2495
|
+
return;
|
|
2496
|
+
}
|
|
2497
|
+
const currentEnv = await this.resolveCurrentEnv();
|
|
2498
|
+
if (disableForEnvs.includes(currentEnv)) {
|
|
2499
|
+
this._disabled = true;
|
|
2500
|
+
}
|
|
2501
|
+
} else {
|
|
2502
|
+
this._loadingError = new Error(`unknown disable decorator function: ${disableDecorator.name}`);
|
|
2503
|
+
return;
|
|
2504
|
+
}
|
|
2505
|
+
} else if (disableDecorator.simplifiedValue) {
|
|
2506
|
+
this._disabled = true;
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
if (this.disabled) return;
|
|
2510
|
+
const envFlagDecoratorValue = this.getRootDecoratorSimpleValue("envFlag");
|
|
2511
|
+
if (envFlagDecoratorValue) {
|
|
2512
|
+
if (!this.configItemDefs[envFlagDecoratorValue]) {
|
|
2513
|
+
this._loadingError = new Error(`@envFlag key ${envFlagDecoratorValue} must be an item within this schema`);
|
|
2514
|
+
return;
|
|
2515
|
+
}
|
|
2516
|
+
this._envFlagKey = envFlagDecoratorValue;
|
|
2517
|
+
}
|
|
2518
|
+
for (const itemKey of this.importKeys || my_dash_default.keys(this.configItemDefs)) {
|
|
2519
|
+
const itemDef = this.configItemDefs[itemKey];
|
|
2520
|
+
if (!itemDef) continue;
|
|
2521
|
+
this.graph.configSchema[itemKey] ??= new ConfigItem4(this.graph, itemKey);
|
|
2522
|
+
}
|
|
2523
|
+
const importDecorators = this.getRootDecorators("import");
|
|
2524
|
+
if (importDecorators.length) {
|
|
2525
|
+
for (const importDecorator of importDecorators) {
|
|
2526
|
+
const importArgs = importDecorator.bareFnArgs?.simplifiedValues;
|
|
2527
|
+
if (!my_dash_default.isArray(importArgs)) {
|
|
2528
|
+
throw new Error("expected @import args to be array");
|
|
2529
|
+
}
|
|
2530
|
+
const importPath = importArgs[0];
|
|
2531
|
+
if (!importPath) throw new Error("@import decorator must have a value");
|
|
2532
|
+
if (!my_dash_default.isString(importPath)) throw new Error("expected @import path to be string");
|
|
2533
|
+
const importKeys = importArgs.slice(1);
|
|
2534
|
+
if (!importKeys.every(my_dash_default.isString)) {
|
|
2535
|
+
throw new Error("expected @import keys to all be strings");
|
|
2536
|
+
}
|
|
2537
|
+
if (importPath.startsWith("./") || importPath.startsWith("../")) {
|
|
2538
|
+
if (!(this instanceof FileBasedDataSource)) {
|
|
2539
|
+
throw new Error("@import of files can only be used from a file-based data source");
|
|
2540
|
+
}
|
|
2541
|
+
const fullImportPath = path2.resolve(this.fullPath, "..", importPath);
|
|
2542
|
+
const fileName = path2.basename(fullImportPath);
|
|
2543
|
+
if (this.graph.virtualImports) {
|
|
2544
|
+
if (importPath.endsWith("/")) {
|
|
2545
|
+
if (!Object.keys(this.graph.virtualImports).some((p) => p.startsWith(fullImportPath))) {
|
|
2546
|
+
this._loadingError = new Error(`Virtual directory import ${fullImportPath} not found`);
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
await this.addChild(new DirectoryDataSource(fullImportPath), {
|
|
2550
|
+
isImport: true,
|
|
2551
|
+
importKeys
|
|
2552
|
+
});
|
|
2553
|
+
} else {
|
|
2554
|
+
if (!this.graph.virtualImports[fullImportPath]) {
|
|
2555
|
+
this._loadingError = new Error(`Virtual import ${fullImportPath} not found`);
|
|
2556
|
+
return;
|
|
2557
|
+
}
|
|
2558
|
+
const source = new DotEnvFileDataSource(fullImportPath, {
|
|
2559
|
+
overrideContents: this.graph.virtualImports[fullImportPath]
|
|
2560
|
+
});
|
|
2561
|
+
await this.addChild(source, { isImport: true, importKeys });
|
|
2562
|
+
}
|
|
2563
|
+
} else {
|
|
2564
|
+
const fsStat = await tryCatch(async () => fs2.stat(importPath), (_err) => {
|
|
2565
|
+
});
|
|
2566
|
+
if (!fsStat) {
|
|
2567
|
+
this._loadingError = new Error(`Import path does not exist: ${fullImportPath}`);
|
|
2568
|
+
return;
|
|
2569
|
+
}
|
|
2570
|
+
if (importPath.endsWith("/")) {
|
|
2571
|
+
if (fsStat.isDirectory()) {
|
|
2572
|
+
await this.addChild(new DirectoryDataSource(fullImportPath), {
|
|
2573
|
+
isImport: true,
|
|
2574
|
+
importKeys
|
|
2575
|
+
});
|
|
2576
|
+
} else {
|
|
2577
|
+
this._loadingError = new Error(`Imported path ending with "/" is not a directory: ${fullImportPath}`);
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2580
|
+
} else {
|
|
2581
|
+
if (fsStat.isDirectory()) {
|
|
2582
|
+
this._loadingError = new Error('Imported path is a directory, add trailing "/" to import');
|
|
2583
|
+
return;
|
|
2584
|
+
} else if (!fileName.startsWith(".env.")) {
|
|
2585
|
+
this._loadingError = new Error("imported file must be a .env.* file");
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
await this.addChild(new DotEnvFileDataSource(fullImportPath), { isImport: true, importKeys });
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
} else if (importPath.startsWith("http://") || importPath.startsWith("https://")) {
|
|
2592
|
+
this._loadingError = new Error("http imports not supported yet");
|
|
2593
|
+
return;
|
|
2594
|
+
} else if (importPath.startsWith("npm:")) {
|
|
2595
|
+
this._loadingError = new Error("npm imports not supported yet");
|
|
2596
|
+
return;
|
|
2597
|
+
} else {
|
|
2598
|
+
this._loadingError = new Error("unsupported import type");
|
|
2599
|
+
return;
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
if (envFlagDecoratorValue) {
|
|
2604
|
+
const envFlagItem = this.envFlagConfigItem;
|
|
2605
|
+
await envFlagItem.earlyResolve();
|
|
2606
|
+
if (!envFlagItem.isValid) {
|
|
2607
|
+
const err = new Error("resolved @envFlag value is not valid");
|
|
2608
|
+
err.cause = envFlagItem.errors[0];
|
|
2609
|
+
throw err;
|
|
2610
|
+
}
|
|
2611
|
+
if (!my_dash_default.isString(envFlagItem.resolvedValue)) {
|
|
2612
|
+
throw new Error("expected resolved @envFlag value to be a string");
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
/**
|
|
2617
|
+
* called by the finishInit - meant to be overridden by subclasses
|
|
2618
|
+
* to add specific behaviour for that data source type
|
|
2619
|
+
* @internal
|
|
2620
|
+
* */
|
|
2621
|
+
async _finishInit() {
|
|
2622
|
+
}
|
|
2395
2623
|
type = "values";
|
|
2396
2624
|
applyForEnv;
|
|
2397
|
-
|
|
2398
|
-
|
|
2625
|
+
_disabled = false;
|
|
2626
|
+
get disabled() {
|
|
2627
|
+
return this._disabled || this.parent?._disabled;
|
|
2628
|
+
}
|
|
2399
2629
|
/** an error encountered while loading/parsing the data source */
|
|
2400
|
-
|
|
2630
|
+
_loadingError;
|
|
2631
|
+
get loadingError() {
|
|
2632
|
+
return this._loadingError;
|
|
2633
|
+
}
|
|
2401
2634
|
get isValid() {
|
|
2402
2635
|
return !this.loadingError;
|
|
2403
2636
|
}
|
|
2404
2637
|
configItemDefs = {};
|
|
2405
|
-
decorators =
|
|
2406
|
-
|
|
2407
|
-
|
|
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;
|
|
2638
|
+
decorators = [];
|
|
2639
|
+
getRootDecorators(decName) {
|
|
2640
|
+
return this.decorators.filter((d) => d.name === decName);
|
|
2414
2641
|
}
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
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
|
-
}
|
|
2642
|
+
getRootDecoratorSimpleValue(decName) {
|
|
2643
|
+
const decorators = this.getRootDecorators(decName);
|
|
2644
|
+
if (decorators.length === 0) return void 0;
|
|
2645
|
+
if (decorators.length > 1) throw new Error(`Multiple ${decName} decorators found`);
|
|
2646
|
+
return decorators[0].simplifiedValue;
|
|
2440
2647
|
}
|
|
2441
2648
|
};
|
|
2442
2649
|
var EnvSourceParseError = class extends Error {
|
|
@@ -2449,7 +2656,7 @@ var EnvSourceParseError = class extends Error {
|
|
|
2449
2656
|
this.location = _location;
|
|
2450
2657
|
}
|
|
2451
2658
|
};
|
|
2452
|
-
var FileBasedDataSource = class extends
|
|
2659
|
+
var FileBasedDataSource = class extends EnvGraphDataSource3 {
|
|
2453
2660
|
static {
|
|
2454
2661
|
__name(this, "FileBasedDataSource");
|
|
2455
2662
|
}
|
|
@@ -2472,40 +2679,44 @@ var FileBasedDataSource = class extends EnvGraphDataSource {
|
|
|
2472
2679
|
constructor(fullPath, opts) {
|
|
2473
2680
|
super();
|
|
2474
2681
|
this.fullPath = fullPath;
|
|
2475
|
-
this.fileName =
|
|
2682
|
+
this.fileName = path2.basename(fullPath);
|
|
2476
2683
|
if (opts?.overrideContents) {
|
|
2477
2684
|
this.rawContents = opts.overrideContents;
|
|
2478
2685
|
this.isGitIgnored = opts.overrideGitIgnored;
|
|
2479
2686
|
}
|
|
2480
|
-
if (
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
fileNameParts.
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2687
|
+
if (this.fileName.startsWith(".env")) {
|
|
2688
|
+
const fileNameParts = this.fileName.substring(1).split(".");
|
|
2689
|
+
const maybeExtension = fileNameParts[fileNameParts.length - 1];
|
|
2690
|
+
if (this.validFileExtensions.includes(maybeExtension)) {
|
|
2691
|
+
fileNameParts.pop();
|
|
2692
|
+
}
|
|
2693
|
+
const maybeFileType = fileNameParts[fileNameParts.length - 1];
|
|
2694
|
+
for (const [possibleSourceType, possibleSourceSpec] of Object.entries(DATA_SOURCE_TYPES)) {
|
|
2695
|
+
if (!("fileSuffixes" in possibleSourceSpec)) continue;
|
|
2696
|
+
if (possibleSourceSpec.fileSuffixes.includes(maybeFileType)) {
|
|
2697
|
+
this.type = possibleSourceType;
|
|
2698
|
+
break;
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
if (this.type !== "values") fileNameParts.pop();
|
|
2702
|
+
if (fileNameParts.length > 2) {
|
|
2703
|
+
throw Error(`Unsure how to interpret filename - ${this.fileName}`);
|
|
2704
|
+
} else if (fileNameParts.length === 2) {
|
|
2705
|
+
this.applyForEnv = fileNameParts[1];
|
|
2493
2706
|
}
|
|
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
2707
|
}
|
|
2501
2708
|
}
|
|
2502
2709
|
// no async constructors... :(
|
|
2503
|
-
async
|
|
2710
|
+
async _finishInit() {
|
|
2504
2711
|
if (!this.rawContents) {
|
|
2712
|
+
if (!await pathExists(this.fullPath)) {
|
|
2713
|
+
this._loadingError = new Error(`File does not exist: ${this.fullPath}`);
|
|
2714
|
+
return;
|
|
2715
|
+
}
|
|
2505
2716
|
this.isGitIgnored = await checkIsFileGitIgnored(this.fullPath);
|
|
2506
2717
|
this.rawContents = await fs2.readFile(this.fullPath, "utf8");
|
|
2507
2718
|
}
|
|
2508
|
-
await this._parseContents();
|
|
2719
|
+
if (this.rawContents) await this._parseContents();
|
|
2509
2720
|
}
|
|
2510
2721
|
};
|
|
2511
2722
|
var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
@@ -2519,7 +2730,7 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
|
2519
2730
|
convertParserValueToResolvers(value) {
|
|
2520
2731
|
if (!this.graph) throw new Error("expected graph to be set");
|
|
2521
2732
|
if (value === void 0) {
|
|
2522
|
-
return
|
|
2733
|
+
return void 0;
|
|
2523
2734
|
} else if (value instanceof ParsedEnvSpecStaticValue) {
|
|
2524
2735
|
return new StaticValueResolver(value.unescapedValue);
|
|
2525
2736
|
} else if (value instanceof ParsedEnvSpecFunctionCall) {
|
|
@@ -2533,12 +2744,16 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
|
2533
2744
|
for (const arg of argsFromParser) {
|
|
2534
2745
|
if (arg instanceof ParsedEnvSpecKeyValuePair) {
|
|
2535
2746
|
keyValueArgs ??= {};
|
|
2536
|
-
|
|
2747
|
+
const valResolver = this.convertParserValueToResolvers(arg.value);
|
|
2748
|
+
if (!valResolver) throw new Error("Did not expect to find undefined resolver in key-value arg");
|
|
2749
|
+
keyValueArgs[arg.key] = valResolver;
|
|
2537
2750
|
} else {
|
|
2538
2751
|
if (keyValueArgs) {
|
|
2539
2752
|
return new ErrorResolver(new SchemaError("After switching to key-value function args, cannot switch back"));
|
|
2540
2753
|
}
|
|
2541
|
-
|
|
2754
|
+
const argResolver = this.convertParserValueToResolvers(arg);
|
|
2755
|
+
if (!argResolver) throw new Error("Did not expect to find undefined resolver in array arg");
|
|
2756
|
+
argsAsResolversArray.push(argResolver);
|
|
2542
2757
|
}
|
|
2543
2758
|
}
|
|
2544
2759
|
if (keyValueArgs) argsAsResolversArray.push(keyValueArgs);
|
|
@@ -2552,19 +2767,19 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
|
2552
2767
|
this.parsedFile = await tryCatch(
|
|
2553
2768
|
() => parseEnvSpecDotEnvFile(rawContents),
|
|
2554
2769
|
(error) => {
|
|
2555
|
-
this.
|
|
2770
|
+
this._loadingError = new EnvSourceParseError(error.message, {
|
|
2556
2771
|
path: this.fullPath,
|
|
2557
2772
|
lineNumber: error.location.start.line,
|
|
2558
2773
|
colNumber: error.location.start.column,
|
|
2559
2774
|
lineStr: rawContents.split("\n")[error.location.start.line - 1]
|
|
2560
2775
|
});
|
|
2561
|
-
this.
|
|
2776
|
+
this._loadingError.cause = error;
|
|
2562
2777
|
}
|
|
2563
2778
|
);
|
|
2564
2779
|
if (this.loadingError) return;
|
|
2565
2780
|
if (!this.parsedFile) throw new Error("Failed to parse .env file");
|
|
2566
|
-
this.decorators = this.parsedFile.decoratorsObject;
|
|
2567
2781
|
if (!this.graph) throw new Error("expected graph to be set");
|
|
2782
|
+
this.decorators = this.parsedFile.decoratorsArray;
|
|
2568
2783
|
for (const item of this.parsedFile.configItems) {
|
|
2569
2784
|
item.processExpansion();
|
|
2570
2785
|
this.configItemDefs[item.key] = {
|
|
@@ -2575,24 +2790,57 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
|
2575
2790
|
}
|
|
2576
2791
|
}
|
|
2577
2792
|
};
|
|
2578
|
-
var
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2793
|
+
var DirectoryDataSource = class extends EnvGraphDataSource3 {
|
|
2794
|
+
constructor(basePath) {
|
|
2795
|
+
super();
|
|
2796
|
+
this.basePath = basePath;
|
|
2797
|
+
}
|
|
2798
|
+
static {
|
|
2799
|
+
__name(this, "DirectoryDataSource");
|
|
2800
|
+
}
|
|
2801
|
+
type = "container";
|
|
2802
|
+
typeLabel = "directory";
|
|
2803
|
+
get label() {
|
|
2804
|
+
return `directory - ${this.basePath}`;
|
|
2805
|
+
}
|
|
2806
|
+
schemaDataSource;
|
|
2807
|
+
get loadingError() {
|
|
2808
|
+
return this._loadingError || this.schemaDataSource?.loadingError;
|
|
2809
|
+
}
|
|
2810
|
+
get envFlagKey() {
|
|
2811
|
+
return this.schemaDataSource?._envFlagKey || this.parent?.envFlagKey;
|
|
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
|
-
|
|
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
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
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.
|
|
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.
|
|
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,
|
|
2811
|
-
//# sourceMappingURL=chunk-
|
|
2812
|
-
//# sourceMappingURL=chunk-
|
|
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-MV5ZAKN7.js.map
|
|
3052
|
+
//# sourceMappingURL=chunk-MV5ZAKN7.js.map
|