miniprogram-ci 2.1.15 → 2.1.16
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 +2 -0
- package/README.md +2 -0
- package/dist/@types/config/config.d.ts +1 -1
- package/dist/ci/cos-upload.js +1 -1
- package/dist/config/config.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/dist/ci/cos-upload.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.uploadByCosSafely=exports.uploadByCos=exports.innerRequest=void 0;const tslib_1=require("tslib"),url_config_1=require("../config/url.config"),tools_1=require("../utils/tools"),request_1=require("../utils/request"),sign_1=require("../utils/sign"),pack_1=require("./utils/pack"),config_1=require("../config/config"),index_1=require("../utils/asyncTask/index"),log=tslib_1.__importStar(require("../utils/log")),jsonParse_1=require("../utils/jsonParse"),__1=require(".."),zlib=require("zlib"),crypto=require("crypto"),COS=require("cos-nodejs-sdk-v5");async function putBufferToCos(e,t){const r=new COS({Proxy:(0,request_1.getCiProxy)(),getAuthorization(e,r){r({TmpSecretId:t.secret_id,TmpSecretKey:t.secret_key,XCosSecurityToken:t.token,ExpiredTime:t.expired_time})}});try{return await new Promise((o,a)=>{r.putObject({Bucket:t.bucket,Region:"ap-shanghai",Key:t.object,Body:e,onProgress(e){}},(e,t)=>{if(e)return console.error(e),a(e.error);o(t)})})}catch(e){throw new Error("upload to cos failed: "+e.message)}}async function innerRequest(e,t){const r=await(0,request_1.request)({url:e,method:"post",body:t,headers:{"content-type":"application/json"}});let o;try{o=JSON.parse(r.body)}catch(t){const r=`request ${e} failed: resp body is not a valid json`;throw log.error(r),new Error(r)}if(0!==o.errCode){const e=`request failed, errCode: ${o.errCode}, errMsg: ${o.errMsg}`;throw log.error(e),new Error(e)}return o.data}async function uploadByCos(e,t,r,o){let a;try{const e=await(0,sign_1.getSignature)(r.privateKey,r.appid);a=await innerRequest(url_config_1.GET_UPLOAD_TOKEN,JSON.stringify({appid:r.appid,signature:e,robot:o}))}catch(e){return console.error("uploadToken error",e),{fallback:!0}}const i=e,s=crypto.randomBytes(12),n=crypto.createCipheriv("aes-256-gcm",Buffer.from(a.crypt_key,"base64"),s),u=Buffer.concat([n.update(i),n.final()]),c=n.getAuthTag(),p=Buffer.alloc(1);p.writeUInt8(c.length+s.length,0);const l=Buffer.concat([p,c,s,u]),d=Date.now();await putBufferToCos(l,a);const f=Date.now()-d,g=(0,tools_1.generateMD5)(i),_=await(0,sign_1.getSignature)(r.privateKey,r.appid),y=`${t}&task_id=${a.task_id}&new_hash=${g}&upload_cos_cost_time=${f}`;log.info("request url:",y);const w=await(0,request_1.request)({url:y,method:"post",body:zlib.gzipSync((0,pack_1.pack)({[index_1.SIGNATURE_FILE_NAME]:JSON.stringify({signature:_,version:config_1.CI_VERSION})}).buffer)});if(0!==(0,jsonParse_1.jsonRespParse)(w.body.toString(),t).errCode)throw new Error(w.body.toString());for(;;){const e=await(0,sign_1.getSignature)(r.privateKey,r.appid),t=await innerRequest(`${url_config_1.GET_ASYNC_RESULT}?task_id=${a.task_id}`,JSON.stringify({appid:r.appid,signature:e,robot:o}));if(1!==t.status){if(0===t.status)return{fallback:!1,body:t,uploadCOSCostTime:f};if(3===t.status)throw new Error(`upload failed with status ${t.status}, task not found`);throw new Error("upload failed with status "+t.status)}await new Promise(e=>{setTimeout(e,1e3)})}}async function uploadByCosSafely(e,t,r,o){let a;try{const e=await(0,sign_1.getSignature)(r.privateKey,r.appid);a=await innerRequest(url_config_1.GET_UPLOAD_INFO,JSON.stringify({appid:r.appid,signature:e,robot:o}))}catch(e){return console.error("getUploadInfo failed",e),{fallback:!0}}const i=crypto.randomBytes(12),s=crypto.createCipheriv("aes-256-gcm",Buffer.from(a.crypt_key,"base64"),i),n=Buffer.concat([s.update(e),s.final()]),u=s.getAuthTag();console.info("nonce:%s, nonce size:%d",i,i.length),console.info("tag:%s, tag size:%d",u,u.length),console.info("encrypted size:%d",n.length);const c=Buffer.alloc(1);c.writeUInt8(u.length+i.length,0);const p=Buffer.concat([c,u,i,n]),l=Date.now();try{await __1.cosUpload.uploadToCosCore({uploadBuf:p,region:"ap-shanghai",getUploadInfoFunc:async()=>a,getAuthFunc:async e=>{let t,i={},s={};switch(e.action){case"name/cos:InitiateMultipartUpload":i={uploads:""};break;case"name/cos:ListMultipartUploads":i={uploads:"",prefix:a.object},s={};break;case"name/cos:UploadPart":case"name/cos:ListParts":case"name/cos:CompleteMultipartUpload":i={uploadId:e.uploadId},s={};break;default:throw new Error("no action ")}try{const n=await(0,sign_1.getSignature)(r.privateKey,r.appid),u=await innerRequest(url_config_1.GET_UPLOAD_SIGN,JSON.stringify({appid:r.appid,signature:n,robot:o,signOpts:JSON.stringify({checksum:a.checksum,action:e.action,upload_id:e.uploadId,headers:s,params:i})}));t={Authorization:u.sign,SecurityToken:u.token,AuthExpireTime:u.expired_time}}catch(e){throw console.info("uploadToCos safely failed ,start fallback"),console.log(e),new Error("")}return t}})}catch(e){return{fallback:!0}}const d=Date.now()-l,f=(0,tools_1.generateMD5)(e),g=await(0,sign_1.getSignature)(r.privateKey,r.appid),_=`${t}&task_id=${a.task_id}&new_hash=${f}&upload_cos_cost_time=${d}`;log.info("request url:",_);const y=await(0,request_1.request)({url:_,method:"post",body:zlib.gzipSync((0,pack_1.pack)({[index_1.SIGNATURE_FILE_NAME]:JSON.stringify({signature:g,version:config_1.CI_VERSION})}).buffer)});if(0!==(0,jsonParse_1.jsonRespParse)(y.body.toString(),t).errCode)throw new Error(y.body.toString());for(;;){const e=await(0,sign_1.getSignature)(r.privateKey,r.appid),t=await innerRequest(`${url_config_1.GET_ASYNC_RESULT}?task_id=${a.task_id}`,JSON.stringify({appid:r.appid,signature:e,robot:o}));if(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.uploadByCosSafely=exports.uploadByCos=exports.innerRequest=void 0;const tslib_1=require("tslib"),url_config_1=require("../config/url.config"),tools_1=require("../utils/tools"),request_1=require("../utils/request"),sign_1=require("../utils/sign"),pack_1=require("./utils/pack"),config_1=require("../config/config"),index_1=require("../utils/asyncTask/index"),log=tslib_1.__importStar(require("../utils/log")),jsonParse_1=require("../utils/jsonParse"),__1=require(".."),zlib=require("zlib"),crypto=require("crypto"),COS=require("cos-nodejs-sdk-v5");async function putBufferToCos(e,t){const r=new COS({Proxy:(0,request_1.getCiProxy)(),getAuthorization(e,r){r({TmpSecretId:t.secret_id,TmpSecretKey:t.secret_key,XCosSecurityToken:t.token,ExpiredTime:t.expired_time})}});try{return await new Promise((o,a)=>{r.putObject({Bucket:t.bucket,Region:"ap-shanghai",Key:t.object,Body:e,onProgress(e){}},(e,t)=>{if(e)return console.error(e),a(e.error);o(t)})})}catch(e){throw new Error("upload to cos failed: "+e.message)}}async function innerRequest(e,t){const r=await(0,request_1.request)({url:e,method:"post",body:t,headers:{"content-type":"application/json"}});let o;try{o=JSON.parse(r.body)}catch(t){const r=`request ${e} failed: resp body is not a valid json`;throw log.error(r),new Error(r)}if(0!==o.errCode){const e=`request failed, errCode: ${o.errCode}, errMsg: ${o.errMsg}`;throw log.error(e),new Error(e)}return o.data}async function uploadByCos(e,t,r,o){let a;try{const e=await(0,sign_1.getSignature)(r.privateKey,r.appid);a=await innerRequest(url_config_1.GET_UPLOAD_TOKEN,JSON.stringify({appid:r.appid,signature:e,robot:o}))}catch(e){return console.error("uploadToken error",e),{fallback:!0}}const i=e,s=crypto.randomBytes(12),n=crypto.createCipheriv("aes-256-gcm",Buffer.from(a.crypt_key,"base64"),s),u=Buffer.concat([n.update(i),n.final()]),c=n.getAuthTag(),p=Buffer.alloc(1);p.writeUInt8(c.length+s.length,0);const l=Buffer.concat([p,c,s,u]),d=Date.now();await putBufferToCos(l,a);const f=Date.now()-d,g=(0,tools_1.generateMD5)(i),_=await(0,sign_1.getSignature)(r.privateKey,r.appid),y=`${t}&task_id=${a.task_id}&new_hash=${g}&upload_cos_cost_time=${f}`;log.info("request url:",y);const w=await(0,request_1.request)({url:y,method:"post",body:zlib.gzipSync((0,pack_1.pack)({[index_1.SIGNATURE_FILE_NAME]:JSON.stringify({signature:_,version:config_1.CI_VERSION})}).buffer)});if(0!==(0,jsonParse_1.jsonRespParse)(w.body.toString(),t).errCode)throw new Error(w.body.toString());for(;;){const e=await(0,sign_1.getSignature)(r.privateKey,r.appid),t=await innerRequest(`${url_config_1.GET_ASYNC_RESULT}?task_id=${a.task_id}`,JSON.stringify({appid:r.appid,signature:e,robot:o}));if(1!==t.status){if(0===t.status)return{fallback:!1,body:t,uploadCOSCostTime:f};if(3===t.status)throw new Error(`upload failed with status ${t.status}, task not found`);throw new Error("upload failed with status "+t.status)}await new Promise(e=>{setTimeout(e,1e3)})}}async function uploadByCosSafely(e,t,r,o){let a;try{const e=await(0,sign_1.getSignature)(r.privateKey,r.appid);a=await innerRequest(url_config_1.GET_UPLOAD_INFO,JSON.stringify({appid:r.appid,signature:e,robot:o}))}catch(e){return console.error("getUploadInfo failed",e),{fallback:!0}}const i=crypto.randomBytes(12),s=crypto.createCipheriv("aes-256-gcm",Buffer.from(a.crypt_key,"base64"),i),n=Buffer.concat([s.update(e),s.final()]),u=s.getAuthTag();console.info("nonce:%s, nonce size:%d",i,i.length),console.info("tag:%s, tag size:%d",u,u.length),console.info("encrypted size:%d",n.length);const c=Buffer.alloc(1);c.writeUInt8(u.length+i.length,0);const p=Buffer.concat([c,u,i,n]),l=Date.now();try{await __1.cosUpload.uploadToCosCore({uploadBuf:p,region:"ap-shanghai",getUploadInfoFunc:async()=>a,getAuthFunc:async e=>{let t,i={},s={};switch(e.action){case"name/cos:InitiateMultipartUpload":i={uploads:""};break;case"name/cos:ListMultipartUploads":i={uploads:"",prefix:a.object},s={};break;case"name/cos:UploadPart":case"name/cos:ListParts":case"name/cos:CompleteMultipartUpload":i={uploadId:e.uploadId},s={};break;default:throw new Error("no action ")}try{const n=await(0,sign_1.getSignature)(r.privateKey,r.appid),u=await innerRequest(url_config_1.GET_UPLOAD_SIGN,JSON.stringify({appid:r.appid,signature:n,robot:o,signOpts:JSON.stringify({checksum:a.checksum,action:e.action,upload_id:e.uploadId,headers:s,params:i})}));t={Authorization:u.sign,SecurityToken:u.token,AuthExpireTime:u.expired_time}}catch(e){throw console.info("uploadToCos safely failed ,start fallback"),console.log(e),new Error("")}return t}})}catch(e){return{fallback:!0}}const d=Date.now()-l,f=(0,tools_1.generateMD5)(e),g=await(0,sign_1.getSignature)(r.privateKey,r.appid),_=`${t}&task_id=${a.task_id}&new_hash=${f}&upload_cos_cost_time=${d}`;log.info("request url:",_);const y=await(0,request_1.request)({url:_,method:"post",body:zlib.gzipSync((0,pack_1.pack)({[index_1.SIGNATURE_FILE_NAME]:JSON.stringify({signature:g,version:config_1.CI_VERSION})}).buffer)});if(0!==(0,jsonParse_1.jsonRespParse)(y.body.toString(),t).errCode)throw new Error(y.body.toString());for(;;){const e=await(0,sign_1.getSignature)(r.privateKey,r.appid),t=await innerRequest(`${url_config_1.GET_ASYNC_RESULT}?task_id=${a.task_id}`,JSON.stringify({appid:r.appid,signature:e,robot:o}));if(1!==t.status){if(0===t.status)return{fallback:!1,body:t,uploadCOSCostTime:d};if(3===t.status)throw new Error(`upload failed with status ${t.status}, task not found`);throw new Error("upload failed with status "+t.status)}await new Promise(e=>{setTimeout(e,1e3)})}}exports.innerRequest=innerRequest,exports.uploadByCos=uploadByCos,exports.uploadByCosSafely=uploadByCosSafely;
|
package/dist/config/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var COMPILE_TYPE,AstType,EFilterCode;function getDefaultIgnores(e){const _=["node_modules/**/*","**/node_modules/**","**/.git/**",".git/**/*","**/.svn/**",".svn/**/*",".DS_Store","**/.DS_Store"];return"multiPlatform"===e.projectArchitecture&&_.push(exports.multiPlatformRoot+"/**/*"),_}Object.defineProperty(exports,"__esModule",{value:!0}),exports.MAX_CODE_LENGTH=exports.EFilterCode=exports.AstType=exports.compileTypeConfig=exports.getDefaultIgnores=exports.FullPkg=exports.MainPkg=exports.multiPlatformRoot=exports.extendedLibMap=exports.jsonVariablePropertyWhiteList=exports.DefaultProjectAttr=exports.TABBAR_ICON_WHITE_LIST=exports.COMPILE_TYPE=exports.APP_TYPE=exports.MINI_GAME_WORKERS_PACKAGE_ROOT=exports.MINI_GAME_MAIN_PACKAGE_ROOT=exports.MINI_PROGRAM_MAIN_PACKAGE_ROOT=exports.PROJECT_TYPE_ERROR=exports.GET_LATEST_VERSION_CGI_ERR=exports.UPLOAD_JS_SERVER_CGI_ERR=exports.CODE_PROTECT_TRANSLATE_FILENAME=exports.UPLOAD_CGI_ERR=exports.GENERATE_LOCAL_SIGNATURE_ERR=exports.GET_SIGNATURE_RAND_STRING_ERR=exports.APP_JSON_NOT_FOUND=exports.JSON_CONTENT_ERR=exports.FILE_NOT_UTF8=exports.JSON_PARSE_ERR=exports.FILE_NOT_FOUND=exports.PLUGIN_JSON_PARSE_ERR=exports.PLUGIN_JSON_CONTENT_ERR=exports.PLUGIN_JSON_FILE_NOT_FOUND=exports.GAME_PLUGIN_LIB_MD5_NOT_MATCH=exports.SUMMER_PLUGIN_CODE_ERR=exports.SUMMER_PLUGIN_ERR=exports.MINIFY_WXML_ERR=exports.POST_WXSS_ERR=exports.FILE_FLAT_ERR=exports.JS_ES6_ERR=exports.BABILI_JS_ERR=exports.UGLIFY_JS_ERR=exports.BABEL_TRANS_JS_ERR=exports.JS_NOT_FOUND=exports.WXML_NOT_FOUND=exports.PARAM_ERROR=exports.CI_VERSION=void 0,exports.CI_VERSION="2.1.
|
|
1
|
+
"use strict";var COMPILE_TYPE,AstType,EFilterCode;function getDefaultIgnores(e){const _=["node_modules/**/*","**/node_modules/**","**/.git/**",".git/**/*","**/.svn/**",".svn/**/*",".DS_Store","**/.DS_Store"];return"multiPlatform"===e.projectArchitecture&&_.push(exports.multiPlatformRoot+"/**/*"),_}Object.defineProperty(exports,"__esModule",{value:!0}),exports.MAX_CODE_LENGTH=exports.EFilterCode=exports.AstType=exports.compileTypeConfig=exports.getDefaultIgnores=exports.FullPkg=exports.MainPkg=exports.multiPlatformRoot=exports.extendedLibMap=exports.jsonVariablePropertyWhiteList=exports.DefaultProjectAttr=exports.TABBAR_ICON_WHITE_LIST=exports.COMPILE_TYPE=exports.APP_TYPE=exports.MINI_GAME_WORKERS_PACKAGE_ROOT=exports.MINI_GAME_MAIN_PACKAGE_ROOT=exports.MINI_PROGRAM_MAIN_PACKAGE_ROOT=exports.PROJECT_TYPE_ERROR=exports.GET_LATEST_VERSION_CGI_ERR=exports.UPLOAD_JS_SERVER_CGI_ERR=exports.CODE_PROTECT_TRANSLATE_FILENAME=exports.UPLOAD_CGI_ERR=exports.GENERATE_LOCAL_SIGNATURE_ERR=exports.GET_SIGNATURE_RAND_STRING_ERR=exports.APP_JSON_NOT_FOUND=exports.JSON_CONTENT_ERR=exports.FILE_NOT_UTF8=exports.JSON_PARSE_ERR=exports.FILE_NOT_FOUND=exports.PLUGIN_JSON_PARSE_ERR=exports.PLUGIN_JSON_CONTENT_ERR=exports.PLUGIN_JSON_FILE_NOT_FOUND=exports.GAME_PLUGIN_LIB_MD5_NOT_MATCH=exports.SUMMER_PLUGIN_CODE_ERR=exports.SUMMER_PLUGIN_ERR=exports.MINIFY_WXML_ERR=exports.POST_WXSS_ERR=exports.FILE_FLAT_ERR=exports.JS_ES6_ERR=exports.BABILI_JS_ERR=exports.UGLIFY_JS_ERR=exports.BABEL_TRANS_JS_ERR=exports.JS_NOT_FOUND=exports.WXML_NOT_FOUND=exports.PARAM_ERROR=exports.CI_VERSION=void 0,exports.CI_VERSION="2.1.16",exports.PARAM_ERROR=1e4,exports.WXML_NOT_FOUND=10007,exports.JS_NOT_FOUND=10008,exports.BABEL_TRANS_JS_ERR=10032,exports.UGLIFY_JS_ERR=10033,exports.BABILI_JS_ERR=10034,exports.JS_ES6_ERR=10035,exports.FILE_FLAT_ERR=10036,exports.POST_WXSS_ERR=10037,exports.MINIFY_WXML_ERR=10038,exports.SUMMER_PLUGIN_ERR=10045,exports.SUMMER_PLUGIN_CODE_ERR=10046,exports.GAME_PLUGIN_LIB_MD5_NOT_MATCH=10081,exports.PLUGIN_JSON_FILE_NOT_FOUND=10091,exports.PLUGIN_JSON_CONTENT_ERR=10092,exports.PLUGIN_JSON_PARSE_ERR=10093,exports.FILE_NOT_FOUND=10005,exports.JSON_PARSE_ERR=10006,exports.FILE_NOT_UTF8=10031,exports.JSON_CONTENT_ERR=10009,exports.APP_JSON_NOT_FOUND=2e4,exports.GET_SIGNATURE_RAND_STRING_ERR=20001,exports.GENERATE_LOCAL_SIGNATURE_ERR=20002,exports.UPLOAD_CGI_ERR=20003,exports.CODE_PROTECT_TRANSLATE_FILENAME=20004,exports.UPLOAD_JS_SERVER_CGI_ERR=20005,exports.GET_LATEST_VERSION_CGI_ERR=20006,exports.PROJECT_TYPE_ERROR=3e4,exports.MINI_PROGRAM_MAIN_PACKAGE_ROOT="__APP__",exports.MINI_GAME_MAIN_PACKAGE_ROOT="__GAME__",exports.MINI_GAME_WORKERS_PACKAGE_ROOT="workers.js",exports.APP_TYPE={NORMAL:0,PLUGIN:1,SHOP:2,MINISHOP:3,GAME:4,CARD:5,NATIVE:7},function(e){e.miniProgram="miniProgram",e.miniProgramPlugin="miniProgramPlugin",e.miniGame="miniGame",e.miniGamePlugin="miniGamePlugin"}(COMPILE_TYPE=exports.COMPILE_TYPE||(exports.COMPILE_TYPE={})),exports.TABBAR_ICON_WHITE_LIST=[".png",".jpg",".jpeg"],exports.DefaultProjectAttr={platform:!1,appType:0,isSandbox:!1,released:!1,setting:{MaxCodeSize:2,MaxSubpackageSubCodeSize:2,MaxSubpackageFullCodeSize:12,NavigateMiniprogramLimit:10,MaxSubPackageLimit:100,MinTabbarCount:2,MaxTabbarCount:5,MaxCustomTabbarCount:10,MaxTabbarIconSize:40}},exports.jsonVariablePropertyWhiteList={windowPropertWhiteList:["navigationBarBackgroundColor","navigationBarTextStyle","backgroundColor","backgroundTextStyle","backgroundColorTop","backgroundColorBottom","backgroundColorContent"],tabBarPropertyWhiteList:["color","selectedColor","backgroundColor","borderStyle"],tabbarListItemPropertyWhiteList:["iconPath","selectedIconPath"]},exports.extendedLibMap={kbone:{packages:["miniprogram-element","miniprogram-render"]},weui:{packages:["weui-miniprogram"]}},exports.multiPlatformRoot="miniapp",exports.MainPkg="__APP__",exports.FullPkg="__FULL__",exports.getDefaultIgnores=getDefaultIgnores,exports.compileTypeConfig={weapp:"weapp",game:"game",plugin:"plugin",gamePlugin:"gamePlugin"},function(e){e.Babel="babel",e.Acorn="acorn"}(AstType=exports.AstType||(exports.AstType={})),function(e){e[e.Include=0]="Include",e[e.PackOptionsIgnore=1]="PackOptionsIgnore",e[e.AnalyseNoUse=2]="AnalyseNoUse",e[e.PartialCompileNoUse=3]="PartialCompileNoUse"}(EFilterCode=exports.EFilterCode||(exports.EFilterCode={})),exports.MAX_CODE_LENGTH=2048e3;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miniprogram-ci",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.16",
|
|
4
4
|
"description": "Module that build miniprogram project for web or app extracted from WeChatDevtools.",
|
|
5
5
|
"homepage": "https://developers.weixin.qq.com/community/homepage",
|
|
6
6
|
"main": "dist/index.js",
|