g-ui-web 1.4.39 → 1.4.41

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.
@@ -88,8 +88,8 @@ var init = WebAssembly.compile(E()).then(WebAssembly.instantiate).then(({ export
88
88
  });
89
89
 
90
90
  // packages/plugins/component-usage.ts
91
- var import_compiler_sfc = require("@vue/compiler-sfc");
92
- var import_compiler_dom = require("@vue/compiler-dom");
91
+ var import_fs = require("fs");
92
+ var import_path = require("path");
93
93
  function componentUsagePlugin(options = {}) {
94
94
  const { libraryName = "", reportUrl = "", extraData = {}, enableInDev = false } = options;
95
95
  const importStats = {
@@ -163,21 +163,14 @@ function componentUsagePlugin(options = {}) {
163
163
  });
164
164
  }
165
165
  if (id.endsWith(".vue")) {
166
- const { descriptor } = (0, import_compiler_sfc.parse)(code);
167
- if (descriptor.template?.ast) {
168
- const walkNode = (node) => {
169
- if (node.type === import_compiler_dom.NodeTypes.ELEMENT && node.tag?.startsWith("g-")) {
170
- const tag = node.tag;
171
- const currentCount = importStats.componentCount.get(tag) || 0;
172
- importStats.componentCount.set(tag, currentCount + 1);
173
- componentsInFile.push(tag);
174
- importStats.totalImports++;
175
- }
176
- if (Array.isArray(node.children)) {
177
- node.children.forEach(walkNode);
178
- }
179
- };
180
- descriptor.template.ast.children.forEach(walkNode);
166
+ const tagRegex = /<(g-[a-z][a-z0-9-]*)/g;
167
+ let match;
168
+ while ((match = tagRegex.exec(code)) !== null) {
169
+ const tag = match[1];
170
+ const currentCount = importStats.componentCount.get(tag) || 0;
171
+ importStats.componentCount.set(tag, currentCount + 1);
172
+ componentsInFile.push(tag);
173
+ importStats.totalImports++;
181
174
  }
182
175
  }
183
176
  if (componentsInFile.length > 0) {
@@ -189,8 +182,8 @@ function componentUsagePlugin(options = {}) {
189
182
  }
190
183
  return null;
191
184
  },
192
- // 整个构建完全结束后再统计和上报,确保所有文件都已处理
193
- async closeBundle() {
185
+ // 构建结束时发送数据
186
+ async buildEnd() {
194
187
  if (!isBuild && !enableInDev) return;
195
188
  if (hasReported) return;
196
189
  hasReported = true;
@@ -208,15 +201,11 @@ function componentUsagePlugin(options = {}) {
208
201
  topComponents: [...importStats.componentCount.entries()].sort((a, b) => b[1] - a[1]).slice(0, 20).map(([name, count]) => ({ name, count })),
209
202
  ...extraData
210
203
  };
211
- console.log("\n\u{1F4CA} \u7EC4\u4EF6\u5F15\u7528\u7EDF\u8BA1:");
212
- console.log(` \u7EC4\u4EF6\u5E93: ${libraryName}`);
213
- console.log(` \u603B\u5F15\u7528\u6B21\u6570: ${reportData.summary.totalImports}`);
214
- console.log(` \u4F7F\u7528\u7684\u7EC4\u4EF6\u6570: ${reportData.summary.uniqueComponents}`);
215
- console.log(` \u6D89\u53CA\u6587\u4EF6\u6570: ${reportData.summary.filesWithImports}`);
216
- console.log("\n Top 10 \u7EC4\u4EF6:");
217
- reportData.topComponents.slice(0, 10).forEach((item, index) => {
218
- console.log(` ${index + 1}. ${item.name}: ${item.count} \u6B21`);
219
- });
204
+ const outputPath = (0, import_path.resolve)(process.cwd(), "component-usage-report.json");
205
+ (0, import_fs.mkdirSync)((0, import_path.dirname)(outputPath), { recursive: true });
206
+ (0, import_fs.writeFileSync)(outputPath, JSON.stringify(reportData, null, 2), "utf-8");
207
+ console.log(`
208
+ \u{1F4CA} \u7EC4\u4EF6\u5F15\u7528\u7EDF\u8BA1\u62A5\u544A\u5DF2\u751F\u6210: ${outputPath}`);
220
209
  if (reportUrl) {
221
210
  try {
222
211
  const response = await fetch(reportUrl, {
@@ -62,8 +62,8 @@ var init = WebAssembly.compile(E()).then(WebAssembly.instantiate).then(({ export
62
62
  });
63
63
 
64
64
  // packages/plugins/component-usage.ts
65
- import { parse as parseSFC } from "@vue/compiler-sfc";
66
- import { NodeTypes } from "@vue/compiler-dom";
65
+ import { writeFileSync, mkdirSync } from "fs";
66
+ import { resolve, dirname } from "path";
67
67
  function componentUsagePlugin(options = {}) {
68
68
  const { libraryName = "", reportUrl = "", extraData = {}, enableInDev = false } = options;
69
69
  const importStats = {
@@ -137,21 +137,14 @@ function componentUsagePlugin(options = {}) {
137
137
  });
138
138
  }
139
139
  if (id.endsWith(".vue")) {
140
- const { descriptor } = parseSFC(code);
141
- if (descriptor.template?.ast) {
142
- const walkNode = (node) => {
143
- if (node.type === NodeTypes.ELEMENT && node.tag?.startsWith("g-")) {
144
- const tag = node.tag;
145
- const currentCount = importStats.componentCount.get(tag) || 0;
146
- importStats.componentCount.set(tag, currentCount + 1);
147
- componentsInFile.push(tag);
148
- importStats.totalImports++;
149
- }
150
- if (Array.isArray(node.children)) {
151
- node.children.forEach(walkNode);
152
- }
153
- };
154
- descriptor.template.ast.children.forEach(walkNode);
140
+ const tagRegex = /<(g-[a-z][a-z0-9-]*)/g;
141
+ let match;
142
+ while ((match = tagRegex.exec(code)) !== null) {
143
+ const tag = match[1];
144
+ const currentCount = importStats.componentCount.get(tag) || 0;
145
+ importStats.componentCount.set(tag, currentCount + 1);
146
+ componentsInFile.push(tag);
147
+ importStats.totalImports++;
155
148
  }
156
149
  }
157
150
  if (componentsInFile.length > 0) {
@@ -163,8 +156,8 @@ function componentUsagePlugin(options = {}) {
163
156
  }
164
157
  return null;
165
158
  },
166
- // 整个构建完全结束后再统计和上报,确保所有文件都已处理
167
- async closeBundle() {
159
+ // 构建结束时发送数据
160
+ async buildEnd() {
168
161
  if (!isBuild && !enableInDev) return;
169
162
  if (hasReported) return;
170
163
  hasReported = true;
@@ -182,15 +175,11 @@ function componentUsagePlugin(options = {}) {
182
175
  topComponents: [...importStats.componentCount.entries()].sort((a, b) => b[1] - a[1]).slice(0, 20).map(([name, count]) => ({ name, count })),
183
176
  ...extraData
184
177
  };
185
- console.log("\n\u{1F4CA} \u7EC4\u4EF6\u5F15\u7528\u7EDF\u8BA1:");
186
- console.log(` \u7EC4\u4EF6\u5E93: ${libraryName}`);
187
- console.log(` \u603B\u5F15\u7528\u6B21\u6570: ${reportData.summary.totalImports}`);
188
- console.log(` \u4F7F\u7528\u7684\u7EC4\u4EF6\u6570: ${reportData.summary.uniqueComponents}`);
189
- console.log(` \u6D89\u53CA\u6587\u4EF6\u6570: ${reportData.summary.filesWithImports}`);
190
- console.log("\n Top 10 \u7EC4\u4EF6:");
191
- reportData.topComponents.slice(0, 10).forEach((item, index) => {
192
- console.log(` ${index + 1}. ${item.name}: ${item.count} \u6B21`);
193
- });
178
+ const outputPath = resolve(process.cwd(), "component-usage-report.json");
179
+ mkdirSync(dirname(outputPath), { recursive: true });
180
+ writeFileSync(outputPath, JSON.stringify(reportData, null, 2), "utf-8");
181
+ console.log(`
182
+ \u{1F4CA} \u7EC4\u4EF6\u5F15\u7528\u7EDF\u8BA1\u62A5\u544A\u5DF2\u751F\u6210: ${outputPath}`);
194
183
  if (reportUrl) {
195
184
  try {
196
185
  const response = await fetch(reportUrl, {
@@ -187,7 +187,7 @@ declare function __VLS_template(): {
187
187
  contentRef: Ref<HTMLElement | undefined>;
188
188
  triggeringElementRef: Ref<any>;
189
189
  referenceElementRef: Ref<any>;
190
- }, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, ("command" | "click" | "visible-change")[], import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, {
190
+ }, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, ("click" | "visible-change" | "command")[], import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, {
191
191
  readonly disabled: boolean;
192
192
  readonly maxHeight: string | number;
193
193
  readonly size: string;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "g-ui-web",
3
3
  "private": false,
4
4
  "description": "可视化组件库",
5
- "version": "1.4.39",
5
+ "version": "1.4.41",
6
6
  "author": "wyu",
7
7
  "license": "MIT",
8
8
  "type": "module",