varlock 0.0.11 → 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-FYLMYWUF.js → chunk-5EBVEGDW.js} +5 -24
- package/dist/chunk-5EBVEGDW.js.map +1 -0
- package/dist/{chunk-4CE75BSX.js → chunk-AS4LIW7A.js} +21 -15
- package/dist/chunk-AS4LIW7A.js.map +1 -0
- package/dist/{chunk-KCX4NC7Q.js → chunk-IML4QZHB.js} +4 -5
- package/dist/chunk-IML4QZHB.js.map +1 -0
- package/dist/{chunk-4WMY2EW3.js → chunk-LXJMZMID.js} +98 -66
- package/dist/chunk-LXJMZMID.js.map +1 -0
- package/dist/{chunk-ZW2T4C6A.js → chunk-MV5ZAKN7.js} +539 -267
- package/dist/chunk-MV5ZAKN7.js.map +1 -0
- package/dist/{chunk-LS6F7BSZ.js → chunk-MVYXWTAV.js} +4 -4
- package/dist/{chunk-LS6F7BSZ.js.map → chunk-MVYXWTAV.js.map} +1 -1
- package/dist/{chunk-PB7RWVE6.js → chunk-T3I4UFB2.js} +16 -5
- package/dist/chunk-T3I4UFB2.js.map +1 -0
- package/dist/{chunk-GWQT5VGW.js → chunk-UA3DMAAQ.js} +4 -4
- package/dist/{chunk-GWQT5VGW.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-KH4bPru7.d.ts → env-B_LAqK4w.d.ts} +103 -64
- 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-ZRQOE2OK.js.map → init.command-CTO64XBL.js.map} +1 -1
- package/dist/load.command-EWIJDF55.js +8 -0
- package/dist/{load.command-YBN3BW6U.js.map → load.command-EWIJDF55.js.map} +1 -1
- package/dist/login.command-UZJJ4XTV.js +8 -0
- package/dist/{login.command-F5AWKZKA.js.map → login.command-UZJJ4XTV.js.map} +1 -1
- package/dist/run.command-T44BAZ7X.js +8 -0
- package/dist/{run.command-WWJ6ZE26.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-IS2JLIZM.js.map → telemetry.command-2C3MQA4K.js.map} +1 -1
- package/package.json +3 -3
- package/dist/chunk-4CE75BSX.js.map +0 -1
- package/dist/chunk-4WMY2EW3.js.map +0 -1
- package/dist/chunk-FYLMYWUF.js.map +0 -1
- package/dist/chunk-KCX4NC7Q.js.map +0 -1
- package/dist/chunk-PB7RWVE6.js.map +0 -1
- package/dist/chunk-ZUG7BEY5.js +0 -17
- package/dist/chunk-ZUG7BEY5.js.map +0 -1
- package/dist/chunk-ZW2T4C6A.js.map +0 -1
- package/dist/init.command-ZRQOE2OK.js +0 -9
- package/dist/load.command-YBN3BW6U.js +0 -9
- package/dist/login.command-F5AWKZKA.js +0 -8
- package/dist/run.command-WWJ6ZE26.js +0 -9
- package/dist/telemetry.command-IS2JLIZM.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 {
|
|
@@ -1780,7 +1808,8 @@ async function getTsDefinitionForItem(item, indentLevel = 0) {
|
|
|
1780
1808
|
}
|
|
1781
1809
|
}
|
|
1782
1810
|
}
|
|
1783
|
-
|
|
1811
|
+
const isRequired = item.isRequired && !item.isRequiredDynamic;
|
|
1812
|
+
itemSrc.push(`readonly ${item.key}${isRequired ? "" : "?"}: ${itemTsType};`);
|
|
1784
1813
|
itemSrc.push("");
|
|
1785
1814
|
return my_dash_default.map(itemSrc, (line) => `${i}${line}`);
|
|
1786
1815
|
}
|
|
@@ -1832,16 +1861,16 @@ export type EnvSchemaAsStrings = {
|
|
|
1832
1861
|
return tsSrc.join("\n");
|
|
1833
1862
|
}
|
|
1834
1863
|
__name(generateTsTypesSrc, "generateTsTypesSrc");
|
|
1835
|
-
async function generateTypes(graph, lang,
|
|
1864
|
+
async function generateTypes(graph, lang, typesPath) {
|
|
1836
1865
|
if (lang !== "ts") throw new Error(`Unsupported @generateTypes lang: ${lang}`);
|
|
1837
1866
|
const tsSrc = await generateTsTypesSrc(graph);
|
|
1838
|
-
if (!graph.basePath) return;
|
|
1839
|
-
const typesPath = path.join(graph.basePath, outputPath);
|
|
1840
1867
|
await fs.promises.writeFile(typesPath, tsSrc, "utf-8");
|
|
1841
1868
|
}
|
|
1842
1869
|
__name(generateTypes, "generateTypes");
|
|
1843
1870
|
|
|
1844
1871
|
// env-graph/lib/env-graph.ts
|
|
1872
|
+
var processExists = !!globalThis.process;
|
|
1873
|
+
var originalProcessEnv = { ...processExists && process.env };
|
|
1845
1874
|
var EnvGraph2 = class {
|
|
1846
1875
|
static {
|
|
1847
1876
|
__name(this, "EnvGraph");
|
|
@@ -1850,26 +1879,29 @@ var EnvGraph2 = class {
|
|
|
1850
1879
|
// or just the files that are relevant to the current resolution attempt
|
|
1851
1880
|
// (which would mean it's always through the lens of the current directory/package)
|
|
1852
1881
|
basePath;
|
|
1853
|
-
/**
|
|
1854
|
-
|
|
1855
|
-
|
|
1882
|
+
/** root data source (.env.schema) */
|
|
1883
|
+
rootDataSource;
|
|
1884
|
+
/** place to store process.env overrides */
|
|
1885
|
+
overrideValues = {};
|
|
1856
1886
|
/** config item key of env flag (toggles env-specific data sources enabled) */
|
|
1857
1887
|
envFlagKey;
|
|
1858
|
-
/**
|
|
1859
|
-
|
|
1888
|
+
/** graph-level fallback value for environment flag */
|
|
1889
|
+
envFlagFallback;
|
|
1860
1890
|
configSchema = {};
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
if (schemas.length === 0) return void 0;
|
|
1869
|
-
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
|
+
}
|
|
1870
1898
|
}
|
|
1871
1899
|
get sortedDataSources() {
|
|
1872
|
-
|
|
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) : [];
|
|
1873
1905
|
}
|
|
1874
1906
|
registeredResolverFunctions = {};
|
|
1875
1907
|
registerResolver(resolverClass) {
|
|
@@ -1890,78 +1922,15 @@ var EnvGraph2 = class {
|
|
|
1890
1922
|
for (const resolverClass of BaseResolvers) {
|
|
1891
1923
|
this.registerResolver(resolverClass);
|
|
1892
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();
|
|
1893
1932
|
}
|
|
1894
1933
|
async finishLoad() {
|
|
1895
|
-
const sortedDataSources = this.sortedDataSources;
|
|
1896
|
-
for (const source of sortedDataSources) {
|
|
1897
|
-
if (source.loadingError) {
|
|
1898
|
-
throw source.loadingError;
|
|
1899
|
-
}
|
|
1900
|
-
if (source.type === "example") {
|
|
1901
|
-
source.disabled = true;
|
|
1902
|
-
continue;
|
|
1903
|
-
}
|
|
1904
|
-
if (source.decorators?.envFlag) {
|
|
1905
|
-
if (source.applyForEnv) {
|
|
1906
|
-
throw new Error(`@envFlag cannot be set from within an env-specific data source - ${source.label}`);
|
|
1907
|
-
} else if (this.envFlagKey) {
|
|
1908
|
-
throw new Error("only a single @envFlag setting is allowed");
|
|
1909
|
-
} else {
|
|
1910
|
-
const envFlagKey = source.decorators.envFlag.simplifiedValue;
|
|
1911
|
-
if (!my_dash_default.isString(envFlagKey)) {
|
|
1912
|
-
throw new Error("@envFlag must be a string");
|
|
1913
|
-
} else {
|
|
1914
|
-
this.envFlagKey = envFlagKey;
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
if (source.applyForEnv) {
|
|
1919
|
-
if (source.applyForEnv && this.envFlagValue !== source.applyForEnv) {
|
|
1920
|
-
source.disabled = true;
|
|
1921
|
-
continue;
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
if (source.decorators?.disable && source.decorators.disable.simplifiedValue) {
|
|
1925
|
-
source.disabled = true;
|
|
1926
|
-
continue;
|
|
1927
|
-
}
|
|
1928
|
-
for (const itemKey in source.configItemDefs) {
|
|
1929
|
-
if (source.ignoreNewDefs && !this.configSchema[itemKey]) continue;
|
|
1930
|
-
const itemDef = source.configItemDefs[itemKey];
|
|
1931
|
-
this.configSchema[itemKey] ??= new ConfigItem3(this, itemKey);
|
|
1932
|
-
this.configSchema[itemKey].addDef(itemDef, source);
|
|
1933
|
-
}
|
|
1934
|
-
if (source.type === "schema" && this.envFlagKey) {
|
|
1935
|
-
if (!this.configSchema[this.envFlagKey]) {
|
|
1936
|
-
throw new Error(`@envFlag key ${this.envFlagKey} not found in schema`);
|
|
1937
|
-
}
|
|
1938
|
-
const envFlagItem = this.configSchema[this.envFlagKey];
|
|
1939
|
-
await envFlagItem.process();
|
|
1940
|
-
for (const depKey of envFlagItem.valueResolver?.deps || []) {
|
|
1941
|
-
const depItem = this.configSchema[depKey];
|
|
1942
|
-
if (!depItem) {
|
|
1943
|
-
throw new Error(`envFlag resolver is using non-existant dependency: ${depKey}`);
|
|
1944
|
-
}
|
|
1945
|
-
await depItem.process();
|
|
1946
|
-
if (depItem.valueResolver?.deps.length) {
|
|
1947
|
-
throw new Error("envFlag cannot follow a chain of dependencies");
|
|
1948
|
-
}
|
|
1949
|
-
await depItem.resolve();
|
|
1950
|
-
}
|
|
1951
|
-
await envFlagItem.resolve();
|
|
1952
|
-
if (!envFlagItem.isValid) {
|
|
1953
|
-
const err = new Error("resolved @envFlag value is not valid");
|
|
1954
|
-
err.cause = envFlagItem.errors[0];
|
|
1955
|
-
throw err;
|
|
1956
|
-
}
|
|
1957
|
-
if (envFlagItem.resolvedValue) {
|
|
1958
|
-
if (!my_dash_default.isString(envFlagItem.resolvedValue)) {
|
|
1959
|
-
throw new Error("expected resolved @envFlag value to be a string");
|
|
1960
|
-
}
|
|
1961
|
-
this.envFlagValue = envFlagItem.resolvedValue;
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
1934
|
for (const itemKey in this.configSchema) {
|
|
1966
1935
|
const item = this.configSchema[itemKey];
|
|
1967
1936
|
await item.process();
|
|
@@ -1987,6 +1956,7 @@ var EnvGraph2 = class {
|
|
|
1987
1956
|
return adjList;
|
|
1988
1957
|
}
|
|
1989
1958
|
async resolveEnvValues() {
|
|
1959
|
+
if (my_dash_default.keys(this.configSchema).length === 0) return;
|
|
1990
1960
|
const adjList = this.graphAdjacencyList;
|
|
1991
1961
|
const reverseAdjList = {};
|
|
1992
1962
|
for (const itemKey in adjList) {
|
|
@@ -2051,7 +2021,7 @@ var EnvGraph2 = class {
|
|
|
2051
2021
|
serializedGraph.sources.push({
|
|
2052
2022
|
label: source.label,
|
|
2053
2023
|
enabled: !source.disabled,
|
|
2054
|
-
path: source instanceof FileBasedDataSource ?
|
|
2024
|
+
path: source instanceof FileBasedDataSource ? path2.relative(this.basePath ?? "", source.fullPath) : void 0
|
|
2055
2025
|
});
|
|
2056
2026
|
}
|
|
2057
2027
|
for (const itemKey in this.configSchema) {
|
|
@@ -2072,13 +2042,30 @@ var EnvGraph2 = class {
|
|
|
2072
2042
|
await generateTypes(this, lang, outputPath);
|
|
2073
2043
|
}
|
|
2074
2044
|
getRootDecoratorValue(decoratorName) {
|
|
2075
|
-
const
|
|
2076
|
-
|
|
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;
|
|
2077
2064
|
}
|
|
2078
2065
|
};
|
|
2079
2066
|
|
|
2080
2067
|
// env-graph/lib/config-item.ts
|
|
2081
|
-
var
|
|
2068
|
+
var ConfigItem4 = class {
|
|
2082
2069
|
static {
|
|
2083
2070
|
__name(this, "ConfigItem");
|
|
2084
2071
|
}
|
|
@@ -2095,9 +2082,19 @@ var ConfigItem3 = class {
|
|
|
2095
2082
|
get key() {
|
|
2096
2083
|
return this.#key;
|
|
2097
2084
|
}
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
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;
|
|
2101
2098
|
}
|
|
2102
2099
|
get description() {
|
|
2103
2100
|
for (const def of this.defs) {
|
|
@@ -2116,6 +2113,9 @@ var ConfigItem3 = class {
|
|
|
2116
2113
|
return links;
|
|
2117
2114
|
}
|
|
2118
2115
|
get valueResolver() {
|
|
2116
|
+
if (this.key in this.envGraph.overrideValues) {
|
|
2117
|
+
return new StaticValueResolver(this.envGraph.overrideValues[this.key]);
|
|
2118
|
+
}
|
|
2119
2119
|
for (const def of this.defs) {
|
|
2120
2120
|
if (def.itemDef.resolver) return def.itemDef.resolver;
|
|
2121
2121
|
}
|
|
@@ -2146,10 +2146,6 @@ var ConfigItem3 = class {
|
|
|
2146
2146
|
return this.valueResolver?.schemaErrors || [];
|
|
2147
2147
|
}
|
|
2148
2148
|
async process() {
|
|
2149
|
-
const finalOverrideDef = this.envGraph.finalOverridesDataSource?.configItemDefs[this.key];
|
|
2150
|
-
if (finalOverrideDef) {
|
|
2151
|
-
this.defs.unshift({ itemDef: finalOverrideDef, source: this.envGraph.finalOverridesDataSource });
|
|
2152
|
-
}
|
|
2153
2149
|
for (const def of this.defs) {
|
|
2154
2150
|
await def.itemDef.resolver?.process(this);
|
|
2155
2151
|
}
|
|
@@ -2175,57 +2171,113 @@ var ConfigItem3 = class {
|
|
|
2175
2171
|
const dataTypeFactory = this.envGraph.dataTypesRegistry[dataTypeName];
|
|
2176
2172
|
this.dataType = dataTypeFactory(...my_dash_default.isPlainObject(dataTypeArgs) ? [dataTypeArgs] : dataTypeArgs);
|
|
2177
2173
|
}
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2174
|
+
this.processRequired();
|
|
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}`);
|
|
2187
2186
|
}
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
if (typeof val === "string") return val !== "true";
|
|
2192
|
-
return !val;
|
|
2187
|
+
await depItem.process();
|
|
2188
|
+
if (depItem.valueResolver?.deps.length) {
|
|
2189
|
+
throw new Error("eager resolution cannot follow a chain of dependencies");
|
|
2193
2190
|
}
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2191
|
+
await depItem.resolve(true);
|
|
2192
|
+
}
|
|
2193
|
+
await this.resolve(true);
|
|
2194
|
+
}
|
|
2195
|
+
_isRequired = true;
|
|
2196
|
+
/**
|
|
2197
|
+
* need to track if required-ness is dynamic, e.g. based on current env
|
|
2198
|
+
* because that will affect type generation (only _always_ required items are never undefined)
|
|
2199
|
+
* */
|
|
2200
|
+
_isRequiredDynamic = false;
|
|
2201
|
+
processRequired() {
|
|
2202
|
+
try {
|
|
2203
|
+
for (const def of this.defs) {
|
|
2204
|
+
const defDecorators = def.itemDef.decorators || {};
|
|
2205
|
+
if ("required" in defDecorators || "optional" in defDecorators) {
|
|
2206
|
+
if ("required" in defDecorators && "optional" in defDecorators) {
|
|
2207
|
+
throw new SchemaError("@required and @optional cannot both be set");
|
|
2208
|
+
}
|
|
2209
|
+
const requiredDecoratorVal = defDecorators.required?.value || defDecorators.optional?.value;
|
|
2210
|
+
const usingOptional = "optional" in defDecorators;
|
|
2211
|
+
if (requiredDecoratorVal instanceof ParsedEnvSpecStaticValue) {
|
|
2212
|
+
const staticVal = requiredDecoratorVal.value;
|
|
2213
|
+
if (my_dash_default.isBoolean(staticVal)) {
|
|
2214
|
+
this._isRequired = usingOptional ? !staticVal : staticVal;
|
|
2201
2215
|
} else {
|
|
2202
|
-
|
|
2216
|
+
throw new SchemaError("@required/@optional can only be set to true/false if using a static value");
|
|
2217
|
+
}
|
|
2218
|
+
} else if (requiredDecoratorVal instanceof ParsedEnvSpecFunctionCall) {
|
|
2219
|
+
this._isRequiredDynamic = true;
|
|
2220
|
+
const requiredFnName = requiredDecoratorVal.name;
|
|
2221
|
+
const requiredFnArgs = requiredDecoratorVal.simplifiedArgs;
|
|
2222
|
+
if (requiredFnName === "forEnv") {
|
|
2223
|
+
const currentEnv = def.source.envFlagValue;
|
|
2224
|
+
if (!currentEnv) {
|
|
2225
|
+
throw new SchemaError("Cannot set @required using forEnv() because environment flag is not set");
|
|
2226
|
+
}
|
|
2227
|
+
const envMatches = requiredFnArgs.includes(currentEnv);
|
|
2228
|
+
this._isRequired = usingOptional ? !envMatches : envMatches;
|
|
2203
2229
|
}
|
|
2204
|
-
} else {
|
|
2205
|
-
continue;
|
|
2206
2230
|
}
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
const defaultRequiredValue = def.source.getRootDecoratorSimpleValue("defaultRequired");
|
|
2234
|
+
if (defaultRequiredValue !== void 0) {
|
|
2235
|
+
if (defaultRequiredValue === "infer") {
|
|
2236
|
+
if (def.source.type === "schema") {
|
|
2237
|
+
const resolver = def.itemDef.resolver;
|
|
2238
|
+
if (resolver === void 0) {
|
|
2239
|
+
this._isRequired = false;
|
|
2240
|
+
} else if (resolver instanceof StaticValueResolver) {
|
|
2241
|
+
this._isRequired = resolver.staticValue !== void 0 && resolver.staticValue !== "";
|
|
2242
|
+
} else {
|
|
2243
|
+
this._isRequired = true;
|
|
2244
|
+
}
|
|
2245
|
+
return;
|
|
2246
|
+
} else {
|
|
2247
|
+
continue;
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
this._isRequired = defaultRequiredValue;
|
|
2251
|
+
return;
|
|
2207
2252
|
}
|
|
2208
|
-
return val;
|
|
2209
2253
|
}
|
|
2254
|
+
} catch (err) {
|
|
2255
|
+
this.schemaErrors.push(err instanceof SchemaError ? err : new SchemaError(err));
|
|
2210
2256
|
}
|
|
2211
|
-
|
|
2257
|
+
}
|
|
2258
|
+
get isRequired() {
|
|
2259
|
+
return this._isRequired;
|
|
2260
|
+
}
|
|
2261
|
+
get isRequiredDynamic() {
|
|
2262
|
+
return this._isRequiredDynamic;
|
|
2212
2263
|
}
|
|
2213
2264
|
get isSensitive() {
|
|
2214
2265
|
for (const def of this.defs) {
|
|
2215
2266
|
const defDecorators = def.itemDef.decorators || {};
|
|
2216
2267
|
if ("sensitive" in defDecorators) {
|
|
2217
2268
|
return defDecorators.sensitive.simplifiedValue;
|
|
2218
|
-
}
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
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;
|
|
2222
2274
|
const prefix = Array.isArray(args) && args.length > 0 ? args[0] : void 0;
|
|
2223
2275
|
if (typeof prefix === "string" && this.key.startsWith(prefix)) {
|
|
2224
2276
|
return false;
|
|
2225
2277
|
}
|
|
2226
2278
|
return true;
|
|
2227
2279
|
}
|
|
2228
|
-
return
|
|
2280
|
+
return defaultSensitiveDec.simplifiedValue;
|
|
2229
2281
|
}
|
|
2230
2282
|
}
|
|
2231
2283
|
return true;
|
|
@@ -2256,18 +2308,31 @@ var ConfigItem3 = class {
|
|
|
2256
2308
|
get isCoerced() {
|
|
2257
2309
|
return this.resolvedRawValue !== this.resolvedValue;
|
|
2258
2310
|
}
|
|
2259
|
-
async resolve() {
|
|
2311
|
+
async resolve(reset2 = false) {
|
|
2260
2312
|
if (this.schemaErrors.length) return;
|
|
2261
2313
|
if (this.resolverSchemaErrors.length) return;
|
|
2262
|
-
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
|
+
}
|
|
2263
2323
|
if (this.isResolved) {
|
|
2264
2324
|
return;
|
|
2265
2325
|
}
|
|
2266
|
-
|
|
2267
|
-
this.
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
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
|
+
}
|
|
2271
2336
|
}
|
|
2272
2337
|
if (this.resolvedRawValue instanceof RegExp) {
|
|
2273
2338
|
this.resolutionError = new ResolutionError("regex() is meant to be used within function args, not as a final resolved value");
|
|
@@ -2330,78 +2395,255 @@ var ConfigItem3 = class {
|
|
|
2330
2395
|
// env-graph/lib/data-source.ts
|
|
2331
2396
|
var DATA_SOURCE_TYPES = Object.freeze({
|
|
2332
2397
|
schema: {
|
|
2333
|
-
fileSuffixes: ["schema"]
|
|
2334
|
-
precedence: 0
|
|
2398
|
+
fileSuffixes: ["schema"]
|
|
2335
2399
|
},
|
|
2336
2400
|
example: {
|
|
2337
|
-
fileSuffixes: ["sample", "example"]
|
|
2338
|
-
precedence: 1
|
|
2401
|
+
fileSuffixes: ["sample", "example"]
|
|
2339
2402
|
},
|
|
2340
2403
|
defaults: {
|
|
2341
|
-
fileSuffixes: ["default", "defaults"]
|
|
2342
|
-
precedence: 2
|
|
2404
|
+
fileSuffixes: ["default", "defaults"]
|
|
2343
2405
|
},
|
|
2344
2406
|
values: {
|
|
2345
|
-
fileSuffixes: []
|
|
2346
|
-
precedence: 3
|
|
2407
|
+
fileSuffixes: []
|
|
2347
2408
|
},
|
|
2348
2409
|
overrides: {
|
|
2349
|
-
fileSuffixes: ["local", "override"]
|
|
2350
|
-
|
|
2351
|
-
}
|
|
2410
|
+
fileSuffixes: ["local", "override"]
|
|
2411
|
+
},
|
|
2412
|
+
container: {}
|
|
2352
2413
|
});
|
|
2353
|
-
var
|
|
2414
|
+
var EnvGraphDataSource3 = class {
|
|
2354
2415
|
static {
|
|
2355
2416
|
__name(this, "EnvGraphDataSource");
|
|
2356
2417
|
}
|
|
2357
2418
|
static DATA_SOURCE_TYPES = DATA_SOURCE_TYPES;
|
|
2358
|
-
|
|
2419
|
+
/** reference back to the graph */
|
|
2359
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
|
+
}
|
|
2360
2623
|
type = "values";
|
|
2361
2624
|
applyForEnv;
|
|
2362
|
-
|
|
2363
|
-
|
|
2625
|
+
_disabled = false;
|
|
2626
|
+
get disabled() {
|
|
2627
|
+
return this._disabled || this.parent?._disabled;
|
|
2628
|
+
}
|
|
2364
2629
|
/** an error encountered while loading/parsing the data source */
|
|
2365
|
-
|
|
2630
|
+
_loadingError;
|
|
2631
|
+
get loadingError() {
|
|
2632
|
+
return this._loadingError;
|
|
2633
|
+
}
|
|
2366
2634
|
get isValid() {
|
|
2367
2635
|
return !this.loadingError;
|
|
2368
2636
|
}
|
|
2369
2637
|
configItemDefs = {};
|
|
2370
|
-
decorators =
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
for (const [key, def] of Object.entries(this.configItemDefs)) {
|
|
2374
|
-
if (def.resolver instanceof StaticValueResolver) {
|
|
2375
|
-
obj[key] = String(def.resolver.staticValue ?? "");
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
return obj;
|
|
2638
|
+
decorators = [];
|
|
2639
|
+
getRootDecorators(decName) {
|
|
2640
|
+
return this.decorators.filter((d) => d.name === decName);
|
|
2379
2641
|
}
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
type = "overrides";
|
|
2386
|
-
typeLabel = "process";
|
|
2387
|
-
label = "process.env";
|
|
2388
|
-
ignoreNewDefs = true;
|
|
2389
|
-
static processEnvValues;
|
|
2390
|
-
// ? do we want to set decorator values from env vars here? -- ex: _ENV_FLAG_KEY
|
|
2391
|
-
// depends if we want those to work only within process.env
|
|
2392
|
-
constructor() {
|
|
2393
|
-
super();
|
|
2394
|
-
if (!_ProcessEnvDataSource.processEnvValues) {
|
|
2395
|
-
_ProcessEnvDataSource.processEnvValues = {};
|
|
2396
|
-
for (const itemKey of Object.keys(process.env)) {
|
|
2397
|
-
_ProcessEnvDataSource.processEnvValues[itemKey] = process.env[itemKey];
|
|
2398
|
-
}
|
|
2399
|
-
}
|
|
2400
|
-
for (const itemKey of Object.keys(_ProcessEnvDataSource.processEnvValues)) {
|
|
2401
|
-
this.configItemDefs[itemKey] = {
|
|
2402
|
-
resolver: new StaticValueResolver(_ProcessEnvDataSource.processEnvValues[itemKey])
|
|
2403
|
-
};
|
|
2404
|
-
}
|
|
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;
|
|
2405
2647
|
}
|
|
2406
2648
|
};
|
|
2407
2649
|
var EnvSourceParseError = class extends Error {
|
|
@@ -2414,7 +2656,7 @@ var EnvSourceParseError = class extends Error {
|
|
|
2414
2656
|
this.location = _location;
|
|
2415
2657
|
}
|
|
2416
2658
|
};
|
|
2417
|
-
var FileBasedDataSource = class extends
|
|
2659
|
+
var FileBasedDataSource = class extends EnvGraphDataSource3 {
|
|
2418
2660
|
static {
|
|
2419
2661
|
__name(this, "FileBasedDataSource");
|
|
2420
2662
|
}
|
|
@@ -2437,43 +2679,44 @@ var FileBasedDataSource = class extends EnvGraphDataSource {
|
|
|
2437
2679
|
constructor(fullPath, opts) {
|
|
2438
2680
|
super();
|
|
2439
2681
|
this.fullPath = fullPath;
|
|
2440
|
-
this.fileName =
|
|
2682
|
+
this.fileName = path2.basename(fullPath);
|
|
2441
2683
|
if (opts?.overrideContents) {
|
|
2442
2684
|
this.rawContents = opts.overrideContents;
|
|
2443
2685
|
this.isGitIgnored = opts.overrideGitIgnored;
|
|
2444
2686
|
}
|
|
2445
|
-
if (
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
fileNameParts.
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
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];
|
|
2458
2706
|
}
|
|
2459
|
-
}
|
|
2460
|
-
if (this.type !== "values") fileNameParts.pop();
|
|
2461
|
-
if (fileNameParts.length > 2) {
|
|
2462
|
-
throw Error(`Unsure how to interpret filename - ${this.fileName}`);
|
|
2463
|
-
} else if (fileNameParts.length === 2) {
|
|
2464
|
-
this.applyForEnv = fileNameParts[1];
|
|
2465
|
-
if (this.applyForEnv === "dev") this.applyForEnv = "development";
|
|
2466
|
-
if (this.applyForEnv === "stage") this.applyForEnv = "staging";
|
|
2467
|
-
if (this.applyForEnv === "prod") this.applyForEnv = "production";
|
|
2468
2707
|
}
|
|
2469
2708
|
}
|
|
2470
2709
|
// no async constructors... :(
|
|
2471
|
-
async
|
|
2710
|
+
async _finishInit() {
|
|
2472
2711
|
if (!this.rawContents) {
|
|
2712
|
+
if (!await pathExists(this.fullPath)) {
|
|
2713
|
+
this._loadingError = new Error(`File does not exist: ${this.fullPath}`);
|
|
2714
|
+
return;
|
|
2715
|
+
}
|
|
2473
2716
|
this.isGitIgnored = await checkIsFileGitIgnored(this.fullPath);
|
|
2474
2717
|
this.rawContents = await fs2.readFile(this.fullPath, "utf8");
|
|
2475
2718
|
}
|
|
2476
|
-
await this._parseContents();
|
|
2719
|
+
if (this.rawContents) await this._parseContents();
|
|
2477
2720
|
}
|
|
2478
2721
|
};
|
|
2479
2722
|
var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
@@ -2487,7 +2730,7 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
|
2487
2730
|
convertParserValueToResolvers(value) {
|
|
2488
2731
|
if (!this.graph) throw new Error("expected graph to be set");
|
|
2489
2732
|
if (value === void 0) {
|
|
2490
|
-
return
|
|
2733
|
+
return void 0;
|
|
2491
2734
|
} else if (value instanceof ParsedEnvSpecStaticValue) {
|
|
2492
2735
|
return new StaticValueResolver(value.unescapedValue);
|
|
2493
2736
|
} else if (value instanceof ParsedEnvSpecFunctionCall) {
|
|
@@ -2501,12 +2744,16 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
|
2501
2744
|
for (const arg of argsFromParser) {
|
|
2502
2745
|
if (arg instanceof ParsedEnvSpecKeyValuePair) {
|
|
2503
2746
|
keyValueArgs ??= {};
|
|
2504
|
-
|
|
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;
|
|
2505
2750
|
} else {
|
|
2506
2751
|
if (keyValueArgs) {
|
|
2507
2752
|
return new ErrorResolver(new SchemaError("After switching to key-value function args, cannot switch back"));
|
|
2508
2753
|
}
|
|
2509
|
-
|
|
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);
|
|
2510
2757
|
}
|
|
2511
2758
|
}
|
|
2512
2759
|
if (keyValueArgs) argsAsResolversArray.push(keyValueArgs);
|
|
@@ -2520,19 +2767,19 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
|
2520
2767
|
this.parsedFile = await tryCatch(
|
|
2521
2768
|
() => parseEnvSpecDotEnvFile(rawContents),
|
|
2522
2769
|
(error) => {
|
|
2523
|
-
this.
|
|
2770
|
+
this._loadingError = new EnvSourceParseError(error.message, {
|
|
2524
2771
|
path: this.fullPath,
|
|
2525
2772
|
lineNumber: error.location.start.line,
|
|
2526
2773
|
colNumber: error.location.start.column,
|
|
2527
2774
|
lineStr: rawContents.split("\n")[error.location.start.line - 1]
|
|
2528
2775
|
});
|
|
2529
|
-
this.
|
|
2776
|
+
this._loadingError.cause = error;
|
|
2530
2777
|
}
|
|
2531
2778
|
);
|
|
2532
2779
|
if (this.loadingError) return;
|
|
2533
2780
|
if (!this.parsedFile) throw new Error("Failed to parse .env file");
|
|
2534
|
-
this.decorators = this.parsedFile.decoratorsObject;
|
|
2535
2781
|
if (!this.graph) throw new Error("expected graph to be set");
|
|
2782
|
+
this.decorators = this.parsedFile.decoratorsArray;
|
|
2536
2783
|
for (const item of this.parsedFile.configItems) {
|
|
2537
2784
|
item.processExpansion();
|
|
2538
2785
|
this.configItemDefs[item.key] = {
|
|
@@ -2543,24 +2790,57 @@ var DotEnvFileDataSource = class extends FileBasedDataSource {
|
|
|
2543
2790
|
}
|
|
2544
2791
|
}
|
|
2545
2792
|
};
|
|
2546
|
-
var
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
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;
|
|
2556
2821
|
}
|
|
2557
|
-
|
|
2558
|
-
envFiles.push(path.join(cwd, fileName));
|
|
2822
|
+
return;
|
|
2559
2823
|
}
|
|
2824
|
+
if (!await pathExists(filePath)) return;
|
|
2825
|
+
const source = new DotEnvFileDataSource(filePath);
|
|
2826
|
+
await this.addChild(source);
|
|
2827
|
+
return source;
|
|
2560
2828
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
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
|
+
};
|
|
2564
2844
|
|
|
2565
2845
|
// env-graph/lib/loader.ts
|
|
2566
2846
|
function autoDetectBasePath() {
|
|
@@ -2578,17 +2858,9 @@ async function loadEnvGraph(opts) {
|
|
|
2578
2858
|
await opts.afterInit(graph);
|
|
2579
2859
|
}
|
|
2580
2860
|
if (opts?.currentEnvFallback) {
|
|
2581
|
-
graph.
|
|
2582
|
-
}
|
|
2583
|
-
const envFilePaths = await findEnvFiles({
|
|
2584
|
-
cwd: graph.basePath
|
|
2585
|
-
});
|
|
2586
|
-
for (const envFilePath of envFilePaths) {
|
|
2587
|
-
const fileDataSource = new DotEnvFileDataSource(envFilePath);
|
|
2588
|
-
graph.addDataSource(fileDataSource);
|
|
2589
|
-
await fileDataSource.finishInit();
|
|
2861
|
+
graph.envFlagFallback = opts.currentEnvFallback;
|
|
2590
2862
|
}
|
|
2591
|
-
graph.
|
|
2863
|
+
await graph.setRootDataSource(new DirectoryDataSource(graph.basePath));
|
|
2592
2864
|
await graph.finishLoad();
|
|
2593
2865
|
return graph;
|
|
2594
2866
|
}
|
|
@@ -2775,6 +3047,6 @@ function gracefulExit(signal = 0) {
|
|
|
2775
3047
|
__name(gracefulExit, "gracefulExit");
|
|
2776
3048
|
//! these are probably not relevant anymore, or needs to move to a plugin layer?
|
|
2777
3049
|
|
|
2778
|
-
export { CoercionError, ConfigLoadError, DotEnvFileDataSource, EnvGraph2 as EnvGraph, EnvSourceParseError,
|
|
2779
|
-
//# sourceMappingURL=chunk-
|
|
2780
|
-
//# 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
|