Comparing version 2.0.0 to 2.1.0
@@ -60,16 +60,16 @@ "use strict"; | ||
recusivelyResolve(files, cwd, stopDir) { | ||
recusivelyResolve(options) { | ||
var _this = this; | ||
return _asyncToGenerator(function* () { | ||
if (cwd === stopDir || _path.default.basename(cwd) === 'node_modules') { | ||
if (options.cwd === options.stopDir || _path.default.basename(options.cwd) === 'node_modules') { | ||
return null; | ||
} | ||
for (const filename of files) { | ||
const file = _path.default.resolve(cwd, filename); | ||
for (const filename of options.files) { | ||
const file = _path.default.resolve(options.cwd, filename); | ||
let exists = process.env.NODE_ENV !== 'test' && _this.existsCache.has(file) ? _this.existsCache.get(file) : yield pathExists(file); | ||
if (exists && _this.options.packageKey && _path.default.basename(file) === 'package.json') { | ||
if (exists && options.packageKey && _path.default.basename(file) === 'package.json') { | ||
const data = require(file); | ||
@@ -81,3 +81,3 @@ | ||
exists = Object.prototype.hasOwnProperty.call(data, _this.options.packageKey); | ||
exists = Object.prototype.hasOwnProperty.call(data, options.packageKey); | ||
} else { | ||
@@ -94,17 +94,19 @@ _this.packageJsonCache.delete(file); | ||
return _this.recusivelyResolve(files, _path.default.dirname(cwd), stopDir); | ||
return _this.recusivelyResolve(Object.assign({}, options, { | ||
cwd: _path.default.dirname(options.cwd) | ||
})); | ||
})(); | ||
} | ||
recusivelyResolveSync(files, cwd, stopDir) { | ||
if (cwd === stopDir || _path.default.basename(cwd) === 'node_modules') { | ||
recusivelyResolveSync(options) { | ||
if (options.cwd === options.stopDir || _path.default.basename(options.cwd) === 'node_modules') { | ||
return null; | ||
} | ||
for (const filename of files) { | ||
const file = _path.default.resolve(cwd, filename); | ||
for (const filename of options.files) { | ||
const file = _path.default.resolve(options.cwd, filename); | ||
let exists = process.env.NODE_ENV !== 'test' && this.existsCache.has(file) ? this.existsCache.get(file) : pathExistsSync(file); | ||
if (exists && this.options.packageKey && _path.default.basename(file) === 'package.json') { | ||
if (exists && options.packageKey && _path.default.basename(file) === 'package.json') { | ||
const data = require(file); | ||
@@ -114,3 +116,3 @@ | ||
this.packageJsonCache.set(file, data); | ||
exists = Object.prototype.hasOwnProperty.call(data, this.options.packageKey); | ||
exists = Object.prototype.hasOwnProperty.call(data, options.packageKey); | ||
} else { | ||
@@ -127,38 +129,74 @@ this.packageJsonCache.delete(file); | ||
return this.recusivelyResolveSync(files, _path.default.dirname(cwd), stopDir); | ||
return this.recusivelyResolveSync(Object.assign({}, options, { | ||
cwd: _path.default.dirname(options.cwd) | ||
})); | ||
} | ||
resolve(files, cwd, stopDir) { | ||
resolve(...args) { | ||
var _this2 = this; | ||
return _asyncToGenerator(function* () { | ||
files = files || _this2.options.files; | ||
cwd = _path.default.resolve(cwd || _this2.options.cwd); | ||
stopDir = _path.default.resolve(stopDir || _this2.options.stopDir || _path.default.parse(cwd).root); | ||
const options = Object.assign({}, _this2.options); | ||
if (!files || files.length === 0) { | ||
if (Object.prototype.toString.call(args[0]) === '[object Object]') { | ||
Object.assign(options, args[0]); | ||
} else { | ||
if (args[0]) { | ||
options.files = args[0]; | ||
} | ||
if (args[1]) { | ||
options.cwd = args[1]; | ||
} | ||
if (args[2]) { | ||
options.stopDir = args[2]; | ||
} | ||
} | ||
options.cwd = _path.default.resolve(options.cwd); | ||
options.stopDir = options.stopDir ? _path.default.resolve(options.stopDir) : _path.default.parse(options.cwd).root; | ||
if (!options.files || options.files.length === 0) { | ||
throw new Error('files must be an non-empty array!'); | ||
} | ||
return _this2.recusivelyResolve(files, cwd, stopDir); | ||
return _this2.recusivelyResolve(options); | ||
})(); | ||
} | ||
resolveSync(files, cwd, stopDir) { | ||
files = files || this.options.files; | ||
cwd = _path.default.resolve(cwd || this.options.cwd); | ||
stopDir = _path.default.resolve(stopDir || this.options.stopDir || _path.default.parse(cwd).root); | ||
resolveSync(...args) { | ||
const options = Object.assign({}, this.options); | ||
if (!files || files.length === 0) { | ||
if (Object.prototype.toString.call(args[0]) === '[object Object]') { | ||
Object.assign(options, args[0]); | ||
} else { | ||
if (args[0]) { | ||
options.files = args[0]; | ||
} | ||
if (args[1]) { | ||
options.cwd = args[1]; | ||
} | ||
if (args[2]) { | ||
options.stopDir = args[2]; | ||
} | ||
} | ||
options.cwd = _path.default.resolve(options.cwd); | ||
options.stopDir = options.stopDir ? _path.default.resolve(options.stopDir) : _path.default.parse(options.cwd).root; | ||
if (!options.files || options.files.length === 0) { | ||
throw new Error('files must be an non-empty array!'); | ||
} | ||
return this.recusivelyResolveSync(files, cwd, stopDir); | ||
return this.recusivelyResolveSync(options); | ||
} | ||
load(files, cwd, stopDir) { | ||
load(...args) { | ||
var _this3 = this; | ||
return _asyncToGenerator(function* () { | ||
const filepath = yield _this3.resolve(files, cwd, stopDir); | ||
const filepath = yield _this3.resolve(...args); | ||
@@ -210,4 +248,4 @@ if (filepath) { | ||
loadSync(files, cwd, stopDir) { | ||
const filepath = this.resolveSync(files, cwd, stopDir); | ||
loadSync(...args) { | ||
const filepath = this.resolveSync(...args); | ||
@@ -214,0 +252,0 @@ if (filepath) { |
{ | ||
"name": "joycon", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Load config with ease.", | ||
@@ -5,0 +5,0 @@ "repository": { |
# joycon | ||
[![NPM version](https://img.shields.io/npm/v/joycon.svg?style=flat)](https://npmjs.com/package/joycon) [![NPM downloads](https://img.shields.io/npm/dm/joycon.svg?style=flat)](https://npmjs.com/package/joycon) [![CircleCI](https://circleci.com/gh/egoist/joycon/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/joycon/tree/master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate) [![chat](https://img.shields.io/badge/chat-on%20discord-7289DA.svg?style=flat)](https://chat.egoist.moe) | ||
[![NPM version](https://img.shields.io/npm/v/joycon.svg?style=flat)](https://npmjs.com/package/joycon) [![NPM downloads](https://img.shields.io/npm/dm/joycon.svg?style=flat)](https://npmjs.com/package/joycon) [![install size](https://packagephobia.now.sh/badge?p=joycon@2.0.0)](https://packagephobia.now.sh/result?p=joycon@2.0.0) [![CircleCI](https://circleci.com/gh/egoist/joycon/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/joycon/tree/master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate) [![chat](https://img.shields.io/badge/chat-on%20discord-7289DA.svg?style=flat)](https://chat.egoist.moe) | ||
@@ -77,2 +77,3 @@ ## Differences with [cosmiconfig](https://github.com/davidtheclark/cosmiconfig)? | ||
### resolve([files], [cwd], [stopDir]) | ||
### resolve([options]) | ||
@@ -85,2 +86,4 @@ `files` defaults to `options.files`. | ||
If using a single object `options`, it will be the same as constructor options. | ||
Search files and resolve the path of the file we found. | ||
@@ -87,0 +90,0 @@ |
@@ -40,7 +40,7 @@ export interface Options { | ||
resolve(files?: string[], cwd?: string, stopDir?: string): Promise<string | null> | ||
resolveSync(files?: string[], cwd?: string, stopDir?: string): string | null | ||
resolve(files?: string[] | Options, cwd?: string, stopDir?: string): Promise<string | null> | ||
resolveSync(files?: string[] | Options, cwd?: string, stopDir?: string): string | null | ||
load(files?: string[], cwd?: string, stopDir?: string): Promise<LoadResult> | ||
loadSync(files?: string[], cwd?: string, stopDir?: string): LoadResult | ||
load(files?: string[] | Options, cwd?: string, stopDir?: string): Promise<LoadResult> | ||
loadSync(files?: string[] | Options, cwd?: string, stopDir?: string): LoadResult | ||
@@ -47,0 +47,0 @@ addLoader(loader: AsyncLoader | SyncLoader | MultiLoader): this |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14589
278
129