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(vite-plugin): add error handling for dynamic import of @lingui/macro #2056

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maastrich
Copy link

Description

Make sure the user understands why @lingui/macro is not handled by babel/swc when dynamically imported.

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
  • Examples update

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 the necessary documentation (if appropriate)

…acro

This commit adds error handling for dynamically importing the @lingui/macro module in the vite-plugin. When the @lingui/macro module is dynamically imported, an error is thrown with a helpful message guiding the user to check their import statement and providing a link to the documentation for configuring Vite with Lingui correctly.

Closes lingui#2050
Copy link

vercel bot commented Oct 18, 2024

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

Name Status Preview Updated (UTC)
js-lingui ✅ Ready (Inspect) Visit Preview Oct 18, 2024 8:45am

Copy link

size-limit report 📦

Path Size
./packages/core/dist/index.mjs 2.88 KB (0%)
./packages/detect-locale/dist/index.mjs 723 B (0%)
./packages/react/dist/index.mjs 1.68 KB (0%)
./packages/remote-loader/dist/index.mjs 7.26 KB (0%)

@timofei-iatsenko
Copy link
Collaborator

LGTM, thanks for contribution

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 75.45%. Comparing base (d6b9698) to head (5f31983).
Report is 70 commits behind head on main.

Files with missing lines Patch % Lines
packages/vite-plugin/src/index.ts 0.00% 2 Missing ⚠️
...ite-plugin/test/dynamic-macro-error/vite.config.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2056      +/-   ##
==========================================
- Coverage   76.65%   75.45%   -1.20%     
==========================================
  Files          81       89       +8     
  Lines        2090     2176      +86     
  Branches      533      552      +19     
==========================================
+ Hits         1602     1642      +40     
- Misses        375      423      +48     
+ Partials      113      111       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@timofei-iatsenko
Copy link
Collaborator

@maastrich are you going to add something to this PR or you finished? We are preparing v5 release and it would be better to switch it to the next branch.

@andrii-bodnar
Copy link
Contributor

Hi @maastrich, is there anything we can do to move this PR forward?

@@ -33,6 +33,16 @@ export function lingui(linguiConfig: LinguiConfigOpts = {}): Plugin[] {
)
}
},
resolveDynamicImport(specifier, importer, options) {
if (specifier === "@lingui/macro") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

in v5 it should check for @lingui/macro and @lingui/react/macro and @lingui/core/macro

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.

3 participants