From 9edac400c6dfb3f87c8e62a5c067a11d356b7679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Padier?= Date: Mon, 7 Jan 2019 18:56:37 +0100 Subject: [PATCH] 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 --- .all-contributorsrc | 9 +++++++++ README.md | 4 ++-- src/index.js | 16 +++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index a09169f..9cf668d 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -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" + ] } ] } diff --git a/README.md b/README.md index 60feb5b..180bec5 100644 --- a/README.md +++ b/README.md @@ -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] @@ -347,7 +347,7 @@ Thanks goes to these people ([emoji key][emojis]): | [
Kent C. Dodds](https://kentcdodds.com)
[πŸ’»](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") | [
Sunil Pai](https://github.com/threepointone)
[πŸ€”](#ideas-threepointone "Ideas, Planning, & Feedback") | [
Stephen Scott](http://suchipi.com/)
[πŸ’¬](#question-suchipi "Answering Questions") [πŸ“–](https://github.com/kentcdodds/babel-plugin-macros/commits?author=suchipi "Documentation") | [
Michiel Dral](http://twitter.com/dralletje)
[πŸ€”](#ideas-dralletje "Ideas, Planning, & Feedback") | [
Kye Hohenberger](https://github.com/tkh44)
[πŸ€”](#ideas-tkh44 "Ideas, Planning, & Feedback") | [
Mitchell Hamilton](https://hamil.town)
[πŸ’»](https://github.com/kentcdodds/babel-plugin-macros/commits?author=mitchellhamilton "Code") [⚠️](https://github.com/kentcdodds/babel-plugin-macros/commits?author=mitchellhamilton "Tests") | [
Justin Hall](https://github.com/wKovacs64)
[πŸ“–](https://github.com/kentcdodds/babel-plugin-macros/commits?author=wKovacs64 "Documentation") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | [
Brian Pedersen](https://github.com/PiereDome)
[πŸ’»](https://github.com/kentcdodds/babel-plugin-macros/commits?author=PiereDome "Code") [πŸ“–](https://github.com/kentcdodds/babel-plugin-macros/commits?author=PiereDome "Documentation") | [
Andrew Palm](https://github.com/apalm)
[πŸ’»](https://github.com/kentcdodds/babel-plugin-macros/commits?author=apalm "Code") | [
Michael Hsu](https://michaelhsu.tw/)
[πŸ“–](https://github.com/kentcdodds/babel-plugin-macros/commits?author=evenchange4 "Documentation") [πŸ”Œ](#plugin-evenchange4 "Plugin/utility libraries") | [
Bo Lingen](https://github.com/citycide)
[πŸ’»](https://github.com/kentcdodds/babel-plugin-macros/commits?author=citycide "Code") | [
Tyler Haas](https://github.com/tylerthehaas)
[πŸ“–](https://github.com/kentcdodds/babel-plugin-macros/commits?author=tylerthehaas "Documentation") | [
FWeinb](https://github.com/FWeinb)
[πŸ’»](https://github.com/kentcdodds/babel-plugin-macros/commits?author=FWeinb "Code") | [
TomΓ‘Ε‘ Ehrlich](http://www.tomasehrlich.cz)
[πŸ›](https://github.com/kentcdodds/babel-plugin-macros/issues?q=author%3Atricoder42 "Bug reports") [πŸ’»](https://github.com/kentcdodds/babel-plugin-macros/commits?author=tricoder42 "Code") | -| [
Jonas Gierer](https://github.com/jgierer12)
[πŸ“–](https://github.com/kentcdodds/babel-plugin-macros/commits?author=jgierer12 "Documentation") | +| [
Jonas Gierer](https://github.com/jgierer12)
[πŸ“–](https://github.com/kentcdodds/babel-plugin-macros/commits?author=jgierer12 "Documentation") | [
LoΓ―c Padier](http://loicpadier.com)
[πŸ’»](https://github.com/kentcdodds/babel-plugin-macros/commits?author=lPadier "Code") | This project follows the [all-contributors][all-contributors] specification. diff --git a/src/index.js b/src/index.js index 684febb..78c3140 100644 --- a/src/index.js +++ b/src/index.js @@ -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] }