Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow macros to end in .cjs #161

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions other/docs/author.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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