@lingui/vite-plugin 4.2.1 → 4.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 +52 -35
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +52 -35
- package/package.json +8 -6
package/dist/index.cjs
CHANGED
|
@@ -9,23 +9,39 @@ const path = require('path');
|
|
|
9
9
|
const fileRegex = /(\.po|\?lingui)$/;
|
|
10
10
|
function lingui(linguiConfig = {}) {
|
|
11
11
|
const config = conf.getConfig(linguiConfig);
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
async transform(src, id) {
|
|
19
|
-
if (fileRegex.test(id)) {
|
|
20
|
-
id = id.split("?")[0];
|
|
21
|
-
const catalogRelativePath = path.relative(config.rootDir, id);
|
|
22
|
-
const fileCatalog = api.getCatalogForFile(
|
|
23
|
-
catalogRelativePath,
|
|
24
|
-
await api.getCatalogs(config)
|
|
25
|
-
);
|
|
26
|
-
if (!fileCatalog) {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
name: "vite-plugin-lingui-report-macro-error",
|
|
15
|
+
enforce: "pre",
|
|
16
|
+
resolveId(id) {
|
|
17
|
+
if (id.includes("@lingui/macro")) {
|
|
27
18
|
throw new Error(
|
|
28
|
-
`
|
|
19
|
+
`The macro you imported from "@lingui/macro" is being executed outside the context of compilation.
|
|
20
|
+
This indicates that you don't have the "babel-plugin-macros" or "@lingui/swc-plugin" configured correctly. Please see the documentation for how to configure Vite with Lingui correctly: https://lingui.dev/tutorials/setup-vite`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "vite-plugin-lingui",
|
|
27
|
+
config: (config2) => {
|
|
28
|
+
if (!config2.optimizeDeps) {
|
|
29
|
+
config2.optimizeDeps = {};
|
|
30
|
+
}
|
|
31
|
+
config2.optimizeDeps.exclude = config2.optimizeDeps.exclude || [];
|
|
32
|
+
config2.optimizeDeps.exclude.push("@lingui/macro");
|
|
33
|
+
},
|
|
34
|
+
async transform(src, id) {
|
|
35
|
+
if (fileRegex.test(id)) {
|
|
36
|
+
id = id.split("?")[0];
|
|
37
|
+
const catalogRelativePath = path.relative(config.rootDir, id);
|
|
38
|
+
const fileCatalog = api.getCatalogForFile(
|
|
39
|
+
catalogRelativePath,
|
|
40
|
+
await api.getCatalogs(config)
|
|
41
|
+
);
|
|
42
|
+
if (!fileCatalog) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Requested resource ${catalogRelativePath} is not matched to any of your catalogs paths specified in "lingui.config".
|
|
29
45
|
|
|
30
46
|
Resource: ${id}
|
|
31
47
|
|
|
@@ -33,28 +49,29 @@ Your catalogs:
|
|
|
33
49
|
${config.catalogs.map((c) => c.path).join("\n")}
|
|
34
50
|
Please check that catalogs.path is filled properly.
|
|
35
51
|
`
|
|
36
|
-
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const { locale, catalog } = fileCatalog;
|
|
55
|
+
const dependency = await api.getCatalogDependentFiles(catalog, locale);
|
|
56
|
+
dependency.forEach((file) => this.addWatchFile(file));
|
|
57
|
+
const messages = await catalog.getTranslations(locale, {
|
|
58
|
+
fallbackLocales: config.fallbackLocales,
|
|
59
|
+
sourceLocale: config.sourceLocale
|
|
60
|
+
});
|
|
61
|
+
const compiled = api.createCompiledCatalog(locale, messages, {
|
|
62
|
+
strict: false,
|
|
63
|
+
namespace: "es",
|
|
64
|
+
pseudoLocale: config.pseudoLocale
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
code: compiled,
|
|
68
|
+
map: null
|
|
69
|
+
// provide source map if available
|
|
70
|
+
};
|
|
37
71
|
}
|
|
38
|
-
const { locale, catalog } = fileCatalog;
|
|
39
|
-
const dependency = await api.getCatalogDependentFiles(catalog, locale);
|
|
40
|
-
dependency.forEach((file) => this.addWatchFile(file));
|
|
41
|
-
const messages = await catalog.getTranslations(locale, {
|
|
42
|
-
fallbackLocales: config.fallbackLocales,
|
|
43
|
-
sourceLocale: config.sourceLocale
|
|
44
|
-
});
|
|
45
|
-
const compiled = api.createCompiledCatalog(locale, messages, {
|
|
46
|
-
strict: false,
|
|
47
|
-
namespace: "es",
|
|
48
|
-
pseudoLocale: config.pseudoLocale
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
code: compiled,
|
|
52
|
-
map: null
|
|
53
|
-
// provide source map if available
|
|
54
|
-
};
|
|
55
72
|
}
|
|
56
73
|
}
|
|
57
|
-
|
|
74
|
+
];
|
|
58
75
|
}
|
|
59
76
|
|
|
60
77
|
exports.default = lingui;
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -5,23 +5,39 @@ import path from 'path';
|
|
|
5
5
|
const fileRegex = /(\.po|\?lingui)$/;
|
|
6
6
|
function lingui(linguiConfig = {}) {
|
|
7
7
|
const config = getConfig(linguiConfig);
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
async transform(src, id) {
|
|
15
|
-
if (fileRegex.test(id)) {
|
|
16
|
-
id = id.split("?")[0];
|
|
17
|
-
const catalogRelativePath = path.relative(config.rootDir, id);
|
|
18
|
-
const fileCatalog = getCatalogForFile(
|
|
19
|
-
catalogRelativePath,
|
|
20
|
-
await getCatalogs(config)
|
|
21
|
-
);
|
|
22
|
-
if (!fileCatalog) {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
name: "vite-plugin-lingui-report-macro-error",
|
|
11
|
+
enforce: "pre",
|
|
12
|
+
resolveId(id) {
|
|
13
|
+
if (id.includes("@lingui/macro")) {
|
|
23
14
|
throw new Error(
|
|
24
|
-
`
|
|
15
|
+
`The macro you imported from "@lingui/macro" is being executed outside the context of compilation.
|
|
16
|
+
This indicates that you don't have the "babel-plugin-macros" or "@lingui/swc-plugin" configured correctly. Please see the documentation for how to configure Vite with Lingui correctly: https://lingui.dev/tutorials/setup-vite`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "vite-plugin-lingui",
|
|
23
|
+
config: (config2) => {
|
|
24
|
+
if (!config2.optimizeDeps) {
|
|
25
|
+
config2.optimizeDeps = {};
|
|
26
|
+
}
|
|
27
|
+
config2.optimizeDeps.exclude = config2.optimizeDeps.exclude || [];
|
|
28
|
+
config2.optimizeDeps.exclude.push("@lingui/macro");
|
|
29
|
+
},
|
|
30
|
+
async transform(src, id) {
|
|
31
|
+
if (fileRegex.test(id)) {
|
|
32
|
+
id = id.split("?")[0];
|
|
33
|
+
const catalogRelativePath = path.relative(config.rootDir, id);
|
|
34
|
+
const fileCatalog = getCatalogForFile(
|
|
35
|
+
catalogRelativePath,
|
|
36
|
+
await getCatalogs(config)
|
|
37
|
+
);
|
|
38
|
+
if (!fileCatalog) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Requested resource ${catalogRelativePath} is not matched to any of your catalogs paths specified in "lingui.config".
|
|
25
41
|
|
|
26
42
|
Resource: ${id}
|
|
27
43
|
|
|
@@ -29,28 +45,29 @@ Your catalogs:
|
|
|
29
45
|
${config.catalogs.map((c) => c.path).join("\n")}
|
|
30
46
|
Please check that catalogs.path is filled properly.
|
|
31
47
|
`
|
|
32
|
-
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const { locale, catalog } = fileCatalog;
|
|
51
|
+
const dependency = await getCatalogDependentFiles(catalog, locale);
|
|
52
|
+
dependency.forEach((file) => this.addWatchFile(file));
|
|
53
|
+
const messages = await catalog.getTranslations(locale, {
|
|
54
|
+
fallbackLocales: config.fallbackLocales,
|
|
55
|
+
sourceLocale: config.sourceLocale
|
|
56
|
+
});
|
|
57
|
+
const compiled = createCompiledCatalog(locale, messages, {
|
|
58
|
+
strict: false,
|
|
59
|
+
namespace: "es",
|
|
60
|
+
pseudoLocale: config.pseudoLocale
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
code: compiled,
|
|
64
|
+
map: null
|
|
65
|
+
// provide source map if available
|
|
66
|
+
};
|
|
33
67
|
}
|
|
34
|
-
const { locale, catalog } = fileCatalog;
|
|
35
|
-
const dependency = await getCatalogDependentFiles(catalog, locale);
|
|
36
|
-
dependency.forEach((file) => this.addWatchFile(file));
|
|
37
|
-
const messages = await catalog.getTranslations(locale, {
|
|
38
|
-
fallbackLocales: config.fallbackLocales,
|
|
39
|
-
sourceLocale: config.sourceLocale
|
|
40
|
-
});
|
|
41
|
-
const compiled = createCompiledCatalog(locale, messages, {
|
|
42
|
-
strict: false,
|
|
43
|
-
namespace: "es",
|
|
44
|
-
pseudoLocale: config.pseudoLocale
|
|
45
|
-
});
|
|
46
|
-
return {
|
|
47
|
-
code: compiled,
|
|
48
|
-
map: null
|
|
49
|
-
// provide source map if available
|
|
50
|
-
};
|
|
51
68
|
}
|
|
52
69
|
}
|
|
53
|
-
|
|
70
|
+
];
|
|
54
71
|
}
|
|
55
72
|
|
|
56
73
|
export { lingui as default, lingui };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/vite-plugin",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Vite plugin for Lingui message catalogs",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -39,16 +39,18 @@
|
|
|
39
39
|
"dist/"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@lingui/cli": "4.
|
|
43
|
-
"@lingui/conf": "4.
|
|
42
|
+
"@lingui/cli": "4.3.0",
|
|
43
|
+
"@lingui/conf": "4.3.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"vite": "3 - 4"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@lingui/format-json": "^4.
|
|
49
|
+
"@lingui/format-json": "^4.3.0",
|
|
50
|
+
"@lingui/macro": "^4.3.0",
|
|
50
51
|
"unbuild": "^1.1.2",
|
|
51
|
-
"vite": "4.1.4"
|
|
52
|
+
"vite": "4.1.4",
|
|
53
|
+
"vite-plugin-babel-macros": "^1.0.6"
|
|
52
54
|
},
|
|
53
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "da6c52629e978c24ec83f2a6c22e4dfc910808b4"
|
|
54
56
|
}
|