Skip to content

Commit 9edac40

Browse files
lPadierKent C. Dodds
authored and
Kent C. Dodds
committed
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
1 parent 7ad592c commit 9edac40

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

.all-contributorsrc

+9
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@
150150
"contributions": [
151151
"doc"
152152
]
153+
},
154+
{
155+
"login": "lPadier",
156+
"name": "Loïc Padier",
157+
"avatar_url": "https://avatars2.githubusercontent.com/u/4009640?v=4",
158+
"profile": "http://loicpadier.com",
159+
"contributions": [
160+
"code"
161+
]
153162
}
154163
]
155164
}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Enables zero-config, importable babel plugins
1313
[![downloads][downloads-badge]][npmchart]
1414
[![MIT License][license-badge]][license]
1515

16-
[![All Contributors](https://img.shields.io/badge/all_contributors-15-orange.svg?style=flat-square)](#contributors)
16+
[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors)
1717
[![PRs Welcome][prs-badge]][prs]
1818
[![Donate][donate-badge]][donate]
1919
[![Code of Conduct][coc-badge]][coc]
@@ -347,7 +347,7 @@ Thanks goes to these people ([emoji key][emojis]):
347347
| [<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") |
348348
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
349349
| [<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") |
350-
| [<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") |
350+
| [<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") |
351351
<!-- ALL-CONTRIBUTORS-LIST:END -->
352352

353353
This project follows the [all-contributors][all-contributors] specification.

src/index.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,20 @@ function getConfig(macro, filename, source) {
223223
// FWIW, this thing told me that cosmiconfig is 227.1 kb of minified JS
224224
// so that's probably significant... https://bundlephobia.com/[email protected]
225225
// Note that cosmiconfig will cache the babel-plugin-macros config 👍
226-
const explorer = require('cosmiconfig')('babel-plugin-macros')
227-
const loaded = explorer.searchSync(filename, {
226+
const explorer = require('cosmiconfig')('babel-plugin-macros', {
227+
searchPlaces: [
228+
'package.json',
229+
`.babel-plugin-macrosrc`,
230+
`.babel-plugin-macrosrc.json`,
231+
`.babel-plugin-macrosrc.yaml`,
232+
`.babel-plugin-macrosrc.yml`,
233+
`.babel-plugin-macrosrc.js`,
234+
`babel-plugin-macros.config.js`,
235+
],
228236
packageProp: 'babelMacros',
229-
rc: '.babel-plugin-macrosrc',
230-
js: 'babel-plugin-macros.config.js',
231-
rcExtensions: true,
232237
sync: true,
233238
})
239+
const loaded = explorer.searchSync(filename)
234240
if (loaded) {
235241
return loaded.config[macro.options.configName]
236242
}

0 commit comments

Comments
 (0)