@lark-apaas/fullstack-cli 1.1.6-alpha.4 → 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/dist/index.js +10 -13
- package/package.json +1 -1
- package/templates/scripts/build.sh +16 -9
- package/templates/scripts/prune-smart.js +41 -7
package/dist/index.js
CHANGED
|
@@ -807,23 +807,20 @@ async function installOne(nameWithVersion) {
|
|
|
807
807
|
const { name, version: requestedVersion } = parsePluginName(nameWithVersion);
|
|
808
808
|
try {
|
|
809
809
|
console.log(`[action-plugin] Installing ${name}@${requestedVersion}...`);
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
if (
|
|
810
|
+
const actualVersion = getPackageVersion(name);
|
|
811
|
+
if (actualVersion && requestedVersion !== "latest") {
|
|
812
|
+
if (actualVersion === requestedVersion) {
|
|
813
813
|
console.log(`[action-plugin] Plugin ${name}@${requestedVersion} is already installed`);
|
|
814
|
-
return { name, version:
|
|
814
|
+
return { name, version: actualVersion, success: true, skipped: true };
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
|
-
if (
|
|
818
|
-
const
|
|
819
|
-
if (
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${installedVer})`);
|
|
823
|
-
return { name, version: installedVer, success: true, skipped: true };
|
|
824
|
-
}
|
|
825
|
-
console.log(`[action-plugin] Found newer version: ${latestInfo.version} (installed: ${installedVer})`);
|
|
817
|
+
if (actualVersion && requestedVersion === "latest") {
|
|
818
|
+
const latestInfo = await getPluginVersion(name, "latest");
|
|
819
|
+
if (actualVersion === latestInfo.version) {
|
|
820
|
+
console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${actualVersion})`);
|
|
821
|
+
return { name, version: actualVersion, success: true, skipped: true };
|
|
826
822
|
}
|
|
823
|
+
console.log(`[action-plugin] Found newer version: ${latestInfo.version} (installed: ${actualVersion})`);
|
|
827
824
|
}
|
|
828
825
|
const downloadResult = await downloadPlugin(name, requestedVersion);
|
|
829
826
|
tgzPath = downloadResult.tgzPath;
|
package/package.json
CHANGED
|
@@ -19,21 +19,28 @@ print_time() {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
# ==================== 步骤 0 ====================
|
|
22
|
-
echo "
|
|
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
28
|
# ==================== 步骤 1 ====================
|
|
29
|
-
echo "
|
|
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
35
|
# ==================== 步骤 2 ====================
|
|
36
|
-
echo "
|
|
36
|
+
echo "🗑️ [2/5] 清理 dist 目录"
|
|
37
|
+
STEP_START=$(node -e "console.log(Date.now())")
|
|
38
|
+
rm -rf "$ROOT_DIR/dist"
|
|
39
|
+
print_time $STEP_START
|
|
40
|
+
echo ""
|
|
41
|
+
|
|
42
|
+
# ==================== 步骤 3 ====================
|
|
43
|
+
echo "🔨 [3/5] 并行构建 server 和 client"
|
|
37
44
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
38
45
|
|
|
39
46
|
# 并行构建
|
|
@@ -70,8 +77,8 @@ echo " ✅ Client 构建完成"
|
|
|
70
77
|
print_time $STEP_START
|
|
71
78
|
echo ""
|
|
72
79
|
|
|
73
|
-
# ==================== 步骤
|
|
74
|
-
echo "📦 [
|
|
80
|
+
# ==================== 步骤 4 ====================
|
|
81
|
+
echo "📦 [4/5] 准备 server 依赖产物"
|
|
75
82
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
76
83
|
|
|
77
84
|
mkdir -p "$OUT_DIR/dist/client"
|
|
@@ -89,8 +96,8 @@ rm -rf "$ROOT_DIR/dist/tsconfig.node.tsbuildinfo"
|
|
|
89
96
|
print_time $STEP_START
|
|
90
97
|
echo ""
|
|
91
98
|
|
|
92
|
-
# ==================== 步骤
|
|
93
|
-
echo "✂️ [
|
|
99
|
+
# ==================== 步骤 5 ====================
|
|
100
|
+
echo "✂️ [5/5] 智能依赖裁剪"
|
|
94
101
|
STEP_START=$(node -e "console.log(Date.now())")
|
|
95
102
|
|
|
96
103
|
# 分析实际依赖、复制并裁剪 node_modules、生成精简的 package.json
|
|
@@ -178,9 +178,41 @@ async function smartPrune() {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
console.log(`📦
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
//
|
|
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} 个`);
|