@cloudbase/manager-node 5.8.5 → 5.8.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/CHANGELOG.md +6 -0
- package/lib/deploy/StaticDeployer.js +12 -18
- package/lib/deploy/framework.js +34 -0
- package/lib/function/index.js +2 -3
- package/lib/index.js +12 -0
- package/package.json +1 -1
- package/types/deploy/StaticDeployer.d.ts +7 -3
- package/types/deploy/framework.d.ts +13 -0
- package/types/index.d.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -52,7 +52,8 @@ class StaticDeployer {
|
|
|
52
52
|
/**
|
|
53
53
|
* hosting 部署(固定静态流程,不写版本记录)
|
|
54
54
|
*
|
|
55
|
-
*
|
|
55
|
+
* 支持本地构建:buildCommand 非空时自动执行 build 后上传产物(依赖由用户自行安装,
|
|
56
|
+
* 不代为执行 npm install);
|
|
56
57
|
* 纯静态(buildCommand 空/未配置且无法检测框架)时直接上传 outputDir(默认 root,保持现状)。
|
|
57
58
|
* 访问地址 = https://{CdnDomain}{deployPath}(与 tcb hosting deploy 一致)
|
|
58
59
|
*/
|
|
@@ -63,7 +64,7 @@ class StaticDeployer {
|
|
|
63
64
|
const cloudPath = config.deployPath || '/';
|
|
64
65
|
// 1. 解析构建命令:显式 buildCommand > framework 映射 > package.json 自动探测 > null(纯静态)
|
|
65
66
|
const buildCommand = (0, framework_1.resolveBuildCommand)(config, root);
|
|
66
|
-
// 2. 有构建命令 →
|
|
67
|
+
// 2. 有构建命令 → 本地构建(仅 build,依赖由用户自行安装);纯静态 → 跳过构建直接上传
|
|
67
68
|
if (buildCommand) {
|
|
68
69
|
this.runLocalBuild(root, Object.assign(Object.assign({}, config), { buildCommand }), config.envVariables);
|
|
69
70
|
}
|
|
@@ -188,34 +189,27 @@ class StaticDeployer {
|
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
/**
|
|
191
|
-
*
|
|
192
|
+
* 本地构建(仅执行 buildCommand,不安装依赖)
|
|
193
|
+
*
|
|
194
|
+
* 只跑用户的构建命令,依赖由用户自行安装(对齐业界:Vercel/Netlify/Cloudflare
|
|
195
|
+
* 均不在本地构建时代装依赖)。installCommand 不再被本地执行 —— CLI 侧通过
|
|
196
|
+
* installCommand: '' 已可跳过云端安装;本地一律不装。
|
|
192
197
|
*
|
|
193
|
-
* - installCommand:默认 npm install,显式空字符串跳过安装
|
|
194
198
|
* - buildCommand:由调用方保证非空(hosting 经 resolveBuildCommand 判定;app local 由 if 判定)
|
|
195
199
|
* - envVariables:注入构建进程环境变量(值统一转字符串)
|
|
196
200
|
*/
|
|
197
201
|
runLocalBuild(projectPath, config, envVariables) {
|
|
198
|
-
var _a;
|
|
199
|
-
const installCommand = (_a = config.installCommand) !== null && _a !== void 0 ? _a : 'npm install';
|
|
200
202
|
const buildCommand = config.buildCommand || '';
|
|
201
203
|
const env = Object.assign(Object.assign({}, process.env), stringifyEnvValues(envVariables));
|
|
202
|
-
const commands = [];
|
|
203
|
-
if (installCommand) {
|
|
204
|
-
commands.push({ cmd: installCommand, label: '安装依赖' });
|
|
205
|
-
}
|
|
206
|
-
if (buildCommand) {
|
|
207
|
-
commands.push({ cmd: buildCommand, label: '构建' });
|
|
208
|
-
}
|
|
209
204
|
try {
|
|
210
|
-
|
|
211
|
-
(0, child_process_1.execSync)(
|
|
205
|
+
if (buildCommand) {
|
|
206
|
+
(0, child_process_1.execSync)(buildCommand, { cwd: projectPath, stdio: 'inherit', env });
|
|
212
207
|
}
|
|
213
208
|
}
|
|
214
209
|
catch (e) {
|
|
215
210
|
const detail = ((e === null || e === void 0 ? void 0 : e.stderr) || (e === null || e === void 0 ? void 0 : e.stdout) || (e === null || e === void 0 ? void 0 : e.message) || String(e)).toString().trim();
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
`请先在项目目录手动执行该命令排查原因(常见原因:npm registry 网络不可达、依赖安装权限、lockfile 不一致)。\n` +
|
|
211
|
+
throw new error_1.CloudBaseError(`本地构建失败:在 ${projectPath} 执行「${buildCommand}」失败。\n` +
|
|
212
|
+
`请先在项目目录手动执行该命令排查原因(常见原因:构建脚本报错、依赖未安装、lockfile 不一致)。\n` +
|
|
219
213
|
(detail ? `原始错误:${detail.slice(0, 500)}` : ''));
|
|
220
214
|
}
|
|
221
215
|
}
|
package/lib/deploy/framework.js
CHANGED
|
@@ -38,8 +38,10 @@ exports.detectFramework = detectFramework;
|
|
|
38
38
|
exports.resolveBuildCommand = resolveBuildCommand;
|
|
39
39
|
exports.resolveOutputDir = resolveOutputDir;
|
|
40
40
|
exports.resolveHostingOutputDir = resolveHostingOutputDir;
|
|
41
|
+
exports.buildHostingItem = buildHostingItem;
|
|
41
42
|
const fs = __importStar(require("fs"));
|
|
42
43
|
const path = __importStar(require("path"));
|
|
44
|
+
const child_process_1 = require("child_process");
|
|
43
45
|
/**
|
|
44
46
|
* 框架 → 默认构建命令映射(hosting 本地构建 / app 云端构建复用)
|
|
45
47
|
*/
|
|
@@ -228,3 +230,35 @@ function resolveHostingOutputDir(config, root, readPkgFile = defaultReadPkgFile)
|
|
|
228
230
|
}
|
|
229
231
|
return config.outputDir ? path.resolve(root, config.outputDir) : root;
|
|
230
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* 本地构建单个 hosting 项(仅执行 buildCommand,不安装依赖,不上传)
|
|
235
|
+
*
|
|
236
|
+
* 从 StaticDeployer.runLocalBuild 提炼的纯函数版:不依赖 Environment,
|
|
237
|
+
* 供 CLI 的 tcb app build 与任何需要「只构建不上传」的调用方复用,
|
|
238
|
+
* 避免各端各自复制推断/执行逻辑。buildCommand 为空 → 直接返回 null。
|
|
239
|
+
*
|
|
240
|
+
* @param config hosting 项配置(framework/buildCommand/outputDir,root 单独传参)
|
|
241
|
+
* @param root 项目目录(绝对路径)
|
|
242
|
+
* @returns 构建产物目录(resolveHostingOutputDir 结果);无可构建命令返回 null
|
|
243
|
+
* @throws 构建失败时(含 stderr 摘要)
|
|
244
|
+
*/
|
|
245
|
+
function buildHostingItem(config, root, envVariables) {
|
|
246
|
+
const buildCommand = resolveBuildCommand(config, root);
|
|
247
|
+
if (!buildCommand) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
const env = Object.assign({}, process.env);
|
|
251
|
+
if (envVariables) {
|
|
252
|
+
for (const [key, value] of Object.entries(envVariables)) {
|
|
253
|
+
env[key] = String(value);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
(0, child_process_1.execSync)(buildCommand, { cwd: root, stdio: 'inherit', env });
|
|
258
|
+
}
|
|
259
|
+
catch (e) {
|
|
260
|
+
const detail = ((e === null || e === void 0 ? void 0 : e.stderr) || (e === null || e === void 0 ? void 0 : e.stdout) || (e === null || e === void 0 ? void 0 : e.message) || String(e)).toString().trim();
|
|
261
|
+
throw new Error(`本地构建失败:在 ${root} 执行「${buildCommand}」失败。\n${detail.slice(0, 500)}`);
|
|
262
|
+
}
|
|
263
|
+
return resolveHostingOutputDir(config, root);
|
|
264
|
+
}
|
package/lib/function/index.js
CHANGED
|
@@ -1154,9 +1154,8 @@ class FunctionService {
|
|
|
1154
1154
|
const { functions, envId } = options;
|
|
1155
1155
|
const promises = functions.map(func => (async () => {
|
|
1156
1156
|
try {
|
|
1157
|
-
func.triggers.
|
|
1158
|
-
|
|
1159
|
-
});
|
|
1157
|
+
await Promise.all(func.triggers.map(trigger => this.deleteFunctionTrigger(func.name, trigger.name)));
|
|
1158
|
+
(0, utils_1.successLog)(`[${func.name}] 删除云函数触发器成功!`);
|
|
1160
1159
|
}
|
|
1161
1160
|
catch (e) {
|
|
1162
1161
|
throw new error_1.CloudBaseError(e.message);
|
package/lib/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const environmentManager_1 = require("./environmentManager");
|
|
|
4
4
|
const docs_1 = require("./docs");
|
|
5
5
|
const projectValidator_1 = require("./projectValidator");
|
|
6
6
|
const DeployOrchestrator_1 = require("./deploy/DeployOrchestrator");
|
|
7
|
+
const framework_1 = require("./deploy/framework");
|
|
7
8
|
class CloudBase {
|
|
8
9
|
/**
|
|
9
10
|
* init 初始化 为单例
|
|
@@ -188,4 +189,15 @@ class CloudBase {
|
|
|
188
189
|
return this.context.isInternalEndpoint();
|
|
189
190
|
}
|
|
190
191
|
}
|
|
192
|
+
// export = 模块只能通过 namespace 合并附加类型(TS 惯用法,规则见下)
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
194
|
+
(function (CloudBase) {
|
|
195
|
+
/**
|
|
196
|
+
* 声明式 hosting 构建推断与执行(CLI 侧 tcb app build / hosting 中立化复用,
|
|
197
|
+
* 避免各端复制同一套 framework 推断逻辑)。均为纯函数,不依赖环境上下文。
|
|
198
|
+
*/
|
|
199
|
+
CloudBase.resolveHostingBuildCommand = framework_1.resolveBuildCommand;
|
|
200
|
+
CloudBase.resolveHostingOutputDir = framework_1.resolveHostingOutputDir;
|
|
201
|
+
CloudBase.buildHosting = framework_1.buildHostingItem;
|
|
202
|
+
})(CloudBase || (CloudBase = {}));
|
|
191
203
|
module.exports = CloudBase;
|
package/package.json
CHANGED
|
@@ -69,7 +69,8 @@ export declare class StaticDeployer {
|
|
|
69
69
|
/**
|
|
70
70
|
* hosting 部署(固定静态流程,不写版本记录)
|
|
71
71
|
*
|
|
72
|
-
*
|
|
72
|
+
* 支持本地构建:buildCommand 非空时自动执行 build 后上传产物(依赖由用户自行安装,
|
|
73
|
+
* 不代为执行 npm install);
|
|
73
74
|
* 纯静态(buildCommand 空/未配置且无法检测框架)时直接上传 outputDir(默认 root,保持现状)。
|
|
74
75
|
* 访问地址 = https://{CdnDomain}{deployPath}(与 tcb hosting deploy 一致)
|
|
75
76
|
*/
|
|
@@ -94,9 +95,12 @@ export declare class StaticDeployer {
|
|
|
94
95
|
*/
|
|
95
96
|
private resolveHostingUrl;
|
|
96
97
|
/**
|
|
97
|
-
*
|
|
98
|
+
* 本地构建(仅执行 buildCommand,不安装依赖)
|
|
99
|
+
*
|
|
100
|
+
* 只跑用户的构建命令,依赖由用户自行安装(对齐业界:Vercel/Netlify/Cloudflare
|
|
101
|
+
* 均不在本地构建时代装依赖)。installCommand 不再被本地执行 —— CLI 侧通过
|
|
102
|
+
* installCommand: '' 已可跳过云端安装;本地一律不装。
|
|
98
103
|
*
|
|
99
|
-
* - installCommand:默认 npm install,显式空字符串跳过安装
|
|
100
104
|
* - buildCommand:由调用方保证非空(hosting 经 resolveBuildCommand 判定;app local 由 if 判定)
|
|
101
105
|
* - envVariables:注入构建进程环境变量(值统一转字符串)
|
|
102
106
|
*/
|
|
@@ -61,3 +61,16 @@ export declare function resolveOutputDir(config: IHostingOutputConfig, root: str
|
|
|
61
61
|
* - outputDir 未配置回退 root(纯静态直传)
|
|
62
62
|
*/
|
|
63
63
|
export declare function resolveHostingOutputDir(config: IHostingOutputConfig, root: string, readPkgFile?: ReadPkgFile): string;
|
|
64
|
+
/**
|
|
65
|
+
* 本地构建单个 hosting 项(仅执行 buildCommand,不安装依赖,不上传)
|
|
66
|
+
*
|
|
67
|
+
* 从 StaticDeployer.runLocalBuild 提炼的纯函数版:不依赖 Environment,
|
|
68
|
+
* 供 CLI 的 tcb app build 与任何需要「只构建不上传」的调用方复用,
|
|
69
|
+
* 避免各端各自复制推断/执行逻辑。buildCommand 为空 → 直接返回 null。
|
|
70
|
+
*
|
|
71
|
+
* @param config hosting 项配置(framework/buildCommand/outputDir,root 单独传参)
|
|
72
|
+
* @param root 项目目录(绝对路径)
|
|
73
|
+
* @returns 构建产物目录(resolveHostingOutputDir 结果);无可构建命令返回 null
|
|
74
|
+
* @throws 构建失败时(含 stderr 摘要)
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildHostingItem(config: IHostingOutputConfig, root: string, envVariables?: Record<string, string | number | boolean>): string | null;
|
package/types/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ import { IntegrationService } from './integration';
|
|
|
25
25
|
import { MonitorService } from './monitor';
|
|
26
26
|
import { ProjectValidator } from './projectValidator';
|
|
27
27
|
import { DeployOrchestrator } from './deploy/DeployOrchestrator';
|
|
28
|
+
import { resolveBuildCommand as frameworkResolveBuildCommand, resolveHostingOutputDir as frameworkResolveHostingOutputDir, buildHostingItem as frameworkBuildHostingItem } from './deploy/framework';
|
|
28
29
|
interface CloudBaseConfig {
|
|
29
30
|
secretId?: string;
|
|
30
31
|
secretKey?: string;
|
|
@@ -127,5 +128,12 @@ declare class CloudBase {
|
|
|
127
128
|
}
|
|
128
129
|
declare namespace CloudBase {
|
|
129
130
|
type RequestFn = CloudApiRequestFn;
|
|
131
|
+
/**
|
|
132
|
+
* 声明式 hosting 构建推断与执行(CLI 侧 tcb app build / hosting 中立化复用,
|
|
133
|
+
* 避免各端复制同一套 framework 推断逻辑)。均为纯函数,不依赖环境上下文。
|
|
134
|
+
*/
|
|
135
|
+
const resolveHostingBuildCommand: typeof frameworkResolveBuildCommand;
|
|
136
|
+
const resolveHostingOutputDir: typeof frameworkResolveHostingOutputDir;
|
|
137
|
+
const buildHosting: typeof frameworkBuildHostingItem;
|
|
130
138
|
}
|
|
131
139
|
export = CloudBase;
|