@lingui/swc-plugin 6.2.0 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/dist/map-options.d.ts +45 -0
- package/dist/map-options.js +17 -0
- package/dist/options.d.ts +4 -37
- package/dist/options.js +3 -10
- package/lingui_macro.wasm +0 -0
- package/package.json +7 -9
- package/LICENSE +0 -21
- package/target/wasm32-wasip1/release/lingui_macro_plugin.wasm +0 -0
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ module.exports = nextConfig;
|
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
> **Note**
|
|
59
|
-
> Consult with full working example for NextJS
|
|
59
|
+
> Consult with [full working example](https://github.com/lingui/js-lingui/tree/main/examples/nextjs-swc) for NextJS with SWC.
|
|
60
60
|
|
|
61
61
|
#### `vite.config.ts`
|
|
62
62
|
|
|
@@ -128,6 +128,18 @@ When using SWC directly via CLI or a JSON-only configuration, pass options manua
|
|
|
128
128
|
|
|
129
129
|
## Options
|
|
130
130
|
|
|
131
|
+
### `corePackage`
|
|
132
|
+
|
|
133
|
+
Defines which module specifiers the plugin should treat as core macro imports.
|
|
134
|
+
|
|
135
|
+
Defaults to `[@lingui/macro, @lingui/core/macro]` for backwards compatibility with the legacy combined macro entrypoint.
|
|
136
|
+
|
|
137
|
+
### `jsxPackage`
|
|
138
|
+
|
|
139
|
+
Defines which module specifiers the plugin should treat as JSX macro imports.
|
|
140
|
+
|
|
141
|
+
Defaults to `[@lingui/macro, @lingui/react/macro]` for backwards compatibility with the legacy combined macro entrypoint.
|
|
142
|
+
|
|
131
143
|
### `descriptorFields`
|
|
132
144
|
|
|
133
145
|
Controls which fields are preserved in the transformed message descriptors. Accepts one of:
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { LinguiConfigNormalized } from "@lingui/conf" with { "resolution-mode": "import" };
|
|
2
|
+
export type RuntimeModuleConfig = readonly [modulePath: string, exportName?: string];
|
|
3
|
+
/** Options accepted by the `@lingui/swc-plugin` WASM plugin. */
|
|
4
|
+
export type LinguiMacroOptions = {
|
|
5
|
+
/** Module specifiers treated as core macro imports, such as `t`, `msg`, and `defineMessage`. */
|
|
6
|
+
corePackage?: string[];
|
|
7
|
+
/** Module specifiers treated as JSX macro imports, such as `Trans` and `useLingui`. */
|
|
8
|
+
jsxPackage?: string[];
|
|
9
|
+
/** JSX attribute name used to provide explicit placeholder names inside `<Trans>` content. */
|
|
10
|
+
jsxPlaceholderAttribute?: string;
|
|
11
|
+
/** Default placeholder names for JSX tags when no explicit placeholder attribute is present. */
|
|
12
|
+
jsxPlaceholderDefaults?: Record<string, string>;
|
|
13
|
+
/** Overrides the runtime imports used by the plugin. Unlike the Babel macro configuration, must be passed as an object. */
|
|
14
|
+
runtimeModules: {
|
|
15
|
+
i18n: RuntimeModuleConfig;
|
|
16
|
+
Trans: RuntimeModuleConfig;
|
|
17
|
+
useLingui: RuntimeModuleConfig;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Compatibility option for using the v6 SWC plugin with `@lingui/cli@5.*`.
|
|
21
|
+
* - `false` (default) — URL-safe Base64 alphabet (Lingui v6).
|
|
22
|
+
* - `true` — Standard Base64 alphabet (Lingui v5).
|
|
23
|
+
*
|
|
24
|
+
* Temporary — will be removed in the next major release.
|
|
25
|
+
*/
|
|
26
|
+
useLinguiV5IdGeneration?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Controls which descriptor fields are preserved in output.
|
|
29
|
+
* - `"auto"` (default) — `"id-only"` in production, `"all"` otherwise.
|
|
30
|
+
* - `"all"` — Keeps id, message, context, and comment.
|
|
31
|
+
* - `"id-only"` — Keeps only id. Most optimized for production bundles.
|
|
32
|
+
* - `"message"` — Keeps id, message, and context (not comment).
|
|
33
|
+
*/
|
|
34
|
+
descriptorFields?: 'auto' | 'all' | 'id-only' | 'message';
|
|
35
|
+
/** Restricts directive-based `idPrefix` to explicit ids starting with this leader string. When omitted, `idPrefix` is prepended to all explicit static ids. */
|
|
36
|
+
idPrefixLeader?: string;
|
|
37
|
+
};
|
|
38
|
+
/** Makes all properties in `T` optional, recursing into nested objects but preserving tuples/arrays as-is. */
|
|
39
|
+
export type DeepPartial<T> = {
|
|
40
|
+
[Key in keyof T]?: T[Key] extends readonly unknown[] ? T[Key] : T[Key] extends object ? DeepPartial<T[Key]> : T[Key];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Maps relevant options from the Lingui config to the SWC plugin format
|
|
44
|
+
*/
|
|
45
|
+
export declare function mapOptions(linguiConfig: LinguiConfigNormalized, overrides?: DeepPartial<LinguiMacroOptions>): LinguiMacroOptions;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps relevant options from the Lingui config to the SWC plugin format
|
|
3
|
+
*/
|
|
4
|
+
export function mapOptions(linguiConfig, overrides) {
|
|
5
|
+
return {
|
|
6
|
+
corePackage: linguiConfig.macro.corePackage,
|
|
7
|
+
jsxPackage: linguiConfig.macro.jsxPackage,
|
|
8
|
+
jsxPlaceholderAttribute: linguiConfig.macro.jsxPlaceholderAttribute,
|
|
9
|
+
jsxPlaceholderDefaults: linguiConfig.macro.jsxPlaceholderDefaults,
|
|
10
|
+
idPrefixLeader: linguiConfig.macro.idPrefixLeader,
|
|
11
|
+
...overrides,
|
|
12
|
+
runtimeModules: {
|
|
13
|
+
...linguiConfig.runtimeConfigModule,
|
|
14
|
+
...overrides?.runtimeModules,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,39 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
/** JSX attribute name used to provide explicit placeholder names inside `<Trans>` content. */
|
|
5
|
-
jsxPlaceholderAttribute?: string;
|
|
6
|
-
/** Default placeholder names for JSX tags when no explicit placeholder attribute is present. */
|
|
7
|
-
jsxPlaceholderDefaults?: Record<string, string>;
|
|
8
|
-
/** Overrides the runtime imports used by the plugin. Unlike the Babel macro configuration, must be passed as an object. */
|
|
9
|
-
runtimeModules: {
|
|
10
|
-
i18n: RuntimeModuleConfig;
|
|
11
|
-
Trans: RuntimeModuleConfig;
|
|
12
|
-
useLingui: RuntimeModuleConfig;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Compatibility option for using the v6 SWC plugin with `@lingui/cli@5.*`.
|
|
16
|
-
* - `false` (default) — URL-safe Base64 alphabet (Lingui v6).
|
|
17
|
-
* - `true` — Standard Base64 alphabet (Lingui v5).
|
|
18
|
-
*
|
|
19
|
-
* Temporary — will be removed in the next major release.
|
|
20
|
-
*/
|
|
21
|
-
useLinguiV5IdGeneration?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Controls which descriptor fields are preserved in output.
|
|
24
|
-
* - `"auto"` (default) — `"id-only"` in production, `"all"` otherwise.
|
|
25
|
-
* - `"all"` — Keeps id, message, context, and comment.
|
|
26
|
-
* - `"id-only"` — Keeps only id. Most optimized for production bundles.
|
|
27
|
-
* - `"message"` — Keeps id, message, and context (not comment).
|
|
28
|
-
*/
|
|
29
|
-
descriptorFields?: 'auto' | 'all' | 'id-only' | 'message';
|
|
30
|
-
/** Restricts directive-based `idPrefix` to explicit ids starting with this leader string. When omitted, `idPrefix` is prepended to all explicit static ids. */
|
|
31
|
-
idPrefixLeader?: string;
|
|
32
|
-
};
|
|
33
|
-
/** Makes all properties in `T` optional, recursing into nested objects but preserving tuples/arrays as-is. */
|
|
34
|
-
export type DeepPartial<T> = {
|
|
35
|
-
[Key in keyof T]?: T[Key] extends readonly unknown[] ? T[Key] : T[Key] extends object ? DeepPartial<T[Key]> : T[Key];
|
|
36
|
-
};
|
|
1
|
+
import { DeepPartial, LinguiMacroOptions } from "./map-options";
|
|
2
|
+
export type { RuntimeModuleConfig, LinguiMacroOptions } from "./map-options";
|
|
3
|
+
export { mapOptions } from "./map-options";
|
|
37
4
|
/** Controls how the Lingui config is located and loaded. */
|
|
38
5
|
export type GetConfigOptions = {
|
|
39
6
|
/** Working directory for config discovery. Defaults to `process.cwd()`. */
|
|
@@ -60,4 +27,4 @@ export type GetConfigOptions = {
|
|
|
60
27
|
* @param overrides - Plugin options merged over values derived from the Lingui config.
|
|
61
28
|
* @param configOptions - Controls how the Lingui config is discovered or loaded.
|
|
62
29
|
*/
|
|
63
|
-
export declare function linguiMacroSwcPlugin(overrides?: DeepPartial<LinguiMacroOptions>, configOptions?: GetConfigOptions):
|
|
30
|
+
export declare function linguiMacroSwcPlugin(overrides?: DeepPartial<LinguiMacroOptions>, configOptions?: GetConfigOptions): [wasmPackage: string, config: LinguiMacroOptions];
|
package/dist/options.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { getConfig } from "@lingui/conf";
|
|
2
|
+
import { mapOptions } from "./map-options";
|
|
3
|
+
export { mapOptions } from "./map-options";
|
|
2
4
|
/**
|
|
3
5
|
* Loads the Lingui config, maps relevant options to the SWC plugin format,
|
|
4
6
|
* and returns a ready-to-use `["@lingui/swc-plugin", options]` tuple.
|
|
@@ -18,14 +20,5 @@ import { getConfig } from "@lingui/conf";
|
|
|
18
20
|
*/
|
|
19
21
|
export function linguiMacroSwcPlugin(overrides, configOptions = {}) {
|
|
20
22
|
const config = getConfig(configOptions);
|
|
21
|
-
|
|
22
|
-
jsxPlaceholderAttribute: config.macro.jsxPlaceholderAttribute,
|
|
23
|
-
jsxPlaceholderDefaults: config.macro.jsxPlaceholderDefaults,
|
|
24
|
-
...overrides,
|
|
25
|
-
runtimeModules: {
|
|
26
|
-
...config.runtimeConfigModule,
|
|
27
|
-
...overrides?.runtimeModules,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
return ["@lingui/swc-plugin", macroOptions];
|
|
23
|
+
return ["@lingui/swc-plugin", mapOptions(config, overrides)];
|
|
31
24
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/swc-plugin",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"description": "A SWC Plugin for LinguiJS",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Timofei Iatsenko",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"i18n",
|
|
22
22
|
"internationalization"
|
|
23
23
|
],
|
|
24
|
-
"main": "
|
|
24
|
+
"main": "./lingui_macro.wasm",
|
|
25
25
|
"exports": {
|
|
26
|
-
".": "./
|
|
26
|
+
".": "./lingui_macro.wasm",
|
|
27
27
|
"./options": {
|
|
28
28
|
"types": "./dist/options.d.ts",
|
|
29
29
|
"default": "./dist/options.js"
|
|
@@ -32,14 +32,13 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"prepublishOnly": "yarn build:ts && yarn build:wasm",
|
|
34
34
|
"build:ts": "tsc -p tsconfig.build.json",
|
|
35
|
-
"build:wasm": "cargo build-
|
|
36
|
-
"test:e2e": "
|
|
35
|
+
"build:wasm": "cargo build -p lingui_macro --target wasm32-wasip1 --release && cp ../../target/wasm32-wasip1/release/lingui_macro.wasm lingui_macro.wasm",
|
|
36
|
+
"test:e2e": "yarn build:wasm && vitest run"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
|
-
"LICENSE",
|
|
40
39
|
"README.md",
|
|
41
40
|
"dist/",
|
|
42
|
-
"
|
|
41
|
+
"lingui_macro.wasm"
|
|
43
42
|
],
|
|
44
43
|
"dependencies": {
|
|
45
44
|
"@lingui/conf": "5 || 6"
|
|
@@ -60,6 +59,5 @@
|
|
|
60
59
|
"@types/node": "22.13.14",
|
|
61
60
|
"typescript": "^6.0.3",
|
|
62
61
|
"vitest": "^4.1.7"
|
|
63
|
-
}
|
|
64
|
-
"packageManager": "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8"
|
|
62
|
+
}
|
|
65
63
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Lingui
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
Binary file
|