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SACtD;KACF;IAED,IAAI,YAAY,IAAI,IAAI,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,EAAE,CAAC,CAAA;KAC3D;IAED,OAAO,YAAY,CAAA;AACrB,CAAC;AA3BD,4CA2BC;AAEM,KAAK,UAAU,OAAO,CAAC,OAAe;IAC3C,MAAM,IAAI,GAAG,MAAM,oBAAoB,CAAC,mBAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;IAClE,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,MAAM,GAAG,cAAQ,CAAC,IAAI,CAAC,CAAA;IAC7B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;QACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YACpC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;SAC/B;KACF;IACD,OAAO,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;IAChC,OAAO,MAAM,CAAA;AACf,CAAC;AAdD,0BAcC","sourcesContent":["import { readFile, readJson } from \"fs-extra\"\nimport { safeLoad } from \"js-yaml\"\nimport * as path from \"path\"\nimport { Lazy } from \"lazy-val\"\nimport { parse as parseEnv } from \"dotenv\"\n\nexport interface ReadConfigResult<T> {\n readonly result: T\n readonly configFile: string | null\n}\n\nasync function readConfig<T>(configFile: string, request: ReadConfigRequest): Promise<ReadConfigResult<T>> {\n const data = await readFile(configFile, \"utf8\")\n let result\n if (configFile.endsWith(\".json5\") || configFile.endsWith(\".json\")) {\n result = require(\"json5\").parse(data)\n }\n else if (configFile.endsWith(\".js\")) {\n result = require(configFile)\n if (result.default != null) {\n result = result.default\n }\n if (typeof result === \"function\") {\n result = result(request)\n }\n result = await Promise.resolve(result)\n }\n else if (configFile.endsWith(\".toml\")) {\n result = require(\"toml\").parse(data)\n }\n else {\n result = safeLoad(data)\n }\n return {result, configFile}\n}\n\nexport async function findAndReadConfig<T>(request: ReadConfigRequest): Promise<ReadConfigResult<T> | null> {\n const prefix = request.configFilename\n for (const configFile of [`${prefix}.yml`, `${prefix}.yaml`, `${prefix}.json`, `${prefix}.json5`, `${prefix}.toml`, `${prefix}.js`]) {\n const data = await orNullIfFileNotExist(readConfig<T>(path.join(request.projectDir, configFile), request))\n if (data != null) {\n return data\n }\n }\n\n return null\n}\n\nexport function orNullIfFileNotExist<T>(promise: Promise<T>): Promise<T | null> {\n return orIfFileNotExist(promise, null)\n}\n\nexport function orIfFileNotExist<T>(promise: Promise<T>, fallbackValue: T): Promise<T> {\n return promise\n .catch(e => {\n if (e.code === \"ENOENT\" || e.code === \"ENOTDIR\") {\n return fallbackValue\n }\n throw e\n })\n}\n\nexport interface ReadConfigRequest {\n packageKey: string\n configFilename: string\n\n projectDir: string\n packageMetadata: Lazy<{ [key: string]: any } | null> | null\n}\n\nexport async function loadConfig<T>(request: ReadConfigRequest): Promise<ReadConfigResult<T> | null> {\n let packageMetadata = request.packageMetadata == null ? null : await request.packageMetadata.value\n if (packageMetadata == null) {\n packageMetadata = await orNullIfFileNotExist(readJson(path.join(request.projectDir, \"package.json\")))\n }\n\n const data: T = packageMetadata == null ? null : packageMetadata[request.packageKey]\n return data == null ? findAndReadConfig<T>(request) : {result: data, configFile: null}\n}\n\nexport function getConfig<T>(request: ReadConfigRequest, configPath?: string | null): Promise<ReadConfigResult<T> | null> {\n if (configPath == null) {\n return loadConfig<T>(request)\n }\n else {\n return readConfig<T>(path.resolve(request.projectDir, configPath), request)\n }\n}\n\nexport async function loadParentConfig<T>(request: ReadConfigRequest, spec: string): Promise<ReadConfigResult<T>> {\n let isFileSpec: boolean | undefined\n if (spec.startsWith(\"file:\")) {\n spec = spec.substring(\"file:\".length)\n isFileSpec = true\n }\n\n let parentConfig = await orNullIfFileNotExist(readConfig<T>(path.resolve(request.projectDir, spec), request))\n if (parentConfig == null && isFileSpec !== true) {\n let resolved: string | null = null\n try {\n resolved = require.resolve(spec)\n }\n catch (e) {\n // ignore\n }\n\n if (resolved != null) {\n parentConfig = await readConfig<T>(resolved, request)\n }\n }\n\n if (parentConfig == null) {\n throw new Error(`Cannot find parent config file: ${spec}`)\n }\n\n return parentConfig\n}\n\nexport async function loadEnv(envFile: string) {\n const data = await orNullIfFileNotExist(readFile(envFile, \"utf8\"))\n if (data == null) {\n return null\n }\n\n const parsed = parseEnv(data)\n for (const key of Object.keys(parsed)) {\n if (!process.env.hasOwnProperty(key)) {\n process.env[key] = parsed[key]\n }\n }\n require(\"dotenv-expand\")(parsed)\n return parsed\n}"]} |