-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add linguiMacroSwcPlugin() helper
#212
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5896227
feat: add linguiSwcOptions helper
mogelbrod e8ae611
add typescript, return the whole tuple of a configuration
timofei-iatsenko b6463c6
update readme and jsdoc
timofei-iatsenko fa90038
update test
timofei-iatsenko 38ae424
Merge branch 'main' into fork/mogelbrod/linguiSwcOptions
timofei-iatsenko 9d1048c
update readme
timofei-iatsenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ node_modules | |
| .yarn | ||
| .swc | ||
| .new | ||
| dist | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export default { | ||
| locales: ["en"], | ||
| sourceLocale: "en", | ||
| runtimeConfigModule: { | ||
| i18n: ["@custom/core", "customI18n"], | ||
| Trans: ["@custom/react", "CustomTrans"], | ||
| useLingui: ["@custom/react", "useCustomLingui"], | ||
| }, | ||
| macro: { | ||
| jsxPlaceholderAttribute: "data-i18n", | ||
| jsxPlaceholderDefaults: { | ||
| a: "anchor", | ||
| strong: "bold", | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export default { | ||
| locales: ["en"], | ||
| sourceLocale: "en", | ||
| runtimeConfigModule: { | ||
| i18n: ["@acme/core", "i18n"], | ||
| Trans: ["@acme/react", "Trans"], | ||
| useLingui: ["@acme/react", "useLingui"], | ||
| }, | ||
| macro: { | ||
| jsxPlaceholderAttribute: "_t", | ||
| jsxPlaceholderDefaults: { | ||
| a: "link", | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import {describe, expect, it} from "vitest" | ||
| import {resolve} from "node:path" | ||
|
|
||
| import {linguiMacroSwcPlugin} from "../src-js/options" | ||
|
|
||
| const fixturesDir = resolve(import.meta.dirname, "fixtures/lingui-options") | ||
|
|
||
| describe("linguiMacroSwcPlugin", () => { | ||
| it("discovers the default Lingui config from cwd", () => { | ||
| const previousCwd = process.cwd() | ||
|
|
||
| try { | ||
| process.chdir(fixturesDir) | ||
|
|
||
| expect(linguiMacroSwcPlugin()).toMatchInlineSnapshot(` | ||
| [ | ||
| "@lingui/swc-plugin", | ||
| { | ||
| "jsxPlaceholderAttribute": "_t", | ||
| "jsxPlaceholderDefaults": { | ||
| "a": "link", | ||
| }, | ||
| "runtimeModules": { | ||
| "i18n": [ | ||
| "@acme/core", | ||
| "i18n", | ||
| ], | ||
| "trans": [ | ||
| "@acme/react", | ||
| "Trans", | ||
| ], | ||
| "useLingui": [ | ||
| "@acme/react", | ||
| "useLingui", | ||
| ], | ||
| }, | ||
| }, | ||
| ] | ||
| `) | ||
| } finally { | ||
| process.chdir(previousCwd) | ||
| } | ||
| }) | ||
|
|
||
| it("maps shared options from an explicit config path", () => { | ||
| expect(linguiMacroSwcPlugin({}, {configPath: resolve(fixturesDir, "custom.config.js")})).toMatchInlineSnapshot( | ||
|
|
||
| ` | ||
| [ | ||
| "@lingui/swc-plugin", | ||
| { | ||
| "jsxPlaceholderAttribute": "data-i18n", | ||
| "jsxPlaceholderDefaults": { | ||
| "a": "anchor", | ||
| "strong": "bold", | ||
| }, | ||
| "runtimeModules": { | ||
| "i18n": [ | ||
| "@custom/core", | ||
| "customI18n", | ||
| ], | ||
| "trans": [ | ||
| "@custom/react", | ||
| "CustomTrans", | ||
| ], | ||
| "useLingui": [ | ||
| "@custom/react", | ||
| "useCustomLingui", | ||
| ], | ||
| }, | ||
| }, | ||
| ] | ||
| `) | ||
| }) | ||
|
|
||
| it("merges overrides over mapped config", () => { | ||
| expect( | ||
| linguiMacroSwcPlugin( | ||
| { | ||
| jsxPlaceholderAttribute: "data-test", | ||
| runtimeModules: { | ||
| trans: ["@override/react", "OverrideTrans"], | ||
| }, | ||
| }, | ||
| {configPath: resolve(fixturesDir, "custom.config.js")}, | ||
| ), | ||
| ).toMatchInlineSnapshot(` | ||
| [ | ||
| "@lingui/swc-plugin", | ||
| { | ||
| "jsxPlaceholderAttribute": "data-test", | ||
| "jsxPlaceholderDefaults": { | ||
| "a": "anchor", | ||
| "strong": "bold", | ||
| }, | ||
| "runtimeModules": { | ||
| "i18n": [ | ||
| "@custom/core", | ||
| "customI18n", | ||
| ], | ||
| "trans": [ | ||
| "@override/react", | ||
| "OverrideTrans", | ||
| ], | ||
| "useLingui": [ | ||
| "@custom/react", | ||
| "useCustomLingui", | ||
| ], | ||
| }, | ||
| }, | ||
| ] | ||
| `) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrii-bodnar i'm going to replace this in the next iteration with a link to main js repo example, and delete nextjs example from this repo. I'm not using for testing this example anymore, the integration now is tested using a e2e test.
I'm going to do this when this feature would be published and example itself will use this helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me