Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

read-config-file

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

read-config-file - npm Package Compare versions

Comparing version 3.1.1 to 3.1.2

231

out/main.js

@@ -6,12 +6,17 @@ "use strict";

});
exports.readConfig = readConfig;
exports.findAndReadConfig = findAndReadConfig;
exports.orNullIfFileNotExist = orNullIfFileNotExist;
exports.orIfFileNotExist = orIfFileNotExist;
exports.loadConfig = loadConfig;
exports.getConfig = getConfig;
exports.loadParentConfig = loadParentConfig;
exports.validateConfig = validateConfig;
exports.loadEnv = loadEnv;
exports.loadEnv = exports.validateConfig = exports.loadParentConfig = exports.loadConfig = exports.findAndReadConfig = exports.readConfig = void 0;
function _bluebirdLst() {
const data = require("bluebird-lst");
_bluebirdLst = function () {
return data;
};
return data;
}
function _fsExtraP() {

@@ -73,36 +78,52 @@ const data = require("fs-extra-p");

async function readConfig(configFile) {
const data = await (0, _fsExtraP().readFile)(configFile, "utf8");
let result;
let readConfig = (() => {
var _ref = (0, _bluebirdLst().coroutine)(function* (configFile) {
const data = yield (0, _fsExtraP().readFile)(configFile, "utf8");
let result;
if (configFile.endsWith(".json5") || configFile.endsWith(".json")) {
result = require("json5").parse(data);
} else if (configFile.endsWith(".js")) {
result = require(configFile);
} else if (configFile.endsWith(".toml")) {
result = require("toml").parse(data);
} else {
result = (0, _jsYaml().safeLoad)(data);
}
if (configFile.endsWith(".json5") || configFile.endsWith(".json")) {
result = require("json5").parse(data);
} else if (configFile.endsWith(".js")) {
result = require(configFile);
} else if (configFile.endsWith(".toml")) {
result = require("toml").parse(data);
} else {
result = (0, _jsYaml().safeLoad)(data);
}
return {
result,
configFile
return {
result,
configFile
};
});
return function readConfig(_x) {
return _ref.apply(this, arguments);
};
}
})();
async function findAndReadConfig(request) {
const prefix = request.configFilename;
exports.readConfig = readConfig;
for (const configFile of [`${prefix}.yml`, `${prefix}.yaml`, `${prefix}.json`, `${prefix}.json5`, `${prefix}.toml`]) {
const data = await orNullIfFileNotExist(readConfig(path.join(request.projectDir, configFile)));
let findAndReadConfig = (() => {
var _ref2 = (0, _bluebirdLst().coroutine)(function* (request) {
const prefix = request.configFilename;
if (data != null) {
return data;
for (const configFile of [`${prefix}.yml`, `${prefix}.yaml`, `${prefix}.json`, `${prefix}.json5`, `${prefix}.toml`]) {
const data = yield orNullIfFileNotExist(readConfig(path.join(request.projectDir, configFile)));
if (data != null) {
return data;
}
}
}
return null;
}
return null;
});
return function findAndReadConfig(_x2) {
return _ref2.apply(this, arguments);
};
})();
exports.findAndReadConfig = findAndReadConfig;
function orNullIfFileNotExist(promise) {

@@ -122,16 +143,24 @@ return orIfFileNotExist(promise, null);

async function loadConfig(request) {
let packageMetadata = request.packageMetadata == null ? null : await request.packageMetadata.value;
let loadConfig = (() => {
var _ref3 = (0, _bluebirdLst().coroutine)(function* (request) {
let packageMetadata = request.packageMetadata == null ? null : yield request.packageMetadata.value;
if (packageMetadata == null) {
packageMetadata = await orNullIfFileNotExist((0, _fsExtraP().readJson)(path.join(request.projectDir, "package.json")));
}
if (packageMetadata == null) {
packageMetadata = yield orNullIfFileNotExist((0, _fsExtraP().readJson)(path.join(request.projectDir, "package.json")));
}
const data = packageMetadata == null ? null : packageMetadata[request.packageKey];
return data == null ? findAndReadConfig(request) : {
result: data,
configFile: null
const data = packageMetadata == null ? null : packageMetadata[request.packageKey];
return data == null ? findAndReadConfig(request) : {
result: data,
configFile: null
};
});
return function loadConfig(_x3) {
return _ref3.apply(this, arguments);
};
}
})();
exports.loadConfig = loadConfig;
function getConfig(request, configPath) {

@@ -145,71 +174,93 @@ if (configPath == null) {

async function loadParentConfig(request, spec) {
let isFileSpec;
let loadParentConfig = (() => {
var _ref4 = (0, _bluebirdLst().coroutine)(function* (request, spec) {
let isFileSpec;
if (spec.startsWith("file:")) {
spec = spec.substring("file:".length);
isFileSpec = true;
}
if (spec.startsWith("file:")) {
spec = spec.substring("file:".length);
isFileSpec = true;
}
let parentConfig = await orNullIfFileNotExist(readConfig(path.resolve(request.projectDir, spec)));
let parentConfig = yield orNullIfFileNotExist(readConfig(path.resolve(request.projectDir, spec)));
if (parentConfig == null && isFileSpec !== true) {
let resolved = null;
if (parentConfig == null && isFileSpec !== true) {
let resolved = null;
try {
resolved = require.resolve(spec);
} catch (e) {// ignore
try {
resolved = require.resolve(spec);
} catch (e) {// ignore
}
if (resolved != null) {
parentConfig = yield readConfig(resolved);
}
}
if (resolved != null) {
parentConfig = await readConfig(resolved);
if (parentConfig == null) {
throw new Error(`Cannot find parent config file: ${spec}`);
}
}
if (parentConfig == null) {
throw new Error(`Cannot find parent config file: ${spec}`);
}
return parentConfig;
});
return parentConfig;
}
return function loadParentConfig(_x4, _x5) {
return _ref4.apply(this, arguments);
};
})();
async function validateConfig(config, scheme, errorMessage) {
const ajv = new (_ajv().default)({
allErrors: true,
coerceTypes: true,
verbose: true,
errorDataPath: "configuration"
});
exports.loadParentConfig = loadParentConfig;
require("ajv-keywords")(ajv, ["typeof"]);
let validateConfig = (() => {
var _ref5 = (0, _bluebirdLst().coroutine)(function* (config, scheme, errorMessage) {
const ajv = new (_ajv().default)({
allErrors: true,
coerceTypes: true,
verbose: true,
errorDataPath: "configuration"
});
const schema = await scheme.value;
const validator = ajv.compile(schema);
require("ajv-keywords")(ajv, ["typeof"]);
if (!validator(config)) {
const error = new Error(errorMessage((0, _ajvErrorNormalizer().normaliseErrorMessages)(validator.errors, schema), validator.errors));
error.code = "ERR_CONFIG_INVALID";
throw error;
}
}
const schema = yield scheme.value;
const validator = ajv.compile(schema);
async function loadEnv(envFile) {
const data = await orNullIfFileNotExist((0, _fsExtraP().readFile)(envFile, "utf8"));
if (!validator(config)) {
const error = new Error(errorMessage((0, _ajvErrorNormalizer().normaliseErrorMessages)(validator.errors, schema), validator.errors));
error.code = "ERR_CONFIG_INVALID";
throw error;
}
});
if (data == null) {
return null;
}
return function validateConfig(_x6, _x7, _x8) {
return _ref5.apply(this, arguments);
};
})();
const parsed = (0, _dotenv().parse)(data);
exports.validateConfig = validateConfig;
for (const key of Object.keys(parsed)) {
if (!process.env.hasOwnProperty(key)) {
process.env[key] = parsed[key];
let loadEnv = (() => {
var _ref6 = (0, _bluebirdLst().coroutine)(function* (envFile) {
const data = yield orNullIfFileNotExist((0, _fsExtraP().readFile)(envFile, "utf8"));
if (data == null) {
return null;
}
}
require("dotenv-expand")(parsed);
const parsed = (0, _dotenv().parse)(data);
return parsed;
}
for (const key of Object.keys(parsed)) {
if (!process.env.hasOwnProperty(key)) {
process.env[key] = parsed[key];
}
}
require("dotenv-expand")(parsed);
return parsed;
});
return function loadEnv(_x9) {
return _ref6.apply(this, arguments);
};
})(); exports.loadEnv = loadEnv;
//# sourceMappingURL=main.js.map
{
"name": "read-config-file",
"version": "3.1.1",
"version": "3.1.2",
"main": "out/main.js",

@@ -14,3 +14,3 @@ "author": "Vladimir Krivosheev",

"scripts": {
"compile": "ts-babel",
"compile": "NODE_ENV=production ts-babel",
"release": "yarn compile && npm publish"

@@ -17,0 +17,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc