miniprogram-ci 1.9.11 → 1.9.14
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 +3 -0
- package/README.md +13 -0
- package/dist/@types/config.d.ts +1 -1
- package/dist/@types/vendor/code-analyse/index.d.ts +11 -0
- package/dist/ci/checkCodeQuality.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/config.js +1 -1
- package/dist/core/worker_thread/task/compilejs.js +1 -1
- package/dist/manifest.json +2 -2
- package/dist/summer/plugins/base/javascript.js +1 -1
- package/dist/vendor/code-analyse/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -7,6 +7,11 @@ miniprogram-ci 是从[微信开发者工具](https://developers.weixin.qq.com/mi
|
|
|
7
7
|
miniprogram-ci 从 1.0.28 开始支持第三方平台开发的上传和预览,调用方式与普通开发模式无异。[查看详情](#第三方平台开发)
|
|
8
8
|
|
|
9
9
|
## 最近变更
|
|
10
|
+
#### 1.9.14
|
|
11
|
+
- `new` 更新 `es6` 或者 `es7` 编译时,忽略编译的文件大小阈值由 500kb 改为 2MB,即大小超过 2MB 的 js 文件不会被编译。
|
|
12
|
+
|
|
13
|
+
#### 1.9.11
|
|
14
|
+
- `new` 新增 `checkCodeQuality` 代码质量检查能力。
|
|
10
15
|
#### 1.9.10
|
|
11
16
|
- `new` 新增 支持 compileWorklet 编译选项。
|
|
12
17
|
#### 1.9.9
|
|
@@ -782,6 +787,14 @@ miniprogram-ci \
|
|
|
782
787
|
--enable-es6 true \
|
|
783
788
|
--save-path ./compiledResult.zip
|
|
784
789
|
|
|
790
|
+
#check-code-quality
|
|
791
|
+
miniprogram-ci \
|
|
792
|
+
check-code-quality \
|
|
793
|
+
--pp ./demo-proj/ \
|
|
794
|
+
--pkp ./private.YOUR_APPID.key \
|
|
795
|
+
--appid YOUR_APPID \
|
|
796
|
+
--save-path ./report.json
|
|
797
|
+
|
|
785
798
|
#pack-npm
|
|
786
799
|
miniprogram-ci \
|
|
787
800
|
pack-npm \
|
package/dist/@types/config.d.ts
CHANGED
|
@@ -154,6 +154,7 @@ declare class GraphContext {
|
|
|
154
154
|
};
|
|
155
155
|
miniprogram: {
|
|
156
156
|
useExtendedPackages: string[];
|
|
157
|
+
accountCardPackage?: IAppJSON['accountCardPackage'];
|
|
157
158
|
};
|
|
158
159
|
constructor(options: GraphOptions);
|
|
159
160
|
private initMiniprogram;
|
|
@@ -202,9 +203,19 @@ declare interface IAppJSON {
|
|
|
202
203
|
tabBar?: {
|
|
203
204
|
custom?: boolean;
|
|
204
205
|
};
|
|
206
|
+
appBar?: {
|
|
207
|
+
custom?: boolean;
|
|
208
|
+
};
|
|
205
209
|
resolveAlias?: {
|
|
206
210
|
[key: string]: string;
|
|
207
211
|
};
|
|
212
|
+
accountCardPackage?: {
|
|
213
|
+
root: string;
|
|
214
|
+
cardList: Array<{
|
|
215
|
+
type: number;
|
|
216
|
+
componentPath: string;
|
|
217
|
+
}>;
|
|
218
|
+
};
|
|
208
219
|
}
|
|
209
220
|
|
|
210
221
|
export declare type ICompilerPlugin = 'typescript' | 'less' | 'sass';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
!function(require, directRequire){
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkCodeQuality=exports.transCompileType=void 0;const tslib_1=require("tslib"),projectconfig_1=require("../core/json/projectconfig"),
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkCodeQuality=exports.transCompileType=void 0;const tslib_1=require("tslib"),projectconfig_1=require("../core/json/projectconfig"),code_analyse_1=require("../vendor/code-analyse"),path_1=tslib_1.__importDefault(require("path")),qualitycheckoption_1=tslib_1.__importDefault(require("./utils/qualitycheckoption")),locales_1=tslib_1.__importDefault(require("../utils/locales/locales")),fomatable_string_1=require("../utils/locales/fomatable_string"),codeDenpendencyQualityChecker_1=require("./utils/codeDenpendencyQualityChecker");function transCompileType(e){if("miniProgram"===e.type)return"miniprogram";if("miniProgramPlugin"===e.type)return"plugin";if("miniGame"===e.type)return"game";if("miniGamePlugin"===e.type)return"gamePlugin";throw new Error("unknown compile type "+e.type)}async function checkCodeQuality(e){const t=transCompileType(e);if("gamePlugin"===t)throw new Error("gamePlugin is not support yet!");if("game"===t)throw new Error("game is not support yet!");if("plugin"===t)throw new Error("plugin is not support yet!");const s=new QualityChecker;return await s.check({project:e}),s.getResult()}exports.transCompileType=transCompileType,exports.checkCodeQuality=checkCodeQuality;const formatDesc=(e,...t)=>{const s=locales_1.default.getLocale();e.text="en"===s?new fomatable_string_1.FormatableString(e.descEn||"").format(...t):new fomatable_string_1.FormatableString(e.desc||"").format(...t)};class QualityChecker{constructor(){this.result=[],this._checkConfig=qualitycheckoption_1.default,this.checkerHandlerMap=new Map,this._codeDepsCheckerPromise=null,this.checkJSCompressIsOpen=async(e,t)=>{var s;let c=!1;formatDesc(e);return c=!!(null===(s=(await(0,projectconfig_1.getProjectConfigJSON)(t.project)).setting)||void 0===s?void 0:s.minified),c},this.checkWXMLCompressIsOpen=async(e,t)=>{var s;let c=!1;formatDesc(e);return c=!!(null===(s=(await(0,projectconfig_1.getProjectConfigJSON)(t.project)).setting)||void 0===s?void 0:s.minifyWXML),c},this.checkWXSSCompressIsOpen=async(e,t)=>{var s;let c=!1;formatDesc(e);return c=!!(null===(s=(await(0,projectconfig_1.getProjectConfigJSON)(t.project)).setting)||void 0===s?void 0:s.minifyWXSS),c},this.checkLazyCodeLoadingIsOpen=async(e,t)=>{let s=!1;formatDesc(e);const c=await(0,projectconfig_1.getProjectConfigJSON)(t.project),{miniprogramRoot:i=""}=c,n=await t.project.getFile(i,"app.json");return s=!!JSON.parse(n.toString("utf-8")).lazyCodeLoading,s},this.checkImageAndAudioSizeLimit=async(e,t)=>{const s=await this.getCodeDepsChecker(t),c=e.limit||200,i=s.caculateResourceFileSize(this._checkConfig.regList.IMAGE_AND_AUDIO_LIMIT)/1024<c;return formatDesc(e,""+c),i},this.checkPackageSizeLimit=async(e,t)=>{const s=(await this.getCodeDepsChecker(t)).caculatePackageSize(),c=e.limit||1.5,i=1024*c;let n=!0;formatDesc(e,""+c);for(const e of Object.values(s))e/1024>i&&(n=!1);return e.detail=s,n},this.getCodeDepsChecker=async e=>{const t=e.project;return this._codeDepsCheckerPromise||(this._codeDepsCheckerPromise=new Promise((s,c)=>{let i=(0,projectconfig_1.getProjectConfigJSON)(t).miniprogramRoot;i=i?path_1.default.posix.join(t.projectPath,i):t.projectPath;const n=new code_analyse_1.Analyzer({root:i,type:"miniprogram",plugins:[]});n.analyse().then(()=>{s(new codeDenpendencyQualityChecker_1.CodeDenpendencyQualityChecker(e.project,n))}).catch(e=>{c(e)})})),this._codeDepsCheckerPromise},this.checkJSDepsOnlyUsedByOtherSubPkg=async(e,t)=>{const s=(await this.getCodeDepsChecker(t)).checkOnlyUsedByOtherPackagesJs();e.detail=s,formatDesc(e,":");let c=!0;return s.size>0&&s.files.length>0&&(c=!1),c},this.checkComponentDepsOnlyUsedByOtherSubPkg=async(e,t)=>{const s=(await this.getCodeDepsChecker(t)).checkMainPackageUnusedComponents();return e.detail=s,formatDesc(e,":"),!0},this.checkUnusedPlugins=async(e,t)=>{const s=await this.getCodeDepsChecker(t),c=await s.checkUnusedPlugins();e.detail=c;let i=!0;return formatDesc(e,""+c.join(" , ")),c.length>0&&(i=!1),i},this.checkUnusedComponents=async(e,t)=>{const s=await this.getCodeDepsChecker(t),c=await s.checkUnusedComponents();e.detail=c,formatDesc(e,":");let i=!0;return c.length>0&&(i=!1),i},this.checkUnusedCodes=async(e,t)=>{var s,c;const i=(await this.getCodeDepsChecker(t)).checkUnusedCodeFiles();e.detail=i,formatDesc(e,i.length);let n=!0;i.length>0&&(n=!1);const r=await(0,projectconfig_1.getProjectConfigJSON)(t.project);return!(!1===(null===(s=r.setting)||void 0===s?void 0:s.ignoreDevUnusedFiles)||!1===(null===(c=r.setting)||void 0===c?void 0:c.ignoreUploadUnusedFiles))||n},this.checkerHandlerMap.set("JS_COMPRESS_OPEN",this.checkJSCompressIsOpen),this.checkerHandlerMap.set("WXML_COMPRESS_OPEN",this.checkWXMLCompressIsOpen),this.checkerHandlerMap.set("WXSS_COMPRESS_OPEN",this.checkWXSSCompressIsOpen),this.checkerHandlerMap.set("LAZYCODE_LOADING_OPEN",this.checkLazyCodeLoadingIsOpen),this.checkerHandlerMap.set("IMAGE_AND_AUDIO_LIMIT",this.checkImageAndAudioSizeLimit),this.checkerHandlerMap.set("PACKAGE_SIZE_LIMIT",this.checkPackageSizeLimit),this.checkerHandlerMap.set("CONTAINS_OTHER_PKG_JS",this.checkJSDepsOnlyUsedByOtherSubPkg),this.checkerHandlerMap.set("CONTAINS_OTHER_PKG_COMPONENTS",this.checkComponentDepsOnlyUsedByOtherSubPkg),this.checkerHandlerMap.set("CONTAINS_UNUSED_COMPONENTS",this.checkUnusedComponents),this.checkerHandlerMap.set("CONTAINS_UNUSED_PLUGINS",this.checkUnusedPlugins),this.checkerHandlerMap.set("CONTAINS_UNUSED_CODES",this.checkUnusedCodes)}async check(e,t){t||(t=[...this.checkerHandlerMap.keys()]);const s=await this.getCheckList(t);return await this.checkList(s,e)}async getCheckList(e){var t;const s=new Set(e);try{return((null===(t=this._checkConfig)||void 0===t?void 0:t.checkList)||[]).filter(e=>s.has(e.name||"")).filter(e=>e.enabled)}catch(e){return console.log(e),[]}}async checkList(e,t){if(!(null==e?void 0:e.length))return[];const s=[];e.forEach(e=>{s.push(this.checkItem(e,t))});const c=await Promise.all(s);return this.result=c.filter(e=>null!==e).map(e=>{const{name:t,success:s,text:c,docURL:i,detail:n}=e;return{name:t,success:s,text:c,docURL:i,detail:n}}),this._codeDepsCheckerPromise=null,this.result}async checkItem(e,t){const s=e.name;if(s&&this.checkerHandlerMap.has(s)){const c=this.checkerHandlerMap.get(s);let i=!1;try{i=await c(e,t)}catch(e){i=!0,console.error(e)}return Object.assign(Object.assign({},e),{success:i})}return null}getResult(){return this.result}}
|
|
3
3
|
}(require("licia/lazyImport")(require), require)
|
package/dist/cli.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
!function(require, directRequire){
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),ci=tslib_1.__importStar(require("./index")),yargs_1=tslib_1.__importDefault(require("yargs")),log_1=tslib_1.__importDefault(require("./utils/log"));async function run(){let e;function o(o){return{command:o,describe:o+" commands",builder:a=>a.usage(`Usage: $0 cloud ${o} <command>`).command({command:"upload",describe:"upload files",builder:e=>e.options({env:{alias:"e",desc:"env id",string:!0,demandOption:!0},path:{alias:"p",desc:"path to the local folder",string:!0,demandOption:!0},remotePath:{alias:"rp",desc:"path to the remote folder",string:!0,demandOption:!0},concurrency:{alias:"c",desc:"concurrenct upload file count",number:!0,default:5,demandOption:!0}}).group(["env","path","remotePath"],"Options:"),handler:a=>e=e=>ci.cloud["storage"===o?"uploadStorage":"uploadStaticStorage"]({project:e,env:a.env,path:a.path,remotePath:a.remotePath})}),handler:()=>{}}}const a=yargs_1.default.usage("Usage: miniprogram-ci <command> [options]").command("$0","",a=>{a.command({command:"preview",describe:"preview project and get a preview qrcode",builder:e=>e.options("appid",{describe:"project appid",string:!0,demandOption:!0}).options("project-path",{alias:"pp",describe:"project path",string:!0,demandOption:!0}).options("private-key-path",{alias:"pkp",describe:"private key path",string:!0,demandOption:!0}),handler:()=>{}}).command({command:"upload",describe:"upload project",builder:e=>e.options("appid",{describe:"project appid",string:!0,demandOption:!0}).options("project-path",{alias:"pp",describe:"project path",string:!0,demandOption:!0}).options("private-key-path",{alias:"pkp",describe:"private key path",string:!0,demandOption:!0}),handler:()=>{}}).command({command:"get-compiled-result",describe:"get local compiled result, which will be uploaded to the server",builder:e=>e.options("appid",{describe:"project appid",string:!0,demandOption:!0}).options("project-path",{alias:"pp",describe:"project path",string:!0,demandOption:!0}).options("private-key-path",{alias:"pkp",describe:"private key path",string:!0,demandOption:!0}).options("save-path",{alias:"sp",describe:"save path",string:!0,demandOption:!0}),handler:()=>{}}).command({command:"pack-npm",describe:"pack npm modules for miniprogram",builder:e=>e.demandOption("appid").demandOption("project-path").demandOption("private-key-path"),handler:()=>{}}).command({command:"get-dev-source-map",describe:"get source map of last upload version",builder:e=>e.demandOption("appid").demandOption("project-path").demandOption("private-key-path").options("robot",{alias:"r",describe:"the robot user who is uploading the project",string:!0,default:"1",choices:["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"],demandOption:!0}).options("source-map-save-path",{describe:"path to save source map zip",string:!0,demandOption:!0}),handler:()=>{}}).command({command:"pack-npm-manually",describe:"pack npm modules with specified node_modules position",builder:e=>e.options({"pack-npm-manually-package-json-path":{desc:"path of node_modules related package.json",string:!0,demandOption:!0},"pack-npm-manually-miniprogram-npm-dist-dir":{desc:"path of target miniprogram_npm position",string:!0,demandOption:!0},ignores:{alias:"i",desc:"ignore files, glob format",array:!0,demandOption:!1}}).group(["pack-npm-manually-package-json-path","pack-npm-manually-miniprogram-npm-dist-dir","ignores"],"Options:"),handler:e=>{(async()=>{const o=await ci.packNpmManually({packageJsonPath:String(e.packNpmManuallyPackageJsonPath),miniprogramNpmDistDir:String(e.packNpmManuallyMiniprogramNpmDistDir),ignores:[]});log_1.default.log("pack npm done, pack result:",o)})()}}).command({command:"cloud",describe:"cloudbase commands",builder:a=>a.usage("Usage: $0 cloud <command>").command({command:"functions",describe:"cloudfunctions commands",builder:o=>o.usage("Usage: $0 cloud functions <command>").command({command:"upload",describe:"upload a cloudfunction",builder:e=>e.options({env:{alias:"e",desc:"env id",string:!0,demandOption:!0},name:{alias:"n",desc:"cloudfunction name",string:!0,demandOption:!0},path:{alias:"p",desc:"path to the folder containing cloudfunction code",string:!0,demandOption:!0},"remote-npm-install":{alias:"rnpm",desc:"if true, node_modules will not be uploaded and NPM dependencies will be installed in the cloud. if false, node_modules will be uploaded.",boolean:!0}}).group(["env","name","path","remote-npm-install"],"Options:"),handler:o=>e=e=>ci.cloud.uploadFunction({project:e,env:o.env,name:o.name,path:o.path,remoteNpmInstall:o["remote-npm-install"]})}),handler:()=>{}}).command(o("storage")).command(o("staticstorage")).command({command:"container",describe:"container commands",builder:o=>o.usage("Usage: $0 cloud container <command>").command({command:"create",describe:"create a version by uploading package",builder:e=>e.options({env:{alias:"e",desc:"env id",string:!0,demandOption:!0},flow:{desc:"flow ratio of this version",number:!0,demandOption:!0},cpu:{desc:"cpu cores of this version",number:!0,demandOption:!0},mem:{desc:"memory gigabytes of this version",number:!0,demandOption:!0},min:{desc:"minimal copies",number:!0,demandOption:!0},max:{desc:"maximum copies",number:!0,demandOption:!0},threshold:{desc:"cpu threshold for auto scaling",number:!0,demandOption:!0},port:{desc:"container listening port for liveness",number:!0,demandOption:!0},service:{desc:"service name",string:!0,demandOption:!0},remark:{desc:"version remark",string:!0},envParams:{desc:"stringified environment parameters Record<string, string>",string:!0,default:"{}"},allowHttp:{desc:"allow direct http request to this version",boolean:!0,default:!1},containerRoot:{alias:"cr",desc:"path to the container folder",string:!0,demandOption:!0},dockerfilePath:{desc:"custom docker file path",string:!0},buildDir:{desc:"build directory",string:!0}}).group(["env","flow","cpu","mem","min","max","threshold","port","service","remark","envParams","allowHttp","containerRoot","dockerfilePath","buildDir"],"Options:"),handler:o=>e=e=>ci.cloud.uploadContainer({project:e,env:o.env,containerRoot:o.containerRoot,version:{flowRatio:o.flow,cpu:o.cpu,mem:o.mem,minNum:o.min,maxNum:o.max,policyType:"cpu",policyThreshold:o.threshold,containerPort:o.port,serverName:o.service,uploadType:"package",buildDir:o.buildDir,envParams:o.envParams,dockerfilePath:o.dockerfilePath,useHttpRoute:o.allowHttp,versionRemark:o.remark}})}),handler:()=>{}}),handler:()=>{}}).options("appid",{describe:"project appid",string:!0}).options("project-path",{alias:"pp",describe:"project path",string:!0}).options("private-key-path",{alias:"pkp",describe:"private key path",string:!0}).options("locales",{describe:"set locales",default:"en",string:!0,choices:["en","zh"]}).option("verbose",{alias:"v",description:"run with verbose logging",default:!0,boolean:!0}).options("proxy",{describe:"proxy url",default:"",string:!0}).options("project-type",{alias:"pt",describe:"project type",string:!0,default:"miniProgram",choices:["miniProgram","miniGame","miniProgramPlugin","miniGamePlugin"]}).options("project-ignores",{alias:"pi",describe:"project ignores",array:!0}).options("upload-description",{alias:"ud",describe:"the uploaded code version description",string:!0}).options("upload-version",{alias:"uv",describe:"the uploaded code version description",string:!0,demandOption:process.argv.includes("preview")||process.argv.includes("upload")&&!process.argv.includes("cloud")}).options("threads",{describe:"the number indicates how many threads will be created for compile the source files",number:!0,default:0,demandOption:process.argv.includes("preview")||process.argv.includes("upload")&&!process.argv.includes("cloud")}).options("use-cos",{describe:"enable uploading code-package through the async way, which is more stable than the direct way",boolean:!0,default:!1,demandOption:process.argv.includes("preview")||process.argv.includes("upload")&&!process.argv.includes("cloud")}).options("robot",{alias:"r",describe:"the robot user who is uploading the project",string:!0,default:"1",choices:["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]}).options("enable-es6",{describe:"enable transform from es6 to es5",default:!1,boolean:!0}).options("enable-es7",{describe:"enable transform from es7 to es5",default:!1,boolean:!0}).options("enable-autoprefixwxss",{describe:"enable autoprefixwxss",default:!1,boolean:!0}).options("enable-minify-wxss",{describe:"enable minify wxss",default:!1,boolean:!0}).options("enable-minify-wxml",{describe:"enable minify wxml",default:!1,boolean:!0}).options("enable-minify-js",{describe:"enable minify js",default:!1,boolean:!0}).options("enable-minify",{describe:"enable minify js/wxml/wxss",default:!1,boolean:!0}).options("enable-code-protect",{describe:"enable code protect",default:!1,boolean:!0}).options("enable-qrcode",{describe:"enable generate weapp qrcode",default:!1,boolean:!0}).options("qrcode-format",{describe:"format of output qrcode",default:"terminal",string:!0,choices:["base64","image","terminal"]}).options("qrcode-output-dest",{describe:"destination of output qrcode",string:!0}).options("preview-page-path",{describe:"preview with page path",string:!0}).options("preview-search-query",{describe:'preview with query, Tips: "&" should be "\\&" in command line',string:!0}).options("scene",{describe:"preview with scene, about scene: https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html",string:!0})},e=>e).help().argv;if(a.help&&(yargs_1.default.showHelp(),process.exit(0)),a.proxy&&ci.proxy(a.proxy),ci.setLocale(a.locales),a._&&!a._.includes("pack-npm-manually")){const o=new ci.Project({appid:a.appid,projectPath:a.projectPath,privateKeyPath:a.privateKeyPath,type:a.projectType,ignores:a.projectIgnores});if(e)await e(o);else if(a._.includes("upload"))await ci.upload({project:o,setting:{es6:a.enableEs6,es7:a.enableEs7,minify:a.enableMinify,autoPrefixWXSS:a.enableHijack,minifyWXML:a.enableMinify||a.enableMinifyWxml,minifyWXSS:a.enableMinify||a.enableMinifyWxss,minifyJS:a.enableMinify||a.enableMinifyJs,codeProtect:a.enableCodeProtect},threads:a.threads,version:a.uploadVersion,desc:a.uploadDescription,robot:a.robot,onProgressUpdate:e=>{a.verbose&&log_1.default.log(""+e)}});else if(a._.includes("preview")){let e=a.scene;e&&(e=parseInt(e,10)),await ci.preview({project:o,setting:{es6:a.enableEs6,es7:a.enableEs7,minify:a.enableMinify,autoPrefixWXSS:a.enableHijack,minifyWXML:a.enableMinify||a.enableMinifyWxml,minifyWXSS:a.enableMinify||a.enableMinifyWxss,minifyJS:a.enableMinify||a.enableMinifyJs,codeProtect:a.enableCodeProtect},threads:a.threads,version:a.uploadVersion,desc:a.uploadDescription,robot:a.robot,pagePath:a.previewPagePath,searchQuery:a.previewSearchQuery,scene:e,onProgressUpdate:e=>{a.verbose&&log_1.default.log(""+e)},qrcodeFormat:a.qrcodeFormat,qrcodeOutputDest:a.qrcodeOutputDest})}else if(a._.includes("get-compiled-result")){let e=a.scene;e&&(e=parseInt(e,10)),await ci.getCompiledResult({project:o,setting:{es6:a.enableEs6,es7:a.enableEs7,minify:a.enableMinify,autoPrefixWXSS:a.enableHijack,minifyWXML:a.enableMinify||a.enableMinify,minifyWXSS:a.enableMinify||a.enableMinifyWxss,minifyJS:a.enableMinify||a.enableMinifyJs,codeProtect:a.enableCodeProtect},threads:a.threads,version:a.uploadVersion,desc:a.uploadDescription,robot:a.robot,pagePath:a.previewPagePath,searchQuery:a.previewSearchQuery,scene:e,onProgressUpdate:e=>{a.verbose&&log_1.default.log(""+e)},qrcodeFormat:a.qrcodeFormat,qrcodeOutputDest:a.qrcodeOutputDest},a.savePath)}else if(a._.includes("pack-npm")){const e=await ci.packNpm(o,{ignores:a.packNpmIgnores,reporter:e=>{a.verbose&&console.log(e)}})||[];e.length&&(log_1.default.log("Pack npm warning:"),log_1.default.log(e.map((e,o)=>`${o+1}. ${e.msg}\n \t> code: ${e.code}\n \t@ ${e.jsPath}:${e.startLine}-${e.endLine}`).join("---------------\n")))}else a._.includes("get-dev-source-map")&&(await ci.getDevSourceMap({project:o,robot:parseInt(a.robot,10),sourceMapSavePath:a.sourceMapSavePath}),log_1.default.info(`save sourcemap.zip to ${a.sourceMapSavePath} successfully`))}}run().catch(e=>{console.error(e),process.exit(1)});
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),ci=tslib_1.__importStar(require("./index")),yargs_1=tslib_1.__importDefault(require("yargs")),log_1=tslib_1.__importDefault(require("./utils/log")),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),path_1=tslib_1.__importDefault(require("path"));async function run(){let e;function a(a){return{command:a,describe:a+" commands",builder:i=>i.usage(`Usage: $0 cloud ${a} <command>`).command({command:"upload",describe:"upload files",builder:e=>e.options({env:{alias:"e",desc:"env id",string:!0,demandOption:!0},path:{alias:"p",desc:"path to the local folder",string:!0,demandOption:!0},remotePath:{alias:"rp",desc:"path to the remote folder",string:!0,demandOption:!0},concurrency:{alias:"c",desc:"concurrenct upload file count",number:!0,default:5,demandOption:!0}}).group(["env","path","remotePath"],"Options:"),handler:i=>e=e=>ci.cloud["storage"===a?"uploadStorage":"uploadStaticStorage"]({project:e,env:i.env,path:i.path,remotePath:i.remotePath})}),handler:()=>{}}}const i=yargs_1.default.usage("Usage: miniprogram-ci <command> [options]").command("$0","",i=>{i.command({command:"preview",describe:"preview project and get a preview qrcode",builder:e=>e.options("appid",{describe:"project appid",string:!0,demandOption:!0}).options("project-path",{alias:"pp",describe:"project path",string:!0,demandOption:!0}).options("private-key-path",{alias:"pkp",describe:"private key path",string:!0,demandOption:!0}),handler:()=>{}}).command({command:"upload",describe:"upload project",builder:e=>e.options("appid",{describe:"project appid",string:!0,demandOption:!0}).options("project-path",{alias:"pp",describe:"project path",string:!0,demandOption:!0}).options("private-key-path",{alias:"pkp",describe:"private key path",string:!0,demandOption:!0}),handler:()=>{}}).command({command:"get-compiled-result",describe:"get local compiled result, which will be uploaded to the server",builder:e=>e.options("appid",{describe:"project appid",string:!0,demandOption:!0}).options("project-path",{alias:"pp",describe:"project path",string:!0,demandOption:!0}).options("private-key-path",{alias:"pkp",describe:"private key path",string:!0,demandOption:!0}).options("save-path",{alias:"sp",describe:"save path",string:!0,demandOption:!0}),handler:()=>{}}).command({command:"check-code-quality",describe:"check code quality and get a json report",builder:e=>e.options("appid",{describe:"project appid",string:!0,demandOption:!0}).options("project-path",{alias:"pp",describe:"project path",string:!0,demandOption:!0}).options("private-key-path",{alias:"pkp",describe:"private key path",string:!0,demandOption:!0}).options("save-path",{alias:"sp",describe:"save path",string:!0,demandOption:!1}),handler:()=>{}}).command({command:"pack-npm",describe:"pack npm modules for miniprogram",builder:e=>e.demandOption("appid").demandOption("project-path").demandOption("private-key-path"),handler:()=>{}}).command({command:"get-dev-source-map",describe:"get source map of last upload version",builder:e=>e.demandOption("appid").demandOption("project-path").demandOption("private-key-path").options("robot",{alias:"r",describe:"the robot user who is uploading the project",string:!0,default:"1",choices:["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"],demandOption:!0}).options("source-map-save-path",{describe:"path to save source map zip",string:!0,demandOption:!0}),handler:()=>{}}).command({command:"pack-npm-manually",describe:"pack npm modules with specified node_modules position",builder:e=>e.options({"pack-npm-manually-package-json-path":{desc:"path of node_modules related package.json",string:!0,demandOption:!0},"pack-npm-manually-miniprogram-npm-dist-dir":{desc:"path of target miniprogram_npm position",string:!0,demandOption:!0},ignores:{alias:"i",desc:"ignore files, glob format",array:!0,demandOption:!1}}).group(["pack-npm-manually-package-json-path","pack-npm-manually-miniprogram-npm-dist-dir","ignores"],"Options:"),handler:e=>{(async()=>{const a=await ci.packNpmManually({packageJsonPath:String(e.packNpmManuallyPackageJsonPath),miniprogramNpmDistDir:String(e.packNpmManuallyMiniprogramNpmDistDir),ignores:[]});log_1.default.log("pack npm done, pack result:",a)})()}}).command({command:"cloud",describe:"cloudbase commands",builder:i=>i.usage("Usage: $0 cloud <command>").command({command:"functions",describe:"cloudfunctions commands",builder:a=>a.usage("Usage: $0 cloud functions <command>").command({command:"upload",describe:"upload a cloudfunction",builder:e=>e.options({env:{alias:"e",desc:"env id",string:!0,demandOption:!0},name:{alias:"n",desc:"cloudfunction name",string:!0,demandOption:!0},path:{alias:"p",desc:"path to the folder containing cloudfunction code",string:!0,demandOption:!0},"remote-npm-install":{alias:"rnpm",desc:"if true, node_modules will not be uploaded and NPM dependencies will be installed in the cloud. if false, node_modules will be uploaded.",boolean:!0}}).group(["env","name","path","remote-npm-install"],"Options:"),handler:a=>e=e=>ci.cloud.uploadFunction({project:e,env:a.env,name:a.name,path:a.path,remoteNpmInstall:a["remote-npm-install"]})}),handler:()=>{}}).command(a("storage")).command(a("staticstorage")).command({command:"container",describe:"container commands",builder:a=>a.usage("Usage: $0 cloud container <command>").command({command:"create",describe:"create a version by uploading package",builder:e=>e.options({env:{alias:"e",desc:"env id",string:!0,demandOption:!0},flow:{desc:"flow ratio of this version",number:!0,demandOption:!0},cpu:{desc:"cpu cores of this version",number:!0,demandOption:!0},mem:{desc:"memory gigabytes of this version",number:!0,demandOption:!0},min:{desc:"minimal copies",number:!0,demandOption:!0},max:{desc:"maximum copies",number:!0,demandOption:!0},threshold:{desc:"cpu threshold for auto scaling",number:!0,demandOption:!0},port:{desc:"container listening port for liveness",number:!0,demandOption:!0},service:{desc:"service name",string:!0,demandOption:!0},remark:{desc:"version remark",string:!0},envParams:{desc:"stringified environment parameters Record<string, string>",string:!0,default:"{}"},allowHttp:{desc:"allow direct http request to this version",boolean:!0,default:!1},containerRoot:{alias:"cr",desc:"path to the container folder",string:!0,demandOption:!0},dockerfilePath:{desc:"custom docker file path",string:!0},buildDir:{desc:"build directory",string:!0}}).group(["env","flow","cpu","mem","min","max","threshold","port","service","remark","envParams","allowHttp","containerRoot","dockerfilePath","buildDir"],"Options:"),handler:a=>e=e=>ci.cloud.uploadContainer({project:e,env:a.env,containerRoot:a.containerRoot,version:{flowRatio:a.flow,cpu:a.cpu,mem:a.mem,minNum:a.min,maxNum:a.max,policyType:"cpu",policyThreshold:a.threshold,containerPort:a.port,serverName:a.service,uploadType:"package",buildDir:a.buildDir,envParams:a.envParams,dockerfilePath:a.dockerfilePath,useHttpRoute:a.allowHttp,versionRemark:a.remark}})}),handler:()=>{}}),handler:()=>{}}).options("appid",{describe:"project appid",string:!0}).options("project-path",{alias:"pp",describe:"project path",string:!0}).options("private-key-path",{alias:"pkp",describe:"private key path",string:!0}).options("locales",{describe:"set locales",default:"en",string:!0,choices:["en","zh"]}).option("verbose",{alias:"v",description:"run with verbose logging",default:!0,boolean:!0}).options("proxy",{describe:"proxy url",default:"",string:!0}).options("project-type",{alias:"pt",describe:"project type",string:!0,default:"miniProgram",choices:["miniProgram","miniGame","miniProgramPlugin","miniGamePlugin"]}).options("project-ignores",{alias:"pi",describe:"project ignores",array:!0}).options("upload-description",{alias:"ud",describe:"the uploaded code version description",string:!0}).options("upload-version",{alias:"uv",describe:"the uploaded code version description",string:!0,demandOption:process.argv.includes("preview")||process.argv.includes("upload")&&!process.argv.includes("cloud")}).options("threads",{describe:"the number indicates how many threads will be created for compile the source files",number:!0,default:0,demandOption:process.argv.includes("preview")||process.argv.includes("upload")&&!process.argv.includes("cloud")}).options("use-cos",{describe:"enable uploading code-package through the async way, which is more stable than the direct way",boolean:!0,default:!1,demandOption:process.argv.includes("preview")||process.argv.includes("upload")&&!process.argv.includes("cloud")}).options("robot",{alias:"r",describe:"the robot user who is uploading the project",string:!0,default:"1",choices:["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"]}).options("enable-es6",{describe:"enable transform from es6 to es5",default:!1,boolean:!0}).options("enable-es7",{describe:"enable transform from es7 to es5",default:!1,boolean:!0}).options("enable-autoprefixwxss",{describe:"enable autoprefixwxss",default:!1,boolean:!0}).options("enable-minify-wxss",{describe:"enable minify wxss",default:!1,boolean:!0}).options("enable-minify-wxml",{describe:"enable minify wxml",default:!1,boolean:!0}).options("enable-minify-js",{describe:"enable minify js",default:!1,boolean:!0}).options("enable-minify",{describe:"enable minify js/wxml/wxss",default:!1,boolean:!0}).options("enable-code-protect",{describe:"enable code protect",default:!1,boolean:!0}).options("enable-qrcode",{describe:"enable generate weapp qrcode",default:!1,boolean:!0}).options("qrcode-format",{describe:"format of output qrcode",default:"terminal",string:!0,choices:["base64","image","terminal"]}).options("qrcode-output-dest",{describe:"destination of output qrcode",string:!0}).options("preview-page-path",{describe:"preview with page path",string:!0}).options("preview-search-query",{describe:'preview with query, Tips: "&" should be "\\&" in command line',string:!0}).options("scene",{describe:"preview with scene, about scene: https://developers.weixin.qq.com/miniprogram/dev/reference/scene-list.html",string:!0})},e=>e).help().argv;if(i.help&&(yargs_1.default.showHelp(),process.exit(0)),i.proxy&&ci.proxy(i.proxy),ci.setLocale(i.locales),i._&&!i._.includes("pack-npm-manually")){const a=new ci.Project({appid:i.appid,projectPath:i.projectPath,privateKeyPath:i.privateKeyPath,type:i.projectType,ignores:i.projectIgnores});if(e)await e(a);else if(i._.includes("upload"))await ci.upload({project:a,setting:{es6:i.enableEs6,es7:i.enableEs7,minify:i.enableMinify,autoPrefixWXSS:i.enableHijack,minifyWXML:i.enableMinify||i.enableMinifyWxml,minifyWXSS:i.enableMinify||i.enableMinifyWxss,minifyJS:i.enableMinify||i.enableMinifyJs,codeProtect:i.enableCodeProtect},threads:i.threads,version:i.uploadVersion,desc:i.uploadDescription,robot:i.robot,onProgressUpdate:e=>{i.verbose&&log_1.default.log(""+e)}});else if(i._.includes("preview")){let e=i.scene;e&&(e=parseInt(e,10)),await ci.preview({project:a,setting:{es6:i.enableEs6,es7:i.enableEs7,minify:i.enableMinify,autoPrefixWXSS:i.enableHijack,minifyWXML:i.enableMinify||i.enableMinifyWxml,minifyWXSS:i.enableMinify||i.enableMinifyWxss,minifyJS:i.enableMinify||i.enableMinifyJs,codeProtect:i.enableCodeProtect},threads:i.threads,version:i.uploadVersion,desc:i.uploadDescription,robot:i.robot,pagePath:i.previewPagePath,searchQuery:i.previewSearchQuery,scene:e,onProgressUpdate:e=>{i.verbose&&log_1.default.log(""+e)},qrcodeFormat:i.qrcodeFormat,qrcodeOutputDest:i.qrcodeOutputDest})}else if(i._.includes("get-compiled-result")){let e=i.scene;e&&(e=parseInt(e,10)),await ci.getCompiledResult({project:a,setting:{es6:i.enableEs6,es7:i.enableEs7,minify:i.enableMinify,autoPrefixWXSS:i.enableHijack,minifyWXML:i.enableMinify||i.enableMinify,minifyWXSS:i.enableMinify||i.enableMinifyWxss,minifyJS:i.enableMinify||i.enableMinifyJs,codeProtect:i.enableCodeProtect},threads:i.threads,version:i.uploadVersion,desc:i.uploadDescription,robot:i.robot,pagePath:i.previewPagePath,searchQuery:i.previewSearchQuery,scene:e,onProgressUpdate:e=>{i.verbose&&log_1.default.log(""+e)},qrcodeFormat:i.qrcodeFormat,qrcodeOutputDest:i.qrcodeOutputDest},i.savePath)}else if(i._.includes("pack-npm")){const e=await ci.packNpm(a,{ignores:i.packNpmIgnores,reporter:e=>{i.verbose&&console.log(e)}})||[];e.length&&(log_1.default.log("Pack npm warning:"),log_1.default.log(e.map((e,a)=>`${a+1}. ${e.msg}\n \t> code: ${e.code}\n \t@ ${e.jsPath}:${e.startLine}-${e.endLine}`).join("---------------\n")))}else if(i._.includes("get-dev-source-map"))await ci.getDevSourceMap({project:a,robot:parseInt(i.robot,10),sourceMapSavePath:i.sourceMapSavePath}),log_1.default.info(`save sourcemap.zip to ${i.sourceMapSavePath} successfully`);else if(i._.includes("check-code-quality")){const e=await ci.checkCodeQuality(a);i.savePath?(fs_extra_1.default.ensureDirSync(path_1.default.dirname(i.savePath)),fs_extra_1.default.writeFileSync(i.savePath,JSON.stringify(e)),log_1.default.info(`save json format report to ${i.savePath} successfully`)):console.log(e)}}}run().catch(e=>{console.error(e),process.exit(1)});
|
|
3
3
|
}(require("licia/lazyImport")(require), require)
|
package/dist/config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
!function(require, directRequire){
|
|
2
|
-
"use strict";var COMPILE_TYPE;Object.defineProperty(exports,"__esModule",{value:!0}),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="1.9.
|
|
2
|
+
"use strict";var COMPILE_TYPE;Object.defineProperty(exports,"__esModule",{value:!0}),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="1.9.14",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(_){_.miniProgram="miniProgram",_.miniProgramPlugin="miniProgramPlugin",_.miniGame="miniGame",_.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"]}};
|
|
3
3
|
}(require("licia/lazyImport")(require), require)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const tslib_1=require("tslib"),fs_1=tslib_1.__importDefault(require("fs")),path_1=tslib_1.__importDefault(require("path")),locales_1=tslib_1.__importDefault(require("../../../utils/locales/locales")),tools_1=require("../../../utils/tools"),config_1=require("../../../config"),call_func_1=require("./call_func"),log_1=tslib_1.__importDefault(require("../../../utils/log")),babel_helper_1=require("../../../utils/babel_helper"),jsonParse_1=require("../../../utils/jsonParse"),sourcemap=()=>require("source-map"),enhanceCompile=()=>require("../../js/enhance"),workletCompile=()=>require("../../js/workletCompile"),es6Compile=()=>require("../../js/es6_transform"),minifyJS=()=>require("../../js/minifyjs"),minifyJSAfterWrap=()=>require("../../js/minifyjs_after_wrap"),MAX_CODE_LENGTH=
|
|
1
|
+
"use strict";const tslib_1=require("tslib"),fs_1=tslib_1.__importDefault(require("fs")),path_1=tslib_1.__importDefault(require("path")),locales_1=tslib_1.__importDefault(require("../../../utils/locales/locales")),tools_1=require("../../../utils/tools"),config_1=require("../../../config"),call_func_1=require("./call_func"),log_1=tslib_1.__importDefault(require("../../../utils/log")),babel_helper_1=require("../../../utils/babel_helper"),jsonParse_1=require("../../../utils/jsonParse"),sourcemap=()=>require("source-map"),enhanceCompile=()=>require("../../js/enhance"),workletCompile=()=>require("../../js/workletCompile"),es6Compile=()=>require("../../js/es6_transform"),minifyJS=()=>require("../../js/minifyjs"),minifyJSAfterWrap=()=>require("../../js/minifyjs_after_wrap"),MAX_CODE_LENGTH=2048e3;async function tryGetInputSourceMap(e,r){try{const t=/\/\/[#|@] sourceMappingURL=[\s]*(\S*)[\s]*$/m.exec(e),s=path_1.default.posix.dirname(r),o=path_1.default.posix.basename(r);let i;if(null==t?void 0:t[1])if(/\.js\.map$/.test(t[1]))i=await(0,call_func_1.call)("readFileAsync",path_1.default.posix.join(s,t[1]),"utf-8");else{const e=t[1].split("base64,")[1];i=Buffer.from(e,"base64").toString()}else{const e=path_1.default.posix.join(s,o+".map");fs_1.default.existsSync(e)&&(i=await(0,call_func_1.call)("readFileAsync",e,"utf-8"))}if(i){const e=(0,jsonParse_1.jsonParse)(i);new(require("source-map").SourceMapConsumer)(e);return await insertSourcesContent(e,r),e}}catch(e){log_1.default.log(`try to get input sourcemap of ${r} catch error ${e}`)}}const insertSourcesContent=async(e,r)=>{if(Array.isArray(e.sources)&&!Array.isArray(e.sourcesContent)){const t=e.sourcesContent;try{const t=path_1.default.posix.dirname(r),s=[],o=e.sources;for(const e of o){const r=await(0,call_func_1.call)("readFileAsync",path_1.default.posix.join(t,e),"utf-8");s.push(r)}e.sourcesContent=s}catch(r){e.sourcesContent=t}}};async function compileJS(e){const{code:r,filePath:t,projectPath:s,setting:o,babelRoot:i="@babel/runtime",root:a="",babelIgnore:n=[]}=e,{es7:l,es6:c,disableUseStrict:u,compileWorklet:p}=o,f="string"==typeof r?r:(0,tools_1.bufferToUtf8String)(Buffer.from(r)),_=path_1.default.posix.join(a,t),m=o.minify||o.minifyJS;if(void 0===f)return{error:{code:config_1.FILE_NOT_UTF8,path:_,message:locales_1.default.config.FILE_NOT_UTF8.format(_)}};const b=f.length>=2048e3;let d=!1;l&&(d=(0,babel_helper_1.isIgnore)(n,t));const h=await tryGetInputSourceMap(f,path_1.default.posix.join(s,a,t));if(b||d)return{error:null,isLargeFile:b,isBabelIgnore:d,map:"object"==typeof h?JSON.stringify(h):h,code:f,helpers:[]};let g=f,j=h,y=[];if(l){const e=await require("../../js/enhance")({code:f,babelRoot:i,filePath:t,disableUseStrict:u,inputSourceMap:h});if(e.error)return{error:Object.assign(Object.assign({},e.error),{path:_})};g=e.code||"",j=e.map,y=e.helpers||[]}else if(c){const e=require("../../js/es6_transform")({code:f,filePath:t,inputSourceMap:h});if(e.error)return{error:Object.assign(Object.assign({},e.error),{path:_})};g=e.code||"",j=e.map}else if(p){if(f.includes('"worklet"')||f.includes("'worklet'")){const e=await require("../../js/workletCompile")({code:f,babelRoot:i,filePath:t,disableUseStrict:u,inputSourceMap:h});if(e.error)return{error:Object.assign(Object.assign({},e.error),{path:_})};g=e.code||"",j=e.map,y=e.helpers||[]}}if(m){if(!c&&!l){const e=require("../../js/minifyjs_after_wrap")({filePath:t,code:g,inputSourceMap:j});if(e.error)return{error:Object.assign(Object.assign({},e.error),{path:_})};g=e.code,j=e.map}else{const e=require("../../js/minifyjs")({filePath:t,code:g,useTerser:!!l,inputSourceMap:j});if(e.error)return{error:Object.assign(Object.assign({},e.error),{path:_})};g=e.code,j=e.map}}if("string"!=typeof j)try{(null==j?void 0:j.sourcesContent)&&(j.sourcesContent=j.sourcesContent.map(e=>e.replace(/\r\n/g,"\n"))),j=JSON.stringify(j)}catch(e){j=""}else j=j.replace(/\\r\\n/g,"\\n");return{error:null,isLargeFile:b,isBabelIgnore:d,map:j,code:g.replace(/\r\n/g,"\n"),helpers:y||[]}}module.exports=compileJS;
|
package/dist/manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MAX_CODE_LENGTH=void 0;const tslib_1=require("tslib"),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),path_1=tslib_1.__importDefault(require("path")),jsonParse_1=require("../../../utils/jsonParse"),sourcemap=()=>require("source-map");async function tryGetInputSourceMap(e,t){try{const s=/\/\/[#|@] sourceMappingURL=[\s]*(\S*)[\s]*$/m.exec(e),r=path_1.default.posix.dirname(t),a=path_1.default.posix.basename(t);let o;if(null==s?void 0:s[1])if(/\.js\.map$/.test(s[1]))o=await fs_extra_1.default.readFile(path_1.default.posix.join(r,s[1]),"utf-8");else{const e=s[1].split("base64,")[1];o=Buffer.from(e,"base64").toString()}else{const e=path_1.default.posix.join(r,a+".map");fs_extra_1.default.existsSync(e)&&(o=await fs_extra_1.default.readFile(e,"utf-8"))}if(o){const e=(0,jsonParse_1.jsonParse)(o);new(require("source-map").SourceMapConsumer)(e);return await insertSourcesContent(e,t),e}}catch(e){console.log(`try to get input sourcemap of ${t} catch error ${e}`)}}exports.MAX_CODE_LENGTH=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MAX_CODE_LENGTH=void 0;const tslib_1=require("tslib"),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),path_1=tslib_1.__importDefault(require("path")),jsonParse_1=require("../../../utils/jsonParse"),sourcemap=()=>require("source-map");async function tryGetInputSourceMap(e,t){try{const s=/\/\/[#|@] sourceMappingURL=[\s]*(\S*)[\s]*$/m.exec(e),r=path_1.default.posix.dirname(t),a=path_1.default.posix.basename(t);let o;if(null==s?void 0:s[1])if(/\.js\.map$/.test(s[1]))o=await fs_extra_1.default.readFile(path_1.default.posix.join(r,s[1]),"utf-8");else{const e=s[1].split("base64,")[1];o=Buffer.from(e,"base64").toString()}else{const e=path_1.default.posix.join(r,a+".map");fs_extra_1.default.existsSync(e)&&(o=await fs_extra_1.default.readFile(e,"utf-8"))}if(o){const e=(0,jsonParse_1.jsonParse)(o);new(require("source-map").SourceMapConsumer)(e);return await insertSourcesContent(e,t),e}}catch(e){console.log(`try to get input sourcemap of ${t} catch error ${e}`)}}exports.MAX_CODE_LENGTH=2048e3;const insertSourcesContent=async(e,t)=>{if(Array.isArray(e.sources)&&!Array.isArray(e.sourcesContent)){const s=e.sourcesContent;try{const s=path_1.default.posix.dirname(t),r=[],a=e.sources;for(const e of a){const t=await fs_extra_1.default.readFile(path_1.default.posix.join(s,e),"utf-8");r.push(t)}e.sourcesContent=r}catch(t){e.sourcesContent=s}}};function default_1(){return{name:"summer-javascript",async load(e,t){if(t.endsWith(".js")){const e=await fs_extra_1.default.readFile(t,{encoding:"utf-8"}),s=await tryGetInputSourceMap(e,t);return{sourceCode:e,inputMap:null!=s?s:void 0,astInfo:void 0,largeFile:e.length>=exports.MAX_CODE_LENGTH}}}}}exports.default=default_1;
|