g-ui-web 1.4.37 → 1.4.39

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,6 +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
93
  function componentUsagePlugin(options = {}) {
92
94
  const { libraryName = "", reportUrl = "", extraData = {}, enableInDev = false } = options;
93
95
  const importStats = {
@@ -161,14 +163,21 @@ function componentUsagePlugin(options = {}) {
161
163
  });
162
164
  }
163
165
  if (id.endsWith(".vue")) {
164
- const tagRegex = /<(g-[a-z][a-z0-9-]*)/g;
165
- let match;
166
- while ((match = tagRegex.exec(code)) !== null) {
167
- const tag = match[1];
168
- const currentCount = importStats.componentCount.get(tag) || 0;
169
- importStats.componentCount.set(tag, currentCount + 1);
170
- componentsInFile.push(tag);
171
- importStats.totalImports++;
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);
172
181
  }
173
182
  }
174
183
  if (componentsInFile.length > 0) {
@@ -180,8 +189,8 @@ function componentUsagePlugin(options = {}) {
180
189
  }
181
190
  return null;
182
191
  },
183
- // 构建结束时发送数据
184
- async buildEnd() {
192
+ // 整个构建完全结束后再统计和上报,确保所有文件都已处理
193
+ async closeBundle() {
185
194
  if (!isBuild && !enableInDev) return;
186
195
  if (hasReported) return;
187
196
  hasReported = true;
@@ -62,6 +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
67
  function componentUsagePlugin(options = {}) {
66
68
  const { libraryName = "", reportUrl = "", extraData = {}, enableInDev = false } = options;
67
69
  const importStats = {
@@ -135,14 +137,21 @@ function componentUsagePlugin(options = {}) {
135
137
  });
136
138
  }
137
139
  if (id.endsWith(".vue")) {
138
- const tagRegex = /<(g-[a-z][a-z0-9-]*)/g;
139
- let match;
140
- while ((match = tagRegex.exec(code)) !== null) {
141
- const tag = match[1];
142
- const currentCount = importStats.componentCount.get(tag) || 0;
143
- importStats.componentCount.set(tag, currentCount + 1);
144
- componentsInFile.push(tag);
145
- importStats.totalImports++;
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);
146
155
  }
147
156
  }
148
157
  if (componentsInFile.length > 0) {
@@ -154,8 +163,8 @@ function componentUsagePlugin(options = {}) {
154
163
  }
155
164
  return null;
156
165
  },
157
- // 构建结束时发送数据
158
- async buildEnd() {
166
+ // 整个构建完全结束后再统计和上报,确保所有文件都已处理
167
+ async closeBundle() {
159
168
  if (!isBuild && !enableInDev) return;
160
169
  if (hasReported) return;
161
170
  hasReported = true;
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.37",
5
+ "version": "1.4.39",
6
6
  "author": "wyu",
7
7
  "license": "MIT",
8
8
  "type": "module",