-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config): pass options to cosmiconfig according to 5.x.x API (#100)
**What**: I've updated babel-plugin-macros' usage of cosmiconfig to use the 5.x.x API. **Why**: This project's dependency on cosmiconfig was updated from 4.x.x to 5.x.x, but without changing the calls to cosmiconfig. Thus, the configuration override was no longer being read (packageProp was not overridden, thus using `babelMacros` in package.json no longer worked). The tests still passed as they only checked `babel-plugin-macros.config.js`, which was read by default by cosmiconfig: https://github.com/davidtheclark/cosmiconfig#searchplaces
- Loading branch information
Showing
3 changed files
with
22 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,14 +223,20 @@ function getConfig(macro, filename, source) { | |
// FWIW, this thing told me that cosmiconfig is 227.1 kb of minified JS | ||
// so that's probably significant... https://bundlephobia.com/[email protected] | ||
// Note that cosmiconfig will cache the babel-plugin-macros config 👍 | ||
const explorer = require('cosmiconfig')('babel-plugin-macros') | ||
const loaded = explorer.searchSync(filename, { | ||
const explorer = require('cosmiconfig')('babel-plugin-macros', { | ||
searchPlaces: [ | ||
'package.json', | ||
`.babel-plugin-macrosrc`, | ||
`.babel-plugin-macrosrc.json`, | ||
`.babel-plugin-macrosrc.yaml`, | ||
`.babel-plugin-macrosrc.yml`, | ||
`.babel-plugin-macrosrc.js`, | ||
`babel-plugin-macros.config.js`, | ||
], | ||
packageProp: 'babelMacros', | ||
rc: '.babel-plugin-macrosrc', | ||
js: 'babel-plugin-macros.config.js', | ||
rcExtensions: true, | ||
sync: true, | ||
}) | ||
const loaded = explorer.searchSync(filename) | ||
if (loaded) { | ||
return loaded.config[macro.options.configName] | ||
} | ||
|