@cloudbase/manager-node 5.6.3 → 5.6.4

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.
@@ -290,7 +290,7 @@ class FunctionService {
290
290
  async createFunction(funcParam) {
291
291
  var _a, _b, _c;
292
292
  const { namespace } = this.getFunctionConfig();
293
- const { func, functionRootPath, force = false, base64Code, codeSecret, functionPath, deployMode } = funcParam;
293
+ const { func, functionRootPath, force = false, base64Code, codeSecret, functionPath, deployMode, code } = funcParam;
294
294
  const funcName = func.name;
295
295
  const { TopicId, LogsetId } = this.getClsServiceConfig();
296
296
  const params = configToParams({
@@ -304,20 +304,30 @@ class FunctionService {
304
304
  ClsLogsetId: LogsetId
305
305
  }
306
306
  });
307
+ const customCode = code;
308
+ const customImageCode = customCode === null || customCode === void 0 ? void 0 : customCode.ImageConfig;
309
+ const funcImageCode = (_a = params.Code) === null || _a === void 0 ? void 0 : _a.ImageConfig;
307
310
  // 根据部署方式处理 Code 参数
308
- // 优先使用显式指定的 deployMode,如果未指定但存在 imageConfig 则认为是镜像部署
309
- const isImageDeploy = deployMode === 'image' || (!deployMode && ((_a = params.Code) === null || _a === void 0 ? void 0 : _a.ImageConfig));
311
+ // 优先级:deployMode=image > 显式传入 code > 原有自动打包逻辑(base64Code/functionPath/functionRootPath)
312
+ const isImageDeploy = deployMode === 'image' || Boolean(customImageCode) || (!deployMode && Boolean(funcImageCode));
310
313
  if (isImageDeploy) {
311
- // 镜像部署:Code 参数已在 configToParams 中通过 imageConfig 设置
314
+ // 镜像部署优先使用显式 code.ImageConfig;未传时回退到 func.imageConfig(configToParams 生成)
315
+ if (customImageCode) {
316
+ params.Code = customCode;
317
+ }
312
318
  if (!((_c = (_b = params.Code) === null || _b === void 0 ? void 0 : _b.ImageConfig) === null || _c === void 0 ? void 0 : _c.ImageUri)) {
313
319
  throw new error_1.CloudBaseError('镜像部署需要配置 imageConfig.imageUri');
314
320
  }
315
- // 镜像部署的特殊配置
316
- // 镜像函数不需要 Handler
321
+ // 镜像函数不需要 Handler / InstallDependency
317
322
  delete params.Handler;
318
- // 镜像函数不需要安装依赖
319
323
  delete params.InstallDependency;
320
324
  }
325
+ else if (customCode) {
326
+ if (base64Code || functionPath || functionRootPath) {
327
+ console.warn(`[${funcName}] 检测到同时传入 code 与本地打包参数,已优先使用 code 参数`);
328
+ }
329
+ params.Code = customCode;
330
+ }
321
331
  else {
322
332
  // 代码部署:通过 getCodeParams 获取代码参数
323
333
  params.Code = await this.getCodeParams({
@@ -372,7 +382,8 @@ class FunctionService {
372
382
  functionPath,
373
383
  functionRootPath,
374
384
  codeSecret: codeSecret,
375
- deployMode: isImageDeploy ? 'image' : undefined
385
+ deployMode: isImageDeploy ? 'image' : deployMode,
386
+ code
376
387
  });
377
388
  // 等待函数状态正常
378
389
  await this.waitFunctionActive(funcName, codeSecret);
@@ -877,7 +888,7 @@ class FunctionService {
877
888
  * @memberof FunctionService
878
889
  */
879
890
  async updateFunctionCode(funcParam) {
880
- const { func, functionRootPath, base64Code, codeSecret, functionPath, deployMode } = funcParam;
891
+ const { func, functionRootPath, base64Code, codeSecret, functionPath, deployMode, code } = funcParam;
881
892
  const funcName = func.name;
882
893
  const { namespace } = this.getFunctionConfig();
883
894
  // 镜像部署:使用镜像配置更新函数代码
@@ -904,6 +915,10 @@ class FunctionService {
904
915
  });
905
916
  }
906
917
  }
918
+ const customCode = code;
919
+ if (customCode && (base64Code || functionPath || functionRootPath)) {
920
+ console.warn(`[${funcName}] 检测到同时传入 code 与本地打包参数,已优先使用 code 参数`);
921
+ }
907
922
  // 代码部署:原有逻辑
908
923
  let installDependency;
909
924
  // Node 函数默认安装依赖
@@ -912,7 +927,7 @@ class FunctionService {
912
927
  if (func.installDependency !== undefined) {
913
928
  installDependency = toBooleanString(func.installDependency);
914
929
  }
915
- const codeParams = await this.getCodeParams({
930
+ const codeParams = customCode || await this.getCodeParams({
916
931
  func,
917
932
  functionPath,
918
933
  functionRootPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "5.6.3",
3
+ "version": "5.6.4",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  import { Environment } from '../environment';
2
2
  import { IResponseInfo, ICloudFunction, ICloudFunctionV2, IFunctionLogOptions, ICloudFunctionTrigger, IFunctionInvokeRes, IFunctionLogRes, IFunctionDownloadUrlRes, IFunctionLogDetailOptions, IFunctionLogDetailRes, IFunctionLogOptionsV2, IFunctionLogResV2 } from '../interfaces';
3
- import { IFunctionInfo } from './types';
3
+ import { IFunctionInfo, IFunctionCode as IScfFunctionCode } from './types';
4
4
  export interface IFunctionCode {
5
5
  func: ICloudFunction;
6
6
  functionRootPath?: string;
@@ -18,6 +18,7 @@ export interface ICreateFunctionParam {
18
18
  functionPath?: string;
19
19
  codeSecret?: string;
20
20
  deployMode?: 'cos' | 'zip' | 'image';
21
+ code?: IScfFunctionCode;
21
22
  }
22
23
  export interface IUpdateFunctionCodeParam {
23
24
  func: ICloudFunction;
@@ -26,6 +27,7 @@ export interface IUpdateFunctionCodeParam {
26
27
  base64Code?: string;
27
28
  codeSecret?: string;
28
29
  deployMode?: 'cos' | 'zip' | 'image';
30
+ code?: IScfFunctionCode;
29
31
  }
30
32
  export interface IUpdateFunctionIncrementalCodeParam {
31
33
  func: ICloudFunction;