vue-i18n-extract-plugin 1.0.65 → 1.0.66
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,24 @@
|
|
|
1
|
+
name: Publish to NPM
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- name: Checkout
|
|
13
|
+
uses: actions/checkout@v2
|
|
14
|
+
|
|
15
|
+
- name: Setup Node
|
|
16
|
+
uses: actions/setup-node@v3
|
|
17
|
+
with:
|
|
18
|
+
node-version: 22
|
|
19
|
+
registry-url: "https://registry.npmjs.org"
|
|
20
|
+
|
|
21
|
+
- name: Publish package to NPM 📦
|
|
22
|
+
run: npm publish
|
|
23
|
+
env:
|
|
24
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -11,13 +11,14 @@ module.exports = function () {
|
|
|
11
11
|
i18nPkgImportPath: importPath,
|
|
12
12
|
JSXElement,
|
|
13
13
|
jsx,
|
|
14
|
-
enabled
|
|
14
|
+
enabled,
|
|
15
|
+
autoImportI18n
|
|
15
16
|
} = {
|
|
16
17
|
...defaultOptions,
|
|
17
18
|
...state.opts
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
if (!enabled) return;
|
|
21
|
+
if (!enabled || !autoImportI18n) return;
|
|
21
22
|
|
|
22
23
|
const ast = path.parentPath?.node || path.node;
|
|
23
24
|
const importNames = jsx ? [importName, JSXElement] : [importName];
|
|
@@ -19,12 +19,15 @@ function i18nImportAstTransform(ast, importName, importPath) {
|
|
|
19
19
|
|
|
20
20
|
const sourcePath = path.node.source.value;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
// 判断是否有 import { $t } from '@/i18n' 或 import $t from '@/i18n'
|
|
23
|
+
const existImport = path.node.specifiers.some(
|
|
24
|
+
spec =>
|
|
24
25
|
(t.isImportSpecifier(spec) || t.isImportDefaultSpecifier(spec)) &&
|
|
25
26
|
spec.local.name === importName
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// 判断是否是其它路径导入了 $t
|
|
30
|
+
const importedElsewhere = sourcePath !== importPath && existImport;
|
|
28
31
|
|
|
29
32
|
if (importedElsewhere) {
|
|
30
33
|
conflictDefined = true;
|
|
@@ -32,12 +35,17 @@ function i18nImportAstTransform(ast, importName, importPath) {
|
|
|
32
35
|
return;
|
|
33
36
|
}
|
|
34
37
|
|
|
38
|
+
// 检查是否已经导入目标路径
|
|
35
39
|
if (sourcePath === importPath) {
|
|
40
|
+
hasI18nImport = true;
|
|
41
|
+
|
|
42
|
+
if (existImport) return;
|
|
43
|
+
|
|
44
|
+
// 添加 $t 到已有的 import
|
|
36
45
|
path.node.specifiers.push(
|
|
37
46
|
t.importSpecifier(t.identifier(importName), t.identifier(importName))
|
|
38
47
|
);
|
|
39
48
|
|
|
40
|
-
hasI18nImport = true;
|
|
41
49
|
needTransform = true;
|
|
42
50
|
}
|
|
43
51
|
},
|
|
@@ -81,6 +89,8 @@ function i18nImportAstTransform(ast, importName, importPath) {
|
|
|
81
89
|
} else {
|
|
82
90
|
ast.program.body.unshift(importNode);
|
|
83
91
|
}
|
|
92
|
+
|
|
93
|
+
needTransform = true;
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
return {
|
|
@@ -11,7 +11,7 @@ function vitePluginImportI18n(option) {
|
|
|
11
11
|
name: "vite-plugin-import-i18n",
|
|
12
12
|
enforce: "pre",
|
|
13
13
|
async transform(code, path) {
|
|
14
|
-
if (!option.enabled || !filter(path)) return;
|
|
14
|
+
if (!option.enabled || !option.autoImportI18n || !filter(path)) return;
|
|
15
15
|
|
|
16
16
|
return i18nImportTransform(
|
|
17
17
|
code,
|