@lark-apaas/fullstack-cli 1.1.13-alpha.2 → 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
|
@@ -112,9 +112,9 @@ print_time $TOTAL_START
|
|
|
112
112
|
|
|
113
113
|
# 输出产物信息
|
|
114
114
|
DIST_SIZE=$(du -sh "$OUT_DIR" | cut -f1)
|
|
115
|
-
NODE_MODULES_SIZE=$(du -sh "$
|
|
115
|
+
NODE_MODULES_SIZE=$(du -sh "$ROOT_DIR/dist/node_modules" | cut -f1)
|
|
116
116
|
echo ""
|
|
117
117
|
echo "📊 构建产物统计:"
|
|
118
|
-
echo "
|
|
118
|
+
echo " 产物大小: $DIST_SIZE"
|
|
119
119
|
echo " node_modules: $NODE_MODULES_SIZE"
|
|
120
120
|
echo ""
|
|
@@ -180,14 +180,23 @@ async function smartPrune() {
|
|
|
180
180
|
|
|
181
181
|
console.log(`📦 静态分析需要 ${requiredPackages.size} 个 npm 包`);
|
|
182
182
|
|
|
183
|
-
// 4.
|
|
183
|
+
// 4. 从 nft 结果递归收集子依赖(处理动态 require 无法被静态分析追踪的问题)
|
|
184
184
|
// 某些包(如 pdf-parse)使用 try-catch 动态加载依赖(如 @napi-rs/canvas),
|
|
185
|
-
// @vercel/nft
|
|
185
|
+
// @vercel/nft 无法追踪这类依赖,需要基于 package.json 声明补充
|
|
186
|
+
// 策略:只对 nft 已追踪到的包递归,避免收集无关依赖
|
|
186
187
|
const originalPackage = JSON.parse(fs.readFileSync(ROOT_PACKAGE_JSON, 'utf8'));
|
|
187
|
-
const projectDeps = Object.keys(originalPackage.dependencies || {});
|
|
188
188
|
|
|
189
189
|
let addedSubDeps = 0;
|
|
190
|
-
|
|
190
|
+
const visited = new Set(); // 防止循环依赖导致无限循环
|
|
191
|
+
const queue = [...requiredPackages]; // BFS 队列,从 nft 结果开始(更精准)
|
|
192
|
+
|
|
193
|
+
while (queue.length > 0) {
|
|
194
|
+
const depName = queue.shift();
|
|
195
|
+
|
|
196
|
+
// 跳过已访问的包(防止循环依赖)
|
|
197
|
+
if (visited.has(depName)) continue;
|
|
198
|
+
visited.add(depName);
|
|
199
|
+
|
|
191
200
|
const depPkgPath = path.join(ROOT_NODE_MODULES, depName, 'package.json');
|
|
192
201
|
if (!fs.existsSync(depPkgPath)) continue;
|
|
193
202
|
|
|
@@ -199,12 +208,19 @@ async function smartPrune() {
|
|
|
199
208
|
};
|
|
200
209
|
|
|
201
210
|
for (const subDep of Object.keys(subDeps)) {
|
|
211
|
+
// 检查包是否存在于 node_modules 中
|
|
212
|
+
const subDepPath = path.join(ROOT_NODE_MODULES, subDep);
|
|
213
|
+
if (!fs.existsSync(subDepPath)) continue;
|
|
214
|
+
|
|
215
|
+
// 如果是新发现的包,添加到结果集并加入队列继续遍历
|
|
202
216
|
if (!requiredPackages.has(subDep)) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
217
|
+
requiredPackages.add(subDep);
|
|
218
|
+
addedSubDeps++;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// 无论是否已在 requiredPackages 中,都需要继续遍历其子依赖
|
|
222
|
+
if (!visited.has(subDep)) {
|
|
223
|
+
queue.push(subDep);
|
|
208
224
|
}
|
|
209
225
|
}
|
|
210
226
|
} catch {
|
|
@@ -213,7 +229,7 @@ async function smartPrune() {
|
|
|
213
229
|
}
|
|
214
230
|
|
|
215
231
|
if (addedSubDeps > 0) {
|
|
216
|
-
console.log(`📦
|
|
232
|
+
console.log(`📦 递归补充动态依赖,新增 ${addedSubDeps} 个包`);
|
|
217
233
|
}
|
|
218
234
|
|
|
219
235
|
// 5. 处理 actionPlugins(动态加载的插件,无法被静态分析追踪)
|