@datkt/konanc-config
Advanced tools
Comparing version 1.0.5 to 2.0.0
70
index.js
const { extname, dirname, resolve } = require('path') | ||
const { existsSync } = require('fs') | ||
const { parse } = require('rc/lib/utils') | ||
@@ -18,3 +19,3 @@ const rc = require('rc') | ||
return rc(name, defaults, { config }, (content) => { | ||
const conf = rc(name, defaults, { config }, (content) => { | ||
Object.assign(env, process.env, { | ||
@@ -27,2 +28,69 @@ __dirname: resolve(dirname(config)), | ||
if (conf.require && conf.require.length) { | ||
if (!Array.isArray(conf.require)) { | ||
conf.require = [ conf.require ] | ||
} | ||
const repos = (conf.repo && !Array.isArray(conf.repo) | ||
? [ conf.repo ] | ||
: conf.repo) | ||
for (const dep of conf.require) { | ||
merge(conf, load(dep, defaults, env)) | ||
for (const repo of repos) { | ||
merge(conf, load(resolve(repo, dep), defaults, env)) | ||
} | ||
} | ||
} | ||
return conf | ||
function merge(target, src) { | ||
if (!target || !src ) { | ||
return | ||
} | ||
if ('object' != typeof target || 'object' != typeof src) { | ||
return | ||
} | ||
for (const k in src) { | ||
if (Array.isArray(src[k])) { | ||
if (Array.isArray(conf[k])) { | ||
for (const x of src[k]) { | ||
if (!conf[k].includes(x)) { | ||
conf[k].push(x) | ||
} | ||
} | ||
} else if ('string' == typeof conf[k]) { | ||
if (src[k].includes(conf[k])) { | ||
conf[k] = src[k] | ||
} else { | ||
conf[k] = [ conf[k] ].concat(src[k]) | ||
} | ||
} else { | ||
conf[k] = src[k] | ||
} | ||
} else if ('string' == typeof src[k]) { | ||
if (Array.isArray(conf[k])) { | ||
if (!conf[k].includes(src[k])) { | ||
conf[k].push(src[k]) | ||
} | ||
} else if ('string' == typeof conf[k]) { | ||
if (conf[k] != src[k]) { | ||
conf[k] = [ conf[k], src[k] ] | ||
} | ||
} | ||
} else if ('object' == typeof src[k]) { | ||
if ('object' == typeof target[k]) { | ||
merge(src[k], target[k]) | ||
} else if (null != target[k] && 'undefined' != typeof target[k]) { | ||
throw new TypeError("Cannot merge source object into target string.") | ||
} else { | ||
target[k] = src[k] | ||
} | ||
} | ||
} | ||
} | ||
function template(content) { | ||
@@ -29,0 +97,0 @@ const vars = Object.keys(env) |
{ | ||
"name": "@datkt/konanc-config", | ||
"version": "1.0.5", | ||
"version": "2.0.0", | ||
"description": "Command line utility to read '*.kc' konanc config files to print compiler flags", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
9650
91
2