feat: 为pnpm添加自动离线安装优化参数以提升缓存命中时的安装性能

This commit is contained in:
Lyda
2025-09-18 11:51:30 +08:00
parent 64403850ee
commit 9e3ffa7ea2

View File

@@ -20,6 +20,10 @@ inputs:
required: false
default: 'store'
optimize-install-flags:
description: '是否启用安装参数优化pnpm+store时自动使用 --offline/--prefer-offline 与 --frozen-lockfile(true/false)'
required: false
default: 'true'
cache-prefix:
description: '缓存前缀名称'
@@ -208,6 +212,18 @@ runs:
if [[ -n "$INSTALL_ARGS" ]]; then
echo " 附加安装参数: $INSTALL_ARGS"
fi
# 根据模式与缓存命中优化安装参数(尽量离线加速)
EXTRA_FLAGS=""
if [[ "${{ inputs.optimize-install-flags }}" == "true" && "${{ inputs.package-manager }}" == "pnpm" && "${{ inputs.cache-mode }}" == "store" ]]; then
if [[ "${{ steps.cache.outputs.cache-hit }}" == "true" ]]; then
# 缓存命中:使用完全离线与锁定安装,避免网络请求
EXTRA_FLAGS="--offline --frozen-lockfile"
else
# 缓存未命中:尽量离线,但允许必要网络;同时锁定避免解析差异
EXTRA_FLAGS="--prefer-offline --frozen-lockfile"
fi
echo "⚡ pnpm安装优化参数: $EXTRA_FLAGS"
fi
# 根据包管理器选择安装命令
case "${{ inputs.package-manager }}" in
"npm")
@@ -222,10 +238,10 @@ runs:
"pnpm")
if [[ "${{ inputs.force-install }}" == "true" ]]; then
echo "🔧 使用pnpm强制安装"
pnpm install --force ${INSTALL_ARGS}
pnpm install --force ${EXTRA_FLAGS} ${INSTALL_ARGS}
else
echo "🔧 使用pnpm安装"
pnpm install ${INSTALL_ARGS}
pnpm install ${EXTRA_FLAGS} ${INSTALL_ARGS}
fi
;;
"yarn")