@lingui/swc-plugin 6.3.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.
@@ -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,43 +1,6 @@
1
- export type RuntimeModuleConfig = readonly [modulePath: string, exportName?: string];
2
- /** Options accepted by the `@lingui/swc-plugin` WASM plugin. */
3
- export type LinguiMacroOptions = {
4
- /** Module specifiers treated as core macro imports, such as `t`, `msg`, and `defineMessage`. */
5
- corePackage?: string[];
6
- /** Module specifiers treated as JSX macro imports, such as `Trans` and `useLingui`. */
7
- jsxPackage?: string[];
8
- /** JSX attribute name used to provide explicit placeholder names inside `<Trans>` content. */
9
- jsxPlaceholderAttribute?: string;
10
- /** Default placeholder names for JSX tags when no explicit placeholder attribute is present. */
11
- jsxPlaceholderDefaults?: Record<string, string>;
12
- /** Overrides the runtime imports used by the plugin. Unlike the Babel macro configuration, must be passed as an object. */
13
- runtimeModules: {
14
- i18n: RuntimeModuleConfig;
15
- Trans: RuntimeModuleConfig;
16
- useLingui: RuntimeModuleConfig;
17
- };
18
- /**
19
- * Compatibility option for using the v6 SWC plugin with `@lingui/cli@5.*`.
20
- * - `false` (default) — URL-safe Base64 alphabet (Lingui v6).
21
- * - `true` — Standard Base64 alphabet (Lingui v5).
22
- *
23
- * Temporary — will be removed in the next major release.
24
- */
25
- useLinguiV5IdGeneration?: boolean;
26
- /**
27
- * Controls which descriptor fields are preserved in output.
28
- * - `"auto"` (default) — `"id-only"` in production, `"all"` otherwise.
29
- * - `"all"` — Keeps id, message, context, and comment.
30
- * - `"id-only"` — Keeps only id. Most optimized for production bundles.
31
- * - `"message"` — Keeps id, message, and context (not comment).
32
- */
33
- descriptorFields?: 'auto' | 'all' | 'id-only' | 'message';
34
- /** Restricts directive-based `idPrefix` to explicit ids starting with this leader string. When omitted, `idPrefix` is prepended to all explicit static ids. */
35
- idPrefixLeader?: string;
36
- };
37
- /** Makes all properties in `T` optional, recursing into nested objects but preserving tuples/arrays as-is. */
38
- export type DeepPartial<T> = {
39
- [Key in keyof T]?: T[Key] extends readonly unknown[] ? T[Key] : T[Key] extends object ? DeepPartial<T[Key]> : T[Key];
40
- };
1
+ import { DeepPartial, LinguiMacroOptions } from "./map-options";
2
+ export type { RuntimeModuleConfig, LinguiMacroOptions } from "./map-options";
3
+ export { mapOptions } from "./map-options";
41
4
  /** Controls how the Lingui config is located and loaded. */
42
5
  export type GetConfigOptions = {
43
6
  /** Working directory for config discovery. Defaults to `process.cwd()`. */
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,16 +20,5 @@ import { getConfig } from "@lingui/conf";
18
20
  */
19
21
  export function linguiMacroSwcPlugin(overrides, configOptions = {}) {
20
22
  const config = getConfig(configOptions);
21
- const macroOptions = {
22
- corePackage: config.macro.corePackage,
23
- jsxPackage: config.macro.jsxPackage,
24
- jsxPlaceholderAttribute: config.macro.jsxPlaceholderAttribute,
25
- jsxPlaceholderDefaults: config.macro.jsxPlaceholderDefaults,
26
- ...overrides,
27
- runtimeModules: {
28
- ...config.runtimeConfigModule,
29
- ...overrides?.runtimeModules,
30
- },
31
- };
32
- return ["@lingui/swc-plugin", macroOptions];
23
+ return ["@lingui/swc-plugin", mapOptions(config, overrides)];
33
24
  }
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/swc-plugin",
3
- "version": "6.3.0",
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": "target/wasm32-wasip1/release/lingui_macro_plugin.wasm",
24
+ "main": "./lingui_macro.wasm",
25
25
  "exports": {
26
- ".": "./target/wasm32-wasip1/release/lingui_macro_plugin.wasm",
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-wasi --release",
36
- "test:e2e": "cargo build-wasi --release && vitest run"
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
- "target/wasm32-wasip1/release/lingui_macro_plugin.wasm"
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.