Skip to content

Commit

Permalink
Merge pull request #24 from jeffijoe/update-packages
Browse files Browse the repository at this point in the history
Update packages, bump supported Node version to 12
  • Loading branch information
jeffijoe committed Feb 4, 2021
2 parents 00f954b + 6371125 commit 81af621
Show file tree
Hide file tree
Showing 17 changed files with 4,593 additions and 3,456 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,6 +1,7 @@
language: node_js
node_js:
- "stable"
- "12"

# Lint errors should trigger a failure.
before_script: npm run lint
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## 3.0.0

* **[BREAKING]** Update packages and minimum engine version to Node v12

## 2.0.0

* **[BREAKING]**:Coerce to known type ([#12](https://github.com/jeffijoe/yenv/issues/12)) (can be disabled)
Expand Down
20 changes: 10 additions & 10 deletions lib/cli.js
Expand Up @@ -6,41 +6,41 @@ require('yargs')
command: 'print [file] [env] [format] [args]',
describe: 'Prints the given environment in the given format',
handler: printEnv,
builder: yargs =>
builder: (yargs) =>
yargs
.positional('file', {
type: 'string',
describe: 'The environment to print'
describe: 'The environment to print',
})
.positional('env', {
type: 'string',
describe: 'The environment to print'
describe: 'The environment to print',
})
.positional('format', {
type: 'string',
describe: 'The format to print in; can be json or dotenv'
describe: 'The format to print in; can be json or dotenv',
})
.default('format')
.option('r', {
describe:
'If specified, prints all values as strings (like a real environment would)',
type: 'boolean',
alias: 'raw',
default: false
default: false,
})
.option('f', {
describe:
'Only includes the values read from the file, not the actual user environment',
type: 'boolean',
default: false,
alias: 'fileOnly'
alias: 'fileOnly',
})
.option('s', {
describe: 'Sort by key',
type: 'boolean',
default: false,
alias: 'sort'
})
alias: 'sort',
}),
})
.demandCommand(1)
.help().argv
Expand All @@ -56,7 +56,7 @@ function printEnv(args) {
raw: raw,
env: env,
strict: false,
envObject: fileOnly ? {} : process.env
envObject: fileOnly ? {} : process.env,
})
const result = sort ? sortObject(processed) : processed
switch (format) {
Expand Down Expand Up @@ -88,7 +88,7 @@ function printEnvList(obj) {
function sortObject(obj) {
const keys = Object.keys(obj).sort()
const result = {}
keys.forEach(key => {
keys.forEach((key) => {
result[key] = obj[key]
})
return result
Expand Down
2 changes: 1 addition & 1 deletion lib/composeSections.js
Expand Up @@ -52,7 +52,7 @@ module.exports = function composeSections(root, sectionsToCompose, state) {
// Passed along in the recursive call.
state = state || {
// Used for tracking circular sections.
sectionTracker: []
sectionTracker: [],
}

const composedObject = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/loadAndParse.js
Expand Up @@ -35,6 +35,6 @@ module.exports = function loadAndParse(filePath, optional) {

if (!contents) return {}
const yamlMarkup = contents.toString()
const parsed = yaml.safeLoad(yamlMarkup)
const parsed = yaml.load(yamlMarkup)
return parsed
}
16 changes: 8 additions & 8 deletions lib/processImports.js
Expand Up @@ -26,7 +26,7 @@ function circularImportsError(fileBeingImported, importTrail) {
const message =
`Circular import of "${fileBeingImported}".\r\n` +
'Import trace:\r\n' +
importTrail.map(f => ` -> ${f}`).join('\r\n')
importTrail.map((f) => ` -> ${f}`).join('\r\n')
return new Error(message)
}

Expand All @@ -49,21 +49,21 @@ module.exports = function processImports(parsed, opts, state) {
// Since this function is recursive, we pass state along
state = state || {
importTrail: [],
loadedFiles: []
loadedFiles: [],
}

state.loadedFiles.push(opts.importingFile)
state.importTrail.unshift(opts.importingFile)

// Helper to check if we have already loaded the given file.
const hasLoadedFile = f => state.loadedFiles.indexOf(f) > -1
const hasLoadedFile = (f) => state.loadedFiles.indexOf(f) > -1

// We need to reverse the order to get the last imported file to win over earlier
// imported files. This is because the outer file is merged onto the inner one,
// so if we did not reverse then the first imported file would win.
const files = [
...mapFiles(parsed[IMPORT_SYMBOL], opts.importingFile, false),
...mapFiles(parsed[REQUIRE_SYMBOL], opts.importingFile, true)
...mapFiles(parsed[REQUIRE_SYMBOL], opts.importingFile, true),
].reverse()
delete parsed[IMPORT_SYMBOL]
delete parsed[REQUIRE_SYMBOL]
Expand All @@ -76,12 +76,12 @@ module.exports = function processImports(parsed, opts, state) {
loaded,
Object.assign({}, opts, { importingFile: descriptor.file }),
Object.assign({}, state, {
importTrail: [...state.importTrail]
importTrail: [...state.importTrail],
})
)

// Make sure all top-level nodes are not null (empty sections)
Object.keys(processed).forEach(key => {
Object.keys(processed).forEach((key) => {
const value = processed[key]
if (value === null) {
processed[key] = {}
Expand All @@ -104,9 +104,9 @@ function mapFiles(files, relative, required) {
files = [files]
}

return files.map(f => ({
return files.map((f) => ({
file: resolvePath(relative, f),
required: required
required: required,
}))
}

Expand Down
4 changes: 1 addition & 3 deletions lib/yenv.d.ts
Expand Up @@ -59,8 +59,6 @@ declare namespace yenv {
*/
declare function yenv<T = any>(filePath?: string, opts?: yenv.IYenvOpts<T>): T

declare namespace yenv {

}
declare namespace yenv {}

export = yenv
10 changes: 5 additions & 5 deletions lib/yenv.js
Expand Up @@ -61,14 +61,14 @@ module.exports = function yenv(filePath, opts) {
cwd: process.cwd(),
raw: false,
strict: true,
optionalKeys: []
optionalKeys: [],
},
opts || {}
)

opts = Object.assign(
{
env: opts.envObject.NODE_ENV || 'development'
env: opts.envObject.NODE_ENV || 'development',
},
opts
)
Expand All @@ -78,16 +78,16 @@ module.exports = function yenv(filePath, opts) {
const processed = processImports(
parsed,
Object.assign({}, opts, {
importingFile: filePath
importingFile: filePath,
})
)

const result = applyEnv(processed, opts)
if (opts.strict) {
return keyblade(result, {
ignore: opts.optionalKeys,
message: key => `[yenv] ${key} not found in the loaded environment`,
logBeforeThrow: opts.logBeforeThrow
message: (key) => `[yenv] ${key} not found in the loaded environment`,
logBeforeThrow: opts.logBeforeThrow,
})
}
return result
Expand Down

0 comments on commit 81af621

Please sign in to comment.