Skip to content

Commit

Permalink
fix(config): pass options to cosmiconfig according to 5.x.x API (#100)
Browse files Browse the repository at this point in the history
**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
lPadier authored and Kent C. Dodds committed Jan 7, 2019
1 parent 7ad592c commit 9edac40
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Expand Up @@ -150,6 +150,15 @@
"contributions": [
"doc"
]
},
{
"login": "lPadier",
"name": "Lo茂c Padier",
"avatar_url": "https://avatars2.githubusercontent.com/u/4009640?v=4",
"profile": "http://loicpadier.com",
"contributions": [
"code"
]
}
]
}
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -13,7 +13,7 @@ Enables zero-config, importable babel plugins
[![downloads][downloads-badge]][npmchart]
[![MIT License][license-badge]][license]

[![All Contributors](https://img.shields.io/badge/all_contributors-15-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Donate][donate-badge]][donate]
[![Code of Conduct][coc-badge]][coc]
Expand Down Expand Up @@ -347,7 +347,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[馃捇](https://github.com/kentcdodds/babel-plugin-macros/commits?author=kentcdodds "Code") [馃摉](https://github.com/kentcdodds/babel-plugin-macros/commits?author=kentcdodds "Documentation") [馃殗](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [鈿狅笍](https://github.com/kentcdodds/babel-plugin-macros/commits?author=kentcdodds "Tests") | [<img src="https://avatars1.githubusercontent.com/u/18808?v=3" width="100px;"/><br /><sub><b>Sunil Pai</b></sub>](https://github.com/threepointone)<br />[馃](#ideas-threepointone "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/1341513?v=3" width="100px;"/><br /><sub><b>Stephen Scott</b></sub>](http://suchipi.com/)<br />[馃挰](#question-suchipi "Answering Questions") [馃摉](https://github.com/kentcdodds/babel-plugin-macros/commits?author=suchipi "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/767261?v=4" width="100px;"/><br /><sub><b>Michiel Dral</b></sub>](http://twitter.com/dralletje)<br />[馃](#ideas-dralletje "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/662750?v=4" width="100px;"/><br /><sub><b>Kye Hohenberger</b></sub>](https://github.com/tkh44)<br />[馃](#ideas-tkh44 "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/11481355?v=4" width="100px;"/><br /><sub><b>Mitchell Hamilton</b></sub>](https://hamil.town)<br />[馃捇](https://github.com/kentcdodds/babel-plugin-macros/commits?author=mitchellhamilton "Code") [鈿狅笍](https://github.com/kentcdodds/babel-plugin-macros/commits?author=mitchellhamilton "Tests") | [<img src="https://avatars1.githubusercontent.com/u/1288694?v=4" width="100px;"/><br /><sub><b>Justin Hall</b></sub>](https://github.com/wKovacs64)<br />[馃摉](https://github.com/kentcdodds/babel-plugin-macros/commits?author=wKovacs64 "Documentation") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars3.githubusercontent.com/u/1903016?v=4" width="100px;"/><br /><sub><b>Brian Pedersen</b></sub>](https://github.com/PiereDome)<br />[馃捇](https://github.com/kentcdodds/babel-plugin-macros/commits?author=PiereDome "Code") [馃摉](https://github.com/kentcdodds/babel-plugin-macros/commits?author=PiereDome "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/4495237?v=4" width="100px;"/><br /><sub><b>Andrew Palm</b></sub>](https://github.com/apalm)<br />[馃捇](https://github.com/kentcdodds/babel-plugin-macros/commits?author=apalm "Code") | [<img src="https://avatars1.githubusercontent.com/u/1527371?v=4" width="100px;"/><br /><sub><b>Michael Hsu</b></sub>](https://michaelhsu.tw/)<br />[馃摉](https://github.com/kentcdodds/babel-plugin-macros/commits?author=evenchange4 "Documentation") [馃攲](#plugin-evenchange4 "Plugin/utility libraries") | [<img src="https://avatars2.githubusercontent.com/u/16605186?v=4" width="100px;"/><br /><sub><b>Bo Lingen</b></sub>](https://github.com/citycide)<br />[馃捇](https://github.com/kentcdodds/babel-plugin-macros/commits?author=citycide "Code") | [<img src="https://avatars1.githubusercontent.com/u/11150235?v=4" width="100px;"/><br /><sub><b>Tyler Haas</b></sub>](https://github.com/tylerthehaas)<br />[馃摉](https://github.com/kentcdodds/babel-plugin-macros/commits?author=tylerthehaas "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/1250430?v=4" width="100px;"/><br /><sub><b>FWeinb</b></sub>](https://github.com/FWeinb)<br />[馃捇](https://github.com/kentcdodds/babel-plugin-macros/commits?author=FWeinb "Code") | [<img src="https://avatars2.githubusercontent.com/u/827862?v=4" width="100px;"/><br /><sub><b>Tom谩拧 Ehrlich</b></sub>](http://www.tomasehrlich.cz)<br />[馃悰](https://github.com/kentcdodds/babel-plugin-macros/issues?q=author%3Atricoder42 "Bug reports") [馃捇](https://github.com/kentcdodds/babel-plugin-macros/commits?author=tricoder42 "Code") |
| [<img src="https://avatars0.githubusercontent.com/u/4331946?v=4" width="100px;"/><br /><sub><b>Jonas Gierer</b></sub>](https://github.com/jgierer12)<br />[馃摉](https://github.com/kentcdodds/babel-plugin-macros/commits?author=jgierer12 "Documentation") |
| [<img src="https://avatars0.githubusercontent.com/u/4331946?v=4" width="100px;"/><br /><sub><b>Jonas Gierer</b></sub>](https://github.com/jgierer12)<br />[馃摉](https://github.com/kentcdodds/babel-plugin-macros/commits?author=jgierer12 "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/4009640?v=4" width="100px;"/><br /><sub><b>Lo茂c Padier</b></sub>](http://loicpadier.com)<br />[馃捇](https://github.com/kentcdodds/babel-plugin-macros/commits?author=lPadier "Code") |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors][all-contributors] specification.
Expand Down
16 changes: 11 additions & 5 deletions src/index.js
Expand Up @@ -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/result?p=cosmiconfig@3.1.0
// 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]
}
Expand Down

0 comments on commit 9edac40

Please sign in to comment.