@lingui/vite-plugin 5.1.2 → 5.3.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/dist/index.cjs +46 -12
- package/dist/index.d.cts +11 -3
- package/dist/index.d.mts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.mjs +47 -13
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -11,14 +11,22 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
12
12
|
|
|
13
13
|
const fileRegex = /(\.po|\?lingui)$/;
|
|
14
|
-
function lingui(
|
|
14
|
+
function lingui({
|
|
15
|
+
failOnMissing,
|
|
16
|
+
failOnCompileError,
|
|
17
|
+
...linguiConfig
|
|
18
|
+
} = {}) {
|
|
15
19
|
const config = conf.getConfig(linguiConfig);
|
|
20
|
+
const macroIds = /* @__PURE__ */ new Set([
|
|
21
|
+
...config.macro.corePackage,
|
|
22
|
+
...config.macro.jsxPackage
|
|
23
|
+
]);
|
|
16
24
|
return [
|
|
17
25
|
{
|
|
18
26
|
name: "vite-plugin-lingui-report-macro-error",
|
|
19
27
|
enforce: "pre",
|
|
20
28
|
resolveId(id) {
|
|
21
|
-
if (
|
|
29
|
+
if (macroIds.has(id)) {
|
|
22
30
|
throw new Error(
|
|
23
31
|
`The macro you imported from "${id}" is being executed outside the context of compilation.
|
|
24
32
|
This indicates that you don't configured correctly one of the "babel-plugin-macros" / "@lingui/swc-plugin" / "babel-plugin-lingui-macro"Please see the documentation for how to configure Vite with Lingui correctly: https://lingui.dev/tutorials/setup-vite`
|
|
@@ -33,9 +41,9 @@ This indicates that you don't configured correctly one of the "babel-plugin-macr
|
|
|
33
41
|
config2.optimizeDeps = {};
|
|
34
42
|
}
|
|
35
43
|
config2.optimizeDeps.exclude = config2.optimizeDeps.exclude || [];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
for (const macroId of macroIds) {
|
|
45
|
+
config2.optimizeDeps.exclude.push(macroId);
|
|
46
|
+
}
|
|
39
47
|
},
|
|
40
48
|
async transform(src, id) {
|
|
41
49
|
if (fileRegex.test(id)) {
|
|
@@ -60,17 +68,43 @@ Please check that catalogs.path is filled properly.
|
|
|
60
68
|
const { locale, catalog } = fileCatalog;
|
|
61
69
|
const dependency = await api.getCatalogDependentFiles(catalog, locale);
|
|
62
70
|
dependency.forEach((file) => this.addWatchFile(file));
|
|
63
|
-
const messages = await catalog.getTranslations(locale, {
|
|
71
|
+
const { messages, missing: missingMessages } = await catalog.getTranslations(locale, {
|
|
64
72
|
fallbackLocales: config.fallbackLocales,
|
|
65
73
|
sourceLocale: config.sourceLocale
|
|
66
74
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
if (failOnMissing && locale !== config.pseudoLocale && missingMessages.length > 0) {
|
|
76
|
+
const message = api.createMissingErrorMessage(
|
|
77
|
+
locale,
|
|
78
|
+
missingMessages,
|
|
79
|
+
"loader"
|
|
80
|
+
);
|
|
81
|
+
throw new Error(
|
|
82
|
+
`${message}
|
|
83
|
+
You see this error because \`failOnMissing=true\` in Vite Plugin configuration.`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const { source: code, errors } = api.createCompiledCatalog(
|
|
87
|
+
locale,
|
|
88
|
+
messages,
|
|
89
|
+
{
|
|
90
|
+
namespace: "es",
|
|
91
|
+
pseudoLocale: config.pseudoLocale
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
if (errors.length) {
|
|
95
|
+
const message = api.createCompilationErrorMessage(locale, errors);
|
|
96
|
+
if (failOnCompileError) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
message + `These errors fail build because \`failOnCompileError=true\` in Lingui Vite plugin configuration.`
|
|
99
|
+
);
|
|
100
|
+
} else {
|
|
101
|
+
console.warn(
|
|
102
|
+
message + `You can fail the build on these errors by setting \`failOnCompileError=true\` in Lingui Vite Plugin configuration.`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
72
106
|
return {
|
|
73
|
-
code
|
|
107
|
+
code,
|
|
74
108
|
map: null
|
|
75
109
|
// provide source map if available
|
|
76
110
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
type
|
|
3
|
+
type LinguiPluginOpts = {
|
|
4
4
|
cwd?: string;
|
|
5
5
|
configPath?: string;
|
|
6
6
|
skipValidation?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* If true would fail compilation on missing translations
|
|
9
|
+
**/
|
|
10
|
+
failOnMissing?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* If true would fail compilation on message compilation errors
|
|
13
|
+
**/
|
|
14
|
+
failOnCompileError?: boolean;
|
|
7
15
|
};
|
|
8
|
-
declare function lingui(linguiConfig?:
|
|
16
|
+
declare function lingui({ failOnMissing, failOnCompileError, ...linguiConfig }?: LinguiPluginOpts): Plugin[];
|
|
9
17
|
|
|
10
|
-
export { lingui as default, lingui };
|
|
18
|
+
export { type LinguiPluginOpts, lingui as default, lingui };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
type
|
|
3
|
+
type LinguiPluginOpts = {
|
|
4
4
|
cwd?: string;
|
|
5
5
|
configPath?: string;
|
|
6
6
|
skipValidation?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* If true would fail compilation on missing translations
|
|
9
|
+
**/
|
|
10
|
+
failOnMissing?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* If true would fail compilation on message compilation errors
|
|
13
|
+
**/
|
|
14
|
+
failOnCompileError?: boolean;
|
|
7
15
|
};
|
|
8
|
-
declare function lingui(linguiConfig?:
|
|
16
|
+
declare function lingui({ failOnMissing, failOnCompileError, ...linguiConfig }?: LinguiPluginOpts): Plugin[];
|
|
9
17
|
|
|
10
|
-
export { lingui as default, lingui };
|
|
18
|
+
export { type LinguiPluginOpts, lingui as default, lingui };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
type
|
|
3
|
+
type LinguiPluginOpts = {
|
|
4
4
|
cwd?: string;
|
|
5
5
|
configPath?: string;
|
|
6
6
|
skipValidation?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* If true would fail compilation on missing translations
|
|
9
|
+
**/
|
|
10
|
+
failOnMissing?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* If true would fail compilation on message compilation errors
|
|
13
|
+
**/
|
|
14
|
+
failOnCompileError?: boolean;
|
|
7
15
|
};
|
|
8
|
-
declare function lingui(linguiConfig?:
|
|
16
|
+
declare function lingui({ failOnMissing, failOnCompileError, ...linguiConfig }?: LinguiPluginOpts): Plugin[];
|
|
9
17
|
|
|
10
|
-
export { lingui as default, lingui };
|
|
18
|
+
export { type LinguiPluginOpts, lingui as default, lingui };
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { getConfig } from '@lingui/conf';
|
|
2
|
-
import { getCatalogForFile, getCatalogs, getCatalogDependentFiles, createCompiledCatalog } from '@lingui/cli/api';
|
|
2
|
+
import { getCatalogForFile, getCatalogs, getCatalogDependentFiles, createMissingErrorMessage, createCompiledCatalog, createCompilationErrorMessage } from '@lingui/cli/api';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
5
5
|
const fileRegex = /(\.po|\?lingui)$/;
|
|
6
|
-
function lingui(
|
|
6
|
+
function lingui({
|
|
7
|
+
failOnMissing,
|
|
8
|
+
failOnCompileError,
|
|
9
|
+
...linguiConfig
|
|
10
|
+
} = {}) {
|
|
7
11
|
const config = getConfig(linguiConfig);
|
|
12
|
+
const macroIds = /* @__PURE__ */ new Set([
|
|
13
|
+
...config.macro.corePackage,
|
|
14
|
+
...config.macro.jsxPackage
|
|
15
|
+
]);
|
|
8
16
|
return [
|
|
9
17
|
{
|
|
10
18
|
name: "vite-plugin-lingui-report-macro-error",
|
|
11
19
|
enforce: "pre",
|
|
12
20
|
resolveId(id) {
|
|
13
|
-
if (
|
|
21
|
+
if (macroIds.has(id)) {
|
|
14
22
|
throw new Error(
|
|
15
23
|
`The macro you imported from "${id}" is being executed outside the context of compilation.
|
|
16
24
|
This indicates that you don't configured correctly one of the "babel-plugin-macros" / "@lingui/swc-plugin" / "babel-plugin-lingui-macro"Please see the documentation for how to configure Vite with Lingui correctly: https://lingui.dev/tutorials/setup-vite`
|
|
@@ -25,9 +33,9 @@ This indicates that you don't configured correctly one of the "babel-plugin-macr
|
|
|
25
33
|
config2.optimizeDeps = {};
|
|
26
34
|
}
|
|
27
35
|
config2.optimizeDeps.exclude = config2.optimizeDeps.exclude || [];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
for (const macroId of macroIds) {
|
|
37
|
+
config2.optimizeDeps.exclude.push(macroId);
|
|
38
|
+
}
|
|
31
39
|
},
|
|
32
40
|
async transform(src, id) {
|
|
33
41
|
if (fileRegex.test(id)) {
|
|
@@ -52,17 +60,43 @@ Please check that catalogs.path is filled properly.
|
|
|
52
60
|
const { locale, catalog } = fileCatalog;
|
|
53
61
|
const dependency = await getCatalogDependentFiles(catalog, locale);
|
|
54
62
|
dependency.forEach((file) => this.addWatchFile(file));
|
|
55
|
-
const messages = await catalog.getTranslations(locale, {
|
|
63
|
+
const { messages, missing: missingMessages } = await catalog.getTranslations(locale, {
|
|
56
64
|
fallbackLocales: config.fallbackLocales,
|
|
57
65
|
sourceLocale: config.sourceLocale
|
|
58
66
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
if (failOnMissing && locale !== config.pseudoLocale && missingMessages.length > 0) {
|
|
68
|
+
const message = createMissingErrorMessage(
|
|
69
|
+
locale,
|
|
70
|
+
missingMessages,
|
|
71
|
+
"loader"
|
|
72
|
+
);
|
|
73
|
+
throw new Error(
|
|
74
|
+
`${message}
|
|
75
|
+
You see this error because \`failOnMissing=true\` in Vite Plugin configuration.`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const { source: code, errors } = createCompiledCatalog(
|
|
79
|
+
locale,
|
|
80
|
+
messages,
|
|
81
|
+
{
|
|
82
|
+
namespace: "es",
|
|
83
|
+
pseudoLocale: config.pseudoLocale
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
if (errors.length) {
|
|
87
|
+
const message = createCompilationErrorMessage(locale, errors);
|
|
88
|
+
if (failOnCompileError) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
message + `These errors fail build because \`failOnCompileError=true\` in Lingui Vite plugin configuration.`
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
console.warn(
|
|
94
|
+
message + `You can fail the build on these errors by setting \`failOnCompileError=true\` in Lingui Vite Plugin configuration.`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
64
98
|
return {
|
|
65
|
-
code
|
|
99
|
+
code,
|
|
66
100
|
map: null
|
|
67
101
|
// provide source map if available
|
|
68
102
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/vite-plugin",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Vite plugin for Lingui message catalogs",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -39,18 +39,18 @@
|
|
|
39
39
|
"dist/"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@lingui/cli": "
|
|
43
|
-
"@lingui/conf": "
|
|
42
|
+
"@lingui/cli": "5.3.0",
|
|
43
|
+
"@lingui/conf": "5.3.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"vite": "^3 || ^4 || ^5.0.9 || ^6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@lingui/core": "^5.
|
|
50
|
-
"@lingui/format-json": "^5.
|
|
49
|
+
"@lingui/core": "^5.3.0",
|
|
50
|
+
"@lingui/format-json": "^5.3.0",
|
|
51
51
|
"unbuild": "2.0.0",
|
|
52
52
|
"vite": "6.0.2",
|
|
53
53
|
"vite-plugin-babel-macros": "^1.0.6"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "ed491cce7e5209378922327e0e7b802fb7b5873d"
|
|
56
56
|
}
|