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.2 to 3.1.3

1

out/ajvErrorNormalizer.js

@@ -245,2 +245,3 @@ "use strict";

}
// __ts-babel@6.0.4
//# sourceMappingURL=ajvErrorNormalizer.js.map

@@ -52,2 +52,3 @@ "use strict";

}
// __ts-babel@6.0.4
//# sourceMappingURL=deepAssign.js.map

232

out/main.js

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

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

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

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

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

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

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

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

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

"scripts": {
"compile": "NODE_ENV=production ts-babel",
"release": "yarn compile && npm publish"
"compile": "ts-babel",
"release": "BABEL_ENV=true yarn compile && npm publish"
},
"dependencies": {
"ajv": "^6.5.2",
"ajv": "^6.5.4",
"ajv-keywords": "^3.2.0",
"bluebird-lst": "^1.0.5",
"dotenv": "^6.0.0",
"bluebird-lst": "^1.0.6",
"dotenv": "^6.1.0",
"dotenv-expand": "^4.2.0",
"fs-extra-p": "^4.6.1",
"fs-extra-p": "^7.0.0",
"js-yaml": "^3.12.0",
"json5": "^1.0.1",
"json5": "^2.1.0",
"lazy-val": "^1.0.3"

@@ -32,6 +32,6 @@ },

"@types/js-yaml": "^3.11.2",
"@types/node": "^10.7.0",
"babel-preset-ts-node6-bluebird": "^2.0.10",
"ts-babel": "^6.0.1",
"typescript": "^3.0.1"
"@types/node": "^10.12.2",
"babel-preset-ts-node6-bluebird": "^3.0.1",
"ts-babel": "^6.1.0",
"typescript": "^3.1.6"
},

@@ -38,0 +38,0 @@ "babel": {

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