mvframe 1.1.11 → 1.1.13

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mvframe",
3
3
  "packageManager": "yarn@4.4.1",
4
- "version": "1.1.11",
4
+ "version": "1.1.13",
5
5
  "author": "matt avis",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -77,7 +77,10 @@
77
77
  ".cursor/rules"
78
78
  ],
79
79
  "peerDependencies": {
80
- "element-plus": "^2.2.0"
80
+ "vue": "^3.5.0",
81
+ "vue-router": "^4.6.0",
82
+ "pinia": "^3.0.0",
83
+ "element-plus": "^2.13.0"
81
84
  },
82
85
  "dependencies": {
83
86
  "@visactor/vtable": "^1.26.0",
@@ -85,15 +88,15 @@
85
88
  "axios": "^1.7.9",
86
89
  "dayjs": "^1.11.20",
87
90
  "flag-icons": "^7.2.3",
88
- "pinia": "^3.0.0",
89
- "vue": "^3.3.4",
90
- "vue-router": "^4.6.3",
91
91
  "vuedraggable": "^4.1.0"
92
92
  },
93
93
  "devDependencies": {
94
94
  "@vitejs/plugin-vue": "^5.2.1",
95
95
  "@vue/shared": "^3.5.25",
96
- "element-plus": "^2.13.6",
96
+ "vue": "^3.5.0",
97
+ "vue-router": "^4.6.0",
98
+ "pinia": "^3.0.0",
99
+ "element-plus": "^2.13.0",
97
100
  "rollup-plugin-terser": "^7.0.2",
98
101
  "sass-embedded": "^1.97.3",
99
102
  "unplugin-auto-import": "0.18.2",
@@ -81,6 +81,14 @@ const SCAFFOLD_SCRIPTS = {
81
81
  preview: "vite preview",
82
82
  };
83
83
 
84
+ const VITE_DEDUPE_DEPENDENCIES = ["vue", "vue-router", "pinia"];
85
+ const VITE_CONFIG_FILES = [
86
+ "vite.config.js",
87
+ "vite.config.mjs",
88
+ "vite.config.ts",
89
+ "vite.config.mts",
90
+ ];
91
+
84
92
  const TEST_DINGTALK_WEBHOOK =
85
93
  "https://oapi.dingtalk.com/robot/send?access_token=142b6ddc73e8656b7906a3cb3982836a59f430a6fe5ef619a5689eed91d5f9f7";
86
94
  const TEST_DINGTALK_SECRET =
@@ -142,6 +150,84 @@ function installDependencies(projectRoot) {
142
150
  });
143
151
  }
144
152
 
153
+ function formatDedupeArray(deps) {
154
+ return `[${deps.map((dep) => `"${dep}"`).join(", ")}]`;
155
+ }
156
+
157
+ function mergeDedupeDeps(currentBody = "") {
158
+ const current = [...currentBody.matchAll(/["']([^"']+)["']/g)].map((m) => m[1]);
159
+ return [
160
+ ...VITE_DEDUPE_DEPENDENCIES,
161
+ ...current.filter((dep) => !VITE_DEDUPE_DEPENDENCIES.includes(dep)),
162
+ ];
163
+ }
164
+
165
+ function injectViteDedupe(source) {
166
+ const dedupeRe = /dedupe\s*:\s*\[([\s\S]*?)\]/m;
167
+ if (dedupeRe.test(source)) {
168
+ return source.replace(dedupeRe, (_all, body) => {
169
+ return `dedupe: ${formatDedupeArray(mergeDedupeDeps(body))}`;
170
+ });
171
+ }
172
+
173
+ const resolveRe = /resolve\s*:\s*\{/m;
174
+ if (resolveRe.test(source)) {
175
+ return source.replace(resolveRe, (match) => {
176
+ return `${match}\n dedupe: ${formatDedupeArray(VITE_DEDUPE_DEPENDENCIES)},`;
177
+ });
178
+ }
179
+
180
+ const defineConfigRe = /defineConfig\s*\(\s*\{/m;
181
+ if (defineConfigRe.test(source)) {
182
+ return source.replace(defineConfigRe, (match) => {
183
+ return `${match}\n resolve: {\n dedupe: ${formatDedupeArray(VITE_DEDUPE_DEPENDENCIES)},\n },`;
184
+ });
185
+ }
186
+
187
+ const exportDefaultObjectRe = /export\s+default\s+\{/m;
188
+ if (exportDefaultObjectRe.test(source)) {
189
+ return source.replace(exportDefaultObjectRe, (match) => {
190
+ return `${match}\n resolve: {\n dedupe: ${formatDedupeArray(VITE_DEDUPE_DEPENDENCIES)},\n },`;
191
+ });
192
+ }
193
+
194
+ return null;
195
+ }
196
+
197
+ function findViteConfig(projectRoot) {
198
+ return VITE_CONFIG_FILES.map((file) => path.join(projectRoot, file)).find((fp) =>
199
+ fs.existsSync(fp),
200
+ );
201
+ }
202
+
203
+ function ensureViteDedupe(projectRoot) {
204
+ const fp = findViteConfig(projectRoot);
205
+ if (!fp) {
206
+ console.warn(
207
+ "[mvframe-init] 未找到 vite.config.*,请手动配置 resolve.dedupe: [\"vue\", \"vue-router\", \"pinia\"]",
208
+ );
209
+ return;
210
+ }
211
+
212
+ const current = fs.readFileSync(fp, "utf8");
213
+ const next = injectViteDedupe(current);
214
+ if (!next) {
215
+ console.warn(
216
+ `[mvframe-init] 未能自动更新 ${path.basename(fp)},请手动配置 resolve.dedupe: ["vue", "vue-router", "pinia"]`,
217
+ );
218
+ return;
219
+ }
220
+ if (next === current) {
221
+ console.log("[mvframe-init] Vite resolve.dedupe 已包含 vue / vue-router / pinia");
222
+ return;
223
+ }
224
+
225
+ fs.writeFileSync(fp, next, "utf8");
226
+ console.log(
227
+ `[mvframe-init] 已更新 ${path.basename(fp)}:resolve.dedupe 去重 vue / vue-router / pinia`,
228
+ );
229
+ }
230
+
145
231
  function main() {
146
232
  if (!fs.existsSync(target)) {
147
233
  console.error("[mvframe-init] 目录不存在:", target);
@@ -698,10 +784,13 @@ code {
698
784
  );
699
785
  }
700
786
 
701
- const viteConfig = path.join(target, "vite.config.js");
702
- if (!fs.existsSync(viteConfig) || FORCE) {
787
+ const existingViteConfig = findViteConfig(target);
788
+ const viteConfigRel = existingViteConfig
789
+ ? path.relative(target, existingViteConfig)
790
+ : "vite.config.js";
791
+ if (!existingViteConfig || FORCE) {
703
792
  write(
704
- "vite.config.js",
793
+ viteConfigRel,
705
794
  `import { defineConfig } from "vite";
706
795
  import vue from "@vitejs/plugin-vue";
707
796
  import path from "path";
@@ -733,6 +822,7 @@ export default defineConfig({
733
822
  }),
734
823
  ],
735
824
  resolve: {
825
+ dedupe: ["vue", "vue-router", "pinia"],
736
826
  alias: {
737
827
  "@": path.resolve(__dirname, "src"),
738
828
  "@cps": path.resolve(__dirname, "src/composition"),
@@ -745,6 +835,7 @@ export default defineConfig({
745
835
  `,
746
836
  );
747
837
  }
838
+ ensureViteDedupe(target);
748
839
 
749
840
  write(
750
841
  ".env.mvframe-notify.example",
@@ -816,7 +907,7 @@ yarn exec mvframe-d
816
907
 
817
908
  若需跳过对 \`package.json\` 的修改:\`node scripts/scaffold-app.js --no-package-json\` 或 \`node scripts/scaffold-app.js -n\`。
818
909
 
819
- 自动生成的 \`vite.config.js\` 已包含 \`unplugin-auto-import\`;\`dts: true\` 时类型默认写在项目根 \`auto-imports.d.ts\`。
910
+ 自动生成的 \`vite.config.js\` 已包含 \`unplugin-auto-import\`;\`dts: true\` 时类型默认写在项目根 \`auto-imports.d.ts\`。初始化脚本还会确保宿主 Vite 配置里存在 \`resolve.dedupe: ["vue", "vue-router", "pinia"]\`,避免宿主项目与 \`mvframe\` 各自解析出多份 Vue / Router / Pinia 实例。
820
911
 
821
912
  \`src/main.js\` 默认在 \`app.use(mvframe, { components: { async: ["VTable"] } })\` 中异步注册 \`VTable\`。这样只有页面实际渲染 \`<VTable>\` 时才加载 VisActor 相关 chunk,避免 \`@visactor/vtable\` 进入宿主首屏同步链。
822
913