Skip to content

Commit

Permalink
fix: upgrade to babel-plugin-macros and add keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed Jan 18, 2018
1 parent 1eb6e01 commit ba2e5ab
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 50 deletions.
11 changes: 3 additions & 8 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ never done that before, that's great! Check this free short video tutorial to
learn how: http://kcd.im/pull-request
-->

- `import-all.macro` version:
- `node` version:
- `npm` (or `yarn`) version:
* `import-all.macro` version:
* `node` version:
* `npm` (or `yarn`) version:

Relevant code or config

```javascript

```

What you did:



What happened:

<!-- Please provide the full error message/screenshots/anything -->
Expand All @@ -38,6 +35,4 @@ minimal amount of code possible.

Problem description:



Suggested solution:
15 changes: 11 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,28 @@ merge of your pull request!
-->

<!-- What changes are being made? (What feature/bug is being fixed here?) -->

**What**:

<!-- Why are these changes necessary? -->

**Why**:

<!-- How were these changes implemented? -->

**How**:

<!-- Have you done all of these things? -->

**Checklist**:

<!-- add "N/A" to the end of each line that's irrelevant to your changes -->

<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->
- [ ] Documentation
- [ ] Tests
- [ ] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
- [ ] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions -->

* [ ] Documentation
* [ ] Tests
* [ ] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
* [ ] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions -->

<!-- feel free to add additional comments -->
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
sudo: false
language: node_js
cache:
directories:
- ~/.npm
notifications:
email: false
node_js: '8'
install: npm install
script: npm run validate
after_success:
- npx codecov
- npx -p semantic-release@8 -c "semantic-release pre && npm publish && semantic-release post"
after_success: kcd-scripts travis-after-success
branches:
only: master
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Thanks for being willing to contribute!

**Working on your first Pull Request?** You can learn how from this *free* series
**Working on your first Pull Request?** You can learn how from this _free_ series
[How to Contribute to an Open Source Project on GitHub][egghead]

## Project setup
Expand Down
42 changes: 31 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->

<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

* [import-all.macro](#import-allmacro)
* [The problem](#the-problem)
* [This solution](#this-solution)
* [Installation](#installation)
* [Usage](#usage)
* [Caveats](#caveats)
* [Inspiration](#inspiration)
* [Other Solutions](#other-solutions)
* [Contributors](#contributors)
* [LICENSE](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

<div align="center">
<h1>import-all.macro</h1>

Expand All @@ -10,19 +27,17 @@
[![Code Coverage][coverage-badge]][coverage]
[![version][version-badge]][package]
[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][LICENSE]
[![MIT License][license-badge]][license]

[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Code of Conduct][coc-badge]][coc]
[![Babel Macro][macros-badge]][babel-macros]
[![Babel Macro][macros-badge]][babel-plugin-macros]

[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
[![Tweet][twitter-badge]][twitter]

<a href="https://app.codesponsor.io/link/PKGFLnhDiFvsUA5P4kAXfiPs/kentcdodds/import-all.macro" rel="nofollow"><img src="https://app.codesponsor.io/embed/PKGFLnhDiFvsUA5P4kAXfiPs/kentcdodds/import-all.macro.svg" style="width: 888px; height: 68px;" alt="Sponsor" /></a>

## The problem

You want to import all files that match a `glob` without having to import them
Expand All @@ -46,7 +61,7 @@ npm install --save-dev import-all.macro

## Usage

Once you've [configured `babel-macros`][https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md] you can
Once you've [configured `babel-plugin-macros`][https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md] you can
import/require `import-all.macro`.

The `importAll` functions accept a [`glob`][glob] and will transpile your code
Expand All @@ -58,10 +73,12 @@ Let's imagine you have a directory called `my-files` with the files
Here are a few before/after examples:

<!-- SNAP_TO_README:START -->

<!-- This section is generated by the other/snap-to-readme.js script. -->

<!-- Do not edit directly. -->

**`importAll` uses dynamic import**
**`importAll` uses dynamic import: README:1 `importAll` uses dynamic import**

```javascript
import importAll from 'import-all.macro'
Expand Down Expand Up @@ -95,7 +112,7 @@ document.getElementById('load-stuff').addEventListener('click', () => {
})
```

**`importAll.sync` uses static imports**
**`importAll.sync` uses static imports: README:2 `importAll.sync` uses static imports**

```javascript
import importAll from 'import-all.macro'
Expand All @@ -117,7 +134,7 @@ const a = {
}
```

**`importAll.deferred` gives an object with dynamic imports**
**`importAll.deferred` gives an object with dynamic imports: README:3 `importAll.deferred` gives an object with dynamic imports**

```javascript
import importAll from 'import-all.macro'
Expand Down Expand Up @@ -165,8 +182,11 @@ here!
Thanks goes to these people ([emoji key][emojis]):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds "Tests") | [<img src="https://avatars0.githubusercontent.com/u/188426?v=4" width="100px;"/><br /><sub>Jonathan Neal</sub>](http://jonathantneal.com)<br />[📖](https://github.com/kentcdodds/import-all.macro/commits?author=jonathantneal "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/6004414?v=4" width="100px;"/><br /><sub>Rafał Ruciński</sub>](https://fatfisz.com)<br />[🐛](https://github.com/kentcdodds/import-all.macro/issues?q=author%3Afatfisz "Bug reports") [💻](https://github.com/kentcdodds/import-all.macro/commits?author=fatfisz "Code") |

<!-- prettier-ignore -->
| [<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/import-all.macro/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/import-all.macro/commits?author=kentcdodds "Tests") | [<img src="https://avatars0.githubusercontent.com/u/188426?v=4" width="100px;"/><br /><sub><b>Jonathan Neal</b></sub>](http://jonathantneal.com)<br />[📖](https://github.com/kentcdodds/import-all.macro/commits?author=jonathantneal "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/6004414?v=4" width="100px;"/><br /><sub><b>Rafał Ruciński</b></sub>](https://fatfisz.com)<br />[🐛](https://github.com/kentcdodds/import-all.macro/issues?q=author%3Afatfisz "Bug reports") [💻](https://github.com/kentcdodds/import-all.macro/commits?author=fatfisz "Code") |
| :---: | :---: | :---: |

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors][all-contributors] specification.
Expand Down Expand Up @@ -194,7 +214,7 @@ MIT
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
[coc]: https://github.com/kentcdodds/import-all.macro/blob/master/other/CODE_OF_CONDUCT.md
[macros-badge]: https://img.shields.io/badge/babel--macro-%F0%9F%8E%A3-f5da55.svg?style=flat-square
[babel-macros]: https://github.com/kentcdodds/babel-macros
[babel-plugin-macros]: https://github.com/kentcdodds/babel-plugin-macros
[github-watch-badge]: https://img.shields.io/github/watchers/kentcdodds/import-all.macro.svg?style=social
[github-watch]: https://github.com/kentcdodds/import-all.macro/watchers
[github-star-badge]: https://img.shields.io/github/stars/kentcdodds/import-all.macro.svg?style=social
Expand All @@ -203,6 +223,6 @@ MIT
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/kentcdodds/import-all.macro.svg?style=social
[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key
[all-contributors]: https://github.com/kentcdodds/all-contributors
[babel-macros-user]: https://github.com/kentcdodds/babel-macros/blob/master/other/docs/user.md
[babel-plugin-macros-user]: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md
[glob]: https://www.npmjs.com/package/glob
[sunil-tweet]: https://twitter.com/threepointone/status/908290510225330176
2 changes: 1 addition & 1 deletion other/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include:
Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
Expand Down
6 changes: 3 additions & 3 deletions other/snap-to-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const readmePath = path.join(__dirname, '../README.md')
const readme = fs.readFileSync(readmePath, 'utf8')
const snaps = require('../src/__tests__/__snapshots__/macro.js.snap')

const snapNumberRegex = /^README:(\d+)/
const snapTitleRegex = /^README:\d+(.*) \d+$/
const snapNumberRegex = /^macros README:(\d+)/
const snapTitleRegex = /^macros README:\d+(.*) \d+$/
const readmeSnapRegex = /<!-- SNAP_TO_README:START -->[\s\S]*?<!-- SNAP_TO_README:END -->/
const snapsToUse = Object.keys(snaps)
.filter(name => name.startsWith('README'))
.filter(name => name.startsWith('macros README'))
.sort(
(nameA, nameB) =>
Number(nameA.match(snapNumberRegex)[1]) >
Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "import-all.macro",
"version": "0.0.0-semantically-released",
"description":
"A babel-macro that allows you to import all files that match a glob",
"A macro for babel-plugin-macros that allows you to import all files that match a glob",
"main": "dist/index.js",
"engines": {
"node": "> 4",
Expand All @@ -18,21 +18,24 @@
"precommit": "kcd-scripts precommit"
},
"files": ["dist"],
"keywords": [],
"keywords": ["babel-plugin-macros"],
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
"license": "MIT",
"dependencies": {
"babel-macros": "^1.2.0",
"babel-plugin-macros": "^2.0.0",
"glob": "^7.1.2"
},
"devDependencies": {
"ast-pretty-print": "^2.0.1",
"babel-plugin-tester": "^4.0.0",
"kcd-scripts": "^0.16.0",
"prettier": "^1.7.0"
"babel-plugin-tester": "^5.0.0",
"kcd-scripts": "^0.32.1",
"prettier": "^1.10.2"
},
"eslintConfig": {
"extends": "./node_modules/kcd-scripts/eslint.js"
"extends": "./node_modules/kcd-scripts/eslint.js",
"rules": {
"complexity": ["error", 12]
}
},
"eslintIgnore": ["node_modules", "coverage", "dist"],
"repository": {
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/__snapshots__/macro.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`README:1 \`importAll\` uses dynamic import 1`] = `
exports[`macros README:1 \`importAll\` uses dynamic import: README:1 \`importAll\` uses dynamic import 1`] = `
import importAll from 'import-all.macro'
Expand Down Expand Up @@ -35,7 +35,7 @@ document.getElementById('load-stuff').addEventListener('click', () => {
`;

exports[`README:2 \`importAll.sync\` uses static imports 1`] = `
exports[`macros README:2 \`importAll.sync\` uses static imports: README:2 \`importAll.sync\` uses static imports 1`] = `
import importAll from 'import-all.macro'
Expand All @@ -58,7 +58,7 @@ const a = {
`;

exports[`README:3 \`importAll.deferred\` gives an object with dynamic imports 1`] = `
exports[`macros README:3 \`importAll.deferred\` gives an object with dynamic imports: README:3 \`importAll.deferred\` gives an object with dynamic imports 1`] = `
import importAll from 'import-all.macro'
Expand All @@ -84,7 +84,7 @@ const routes = {
`;

exports[`incorrect API usage 1`] = `
exports[`macros incorrect API usage: incorrect API usage 1`] = `
import importAll from 'import-all.macro'
const x = importAll.defered('hi')
Expand All @@ -95,7 +95,7 @@ Error: <PROJECT_ROOT>/src/__tests__/macro.js: ../macro: This is not supported: \
`;
exports[`no usage 1`] = `
exports[`macros no usage: no usage 1`] = `
import importAll from 'import-all.macro'
Expand All @@ -105,7 +105,7 @@ import importAll from 'import-all.macro'
`;
exports[`non-static evaluate-able expression 1`] = `
exports[`macros non-static evaluate-able expression: non-static evaluate-able expression 1`] = `
import importAll from 'import-all.macro'
const x = importAll(global.whatever)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/macro.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'
import pluginTester from 'babel-plugin-tester'
import plugin from 'babel-macros'
import plugin from 'babel-plugin-macros'
import prettier from 'prettier'
import {prettier as prettierConfig} from 'kcd-scripts/config'

Expand Down
2 changes: 1 addition & 1 deletion src/macro.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
// const printAST = require('ast-pretty-print')
const {createMacro} = require('babel-macros')
const {createMacro} = require('babel-plugin-macros')
const glob = require('glob')

module.exports = createMacro(prevalMacros)
Expand Down

0 comments on commit ba2e5ab

Please sign in to comment.