pkg-conf
Advanced tools
Comparing version 2.1.0 to 3.0.0
49
index.js
@@ -10,8 +10,8 @@ 'use strict'; | ||
const addFp = (obj, fp) => { | ||
filepaths.set(obj, fp); | ||
return obj; | ||
const addFilePath = (object, filePath) => { | ||
filepaths.set(object, filePath); | ||
return object; | ||
}; | ||
const pkgConf = (namespace, opts) => { | ||
const pkgConf = (namespace, options = {}) => { | ||
if (!namespace) { | ||
@@ -21,17 +21,15 @@ return Promise.reject(new TypeError('Expected a namespace')); | ||
opts = opts || {}; | ||
return findUp('package.json', opts.cwd ? {cwd: opts.cwd} : {}) | ||
.then(fp => { | ||
if (!fp) { | ||
return addFp(Object.assign({}, opts.defaults), fp); | ||
return findUp('package.json', options.cwd ? {cwd: options.cwd} : {}) | ||
.then(filePath => { | ||
if (!filePath) { | ||
return addFilePath(Object.assign({}, options.defaults), filePath); | ||
} | ||
return loadJsonFile(fp).then(pkg => { | ||
if (opts.skipOnFalse && pkg[namespace] === false) { | ||
const newOpts = Object.assign({}, opts, {cwd: findNextCwd(fp)}); | ||
return pkgConf(namespace, newOpts); | ||
return loadJsonFile(filePath).then(package_ => { | ||
if (options.skipOnFalse && package_[namespace] === false) { | ||
const newOptions = Object.assign({}, options, {cwd: findNextCwd(filePath)}); | ||
return pkgConf(namespace, newOptions); | ||
} | ||
return addFp(Object.assign({}, opts.defaults, pkg[namespace]), fp); | ||
return addFilePath(Object.assign({}, options.defaults, package_[namespace]), filePath); | ||
}); | ||
@@ -41,3 +39,3 @@ }); | ||
const sync = (namespace, opts) => { | ||
const sync = (namespace, options = {}) => { | ||
if (!namespace) { | ||
@@ -47,22 +45,21 @@ throw new TypeError('Expected a namespace'); | ||
opts = opts || {}; | ||
const filePath = findUp.sync('package.json', options.cwd ? {cwd: options.cwd} : {}); | ||
const fp = findUp.sync('package.json', opts.cwd ? {cwd: opts.cwd} : {}); | ||
if (!fp) { | ||
return addFp(Object.assign({}, opts.defaults), fp); | ||
if (!filePath) { | ||
return addFilePath(Object.assign({}, options.defaults), filePath); | ||
} | ||
const pkg = loadJsonFile.sync(fp); | ||
const package_ = loadJsonFile.sync(filePath); | ||
if (opts.skipOnFalse && pkg[namespace] === false) { | ||
const newOpts = Object.assign({}, opts, {cwd: findNextCwd(fp)}); | ||
return sync(namespace, newOpts); | ||
if (options.skipOnFalse && package_[namespace] === false) { | ||
const newOptions = Object.assign({}, options, {cwd: findNextCwd(filePath)}); | ||
return sync(namespace, newOptions); | ||
} | ||
return addFp(Object.assign({}, opts.defaults, pkg[namespace]), fp); | ||
return addFilePath(Object.assign({}, options.defaults, package_[namespace]), filePath); | ||
}; | ||
module.exports = pkgConf; | ||
module.exports.default = pkgConf; | ||
module.exports.filepath = filepath; | ||
module.exports.sync = sync; |
{ | ||
"name": "pkg-conf", | ||
"version": "2.1.0", | ||
"description": "Get namespaced config from the closest package.json", | ||
"license": "MIT", | ||
"repository": "sindresorhus/pkg-conf", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"json", | ||
"read", | ||
"parse", | ||
"file", | ||
"fs", | ||
"graceful", | ||
"load", | ||
"pkg", | ||
"package", | ||
"config", | ||
"conf", | ||
"configuration", | ||
"object", | ||
"namespace", | ||
"namespaced" | ||
], | ||
"dependencies": { | ||
"find-up": "^2.0.0", | ||
"load-json-file": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"fixture": { | ||
"foo": true | ||
} | ||
"name": "pkg-conf", | ||
"version": "3.0.0", | ||
"description": "Get namespaced config from the closest package.json", | ||
"license": "MIT", | ||
"repository": "sindresorhus/pkg-conf", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"json", | ||
"read", | ||
"parse", | ||
"file", | ||
"fs", | ||
"graceful", | ||
"load", | ||
"pkg", | ||
"package", | ||
"config", | ||
"conf", | ||
"configuration", | ||
"object", | ||
"namespace", | ||
"namespaced" | ||
], | ||
"dependencies": { | ||
"find-up": "^3.0.0", | ||
"load-json-file": "^5.2.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.2.1", | ||
"tsd-check": "^0.3.0", | ||
"xo": "^0.24.0" | ||
}, | ||
"fixture": { | ||
"foo": true | ||
} | ||
} |
@@ -5,3 +5,3 @@ # pkg-conf [![Build Status](https://travis-ci.org/sindresorhus/pkg-conf.svg?branch=master)](https://travis-ci.org/sindresorhus/pkg-conf) | ||
Having tool specific config in package.json reduces the amount of metafiles in your repo (there are usually a lot!) and makes the config obvious compared to hidden dotfiles like `.eslintrc`, which can end up causing confusion. [XO](https://github.com/sindresorhus/xo), for example, uses the `xo` namespace in package.json, and [ESLint](http://eslint.org) uses `eslintConfig`. Many more tools supports this, like [AVA](https://ava.li), [Babel](https://babeljs.io), [nyc](https://github.com/istanbuljs/nyc), etc. | ||
Having tool specific config in package.json reduces the amount of metafiles in your repo (there are usually a lot!) and makes the config obvious compared to hidden dotfiles like `.eslintrc`, which can end up causing confusion. [XO](https://github.com/xojs/xo), for example, uses the `xo` namespace in package.json, and [ESLint](http://eslint.org) uses `eslintConfig`. Many more tools supports this, like [AVA](https://ava.li), [Babel](https://babeljs.io), [nyc](https://github.com/istanbuljs/nyc), etc. | ||
@@ -60,2 +60,4 @@ | ||
Type: `Object` | ||
##### cwd | ||
@@ -84,2 +86,3 @@ | ||
Example usage for the user: | ||
```json | ||
@@ -86,0 +89,0 @@ { |
8462
5
105
110
3
+ Addedfind-up@3.0.0(transitive)
+ Addedload-json-file@5.3.0(transitive)
+ Addedlocate-path@3.0.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpify@4.0.1(transitive)
+ Addedtype-fest@0.3.1(transitive)
- Removedfind-up@2.1.0(transitive)
- Removedload-json-file@4.0.0(transitive)
- Removedlocate-path@2.0.0(transitive)
- Removedp-limit@1.3.0(transitive)
- Removedp-locate@2.0.0(transitive)
- Removedp-try@1.0.0(transitive)
- Removedpify@3.0.0(transitive)
Updatedfind-up@^3.0.0
Updatedload-json-file@^5.2.0