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

Conversation

conartist6
Copy link
Collaborator

@conartist6 conartist6 commented Nov 25, 2020

When a macro is defined in a package with "type": "module" set in package.json, babel-plugin-macros uses require to load it. This fails because require is not allowed on an es module (which the macro is now assumed to be). The answer for the moment is for the macro not to be a module, which requires that its extension be macro.cjs and that it be imported with an explicit extension. This change ensures that that is possible.

@codecov
Copy link

codecov bot commented Nov 25, 2020

Codecov Report

Merging #161 (a3883f8) into master (1303686) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #161   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           97        98    +1     
  Branches        22        22           
=========================================
+ Hits            97        98    +1     
Impacted Files Coverage Δ
src/index.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3263dbe...a3883f8. Read the comment docs.

@conartist6
Copy link
Collaborator Author

Hmm, there might be some problems with how references are determined too. Investigating further.

@conartist6
Copy link
Collaborator Author

conartist6 commented Nov 25, 2020

Ah ok no this error I'm seeing is a problem of my own making (not a bug).

@conartist6
Copy link
Collaborator Author

conartist6 commented Nov 25, 2020

By the way if anyone finds this and needs the workaround it's simple enough. Just add a bit to your babel config:

{
  plugins: [
    ['macros', { isMacrosName: (v) => v.endsWith('.macro.cjs') }],
  ],
}

Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super 👍 Thanks!

@kentcdodds kentcdodds merged commit 0c63f6f into kentcdodds:master Nov 25, 2020
@kentcdodds
Copy link
Owner

@all-contributors please add @conartist6 for code and docs

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @conartist6! 🎉

@kentcdodds
Copy link
Owner

Thanks so much for your help! I've added you as a collaborator on the project. Please make sure that you review the other/MAINTAINING.md and CONTRIBUTING.md files (specifically the bit about the commit messages and the git hooks) and familiarize yourself with the code of conduct (we're using the contributor covenant). You might also want to watch the repo to be notified when someone files an issue/PR. Please continue to make PRs as you feel the need (you can make your branches directly on the repo rather than your fork if you want). Thanks! And welcome to the team :)

@conartist6 conartist6 deleted the cjs-macros branch November 25, 2020 17:57
@conartist6
Copy link
Collaborator Author

Thanks! As you suggested I read those and watched the repo. I love makeapullrequest.com and the explicit goal of inclusivity and growing the community of contributors and maintainers.

@github-actions
Copy link

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants