Skip to content

Commit

Permalink
feat: allow macros to end in .cjs (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
conartist6 committed Nov 25, 2020
1 parent 3263dbe commit 0c63f6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions other/docs/author.md
Expand Up @@ -56,15 +56,17 @@ There are two parts to the `babel-plugin-macros` API:

The way that `babel-plugin-macros` determines whether to run a macro is based on
the source string of the `import` or `require` statement. It must match this
regex: `/[./]macro(\.js)?$/` for example:
regex: `/[./]macro(\.c?js)?$/` for example:

_matches_:

```
'my.macro'
'my.macro.js'
'my.macro.cjs'
'my/macro'
'my/macro.js'
'my/macro.cjs'
```

_does not match_:
Expand Down Expand Up @@ -305,8 +307,8 @@ Contributions to improve this experience are definitely welcome!

## Async logic

Unfortunately, babel plugins are synchronous so you can't do anything asynchronous
with `babel-plugin-macros`. However, you can cheat a bit by running
Unfortunately, babel plugins are synchronous so you can't do anything
asynchronous with `babel-plugin-macros`. However, you can cheat a bit by running
`child_process`'s `spawnSync` to synchronously execute a file. It's definitely a
hack and is not great for performance, but in most cases it's fast enough鈩笍.

Expand Down
4 changes: 2 additions & 2 deletions src/index.js
@@ -1,9 +1,9 @@
const p = require('path')
const resolve = require('resolve')
const traverse = require("@babel/traverse").default
const traverse = require('@babel/traverse').default
// const printAST = require('ast-pretty-print')

const macrosRegex = /[./]macro(\.js)?$/
const macrosRegex = /[./]macro(\.c?js)?$/
const testMacrosRegex = v => macrosRegex.test(v)

// https://stackoverflow.com/a/32749533/971592
Expand Down

0 comments on commit 0c63f6f

Please sign in to comment.