-
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support setting flags globally and locally using
cosmiconfig
(#354)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
- Loading branch information
1 parent
c7d4cd0
commit 9dac7aa
Showing
4 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
const os = require('os'); | ||
const isInstalledGlobally = require('is-installed-globally'); | ||
const pkgDir = require('pkg-dir'); | ||
const cosmiconfig = require('cosmiconfig'); | ||
|
||
module.exports = async () => { | ||
const searchDir = isInstalledGlobally ? os.homedir() : await pkgDir(); | ||
const searchPlaces = ['.np-config.json', '.np-config.js']; | ||
if (!isInstalledGlobally) { | ||
searchPlaces.push('package.json'); | ||
} | ||
|
||
const explorer = cosmiconfig('np', { | ||
searchPlaces, | ||
stopDir: searchDir | ||
}); | ||
const {config} = (await explorer.search(searchDir)) || {}; | ||
|
||
return config; | ||
}; |