@lingui/extractor-vue 5.9.0 → 6.0.0-next.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.d.mts +9 -1
- package/dist/index.mjs +67 -21
- package/package.json +18 -12
- package/dist/index.cjs +0 -59
- package/dist/index.d.cts +0 -5
- package/dist/index.d.ts +0 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ExtractorType } from '@lingui/conf';
|
|
2
2
|
|
|
3
|
+
interface VueExtractorConfig {
|
|
4
|
+
reactivityTransform?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare const createVueExtractor: (config?: VueExtractorConfig) => ExtractorType;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated use {@link createVueExtractor} instead
|
|
9
|
+
*/
|
|
3
10
|
declare const vueExtractor: ExtractorType;
|
|
4
11
|
|
|
5
|
-
export { vueExtractor };
|
|
12
|
+
export { createVueExtractor, vueExtractor };
|
|
13
|
+
export type { VueExtractorConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,53 @@
|
|
|
1
|
-
import { parse, compileTemplate } from '@vue/compiler-sfc';
|
|
1
|
+
import { compileScript, parse, compileTemplate } from '@vue/compiler-sfc';
|
|
2
2
|
import { extractor } from '@lingui/cli/api';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
function compileScriptSetup(descriptor, filename, reactivityTransform) {
|
|
5
|
+
const isTsScript = descriptor.script?.lang === "ts";
|
|
6
|
+
const isTsScriptSetup = descriptor.scriptSetup?.lang === "ts";
|
|
7
|
+
if (!reactivityTransform || !descriptor.scriptSetup) {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
source: descriptor.script?.content ?? "",
|
|
11
|
+
map: descriptor.script?.map,
|
|
12
|
+
isTs: isTsScript
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
source: descriptor.scriptSetup?.content ?? "",
|
|
16
|
+
map: descriptor.scriptSetup?.map,
|
|
17
|
+
isTs: isTsScriptSetup
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const compiled = compileScript(descriptor, {
|
|
23
|
+
id: filename,
|
|
24
|
+
sourceMap: true,
|
|
25
|
+
reactivityTransform
|
|
26
|
+
});
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
source: compiled.content,
|
|
30
|
+
map: compiled.map,
|
|
31
|
+
isTs: isTsScriptSetup
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
source: descriptor.script?.content ?? "",
|
|
38
|
+
map: descriptor.script?.map,
|
|
39
|
+
isTs: isTsScript
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
source: descriptor.scriptSetup.content,
|
|
43
|
+
map: descriptor.scriptSetup.map,
|
|
44
|
+
isTs: isTsScriptSetup
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const createVueExtractor = (config = {}) => ({
|
|
5
51
|
match(filename) {
|
|
6
52
|
return filename.endsWith(".vue");
|
|
7
53
|
},
|
|
@@ -12,6 +58,12 @@ const vueExtractor = {
|
|
|
12
58
|
ignoreEmpty: true
|
|
13
59
|
});
|
|
14
60
|
const isTsBlock = (block) => block?.lang === "ts";
|
|
61
|
+
const { reactivityTransform = false } = config;
|
|
62
|
+
const compiledScripts = compileScriptSetup(
|
|
63
|
+
descriptor,
|
|
64
|
+
filename,
|
|
65
|
+
reactivityTransform
|
|
66
|
+
);
|
|
15
67
|
const compiledTemplate = descriptor.template && compileTemplate({
|
|
16
68
|
source: descriptor.template.content,
|
|
17
69
|
filename,
|
|
@@ -22,25 +74,18 @@ const vueExtractor = {
|
|
|
22
74
|
}
|
|
23
75
|
});
|
|
24
76
|
const targets = [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
descriptor.scriptSetup?.content,
|
|
32
|
-
descriptor.scriptSetup?.map,
|
|
33
|
-
isTsBlock(descriptor.scriptSetup)
|
|
34
|
-
],
|
|
35
|
-
[
|
|
36
|
-
compiledTemplate?.code,
|
|
37
|
-
compiledTemplate?.map,
|
|
38
|
-
isTsBlock(descriptor.script) || isTsBlock(descriptor.scriptSetup)
|
|
39
|
-
]
|
|
77
|
+
...compiledScripts,
|
|
78
|
+
{
|
|
79
|
+
source: compiledTemplate?.code ?? "",
|
|
80
|
+
map: compiledTemplate?.map,
|
|
81
|
+
isTs: isTsBlock(descriptor.script) || isTsBlock(descriptor.scriptSetup)
|
|
82
|
+
}
|
|
40
83
|
];
|
|
41
84
|
await Promise.all(
|
|
42
|
-
targets.filter(
|
|
43
|
-
(
|
|
85
|
+
targets.filter(
|
|
86
|
+
(target) => target != null && target.source !== ""
|
|
87
|
+
).map(
|
|
88
|
+
({ source, map, isTs }) => extractor.extract(
|
|
44
89
|
filename + (isTs ? ".ts" : ""),
|
|
45
90
|
source,
|
|
46
91
|
onMessageExtracted,
|
|
@@ -52,6 +97,7 @@ const vueExtractor = {
|
|
|
52
97
|
)
|
|
53
98
|
);
|
|
54
99
|
}
|
|
55
|
-
};
|
|
100
|
+
});
|
|
101
|
+
const vueExtractor = createVueExtractor();
|
|
56
102
|
|
|
57
|
-
export { vueExtractor };
|
|
103
|
+
export { createVueExtractor, vueExtractor };
|
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/extractor-vue",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-next.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "Custom Vue.js extractor to be used with the CLI tool",
|
|
5
|
-
"main": "./dist/index.cjs",
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
6
|
"keywords": [
|
|
9
7
|
"cli",
|
|
10
8
|
"i18n",
|
|
@@ -31,25 +29,33 @@
|
|
|
31
29
|
"email": "christoffer@jahren.it"
|
|
32
30
|
},
|
|
33
31
|
"scripts": {
|
|
34
|
-
"build": "
|
|
35
|
-
"
|
|
32
|
+
"build": "unbuild",
|
|
33
|
+
"check-types": "tsc --noEmit"
|
|
36
34
|
},
|
|
37
35
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
36
|
+
"node": ">=22.19.0"
|
|
39
37
|
},
|
|
40
38
|
"files": [
|
|
41
39
|
"LICENSE",
|
|
42
40
|
"README.md",
|
|
43
41
|
"/dist"
|
|
44
42
|
],
|
|
43
|
+
"exports": {
|
|
44
|
+
".": "./dist/index.mjs"
|
|
45
|
+
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@lingui/cli": "
|
|
47
|
-
"@lingui/conf": "
|
|
47
|
+
"@lingui/cli": "6.0.0-next.0",
|
|
48
|
+
"@lingui/conf": "6.0.0-next.0",
|
|
48
49
|
"@vue/compiler-sfc": "^3.2.47"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@lingui/babel-plugin-extract-messages": "
|
|
52
|
-
"
|
|
52
|
+
"@lingui/babel-plugin-extract-messages": "6.0.0-next.0",
|
|
53
|
+
"@lingui/core": "6.0.0-next.0",
|
|
54
|
+
"unbuild": "3.6.1",
|
|
55
|
+
"vitest": "4.0.18"
|
|
56
|
+
},
|
|
57
|
+
"unbuild": {
|
|
58
|
+
"declaration": "node16"
|
|
53
59
|
},
|
|
54
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "a9576050487a4f7dfbc88db20814d5a1bb861c8c"
|
|
55
61
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const compilerSfc = require('@vue/compiler-sfc');
|
|
4
|
-
const api = require('@lingui/cli/api');
|
|
5
|
-
|
|
6
|
-
const vueExtractor = {
|
|
7
|
-
match(filename) {
|
|
8
|
-
return filename.endsWith(".vue");
|
|
9
|
-
},
|
|
10
|
-
async extract(filename, code, onMessageExtracted, ctx) {
|
|
11
|
-
const { descriptor } = compilerSfc.parse(code, {
|
|
12
|
-
sourceMap: true,
|
|
13
|
-
filename,
|
|
14
|
-
ignoreEmpty: true
|
|
15
|
-
});
|
|
16
|
-
const isTsBlock = (block) => block?.lang === "ts";
|
|
17
|
-
const compiledTemplate = descriptor.template && compilerSfc.compileTemplate({
|
|
18
|
-
source: descriptor.template.content,
|
|
19
|
-
filename,
|
|
20
|
-
inMap: descriptor.template.map,
|
|
21
|
-
id: filename,
|
|
22
|
-
compilerOptions: {
|
|
23
|
-
isTS: isTsBlock(descriptor.script) || isTsBlock(descriptor.scriptSetup)
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
const targets = [
|
|
27
|
-
[
|
|
28
|
-
descriptor.script?.content,
|
|
29
|
-
descriptor.script?.map,
|
|
30
|
-
isTsBlock(descriptor.script)
|
|
31
|
-
],
|
|
32
|
-
[
|
|
33
|
-
descriptor.scriptSetup?.content,
|
|
34
|
-
descriptor.scriptSetup?.map,
|
|
35
|
-
isTsBlock(descriptor.scriptSetup)
|
|
36
|
-
],
|
|
37
|
-
[
|
|
38
|
-
compiledTemplate?.code,
|
|
39
|
-
compiledTemplate?.map,
|
|
40
|
-
isTsBlock(descriptor.script) || isTsBlock(descriptor.scriptSetup)
|
|
41
|
-
]
|
|
42
|
-
];
|
|
43
|
-
await Promise.all(
|
|
44
|
-
targets.filter(([source]) => Boolean(source)).map(
|
|
45
|
-
([source, map, isTs]) => api.extractor.extract(
|
|
46
|
-
filename + (isTs ? ".ts" : ""),
|
|
47
|
-
source,
|
|
48
|
-
onMessageExtracted,
|
|
49
|
-
{
|
|
50
|
-
sourceMaps: map,
|
|
51
|
-
...ctx
|
|
52
|
-
}
|
|
53
|
-
)
|
|
54
|
-
)
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
exports.vueExtractor = vueExtractor;
|
package/dist/index.d.cts
DELETED