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

feat(extractor): expose extractFromFileWithBabel function for better flexibility #1719

Merged

Conversation

timofei-iatsenko
Copy link
Collaborator

@timofei-iatsenko timofei-iatsenko commented Jun 28, 2023

Description

This PR brings improvement for those who wants more flexibility in what files extractor could understand. It's covering #1717

When user has a Ecmascript feature which is not enabled in the parser by default there is only thing it could do about it override extractor completely and pass all needed plugins manually. This is not future-proof solution, as user have to copy-paste lingui's default implementation and adjust it by its needs.

Solution: I extracted from the default implementation a low level function extractFromFileWithBabel which is now a part of a public api and could be used in the userland. I choosed this approach among others, because parserPlugins is not a static list and could vary depending on a file passed for extractor. So this would give to users enough flexibility to express any required logic.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Fixes # (issue)

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@vercel
Copy link

vercel bot commented Jun 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
js-lingui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 28, 2023 11:45am

@github-actions
Copy link

size-limit report 📦

Path Size
./packages/core/dist/index.mjs 2.76 KB (0%)
./packages/detect-locale/dist/index.mjs 721 B (0%)
./packages/react/dist/index.mjs 1.59 KB (0%)
./packages/remote-loader/dist/index.mjs 7.24 KB (0%)

@codecov
Copy link

codecov bot commented Jun 28, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.08 🎉

Comparison is base (dc82882) 76.01% compared to head (d5f06c8) 76.09%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1719      +/-   ##
==========================================
+ Coverage   76.01%   76.09%   +0.08%     
==========================================
  Files          79       79              
  Lines        2039     2046       +7     
  Branches      524      524              
==========================================
+ Hits         1550     1557       +7     
  Misses        376      376              
  Partials      113      113              
Impacted Files Coverage Δ
packages/cli/src/api/extractors/babel.ts 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@andrii-bodnar
Copy link
Contributor

Thanks @thekip! What do you think about adding this to the documentation? However, I have doubts about where exactly it can be added. Maybe Lingui Configuration?

@andrii-bodnar andrii-bodnar linked an issue Jun 29, 2023 that may be closed by this pull request
@andrii-bodnar andrii-bodnar merged commit 43486dc into lingui:main Jun 29, 2023
@timofei-iatsenko timofei-iatsenko deleted the expose-extract-with-babel-fn branch June 29, 2023 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experimental Syntax 'importAttributes' Not Enabled
2 participants