read-config-file
Advanced tools
Comparing version 1.2.2 to 2.0.0
import { Lazy } from "lazy-val"; | ||
import { ErrorObject } from "ajv"; | ||
export declare function readConfig<T>(configFile: string, projectDir?: string, log?: (message: string) => void): Promise<T>; | ||
export declare function findAndReadConfig<T>(request: ReadConfigRequest): Promise<T | null>; | ||
export interface ReadConfigResult<T> { | ||
readonly result: T; | ||
readonly configFile: string; | ||
} | ||
export declare function readConfig<T>(configFile: string): Promise<ReadConfigResult<T>>; | ||
export declare function findAndReadConfig<T>(request: ReadConfigRequest): Promise<ReadConfigResult<T> | null>; | ||
export declare function orNullIfFileNotExist<T>(promise: Promise<T>): Promise<T | null>; | ||
@@ -14,7 +18,6 @@ export declare function orIfFileNotExist<T>(promise: Promise<T>, fallbackValue: T): Promise<T>; | ||
} | null> | null; | ||
log?: (message: string) => void; | ||
} | ||
export declare function loadConfig<T>(request: ReadConfigRequest): Promise<T | null>; | ||
export declare function getConfig<T>(request: ReadConfigRequest, configPath?: string | null, configFromOptions?: T | null): Promise<T>; | ||
export declare function loadParentConfig<T>(request: ReadConfigRequest, spec: string): Promise<T>; | ||
export declare function loadConfig<T>(request: ReadConfigRequest): Promise<ReadConfigResult<T> | null>; | ||
export declare function getConfig<T>(request: ReadConfigRequest, configPath?: string | null): Promise<ReadConfigResult<T> | null>; | ||
export declare function loadParentConfig<T>(request: ReadConfigRequest, spec: string): Promise<ReadConfigResult<T>>; | ||
export declare function validateConfig(config: any, scheme: Lazy<any>, errorMessage: (error: string, errors: Array<ErrorObject>) => string): Promise<void>; | ||
@@ -21,0 +24,0 @@ export declare function loadEnv(envFile: string): Promise<{ |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.loadEnv = exports.validateConfig = exports.loadParentConfig = exports.getConfig = exports.loadConfig = exports.findAndReadConfig = exports.readConfig = undefined; | ||
exports.loadEnv = exports.validateConfig = exports.loadParentConfig = exports.loadConfig = exports.findAndReadConfig = exports.readConfig = undefined; | ||
@@ -16,3 +16,3 @@ var _bluebirdLst; | ||
let readConfig = exports.readConfig = (() => { | ||
var _ref = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (configFile, projectDir, log) { | ||
var _ref = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (configFile) { | ||
const data = yield (0, (_fsExtraP || _load_fsExtraP()).readFile)(configFile, "utf8"); | ||
@@ -27,10 +27,6 @@ let result; | ||
} | ||
if (log != null && projectDir != null) { | ||
const relativePath = _path.relative(projectDir, configFile); | ||
log(`Using ${relativePath.startsWith("..") ? configFile : relativePath} configuration file`); | ||
} | ||
return result; | ||
return { result, configFile }; | ||
}); | ||
return function readConfig(_x, _x2, _x3) { | ||
return function readConfig(_x) { | ||
return _ref.apply(this, arguments); | ||
@@ -44,3 +40,3 @@ }; | ||
for (const configFile of [`${prefix}.yml`, `${prefix}.yaml`, `${prefix}.json`, `${prefix}.json5`, `${prefix}.toml`]) { | ||
const data = yield orNullIfFileNotExist(readConfig(_path.join(request.projectDir, configFile), request.projectDir, request.log)); | ||
const data = yield orNullIfFileNotExist(readConfig(_path.join(request.projectDir, configFile))); | ||
if (data != null) { | ||
@@ -53,3 +49,3 @@ return data; | ||
return function findAndReadConfig(_x4) { | ||
return function findAndReadConfig(_x2) { | ||
return _ref2.apply(this, arguments); | ||
@@ -69,3 +65,3 @@ }; | ||
return function loadConfig(_x5) { | ||
return function loadConfig(_x3) { | ||
return _ref3.apply(this, arguments); | ||
@@ -75,20 +71,4 @@ }; | ||
let getConfig = exports.getConfig = (() => { | ||
var _ref4 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (request, configPath, configFromOptions) { | ||
let fileOrPackageConfig; | ||
if (configPath == null) { | ||
fileOrPackageConfig = yield loadConfig(request); | ||
} else { | ||
fileOrPackageConfig = yield readConfig(_path.resolve(request.projectDir, configPath), request.projectDir, request.log); | ||
} | ||
return (0, (_deepAssign || _load_deepAssign()).deepAssign)(fileOrPackageConfig == null ? Object.create(null) : fileOrPackageConfig, configFromOptions); | ||
}); | ||
return function getConfig(_x6, _x7, _x8) { | ||
return _ref4.apply(this, arguments); | ||
}; | ||
})(); | ||
let loadParentConfig = exports.loadParentConfig = (() => { | ||
var _ref5 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (request, spec) { | ||
var _ref4 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (request, spec) { | ||
let isFileSpec; | ||
@@ -99,3 +79,3 @@ if (spec.startsWith("file:")) { | ||
} | ||
let parentConfig = yield orNullIfFileNotExist(readConfig(_path.resolve(request.projectDir, spec), request.projectDir, request.log)); | ||
let parentConfig = yield orNullIfFileNotExist(readConfig(_path.resolve(request.projectDir, spec))); | ||
if (parentConfig == null && isFileSpec !== true) { | ||
@@ -109,3 +89,3 @@ let resolved = null; | ||
if (resolved != null) { | ||
parentConfig = yield readConfig(resolved, request.projectDir, request.log); | ||
parentConfig = yield readConfig(resolved); | ||
} | ||
@@ -119,4 +99,4 @@ } | ||
return function loadParentConfig(_x9, _x10) { | ||
return _ref5.apply(this, arguments); | ||
return function loadParentConfig(_x4, _x5) { | ||
return _ref4.apply(this, arguments); | ||
}; | ||
@@ -126,3 +106,3 @@ })(); | ||
let validateConfig = exports.validateConfig = (() => { | ||
var _ref6 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (config, scheme, errorMessage) { | ||
var _ref5 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (config, scheme, errorMessage) { | ||
const ajv = new (_ajv || _load_ajv()).default({ | ||
@@ -143,4 +123,4 @@ allErrors: true, | ||
return function validateConfig(_x11, _x12, _x13) { | ||
return _ref6.apply(this, arguments); | ||
return function validateConfig(_x6, _x7, _x8) { | ||
return _ref5.apply(this, arguments); | ||
}; | ||
@@ -150,3 +130,3 @@ })(); | ||
let loadEnv = exports.loadEnv = (() => { | ||
var _ref7 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (envFile) { | ||
var _ref6 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (envFile) { | ||
const data = yield orNullIfFileNotExist((0, (_fsExtraP || _load_fsExtraP()).readFile)(envFile, "utf8")); | ||
@@ -166,4 +146,4 @@ if (data == null) { | ||
return function loadEnv(_x14) { | ||
return _ref7.apply(this, arguments); | ||
return function loadEnv(_x9) { | ||
return _ref6.apply(this, arguments); | ||
}; | ||
@@ -176,2 +156,3 @@ })(); | ||
exports.orIfFileNotExist = orIfFileNotExist; | ||
exports.getConfig = getConfig; | ||
@@ -192,8 +173,2 @@ var _fsExtraP; | ||
var _deepAssign; | ||
function _load_deepAssign() { | ||
return _deepAssign = require("./deepAssign"); | ||
} | ||
var _ajv; | ||
@@ -231,2 +206,9 @@ | ||
}); | ||
} | ||
function getConfig(request, configPath) { | ||
if (configPath == null) { | ||
return loadConfig(request); | ||
} else { | ||
return readConfig(_path.resolve(request.projectDir, configPath)); | ||
} | ||
} |
{ | ||
"name": "read-config-file", | ||
"version": "1.2.2", | ||
"version": "2.0.0", | ||
"main": "out/main.js", | ||
@@ -5,0 +5,0 @@ "author": "Vladimir Krivosheev", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53826
428