@lingui/vite-plugin 6.0.0-next.2 → 6.0.0-next.3
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/dist/index.d.mts +51 -1
- package/dist/index.mjs +33 -18
- package/package.json +21 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,54 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
import * as pluginBabel from '@rolldown/plugin-babel';
|
|
3
|
+
import * as babelPluginLinguiMacro from '@lingui/babel-plugin-lingui-macro';
|
|
4
|
+
|
|
5
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// @ts-ignore --- `@rolldown/plugin-babel` is an optional peer dependency, so this may cause an error
|
|
10
|
+
type RolldownBabelPreset = pluginBabel.RolldownBabelPreset
|
|
11
|
+
// @ts-ignore --- `babel-plugin-react-compiler` is an optional peer dependency, so this may cause an error
|
|
12
|
+
type LinguiMacroBabelPluginOptions =
|
|
13
|
+
babelPluginLinguiMacro.LinguiPluginOpts
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Convenient helper to define a rolldown preset with Lingui Transformer for `@rolldown/plugin-babel`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```js
|
|
20
|
+
* // vite.config.js
|
|
21
|
+
* import { defineConfig } from 'vite'
|
|
22
|
+
* import react from '@vitejs/plugin-react'
|
|
23
|
+
* import babel from '@rolldown/plugin-babel'
|
|
24
|
+
* import { lingui, linguiTransformerBabelPreset } from '@lingui/vite-plugin'
|
|
25
|
+
*
|
|
26
|
+
* export default defineConfig({
|
|
27
|
+
* plugins: [react(), lingui(), babel({ presets: [linguiTransformerBabelPreset()] })],
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
* @param options Options Passed to the babel-plugin-lingui-macro
|
|
31
|
+
* @param linguiConfigConfigOpts options passed to the lingui config discovery function
|
|
32
|
+
*
|
|
33
|
+
*
|
|
34
|
+
* > [!TIP]
|
|
35
|
+
* >
|
|
36
|
+
* > `linguiTransformerBabelPreset` is only a convenient helper with a preconfigured filter. You can configure override the filters to fit your project structure or code. For example, if you know a large portion of your files are never Lingui-related, you can aggressively exclude them via `rolldown.filter`:
|
|
37
|
+
* >
|
|
38
|
+
* > ```js
|
|
39
|
+
* > const myPreset = linguiTransformerBabelPreset()
|
|
40
|
+
* > myPreset.rolldown.filter.id.exclude = ['src/legacy/**', 'src/utils/**']
|
|
41
|
+
* >
|
|
42
|
+
* > babel({
|
|
43
|
+
* > presets: [myPreset],
|
|
44
|
+
* > })
|
|
45
|
+
* > ```
|
|
46
|
+
*/
|
|
47
|
+
declare const linguiTransformerBabelPreset: (options?: LinguiMacroBabelPluginOptions, linguiConfigConfigOpts?: {
|
|
48
|
+
cwd?: string;
|
|
49
|
+
configPath?: string;
|
|
50
|
+
skipValidation?: boolean;
|
|
51
|
+
}) => RolldownBabelPreset;
|
|
2
52
|
|
|
3
53
|
type LinguiPluginOpts = {
|
|
4
54
|
cwd?: string;
|
|
@@ -15,5 +65,5 @@ type LinguiPluginOpts = {
|
|
|
15
65
|
};
|
|
16
66
|
declare function lingui({ failOnMissing, failOnCompileError, ...linguiConfig }?: LinguiPluginOpts): Plugin[];
|
|
17
67
|
|
|
18
|
-
export { lingui as default, lingui };
|
|
68
|
+
export { lingui as default, lingui, linguiTransformerBabelPreset };
|
|
19
69
|
export type { LinguiPluginOpts };
|
package/dist/index.mjs
CHANGED
|
@@ -2,35 +2,50 @@ import { getConfig } from '@lingui/conf';
|
|
|
2
2
|
import { getCatalogForFile, getCatalogs, getCatalogDependentFiles, createMissingErrorMessage, createCompiledCatalog, createCompilationErrorMessage } from '@lingui/cli/api';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
5
|
+
const linguiTransformerBabelPreset = (options, linguiConfigConfigOpts = {}) => {
|
|
6
|
+
const config = getConfig(linguiConfigConfigOpts);
|
|
7
|
+
const macroIds = /* @__PURE__ */ new Set([
|
|
8
|
+
...config.macro.corePackage,
|
|
9
|
+
...config.macro.jsxPackage
|
|
10
|
+
]);
|
|
11
|
+
const macroPattern = Array.from(macroIds).map((id) => id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
12
|
+
return {
|
|
13
|
+
preset: {
|
|
14
|
+
plugins: [["@lingui/babel-plugin-lingui-macro", options]]
|
|
15
|
+
},
|
|
16
|
+
rolldown: {
|
|
17
|
+
filter: {
|
|
18
|
+
code: new RegExp(`from ['"](?:${macroPattern})['"]`)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
5
24
|
const fileRegex = /(\.po|\?lingui)$/;
|
|
6
25
|
function lingui({
|
|
7
26
|
failOnMissing,
|
|
8
27
|
failOnCompileError,
|
|
9
28
|
...linguiConfig
|
|
10
29
|
} = {}) {
|
|
11
|
-
|
|
12
|
-
const macroIds = /* @__PURE__ */ new Set([
|
|
13
|
-
...config.macro.corePackage,
|
|
14
|
-
...config.macro.jsxPackage
|
|
15
|
-
]);
|
|
30
|
+
let config;
|
|
16
31
|
return [
|
|
17
32
|
{
|
|
18
|
-
name: "vite-plugin-lingui-
|
|
33
|
+
name: "vite-plugin-lingui-get-config",
|
|
19
34
|
enforce: "pre",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
throw new Error(
|
|
23
|
-
`The macro you imported from "${id}" cannot be dynamically imported.
|
|
24
|
-
Please check the import statement in file "${importer}".
|
|
25
|
-
Please see the documentation for how to configure Vite with Lingui correctly: https://lingui.dev/tutorials/setup-vite`
|
|
26
|
-
);
|
|
27
|
-
}
|
|
35
|
+
configResolved: () => {
|
|
36
|
+
config = getConfig(linguiConfig);
|
|
28
37
|
}
|
|
29
38
|
},
|
|
30
39
|
{
|
|
31
|
-
name: "vite-plugin-lingui",
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
name: "vite-plugin-lingui-load-catalog",
|
|
41
|
+
transform: {
|
|
42
|
+
filter: {
|
|
43
|
+
id: fileRegex
|
|
44
|
+
},
|
|
45
|
+
async handler(src, id) {
|
|
46
|
+
if (!fileRegex.test(id)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
34
49
|
id = id.split("?")[0];
|
|
35
50
|
const catalogRelativePath = path.relative(config.rootDir, id);
|
|
36
51
|
const fileCatalog = getCatalogForFile(
|
|
@@ -102,4 +117,4 @@ You see this error because \`failOnMissing=true\` in Vite Plugin configuration.`
|
|
|
102
117
|
];
|
|
103
118
|
}
|
|
104
119
|
|
|
105
|
-
export { lingui as default, lingui };
|
|
120
|
+
export { lingui as default, lingui, linguiTransformerBabelPreset };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/vite-plugin",
|
|
3
|
-
"version": "6.0.0-next.
|
|
3
|
+
"version": "6.0.0-next.3",
|
|
4
4
|
"description": "Vite plugin for Lingui message catalogs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -42,23 +42,35 @@
|
|
|
42
42
|
"dist/"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@lingui/cli": "6.0.0-next.
|
|
46
|
-
"@lingui/conf": "6.0.0-next.
|
|
45
|
+
"@lingui/cli": "6.0.0-next.3",
|
|
46
|
+
"@lingui/conf": "6.0.0-next.3"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"
|
|
49
|
+
"@lingui/babel-plugin-lingui-macro": "^5 || ^6",
|
|
50
|
+
"@rolldown/plugin-babel": "^0.1.7 || ^0.2.0",
|
|
51
|
+
"vite": "^6.3.0 || ^7 || ^8"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"@lingui/babel-plugin-lingui-macro": {
|
|
55
|
+
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"@rolldown/plugin-babel": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
50
60
|
},
|
|
51
61
|
"devDependencies": {
|
|
52
|
-
"@lingui/
|
|
53
|
-
"@lingui/
|
|
54
|
-
"@lingui/
|
|
62
|
+
"@lingui/babel-plugin-lingui-macro": "^6.0.0-next.3",
|
|
63
|
+
"@lingui/core": "^6.0.0-next.3",
|
|
64
|
+
"@lingui/format-json": "^6.0.0-next.3",
|
|
65
|
+
"@lingui/react": "^6.0.0-next.3",
|
|
66
|
+
"@rolldown/plugin-babel": "^0.2.2",
|
|
55
67
|
"unbuild": "3.6.1",
|
|
56
|
-
"vite": "
|
|
68
|
+
"vite": "^8.0.3",
|
|
57
69
|
"vite-plugin-babel-macros": "^1.0.6",
|
|
58
70
|
"vitest": "4.0.18"
|
|
59
71
|
},
|
|
60
72
|
"unbuild": {
|
|
61
73
|
"declaration": "node16"
|
|
62
74
|
},
|
|
63
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "ebcb6dc8e8d327ae5775cadee931942ef309480f"
|
|
64
76
|
}
|