@lark-apaas/fullstack-cli 1.1.6-alpha.5 → 1.1.6-alpha.6

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-cli",
3
- "version": "1.1.6-alpha.5",
3
+ "version": "1.1.6-alpha.6",
4
4
  "description": "CLI tool for fullstack template management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -19,28 +19,28 @@ print_time() {
19
19
  }
20
20
 
21
21
  # ==================== 步骤 0 ====================
22
- echo "🗑️ [0/4] 安装插件"
22
+ echo "🗑️ [0/5] 安装插件"
23
23
  STEP_START=$(node -e "console.log(Date.now())")
24
24
  npx fullstack-cli action-plugin init
25
25
  print_time $STEP_START
26
26
  echo ""
27
27
 
28
- # ==================== 步骤 0 ====================
29
- echo "📝 [0/4] 更新 openapi 代码"
28
+ # ==================== 步骤 1 ====================
29
+ echo "📝 [1/5] 更新 openapi 代码"
30
30
  STEP_START=$(node -e "console.log(Date.now())")
31
31
  npm run gen:openapi
32
32
  print_time $STEP_START
33
33
  echo ""
34
34
 
35
- # ==================== 步骤 1 ====================
36
- echo "🗑️ [1/4] 清理 dist 目录"
35
+ # ==================== 步骤 2 ====================
36
+ echo "🗑️ [2/5] 清理 dist 目录"
37
37
  STEP_START=$(node -e "console.log(Date.now())")
38
38
  rm -rf "$ROOT_DIR/dist"
39
39
  print_time $STEP_START
40
40
  echo ""
41
41
 
42
- # ==================== 步骤 2 ====================
43
- echo "🔨 [2/4] 并行构建 server 和 client"
42
+ # ==================== 步骤 3 ====================
43
+ echo "🔨 [3/5] 并行构建 server 和 client"
44
44
  STEP_START=$(node -e "console.log(Date.now())")
45
45
 
46
46
  # 并行构建
@@ -77,8 +77,8 @@ echo " ✅ Client 构建完成"
77
77
  print_time $STEP_START
78
78
  echo ""
79
79
 
80
- # ==================== 步骤 3 ====================
81
- echo "📦 [3/4] 准备 server 依赖产物"
80
+ # ==================== 步骤 4 ====================
81
+ echo "📦 [4/5] 准备 server 依赖产物"
82
82
  STEP_START=$(node -e "console.log(Date.now())")
83
83
 
84
84
  mkdir -p "$OUT_DIR/dist/client"
@@ -96,8 +96,8 @@ rm -rf "$ROOT_DIR/dist/tsconfig.node.tsbuildinfo"
96
96
  print_time $STEP_START
97
97
  echo ""
98
98
 
99
- # ==================== 步骤 4 ====================
100
- echo "✂️ [4/4] 智能依赖裁剪"
99
+ # ==================== 步骤 5 ====================
100
+ echo "✂️ [5/5] 智能依赖裁剪"
101
101
  STEP_START=$(node -e "console.log(Date.now())")
102
102
 
103
103
  # 分析实际依赖、复制并裁剪 node_modules、生成精简的 package.json
@@ -178,9 +178,41 @@ async function smartPrune() {
178
178
  }
179
179
  }
180
180
 
181
- console.log(`📦 实际需要 ${requiredPackages.size} 个 npm 包\n`);
181
+ console.log(`📦 静态分析需要 ${requiredPackages.size} 个 npm 包`);
182
182
 
183
- // 4. 选择性复制包(只复制需要的)
183
+ // 4. 处理 actionPlugins(动态加载的插件,无法被静态分析追踪)
184
+ const originalPackage = JSON.parse(fs.readFileSync(ROOT_PACKAGE_JSON, 'utf8'));
185
+ const actionPlugins = originalPackage.actionPlugins || {};
186
+ const actionPluginNames = Object.keys(actionPlugins);
187
+
188
+ if (actionPluginNames.length > 0) {
189
+ console.log(`🔌 发现 ${actionPluginNames.length} 个 Action 插件,添加到依赖列表...`);
190
+
191
+ for (const pluginName of actionPluginNames) {
192
+ requiredPackages.add(pluginName);
193
+
194
+ // 检查插件的 peerDependencies,也添加进去
195
+ const pluginPkgPath = path.join(ROOT_NODE_MODULES, pluginName, 'package.json');
196
+ if (fs.existsSync(pluginPkgPath)) {
197
+ try {
198
+ const pluginPkg = JSON.parse(fs.readFileSync(pluginPkgPath, 'utf8'));
199
+ if (pluginPkg.peerDependencies) {
200
+ for (const peerDep of Object.keys(pluginPkg.peerDependencies)) {
201
+ requiredPackages.add(peerDep);
202
+ }
203
+ }
204
+ } catch {
205
+ // 忽略解析错误
206
+ }
207
+ }
208
+ }
209
+
210
+ console.log(` ✅ 插件: ${actionPluginNames.join(', ')}`);
211
+ }
212
+
213
+ console.log(`📦 总共需要 ${requiredPackages.size} 个 npm 包\n`);
214
+
215
+ // 5. 选择性复制包(只复制需要的)
184
216
  console.log('📋 选择性复制 node_modules(仅复制需要的包)...');
185
217
  const copyStart = Date.now();
186
218
 
@@ -192,16 +224,15 @@ async function smartPrune() {
192
224
  console.log(` 成功: ${copiedCount.success} 个包,失败: ${copiedCount.failed} 个`);
193
225
  console.log(` 硬链接: ${fileStats.hardLinks} 个文件,复制: ${fileStats.copies} 个文件\n`);
194
226
 
195
- // 5. 读取原始 package.json 并生成精简版本
196
- const originalPackage = JSON.parse(fs.readFileSync(ROOT_PACKAGE_JSON, 'utf8'));
197
-
227
+ // 6. 生成精简版 package.json
198
228
  // 优化:直接构建 dependencies,避免多次对象展开
199
229
  const prunedDependencies = {};
200
230
  const allDeps = originalPackage.dependencies || {};
201
231
  const allDevDeps = originalPackage.devDependencies || {};
202
232
 
203
233
  for (const pkg of requiredPackages) {
204
- const version = allDeps[pkg] || allDevDeps[pkg];
234
+ // 优先从 dependencies/devDependencies 获取版本,其次从 actionPlugins 获取
235
+ const version = allDeps[pkg] || allDevDeps[pkg] || actionPlugins[pkg];
205
236
  if (version) {
206
237
  prunedDependencies[pkg] = version;
207
238
  }
@@ -222,11 +253,14 @@ async function smartPrune() {
222
253
 
223
254
  const totalElapsed = Date.now() - totalStartTime;
224
255
 
225
- // 6. 输出统计信息
256
+ // 7. 输出统计信息
226
257
  console.log('='.repeat(60));
227
258
  console.log('📊 智能裁剪统计:');
228
259
  console.log('='.repeat(60));
229
260
  console.log(` 需要的包数量: ${requiredPackages.size}`);
261
+ if (actionPluginNames.length > 0) {
262
+ console.log(` Action 插件: ${actionPluginNames.length} 个`);
263
+ }
230
264
  console.log(` 成功复制: ${copiedCount.success} 个包`);
231
265
  console.log(` 失败: ${copiedCount.failed} 个包`);
232
266
  console.log(` 硬链接文件: ${fileStats.hardLinks} 个`);