kentcdodds / babel-plugin-macros

🎣 Allows you to build simple compile-time libraries
https://npm.im/babel-plugin-macros
MIT License
2.62k stars 135 forks source link

Allow macros to end in .cjs #161

Closed conartist6 closed 3 years ago

conartist6 commented 3 years ago

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[bot] commented 3 years ago

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 commented 3 years ago

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

conartist6 commented 3 years ago

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

conartist6 commented 3 years ago

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') }],
  ],
}
kentcdodds commented 3 years ago

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

allcontributors[bot] commented 3 years ago

@kentcdodds

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

kentcdodds commented 3 years ago

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 commented 3 years ago

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[bot] commented 3 years ago

:tada: This PR is included in version 3.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: