miniprogram-ci 2.0.9 → 2.0.10
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/@types/modules/corecompiler/original/validate/schemaValidate.d.ts +1 -1
- package/dist/@types/modules/corecompiler/original/workerThread/task/minifywxml.d.ts +21 -25
- package/dist/@types/modules/corecompiler/summer/graph/basegraph.d.ts +1 -0
- package/dist/@types/modules/corecompiler/summer/module.d.ts +20 -14
- package/dist/@types/modules/corecompiler/summerCompiler.d.ts +1 -3
- package/dist/@types/modules/index.d.ts +2 -0
- package/dist/@types/modules/nativecompiler/index.d.ts +1 -0
- package/dist/@types/modules/nativecompiler/ios/buildCloud.d.ts +9 -2
- package/dist/@types/modules/nativecompiler/ios/index.d.ts +2 -0
- package/dist/@types/modules/nativecompiler/nativeCompiler.d.ts +3 -0
- package/dist/@types/schema/@types/appjson.d.ts +215 -0
- package/dist/@types/schema/@types/extjson.d.ts +82 -0
- package/dist/@types/schema/@types/gamejson.d.ts +55 -0
- package/dist/@types/schema/@types/pagejson.d.ts +47 -0
- package/dist/@types/schema/@types/pluginjson.d.ts +17 -0
- package/dist/@types/schema/@types/pluginpagejson.d.ts +5 -0
- package/dist/@types/schema/@types/projectconfigjson.d.ts +194 -0
- package/dist/@types/schema/@types/projectprivateconfigjson.d.ts +114 -0
- package/dist/@types/schema/@types/sitemapjson.d.ts +10 -0
- package/dist/@types/schema/@types/themejson.d.ts +8 -0
- package/dist/@types/schema/src/index.d.ts +60 -0
- package/dist/@types/types/core.d.ts +2 -2
- package/dist/@types/types/devtools.d.ts +12 -0
- package/dist/@types/types/miniapp/index.d.ts +5 -0
- package/dist/@types/types/summer.d.ts +1 -0
- package/dist/@types/utils/miniapp-builder.d.ts +6 -1
- package/dist/@types/utils/tools.d.ts +1 -0
- package/dist/@types/utils/usbProcess.d.ts +3 -0
- package/dist/config/config.js +1 -1
- package/dist/modules/corecompiler/original/workerThread/task/index.js +1 -1
- package/dist/modules/corecompiler/original/workerThread/task/minifywxml.js +1 -1
- package/dist/modules/corecompiler/originalCompiler.js +1 -1
- package/dist/modules/corecompiler/summer/graph/appgraph.js +1 -1
- package/dist/modules/corecompiler/summer/graph/basegraph.js +1 -1
- package/dist/modules/corecompiler/summer/module.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/base/es6module.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/base/javascript.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/base/swc.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/base/wxss.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/enhance.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/less.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/minifywxml.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/sass.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/terser.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/typescript.js +1 -1
- package/dist/modules/corecompiler/summer/plugins/worklet.js +1 -1
- package/dist/modules/corecompiler/summer/summer.js +1 -1
- package/dist/modules/corecompiler/summerCompiler.js +1 -1
- package/dist/modules/createSummer.js +1 -1
- package/dist/modules/index.js +1 -1
- package/dist/modules/nativecompiler/index.js +1 -1
- package/dist/modules/nativecompiler/ios/buildCloud.js +1 -1
- package/dist/modules/nativecompiler/ios/index.js +1 -1
- package/dist/modules/nativecompiler/nativeCompiler.js +1 -1
- package/dist/modules/nativecompiler/nativeEntryProcess.js +1 -1
- package/dist/project/baseProject.js +1 -1
- package/dist/schema/@types/appjson.js +1 -0
- package/dist/schema/@types/extjson.js +1 -0
- package/dist/schema/@types/gamejson.js +1 -0
- package/dist/schema/@types/pagejson.js +1 -0
- package/dist/schema/@types/pluginjson.js +1 -0
- package/dist/schema/@types/pluginpagejson.js +1 -0
- package/dist/schema/@types/projectconfigjson.js +1 -0
- package/dist/schema/@types/projectprivateconfigjson.js +1 -0
- package/dist/schema/@types/sitemapjson.js +1 -0
- package/dist/schema/@types/themejson.js +1 -0
- package/dist/schema/dist/app.js +1 -1
- package/dist/schema/dist/ext.js +1 -1
- package/dist/schema/dist/game.js +1 -1
- package/dist/schema/dist/page.js +1 -1
- package/dist/schema/dist/plugin.js +1 -1
- package/dist/schema/dist/pluginpage.js +1 -1
- package/dist/schema/dist/projectconfig.js +37 -1
- package/dist/schema/dist/projectprivateconfig.js +1 -1
- package/dist/schema/dist/sitemap.js +1 -1
- package/dist/schema/dist/theme.js +1 -1
- package/dist/schema/src/index.js +1 -0
- package/dist/utils/codesign.js +1 -1
- package/dist/utils/miniapp-builder.js +1 -1
- package/dist/utils/miniappJson.js +1 -1
- package/dist/utils/tools.js +1 -1
- package/dist/utils/usbProcess.js +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),tools_1=require("../../../../../utils/tools"),log=tslib_1.__importStar(require("../../../../../utils/log")),config_1=require("../../../../../config/config"),locales_1=tslib_1.__importDefault(require("../../../../../utils/locales/locales"));function getCharCode(T){return T.charCodeAt(0)>=STATE.OTHERS?STATE.OTHERS:T.charCodeAt(0)}var TokenType,STATE,ACTION;!function(T){T[T.ATTR=0]="ATTR",T[T.STRING1=1]="STRING1",T[T.STRING2=2]="STRING2",T[T.OTHERS=3]="OTHERS"}(TokenType||(TokenType={})),function(T){T[T.ERROR=-1]="ERROR",T[T.NOT_SET=0]="NOT_SET",T[T.SIMPLE=1]="SIMPLE",T[T.TAG_START=2]="TAG_START",T[T.IN_TAG=3]="IN_TAG",T[T.IN_TAG_WORD=4]="IN_TAG_WORD",T[T.IN_STRING=5]="IN_STRING",T[T.IN_STRING_ESCAPE=6]="IN_STRING_ESCAPE",T[T.TAG_EQ=7]="TAG_EQ",T[T.IN_STRING2=9]="IN_STRING2",T[T.IN_STRING2_ESCAPE=10]="IN_STRING2_ESCAPE",T[T.IN_TEMPLATE_STRING=11]="IN_TEMPLATE_STRING",T[T.IN_TEMPLATE_STRING_ESCAPE=12]="IN_TEMPLATE_STRING_ESCAPE",T[T.IN_TEMPLATE_STRING2=13]="IN_TEMPLATE_STRING2",T[T.IN_TEMPLATE_STRING2_ESCAPE=14]="IN_TEMPLATE_STRING2_ESCAPE",T[T.WAIT_TEMPLATE_START=15]="WAIT_TEMPLATE_START",T[T.IN_TEMPLATE=16]="IN_TEMPLATE",T[T.WAIT_TEMPLATE_END=17]="WAIT_TEMPLATE_END",T[T.WAIT_FOR_RIGHT_BRACKET=18]="WAIT_FOR_RIGHT_BRACKET",T[T.IN_COMMENT=19]="IN_COMMENT",T[T.WAIT_FOR_COMMENT_END1=20]="WAIT_FOR_COMMENT_END1",T[T.WAIT_FOR_COMMENT_END2=21]="WAIT_FOR_COMMENT_END2",T[T.IN_COMMENT_BEGIN1=33]="IN_COMMENT_BEGIN1",T[T.IN_COMMENT_BEGIN2=34]="IN_COMMENT_BEGIN2",T[T.WXS_BEGIN_STEP1=22]="WXS_BEGIN_STEP1",T[T.WXS_BEGIN_STEP2=23]="WXS_BEGIN_STEP2",T[T.WXS_BEGIN_STEP3=24]="WXS_BEGIN_STEP3",T[T.WXS_BEGIN_STEP4=25]="WXS_BEGIN_STEP4",T[T.WXS_END_STEP1=26]="WXS_END_STEP1",T[T.WXS_END_STEP2=27]="WXS_END_STEP2",T[T.WXS_END_STEP3=28]="WXS_END_STEP3",T[T.WXS_END_STEP4=29]="WXS_END_STEP4",T[T.WXS_END_STEP5=30]="WXS_END_STEP5",T[T.IN_WXS=31]="IN_WXS",T[T.WXS_BEGIN_WAIT_FOR_RIGHT_BRACKET=32]="WXS_BEGIN_WAIT_FOR_RIGHT_BRACKET",T[T.SIMPLE_LINE_BREAK_BEGIN1=35]="SIMPLE_LINE_BREAK_BEGIN1",T[T.SIMPLE_LINE_BREAK_BEGIN2=36]="SIMPLE_LINE_BREAK_BEGIN2",T[T.SIMPLE_SPACE_OR_TAB=37]="SIMPLE_SPACE_OR_TAB",T[T.TEXT_BEGIN_STEP1=38]="TEXT_BEGIN_STEP1",T[T.TEXT_BEGIN_STEP2=39]="TEXT_BEGIN_STEP2",T[T.TEXT_BEGIN_STEP3=40]="TEXT_BEGIN_STEP3",T[T.TEXT_BEGIN_STEP4=41]="TEXT_BEGIN_STEP4",T[T.TEXT_BEGIN_STEP5=42]="TEXT_BEGIN_STEP5",T[T.TEXT_END_STEP1=43]="TEXT_END_STEP1",T[T.TEXT_END_STEP2=44]="TEXT_END_STEP2",T[T.TEXT_END_STEP3=45]="TEXT_END_STEP3",T[T.TEXT_END_STEP4=46]="TEXT_END_STEP4",T[T.TEXT_END_STEP5=47]="TEXT_END_STEP5",T[T.TEXT_END_STEP6=48]="TEXT_END_STEP6",T[T.IN_TEXT=49]="IN_TEXT",T[T.TEXT_BEGIN_WAIT_FOR_RIGHT_BRACKET=50]="TEXT_BEGIN_WAIT_FOR_RIGHT_BRACKET",T[T.END=99]="END",T[T.OTHERS=256]="OTHERS"}(STATE||(STATE={})),function(T){T[T.NOTHING=0]="NOTHING",T[T.DO_ACTION=65536]="DO_ACTION",T[T.STORE_TOKEN_EXCLUDE=131072]="STORE_TOKEN_EXCLUDE",T[T.STORE_TOKEN_INCLUDE=262144]="STORE_TOKEN_INCLUDE",T[T.IGNORE=524288]="IGNORE",T[T.REFEED=1048576]="REFEED",T[T.STORE_TOKEN_FIRST=2097152]="STORE_TOKEN_FIRST",T[T.STORE_ONE_SPACE=4194304]="STORE_ONE_SPACE",T[T.STORE_ONE_LINE_BREAK=8388608]="STORE_ONE_LINE_BREAK",T[T.GET_WHITECHARS_BEFORE=16777216]="GET_WHITECHARS_BEFORE",T[T.STORE_STATE_BEFORE_COMMENT=33554432]="STORE_STATE_BEFORE_COMMENT",T[T.SET_WXS_STATE=67108864]="SET_WXS_STATE",T[T.WXS_BACK=134217728]="WXS_BACK",T[T.SET_TEXT_STATE=268435456]="SET_TEXT_STATE",T[T.TEXT_BACK=536870912]="TEXT_BACK"}(ACTION||(ACTION={}));class Token{constructor(T,E){this.type=T,this.value=E}}class MachineState{constructor(){this.cur_pos=0,this.last_pos=0,this.line=1,this.col=1,this.last_line=this.line,this.last_col=1,this.state=STATE.SIMPLE}}class Machine{constructor(T,E){this.mState=new MachineState,this.TT=new Array(1024);for(let T=0;T<1024;T++){const E=new Array(257);this.TT[T]=E}this.InitTransitTable(),this.mPath=T,this.mSrc=E,this.stateBeforeComment=STATE.SIMPLE,this.wxsState=!1,this.textState=!1}Reset(){return this.mState.cur_pos=this.mState.last_pos=0,this.mState.line=1,this.mState.col=1,this.mState.last_line=this.mState.line,this.mState.last_col=1,this.mState.state=STATE.SIMPLE,0}Feed(T,E){let _,S,t,A,N;"\n"===T&&(this.mState.line++,this.mState.col=0);do{if(N=!1,void 0!==_&&_&ACTION.REFEED&&(N=!0),_=this.TT[this.mState.state][getCharCode(T)],_===STATE.NOT_SET&&(_=this.TT[this.mState.state][STATE.OTHERS]),_===STATE.NOT_SET)throw{msg:`BAD STATE MACHINE! AT INPUT ${this.mState.state} ${T}`};if(_<0)throw"\0"!==T?{msg:`${this.mState.line}:${this.mState.col}:unexpected character \`${T.replace("\n","\\n")}\``}:{msg:`${this.mState.line}:${this.mState.col}:unexpected end`};if(S=_,t=65535&_,A=this.mState.state,S&ACTION.STORE_STATE_BEFORE_COMMENT&&!N&&(this.stateBeforeComment=A),A===STATE.WAIT_FOR_RIGHT_BRACKET&&">"===T&&this.wxsState&&(this.wxsState=!1),A===STATE.WAIT_FOR_RIGHT_BRACKET&&">"===T&&this.textState&&(this.textState=!1),S&ACTION.SET_WXS_STATE&&(this.wxsState=!this.wxsState),S&ACTION.SET_TEXT_STATE&&(this.textState=!this.textState),">"===T&&t===STATE.SIMPLE&&this.wxsState&&(t=STATE.IN_WXS),">"===T&&t===STATE.SIMPLE&&this.textState&&(t=STATE.IN_TEXT),this.mState.state=t,S&ACTION.STORE_TOKEN_FIRST&&this.mState.cur_pos>this.mState.last_pos){const T=new Token(TokenType.OTHERS,this.mSrc.substring(this.mState.last_pos,this.mState.last_pos+1));E.push(T),this.mState.last_pos++,this.mState.last_col++}if(S&ACTION.STORE_ONE_LINE_BREAK){const T=new Token(TokenType.OTHERS,"\n");E.push(T),this.mState.last_pos=this.mState.cur_pos,this.mState.last_col=this.mState.col,this.mState.last_line=this.mState.line}if(S&ACTION.STORE_ONE_SPACE){const T=new Token(TokenType.OTHERS," ");E.push(T),this.mState.last_pos=this.mState.cur_pos,this.mState.last_col=this.mState.col,this.mState.last_line=this.mState.line}}while(_&ACTION.REFEED);if(S&ACTION.STORE_TOKEN_EXCLUDE){const T=this.mState.cur_pos,_=this.mState.last_pos;if(T>_){let S;S=A===STATE.IN_TAG_WORD&&_>0&&" \n\t\r".includes(this.mSrc[_-1])?new Token(TokenType.ATTR,this.mSrc.substring(_,T)):(this.wxsState&&STATE.IN_WXS,new Token(TokenType.OTHERS,this.mSrc.substring(_,T))),E.push(S),this.mState.last_pos=this.mState.cur_pos,this.mState.last_col=this.mState.col,this.mState.last_line=this.mState.line}}if(S&ACTION.WXS_BACK){const T=new Token(TokenType.OTHERS,this.mSrc.substring(this.mState.last_pos,this.mState.cur_pos-4));E.push(T),this.mState.last_pos=this.mState.cur_pos-4,this.mState.last_col=this.mState.col-4,this.mState.last_line=this.mState.line}if(S&ACTION.TEXT_BACK){const T=new Token(TokenType.OTHERS,this.mSrc.substring(this.mState.last_pos,this.mState.cur_pos-5));E.push(T),this.mState.last_pos=this.mState.cur_pos-5,this.mState.last_col=this.mState.col-5,this.mState.last_line=this.mState.line}if(this.mState.cur_pos++,this.mState.col++,S&ACTION.STORE_TOKEN_INCLUDE){let T;T=A===STATE.IN_STRING?TokenType.STRING1:A===STATE.IN_STRING2?TokenType.STRING2:TokenType.OTHERS;const _=new Token(T,this.mSrc.substring(this.mState.last_pos,this.mState.cur_pos));E.push(_),this.mState.last_pos=this.mState.cur_pos,this.mState.last_col=this.mState.col,this.mState.last_line=this.mState.line}return S&ACTION.IGNORE&&(this.mState.last_pos=this.mState.cur_pos,this.mState.last_col=this.mState.col),S&ACTION.GET_WHITECHARS_BEFORE&&(this.mState.state=this.stateBeforeComment,this.stateBeforeComment!==STATE.SIMPLE_LINE_BREAK_BEGIN2&&this.stateBeforeComment!==STATE.SIMPLE_SPACE_OR_TAB||E.pop(),this.stateBeforeComment=STATE.SIMPLE),0}FillTT(T,E,_,S){for(const t of S)this.TT[T][getCharCode(t)]=E|_}FillTT_template_string(T,E){const _=T+1;this.TT[T][getCharCode("\\")]=_,this.TT[_][STATE.OTHERS]=T,this.TT[T][getCharCode(E)]=STATE.IN_TEMPLATE,this.TT[T][0]=STATE.ERROR,this.TT[T][STATE.OTHERS]=T}FillTT_string(T,E){const _=T+1;this.TT[T][getCharCode("\\")]=_,this.TT[T][getCharCode("\n")]=STATE.ERROR,this.TT[_][STATE.OTHERS]=T,this.TT[_][getCharCode("\n")]=STATE.IN_TAG|ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE,this.TT[T][getCharCode(E)]=STATE.IN_TAG|ACTION.STORE_TOKEN_INCLUDE,this.TT[T][0]=STATE.ERROR,this.TT[T][STATE.OTHERS]=T}InitTransitTable(){for(let T=0;T<1024;T++)this.TT[T].fill(0);const T="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-:";this.TT[STATE.END][STATE.OTHERS]=STATE.END,this.TT[STATE.SIMPLE][getCharCode("<")]=STATE.TAG_START|ACTION.STORE_TOKEN_EXCLUDE|ACTION.STORE_STATE_BEFORE_COMMENT,this.TT[STATE.SIMPLE][getCharCode("{")]=STATE.WAIT_TEMPLATE_START,this.TT[STATE.SIMPLE][STATE.OTHERS]=STATE.SIMPLE,this.TT[STATE.SIMPLE][0]=STATE.END|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.WAIT_TEMPLATE_START][getCharCode("{")]=STATE.IN_TEMPLATE,this.TT[STATE.WAIT_TEMPLATE_START][STATE.OTHERS]=STATE.SIMPLE,this.TT[STATE.IN_TEMPLATE][getCharCode("}")]=STATE.WAIT_TEMPLATE_END,this.TT[STATE.IN_TEMPLATE][0]=STATE.ERROR,this.TT[STATE.IN_TEMPLATE][STATE.OTHERS]=STATE.IN_TEMPLATE,this.TT[STATE.WAIT_TEMPLATE_END][getCharCode("}")]=STATE.SIMPLE,this.TT[STATE.WAIT_TEMPLATE_END][STATE.OTHERS]=STATE.IN_TEMPLATE|ACTION.REFEED,this.TT[STATE.IN_TEMPLATE][getCharCode('"')]=STATE.IN_TEMPLATE_STRING,this.TT[STATE.IN_TEMPLATE][getCharCode("'")]=STATE.IN_TEMPLATE_STRING2,this.FillTT_template_string(STATE.IN_TEMPLATE_STRING,'"'),this.FillTT_template_string(STATE.IN_TEMPLATE_STRING2,"'"),this.FillTT(STATE.TAG_START,STATE.IN_TAG,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.FillTT(STATE.TAG_START,STATE.IN_TAG_WORD,ACTION.STORE_TOKEN_EXCLUDE,T),this.TT[STATE.TAG_START][getCharCode("/")]=STATE.IN_TAG|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.TAG_START][getCharCode("!")]=STATE.IN_COMMENT_BEGIN1,this.TT[STATE.TAG_START][STATE.OTHERS]=STATE.ERROR,this.TT[STATE.IN_COMMENT_BEGIN1][getCharCode("-")]=STATE.IN_COMMENT_BEGIN2,this.TT[STATE.IN_COMMENT_BEGIN1][STATE.OTHERS]=STATE.ERROR,this.TT[STATE.IN_COMMENT_BEGIN2][getCharCode("-")]=STATE.IN_COMMENT,this.TT[STATE.IN_COMMENT_BEGIN2][STATE.OTHERS]=STATE.ERROR,this.TT[STATE.IN_COMMENT][getCharCode("-")]=STATE.WAIT_FOR_COMMENT_END1,this.TT[STATE.IN_COMMENT][STATE.OTHERS]=STATE.IN_COMMENT,this.TT[STATE.WAIT_FOR_COMMENT_END1][getCharCode("-")]=STATE.WAIT_FOR_COMMENT_END2,this.TT[STATE.WAIT_FOR_COMMENT_END1][STATE.OTHERS]=STATE.IN_COMMENT,this.TT[STATE.WAIT_FOR_COMMENT_END2][getCharCode(">")]=STATE.SIMPLE|ACTION.IGNORE|ACTION.GET_WHITECHARS_BEFORE,this.TT[STATE.WAIT_FOR_COMMENT_END2][getCharCode("-")]=STATE.WAIT_FOR_COMMENT_END2,this.TT[STATE.WAIT_FOR_COMMENT_END2][STATE.OTHERS]=STATE.IN_COMMENT,this.FillTT(STATE.IN_TAG_WORD,STATE.IN_TAG_WORD,ACTION.NOTHING,T),this.FillTT(STATE.IN_TAG_WORD,STATE.IN_TAG_WORD,ACTION.NOTHING,"0123456789"),this.FillTT(STATE.IN_TAG_WORD,STATE.IN_TAG,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[STATE.IN_TAG_WORD][getCharCode("=")]=STATE.TAG_EQ|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_TAG_WORD][getCharCode('"')]=STATE.ERROR,this.TT[STATE.IN_TAG_WORD][getCharCode(">")]=STATE.SIMPLE|ACTION.STORE_TOKEN_EXCLUDE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.IN_TAG_WORD][getCharCode("/")]=STATE.WAIT_FOR_RIGHT_BRACKET|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_TAG_WORD][STATE.OTHERS]=STATE.IN_TAG|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_TAG_WORD][0]=STATE.ERROR,this.FillTT(STATE.TAG_EQ,STATE.IN_TAG,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.FillTT(STATE.TAG_EQ,STATE.IN_STRING,ACTION.STORE_TOKEN_EXCLUDE,T),this.TT[STATE.TAG_EQ][getCharCode('"')]=STATE.IN_STRING|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.TAG_EQ][getCharCode("'")]=STATE.IN_STRING2|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.TAG_EQ][0]=STATE.ERROR,this.TT[STATE.TAG_EQ][STATE.OTHERS]=STATE.ERROR,this.FillTT(STATE.IN_TAG,STATE.IN_TAG,ACTION.IGNORE," \n\t\r"),this.FillTT(STATE.IN_TAG,STATE.IN_TAG_WORD,ACTION.NOTHING,T),this.FillTT(STATE.IN_TAG,STATE.ERROR,ACTION.NOTHING,"0123456789"),this.TT[STATE.IN_TAG][getCharCode("<")]=STATE.ERROR,this.TT[STATE.IN_TAG][getCharCode('"')]=STATE.IN_STRING,this.TT[STATE.IN_TAG][getCharCode("'")]=STATE.IN_STRING2,this.TT[STATE.IN_TAG][getCharCode("/")]=STATE.WAIT_FOR_RIGHT_BRACKET,this.TT[STATE.IN_TAG][getCharCode(">")]=STATE.SIMPLE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.IN_TAG][getCharCode("=")]=STATE.TAG_EQ,this.TT[STATE.IN_TAG][0]=STATE.ERROR,this.TT[STATE.IN_TAG][STATE.OTHERS]=STATE.ERROR,this.FillTT(STATE.WAIT_FOR_RIGHT_BRACKET,STATE.IN_TAG_WORD,ACTION.STORE_TOKEN_EXCLUDE,T),this.TT[STATE.WAIT_FOR_RIGHT_BRACKET][getCharCode(">")]=STATE.SIMPLE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.WAIT_FOR_RIGHT_BRACKET][STATE.OTHERS]=STATE.ERROR,this.FillTT_string(STATE.IN_STRING,'"'),this.FillTT_string(STATE.IN_STRING2,"'"),this.TT[STATE.TAG_START][getCharCode("w")]=STATE.WXS_BEGIN_STEP1;let E="wxs",_=STATE.WXS_BEGIN_STEP1;for(let T=1,S=_;T<E.length;T++)this.TT[S][getCharCode(E[T])]=_+T,this.TT[S][STATE.OTHERS]=STATE.IN_TAG_WORD|ACTION.REFEED|ACTION.STORE_TOKEN_FIRST,2===T&&(this.TT[S][getCharCode(E[T])]|=ACTION.SET_WXS_STATE),S=_+T;this.FillTT(STATE.WXS_BEGIN_STEP3,STATE.IN_TAG,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[STATE.WXS_BEGIN_STEP3][getCharCode(">")]=STATE.IN_WXS|ACTION.STORE_TOKEN_EXCLUDE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.WXS_BEGIN_STEP3][STATE.OTHERS]=STATE.IN_TAG_WORD|ACTION.REFEED|ACTION.STORE_TOKEN_FIRST|ACTION.SET_WXS_STATE,this.TT[STATE.IN_WXS][getCharCode("<")]=STATE.WXS_END_STEP1,this.TT[STATE.IN_WXS][STATE.OTHERS]=STATE.IN_WXS,E="</wxs",_=STATE.WXS_END_STEP1;for(let T=1,S=_;T<E.length;T++)this.TT[S][getCharCode(E[T])]=_+T,4===T&&(this.TT[S][getCharCode(E[T])]|=ACTION.WXS_BACK|ACTION.SET_WXS_STATE),this.TT[S][STATE.OTHERS]=STATE.IN_WXS|ACTION.REFEED,S=_+T;this.FillTT(STATE.WXS_END_STEP5,STATE.WXS_END_STEP5,ACTION.NOTHING," \n\t\r"),this.TT[STATE.WXS_END_STEP5][getCharCode(">")]=STATE.SIMPLE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.WXS_END_STEP5][STATE.OTHERS]=STATE.ERROR,this.TT[STATE.SIMPLE][getCharCode(" ")]=STATE.SIMPLE_SPACE_OR_TAB|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.SIMPLE][getCharCode("\t")]=STATE.SIMPLE_SPACE_OR_TAB|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.SIMPLE][getCharCode("\n")]=STATE.SIMPLE_LINE_BREAK_BEGIN1|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.SIMPLE_SPACE_OR_TAB][getCharCode(" ")]=STATE.SIMPLE_SPACE_OR_TAB,this.TT[STATE.SIMPLE_SPACE_OR_TAB][getCharCode("\t")]=STATE.SIMPLE_SPACE_OR_TAB,this.TT[STATE.SIMPLE_SPACE_OR_TAB][getCharCode("\n")]=STATE.SIMPLE_SPACE_OR_TAB,this.TT[STATE.SIMPLE_SPACE_OR_TAB][getCharCode("<")]=STATE.SIMPLE|ACTION.STORE_ONE_SPACE|ACTION.REFEED|ACTION.STORE_STATE_BEFORE_COMMENT,this.TT[STATE.SIMPLE_SPACE_OR_TAB][STATE.OTHERS]=STATE.SIMPLE|ACTION.STORE_ONE_SPACE|ACTION.REFEED,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN1][getCharCode("\n")]=STATE.SIMPLE_LINE_BREAK_BEGIN2,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN1][getCharCode("\t")]=STATE.SIMPLE_SPACE_OR_TAB,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN1][getCharCode(" ")]=STATE.SIMPLE_SPACE_OR_TAB,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN1][getCharCode("<")]=STATE.SIMPLE|ACTION.REFEED|ACTION.STORE_STATE_BEFORE_COMMENT,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN1][STATE.OTHERS]=STATE.SIMPLE|ACTION.REFEED|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN2][getCharCode("\n")]=STATE.SIMPLE_LINE_BREAK_BEGIN2,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN2][getCharCode("\t")]=STATE.SIMPLE_SPACE_OR_TAB,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN2][getCharCode(" ")]=STATE.SIMPLE_SPACE_OR_TAB,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN2][getCharCode("<")]=STATE.SIMPLE|ACTION.STORE_ONE_LINE_BREAK|ACTION.REFEED|ACTION.STORE_STATE_BEFORE_COMMENT,this.TT[STATE.SIMPLE_LINE_BREAK_BEGIN2][STATE.OTHERS]=STATE.SIMPLE|ACTION.REFEED|ACTION.STORE_ONE_LINE_BREAK,this.TT[STATE.TAG_START][getCharCode("t")]=STATE.TEXT_BEGIN_STEP1,E="text",_=STATE.TEXT_BEGIN_STEP1;for(let T=1,S=_;T<E.length;T++)this.TT[S][getCharCode(E[T])]=_+T,3===T&&(this.TT[S][getCharCode(E[T])]|=ACTION.SET_TEXT_STATE),this.TT[S][STATE.OTHERS]=STATE.IN_TAG_WORD|ACTION.REFEED|ACTION.STORE_TOKEN_FIRST,S=_+T;this.FillTT(STATE.TEXT_BEGIN_STEP4,STATE.IN_TAG,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[STATE.TEXT_BEGIN_STEP4][getCharCode(">")]=STATE.IN_TEXT|ACTION.STORE_TOKEN_EXCLUDE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.TEXT_BEGIN_STEP4][STATE.OTHERS]=STATE.IN_TAG_WORD|ACTION.REFEED|ACTION.STORE_TOKEN_FIRST|ACTION.SET_TEXT_STATE,this.TT[STATE.IN_TEXT][getCharCode("<")]=STATE.TEXT_END_STEP1,this.TT[STATE.IN_TEXT][STATE.OTHERS]=STATE.IN_TEXT,E="</text",_=STATE.TEXT_END_STEP1;for(let T=1,S=_;T<E.length;T++)this.TT[S][getCharCode(E[T])]=_+T,5===T&&(this.TT[S][getCharCode(E[T])]|=ACTION.TEXT_BACK|ACTION.SET_TEXT_STATE),this.TT[S][STATE.OTHERS]=STATE.IN_TEXT|ACTION.REFEED,S=_+T;this.FillTT(STATE.TEXT_END_STEP6,STATE.TEXT_END_STEP6,ACTION.NOTHING," \n\t\r"),this.TT[STATE.TEXT_END_STEP6][getCharCode(">")]=STATE.SIMPLE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.TEXT_END_STEP6][STATE.OTHERS]=STATE.ERROR}}class Tokenizer{constructor(T,E){this.machine=new Machine(E,T),this.m_pSrc=T,this.path=E}generateTokens(T){this.machine.Reset();let E=0;if(0===this.m_pSrc.length)return E;for(let _=0;_<this.m_pSrc.length&&0==E;_++){const S=this.m_pSrc[_];E=this.machine.Feed(S,T)}return 0!==E||(E=this.machine.Feed("\0",T)),E}}function generateWXMLFromTokens(T){let E="";for(const _ of T){let{value:T}=_;_.type===TokenType.ATTR&&(T=" "+T),E+=T}return E}async function minifyWXML(T){const{code:E,filePath:_,setting:S={},root:t=""}=T,{minifyWXML:A}=S,N=!!A,e=path_1.default.posix.join(t,_),I=Buffer.from(E);let s=(0,tools_1.bufferToUtf8String)(I);if(void 0===s)return{error:{code:config_1.FILE_NOT_UTF8,path:e,message:locales_1.default.config.FILE_NOT_UTF8.format(e)}};if(N&&s.length>0)try{const T=new Tokenizer(s.replace(/\r\n/g,"\n"),e),E=[],_=T.generateTokens(E);if(0!==_)throw new Error("minifywxml tokenizer error ret: "+_);return s=generateWXMLFromTokens(E),{error:null,code:s.replace(/\r\n/g,"\n")}}catch(T){return log.error("minifywxml error @ "+e),log.error(T.msg),{error:{code:config_1.MINIFY_WXML_ERR,path:e,message:T.msg}}}return{error:null,code:s.replace(/\r\n/g,"\n")}}module.exports={minifyWXML:minifyWXML,Tokenizer:Tokenizer,generateWXMLFromTokens:generateWXMLFromTokens,Token:Token};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.minifyWXML=exports.StyleAttrValueTokenizer=exports.TemplateTokenizer=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),log=tslib_1.__importStar(require("../../../../../utils/log")),config_1=require("../../../../../config/config");function getCharCode(T){return T.charCodeAt(0)>=256?BASE_STATE.OTHERS:T.charCodeAt(0)}function trimStringLeft(T,E=!0){return E?T.trimLeft():T.split("\n").map(T=>T.replace(/^[ \t]*/g,"")).join("\n")}function trimStringRight(T,E=!0){return E?T.trimRight():T.split("\n").map(T=>T.replace(/[ \t]*$/,"")).join("\n")}var TokenType,BASE_STATE,STATE,TEMPLATE_STATE,STYLE_ATTR_VALUE_STATE,ACTION;!function(T){T[T.ATTR=0]="ATTR",T[T.TAG=1]="TAG",T[T.LEFT_ANGLE_BRACKET=2]="LEFT_ANGLE_BRACKET",T[T.RIGHT_ANGLE_BRACKET=3]="RIGHT_ANGLE_BRACKET",T[T.END_LEFT_ANGLE_BRACKET=4]="END_LEFT_ANGLE_BRACKET",T[T.STRING1=5]="STRING1",T[T.STRING2=6]="STRING2",T[T.ATTR_VALUE=7]="ATTR_VALUE",T[T.TEXT_VALUE=8]="TEXT_VALUE",T[T.TAG_TEXT_VALUE=9]="TAG_TEXT_VALUE",T[T.TEMPLATE_START=10]="TEMPLATE_START",T[T.TEMPLATE_END=11]="TEMPLATE_END",T[T.TEMPLATE_ITEM=12]="TEMPLATE_ITEM",T[T.TEMPLATE_STRING=13]="TEMPLATE_STRING",T[T.SELF_CLOSE=14]="SELF_CLOSE",T[T.WXS_VALUE=15]="WXS_VALUE",T[T.STYLE_KEY=16]="STYLE_KEY",T[T.TAG_EQ=17]="TAG_EQ",T[T.STYLE_VALUE=18]="STYLE_VALUE",T[T.STYLE_ATTR_VALUE=19]="STYLE_ATTR_VALUE",T[T.CLASS_ATTR_VALUE=20]="CLASS_ATTR_VALUE",T[T.OTHERS=21]="OTHERS"}(TokenType||(TokenType={})),function(T){T[T.ERROR=-1]="ERROR",T[T.NOT_SET=0]="NOT_SET",T[T.START=1]="START",T[T.OTHERS=2]="OTHERS",T[T.END=3]="END",T[T.MAX_STATE=4]="MAX_STATE"}(BASE_STATE||(BASE_STATE={})),function(T){T[T.IN_TAG_TEXT=5]="IN_TAG_TEXT",T[T.TAG_START=6]="TAG_START",T[T.IN_TAG_WORD=7]="IN_TAG_WORD",T[T.TAG_EQ=8]="TAG_EQ",T[T.IN_TAG_ATTR_WORD=9]="IN_TAG_ATTR_WORD",T[T.IN_TAG_ATTR_VALUE_STRING=10]="IN_TAG_ATTR_VALUE_STRING",T[T.IN_TAG_ATTR_VALUE_STRING_ESCAPE=11]="IN_TAG_ATTR_VALUE_STRING_ESCAPE",T[T.IN_TAG_ATTR_VALUE_STRING_SINGLE=12]="IN_TAG_ATTR_VALUE_STRING_SINGLE",T[T.IN_TAG_ATTR_VALUE_STRING_SINGLE_ESCAPE=13]="IN_TAG_ATTR_VALUE_STRING_SINGLE_ESCAPE",T[T.WAIT_TEMPLATE_START=14]="WAIT_TEMPLATE_START",T[T.IN_TEMPLATE=15]="IN_TEMPLATE",T[T.WAIT_TEMPLATE_END=16]="WAIT_TEMPLATE_END",T[T.TEMPLATE_END_CHECK=17]="TEMPLATE_END_CHECK",T[T.IN_TEMPLATE_STRING=18]="IN_TEMPLATE_STRING",T[T.IN_TEMPLATE_STRING_ESCAPE=19]="IN_TEMPLATE_STRING_ESCAPE",T[T.IN_TEMPLATE_STRING2=20]="IN_TEMPLATE_STRING2",T[T.IN_TEMPLATE_STRING2_ESCAPE=21]="IN_TEMPLATE_STRING2_ESCAPE",T[T.WAIT_FOR_RIGHT_BRACKET=22]="WAIT_FOR_RIGHT_BRACKET",T[T.IN_WXS=23]="IN_WXS",T[T.IN_WXS_STRING=24]="IN_WXS_STRING",T[T.IN_WXS_STRING_ESCAPE=25]="IN_WXS_STRING_ESCAPE",T[T.IN_WXS_STRING_SINGLE=26]="IN_WXS_STRING_SINGLE",T[T.IN_WXS_STRING_SINGLE_ESCAPE=27]="IN_WXS_STRING_SINGLE_ESCAPE",T[T.WXS_END_STEP=28]="WXS_END_STEP",T[T.IN_COMMENT_BEGIN1=29]="IN_COMMENT_BEGIN1",T[T.IN_COMMENT_BEGIN2=30]="IN_COMMENT_BEGIN2",T[T.IN_COMMENT=31]="IN_COMMENT",T[T.WAIT_FOR_COMMENT_END1=32]="WAIT_FOR_COMMENT_END1",T[T.WAIT_FOR_COMMENT_END2=33]="WAIT_FOR_COMMENT_END2",T[T.IN_TEXT=34]="IN_TEXT",T[T.IN_END_TAG=35]="IN_END_TAG",T[T.IN_END_TAG_WORD=36]="IN_END_TAG_WORD",T[T.MAX_STATE=37]="MAX_STATE"}(STATE||(STATE={})),function(T){T[T.WAIT_TEMPLATE_START=5]="WAIT_TEMPLATE_START",T[T.IN_TEMPLATE_ITEM=6]="IN_TEMPLATE_ITEM",T[T.WAIT_TEMPLATE_END=7]="WAIT_TEMPLATE_END",T[T.IN_TEMPLATE_STRING=8]="IN_TEMPLATE_STRING",T[T.IN_TEMPLATE_STRING_ESCAPE=9]="IN_TEMPLATE_STRING_ESCAPE",T[T.IN_TEMPLATE_STRING2=10]="IN_TEMPLATE_STRING2",T[T.IN_TEMPLATE_STRING2_ESCAPE=11]="IN_TEMPLATE_STRING2_ESCAPE",T[T.WAIT_FOR_COMMENT_START=12]="WAIT_FOR_COMMENT_START",T[T.IN_COMMENT=13]="IN_COMMENT",T[T.WAIT_FOR_COMMENT_END=14]="WAIT_FOR_COMMENT_END",T[T.IN_TEMPLATE_SPACE=15]="IN_TEMPLATE_SPACE",T[T.MAX_STATE=16]="MAX_STATE"}(TEMPLATE_STATE||(TEMPLATE_STATE={})),function(T){T[T.WAIT_KEY=5]="WAIT_KEY",T[T.IN_KEY=6]="IN_KEY",T[T.WAIT_KEY_VALUE_SAPERATE=7]="WAIT_KEY_VALUE_SAPERATE",T[T.IN_KEY_VALUE_SAPERATE=8]="IN_KEY_VALUE_SAPERATE",T[T.WAIT_VALUE=9]="WAIT_VALUE",T[T.IN_VALUE=10]="IN_VALUE",T[T.WAIT_ITEM_SAPERATE=11]="WAIT_ITEM_SAPERATE",T[T.IN_ITEM_SAPERATE=12]="IN_ITEM_SAPERATE",T[T.IN_STRING=13]="IN_STRING",T[T.IN_STRING_ESCAPE=14]="IN_STRING_ESCAPE",T[T.IN_STRING2=15]="IN_STRING2",T[T.IN_STRING2_ESCAPE=16]="IN_STRING2_ESCAPE",T[T.WAIT_TEMPLATE_START=17]="WAIT_TEMPLATE_START",T[T.IN_TEMPLATE=18]="IN_TEMPLATE",T[T.WAIT_TEMPLATE_END=19]="WAIT_TEMPLATE_END",T[T.IN_TEMPLATE_STRING=20]="IN_TEMPLATE_STRING",T[T.IN_TEMPLATE_STRING_ESCAPE=21]="IN_TEMPLATE_STRING_ESCAPE",T[T.IN_TEMPLATE_STRING2=22]="IN_TEMPLATE_STRING2",T[T.IN_TEMPLATE_STRING2_ESCAPE=23]="IN_TEMPLATE_STRING2_ESCAPE",T[T.MAX_STATE=24]="MAX_STATE"}(STYLE_ATTR_VALUE_STATE||(STYLE_ATTR_VALUE_STATE={})),function(T){T[T.NOTHING=0]="NOTHING",T[T.DO_ACTION=65536]="DO_ACTION",T[T.STORE_TOKEN_EXCLUDE=131072]="STORE_TOKEN_EXCLUDE",T[T.STORE_TOKEN_INCLUDE=262144]="STORE_TOKEN_INCLUDE",T[T.IGNORE=524288]="IGNORE",T[T.REFEED=1048576]="REFEED",T[T.STORE_TOKEN_FIRST=2097152]="STORE_TOKEN_FIRST",T[T.STORE_ONE_SPACE=4194304]="STORE_ONE_SPACE",T[T.STORE_ONE_LINE_BREAK=8388608]="STORE_ONE_LINE_BREAK",T[T.GET_STATE_BEFORE=16777216]="GET_STATE_BEFORE",T[T.STORE_STATE_BEFORE=33554432]="STORE_STATE_BEFORE",T[T.SET_WXS_STATE=67108864]="SET_WXS_STATE"}(ACTION||(ACTION={}));class Token{constructor(T,E){this.type=T,this.value=E}}class MachineState{constructor(){this.cur_pos=0,this.last_pos=0,this.line=1,this.col=1,this.mark_pos=0,this.mark_col=0,this.last_line=this.line,this.last_col=1,this.state=BASE_STATE.START}}const ALPHA="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-:",DIGIT="0123456789.",WHITECHARS=" \n\t\r";class BaseMachine{constructor(T,E){this.mState=new MachineState,this.storedStates=[],this.oldState=BASE_STATE.START,this.tokens=[],this.mPath=T,this.mSrc=E}FillTT(T,E,A,_){for(const S of _)this.TT[T][getCharCode(S)]=E|A}Reset(){return this.mState.cur_pos=0,this.mState.last_pos=0,this.mState.mark_pos=0,this.mState.line=1,this.mState.col=1,this.mState.last_col=1,this.mState.mark_col=1,this.mState.last_line=this.mState.line,this.mState.state=BASE_STATE.START,0}refeed(T){let E=this.TT[this.mState.state][getCharCode(T)];if(E===BASE_STATE.NOT_SET&&(E=this.TT[this.mState.state][BASE_STATE.OTHERS]),E===BASE_STATE.NOT_SET)throw{col:this.mState.col,line:this.mState.line,message:"BAD STATE MACHINE!"};if(E<0){if("\0"!==T)throw{col:this.mState.col,line:this.mState.line,message:`unexpected character \`${T.replace(/\n/g,"\\n")}\``};throw{col:this.mState.col,line:this.mState.line,message:"unexpected end"}}const A=E,_=65535&E,S=this.mState.state;A&ACTION.STORE_STATE_BEFORE&&(this.storedStates.push(S),this.mState.mark_pos=this.mState.cur_pos,this.mState.mark_col=this.mState.mark_col),this.mState.state=_,this.doAction(T,S,A)}Feed(T){"\n"===T&&(this.mState.line++,this.mState.col=0),this.refeed(T)}FillTT_template_string(T,E,A){const _=T+1;this.TT[T][getCharCode("\\")]=_,this.TT[_][BASE_STATE.OTHERS]=T,this.TT[T][getCharCode(A)]=E,this.TT[T][0]=BASE_STATE.ERROR,this.TT[T][BASE_STATE.OTHERS]=T}updatePosition(){this.mState.last_pos=this.mState.cur_pos,this.mState.last_col=this.mState.col,this.mState.last_line=this.mState.line}processPosition(){this.mState.cur_pos++,this.mState.col++}doAction(T,E,A){if(A&ACTION.STORE_TOKEN_FIRST&&this.mState.mark_pos>this.mState.last_pos){const T=this.mSrc.substring(this.mState.last_pos,this.mState.mark_pos);this.doExcludeAction(this.storedStates[this.storedStates.length-1],T),this.mState.last_pos=this.mState.mark_pos,this.mState.last_col=this.mState.mark_col}if(A&ACTION.STORE_ONE_LINE_BREAK&&(this.appendToken(TokenType.OTHERS,"\n"),this.updatePosition()),A&ACTION.STORE_ONE_SPACE&&(this.appendToken(TokenType.OTHERS," "),this.updatePosition()),A&ACTION.STORE_TOKEN_EXCLUDE){const T=this.mState.cur_pos,A=this.mState.last_pos;if(T>A){const _=this.mSrc.substring(A,T);this.doExcludeAction(E,_),this.updatePosition()}}if(A&ACTION.REFEED){if(A&ACTION.IGNORE&&this.updatePosition(),A&ACTION.GET_STATE_BEFORE){const T=this.storedStates.pop();T&&(this.mState.state=T)}this.refeed(T)}else{if(this.processPosition(),A&ACTION.STORE_TOKEN_INCLUDE){const A=this.mSrc.substring(this.mState.last_pos,this.mState.cur_pos);this.doIncludeAction(T,E,A),this.updatePosition()}if(A&ACTION.IGNORE&&this.updatePosition(),A&ACTION.GET_STATE_BEFORE){const T=this.storedStates.pop();T&&(this.mState.state=T)}}}}class StyleAttrValueMachine extends BaseMachine{get TT(){return StyleAttrValueMachine._TT||this.InitTransitTable(),StyleAttrValueMachine._TT}constructor(T,E){super(T,E),this.mState.state=BASE_STATE.START}getTokens(){return[...this.tokens]}appendToken(T,E){T===TokenType.STYLE_VALUE&&(E=E.replace(/[ \t]+/g," ")),this.tokens.push(new Token(T,E))}doExcludeAction(T,E){let A=TokenType.OTHERS;switch(T){case STYLE_ATTR_VALUE_STATE.IN_KEY:A=TokenType.STYLE_KEY;break;case STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE:case STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE:A=TokenType.OTHERS;break;case STYLE_ATTR_VALUE_STATE.IN_VALUE:A=TokenType.STYLE_VALUE}this.appendToken(A,E)}doIncludeAction(T,E,A){let _=TokenType.OTHERS;switch(E){case STYLE_ATTR_VALUE_STATE.IN_STRING:_=TokenType.STRING1;break;case STYLE_ATTR_VALUE_STATE.IN_STRING2:_=TokenType.STRING2;break;case STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_END:_=TokenType.TEMPLATE_ITEM,A=new TemplateTokenizer(A,this.mPath).toString()}this.appendToken(_,A)}FillTT_string(T,E,A){const _=T+1;this.TT[T][getCharCode("\\")]=_,this.TT[T][getCharCode("\n")]=BASE_STATE.ERROR,this.TT[_][BASE_STATE.OTHERS]=T,this.TT[_][getCharCode("\n")]=E|ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE,this.TT[T][getCharCode(A)]=E|ACTION.STORE_TOKEN_INCLUDE,this.TT[T][getCharCode("{")]=STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE,this.TT[T][0]=BASE_STATE.ERROR,this.TT[T][BASE_STATE.OTHERS]=T}InitTransitTable(){StyleAttrValueMachine._TT=new Array(STYLE_ATTR_VALUE_STATE.MAX_STATE);for(let T=0;T<STYLE_ATTR_VALUE_STATE.MAX_STATE;T++){const E=new Array(257);E.fill(0),this.TT[T]=E}this.TT[BASE_STATE.END][BASE_STATE.OTHERS]=BASE_STATE.END,this.FillTT(BASE_STATE.START,BASE_STATE.START,ACTION.IGNORE," \n\t\r"),this.TT[BASE_STATE.START][getCharCode(":")]=BASE_STATE.ERROR,this.TT[BASE_STATE.START][getCharCode(";")]=STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE|ACTION.IGNORE,this.TT[BASE_STATE.START][getCharCode("{")]=STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE,this.TT[BASE_STATE.START][BASE_STATE.OTHERS]=STYLE_ATTR_VALUE_STATE.IN_KEY,this.FillTT(STYLE_ATTR_VALUE_STATE.WAIT_KEY,STYLE_ATTR_VALUE_STATE.WAIT_KEY,ACTION.IGNORE," \n\t\r"),this.TT[STYLE_ATTR_VALUE_STATE.WAIT_KEY][getCharCode(":")]=BASE_STATE.ERROR,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_KEY][getCharCode(";")]=STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE|ACTION.IGNORE,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_KEY][getCharCode("{")]=STYLE_ATTR_VALUE_STATE.IN_KEY|ACTION.REFEED,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_KEY][BASE_STATE.OTHERS]=STYLE_ATTR_VALUE_STATE.IN_KEY,this.FillTT(STYLE_ATTR_VALUE_STATE.IN_KEY,STYLE_ATTR_VALUE_STATE.WAIT_KEY_VALUE_SAPERATE,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY][getCharCode(":")]=STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY][getCharCode(";")]=STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY][getCharCode("{")]=STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY][getCharCode('"')]=BASE_STATE.ERROR,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY][getCharCode("'")]=BASE_STATE.ERROR,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY][BASE_STATE.OTHERS]=STYLE_ATTR_VALUE_STATE.IN_KEY,this.FillTT(STYLE_ATTR_VALUE_STATE.WAIT_KEY_VALUE_SAPERATE,STYLE_ATTR_VALUE_STATE.WAIT_KEY_VALUE_SAPERATE,ACTION.IGNORE," \n\t\r"),this.TT[STYLE_ATTR_VALUE_STATE.WAIT_KEY_VALUE_SAPERATE][getCharCode(":")]=STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_KEY_VALUE_SAPERATE][getCharCode(";")]=STYLE_ATTR_VALUE_STATE.WAIT_KEY|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_KEY_VALUE_SAPERATE][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.FillTT(STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE,STYLE_ATTR_VALUE_STATE.WAIT_VALUE,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE][getCharCode(":")]=STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE][getCharCode(";")]=STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE][BASE_STATE.OTHERS]=STYLE_ATTR_VALUE_STATE.IN_VALUE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE][getCharCode("\0")]=BASE_STATE.END|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE][getCharCode('"')]=STYLE_ATTR_VALUE_STATE.IN_VALUE|ACTION.REFEED,this.TT[STYLE_ATTR_VALUE_STATE.IN_KEY_VALUE_SAPERATE][getCharCode("'")]=STYLE_ATTR_VALUE_STATE.IN_VALUE|ACTION.REFEED,this.FillTT(STYLE_ATTR_VALUE_STATE.WAIT_VALUE,STYLE_ATTR_VALUE_STATE.WAIT_VALUE,ACTION.IGNORE," \n\t\r"),this.TT[STYLE_ATTR_VALUE_STATE.WAIT_VALUE][getCharCode(":")]=BASE_STATE.ERROR,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_VALUE][getCharCode(";")]=STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_VALUE][getCharCode("{")]=STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_VALUE][getCharCode('"')]=STYLE_ATTR_VALUE_STATE.IN_VALUE|ACTION.REFEED,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_VALUE][getCharCode("'")]=STYLE_ATTR_VALUE_STATE.IN_VALUE|ACTION.REFEED,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_VALUE][getCharCode("\0")]=BASE_STATE.END,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_VALUE][BASE_STATE.OTHERS]=STYLE_ATTR_VALUE_STATE.IN_VALUE,this.TT[STYLE_ATTR_VALUE_STATE.IN_VALUE][getCharCode(";")]=STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_VALUE][getCharCode('"')]=STYLE_ATTR_VALUE_STATE.IN_STRING|ACTION.STORE_STATE_BEFORE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_VALUE][getCharCode("'")]=STYLE_ATTR_VALUE_STATE.IN_STRING2|ACTION.STORE_STATE_BEFORE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_VALUE][getCharCode("{")]=STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE,this.TT[STYLE_ATTR_VALUE_STATE.IN_VALUE][BASE_STATE.OTHERS]=STYLE_ATTR_VALUE_STATE.IN_VALUE,this.TT[STYLE_ATTR_VALUE_STATE.IN_VALUE][getCharCode("\0")]=BASE_STATE.END|ACTION.STORE_TOKEN_EXCLUDE,this.FillTT(STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE,STYLE_ATTR_VALUE_STATE.WAIT_KEY,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE][getCharCode(";")]=STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE|ACTION.IGNORE,this.TT[STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE][getCharCode("{")]=STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE,this.TT[STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE][getCharCode("'")]=BASE_STATE.ERROR,this.TT[STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE][getCharCode('"')]=BASE_STATE.ERROR,this.TT[STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE][BASE_STATE.OTHERS]=STYLE_ATTR_VALUE_STATE.IN_KEY|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.IN_ITEM_SAPERATE][getCharCode("\0")]=BASE_STATE.END|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_START][getCharCode("{")]=STYLE_ATTR_VALUE_STATE.IN_TEMPLATE|ACTION.STORE_TOKEN_FIRST,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_START][BASE_STATE.OTHERS]=ACTION.GET_STATE_BEFORE,this.TT[STYLE_ATTR_VALUE_STATE.IN_TEMPLATE][getCharCode("}")]=STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_END,this.TT[STYLE_ATTR_VALUE_STATE.IN_TEMPLATE][getCharCode("\\")]=BASE_STATE.ERROR,this.FillTT(STYLE_ATTR_VALUE_STATE.IN_TEMPLATE,STYLE_ATTR_VALUE_STATE.IN_TEMPLATE,ACTION.NOTHING," \n\t\r"),this.TT[STYLE_ATTR_VALUE_STATE.IN_TEMPLATE][BASE_STATE.OTHERS]=STYLE_ATTR_VALUE_STATE.IN_TEMPLATE,this.TT[STYLE_ATTR_VALUE_STATE.IN_TEMPLATE][0]=BASE_STATE.ERROR,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_END][getCharCode("}")]=ACTION.GET_STATE_BEFORE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STYLE_ATTR_VALUE_STATE.WAIT_TEMPLATE_END][BASE_STATE.OTHERS]=STYLE_ATTR_VALUE_STATE.IN_TEMPLATE|ACTION.REFEED,this.TT[STYLE_ATTR_VALUE_STATE.IN_TEMPLATE][getCharCode('"')]=STYLE_ATTR_VALUE_STATE.IN_TEMPLATE_STRING|ACTION.NOTHING,this.TT[STYLE_ATTR_VALUE_STATE.IN_TEMPLATE][getCharCode("'")]=STYLE_ATTR_VALUE_STATE.IN_TEMPLATE_STRING2|ACTION.NOTHING,this.FillTT_template_string(STYLE_ATTR_VALUE_STATE.IN_TEMPLATE_STRING,STYLE_ATTR_VALUE_STATE.IN_TEMPLATE|ACTION.NOTHING,'"'),this.FillTT_template_string(STYLE_ATTR_VALUE_STATE.IN_TEMPLATE_STRING2,STYLE_ATTR_VALUE_STATE.IN_TEMPLATE|ACTION.NOTHING,"'"),this.FillTT_string(STYLE_ATTR_VALUE_STATE.IN_STRING,ACTION.GET_STATE_BEFORE,'"'),this.FillTT_string(STYLE_ATTR_VALUE_STATE.IN_STRING2,ACTION.GET_STATE_BEFORE,"'")}}class TemplateMachine extends BaseMachine{get TT(){return TemplateMachine._TT||this.InitTransitTable(),TemplateMachine._TT}constructor(T,E){super(T,E),this.mState.state=BASE_STATE.START}getTokens(){return[...this.tokens]}appendToken(T,E){this.tokens.push(new Token(T,E))}doExcludeAction(T,E){let A=TokenType.OTHERS;switch(T){case TEMPLATE_STATE.IN_TEMPLATE_ITEM:A=TokenType.TEMPLATE_ITEM}this.appendToken(A,E)}doIncludeAction(T,E,A){let _=TokenType.OTHERS;switch(E){case TEMPLATE_STATE.WAIT_TEMPLATE_START:_=TokenType.TEMPLATE_START;break;case TEMPLATE_STATE.WAIT_TEMPLATE_END:_=TokenType.TEMPLATE_END}this.appendToken(_,A)}InitTransitTable(){TemplateMachine._TT=new Array(TEMPLATE_STATE.MAX_STATE);for(let T=0;T<TEMPLATE_STATE.MAX_STATE;T++){const E=new Array(257);E.fill(0),this.TT[T]=E}this.FillTT(BASE_STATE.START,BASE_STATE.START,ACTION.IGNORE," \n\t\r"),this.TT[BASE_STATE.START][getCharCode("{")]=TEMPLATE_STATE.WAIT_TEMPLATE_START,this.TT[BASE_STATE.START][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.TT[TEMPLATE_STATE.WAIT_TEMPLATE_START][getCharCode("{")]=TEMPLATE_STATE.IN_TEMPLATE_ITEM|ACTION.STORE_TOKEN_INCLUDE,this.TT[TEMPLATE_STATE.WAIT_TEMPLATE_START][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.FillTT(TEMPLATE_STATE.IN_TEMPLATE_SPACE,TEMPLATE_STATE.IN_TEMPLATE_SPACE,ACTION.IGNORE," \n\t\r"),this.TT[TEMPLATE_STATE.IN_TEMPLATE_SPACE][getCharCode("}")]=TEMPLATE_STATE.WAIT_TEMPLATE_END,this.TT[TEMPLATE_STATE.IN_TEMPLATE_SPACE][getCharCode('"')]=TEMPLATE_STATE.IN_TEMPLATE_STRING|ACTION.STORE_STATE_BEFORE,this.TT[TEMPLATE_STATE.IN_TEMPLATE_SPACE][getCharCode("'")]=TEMPLATE_STATE.IN_TEMPLATE_STRING2|ACTION.STORE_STATE_BEFORE,this.TT[TEMPLATE_STATE.IN_TEMPLATE_SPACE][getCharCode("/")]=TEMPLATE_STATE.WAIT_FOR_COMMENT_START,this.TT[TEMPLATE_STATE.IN_TEMPLATE_SPACE][BASE_STATE.OTHERS]=TEMPLATE_STATE.IN_TEMPLATE_ITEM,this.FillTT(TEMPLATE_STATE.IN_TEMPLATE_ITEM,TEMPLATE_STATE.IN_TEMPLATE_SPACE,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[TEMPLATE_STATE.IN_TEMPLATE_ITEM][getCharCode("}")]=TEMPLATE_STATE.WAIT_TEMPLATE_END,this.TT[TEMPLATE_STATE.IN_TEMPLATE_ITEM][getCharCode("\\")]=BASE_STATE.ERROR,this.TT[TEMPLATE_STATE.IN_TEMPLATE_ITEM][getCharCode('"')]=TEMPLATE_STATE.IN_TEMPLATE_STRING|ACTION.STORE_STATE_BEFORE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[TEMPLATE_STATE.IN_TEMPLATE_ITEM][getCharCode("'")]=TEMPLATE_STATE.IN_TEMPLATE_STRING2|ACTION.STORE_STATE_BEFORE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[TEMPLATE_STATE.IN_TEMPLATE_ITEM][BASE_STATE.OTHERS]=TEMPLATE_STATE.IN_TEMPLATE_ITEM,this.TT[TEMPLATE_STATE.IN_TEMPLATE_ITEM][0]=BASE_STATE.ERROR,this.TT[TEMPLATE_STATE.WAIT_FOR_COMMENT_START][getCharCode("*")]=TEMPLATE_STATE.IN_COMMENT,this.FillTT(TEMPLATE_STATE.WAIT_FOR_COMMENT_START,TEMPLATE_STATE.IN_TEMPLATE_ITEM,ACTION.REFEED," \n\t\r"),this.TT[TEMPLATE_STATE.WAIT_FOR_COMMENT_START][BASE_STATE.OTHERS]=TEMPLATE_STATE.IN_TEMPLATE_ITEM,this.TT[TEMPLATE_STATE.IN_COMMENT][getCharCode("*")]=TEMPLATE_STATE.WAIT_FOR_COMMENT_END,this.TT[TEMPLATE_STATE.IN_COMMENT][BASE_STATE.OTHERS]=TEMPLATE_STATE.IN_COMMENT,this.TT[TEMPLATE_STATE.WAIT_FOR_COMMENT_END][getCharCode("/")]=TEMPLATE_STATE.IN_TEMPLATE_SPACE|ACTION.IGNORE,this.FillTT_template_string(TEMPLATE_STATE.IN_TEMPLATE_STRING,TEMPLATE_STATE.IN_TEMPLATE_ITEM|ACTION.STORE_TOKEN_INCLUDE|ACTION.GET_STATE_BEFORE,'"'),this.FillTT_template_string(TEMPLATE_STATE.IN_TEMPLATE_STRING2,TEMPLATE_STATE.IN_TEMPLATE_ITEM|ACTION.STORE_TOKEN_INCLUDE|ACTION.GET_STATE_BEFORE,"'"),this.TT[TEMPLATE_STATE.WAIT_TEMPLATE_END][getCharCode("}")]=BASE_STATE.END|ACTION.STORE_TOKEN_INCLUDE,this.TT[TEMPLATE_STATE.WAIT_TEMPLATE_END][BASE_STATE.OTHERS]=TEMPLATE_STATE.IN_TEMPLATE_ITEM|ACTION.REFEED,this.FillTT(BASE_STATE.END,BASE_STATE.END,ACTION.IGNORE," \n\t\r"),this.TT[BASE_STATE.END][getCharCode("\0")]=BASE_STATE.END,this.TT[BASE_STATE.END][BASE_STATE.OTHERS]=BASE_STATE.ERROR}}class TemplateTokenizer{constructor(T,E){this.machine=new TemplateMachine(E,T),this.m_pSrc=T,this.path=E}toString(){this.tokens||(this.tokens=this.generateTokens());const T=this.tokens.map(T=>T.value).join("");return T.endsWith("}}}")?T.replace(/}}}$/,"} }}"):T}generateTokens(){if(this.machine.Reset(),0===this.m_pSrc.length)return[];for(let T=0;T<this.m_pSrc.length;T++){const E=this.m_pSrc[T];this.machine.Feed(E)}return this.machine.Feed("\0"),this.machine.getTokens()}}exports.TemplateTokenizer=TemplateTokenizer;class StyleAttrValueTokenizer{constructor(T,E){this.machine=new StyleAttrValueMachine(E,T),this.m_pSrc=T,this.path=E}toString(){return this.tokens||(this.tokens=this.generateTokens()),this.tokens.map(T=>T.value).join("")}generateTokens(){if(this.machine.Reset(),0===this.m_pSrc.length)return[];for(let T=0;T<this.m_pSrc.length;T++){const E=this.m_pSrc[T];this.machine.Feed(E)}return this.machine.Feed("\0"),this.machine.getTokens()}}exports.StyleAttrValueTokenizer=StyleAttrValueTokenizer;class Machine extends BaseMachine{get TT(){return Machine._TT||this.InitTransitTable(),Machine._TT}constructor(T,E){super(T,E),this.tagStack=[],this.InitTransitTable(),this.mPath=T,this.mSrc=E}get wxsState(){return"wxs"===this.tagStack[this.tagStack.length-1]}get textState(){return"text"===this.tagStack[this.tagStack.length-1]}getTokens(){return[...this.tokens]}checkLastTokenIfTypeMatch(T){var E;return(null===(E=this.tokens[this.tokens.length-1])||void 0===E?void 0:E.type)===T?this.tokens[this.tokens.length-1]:void 0}getLastTokenIfTypeMatch(T){if(0!==this.tokens.length)for(let E=this.tokens.length-1;E>=0;E--){const A=this.tokens[E];if(A.type===T)return A}}canBeOmittedTokenType(T){return T===TokenType.WXS_VALUE}appendToken(T,E){if(this.canBeOmittedTokenType(T)&&(E=this.transTagTextTokenValue(E)),T===TokenType.ATTR_VALUE){const T=this.getLastTokenIfTypeMatch(TokenType.ATTR);"style"===(null==T?void 0:T.value)&&(E=this.trySlimStyleAttrValue(E))}E&&this.tokens.push(new Token(T,E))}transTagTextTokenValue(T){return this.wxsState?(T=T.split("\n").map(T=>T.trim()).join("\n")).trim():T}trySlimStyleAttrValue(T){const E=[];try{if(T.length<=1)return T;for(let T=this.tokens.length-1;T>=0;T--){if(this.tokens[T].type===TokenType.TAG_EQ)break;E.unshift(this.tokens.pop())}const A=`${E.map(T=>null==T?void 0:T.value).join("")}${T}`,_=A.startsWith('"')||A.startsWith("'"),S=A.endsWith('"')||A.endsWith("'"),t=new StyleAttrValueTokenizer(A.replace(/^['"]/,"").replace(/['"]$/,""),this.mPath).toString();return`${_?A.substr(0,1):""}${t}${S?A.substr(A.length-1,1):""}`}catch(T){console.error(T),this.tokens.push(...E)}return T}doExcludeAction(T,E){let A=TokenType.OTHERS;switch(T){case STATE.IN_TAG_ATTR_VALUE_STRING:case STATE.IN_TAG_ATTR_VALUE_STRING_SINGLE:A=TokenType.ATTR_VALUE;break;case STATE.IN_TAG_WORD:A=TokenType.TAG,this.tagStack.push(E);break;case STATE.IN_END_TAG_WORD:A=TokenType.TAG;if(this.tagStack.pop()!==E)throw{col:this.mState.col-E.length,line:this.mState.line,message:"unexpected end tag: "+E};break;case STATE.IN_WXS:A=TokenType.WXS_VALUE;break;case STATE.IN_TEXT:A=TokenType.TEXT_VALUE;break;case STATE.IN_TAG_TEXT:A=TokenType.TAG_TEXT_VALUE;break;case STATE.IN_TAG_ATTR_WORD:A=TokenType.ATTR;break;case STATE.TAG_START:A=TokenType.LEFT_ANGLE_BRACKET;break;case STATE.IN_TEMPLATE:A=TokenType.TEMPLATE_ITEM;break;case STATE.TAG_EQ:A=TokenType.TAG_EQ;break;case STATE.TEMPLATE_END_CHECK:this.appendToken(TokenType.TEMPLATE_ITEM,""+new TemplateTokenizer(E,this.mPath)),A=TokenType.TEMPLATE_END,E=""}this.appendToken(A,E)}doIncludeAction(T,E,A){const _=this.mState.state;let S;E===STATE.WXS_END_STEP?(this.appendToken(TokenType.WXS_VALUE,A.substr(0,A.length-2)),S=TokenType.END_LEFT_ANGLE_BRACKET,A="</"):E===STATE.IN_WXS_STRING||E===STATE.IN_WXS_STRING_SINGLE?S=TokenType.WXS_VALUE:E===STATE.IN_TAG_ATTR_VALUE_STRING||E===STATE.IN_TAG_ATTR_VALUE_STRING_SINGLE?S=TokenType.ATTR_VALUE:E===STATE.TAG_START&&_===STATE.IN_END_TAG?S=TokenType.END_LEFT_ANGLE_BRACKET:E===STATE.WAIT_FOR_RIGHT_BRACKET?(S=TokenType.SELF_CLOSE,this.tagStack.pop()):S=TokenType.OTHERS,">"!==T||E!==STATE.IN_TAG_WORD&&E!==STATE.IN_TAG_ATTR_WORD&&E!==STATE.IN_TAG_ATTR_VALUE_STRING&&E!==STATE.IN_TAG_ATTR_VALUE_STRING_SINGLE&&E!==STATE.IN_END_TAG_WORD||(S=TokenType.RIGHT_ANGLE_BRACKET),this.appendToken(S,A)}Feed(T){super.Feed(T),this.wxsState&&this.mState.state===STATE.IN_TAG_TEXT&&(this.mState.state=STATE.IN_WXS),this.textState&&this.mState.state===STATE.IN_TAG_TEXT&&(this.mState.state=STATE.IN_TEXT)}FillTT_attr_string(T,E,A){const _=T+1;this.TT[T][getCharCode("\\")]=_,this.TT[T][getCharCode("\n")]=BASE_STATE.ERROR,this.TT[_][BASE_STATE.OTHERS]=T,this.TT[_][getCharCode("\n")]=E|ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE,this.TT[T][getCharCode(A)]=E|ACTION.STORE_TOKEN_INCLUDE,this.TT[T][getCharCode("{")]=STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE,this.TT[T][0]=BASE_STATE.ERROR,this.TT[T][BASE_STATE.OTHERS]=T}InitTransitTable(){Machine._TT=new Array(STATE.MAX_STATE);for(let T=0;T<STATE.MAX_STATE;T++){const E=new Array(257);E.fill(0),this.TT[T]=E}this.TT[BASE_STATE.END][BASE_STATE.OTHERS]=BASE_STATE.END,this.TT[BASE_STATE.START][getCharCode("<")]=STATE.TAG_START|ACTION.STORE_TOKEN_EXCLUDE|ACTION.STORE_STATE_BEFORE,this.TT[BASE_STATE.START][getCharCode("{")]=STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE,this.TT[BASE_STATE.START][BASE_STATE.OTHERS]=STATE.IN_TAG_TEXT|ACTION.NOTHING,this.TT[BASE_STATE.START][0]=BASE_STATE.END|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_TAG_TEXT][getCharCode("<")]=STATE.TAG_START|ACTION.STORE_TOKEN_EXCLUDE|ACTION.STORE_STATE_BEFORE,this.TT[STATE.IN_TAG_TEXT][getCharCode("{")]=STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE,this.TT[STATE.IN_TAG_TEXT][BASE_STATE.OTHERS]=STATE.IN_TAG_TEXT|ACTION.NOTHING,this.TT[STATE.IN_TAG_TEXT][0]=BASE_STATE.END|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_TAG_TEXT][BASE_STATE.OTHERS]=STATE.IN_TAG_TEXT,this.TT[STATE.WAIT_TEMPLATE_START][getCharCode("{")]=STATE.IN_TEMPLATE|ACTION.STORE_TOKEN_FIRST,this.TT[STATE.WAIT_TEMPLATE_START][BASE_STATE.OTHERS]=STATE.IN_TAG_TEXT|ACTION.GET_STATE_BEFORE,this.TT[STATE.IN_TEMPLATE][getCharCode("}")]=STATE.WAIT_TEMPLATE_END,this.TT[STATE.IN_TEMPLATE][getCharCode("\\")]=BASE_STATE.ERROR,this.FillTT(STATE.IN_TEMPLATE,STATE.IN_TEMPLATE,ACTION.NOTHING," \n\t\r"),this.TT[STATE.IN_TEMPLATE][BASE_STATE.OTHERS]=STATE.IN_TEMPLATE,this.TT[STATE.IN_TEMPLATE][0]=BASE_STATE.ERROR,this.TT[STATE.WAIT_TEMPLATE_END][getCharCode("}")]=STATE.TEMPLATE_END_CHECK,this.TT[STATE.TEMPLATE_END_CHECK][getCharCode("}")]=BASE_STATE.ERROR,this.TT[STATE.TEMPLATE_END_CHECK][BASE_STATE.OTHERS]=STATE.IN_TAG_TEXT|ACTION.REFEED|ACTION.STORE_TOKEN_EXCLUDE|ACTION.GET_STATE_BEFORE,this.TT[STATE.WAIT_TEMPLATE_END][BASE_STATE.OTHERS]=STATE.IN_TEMPLATE|ACTION.REFEED,this.TT[STATE.IN_TEMPLATE][getCharCode('"')]=STATE.IN_TEMPLATE_STRING|ACTION.NOTHING,this.TT[STATE.IN_TEMPLATE][getCharCode("'")]=STATE.IN_TEMPLATE_STRING2|ACTION.NOTHING,this.FillTT_template_string(STATE.IN_TEMPLATE_STRING,STATE.IN_TEMPLATE|ACTION.NOTHING,'"'),this.FillTT_template_string(STATE.IN_TEMPLATE_STRING2,STATE.IN_TEMPLATE|ACTION.NOTHING,"'"),this.FillTT(STATE.TAG_START,STATE.TAG_START,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.FillTT(STATE.TAG_START,STATE.IN_TAG_WORD,ACTION.STORE_TOKEN_EXCLUDE,ALPHA),this.TT[STATE.TAG_START][getCharCode("/")]=STATE.IN_END_TAG|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.TAG_START][getCharCode("!")]=STATE.IN_COMMENT_BEGIN1,this.TT[STATE.TAG_START][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.TT[STATE.IN_COMMENT_BEGIN1][getCharCode("-")]=STATE.IN_COMMENT_BEGIN2,this.TT[STATE.IN_COMMENT_BEGIN1][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.TT[STATE.IN_COMMENT_BEGIN2][getCharCode("-")]=STATE.IN_COMMENT,this.TT[STATE.IN_COMMENT_BEGIN2][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.TT[STATE.IN_COMMENT][getCharCode("-")]=STATE.WAIT_FOR_COMMENT_END1,this.TT[STATE.IN_COMMENT][BASE_STATE.OTHERS]=STATE.IN_COMMENT,this.TT[STATE.WAIT_FOR_COMMENT_END1][getCharCode("-")]=STATE.WAIT_FOR_COMMENT_END2,this.TT[STATE.WAIT_FOR_COMMENT_END1][BASE_STATE.OTHERS]=STATE.IN_COMMENT,this.TT[STATE.WAIT_FOR_COMMENT_END2][getCharCode(">")]=STATE.IN_TAG_TEXT|ACTION.IGNORE|ACTION.GET_STATE_BEFORE,this.TT[STATE.WAIT_FOR_COMMENT_END2][getCharCode("-")]=STATE.WAIT_FOR_COMMENT_END2,this.TT[STATE.WAIT_FOR_COMMENT_END2][BASE_STATE.OTHERS]=STATE.IN_COMMENT,this.FillTT(STATE.IN_TAG_WORD,STATE.IN_TAG_WORD,ACTION.NOTHING,ALPHA),this.FillTT(STATE.IN_TAG_WORD,STATE.IN_TAG_WORD,ACTION.NOTHING,DIGIT),this.FillTT(STATE.IN_TAG_WORD,STATE.IN_TAG_ATTR_WORD,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[STATE.IN_TAG_WORD][getCharCode(">")]=STATE.IN_TAG_TEXT|ACTION.STORE_TOKEN_EXCLUDE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.IN_TAG_WORD][getCharCode("/")]=STATE.WAIT_FOR_RIGHT_BRACKET|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_TAG_WORD][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.TT[STATE.IN_TAG_WORD][0]=BASE_STATE.ERROR,this.FillTT(STATE.IN_TAG_ATTR_WORD,STATE.IN_TAG_ATTR_WORD,ACTION.NOTHING,ALPHA),this.FillTT(STATE.IN_TAG_ATTR_WORD,STATE.IN_TAG_ATTR_WORD,ACTION.NOTHING,DIGIT),this.FillTT(STATE.IN_TAG_ATTR_WORD,STATE.IN_TAG_ATTR_WORD,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[STATE.IN_TAG_ATTR_WORD][getCharCode("=")]=STATE.TAG_EQ|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_TAG_ATTR_WORD][getCharCode('"')]=BASE_STATE.ERROR,this.TT[STATE.IN_TAG_ATTR_WORD][getCharCode(">")]=STATE.IN_TAG_TEXT|ACTION.STORE_TOKEN_EXCLUDE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.IN_TAG_ATTR_WORD][getCharCode("/")]=STATE.WAIT_FOR_RIGHT_BRACKET|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_TAG_ATTR_WORD][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.TT[STATE.IN_TAG_ATTR_WORD][0]=BASE_STATE.ERROR,this.FillTT(STATE.TAG_EQ,STATE.TAG_EQ,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.FillTT(STATE.TAG_EQ,STATE.IN_TAG_ATTR_VALUE_STRING,ACTION.STORE_TOKEN_EXCLUDE,ALPHA),this.TT[STATE.TAG_EQ][getCharCode('"')]=STATE.IN_TAG_ATTR_VALUE_STRING|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.TAG_EQ][getCharCode("'")]=STATE.IN_TAG_ATTR_VALUE_STRING_SINGLE|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.TAG_EQ][0]=BASE_STATE.ERROR,this.TT[STATE.TAG_EQ][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.FillTT(STATE.IN_END_TAG,STATE.IN_END_TAG,ACTION.IGNORE," \n\t\r"),this.FillTT(STATE.IN_END_TAG,STATE.IN_END_TAG_WORD,ACTION.NOTHING,ALPHA),this.FillTT(STATE.IN_END_TAG,BASE_STATE.ERROR,ACTION.NOTHING,DIGIT),this.TT[STATE.IN_END_TAG][getCharCode(">")]=STATE.IN_TAG_TEXT|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.IN_END_TAG][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.FillTT(STATE.IN_END_TAG_WORD,STATE.IN_END_TAG_WORD,ACTION.NOTHING,ALPHA),this.FillTT(STATE.IN_END_TAG_WORD,STATE.IN_END_TAG_WORD,ACTION.NOTHING,DIGIT),this.FillTT(STATE.IN_END_TAG_WORD,STATE.IN_END_TAG,ACTION.STORE_TOKEN_EXCLUDE|ACTION.IGNORE," \n\t\r"),this.TT[STATE.IN_END_TAG_WORD][getCharCode(">")]=STATE.IN_TAG_TEXT|ACTION.STORE_TOKEN_EXCLUDE|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.IN_END_TAG_WORD][getCharCode("/")]=STATE.WAIT_FOR_RIGHT_BRACKET|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_END_TAG_WORD][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.FillTT(STATE.WAIT_FOR_RIGHT_BRACKET,STATE.IN_TAG_WORD,ACTION.STORE_TOKEN_EXCLUDE,ALPHA),this.TT[STATE.WAIT_FOR_RIGHT_BRACKET][getCharCode(">")]=STATE.IN_TAG_TEXT|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.WAIT_FOR_RIGHT_BRACKET][BASE_STATE.OTHERS]=BASE_STATE.ERROR,this.FillTT_attr_string(STATE.IN_TAG_ATTR_VALUE_STRING,STATE.IN_TAG_ATTR_WORD,'"'),this.FillTT_attr_string(STATE.IN_TAG_ATTR_VALUE_STRING_SINGLE,STATE.IN_TAG_ATTR_WORD,"'"),this.TT[STATE.IN_WXS][getCharCode("<")]=STATE.WXS_END_STEP,this.TT[STATE.IN_WXS][getCharCode('"')]=STATE.IN_WXS_STRING|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_WXS][getCharCode("'")]=STATE.IN_WXS_STRING_SINGLE|ACTION.STORE_TOKEN_EXCLUDE,this.FillTT_attr_string(STATE.IN_WXS_STRING,STATE.IN_WXS,'"'),this.FillTT_attr_string(STATE.IN_WXS_STRING_SINGLE,STATE.IN_WXS,"'"),this.TT[STATE.IN_WXS][BASE_STATE.OTHERS]=STATE.IN_WXS,this.TT[STATE.WXS_END_STEP][getCharCode("/")]=STATE.IN_END_TAG|ACTION.STORE_TOKEN_INCLUDE,this.TT[STATE.WXS_END_STEP][BASE_STATE.OTHERS]=STATE.IN_WXS,this.TT[STATE.IN_TEXT][getCharCode("<")]=STATE.TAG_START|ACTION.STORE_TOKEN_EXCLUDE,this.TT[STATE.IN_TEXT][BASE_STATE.OTHERS]=STATE.IN_TEXT,this.TT[STATE.IN_TEXT][getCharCode("{")]=STATE.WAIT_TEMPLATE_START|ACTION.STORE_STATE_BEFORE}}class Tokenizer{constructor(T,E){this.machine=new Machine(E,T),this.m_pSrc=T,this.path=E}generateTokens(){if(this.machine.Reset(),0===this.m_pSrc.length)return[];try{for(let T=0;T<this.m_pSrc.length;T++){const E=this.m_pSrc[T];this.machine.Feed(E)}this.machine.Feed("\0")}catch(T){throw new Error(`${T.line}:${T.col}:${T.message}`)}return this.machine.getTokens()}}function generateWXMLFromTokens(T,E={collapseWhitespace:!0,conservativeCollapse:!1,preserveLineBreaks:!1}){const{collapseWhitespace:A,conservativeCollapse:_,preserveLineBreaks:S}=E,t=[];for(let E=0;E<T.length;E++){const e=T[E];let N=e.value;const I=e.type;if(I===TokenType.ATTR&&(N=" "+N),I===TokenType.TAG_TEXT_VALUE){S||(N=N.replace(/\n/g," ")),A&&(N=N.replace(/([ \t])+/g," "));const t=T[E-1];t&&t.type!==TokenType.RIGHT_ANGLE_BRACKET&&t.type!==TokenType.SELF_CLOSE||A&&!_&&(N=trimStringLeft(N,!1)),(null==t?void 0:t.type)===TokenType.TAG_TEXT_VALUE&&((null==t?void 0:t.value.endsWith(" "))||(null==t?void 0:t.value.endsWith("\n")))&&A&&(N=trimStringLeft(N,!1))}if(I===TokenType.LEFT_ANGLE_BRACKET||I===TokenType.END_LEFT_ANGLE_BRACKET){const S=T[E-1];if((null==S?void 0:S.type)===TokenType.TAG_TEXT_VALUE&&A&&!_){const T=t.pop()||"";t.push(trimStringRight(T,!1))}}t.push(N)}return t.join("")}async function minifyWXML(T){const{filePath:E,root:A=""}=T,_=T.code instanceof Buffer?T.code.toString():T.code,S=Object.assign({collapseWhitespace:!0,conservativeCollapse:!1,preserveLineBreaks:!1},T.setting),t=path_1.default.posix.join(A,E);if(_.length>0)try{const T=new Tokenizer(_.replace(/\r\n/g,"\n"),t);return{error:null,code:generateWXMLFromTokens(T.generateTokens(),S)}}catch(T){return log.error("minifywxml error @ "+t),log.error(T.message),{error:{code:config_1.MINIFY_WXML_ERR,path:t,message:T.message}}}return{error:null,code:_.replace(/\r\n/g,"\n")}}exports.minifyWXML=minifyWXML;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OriginalCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=tslib_1.__importDefault(require("lodash")),baseCompiler_1=require("./baseCompiler"),original_1=require("./original"),tools_1=require("../../utils/tools");class OriginalCompiler extends baseCompiler_1.BaseCoreCompiler{constructor(e){super(e),this.isSummer=!1,this.ready()}destroy(){this._checkReadyTask=void 0,this.compileManager=void 0}async init(){this.compileManager=new original_1.OriginalCompileManager(this.project)}async isGameApp(){if(!this.project)return!1;const e=await this.project.attr();return null==e?void 0:e.gameApp}checkProject(){}async getExtJSON(){return await this.compileManager.getExtJSON()}async getAppJSON(){return this.checkProject(),await this.compileManager.getAppJSON()}async getSiteMapJSON(){const e=await this.compileManager.getSiteMapJSON();return lodash_1.default.cloneDeep(e)}async getPageJSON(e){this.checkProject();return await this.compileManager.getPageJSON({miniprogramRoot:this.project.miniprogramRoot,pagePath:e})}async getGameJSON(){return this.checkProject(),this.compileManager.getGameJSON()}async getPluginJSON(e=""){return this.checkProject(),await this.compileManager.getPluginJSON(e)}async getPluginPageJSON(e){this.checkProject();return await this.compileManager.getPluginPageJSON({root:this.project.pluginRoot,project:this.project,filePath:path_1.default.posix.join(this.project.pluginRoot||"",e+".json")})}async getPluginComponents(){var e;const t=this.getPluginJSONFileList(),o=[];for(let i=0,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OriginalCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=tslib_1.__importDefault(require("lodash")),baseCompiler_1=require("./baseCompiler"),original_1=require("./original"),tools_1=require("../../utils/tools");class OriginalCompiler extends baseCompiler_1.BaseCoreCompiler{constructor(e){super(e),this.isSummer=!1,this.ready()}destroy(){this._checkReadyTask=void 0,this.compileManager=void 0}async init(){this.compileManager=new original_1.OriginalCompileManager(this.project)}async isGameApp(){if(!this.project)return!1;const e=await this.project.attr();return null==e?void 0:e.gameApp}checkProject(){}async getExtJSON(){return await this.compileManager.getExtJSON()}async getAppJSON(){return this.checkProject(),await this.compileManager.getAppJSON()}async getSiteMapJSON(){const e=await this.compileManager.getSiteMapJSON();return lodash_1.default.cloneDeep(e)}async getPageJSON(e){this.checkProject();return await this.compileManager.getPageJSON({miniprogramRoot:this.project.miniprogramRoot,pagePath:e})}async getGameJSON(){return this.checkProject(),this.compileManager.getGameJSON()}async getPluginJSON(e=""){return this.checkProject(),await this.compileManager.getPluginJSON(e)}async getPluginPageJSON(e){this.checkProject();return await this.compileManager.getPluginPageJSON({root:this.project.pluginRoot,project:this.project,filePath:path_1.default.posix.join(this.project.pluginRoot||"",e+".json")})}async getPluginComponents(){var e;const t=this.getPluginJSONFileList(),o=[];for(let i=0,r=t.length;i<r;i++){const r=t[i].replace(/\.json$/,"");"plugin"!==path_1.default.normalize(r)&&(this.isValidComponent(null===(e=this.project)||void 0===e?void 0:e.pluginRoot,r)&&o.push(r))}return o}getWxssMap(e,t){throw new Error("Method not implemented.")}async getPluginJSFiles(){const e=this.getPluginJSFileList();return{jsFiles:e,content:e.reduce((e,t)=>{var o;return e[t]=this.project.getFile((null===(o=this.project)||void 0===o?void 0:o.pluginRoot)||"",t).toString(),e},{})}}async getPluginWxssFiles(){const e=this.getPluginWXSSFileList();return{wxssFiles:e,content:e.reduce((e,t)=>{var o;return e[t]=this.project.getFile((null===(o=this.project)||void 0===o?void 0:o.pluginRoot)||"",t).toString(),e},{})}}async getPluginWxmlAndWxsFiles(){const e=this.getPluginWXSFileList(),t=this.getPluginWXMLFileList(),o=e.concat(t);return{wxsFiles:e,wxmlFiles:t,content:o.reduce((e,t)=>{var o;return e[t]=this.project.getFile((null===(o=this.project)||void 0===o?void 0:o.pluginRoot)||"",t).toString(),e},{})}}async getMPFileInfo(){var e,t;const o=null===(e=this.project)||void 0===e?void 0:e.miniprogramRoot;return this.excludeKeyRoot(this.getAllFileInfo(null===(t=this.project)||void 0===t?void 0:t.miniprogramRoot),o)}async getPluginFileInfo(){var e,t;const o=null===(e=this.project)||void 0===e?void 0:e.pluginRoot;return this.excludeKeyRoot(this.getAllFileInfo(null===(t=this.project)||void 0===t?void 0:t.pluginRoot),o)}async checkThemeJSON(e){return this.checkProject(),await this.compileManager.checkThemeJSON(e)}async compile(e){return this.checkProject(),await this.compileManager.compile({nameMapping:e.nameMapping||{},setting:e.setting,onProgressUpdate:e.onProgressUpdate,__compileDebugInfo__:e.__compileDebugInfo__,compilePages:e.compilePages,analyzer:e.analyzer,devToolsCompileCache:e.devToolsCompileCache,disableSpreadingUsingComponents:e.disableSpreadingUsingComponents,resultType:e.resultType})}async compileJS(e){this.checkProject();const{root:t,filePath:o,babelRoot:i="@babel/runtime"}=e;try{return await this.compileManager.compileJS(o,{root:t,sourceCode:e.sourceCode,setting:Object.assign({},e.setting),babelRoot:i,onProgressUpdate:e.onProgressUpdate})}catch(e){throw e}}setLocale(e){this.compileManager.setLocale(e)}clearCache(){this.compileManager.clearCache()}async getPackageWxssFileList(e){return[]}async getPackageWxssFiles(e){return{}}async getPackageWxmlAndWxsFiles(e){return{}}async getAllWxmlAndWxsFiles(){return{}}getAllSortedJSFiles(){throw new Error("Method not implemented.")}getMainPkgSortedJSFiles(){throw new Error("Method not implemented.")}async getPackageFiles(e,t){if(this.isGameType(e)){const e=await this.getGameJSON(),o=this.getMPFileList();let i=e.workers||"";i="string"==typeof i?i:i.path;const r=e.openDataContext,n={__APP__:[],[r]:[]};i&&(n[i]=[]);for(const t of o)if(r&&(0,tools_1.isLeftSubPathOfRight)(t,r))n[r].push({path:t,source:t,sourceExt:path_1.default.extname(t),independentRoot:r,isBabelIgnore:!1});else if(i&&(0,tools_1.isLeftSubPathOfRight)(t,i))n[i].push({path:t,source:t,sourceExt:path_1.default.extname(t),independentRoot:"object"==typeof e.workers&&e.workers.isSubpackage?i:"",isBabelIgnore:!1});else{if(e.subPackages){let o=!1;for(const i of e.subPackages){const e=i.root.replace(/^\//,"");if((0,tools_1.isLeftSubPathOfRight)(t,e)){n[i.root]||(n[e]=[]),n[e].push({path:t,source:t,sourceExt:path_1.default.extname(t),independentRoot:i.independent?e:"",isBabelIgnore:!1}),o=!0;break}}if(o)continue}n.__APP__.push({path:t,source:t,sourceExt:path_1.default.extname(t),independentRoot:"",isBabelIgnore:!1})}return n[t]||[]}throw new Error("Method not implemented.")}getSubPkgSortedJSFiles(e){throw new Error("Method not implemented.")}getCompAndPagesOfConf(){throw new Error("Method not implemented.")}async getAllPageAndComponent(){var e;const t=this.getMPJSONFileList(),o=[];for(let i=0,r=t.length;i<r;i++){const r=t[i].replace(/\.json$/,"");this.isValidComponent(null===(e=this.project)||void 0===e?void 0:e.miniprogramRoot,r)&&o.push(r)}return o}}exports.OriginalCompiler=OriginalCompiler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AppGraph=void 0;const tools_1=require("../../../../utils/tools"),mpjson_1=require("../../original/compile/handler/mpjson"),config_1=require("../../../../config/config"),progressRecorder_1=require("../../../../utils/progressRecorder"),white_ext_list_1=require("../../../../utils/white_ext_list"),appconf_1=require("./appconf"),basegraph_1=require("./basegraph");class AppGraph extends basegraph_1.BaseGraph{constructor(e){super(e),this.appConf=new appconf_1.AppConf(this.compiler.proxyProject,this.root)}async getWhiteListConfig(){if(!this._whiteListConfig){const e=await(0,white_ext_list_1.getWhiteExtList)();this._whiteListConfig=e.MiniProgramWhiteList}return this._whiteListConfig}destroy(){this.appConf.destroy(),super.destroy()}async getConf(e){return this.conf=await this.appConf.getConf(e),this.conf}async compileSingleCode(e,t){await this.ensureConf(progressRecorder_1.silentRecorder);const s=this.resolver.resolveInfoMap.get(e);if(s)return super.doCompileSingleCode(Object.assign(Object.assign({},s),{independentRoot:this.getIndependentRoot(s.path),isBabelIgnore:this.isBabelSettingIgnore(s)}),t);throw new Error("file not found")}async getDevCode(e,t){let s=await this.getPackageFile(t.package);return s=s.filter(e=>!e.path.endsWith("json")),this.getCodeFiles(s,e)}async getProdCode(e,t){let s=await this.getPackageFile(t.package);return s=s.filter(e=>!e.path.endsWith("json")),this.getCodeFiles(s,e,Object.assign(Object.assign({},t),{useCache:!1,resultType:"prod"}))}getLocalCodeFileList(){return Array.from(this.resolver.resolveInfoMap.entries()).map(([e,t])=>t.source)}onFileChangeForGraph(e,t){this.appConf.onFileChange(e,t)}getIndependentRoot(e){for(const t of Object.values(this.conf.packages))if(!0===t.independent){const s=t.root.replace(/^\//,"");if(e.startsWith(s))return s}if("object"==typeof this.conf.app.functionalPages&&!0===this.conf.app.functionalPages.independent&&e.startsWith("functional-pages/"))return"functional-pages";if("string"==typeof this.conf.app.openDataContext&&e.startsWith(this.conf.app.openDataContext))return this.conf.app.openDataContext;const t=this.conf.app.workers&&(0,tools_1.getWorkersPath)(this.conf.app.workers);return t&&e.startsWith(t)?t:""}checkFilePackage(e){for(const t of Object.keys(this.conf.packages))if(e.startsWith(t))return t;return config_1.MainPkg}async compileJSON(e,t){const s=await this.getConf(progressRecorder_1.silentRecorder),o={};o["app.json"]=JSON.stringify(s.app);const{pageResults:n,componentResults:i}=await this.appConf.buildPagesAndCompsForUpload(progressRecorder_1.silentRecorder,e.disableSpreadingUsingComponents);return(0,mpjson_1.addSkylineRendererToComponents)(n,i),{conf:s,jsons:Object.assign(Object.assign(Object.assign({},o),n),i)}}async compileJSONWithFileList(e,t){const s=await this.getConf(progressRecorder_1.silentRecorder),o={};o["app.json"]=JSON.stringify(s.app);const{pageResults:n,componentResults:i}=await this.appConf.buildPagesAndCompsWithFileListForUpload(progressRecorder_1.silentRecorder,e.fileList,e.disableSpreadingUsingComponents);return(0,mpjson_1.addSkylineRendererToComponents)(n,i),{conf:s,jsons:Object.assign(Object.assign(Object.assign({},o),n),i)}}}exports.AppGraph=AppGraph;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AppGraph=void 0;const tools_1=require("../../../../utils/tools"),mpjson_1=require("../../original/compile/handler/mpjson"),config_1=require("../../../../config/config"),progressRecorder_1=require("../../../../utils/progressRecorder"),white_ext_list_1=require("../../../../utils/white_ext_list"),appconf_1=require("./appconf"),basegraph_1=require("./basegraph");class AppGraph extends basegraph_1.BaseGraph{constructor(e){super(e),this.appConf=new appconf_1.AppConf(this.compiler.proxyProject,this.root)}async getWhiteListConfig(){if(!this._whiteListConfig){const e=await(0,white_ext_list_1.getWhiteExtList)();this._whiteListConfig=e.MiniProgramWhiteList}return this._whiteListConfig}destroy(){this.appConf.destroy(),super.destroy()}async getConf(e){return this.conf=await this.appConf.getConf(e),this.conf}async compileSingleCode(e,t){await this.ensureConf(progressRecorder_1.silentRecorder);const s=this.resolver.resolveInfoMap.get(e);if(s)return super.doCompileSingleCode(Object.assign(Object.assign({},s),{independentRoot:this.getIndependentRoot(s.path),isBabelIgnore:this.isBabelSettingIgnore(s)}),t);throw new Error("file not found")}async getDevCode(e,t){let s=await this.getPackageFile(t.package);return s=s.filter(e=>!e.path.endsWith("json")),this.getCodeFiles(s,e)}async getProdCode(e,t){let s=await this.getPackageFile(t.package);return s=s.filter(e=>!e.path.endsWith("json")),this.getCodeFiles(s,e,Object.assign(Object.assign({},t),{useCache:!1,resultType:t.resultType||"prod"}))}getLocalCodeFileList(){return Array.from(this.resolver.resolveInfoMap.entries()).map(([e,t])=>t.source)}onFileChangeForGraph(e,t){this.appConf.onFileChange(e,t)}getIndependentRoot(e){for(const t of Object.values(this.conf.packages))if(!0===t.independent){const s=t.root.replace(/^\//,"");if(e.startsWith(s))return s}if("object"==typeof this.conf.app.functionalPages&&!0===this.conf.app.functionalPages.independent&&e.startsWith("functional-pages/"))return"functional-pages";if("string"==typeof this.conf.app.openDataContext&&e.startsWith(this.conf.app.openDataContext))return this.conf.app.openDataContext;const t=this.conf.app.workers&&(0,tools_1.getWorkersPath)(this.conf.app.workers);return t&&e.startsWith(t)?t:""}checkFilePackage(e){for(const t of Object.keys(this.conf.packages))if(e.startsWith(t))return t;return config_1.MainPkg}async compileJSON(e,t){const s=await this.getConf(progressRecorder_1.silentRecorder),o={};o["app.json"]=JSON.stringify(s.app);const{pageResults:n,componentResults:i}=await this.appConf.buildPagesAndCompsForUpload(progressRecorder_1.silentRecorder,e.disableSpreadingUsingComponents);return(0,mpjson_1.addSkylineRendererToComponents)(n,i),{conf:s,jsons:Object.assign(Object.assign(Object.assign({},o),n),i)}}async compileJSONWithFileList(e,t){const s=await this.getConf(progressRecorder_1.silentRecorder),o={};o["app.json"]=JSON.stringify(s.app);const{pageResults:n,componentResults:i}=await this.appConf.buildPagesAndCompsWithFileListForUpload(progressRecorder_1.silentRecorder,e.fileList,e.disableSpreadingUsingComponents);return(0,mpjson_1.addSkylineRendererToComponents)(n,i),{conf:s,jsons:Object.assign(Object.assign(Object.assign({},o),n),i)}}}exports.AppGraph=AppGraph;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseGraph=exports.JSONType=exports.FileType=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=require("lodash"),pluginDriver_1=require("../pluginDriver"),module_1=tslib_1.__importDefault(require("../module")),config_1=require("../../../../config/config"),resolver_1=require("../resolver"),common_1=require("../../original/compile/common"),packOptionsHelper_1=tslib_1.__importDefault(require("../../../../utils/packOptionsHelper")),tools_1=require("../../../../utils/tools"),babel_helper_1=require("../../../../utils/babel_helper"),helper_util_1=require("../../../../utils/helper_util"),progressRecorder_1=require("../../../../utils/progressRecorder"),locales_1=tslib_1.__importDefault(require("../../../../utils/locales/locales")),customError_1=require("../../../../utils/customError"),taskmanager_1=tslib_1.__importDefault(require("../../../../utils/taskmanager")),pluginconfig_1=require("../pluginconfig");var FileType,JSONType;function getFileType(e){let t=path_1.default.extname(e);if(t.startsWith(".")){if(t=t.slice(1),t===FileType.JS)return FileType.JS;if(t===FileType.WXML)return FileType.WXML;if(t===FileType.WXSS)return FileType.WXSS;if(t===FileType.WXS)return FileType.WXS;if(t===FileType.JSON)return FileType.JSON}throw Error("unknown the filetype of "+e)}!function(e){e.JSON="json",e.WXML="wxml",e.WXSS="wxss",e.WXS="wxs",e.JS="js"}(FileType=exports.FileType||(exports.FileType={})),function(e){e.APP="app",e.Page="page",e.EXT="ext",e.SITEMAP="sitemap",e.THEME="theme"}(JSONType=exports.JSONType||(exports.JSONType={}));class BaseGraph{constructor(e){var t;this.invalidated=!0,this.running=!1,this.onFileChange=(e,t)=>{t.startsWith(this.root)&&(t=t.replace(new RegExp("^"+this.root),""),this.resolver.onFileChange(e,t),"change"!==e&&"unlink"!==e||this.invalidateModules(t),this.onFileChangeForGraph(e,t))},this.getCodeFileTask=async(e,t,i={useCache:!0,resultType:"dev"})=>{const o=await this.loadModuleFromFile(e,t,i),s=o.toCodeFile();if(!("error"in s)&&"prod"===i.resultType){const e=o.toGenerateResult(),t=await this.optimize(e,i),r=await this.compress(t,i);s.code=r.target.code,s.map=r.target.map}return{file:e,codeFile:s,process:o.processInfo||[]}},this.type=e.type,this.root=e.root,this.rootPath=path_1.default.posix.join(e.compiler.project.projectPath,this.root),this.persistCache=e.persistCache,this.compiler=e.compiler,this.project=this.compiler.project,this.cachedModules=new Map,this.pluginDriver=new pluginDriver_1.PluginDriver(this,e),this.modulesByPath=new Map,this.resolver=new resolver_1.Resolver(this,this.root,this.pluginDriver.resolveExtConf),this.compiler.proxyProject.addResolver(this.resolver),null===(t=this.project.event)||void 0===t||t.on("fileChange",this.onFileChange)}destroy(){var e;this.compiler.proxyProject.removeResolver(this.resolver),null===(e=this.project.event)||void 0===e||e.off("fileChange",this.onFileChange)}clearCache(){this.modulesByPath.clear()}async ensureConf(e){this.conf||await this.getConf(e)}async getPackageFile(e){await this.ensureConf(progressRecorder_1.silentRecorder);const t=[];for(const[i,o]of this.resolver.resolveInfoMap.entries())e!==config_1.FullPkg&&this.checkFilePackage(i)!==e||t.push(o);return t.map(e=>Object.assign(Object.assign({},e),{independentRoot:this.getIndependentRoot(e.path),isBabelIgnore:this.isBabelSettingIgnore(e)}))}invalidateModules(e){for(const t of this.modulesByPath.values())(t.sourcePath===e||t.depFiles.includes(e))&&this.modulesByPath.delete(t.path)}async loadModuleFromFile(e,t,i={}){var o;let s=this.modulesByPath.get(e.path);if(null==s?void 0:s.loadingPromise)return await s.loadingPromise,this.loadModuleFromFile(e,t,i);let r=!s||s.sourcePath!==e.source||s.independentRoot!==e.independentRoot;if(!r&&(null==s?void 0:s.error)){if(s.loadEnd+1e3>Date.now())return s;r=!0}if(r){const r=getFileType(e.path);s=new module_1.default(this,e.path,e.source,r),s.independentRoot=e.independentRoot,e.isBabelIgnore&&(null===(o=s.jsTag)||void 0===o||o.setBabelIgnore()),this.modulesByPath.set(e.path,s),s.loadingPromise=t.run(locales_1.default.config.SUMMER_COMPILING_MODULE.format(e.source),()=>this.loadSourceForModule(s,i)),await s.loadingPromise,s.loadingPromise=void 0}return s}async loadSourceForModule(e,t={}){var i,o;try{const s=path_1.default.posix.join(this.rootPath,e.sourcePath),r=t=>Object.assign(Object.assign({},t),{rootPath:this.rootPath,addWatchFile:t=>{const i=(0,tools_1.normalizePath)(t);if(!i.startsWith(this.rootPath))throw(0,customError_1.makeCustomError)(`The file (${t}) required by ${e.sourcePath} is outside the project`,customError_1.CustomErrors.SUMMER_PLUGIN_CODE_ERR,e.path);e.addWatchFile(path_1.default.posix.relative(this.rootPath,i))}}),a=null!==(o=await this.pluginDriver.hookFirst("load",[e.path,s,Object.assign(Object.assign({},t),{independentRoot:e.independentRoot,isBabelIgnore:(null===(i=e.jsTag)||void 0===i?void 0:i.isBabelIgnore)||!1})],r))&&void 0!==o?o:{targetPath:e.path,source:{sourceCode:await this.readFile(s)},process:[{pluginName:"readFile",action:"load"}]},l=await this.tranform(a,e,r,t),n=await this.generate(l,e,r,t);return e.setResult(n),!0}catch(t){return t.path=path_1.default.posix.join(this.root,e.sourcePath),e.setError(t),!1}}async doCompileSingleCode(e,t){const i=getFileType(e.path),o=new module_1.default(this,e.path,e.source,i);if(await this.loadSourceForModule(o),o.error)throw o.error;return o.toCodeFile()}async getCodeFiles(e,t,i={useCache:!0,resultType:"dev"}){var o;const s=Date.now(),r={},a=new taskmanager_1.default({poolLimit:10,breakWhenError:!0});for(const o of e)a.addTask(this.getCodeFileTask,o,t,i);const l=await a.runAllAsync();for(const e of l)r[e.file.path]=e.codeFile,(null===(o=e.codeFile.jsTag)||void 0===o?void 0:o.isLargeFile)&&t.message("warn",locales_1.default.config.LARGEFILE_WARNING.format(e.file.path,config_1.MAX_CODE_LENGTH/1024));return console.info("!!!",`getCodeFiles: count: ${e.length}, cost: ${Date.now()-s}ms.`),r}async readFile(e){const t=path_1.default.relative(this.project.projectPath,e);return this.project.getFile("",t).toString()}async tranform(e,t,i,o={}){var s;return await this.pluginDriver.hookReduceArg0("transform",[e,t.path,t.sourcePath,Object.assign(Object.assign({},o),{independentRoot:t.independentRoot,isBabelIgnore:(null===(s=t.jsTag)||void 0===s?void 0:s.isBabelIgnore)||!1})],(function(e,t){return void 0===t?e:t}),i)}async generate(e,t,i,o={}){var s;const r=await this.pluginDriver.hookFirst("generate",[e,t.path,t.sourcePath,Object.assign(Object.assign({},o),{independentRoot:t.independentRoot,isBabelIgnore:(null===(s=t.jsTag)||void 0===s?void 0:s.isBabelIgnore)||!1})]);return void 0===r||(0,lodash_1.isNull)(r)?Object.assign(Object.assign({},e),{target:{code:e.source.sourceCode,map:e.source.inputMap}}):r}async optimize(e,t={}){return await this.pluginDriver.hookReduceArg0("optimize",[e,t],(e,t)=>t,e=>e)}async compress(e,t={}){return await this.pluginDriver.hookReduceArg0("compress",[e,t],(e,t)=>t,e=>e)}async compile(e,t){const{jsons:i}=await t.run(locales_1.default.config.SUMMER_COMPILE_JSON.format(),()=>this.compileJSON(e,t)),o=await this.compileCodeWithoutJSON(e,t),s=await t.run(locales_1.default.config.SUMMER_PACK_FILES.format(),()=>this.compileOther(Object.keys(i),t)),r=Object.assign(Object.assign(Object.assign({},s),o),i);return await t.run(locales_1.default.config.SUMMER_SEAL_PACK.format(),()=>this.pluginDriver.hookParallel("sealed",[r])),r}async compileWithFileList(e,t){const i=e.fileList,{jsons:o}=await t.run(locales_1.default.config.SUMMER_COMPILE_JSON.format(),()=>this.compileJSONWithFileList(Object.assign(Object.assign({},e),{fileList:i.filter(e=>e.endsWith(".json"))}),t)),s=i.filter(e=>!e.endsWith(".json")),r=await this.compileCodeWithoutJSONWithFileList(Object.assign(Object.assign({},e),{fileList:s}),t),a=Object.assign(Object.assign({},r),o);return await t.run(locales_1.default.config.SUMMER_SEAL_PACK.format(),()=>this.pluginDriver.hookParallel("sealed",[a])),a}async getLocalFileList(){const e=this.getLocalCodeFileList(),t=new Set(this.resolver.allExts.map(e=>"."+e)),i=await this.getWhiteListConfig(),o=this.project.getFileList(this.root,"").filter(e=>{const o=path_1.default.posix.extname(e);return i.has(o)&&!t.has(o)}).map(e=>e.replace(new RegExp("^"+this.root),"")),s={};for(const t of e.concat(o)){const e=this.project.stat(this.root,t);s[t]=e}return s}async compileOther(e,t=progressRecorder_1.silentRecorder){const i=new Set(this.resolver.allExts.map(e=>"."+e));i.delete(".json");const o=await this.getWhiteListConfig(),s=this.project.getFileList(this.root,"").filter(s=>{const r=path_1.default.posix.extname(s),a=path_1.default.posix.relative(this.root,s);if(!o.has(r)||i.has(r)||e.includes(a))return!1;return!packOptionsHelper_1.default.isIgnoredByRules(s)||(t.message("warn",s+" is ignored by project.config.json packOptions.ignore setting"),!1)}),r=await(0,common_1.compileOther)(this.project,s,{onProgressUpdate:()=>{}}),a={};for(const e in r){a[path_1.default.posix.relative(this.root,e)]=r[e]}return a}async compileCodeWithoutJSON(e,t){var i;const o={},s=await this.getProdCode(t,Object.assign(Object.assign({},e),{package:config_1.FullPkg})),r=new Set;for(const e in s){const t=s[e];if("error"in t)throw t.error;if(t.path.endsWith(".js")){((null===(i=t.jsTag)||void 0===i?void 0:i.helpers)||[]).forEach(e=>{r.add(e)}),o[e]=t.code;const s=t.map&&(0,tools_1.formatSourceMap)(t.map);s&&(o[e+".map"]=s)}else o[e]=t.code}return await t.run(locales_1.default.config.SUMMER_APPEND_BABEL_HELPERS.format((0,pluginconfig_1.couldUseSWCMode)(this.project.setting)?"swc":"babel"),()=>(0,helper_util_1.appendHelpers)(this.project,r,"",o)),o}async compileCodeWithoutJSONWithFileList(e,t){var i;const o={},s=await this.getProdCodeByFileList(t,e),r=new Set;for(const e in s){const t=s[e];if("error"in t)throw t.error;if(t.path.endsWith(".js")){((null===(i=t.jsTag)||void 0===i?void 0:i.helpers)||[]).forEach(e=>{r.add(e)}),o[e]=t.code;const s=t.map&&(0,tools_1.formatSourceMap)(t.map);s&&(o[e+".map"]=s)}else o[e]=t.code}return await t.run(locales_1.default.config.SUMMER_APPEND_BABEL_HELPERS.format((0,pluginconfig_1.couldUseSWCMode)(this.project.setting)?"swc":"babel"),()=>(0,helper_util_1.appendHelpers)(this.project,r,"",o)),o}isBabelSettingIgnore(e){var t,i;let o=!1;if(e.path.endsWith(".js")){const s=(0,pluginconfig_1.couldUseSWCMode)(this.project.setting)?null===(t=this.compiler.getSWCSetting())||void 0===t?void 0:t.ignore:null===(i=this.compiler.getBabelSetting())||void 0===i?void 0:i.ignore;s&&(o=(0,babel_helper_1.isIgnore)(s,e.source))}return o}async getDevCodeByFileList(e,t){let i=await this.getPackageFile(config_1.FullPkg);return i=i.filter(e=>t.fileList.includes(e.path)),this.getCodeFiles(i,e)}async getProdCodeByFileList(e,t){let i=await this.getPackageFile(config_1.FullPkg);return i=i.filter(e=>t.fileList.includes(e.path)),this.getCodeFiles(i,e,{useCache:!1,resultType:"prod"})}}exports.BaseGraph=BaseGraph;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseGraph=exports.JSONType=exports.FileType=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=require("lodash"),pluginDriver_1=require("../pluginDriver"),module_1=tslib_1.__importDefault(require("../module")),config_1=require("../../../../config/config"),resolver_1=require("../resolver"),common_1=require("../../original/compile/common"),packOptionsHelper_1=tslib_1.__importDefault(require("../../../../utils/packOptionsHelper")),tools_1=require("../../../../utils/tools"),babel_helper_1=require("../../../../utils/babel_helper"),helper_util_1=require("../../../../utils/helper_util"),progressRecorder_1=require("../../../../utils/progressRecorder"),locales_1=tslib_1.__importDefault(require("../../../../utils/locales/locales")),customError_1=require("../../../../utils/customError"),taskmanager_1=tslib_1.__importDefault(require("../../../../utils/taskmanager")),pluginconfig_1=require("../pluginconfig");var FileType,JSONType;function getFileType(e){let t=path_1.default.extname(e);if(t.startsWith(".")){if(t=t.slice(1),t===FileType.JS)return FileType.JS;if(t===FileType.WXML)return FileType.WXML;if(t===FileType.WXSS)return FileType.WXSS;if(t===FileType.WXS)return FileType.WXS;if(t===FileType.JSON)return FileType.JSON}throw Error("unknown the filetype of "+e)}!function(e){e.JSON="json",e.WXML="wxml",e.WXSS="wxss",e.WXS="wxs",e.JS="js"}(FileType=exports.FileType||(exports.FileType={})),function(e){e.APP="app",e.Page="page",e.EXT="ext",e.SITEMAP="sitemap",e.THEME="theme"}(JSONType=exports.JSONType||(exports.JSONType={}));class BaseGraph{constructor(e){var t;this.invalidated=!0,this.running=!1,this.onFileChange=(e,t)=>{t.startsWith(this.root)&&(t=t.replace(new RegExp("^"+this.root),""),this.resolver.onFileChange(e,t),"change"!==e&&"unlink"!==e||this.invalidateModules(t),this.onFileChangeForGraph(e,t))},this.getCodeFileTask=async(e,t,i={useCache:!0,resultType:"dev"})=>{const o=this.loadModuleFromFile(e,t,i),s=await o.toCodeFile(i.resultType||"dev");if(!("error"in s)&&"dev"!==i.resultType){const e=await o.toGenerateResult(i.resultType||"dev");if(!("error"in e)){const t=await this.optimize(e,i),o=await this.compress(t,i);s.code=o.target.code,s.map=o.target.map}}return{file:e,codeFile:s,process:await o.getProcessInfo(i.resultType||"dev")||[]}},this.type=e.type,this.root=e.root,this.rootPath=(0,tools_1.joinPath)(e.compiler.project.projectPath,this.root),this.persistCache=e.persistCache,this.compiler=e.compiler,this.project=this.compiler.project,this.cachedModules=new Map,this.pluginDriver=new pluginDriver_1.PluginDriver(this,e),this.modulesByPath=new Map,this.resolver=new resolver_1.Resolver(this,this.root,this.pluginDriver.resolveExtConf),this.compiler.proxyProject.addResolver(this.resolver),null===(t=this.project.event)||void 0===t||t.on("fileChange",this.onFileChange)}destroy(){var e;this.compiler.proxyProject.removeResolver(this.resolver),null===(e=this.project.event)||void 0===e||e.off("fileChange",this.onFileChange)}clearCache(){this.modulesByPath.clear()}async ensureConf(e){this.conf||await this.getConf(e)}async getPackageFile(e){await this.ensureConf(progressRecorder_1.silentRecorder);const t=[];for(const[i,o]of this.resolver.resolveInfoMap.entries())e!==config_1.FullPkg&&this.checkFilePackage(i)!==e||t.push(o);return t.map(e=>Object.assign(Object.assign({},e),{independentRoot:this.getIndependentRoot(e.path),isBabelIgnore:this.isBabelSettingIgnore(e)}))}invalidateModules(e){for(const t of this.modulesByPath.values())(t.sourcePath===e||t.depFiles.includes(e))&&this.modulesByPath.delete(t.path)}loadModuleFromFile(e,t,i){let o=this.modulesByPath.get(e.path),s=!o||o.sourcePath!==e.source||o.independentRoot!==e.independentRoot;if(!s&&(null==o?void 0:o.getError(i.resultType))){if(o.getGeneratedTS(i.resultType)+1e3>Date.now())return o;s=!0}if(s){const t=getFileType(e.path);o=new module_1.default(this,e.path,e.source,t),o.independentRoot=e.independentRoot,e.isBabelIgnore&&(o.isBabelIgnore=!0),this.modulesByPath.set(e.path,o)}let r=o.getLoadingPromise();void 0===r&&(r=t.run(locales_1.default.config.SUMMER_COMPILING_MODULE.format(e.source),()=>this.loadSourceForModule(o,i)),o.setLoadingPromise(r));let a=o.getGeneratingPromise(i.resultType);return void 0===a&&(a=t.run(locales_1.default.config.SUMMER_COMPILING_MODULE.format(e.source),async()=>{const e=await o.getLoadingPromise();return this.generate(e,o,i)}),o.setGeneratingPromise(i.resultType,a)),o}async loadSourceForModule(e,t){try{const i=(0,tools_1.joinPath)(this.rootPath,e.sourcePath),o=t=>Object.assign(Object.assign({},t),{rootPath:this.rootPath,addWatchFile:t=>{const i=(0,tools_1.normalizePath)(t);if(!i.startsWith(this.rootPath))throw(0,customError_1.makeCustomError)(`The file (${t}) required by ${e.sourcePath} is outside the project`,customError_1.CustomErrors.SUMMER_PLUGIN_CODE_ERR,e.path);e.addWatchFile(path_1.default.posix.relative(this.rootPath,i))}});let s=await this.pluginDriver.hookFirst("load",[e.path,i,Object.assign(Object.assign({},t),{independentRoot:e.independentRoot,isBabelIgnore:e.isBabelIgnore||!1})],o);if(!s){const t=Date.now(),o=await this.readFile(i);s={targetPath:e.path,source:{sourceCode:o},process:[{cost:Date.now()-t,pluginName:"readFile",action:"load"}]}}return await this.tranform(s,e,o,t)}catch(i){throw i.path=(0,tools_1.joinPath)(this.root,e.sourcePath),e.setError(t.resultType,i),i}}async doCompileSingleCode(e,t){const i=this.loadModuleFromFile(e,progressRecorder_1.silentRecorder,{resultType:"dev"}),o=i.getError("dev");if(o)throw o;return await i.toCodeFile("dev")}async getCodeFiles(e,t,i={useCache:!0,resultType:"dev"}){var o;const s=Date.now(),r={},a=new taskmanager_1.default({poolLimit:10,breakWhenError:!0});for(const o of e)a.addTask(this.getCodeFileTask,o,t,i);const n=await a.runAllAsync();for(const e of n)r[e.file.path]=e.codeFile,(null===(o=e.codeFile.jsTag)||void 0===o?void 0:o.isLargeFile)&&t.message("warn",locales_1.default.config.LARGEFILE_WARNING.format(e.file.path,config_1.MAX_CODE_LENGTH/1024));return console.info("!!!",`getCodeFiles: count: ${e.length}, cost: ${Date.now()-s}ms.`),r}async readFile(e){const t=path_1.default.relative(this.project.projectPath,e);return this.project.getFile("",t).toString()}async tranform(e,t,i,o){return await this.pluginDriver.hookReduceArg0("transform",[e,t.path,t.sourcePath,Object.assign(Object.assign({},o),{independentRoot:t.independentRoot,isBabelIgnore:t.isBabelIgnore||!1})],(function(e,t){return void 0===t?e:t}),i)}async generate(e,t,i){const o=await this.pluginDriver.hookFirst("generate",[e,t.path,t.sourcePath,Object.assign(Object.assign({},i),{independentRoot:t.independentRoot,isBabelIgnore:t.isBabelIgnore||!1})]);return void 0===o||(0,lodash_1.isNull)(o)?Object.assign(Object.assign({},e),{target:{code:e.source.sourceCode,map:e.source.inputMap}}):o}async optimize(e,t){return await this.pluginDriver.hookReduceArg0("optimize",[e,t],(e,t)=>t,e=>e)}async compress(e,t){return await this.pluginDriver.hookReduceArg0("compress",[e,t],(e,t)=>t,e=>e)}async compile(e,t){const{jsons:i}=await t.run(locales_1.default.config.SUMMER_COMPILE_JSON.format(),()=>this.compileJSON(e,t)),o=await this.compileCodeWithoutJSON(e,t),s=await t.run(locales_1.default.config.SUMMER_PACK_FILES.format(),()=>this.compileOther(Object.keys(i),t)),r=Object.assign(Object.assign(Object.assign({},s),o),i);return await t.run(locales_1.default.config.SUMMER_SEAL_PACK.format(),()=>this.pluginDriver.hookParallel("sealed",[r])),r}async compileWithFileList(e,t){const i=e.fileList,{jsons:o}=await t.run(locales_1.default.config.SUMMER_COMPILE_JSON.format(),()=>this.compileJSONWithFileList(Object.assign(Object.assign({},e),{fileList:i.filter(e=>e.endsWith(".json"))}),t)),s=i.filter(e=>!e.endsWith(".json")),r=await this.compileCodeWithoutJSONWithFileList(Object.assign(Object.assign({},e),{fileList:s}),t),a=Object.assign(Object.assign({},r),o);return await t.run(locales_1.default.config.SUMMER_SEAL_PACK.format(),()=>this.pluginDriver.hookParallel("sealed",[a])),a}async getLocalFileList(){const e=this.getLocalCodeFileList(),t=new Set(this.resolver.allExts.map(e=>"."+e)),i=await this.getWhiteListConfig(),o=this.project.getFileList(this.root,"").filter(e=>{const o=path_1.default.posix.extname(e);return i.has(o)&&!t.has(o)}).map(e=>e.replace(new RegExp("^"+this.root),"")),s={};for(const t of e.concat(o)){const e=this.project.stat(this.root,t);s[t]=e}return s}async compileOther(e,t=progressRecorder_1.silentRecorder){const i=new Set(this.resolver.allExts.map(e=>"."+e));i.delete(".json");const o=await this.getWhiteListConfig(),s=this.project.getFileList(this.root,"").filter(s=>{const r=path_1.default.posix.extname(s),a=path_1.default.posix.relative(this.root,s);if(!o.has(r)||i.has(r)||e.includes(a))return!1;return!packOptionsHelper_1.default.isIgnoredByRules(s)||(t.message("warn",s+" is ignored by project.config.json packOptions.ignore setting"),!1)}),r=await(0,common_1.compileOther)(this.project,s,{onProgressUpdate:()=>{}}),a={};for(const e in r){a[path_1.default.posix.relative(this.root,e)]=r[e]}return a}async compileCodeWithoutJSON(e,t){var i;const o={},s=await this.getProdCode(t,Object.assign(Object.assign({},e),{package:config_1.FullPkg})),r=new Set;for(const e in s){const t=s[e];if("error"in t)throw t.error;if(t.path.endsWith(".js")){((null===(i=t.jsTag)||void 0===i?void 0:i.helpers)||[]).forEach(e=>{r.add(e)}),o[e]=t.code;const s=t.map&&(0,tools_1.formatSourceMap)(t.map);s&&(o[e+".map"]=s)}else o[e]=t.code}return await t.run(locales_1.default.config.SUMMER_APPEND_BABEL_HELPERS.format((0,pluginconfig_1.couldUseSWCMode)(this.project.setting)?"swc":"babel"),()=>(0,helper_util_1.appendHelpers)(this.project,r,"",o)),o}async compileCodeWithoutJSONWithFileList(e,t){var i;const o={},s=await this.getProdCodeByFileList(t,e),r=new Set;for(const e in s){const t=s[e];if("error"in t)throw t.error;if(t.path.endsWith(".js")){((null===(i=t.jsTag)||void 0===i?void 0:i.helpers)||[]).forEach(e=>{r.add(e)}),o[e]=t.code;const s=t.map&&(0,tools_1.formatSourceMap)(t.map);s&&(o[e+".map"]=s)}else o[e]=t.code}return await t.run(locales_1.default.config.SUMMER_APPEND_BABEL_HELPERS.format((0,pluginconfig_1.couldUseSWCMode)(this.project.setting)?"swc":"babel"),()=>(0,helper_util_1.appendHelpers)(this.project,r,"",o)),o}isBabelSettingIgnore(e){var t,i;let o=!1;if(e.path.endsWith(".js")){const s=(0,pluginconfig_1.couldUseSWCMode)(this.project.setting)?null===(t=this.compiler.getSWCSetting())||void 0===t?void 0:t.ignore:null===(i=this.compiler.getBabelSetting())||void 0===i?void 0:i.ignore;s&&(o=(0,babel_helper_1.isIgnore)(s,e.source))}return o}async getDevCodeByFileList(e,t){let i=await this.getPackageFile(config_1.FullPkg);return i=i.filter(e=>t.fileList.includes(e.path)),this.getCodeFiles(i,e)}async getProdCodeByFileList(e,t){let i=await this.getPackageFile(config_1.FullPkg);return i=i.filter(e=>t.fileList.includes(e.path)),this.getCodeFiles(i,e,{useCache:!1,resultType:t.resultType||"prod"})}}exports.BaseGraph=BaseGraph;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tools_1=require("../../../utils/tools"),customError_1=require("../../../utils/customError"),basegraph_1=require("./graph/basegraph");class JsTag{constructor(){this.isLargeFile=!1,this.isBabelIgnore=!1,this.helpers=[],this.resultType="dev"}setBabelIgnore(){this.isBabelIgnore=!0}setLargeFile(){this.isLargeFile=!0}addHelpers(e){for(const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tools_1=require("../../../utils/tools"),customError_1=require("../../../utils/customError"),basegraph_1=require("./graph/basegraph");class JsTag{constructor(){this.isLargeFile=!1,this.isBabelIgnore=!1,this.helpers=[],this.resultType="dev"}setBabelIgnore(){this.isBabelIgnore=!0}setLargeFile(){this.isLargeFile=!0}addHelpers(e){for(const t of e)this.helpers.includes(t)||this.helpers.push(t)}setResultType(e="dev"){this.resultType=e}toJSON(){return{isLargeFile:this.isLargeFile,isBabelIgnore:this.isBabelIgnore,helpers:this.helpers}}}class Module{constructor(e,t,s,r){this.graph=e,this.path=t,this.sourcePath=s,this.fileType=r,this._error={},this.generateResultPromise={},this.depFiles=[],this.independentRoot="",this.isBabelIgnore=!1,this.generatedTS={}}transResultType(e){return this.fileType===basegraph_1.FileType.JS||this.fileType===basegraph_1.FileType.WXML?e:"common"}getGeneratedTS(e){return this.generatedTS[this.transResultType(e)]||0}setError(e,t){const s=this.transResultType(e);this._error[s]=t,this.generatedTS[s]=Date.now()}getError(e){const t=this.transResultType(e);return this._error[t]}async getJsTag(){if(this.fileType!==basegraph_1.FileType.JS)return;if(this._jsTag)return this._jsTag;const e=new JsTag;(await this.getSource()).largeFile&&e.setLargeFile();const t=await this.generateResultPromise.common;return t.target&&(e.addHelpers(t.target.helpers||[]),e.setResultType(t.target.resultType)),this.isBabelIgnore&&e.setBabelIgnore(),this._jsTag=e,e}async getSource(){return(await this.getLoadingPromise()).source}async getMd5(){const e=await this.getSource();return(0,tools_1.generateMD5)(e.sourceCode)}setLoadingPromise(e){this.loadResult=e}getLoadingPromise(){return this.loadResult}setGeneratingPromise(e,t){const s=this.transResultType(e);this.generateResultPromise[s]=t,this.generateResultPromise.common=t,t.then(()=>{this.generatedTS[s]=Date.now()})}getGeneratingPromise(e){const t=this.transResultType(e);return this.generateResultPromise[t]}async getProcessInfo(e){var t;const s=this.getGeneratingPromise(e);return null===(t=await s)||void 0===t?void 0:t.process}async toCodeFile(e){const t=this.getError(e);if(t)return t instanceof customError_1.CustomError?{path:this.path,error:t.toJSON()}:{path:this.path,error:this._error};const s=this.getGeneratingPromise(e);if(void 0===s)return{path:this.path,error:"empty result"};const r=await this.getJsTag();try{return Object.assign({path:this.path,md5:await this.getMd5(),jsTag:null==r?void 0:r.toJSON()},(await s).target)}catch(e){return{path:this.path,error:e}}}async toGenerateResult(e){const t=this.getGeneratingPromise(e);if(void 0===t)return{path:this.path,error:"empty result"};const s=await t;return{targetPath:this.path,source:await this.getSource(),target:s.target,process:s.process||[]}}toJSON(){return{code:"",map:void 0,path:this.path,sourcePath:this.sourcePath,depFileIds:this.depFiles}}addWatchFile(e){-1===this.depFiles.indexOf(e)&&this.depFiles.push(e)}}exports.default=Module;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.transformES6ModuleAndGenCode=exports.getBabelRoot=void 0;const config_1=require("../../../../../config/config"),babel_helper_1=require("../../../../../utils/babel_helper"),tools_1=require("../../../../../utils/tools"),pluginTransformModulesCommonjs=()=>require("@babel/plugin-transform-modules-commonjs"),babel7=()=>require("@babel/core");function getES6ModulePluginsList(e){return[[require("@babel/plugin-transform-modules-commonjs"),{allowTopLevelThis:e,importInterop:e=>e.startsWith("@babel/runtime/helpers/")?"node":"babel"}]]}function getBabelRoot(e){return""===e?"@babel/runtime":(0,tools_1.normalizePath)(e+"/@babel/runtime")}function transformES6ModuleAndGenCode(e,o,t){const r=t.disableUseStrict||/^\s*\/\/\s?use strict disable;/i.test(o.sourceCode||"");let s;try{const t={babelrc:!1,plugins:getES6ModulePluginsList(r),filename:e,sourceFileName:e,sourceMaps:!0,inputSourceMap:o.inputMap,configFile:!1,code:!0,cloneInputAst:!0},n=require("@babel/core");if(!o.astInfo)throw new Error("source.astInfo is not exist");if(o.astInfo.type!==config_1.AstType.Babel)throw new Error("ast type is not babel");s=n.transformFromAstSync(o.astInfo.ast,o.sourceCode,t)}catch(o){throw o.code=config_1.BABEL_TRANS_JS_ERR,o.message=`file: ${e}\n ${o.message}`,o.path=e,o}if(!s)throw new Error("no trans result for callPostEnhance");let n=s.code;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.transformES6ModuleAndGenCode=exports.getBabelRoot=void 0;const config_1=require("../../../../../config/config"),babel_helper_1=require("../../../../../utils/babel_helper"),tools_1=require("../../../../../utils/tools"),pluginTransformModulesCommonjs=()=>require("@babel/plugin-transform-modules-commonjs"),babel7=()=>require("@babel/core");function getES6ModulePluginsList(e){return[[require("@babel/plugin-transform-modules-commonjs"),{allowTopLevelThis:e,importInterop:e=>e.startsWith("@babel/runtime/helpers/")?"node":"babel"}]]}function getBabelRoot(e){return""===e?"@babel/runtime":(0,tools_1.normalizePath)(e+"/@babel/runtime")}function transformES6ModuleAndGenCode(e,o,t){const r=t.disableUseStrict||/^\s*\/\/\s?use strict disable;/i.test(o.sourceCode||"");let s;try{const t={babelrc:!1,plugins:getES6ModulePluginsList(r),filename:e,sourceFileName:e,sourceMaps:!0,inputSourceMap:o.inputMap,configFile:!1,code:!0,cloneInputAst:!0},n=require("@babel/core");if(!o.astInfo)throw new Error("source.astInfo is not exist");if(o.astInfo.type!==config_1.AstType.Babel)throw new Error("ast type is not babel");s=n.transformFromAstSync(o.astInfo.ast,o.sourceCode,t)}catch(o){throw o.code=config_1.BABEL_TRANS_JS_ERR,o.message=`file: ${e}\n ${o.message}`,o.path=e,o}if(!s)throw new Error("no trans result for callPostEnhance");let n=s.code;const a=s.map;r&&(n=n.replace(/^"use strict";/,""));const l=(0,babel_helper_1.collectBabelHelpers)(o.sourceCode),i=(0,babel_helper_1.replaceBabelHelpers)(n,l,e,t.babelRoot);return{code:i.transformCode,map:a,helpers:i.helpers}}function default_1(e,o){return{name:"summer-es6module",workerMethods:{async doGenerate(e,o,t){const r=await transformES6ModuleAndGenCode(e,o,t);return Object.assign(Object.assign({},r),{resultType:t.resultType})}},async generate(e,t,r,{independentRoot:s,isBabelIgnore:n,resultType:a}){const l=Date.now(),{source:i}=e;if(t.endsWith(".js")&&!i.largeFile&&!n){if(!i.astInfo){if(null===i.sourceCode)throw new Error("source.sourceCode is null");return Object.assign(Object.assign({},e),{target:{code:i.sourceCode,map:i.inputMap,helpers:[],resultType:a||"prod"},process:[...e.process,{cost:Date.now()-l,pluginName:"summer-es6module",action:"generate"}]})}const t={babelRoot:getBabelRoot(s),disableUseStrict:o.disableUseStrict,resultType:a},n=await this.runWorkerMethod("doGenerate",r,i,t);return Object.assign(Object.assign({},e),{target:n,process:[...e.process,{cost:Date.now()-l,pluginName:"summer-es6module",action:"generate",options:t}]})}}}}exports.getBabelRoot=getBabelRoot,exports.transformES6ModuleAndGenCode=transformES6ModuleAndGenCode,exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MAX_CODE_LENGTH=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),config_1=require("../../../../../config/config"),inputsourcemap_1=require("../../utils/inputsourcemap");var config_2=require("../../../../../config/config");function default_1(e){return{name:"summer-javascript",async load(t,r){if(r.endsWith(".js")){const i=path_1.default.relative(e.projectPath,r),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MAX_CODE_LENGTH=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),config_1=require("../../../../../config/config"),inputsourcemap_1=require("../../utils/inputsourcemap");var config_2=require("../../../../../config/config");function default_1(e){return{name:"summer-javascript",async load(t,r){if(r.endsWith(".js")){const i=Date.now(),o=path_1.default.relative(e.projectPath,r),a=e.getFile("",o).toString(),n=await(0,inputsourcemap_1.tryGetInputSourceMap)(a,r);return{targetPath:t,source:{sourceCode:a,inputMap:null!=n?n:void 0,astInfo:void 0,largeFile:a.length>=config_1.MAX_CODE_LENGTH},process:[{cost:Date.now()-i,pluginName:"summer-javascript",action:"load"}]}}}}}Object.defineProperty(exports,"MAX_CODE_LENGTH",{enumerable:!0,get:function(){return config_2.MAX_CODE_LENGTH}}),exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getSWCRoot=exports.MAX_CODE_LENGTH=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),config_1=require("../../../../../config/config"),tools_1=require("../../../../../utils/tools"),swc_helper_1=require("../../../../../utils/swc_helper"),inputsourcemap_1=require("../../utils/inputsourcemap"),swc=()=>require("@swc/core");var config_2=require("../../../../../config/config");function getSWCRoot(e,t){const r=(0,swc_helper_1.getSWCOutputPath)(e.setting);return""===t?r:(0,tools_1.normalizePath)(`${t}/${r}`)}function default_1(e,t){return{name:"summer-swc",workerMethods:{async doGenerate(e,t,r,s){var o,i;const n=s.disableUseStrict||/^\s*\/\/\s?use strict disable;/i.test(e.sourceCode||""),a=require("@swc/core").transformSync(e.sourceCode,{jsc:{parser:Object.assign(Object.assign({},null===(o=s.rc)||void 0===o?void 0:o.parser),{syntax:t.endsWith("ts")?"typescript":"ecmascript"}),target:s.target,externalHelpers:!0,loose:!1,minify:{compress:{drop_console:!1,drop_debugger:!1},toplevel:!0}},module:Object.assign({type:"commonjs",strictMode:!n,noInterop:!0,allowTopLevelThis:n},null===(i=s.rc)||void 0===i?void 0:i.module),inputSourceMap:e.inputMap?JSON.stringify(e.inputMap):void 0,sourceMaps:!0,filename:t,minify:s.minify}),c=(0,swc_helper_1.replaceSWCHelpers)(a.code,t,r);return{code:c.transformCode,map:a.map?JSON.parse(a.map):void 0,helpers:c.helpers,resultType:s.resultType}}},async load(t,r){if(!t.endsWith(".js"))return;const s=path_1.default.relative(e.projectPath,r),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getSWCRoot=exports.MAX_CODE_LENGTH=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),config_1=require("../../../../../config/config"),tools_1=require("../../../../../utils/tools"),swc_helper_1=require("../../../../../utils/swc_helper"),inputsourcemap_1=require("../../utils/inputsourcemap"),swc=()=>require("@swc/core");var config_2=require("../../../../../config/config");function getSWCRoot(e,t){const r=(0,swc_helper_1.getSWCOutputPath)(e.setting);return""===t?r:(0,tools_1.normalizePath)(`${t}/${r}`)}function default_1(e,t){return{name:"summer-swc",workerMethods:{async doGenerate(e,t,r,s){var o,i;const n=s.disableUseStrict||/^\s*\/\/\s?use strict disable;/i.test(e.sourceCode||""),a=require("@swc/core").transformSync(e.sourceCode,{jsc:{parser:Object.assign(Object.assign({},null===(o=s.rc)||void 0===o?void 0:o.parser),{syntax:t.endsWith("ts")?"typescript":"ecmascript"}),target:s.target,externalHelpers:!0,loose:!1,minify:{compress:{drop_console:!1,drop_debugger:!1},toplevel:!0}},module:Object.assign({type:"commonjs",strictMode:!n,noInterop:!0,allowTopLevelThis:n},null===(i=s.rc)||void 0===i?void 0:i.module),inputSourceMap:e.inputMap?JSON.stringify(e.inputMap):void 0,sourceMaps:!0,filename:t,minify:"dev"!==s.resultType&&s.minify}),c=(0,swc_helper_1.replaceSWCHelpers)(a.code,t,r);return{code:c.transformCode,map:a.map?JSON.parse(a.map):void 0,helpers:c.helpers,resultType:s.resultType}}},async load(t,r){if(!t.endsWith(".js"))return;const s=Date.now(),o=path_1.default.relative(e.projectPath,r),i=e.getFile("",o).toString(),n=await(0,inputsourcemap_1.tryGetInputSourceMap)(i,r);return{targetPath:t,source:{sourceCode:i,inputMap:null!=n?n:void 0,astInfo:void 0,largeFile:i.length>=config_1.MAX_CODE_LENGTH},process:[{cost:Date.now()-s,pluginName:"summer-swc",action:"load"}]}},async generate(r,s,o,{independentRoot:i,isBabelIgnore:n,resultType:a}){var c;if(!s.endsWith(".js")||n)return;const u=Date.now(),p=getSWCRoot(e,i),l={disableUseStrict:t.disableUseStrict,target:e.setting.enhance||e.setting.es6?"es5":"es2022",rc:null===(c=e.setting.swcSetting)||void 0===c?void 0:c.rc,minify:e.setting.minified,resultType:a},d=await this.runWorkerMethod("doGenerate",r.source,o,p,l);return Object.assign(Object.assign({},r),{target:d,process:[...r.process,{cost:Date.now()-u,pluginName:"summer-swc",action:"transform",options:l}]})}}}Object.defineProperty(exports,"MAX_CODE_LENGTH",{enumerable:!0,get:function(){return config_2.MAX_CODE_LENGTH}}),exports.getSWCRoot=getSWCRoot,exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),postcss_1=tslib_1.__importDefault(require("postcss")),autoprefixer_1=tslib_1.__importDefault(require("autoprefixer")),cssnano_1=tslib_1.__importDefault(require("cssnano")),tools_1=require("../../../../../utils/tools"),config_1=require("../../../../../config/config"),customError_1=require("../../../../../utils/customError");process.env.BROWSERSLIST=process.env.BROWSERSLIST||"iOS >= 8, Chrome >= 37";const MAX_LINE_SHOW_LENGTH=45;function shortString(r,e,t=-1){const s=r.length;if(s<=e)return{result:r,marker:t};const o=Math.floor(e/2);return-1===t||t<=o?{result:r.substr(0,e-3)+"...",marker:t}:t+o>=s?{result:"..."+r.substr(s-e+3,e-3),marker:Math.min(e,e-(s-t))}:{result:`...${r.substr(t-o+3,e-6)}...`,marker:o}}function formatPostcssError(r,e){try{const t=e.line-1,s=e.column-1,o=r.replace(/\r\n/g,"\n").split("\n"),n=[],i=Math.max(0,t-1),u=Math.min(t+2,o.length);for(let r=i;r<u;r++){const e=shortString(o[r],45,s);r===t?n.push(`> ${r+1} | ${e.result.substr(0,e.marker)}${e.result.substr(e.marker)}`):n.push(`> ${r+1} | ${e.result}`)}return`${e.message}\n${n.join("\n")}`}catch(r){}return e.message}function default_1(r,e){const{autoPrefix:t=!0,minify:s=!0}=e||{},o=["iOS >= 8","Chrome >= 37"];return{name:"summer-wxss",workerMethods:{async doOptimize(r,e){try{const n=[];t&&n.push((0,autoprefixer_1.default)({overrideBrowserslist:o,remove:!1})),s&&n.push((0,cssnano_1.default)({preset:["default",{reduceTransforms:!1,calc:!1,minifySelectors:!1,normalizeUrl:!1}]}));return{error:null,content:(await(0,postcss_1.default)(n).process(e,{from:(0,tools_1.leading)(r,"/")})).css.replace(/\r\n/g,"\n")}}catch(t){return{error:(0,customError_1.makeCustomError)(formatPostcssError(e,t),config_1.POST_WXSS_ERR,r)}}}},async optimize(r,e){if("prod"!==e.resultType||!r.targetPath.endsWith(".wxss")||!t&&!s)return r;const o=await this.runWorkerMethod("doOptimize",r.targetPath,r.target.code);if(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),postcss_1=tslib_1.__importDefault(require("postcss")),autoprefixer_1=tslib_1.__importDefault(require("autoprefixer")),cssnano_1=tslib_1.__importDefault(require("cssnano")),tools_1=require("../../../../../utils/tools"),config_1=require("../../../../../config/config"),customError_1=require("../../../../../utils/customError");process.env.BROWSERSLIST=process.env.BROWSERSLIST||"iOS >= 8, Chrome >= 37";const MAX_LINE_SHOW_LENGTH=45;function shortString(r,e,t=-1){const s=r.length;if(s<=e)return{result:r,marker:t};const o=Math.floor(e/2);return-1===t||t<=o?{result:r.substr(0,e-3)+"...",marker:t}:t+o>=s?{result:"..."+r.substr(s-e+3,e-3),marker:Math.min(e,e-(s-t))}:{result:`...${r.substr(t-o+3,e-6)}...`,marker:o}}function formatPostcssError(r,e){try{const t=e.line-1,s=e.column-1,o=r.replace(/\r\n/g,"\n").split("\n"),n=[],i=Math.max(0,t-1),u=Math.min(t+2,o.length);for(let r=i;r<u;r++){const e=shortString(o[r],45,s);r===t?n.push(`> ${r+1} | ${e.result.substr(0,e.marker)}${e.result.substr(e.marker)}`):n.push(`> ${r+1} | ${e.result}`)}return`${e.message}\n${n.join("\n")}`}catch(r){}return e.message}function default_1(r,e){const{autoPrefix:t=!0,minify:s=!0}=e||{},o=["iOS >= 8","Chrome >= 37"];return{name:"summer-wxss",workerMethods:{async doOptimize(r,e){try{const n=[];t&&n.push((0,autoprefixer_1.default)({overrideBrowserslist:o,remove:!1})),s&&n.push((0,cssnano_1.default)({preset:["default",{reduceTransforms:!1,calc:!1,minifySelectors:!1,normalizeUrl:!1}]}));return{error:null,content:(await(0,postcss_1.default)(n).process(e,{from:(0,tools_1.leading)(r,"/")})).css.replace(/\r\n/g,"\n")}}catch(t){return{error:(0,customError_1.makeCustomError)(formatPostcssError(e,t),config_1.POST_WXSS_ERR,r)}}}},async optimize(r,e){if("prod"!==e.resultType||!r.targetPath.endsWith(".wxss")||!t&&!s)return r;const o=Date.now(),n=await this.runWorkerMethod("doOptimize",r.targetPath,r.target.code);if(n.error)throw n.error;return Object.assign(Object.assign({},r),{target:Object.assign(Object.assign({},r.target),{code:n.content}),process:[...r.process,{cost:Date.now()-o,pluginName:"summer-wxss",action:"optimize"}]})}}}exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const config_1=require("../../../../config/config"),babel_helper_1=require("../../../../utils/babel_helper"),es6module_1=require("./base/es6module"),_transformRuntimeCustom=()=>require("../../../../utils/babel_transform_plugin"),_pluginTransformRuntime=()=>require("@babel/plugin-transform-runtime"),_pluginTransformWorklet=()=>require("../../../../utils/babel_plugin_worklet"),babel7=()=>require("@babel/core"),_presetEnv=()=>require("@babel/preset-env");function getEnhancePluginsList(e){const r=[[require("../../../../utils/babel_transform_plugin")],[require("@babel/plugin-transform-runtime"),{corejs:!1,helpers:!0,regenerator:!0,version:"7.21.0"}]].concat((0,babel_helper_1.getCustomPlugins)([]));return e.supportWorklet&&r.push([require("../../../../utils/babel_plugin_worklet")]),r}const enhance=(e,r)=>{const t=babel7(),s=e.sourceCode.includes('"worklet"')||e.sourceCode.includes("'worklet'");let o;try{const n={presets:[[require("@babel/preset-env"),{targets:{chrome:53,ios:8},modules:!1,include:["@babel/plugin-transform-computed-properties"]}]],babelrc:!1,plugins:getEnhancePluginsList({supportWorklet:s}),sourceFileName:r,inputSourceMap:!1,configFile:!1,code:!1,ast:!0,cloneInputAst:!1};if(e.astInfo){if(e.astInfo.type!==config_1.AstType.Babel)throw new Error("ast type is not babel");o=t.transformFromAstSync(e.astInfo.ast,e.sourceCode,n)}else{if(null===e.sourceCode)throw new Error("source.targetCode is null");o=babel7().transform(e.sourceCode,n)}}catch(e){const t=`file: ${r}\n ${e.message}`,s=new Error(t);throw s.code=config_1.BABEL_TRANS_JS_ERR,s}return{sourceCode:e.sourceCode,inputMap:e.inputMap,astInfo:{ast:o.ast,type:config_1.AstType.Babel}}};function default_1(e,r){return{name:"summer-enhance",workerMethods:{doTransform:(e,r,t,s)=>enhance(e,r)},async transform(e,t,s,{independentRoot:o,isBabelIgnore:n}){const{source:u}=e;if(t.endsWith(".js")&&!u.largeFile&&!n){const t=(0,es6module_1.getBabelRoot)(o);return Object.assign(Object.assign({},e),{source:Object.assign(Object.assign({},e.source),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const config_1=require("../../../../config/config"),babel_helper_1=require("../../../../utils/babel_helper"),es6module_1=require("./base/es6module"),_transformRuntimeCustom=()=>require("../../../../utils/babel_transform_plugin"),_pluginTransformRuntime=()=>require("@babel/plugin-transform-runtime"),_pluginTransformWorklet=()=>require("../../../../utils/babel_plugin_worklet"),babel7=()=>require("@babel/core"),_presetEnv=()=>require("@babel/preset-env");function getEnhancePluginsList(e){const r=[[require("../../../../utils/babel_transform_plugin")],[require("@babel/plugin-transform-runtime"),{corejs:!1,helpers:!0,regenerator:!0,version:"7.21.0"}]].concat((0,babel_helper_1.getCustomPlugins)([]));return e.supportWorklet&&r.push([require("../../../../utils/babel_plugin_worklet")]),r}const enhance=(e,r)=>{const t=babel7(),s=e.sourceCode.includes('"worklet"')||e.sourceCode.includes("'worklet'");let o;try{const n={presets:[[require("@babel/preset-env"),{targets:{chrome:53,ios:8},modules:!1,include:["@babel/plugin-transform-computed-properties"]}]],babelrc:!1,plugins:getEnhancePluginsList({supportWorklet:s}),sourceFileName:r,inputSourceMap:!1,configFile:!1,code:!1,ast:!0,cloneInputAst:!1};if(e.astInfo){if(e.astInfo.type!==config_1.AstType.Babel)throw new Error("ast type is not babel");o=t.transformFromAstSync(e.astInfo.ast,e.sourceCode,n)}else{if(null===e.sourceCode)throw new Error("source.targetCode is null");o=babel7().transform(e.sourceCode,n)}}catch(e){const t=`file: ${r}\n ${e.message}`,s=new Error(t);throw s.code=config_1.BABEL_TRANS_JS_ERR,s}return{sourceCode:e.sourceCode,inputMap:e.inputMap,astInfo:{ast:o.ast,type:config_1.AstType.Babel}}};function default_1(e,r){return{name:"summer-enhance",workerMethods:{doTransform:(e,r,t,s)=>enhance(e,r)},async transform(e,t,s,{independentRoot:o,isBabelIgnore:n}){const{source:u}=e;if(t.endsWith(".js")&&!u.largeFile&&!n){const t=Date.now(),n=(0,es6module_1.getBabelRoot)(o),a=await this.runWorkerMethod("doTransform",u,s,n,r.disableUseStrict);return Object.assign(Object.assign({},e),{source:Object.assign(Object.assign({},e.source),a),process:[...e.process,{cost:Date.now()-t,pluginName:"summer-enhance",action:"transform"}]})}return e}}}exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.importWxssCssReg=exports.importWxssReg=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),tools_1=require("../../../../utils/tools"),customError_1=require("../../../../utils/customError"),less=()=>require("less");function default_1(s,e){return{name:"summer-less",resolveExt:{wxss:"less"},async load(t,r){var o;if(r.endsWith(".less")){const a=(0,tools_1.pathRelative)(s.projectPath,r);let
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.importWxssCssReg=exports.importWxssReg=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),tools_1=require("../../../../utils/tools"),customError_1=require("../../../../utils/customError"),less=()=>require("less");function default_1(s,e){return{name:"summer-less",resolveExt:{wxss:"less"},async load(t,r){var o;if(r.endsWith(".less")){const a=Date.now(),i=(0,tools_1.pathRelative)(s.projectPath,r);let l=s.getFile("",i).toString();if(i!==s.getTargetPath(s.miniprogramRoot,"app")+".less"&&s.exists(s.miniprogramRoot,"app.less")){const e=(0,tools_1.pathRelative)(s.miniprogramRoot,path_1.default.dirname(i))||".";l=`@import (optional, reference) '${"."===e?".":(0,tools_1.pathRelative)(e,"./")}/app.less';\n${l}`}const p=[];l=l.replace(exports.importWxssReg,(s,e,t)=>(p.push(t),s.replace(t,t+"?css")));try{const i=await require("less").render(l,{sourceMap:{outputSourceFiles:!0},paths:this.rootPath?[this.rootPath]:[],filename:r,globalVars:null!==(o=null==e?void 0:e.globalVars)&&void 0!==o?o:{}}),u=i.css.replace(exports.importWxssCssReg,(s,e,t)=>{const r=t.slice(0,-4);return p.includes(r)?s.replace(t,r):s});if(i.imports.length)for(const s of i.imports)this.addWatchFile(s);let c=void 0;return i.map&&(c=JSON.parse(i.map),c.sources=c.sources.map(e=>path_1.default.posix.relative(s.projectPath,e))),{targetPath:t,source:{sourceCode:u,inputMap:c},process:[{cost:Date.now()-a,pluginName:"summer-less",action:"load"}]}}catch(s){throw(0,customError_1.makeCustomError)(s,customError_1.CustomErrors.SUMMER_PLUGIN_CODE_ERR)}}}}}exports.importWxssReg=/(?:^|\s)?(?:@import)(?:\s*)?(["'])([^"']+.wxss)\1(?:\s*);/g,exports.importWxssCssReg=/(?:^|\s)?(?:@import)(?:\s*)?(["'])([^"']+.wxss\?css)\1(?:\s*);/g,exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),config_1=require("../../../../config/config"),log=tslib_1.__importStar(require("../../../../utils/log")),customError_1=require("../../../../utils/customError"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),config_1=require("../../../../config/config"),log=tslib_1.__importStar(require("../../../../utils/log")),customError_1=require("../../../../utils/customError"),minifywxml_1=require("../../original/workerThread/task/minifywxml");function default_1(e,t){const{minify:r=!0}=t||{};return{name:"summer-minifywxml",workerMethods:{async doCompress(e,t,r){try{const i=await(0,minifywxml_1.minifyWXML)({code:e,filePath:t,setting:r});if(i.error)throw i.error;return i.code}catch(e){throw log.error(e),(0,customError_1.makeCustomError)(e.message,config_1.MINIFY_WXML_ERR,t)}}},async compress(t,i){var s,o;if(!r||"dev"===i.resultType||!t.targetPath.endsWith(".wxml"))return t;const n=Date.now(),a=t.target.code,c=await this.runWorkerMethod("doCompress",a,t.targetPath,Object.assign(Object.assign({collapseWhitespace:!0,conservativeCollapse:!1,preserveLineBreaks:!1},null===(s=e.setting.minifyWXMLSetting)||void 0===s?void 0:s.global),null===(o=e.setting.minifyWXMLSetting)||void 0===o?void 0:o[t.targetPath]));return Object.assign(Object.assign({},t),{target:Object.assign(Object.assign({},t.target),{code:c}),process:[...t.process,{cost:Date.now()-n,pluginName:"summer-minifywxml",action:"compress"}]})}}}exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.random=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),tools_1=require("../../../../utils/tools"),customError_1=require("../../../../utils/customError"),debug_1=require("../../../../utils/debug"),sass=(0,debug_1.shouldRunInMainProcess)()?()=>{process.versions.electron="0.54.0";const s=require("sass");return delete process.versions.electron,s}:()=>require("sass");function random(){return(0,tools_1.generateMD5)(`${Math.random()}${Date.now()}`)}exports.random=random;const importWxssReg=/(?:^|\s)?(?:@import)(?:\s*)?(["'])([^"']+.wxss)\1(?:\s*);/g,importCssReg=/(?:^|\s)?(?:@import)(?:\s*)?(["'])([^"']+.css)\1(?:\s*);/g;function default_1(s){return{name:"summer-sass",resolveExt:{wxss:["sass","scss"]},async load(t,e){if(e.endsWith(".scss")||e.endsWith(".sass")){const o=(0,tools_1.pathRelative)(s.projectPath,e);let r=s.getFile("",o).toString();const a=s.getTargetPath(s.miniprogramRoot,"global");if(o!==a+".scss"&&o!==a+".sass"){let t=path_1.default.extname(o);const e=(0,tools_1.pathRelative)(s.miniprogramRoot,path_1.default.dirname(o))||".";s.exists(s.miniprogramRoot,"global"+t)||(t=".sass"===t?".scss":".sass"),s.exists(s.miniprogramRoot,"global"+t)&&(r=".sass"===t?`@use '${"."===e?".":(0,tools_1.pathRelative)(e,"./")}/global${t}'\n${r}`:`@use '${"."===e?".":(0,tools_1.pathRelative)(e,"./")}/global${t}';\n${r}`)}const i=[];r=r.replace(importWxssReg,(s,t,e)=>(i.push(e),s.replace(e,e.slice(0,-4)+"css")));const n=path_1.default.posix.dirname((0,tools_1.pathRelative)(s.projectPath,e));return new Promise((s,o)=>{sass().render({file:e,data:r,sourceMap:!0,sourceMapContents:!0,omitSourceMapUrl:!0,outFile:e.slice(0,-5)+".wxss",includePaths:this.rootPath?[this.rootPath]:[]},(r,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.random=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),tools_1=require("../../../../utils/tools"),customError_1=require("../../../../utils/customError"),debug_1=require("../../../../utils/debug"),sass=(0,debug_1.shouldRunInMainProcess)()?()=>{process.versions.electron="0.54.0";const s=require("sass");return delete process.versions.electron,s}:()=>require("sass");function random(){return(0,tools_1.generateMD5)(`${Math.random()}${Date.now()}`)}exports.random=random;const importWxssReg=/(?:^|\s)?(?:@import)(?:\s*)?(["'])([^"']+.wxss)\1(?:\s*);/g,importCssReg=/(?:^|\s)?(?:@import)(?:\s*)?(["'])([^"']+.css)\1(?:\s*);/g;function default_1(s){return{name:"summer-sass",resolveExt:{wxss:["sass","scss"]},async load(t,e){if(e.endsWith(".scss")||e.endsWith(".sass")){const o=(0,tools_1.pathRelative)(s.projectPath,e);let r=s.getFile("",o).toString();const a=s.getTargetPath(s.miniprogramRoot,"global");if(o!==a+".scss"&&o!==a+".sass"){let t=path_1.default.extname(o);const e=(0,tools_1.pathRelative)(s.miniprogramRoot,path_1.default.dirname(o))||".";s.exists(s.miniprogramRoot,"global"+t)||(t=".sass"===t?".scss":".sass"),s.exists(s.miniprogramRoot,"global"+t)&&(r=".sass"===t?`@use '${"."===e?".":(0,tools_1.pathRelative)(e,"./")}/global${t}'\n${r}`:`@use '${"."===e?".":(0,tools_1.pathRelative)(e,"./")}/global${t}';\n${r}`)}const i=[];r=r.replace(importWxssReg,(s,t,e)=>(i.push(e),s.replace(e,e.slice(0,-4)+"css")));const n=path_1.default.posix.dirname((0,tools_1.pathRelative)(s.projectPath,e));return new Promise((s,o)=>{const a=Date.now();sass().render({file:e,data:r,sourceMap:!0,sourceMapContents:!0,omitSourceMapUrl:!0,outFile:e.slice(0,-5)+".wxss",includePaths:this.rootPath?[this.rootPath]:[]},(r,l)=>{if(r){const s=(0,customError_1.makeCustomError)(r,customError_1.CustomErrors.SUMMER_PLUGIN_CODE_ERR);return void o(s)}if(!l)return void o(new Error("no result"));const u=l.css.toString("utf-8").replace(importCssReg,(s,t,e)=>{const o=e.slice(0,-3)+"wxss";return i.includes(o)?s.replace(e,o):s});if(l.stats.includedFiles.length>0)for(const s of l.stats.includedFiles)s!==e&&this.addWatchFile(s);const c=l.map?JSON.parse(l.map.toString("utf-8")):void 0;c&&(c.sourceRoot=n),s({targetPath:t,source:{sourceCode:u,inputMap:c},process:[{cost:Date.now()-a,pluginName:"summer-sass",action:"load"}]})})})}}}}exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const config_1=require("../../../../config/config"),customError_1=require("../../../../utils/customError"),terser=()=>require("terser"),babelCodeFrame=()=>require("babel-code-frame");function default_1(e){const r=e.setting.minified;return{name:"summer-terser",workerMethods:{doCompress:async(e,r)=>require("terser").minify(e,{toplevel:!0,compress:{drop_console:!1,drop_debugger:!1},sourceMap:r})},async compress(e,o){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const config_1=require("../../../../config/config"),customError_1=require("../../../../utils/customError"),terser=()=>require("terser"),babelCodeFrame=()=>require("babel-code-frame");function default_1(e){const r=e.setting.minified;return{name:"summer-terser",workerMethods:{doCompress:async(e,r)=>require("terser").minify(e,{toplevel:!0,compress:{drop_console:!1,drop_debugger:!1},sourceMap:r})},async compress(e,o){const t=e.targetPath;if(!r||"prod"!==o.resultType||!t.endsWith(".js"))return e;const s=Date.now(),{map:n}=e.target,c=n?{includeSources:!0,content:"string"==typeof n?JSON.parse(n):n,filename:t}:{includeSources:!0,content:void 0,filename:t},i=e.target.code,a=await this.runWorkerMethod("doCompress",i,c);if(a.error){const e=a.error,r=`file: ${t}\n ${a.error.message}\n ${require("babel-code-frame")(i,e.line,e.col>0?e.col:1)}`;throw(0,customError_1.makeCustomError)(r,config_1.UGLIFY_JS_ERR,t)}return Object.assign(Object.assign({},e),{target:Object.assign(Object.assign({},e.target),{code:a.code,map:a.map}),process:[...e.process,{cost:Date.now()-s,pluginName:"summer-terser",action:"compress"}]})}}}exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),customError_1=require("../../../../utils/customError"),config_1=require("../../../../config/config"),pluginconfig_1=require("../pluginconfig"),babel7=()=>require("@babel/core"),pluginTransformTypescript=()=>require("@babel/plugin-transform-typescript"),pluginReplaceTsExportAssignment=e=>{const r=e.template("\n module.exports = ASSIGNMENT;\n ");return{name:"replace-ts-export-assignment",visitor:{TSExportAssignment(e){e.replaceWith(r({ASSIGNMENT:e.node.expression}))}}}},pluginReplaceTsImportEqualsDeclaration=e=>{const r=e.template("\n const ID = require(SOURCE);\n ");return{name:"replace-ts-import-equals-declaration",visitor:{TSImportEqualsDeclaration(e){e.replaceWith(r({ID:e.node.id,SOURCE:e.node.moduleReference.expression}))}}}};function default_1(e){return{name:"summer-typescript",resolveExt:{js:"ts"},workerMethods:{doLoad(e,r,t){let o;try{o=require("@babel/core").transform(e,{babelrc:!1,plugins:[[pluginReplaceTsImportEqualsDeclaration,{}],[pluginReplaceTsExportAssignment,{}],[require("@babel/plugin-transform-typescript"),{}]],sourceFileName:r,sourceMaps:!1,ast:!0,configFile:!1,code:!1})}catch(e){throw(0,customError_1.makeCustomError)(e,customError_1.CustomErrors.SUMMER_PLUGIN_CODE_ERR,r)}return{sourceCode:e,inputMap:t,astInfo:{ast:o.ast,type:config_1.AstType.Babel}}}},async load(r,t){if(!(0,pluginconfig_1.couldUseSWCMode)(e.setting)&&t.endsWith(".ts")){const o=path_1.default.relative(e.projectPath,t),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),customError_1=require("../../../../utils/customError"),config_1=require("../../../../config/config"),pluginconfig_1=require("../pluginconfig"),babel7=()=>require("@babel/core"),pluginTransformTypescript=()=>require("@babel/plugin-transform-typescript"),pluginReplaceTsExportAssignment=e=>{const r=e.template("\n module.exports = ASSIGNMENT;\n ");return{name:"replace-ts-export-assignment",visitor:{TSExportAssignment(e){e.replaceWith(r({ASSIGNMENT:e.node.expression}))}}}},pluginReplaceTsImportEqualsDeclaration=e=>{const r=e.template("\n const ID = require(SOURCE);\n ");return{name:"replace-ts-import-equals-declaration",visitor:{TSImportEqualsDeclaration(e){e.replaceWith(r({ID:e.node.id,SOURCE:e.node.moduleReference.expression}))}}}};function default_1(e){return{name:"summer-typescript",resolveExt:{js:"ts"},workerMethods:{doLoad(e,r,t){let o;try{o=require("@babel/core").transform(e,{babelrc:!1,plugins:[[pluginReplaceTsImportEqualsDeclaration,{}],[pluginReplaceTsExportAssignment,{}],[require("@babel/plugin-transform-typescript"),{}]],sourceFileName:r,sourceMaps:!1,ast:!0,configFile:!1,code:!1})}catch(e){throw(0,customError_1.makeCustomError)(e,customError_1.CustomErrors.SUMMER_PLUGIN_CODE_ERR,r)}return{sourceCode:e,inputMap:t,astInfo:{ast:o.ast,type:config_1.AstType.Babel}}}},async load(r,t){if(!(0,pluginconfig_1.couldUseSWCMode)(e.setting)&&t.endsWith(".ts")){const o=Date.now(),s=path_1.default.relative(e.projectPath,t),i=e.getFile("",s).toString();return{targetPath:r,source:await this.runWorkerMethod("doLoad",i,t),process:[{cost:Date.now()-o,pluginName:"summer-typescript",action:"load"}]}}}}}exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const config_1=require("../../../../config/config"),_pluginTransformWorklet=()=>require("../../../../utils/babel_plugin_worklet"),babel7=()=>require("@babel/core"),worklet=(e,r)=>{const o=babel7();let t;try{const s={babelrc:!1,plugins:[require("../../../../utils/babel_plugin_worklet")],sourceFileName:r,inputSourceMap:!1,configFile:!1,code:!1,ast:!0,cloneInputAst:!1};if(e.astInfo){if(e.astInfo.type!==config_1.AstType.Babel)throw new Error("ast type is not babel");t=o.transformFromAstSync(e.astInfo.ast,e.sourceCode,s)}else{if(null===e.sourceCode)throw new Error("source.targetCode is null");t=babel7().transform(e.sourceCode,s)}}catch(e){const o=`file: ${r}\n ${e.message}`,t=new Error(o);throw t.code=config_1.BABEL_TRANS_JS_ERR,t}return{sourceCode:e.sourceCode,inputMap:e.inputMap,astInfo:{ast:t.ast,type:config_1.AstType.Babel}}};function default_1(e,r){return{name:"summer-worklet",workerMethods:{worklet:worklet},async transform(e,r,o,{isBabelIgnore:t}){if(r.endsWith(".js")&&!t){const{source:r}=e;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const config_1=require("../../../../config/config"),_pluginTransformWorklet=()=>require("../../../../utils/babel_plugin_worklet"),babel7=()=>require("@babel/core"),worklet=(e,r)=>{const o=babel7();let t;try{const s={babelrc:!1,plugins:[require("../../../../utils/babel_plugin_worklet")],sourceFileName:r,inputSourceMap:!1,configFile:!1,code:!1,ast:!0,cloneInputAst:!1};if(e.astInfo){if(e.astInfo.type!==config_1.AstType.Babel)throw new Error("ast type is not babel");t=o.transformFromAstSync(e.astInfo.ast,e.sourceCode,s)}else{if(null===e.sourceCode)throw new Error("source.targetCode is null");t=babel7().transform(e.sourceCode,s)}}catch(e){const o=`file: ${r}\n ${e.message}`,t=new Error(o);throw t.code=config_1.BABEL_TRANS_JS_ERR,t}return{sourceCode:e.sourceCode,inputMap:e.inputMap,astInfo:{ast:t.ast,type:config_1.AstType.Babel}}};function default_1(e,r){return{name:"summer-worklet",workerMethods:{worklet:worklet},async transform(e,r,o,{isBabelIgnore:t}){if(r.endsWith(".js")&&!t){const{source:r}=e;if(r.sourceCode.includes('"worklet"')||r.sourceCode.includes("'worklet'")){const t=Date.now(),s=await this.runWorkerMethod("worklet",r,o);return Object.assign(Object.assign({},e),{source:Object.assign(Object.assign({},e.source),s),process:[...e.process,{cost:Date.now()-t,pluginName:"summer-worklet",action:"transform"}]})}return e}return e}}}exports.default=default_1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SummerCompiler=void 0;const tslib_1=require("tslib"),nodePath=tslib_1.__importStar(require("path")),lodash_1=require("lodash"),reactiveCache_1=require("../original/json/reactiveCache"),locales_1=tslib_1.__importDefault(require("../../../utils/locales/locales")),tools_1=require("../../../utils/tools"),plugingraph_1=require("./graph/plugingraph"),gameplugingraph_1=require("./graph/gameplugingraph"),appgraph_1=require("./graph/appgraph"),initPlugin_1=require("./initPlugin"),pluginDriver_1=require("./pluginDriver"),persistCache_1=tslib_1.__importDefault(require("./persistCache")),babel_helper_1=require("../../../utils/babel_helper"),config_1=require("../../../config/config"),gamegraph_1=require("./graph/gamegraph");function initProxyProjectForJSON(i){let e={};function t(t,r){const o=i.stat(t,r);if(o)return o;const s=i.getTargetPath(t,r);for(const i in e)if(s.startsWith(i))return e[i].stat(nodePath.posix.relative(i,s))}const r=new Proxy(i,{get:(i,e,r)=>"stat"===e?t:Reflect.get(i,e,r)});return r.addResolver=i=>{(0,reactiveCache_1.cleanReactiveCache)(),e[i.root]=i},r.removeResolver=i=>{(0,reactiveCache_1.cleanReactiveCache)(),delete e[i.root]},r.clearResolver=()=>{e={},(0,reactiveCache_1.cleanReactiveCache)()},r}function getCacheBaseKey(i){const e=["es6","minified","postcss","uglifyFileName","compileWorklet","enhance","swc","minifyWXSS","minifyWXML","disableUseStrict"],t=[i.miniprogramRoot,i.pluginRoot,i.compileType,i.projectArchitecture,...i.summerPlugins,(0,babel_helper_1.getBabelHelperVersion)(),JSON.stringify(i.setting.swcSetting),JSON.stringify(i.setting.babelSetting)];for(const r of e)t.push(i.setting[r]?"1":"0");return(0,tools_1.generateMD5)(t.join("|"))}class SummerCompiler{constructor(i,e,t){this.project=i,this.cachePath=e,this.devtoolsProject=t,this.proxyProject=initProxyProjectForJSON(i),this.projectPath=i.projectPath,this.persistCache=new persistCache_1.default(this.proxyProject,e,getCacheBaseKey(t)),this.initPlugins(),this.initAppGraph(),this.isPluginType(i.type)&&this.initPluginGraph()}getBabelSetting(){return this.devtoolsProject.setting.babelSetting}getSWCSetting(){return this.devtoolsProject.setting.swcSetting}initPlugins(){this.plugins=this.devtoolsProject.summerPlugins.map(i=>{let e,t={};return"string"==typeof i?e=i:(e=i[0],t=i[1]),(0,initPlugin_1.initPlugin)(e,this.project,t)})}isGameType(i){return i===config_1.COMPILE_TYPE.miniGame||i===config_1.COMPILE_TYPE.miniGamePlugin}isPluginType(i){return i===config_1.COMPILE_TYPE.miniProgramPlugin||i===config_1.COMPILE_TYPE.miniGamePlugin}initAppGraph(){var i;null===(i=this.appGraph)||void 0===i||i.destroy(),this.isGameType(this.project.type)?this.appGraph=new gamegraph_1.GameGraph({type:"minigame",root:this.project.miniprogramRoot,persistCache:this.persistCache,plugins:this.plugins,compiler:this}):this.appGraph=new appgraph_1.AppGraph({type:"miniprogram",root:this.project.miniprogramRoot,persistCache:this.persistCache,plugins:this.plugins,compiler:this})}initPluginGraph(){var i;null===(i=this.pluginGraph)||void 0===i||i.destroy(),this.devtoolsProject.compileType===config_1.COMPILE_TYPE.miniGamePlugin?this.pluginGraph=new gameplugingraph_1.GamePluginGraph({type:"plugin",root:this.project.pluginRoot,persistCache:this.persistCache,plugins:this.plugins,compiler:this}):this.pluginGraph=new plugingraph_1.PluginGraph({type:"plugin",root:this.project.pluginRoot,persistCache:this.persistCache,plugins:this.plugins,compiler:this})}updateOptions(i){var e;const t=this.devtoolsProject;if(this.devtoolsProject=i,this.persistCache.updateBaseCacheKey(getCacheBaseKey(i)),!(0,lodash_1.isEqual)(i.setting,t.setting)||!(0,lodash_1.isEqual)(this.devtoolsProject.summerPlugins,t.summerPlugins))return this.project.setting=i.setting,this.initPlugins(),this.initAppGraph(),void("miniProgramPlugin"===this.devtoolsProject.compileType&&this.initPluginGraph());this.devtoolsProject.compileType!==t.compileType&&("miniProgramPlugin"===this.devtoolsProject.compileType?this.initPluginGraph():(null===(e=this.pluginGraph)||void 0===e||e.destroy(),this.pluginGraph=void 0)),this.appGraph.root!==this.project.miniprogramRoot&&this.initAppGraph(),this.pluginGraph&&this.pluginGraph.root!==this.project.pluginRoot&&this.initPluginGraph()}destroy(){var i,e;null===(i=this.appGraph)||void 0===i||i.destroy(),null===(e=this.pluginGraph)||void 0===e||e.destroy(),this.proxyProject.clearResolver()}getStatus(){const i=(0,pluginDriver_1.genResovleExtConf)(this.plugins),e={},t=new Set;for(const r of["json","js","wxml","wxss","wxs"])e[r]={exts:i[r].reverse()},i[r].forEach(i=>{t.add(i)});return{codeExts:Array.from(t.keys()),codeConf:e}}clearCache(){var i,e,t;null===(e=(i=this.project).clearCache)||void 0===e||e.call(i),this.appGraph.clearCache(),null===(t=this.pluginGraph)||void 0===t||t.clearCache(),this.persistCache.clean(),(0,reactiveCache_1.cleanReactiveCache)()}async getPackageFiles({graphId:i,root:e},t){var r;return this.isPluginType(i)?await(null===(r=this.pluginGraph)||void 0===r?void 0:r.getPackageFile()):await this.appGraph.getPackageFile(e)}async getConf({graphId:i},e){if(i===config_1.COMPILE_TYPE.miniProgram||i===config_1.COMPILE_TYPE.miniGame){return await this.appGraph.getConf(e)}if(this.isPluginType(i)){return await this.pluginGraph.getConf(e)}throw new Error("no support getConf for "+i)}async getCode(i,e){if(i.graphId===config_1.COMPILE_TYPE.miniProgram||i.graphId===config_1.COMPILE_TYPE.miniGame){return await this.appGraph.getDevCode(e,{package:i.package})}if(this.isPluginType(i.graphId)){return await this.pluginGraph.getDevCode(e)}throw new Error("no support getCode for "+i.graphId)}async getDevCodeByFileList(i,e){if(i.graphId===config_1.COMPILE_TYPE.miniProgram||i.graphId===config_1.COMPILE_TYPE.miniGame){return await this.appGraph.getDevCodeByFileList(e,{fileList:i.fileList})}if(this.isPluginType(i.graphId)){return await this.pluginGraph.getDevCodeByFileList(e,{fileList:i.fileList})}throw new Error("no support getDevCodeByFileList for "+i.graphId)}async getLocalFileList(i){if(i===config_1.COMPILE_TYPE.miniProgram||i===config_1.COMPILE_TYPE.miniGame)return await this.appGraph.getLocalFileList();if(this.isPluginType(i))return await this.pluginGraph.getLocalFileList();throw new Error("no support getCode for "+i)}async compileSingleCode(i,e){if(i.graphId===config_1.COMPILE_TYPE.miniProgram||i.graphId===config_1.COMPILE_TYPE.miniGame){return await this.appGraph.compileSingleCode(i.filePath,i.sourceCode)}if(this.isPluginType(i.graphId)){return await this.pluginGraph.compileSingleCode(i.filePath,i.sourceCode)}throw new Error("no support getCode for "+i.graphId)}async compileNewLogic(i,e){const t=await e.run(this.isGameType(this.project.type)?locales_1.default.config.SUMMER_COMPILE_MINIGAME.format():locales_1.default.config.SUMMER_COMPILE_MINIPROGRAM.format(),()=>this.appGraph.compileWithFileList(i,e));if(this.project.type===config_1.COMPILE_TYPE.miniProgram||this.project.type===config_1.COMPILE_TYPE.miniGame)return{app:t};if(this.isPluginType(this.project.type)){return{app:t,plugin:await e.run(locales_1.default.config.SUMMER_COMPILE_PLUGIN.format(),()=>this.pluginGraph.compile(i,e))}}throw new Error("no support compile for "+this.project.type)}async compile(i,e){const t=await e.run(this.isGameType(this.project.type)?locales_1.default.config.SUMMER_COMPILE_MINIGAME.format():locales_1.default.config.SUMMER_COMPILE_MINIPROGRAM.format(),()=>this.appGraph.compile(i,e));if(this.project.type===config_1.COMPILE_TYPE.miniProgram||this.project.type===config_1.COMPILE_TYPE.miniGame)return t["project.config.json"]=JSON.stringify({miniprogramRoot:"",__compileDebugInfo__:{useSummer:!0}}),t;if(this.isPluginType(this.project.type)){const r={},o=await e.run(locales_1.default.config.SUMMER_COMPILE_PLUGIN.format(),()=>this.pluginGraph.compile(i,e));return Object.keys(t).forEach(i=>{r[nodePath.posix.join(this.project.miniprogramRoot,i)]=t[i]}),Object.keys(o).forEach(i=>{r[nodePath.posix.join(this.project.pluginRoot,i)]=o[i]}),r["project.config.json"]=JSON.stringify({miniprogramRoot:this.project.miniprogramRoot,pluginRoot:this.project.pluginRoot,__compileDebugInfo__:{useSummer:!0}}),r}throw new Error("no support compile for "+this.project.type)}}exports.SummerCompiler=SummerCompiler;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SummerCompiler=void 0;const tslib_1=require("tslib"),nodePath=tslib_1.__importStar(require("path")),lodash_1=require("lodash"),reactiveCache_1=require("../original/json/reactiveCache"),locales_1=tslib_1.__importDefault(require("../../../utils/locales/locales")),tools_1=require("../../../utils/tools"),plugingraph_1=require("./graph/plugingraph"),gameplugingraph_1=require("./graph/gameplugingraph"),appgraph_1=require("./graph/appgraph"),initPlugin_1=require("./initPlugin"),pluginDriver_1=require("./pluginDriver"),persistCache_1=tslib_1.__importDefault(require("./persistCache")),babel_helper_1=require("../../../utils/babel_helper"),config_1=require("../../../config/config"),gamegraph_1=require("./graph/gamegraph");function initProxyProjectForJSON(i){let e={};function t(t,r){const o=i.stat(t,r);if(o)return o;const s=i.getTargetPath(t,r);for(const i in e)if(s.startsWith(i))return e[i].stat(nodePath.posix.relative(i,s))}const r=new Proxy(i,{get:(i,e,r)=>"stat"===e?t:Reflect.get(i,e,r)});return r.addResolver=i=>{(0,reactiveCache_1.cleanReactiveCache)(),e[i.root]=i},r.removeResolver=i=>{(0,reactiveCache_1.cleanReactiveCache)(),delete e[i.root]},r.clearResolver=()=>{e={},(0,reactiveCache_1.cleanReactiveCache)()},r}function getCacheBaseKey(i){const e=["es6","minified","postcss","uglifyFileName","compileWorklet","enhance","swc","minifyWXSS","minifyWXML","disableUseStrict"],t=[i.miniprogramRoot,i.pluginRoot,i.compileType,i.projectArchitecture,...i.summerPlugins,(0,babel_helper_1.getBabelHelperVersion)(),JSON.stringify(i.setting.swcSetting),JSON.stringify(i.setting.minifyWXMLSetting),JSON.stringify(i.setting.babelSetting)];for(const r of e)t.push(i.setting[r]?"1":"0");return(0,tools_1.generateMD5)(t.join("|"))}class SummerCompiler{constructor(i,e,t){this.project=i,this.cachePath=e,this.devtoolsProject=t,this.proxyProject=initProxyProjectForJSON(i),this.projectPath=i.projectPath,this.persistCache=new persistCache_1.default(this.proxyProject,e,getCacheBaseKey(t)),this.initPlugins(),this.initAppGraph(),this.isPluginType(i.type)&&this.initPluginGraph()}getBabelSetting(){return this.devtoolsProject.setting.babelSetting}getSWCSetting(){return this.devtoolsProject.setting.swcSetting}initPlugins(){this.plugins=this.devtoolsProject.summerPlugins.map(i=>{let e,t={};return"string"==typeof i?e=i:(e=i[0],t=i[1]),(0,initPlugin_1.initPlugin)(e,this.project,t)})}isGameType(i){return i===config_1.COMPILE_TYPE.miniGame||i===config_1.COMPILE_TYPE.miniGamePlugin}isPluginType(i){return i===config_1.COMPILE_TYPE.miniProgramPlugin||i===config_1.COMPILE_TYPE.miniGamePlugin}initAppGraph(){var i;null===(i=this.appGraph)||void 0===i||i.destroy(),this.isGameType(this.project.type)?this.appGraph=new gamegraph_1.GameGraph({type:"minigame",root:this.project.miniprogramRoot,persistCache:this.persistCache,plugins:this.plugins,compiler:this}):this.appGraph=new appgraph_1.AppGraph({type:"miniprogram",root:this.project.miniprogramRoot,persistCache:this.persistCache,plugins:this.plugins,compiler:this})}initPluginGraph(){var i;null===(i=this.pluginGraph)||void 0===i||i.destroy(),this.devtoolsProject.compileType===config_1.COMPILE_TYPE.miniGamePlugin?this.pluginGraph=new gameplugingraph_1.GamePluginGraph({type:"plugin",root:this.project.pluginRoot,persistCache:this.persistCache,plugins:this.plugins,compiler:this}):this.pluginGraph=new plugingraph_1.PluginGraph({type:"plugin",root:this.project.pluginRoot,persistCache:this.persistCache,plugins:this.plugins,compiler:this})}updateOptions(i){var e;const t=this.devtoolsProject;if(this.devtoolsProject=i,this.persistCache.updateBaseCacheKey(getCacheBaseKey(i)),!(0,lodash_1.isEqual)(i.setting,t.setting)||!(0,lodash_1.isEqual)(this.devtoolsProject.summerPlugins,t.summerPlugins))return this.project.setting=i.setting,this.initPlugins(),this.initAppGraph(),void("miniProgramPlugin"===this.devtoolsProject.compileType&&this.initPluginGraph());this.devtoolsProject.compileType!==t.compileType&&("miniProgramPlugin"===this.devtoolsProject.compileType?this.initPluginGraph():(null===(e=this.pluginGraph)||void 0===e||e.destroy(),this.pluginGraph=void 0)),this.appGraph.root!==this.project.miniprogramRoot&&this.initAppGraph(),this.pluginGraph&&this.pluginGraph.root!==this.project.pluginRoot&&this.initPluginGraph()}destroy(){var i,e;null===(i=this.appGraph)||void 0===i||i.destroy(),null===(e=this.pluginGraph)||void 0===e||e.destroy(),this.proxyProject.clearResolver()}getStatus(){const i=(0,pluginDriver_1.genResovleExtConf)(this.plugins),e={},t=new Set;for(const r of["json","js","wxml","wxss","wxs"])e[r]={exts:i[r].reverse()},i[r].forEach(i=>{t.add(i)});return{codeExts:Array.from(t.keys()),codeConf:e}}clearCache(){var i,e,t;null===(e=(i=this.project).clearCache)||void 0===e||e.call(i),this.appGraph.clearCache(),null===(t=this.pluginGraph)||void 0===t||t.clearCache(),this.persistCache.clean(),(0,reactiveCache_1.cleanReactiveCache)()}async getPackageFiles({graphId:i,root:e},t){var r;return this.isPluginType(i)?await(null===(r=this.pluginGraph)||void 0===r?void 0:r.getPackageFile()):await this.appGraph.getPackageFile(e)}async getConf({graphId:i},e){if(i===config_1.COMPILE_TYPE.miniProgram||i===config_1.COMPILE_TYPE.miniGame){return await this.appGraph.getConf(e)}if(this.isPluginType(i)){return await this.pluginGraph.getConf(e)}throw new Error("no support getConf for "+i)}async getCode(i,e){if(i.graphId===config_1.COMPILE_TYPE.miniProgram||i.graphId===config_1.COMPILE_TYPE.miniGame){return await this.appGraph.getDevCode(e,{package:i.package})}if(this.isPluginType(i.graphId)){return await this.pluginGraph.getDevCode(e)}throw new Error("no support getCode for "+i.graphId)}async getDevCodeByFileList(i,e){if(i.graphId===config_1.COMPILE_TYPE.miniProgram||i.graphId===config_1.COMPILE_TYPE.miniGame){return await this.appGraph.getDevCodeByFileList(e,{fileList:i.fileList})}if(this.isPluginType(i.graphId)){return await this.pluginGraph.getDevCodeByFileList(e,{fileList:i.fileList})}throw new Error("no support getDevCodeByFileList for "+i.graphId)}async getLocalFileList(i){if(i===config_1.COMPILE_TYPE.miniProgram||i===config_1.COMPILE_TYPE.miniGame)return await this.appGraph.getLocalFileList();if(this.isPluginType(i))return await this.pluginGraph.getLocalFileList();throw new Error("no support getCode for "+i)}async compileSingleCode(i,e){if(i.graphId===config_1.COMPILE_TYPE.miniProgram||i.graphId===config_1.COMPILE_TYPE.miniGame){return await this.appGraph.compileSingleCode(i.filePath,i.sourceCode)}if(this.isPluginType(i.graphId)){return await this.pluginGraph.compileSingleCode(i.filePath,i.sourceCode)}throw new Error("no support getCode for "+i.graphId)}async compileNewLogic(i,e){const t=await e.run(this.isGameType(this.project.type)?locales_1.default.config.SUMMER_COMPILE_MINIGAME.format():locales_1.default.config.SUMMER_COMPILE_MINIPROGRAM.format(),()=>this.appGraph.compileWithFileList(i,e));if(this.project.type===config_1.COMPILE_TYPE.miniProgram||this.project.type===config_1.COMPILE_TYPE.miniGame)return{app:t};if(this.isPluginType(this.project.type)){return{app:t,plugin:await e.run(locales_1.default.config.SUMMER_COMPILE_PLUGIN.format(),()=>this.pluginGraph.compile(i,e))}}throw new Error("no support compile for "+this.project.type)}async compile(i,e){const t=await e.run(this.isGameType(this.project.type)?locales_1.default.config.SUMMER_COMPILE_MINIGAME.format():locales_1.default.config.SUMMER_COMPILE_MINIPROGRAM.format(),()=>this.appGraph.compile(i,e));if(this.project.type===config_1.COMPILE_TYPE.miniProgram||this.project.type===config_1.COMPILE_TYPE.miniGame)return t["project.config.json"]=JSON.stringify({miniprogramRoot:"",__compileDebugInfo__:{useSummer:!0}}),t;if(this.isPluginType(this.project.type)){const r={},o=await e.run(locales_1.default.config.SUMMER_COMPILE_PLUGIN.format(),()=>this.pluginGraph.compile(i,e));return Object.keys(t).forEach(i=>{r[nodePath.posix.join(this.project.miniprogramRoot,i)]=t[i]}),Object.keys(o).forEach(i=>{r[nodePath.posix.join(this.project.pluginRoot,i)]=o[i]}),r["project.config.json"]=JSON.stringify({miniprogramRoot:this.project.miniprogramRoot,pluginRoot:this.project.pluginRoot,__compileDebugInfo__:{useSummer:!0}}),r}throw new Error("no support compile for "+this.project.type)}}exports.SummerCompiler=SummerCompiler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SummerCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=tslib_1.__importDefault(require("lodash")),locales_1=tslib_1.__importDefault(require("../../utils/locales/locales")),request_1=require("../../utils/request"),progressRecorder_1=require("../../utils/progressRecorder"),common_1=require("./original/compile/common"),tools_1=require("../../utils/tools"),white_ext_list_1=require("../../utils/white_ext_list"),config_1=require("../../config/config"),processManager_1=require("../../utils/subprocess/processManager"),messageHub_1=require("../../utils/messageHub"),singletontask_1=require("../../utils/singletontask"),uglifyfilenames_1=require("./original/protect/uglifyfilenames"),index_1=require("./original/index"),baseCompiler_1=require("./baseCompiler"),packOptionsHelper_1=tslib_1.__importDefault(require("../../utils/packOptionsHelper")),miniProgram=config_1.COMPILE_TYPE.miniProgram,miniGame=config_1.COMPILE_TYPE.miniGame,miniProgramPlugin=config_1.COMPILE_TYPE.miniProgramPlugin,miniGamePlugin=config_1.COMPILE_TYPE.miniGamePlugin;function performanceMark(e,t){}class SummerCompiler extends baseCompiler_1.BaseCoreCompiler{constructor(e,t,i,s,o,r){super(e),this.project=e,this.cachePath=t,this.projectInfo=i,this.devtoolMessagehub=s,this.analyzer=o,this._filterFactory=r,this.isSummer=!0,this.codeCache=new Map,this.promiseCache=new Map,this._taskCache=new Map,this._status=void 0,this._eventAdded=!1,this._locale="",this.codeCacheByPath=new Map,this.onFileChange=(e,t)=>{if("change"!==e||t.endsWith(".json"))for(const e of this.promiseCache.keys())e.startsWith("getConf-")&&this.promiseCache.delete(e);if("change"!==e){for(const e of this.promiseCache.keys())e.startsWith("getPackageFiles-")&&this.promiseCache.delete(e);for(const e of this._taskCache.keys())e.startsWith("getPackageFiles-")&&this._taskCache.delete(e)}this.invalidCodeCache(t),this.subProcessManager.sendEvent("fileChange",{type:e,targetPath:t})},this.onPreCompileOptionsChange=async e=>{await this.clearCache(),this.subProcessManager.sendEvent("precompileOptionsChange",e)},this.onProgressUpdate=(e,t,i)=>{const s="warn"===t?"warn":"doing"===t?"doing":"done"===t?"success":"error";this.messageHub.showBuildLog(""+e,s,i)},this._getPackageFiles=async(e,t,i="dev")=>{performanceMark("request get getPackageFiles");const s=await this.subProcessManager.runTask("getPackageFiles",{graphId:e,root:t},this.onProgressUpdate);performanceMark("request get getPackageFiles",!0);const o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,r=await this.filterFactory(i),a={},n=s.filter(t=>{const i=path_1.default.posix.join(o,t.path),s=r(e,i);return s!==config_1.EFilterCode.Include&&(a[s]||(a[s]=[]),a[s].push(i)),s===config_1.EFilterCode.Include}),c={[config_1.EFilterCode.AnalyseNoUse]:locales_1.default.config.UNUSE_FILE_LIST,[config_1.EFilterCode.PackOptionsIgnore]:locales_1.default.config.PACK_OPTIONS_IGNORE_LIST,[config_1.EFilterCode.PartialCompileNoUse]:locales_1.default.config.PARTIAL_COMPILE_IGNORE_LIST};for(const e in a)c[e]?this.onProgressUpdate(e,"warn",c[e].format(a[e].join(","))):this.onProgressUpdate(e,"warn",locales_1.default.config.UNKNOWN_REASON_INGORE_LIST.format(e,a[e].join(",")));return n},performanceMark("create summer compiler"),this.messageHub=new messageHub_1.MessageHub(s),this.ready()}get status(){return this._status}async init(){performanceMark("init summer compiler");const e=path_1.default.posix.join(__dirname,"./summerEntryProcess.js");this.subProcessManager=new processManager_1.SubProcessProxy(this.project,e,{cachePath:this.cachePath},this.projectInfo,8891),this.addProjectListener(),this.loadStatus(),performanceMark("init summer compiler",!0)}async loadStatus(){this._status=await this.subProcessManager.runTask("loadStatus")}destroy(){var e;null===(e=this.subProcessManager)||void 0===e||e.destroy(),this.removeProjectListener(),this._checkReadyTask=void 0}async clearCache(){var e;await(null===(e=this.subProcessManager)||void 0===e?void 0:e.runTask("clearCache")),this.codeCache.clear(),this.promiseCache.clear(),this.codeCacheByPath.clear(),this._taskCache.clear()}updateOptions(e){var t;lodash_1.default.isEqual(e,this.projectInfo)||(this.projectInfo=e,this.promiseCache.clear(),this.codeCache.clear(),this.codeCacheByPath.clear(),null===(t=this.subProcessManager)||void 0===t||t.sendEvent("updateOptions",e),this.loadStatus(),this.project.updateOptions(e))}addProjectListener(){var e,t;this._eventAdded&&this.removeProjectListener(),null===(e=this.project.event)||void 0===e||e.on("fileChange",this.onFileChange),null===(t=this.project.event)||void 0===t||t.on("precompileOptionsChange",this.onPreCompileOptionsChange),this._eventAdded=!0}removeProjectListener(){var e,t;null===(e=this.project.event)||void 0===e||e.off("fileChange",this.onFileChange),null===(t=this.project.event)||void 0===t||t.off("precompileOptionsChange",this.onPreCompileOptionsChange),this._eventAdded=!1}invalidCodeCache(e){for(const e of this.codeCache.values())e.isValid=!1;this.codeCacheByPath.delete((0,tools_1.sourcePathToTargetPath)(e))}async getConf(e){var t,i;const s="getConf-"+e;if(this.promiseCache.has(s))return(null===(t=process.env)||void 0===t?void 0:t.isDevtools)&&console.log(s,"hit cache"),this.promiseCache.get(s);(null===(i=process.env)||void 0===i?void 0:i.isDevtools)&&console.log(s,"do request"),performanceMark("request get conf");const o={graphId:e},r=this.subProcessManager.runTask("getConf",o,this.onProgressUpdate);return this.promiseCache.set(s,r),performanceMark("request get conf",!0),r}async getPackageFiles(e,t,i="dev",s=!0){const o=`getPackageFiles-${e}-${t}-${i}`;if(this._taskCache.has(o)&&s){const e=this._taskCache.get(o);return null==e?void 0:e.getResult(!0)}const r=new singletontask_1.SingletonTask(this._getPackageFiles.bind(this,e,t,i),o);return this._taskCache.set(o,r),null==r?void 0:r.getResult(!0)}async filterFactory(e){packOptionsHelper_1.default.updateState(this.project),this.onProgressUpdate("initUnusedFiles","doing","analyzing codes..."),await packOptionsHelper_1.default.initUnusedFiles(this.project,this.analyzer,"prod"===e),this.onProgressUpdate("initUnusedFiles","done","analyzing codes success");const t=this._filterFactory?await this._filterFactory(e):()=>0;return(i,s)=>"mini-android"!==this.project.targetPlatform&&"mini-ios"!==this.project.targetPlatform||path_1.default.posix.join(this.project.miniprogramRoot,"app.miniapp.json")!==s?i===miniProgram&&packOptionsHelper_1.default.isIgnoreByUnusedFiles(s,"prod"===e)?config_1.EFilterCode.AnalyseNoUse:packOptionsHelper_1.default.isIgnoredByRules(s)?config_1.EFilterCode.PackOptionsIgnore:t(i,s):config_1.EFilterCode.Include}async getCodeByFileList(e,t){const i={},s={},o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot;for(const e of t){const t=this.codeCacheByPath.get(path_1.default.posix.join(o,e));t&&("error"in t||(i[e]=t.md5,s[e]=t))}const r=await this.subProcessManager.runTask("getDevCodeByFileList",{graphId:e,fileList:t,cacheMd5:i},this.onProgressUpdate);console.error(r);for(const e in r){const t=r[e],i=path_1.default.posix.join(o,e);"error"in t||""!==t.md5?this.codeCacheByPath.set(i,t):this.codeCacheByPath.delete(i),s[e]=t}return s}async getCode(e,t){var i,s,o;const r=`getCode-${e}${t?"-"+t.package:""}`;if(this.promiseCache.has(r))return(null===(i=process.env)||void 0===i?void 0:i.isDevtools)&&console.log(r,"hit promise cache"),this.promiseCache.get(r);const a=this.codeCache.get(r);if(null==a?void 0:a.isValid)return a.codeFiles;(null===(s=process.env)||void 0===s?void 0:s.isDevtools)&&console.log(r,"do request");const n={};if(a){const{codeFiles:e}=a;for(const t of Object.keys(e)){const i=e[t];"error"in i||(n[t]=i.md5)}}const c={graphId:e,cacheMd5:n,package:null==t?void 0:t.package};performanceMark("request get code");const l=Date.now();(null===(o=process.env)||void 0===o?void 0:o.isDevtools)&&(console.time("[summer-compiler] runTask "+r),console.log(`[summer-compiler] [${(0,progressRecorder_1.getPrintTime)()}] runTask ${r}`));const g=this.subProcessManager.runTask("getCode",c,this.onProgressUpdate).then(e=>{var t,i;(null===(t=process.env)||void 0===t?void 0:t.isDevtools)&&console.timeEnd("[summer-compiler] runTask "+r);const s=(null===(i=this.codeCache.get(r))||void 0===i?void 0:i.codeFiles)||{};for(const t of Object.keys(e)){const i=e[t];"error"in i||""!==i.md5?s[t]=i:delete s[t]}return this.codeCache.set(r,{isValid:!0,codeFiles:s}),s},e=>{throw e.code?console.error(e):console.error("Unexpected error when getCode",e),e});return g.finally(()=>{var e;performanceMark("request get code",!0),(null===(e=process.env)||void 0===e?void 0:e.isDevtools)&&console.log(`[summer-compiler] [${(0,progressRecorder_1.getPrintTime)()}] [cost ${Date.now()-l}ms] runTask ${r}`),this.promiseCache.delete(r)}),this.promiseCache.set(r,g),g}async getExtJSON(){return await(0,index_1.getExtJSON)(this.project)}async getAppJSON(){return(await this.getConf(miniProgram)).app}async getGameJSON(){return(await this.getConf(miniGame)).app}async getSiteMapJSON(){return(await this.getConf(miniProgram)).sitemap}async getPageJSON(e){const t=await this.getConf(miniProgram),i=t.pages[e]||t.comps[e];if(!i)throw new Error("summer-compiler 收集json配置有遗漏, "+e);return i}async getAllPageAndComponent(){const e=await this.getConf(miniProgram),t=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".json"));return Object.keys(e.pages).concat(Object.keys(e.comps)).filter(e=>t.includes(e+".json"))}async getAllSortedJSFiles(){const e=await this.getConf(miniProgram),t=Object.keys(e.pages),i=Object.keys(e.comps),s=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),o=t.filter(e=>!i.includes(e)).map(e=>e+".js").filter(e=>s.includes(e)),r=i.map(e=>e+".js").filter(e=>s.includes(e)),a=s.filter(e=>e.endsWith(".js")&&"app.js"!==e&&!o.includes(e)&&!r.includes(e));return{jsPagesFiles:o,components:r,otherJsFiles:a}}async getAllWxmlAndWxsFiles(){const e=await this.getCode(miniProgram,{package:config_1.FullPkg}),t=Object.keys(e).filter(e=>e.endsWith(".wxml")),i=Object.keys(e).filter(e=>e.endsWith(".wxs"));return{wxmlFiles:t,wxsFiles:i,content:t.concat(i).reduce((t,i)=>{const s=e[i];if("error"in s)throw s.error;return t[i]=s.code,t["./"+i]=s.code,t},{})}}async getPackageWxmlAndWxsFiles(e){let t=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path);if(e!==config_1.MainPkg&&e!==config_1.FullPkg){const e=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path);t=t.concat(e)}const i=t.filter(e=>e.endsWith(".wxml")),s=t.filter(e=>e.endsWith(".wxs")),o=await this.getCodeByFileList(miniProgram,i.concat(s));return{wxmlFiles:i,wxsFiles:s,content:i.concat(s).reduce((e,t)=>{const i=o[t];if(!i)throw`lack of ${t} code`;if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async getPackageWxssFileList(e){let t=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path);if(e!==config_1.MainPkg&&e!==config_1.FullPkg){const e=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path);t=t.concat(e)}return t.filter(e=>e.endsWith(".wxss"))}async getPackageWxssFiles(e){const t=await this.getPackageWxssFileList(e),i=await this.getCodeByFileList(miniProgram,t);return{wxssFiles:t,content:t.reduce((e,t)=>{const s=i[t];if(!s)throw`lack of ${t} code`;if("error"in s)throw s.error;return e[t]=s.code,e["./"+t]=s.code,e},{})}}getWxssMap(e,t){t=(0,tools_1.normalizePath)(t);for(const[i,s]of this.codeCache.entries())if(i.startsWith("getCode-"+e)){const e=s.codeFiles[t];if(e&&!("error"in e))return e.map}}async getMainPkgSortedJSFiles(){const e=await this.getConf(miniProgram),t=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),i=[],s=[],o=[],r=[],a=[];let n=!1;const c={},l=t=>Object.keys(e.packages).find(e=>t.startsWith(e))||config_1.MainPkg;e.app.functionalPages&&t.forEach(e=>{if(e.startsWith("functional-pages/")){const t=e.replace(/\.js$/,"");if(c[t])return;c[t]=!0,a.push(encodeURI(t))}}),e.app.workers&&t.forEach(t=>{if(t.startsWith((0,tools_1.getWorkersPath)(e.app.workers))){const e=t.replace(/\.js$/,"");if(c[e])return;c[e]=!0,r.push(e)}});Object.keys(e.comps).filter(e=>l(e)===config_1.MainPkg).forEach(t=>{if((t.startsWith("miniprogram_npm/weui-miniprogram")||t.startsWith("weui-miniprogram"))&&e.app.useExtendedLib&&e.app.useExtendedLib.weui)return;if(c[t])return;c[t]=!0;const i=encodeURI(t);o.push(""+i)});Object.keys(e.pages).filter(e=>l(e)===config_1.MainPkg).forEach(e=>{if(c[e])return;c[e]=!0;const t=encodeURI(e);i.push(""+t)}),t.forEach(e=>{const t=e.replace(/\.js$/,"");c[t]||(c[t]=!0,"app.js"!==e?s.push(""+encodeURI(t)):n=!0)});const g=[...s,...o,...i];return n&&g.push("app"),{hasAppJS:n,allFiles:g,pageFiles:i,componentFiles:o,workerFiles:r,functionalPageFiles:a,otherFiles:s}}async getSubPkgSortedJSFiles(e){const t=await this.getConf(miniProgram),i=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path).filter(e=>e.endsWith(".js")),s=[],o=[],r=[],a={},n=e=>Object.keys(t.packages).find(t=>e.startsWith(t))||config_1.MainPkg;Object.keys(t.comps).filter(t=>n(t)===e).forEach(e=>{if((e.startsWith("miniprogram_npm/weui-miniprogram")||e.startsWith("weui-miniprogram"))&&t.app.useExtendedLib&&t.app.useExtendedLib.weui)return;if(a[e])return;a[e]=!0;const i=encodeURI(e);r.push(""+i)});Object.keys(t.pages).filter(t=>n(t)===e).forEach(e=>{if(a[e])return;a[e]=!0;const t=encodeURI(e);s.push(""+t)});let c=t.packages[e].entry||"";c&&(c=path_1.default.join(e,c),c=c.replace(/\.js$/,"")),i.forEach(e=>{const t=e.replace(/\.js$/,"");a[t]||(a[t]=!0,t!==c&&o.push(""+encodeURI(t)))});const l=i.map(e=>""+encodeURI(e.replace(/\.js$/,"")));return{entryJS:c,allFiles:l,pageFiles:s,componentFiles:r,otherFiles:o}}async compileJSList(e){const t=this.project.type;let i=config_1.COMPILE_TYPE.miniProgram;i=e.root===this.project.miniprogramRoot?this.isGameType(t)?config_1.COMPILE_TYPE.miniGame:config_1.COMPILE_TYPE.miniProgram:this.isGameType(t)?config_1.COMPILE_TYPE.miniGamePlugin:miniProgramPlugin;const s=await this.getCodeByFileList(i,e.fileList),o=[];for(const e in s){const t=s[e];if("error"in t)throw t.error;o.push(Object.assign({filePath:e,code:t.code,map:t.map},t.jsTag))}return o}async compileJS(e){const t=this.project.type;let i;if(e.root===this.project.miniprogramRoot){i=(await this.getCodeByFileList(this.isGameType(t)?config_1.COMPILE_TYPE.miniGame:config_1.COMPILE_TYPE.miniProgram,[e.filePath]))[e.filePath]}else{i=(await this.getCodeByFileList(this.isGameType(t)?config_1.COMPILE_TYPE.miniGamePlugin:miniProgramPlugin,[e.filePath]))[e.filePath]}if(!i){const t=new Error(`summer-compiler miss ${e.root} js file, ${e.filePath}`);throw t.code="ENOENT",t}if("error"in i)throw i.error;return Object.assign({filePath:e.filePath,code:i.code,map:i.map},i.jsTag)}async compile(e){Date.now();const t=(await this.getPackageFiles(this.isGameType(this.project.type)?miniGame:miniProgram,config_1.FullPkg,e.resultType,e.useCache)).map(e=>e.path),i=await this.subProcessManager.runTask("compileNewLogic",Object.assign(Object.assign({},e),{fileList:t}),this.onProgressUpdate),s=i.app,o=Object.keys(s).filter(e=>e.endsWith(".json"));this.onProgressUpdate(111,"doing","打包资源文件");const r=await this.compileOther(this.isGameType(this.project.type)?miniGame:miniProgram,e.resultType||"prod",o);let a={};if(this.isPluginType(this.project.type)){const t=i.plugin,o=Object.keys(t).filter(e=>e.endsWith(".json")),n=await this.compileOther(this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin,e.resultType||"prod",o);Object.keys(r).forEach(e=>{a[path_1.default.posix.join("miniprogram",e)]=r[e]}),Object.keys(n).forEach(e=>{a[path_1.default.posix.join("plugin",e)]=n[e]}),Object.keys(s).forEach(e=>{a[path_1.default.posix.join("miniprogram",e)]=s[e]}),Object.keys(t).forEach(e=>{a[path_1.default.posix.join("plugin",e)]=t[e]}),a["project.config.json"]=JSON.stringify({miniprogramRoot:"miniprogram",pluginRoot:"plugin",__compileDebugInfo__:{useSummer:!0}})}else a=Object.assign(Object.assign({},r),s),a["project.config.json"]=JSON.stringify({miniprogramRoot:"",__compileDebugInfo__:{useSummer:!0}});this.onProgressUpdate(111,"done","打包资源文件完成");for(const e of Object.keys(a))"object"==typeof a[e]&&"Buffer"===a[e].type&&(a[e]=Buffer.from(a[e].data));return a}async compileOther(e,t,i){const s=(0,tools_1.getSupportCodeFileExtSet)(this.project);s.delete(".json");const o=await(0,white_ext_list_1.getWhiteExtList)();let r=o.MiniProgramWhiteList;this.isGameType(this.project.type)&&(r=o.GameWhiteList);const a=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,n=await this.filterFactory(t),c=this.project.getFileList(a,"").filter(t=>{const o=path_1.default.posix.extname(t),c=path_1.default.posix.relative(a,t);return!(!r.has(o)||s.has(o)||i.includes(c))&&n(e,t)===config_1.EFilterCode.Include}),l=await(0,common_1.compileOther)(this.project,c,{onProgressUpdate:()=>{}}),g={};for(const e in l){g[path_1.default.posix.relative(a,e)]=l[e]}return g}async compile2(e){const t=await this.subProcessManager.runTask("compile",e,(t,i,s)=>{var o;null===(o=e.onProgressUpdate)||void 0===o||o.call(e,{id:t.toString(),status:i,message:s})});for(const e of Object.keys(t))"object"==typeof t[e]&&"Buffer"===t[e].type&&(t[e]=Buffer.from(t[e].data));return t}async getPluginJSON(e=""){return(await this.getConf(this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin)).plugin}async getPluginPageJSON(e){const t=await this.getConf(miniProgramPlugin),i=t.pages[e]||t.comps[e];if(!i)throw new Error("summer-compiler 收集plugin json配置有遗漏, "+e);return i}async getPluginComponents(){const e=await this.getConf(miniProgramPlugin),t=new Set(Object.keys(e.pages).concat(Object.keys(e.comps)));return Array.from(t)}async getPluginJSFiles(){const e=this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin,t=(await this.getPackageFiles(e,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),i=await this.getCodeByFileList(e,t);return{jsFiles:t,content:t.reduce((e,t)=>{const s=i[t];if(!s)throw`lack of ${t} code`;if("error"in s)throw s.error;return e[t]=s.code,e["./"+t]=s.code,e},{})}}async getPluginWxssFiles(){const e=(await this.getPackageFiles(miniProgramPlugin,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".wxss")),t=await this.getCodeByFileList(miniProgramPlugin,e);return{wxssFiles:e,content:e.reduce((e,i)=>{const s=t[i];if(!s)throw`lack of ${i} code`;if("error"in s)throw s.error;return e[i]=s.code,e["./"+i]=s.code,e},{})}}async getPluginWxmlAndWxsFiles(){const e=(await this.getPackageFiles(miniProgramPlugin,config_1.FullPkg)).map(e=>e.path),t=e.filter(e=>e.endsWith(".wxml")),i=e.filter(e=>e.endsWith(".wxs")),s=await this.getCodeByFileList(miniProgramPlugin,t.concat(i));return{wxmlFiles:t,wxsFiles:i,content:t.concat(i).reduce((e,t)=>{const i=s[t];if(!i)throw`lack of ${t} code`;if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async checkThemeJSON(e){return(await this.getConf(miniProgram)).theme}setProxy(e){(0,request_1.setCiProxy)(e)}setLocale(e){this._locale!==e&&(this._locale=e,this.subProcessManager.runTask("setLocale",e))}async uglifyFileNames(e,t,i){return await(0,uglifyfilenames_1.uglifyFileNames)(e,t,i)}async getMPFileInfo(){return this.subProcessManager.runTask("getLocalFileList",miniProgram)}async getPluginFileInfo(){return this.subProcessManager.runTask("getLocalFileList",miniProgramPlugin)}async getCompAndPagesOfConf(){const e=await this.getConf(miniProgram);return{pages:e.pages,comps:e.comps}}async getFiltedFileListReason(e){const t=this.project.getFileList(this.project.miniprogramRoot),i=[],s=await this.filterFactory(e),o=this.isGameType(this.project.type)?miniGame:miniProgram;for(const e of t){const t=s(o,e);t!==config_1.EFilterCode.Include&&i.push({file:e,code:t})}if(this.isPluginType(this.project.type)){const e=this.project.getFileList(this.project.pluginRoot),t=this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin;for(const o of e){const e=s(t,o);e!==config_1.EFilterCode.Include&&i.push({file:o,code:e})}}return i}}exports.SummerCompiler=SummerCompiler;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SummerCompiler=void 0;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),lodash_1=tslib_1.__importDefault(require("lodash")),locales_1=tslib_1.__importDefault(require("../../utils/locales/locales")),request_1=require("../../utils/request"),common_1=require("./original/compile/common"),tools_1=require("../../utils/tools"),white_ext_list_1=require("../../utils/white_ext_list"),config_1=require("../../config/config"),processManager_1=require("../../utils/subprocess/processManager"),messageHub_1=require("../../utils/messageHub"),singletontask_1=require("../../utils/singletontask"),uglifyfilenames_1=require("./original/protect/uglifyfilenames"),index_1=require("./original/index"),baseCompiler_1=require("./baseCompiler"),packOptionsHelper_1=tslib_1.__importDefault(require("../../utils/packOptionsHelper")),miniProgram=config_1.COMPILE_TYPE.miniProgram,miniGame=config_1.COMPILE_TYPE.miniGame,miniProgramPlugin=config_1.COMPILE_TYPE.miniProgramPlugin,miniGamePlugin=config_1.COMPILE_TYPE.miniGamePlugin;function performanceMark(e,t){}class SummerCompiler extends baseCompiler_1.BaseCoreCompiler{constructor(e,t,i,s,o,r){super(e),this.project=e,this.cachePath=t,this.projectInfo=i,this.devtoolMessagehub=s,this.analyzer=o,this._filterFactory=r,this.isSummer=!0,this.promiseCache=new Map,this._taskCache=new Map,this._status=void 0,this._eventAdded=!1,this._locale="",this.devCodeCacheByPath=new Map,this.onFileChange=(e,t)=>{if("change"!==e||t.endsWith(".json"))for(const e of this.promiseCache.keys())e.startsWith("getConf-")&&this.promiseCache.delete(e);if("change"!==e){for(const e of this.promiseCache.keys())e.startsWith("getPackageFiles-")&&this.promiseCache.delete(e);for(const e of this._taskCache.keys())e.startsWith("getPackageFiles-")&&this._taskCache.delete(e)}this.invalidCodeCache(t),this.subProcessManager.sendEvent("fileChange",{type:e,targetPath:t})},this.onPreCompileOptionsChange=async e=>{await this.clearCache(),this.subProcessManager.sendEvent("precompileOptionsChange",e)},this.onProgressUpdate=(e,t,i)=>{const s="warn"===t?"warn":"doing"===t?"doing":"done"===t?"success":"error";this.messageHub.showBuildLog(""+e,s,i)},this._getPackageFiles=async(e,t,i="dev")=>{performanceMark("request get getPackageFiles");const s=await this.subProcessManager.runTask("getPackageFiles",{graphId:e,root:t},this.onProgressUpdate);performanceMark("request get getPackageFiles",!0);const o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,r=await this.filterFactory(i),a={},n=s.filter(t=>{const i=path_1.default.posix.join(o,t.path),s=r(e,i);return s!==config_1.EFilterCode.Include&&(a[s]||(a[s]=[]),a[s].push(i)),s===config_1.EFilterCode.Include}),c={[config_1.EFilterCode.AnalyseNoUse]:locales_1.default.config.UNUSE_FILE_LIST,[config_1.EFilterCode.PackOptionsIgnore]:locales_1.default.config.PACK_OPTIONS_IGNORE_LIST,[config_1.EFilterCode.PartialCompileNoUse]:locales_1.default.config.PARTIAL_COMPILE_IGNORE_LIST};for(const e in a)c[e]?this.onProgressUpdate(e,"warn",c[e].format(a[e].join(","))):this.onProgressUpdate(e,"warn",locales_1.default.config.UNKNOWN_REASON_INGORE_LIST.format(e,a[e].join(",")));return n},performanceMark("create summer compiler"),this.messageHub=new messageHub_1.MessageHub(s),this.ready()}get status(){return this._status}async init(){performanceMark("init summer compiler");const e=path_1.default.posix.join(__dirname,"./summerEntryProcess.js");this.subProcessManager=new processManager_1.SubProcessProxy(this.project,e,{cachePath:this.cachePath},this.projectInfo,8891),this.addProjectListener(),this.loadStatus(),performanceMark("init summer compiler",!0)}async loadStatus(){this._status=await this.subProcessManager.runTask("loadStatus")}destroy(){var e;null===(e=this.subProcessManager)||void 0===e||e.destroy(),this.removeProjectListener(),this._checkReadyTask=void 0}async clearCache(){var e;await(null===(e=this.subProcessManager)||void 0===e?void 0:e.runTask("clearCache")),this.promiseCache.clear(),this.devCodeCacheByPath.clear(),this._taskCache.clear()}updateOptions(e){var t;lodash_1.default.isEqual(e,this.projectInfo)||(this.projectInfo=e,this.promiseCache.clear(),this.devCodeCacheByPath.clear(),null===(t=this.subProcessManager)||void 0===t||t.sendEvent("updateOptions",e),this.loadStatus(),this.project.updateOptions(e))}addProjectListener(){var e,t;this._eventAdded&&this.removeProjectListener(),null===(e=this.project.event)||void 0===e||e.on("fileChange",this.onFileChange),null===(t=this.project.event)||void 0===t||t.on("precompileOptionsChange",this.onPreCompileOptionsChange),this._eventAdded=!0}removeProjectListener(){var e,t;null===(e=this.project.event)||void 0===e||e.off("fileChange",this.onFileChange),null===(t=this.project.event)||void 0===t||t.off("precompileOptionsChange",this.onPreCompileOptionsChange),this._eventAdded=!1}invalidCodeCache(e){this.devCodeCacheByPath.delete((0,tools_1.sourcePathToTargetPath)(e))}async getConf(e){var t,i;const s="getConf-"+e;if(this.promiseCache.has(s))return(null===(t=process.env)||void 0===t?void 0:t.isDevtools)&&console.log(s,"hit cache"),this.promiseCache.get(s);(null===(i=process.env)||void 0===i?void 0:i.isDevtools)&&console.log(s,"do request"),performanceMark("request get conf");const o={graphId:e},r=this.subProcessManager.runTask("getConf",o,this.onProgressUpdate);return this.promiseCache.set(s,r),performanceMark("request get conf",!0),r}async getPackageFiles(e,t,i="dev",s=!0){const o=`getPackageFiles-${e}-${t}-${i}`;if(this._taskCache.has(o)&&s){const e=this._taskCache.get(o);return null==e?void 0:e.getResult(!0)}const r=new singletontask_1.SingletonTask(this._getPackageFiles.bind(this,e,t,i),o);return this._taskCache.set(o,r),null==r?void 0:r.getResult(!0)}async filterFactory(e){packOptionsHelper_1.default.updateState(this.project),this.onProgressUpdate("initUnusedFiles","doing","analyzing codes..."),await packOptionsHelper_1.default.initUnusedFiles(this.project,this.analyzer,"prod"===e),this.onProgressUpdate("initUnusedFiles","done","analyzing codes success");const t=this._filterFactory?await this._filterFactory(e):()=>0;return(i,s)=>"mini-android"!==this.project.targetPlatform&&"mini-ios"!==this.project.targetPlatform||path_1.default.posix.join(this.project.miniprogramRoot,"app.miniapp.json")!==s?i===miniProgram&&packOptionsHelper_1.default.isIgnoreByUnusedFiles(s,"prod"===e)?config_1.EFilterCode.AnalyseNoUse:packOptionsHelper_1.default.isIgnoredByRules(s)?config_1.EFilterCode.PackOptionsIgnore:t(i,s):config_1.EFilterCode.Include}async getCodeByFileList(e,t){const i={},s={},o=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot;for(const e of t){const t=this.devCodeCacheByPath.get(path_1.default.posix.join(o,e));t&&("error"in t||(i[e]=t.md5,s[e]=t))}const r=await this.subProcessManager.runTask("getDevCodeByFileList",{graphId:e,fileList:t,cacheMd5:i},this.onProgressUpdate);for(const e in r){const t=r[e],i=path_1.default.posix.join(o,e);"error"in t||""!==t.md5?this.devCodeCacheByPath.set(i,t):this.devCodeCacheByPath.delete(i),s[e]=t}return s}async getExtJSON(){return await(0,index_1.getExtJSON)(this.project)}async getAppJSON(){return(await this.getConf(miniProgram)).app}async getGameJSON(){return(await this.getConf(miniGame)).app}async getSiteMapJSON(){return(await this.getConf(miniProgram)).sitemap}async getPageJSON(e){const t=await this.getConf(miniProgram),i=t.pages[e]||t.comps[e];if(!i)throw new Error("summer-compiler 收集json配置有遗漏, "+e);return i}async getAllPageAndComponent(){const e=await this.getConf(miniProgram),t=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".json"));return Object.keys(e.pages).concat(Object.keys(e.comps)).filter(e=>t.includes(e+".json"))}async getAllSortedJSFiles(){const e=await this.getConf(miniProgram),t=Object.keys(e.pages),i=Object.keys(e.comps),s=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),o=t.filter(e=>!i.includes(e)).map(e=>e+".js").filter(e=>s.includes(e)),r=i.map(e=>e+".js").filter(e=>s.includes(e)),a=s.filter(e=>e.endsWith(".js")&&"app.js"!==e&&!o.includes(e)&&!r.includes(e));return{jsPagesFiles:o,components:r,otherJsFiles:a}}async getAllWxmlAndWxsFiles(){const e=(await this.getPackageFiles(miniProgram,config_1.FullPkg)).map(e=>e.path),t=e.filter(e=>e.endsWith(".wxml")),i=e.filter(e=>e.endsWith(".wxs")),s=await this.getCodeByFileList(miniProgram,t.concat(i));return{wxmlFiles:t,wxsFiles:i,content:t.concat(i).reduce((e,t)=>{const i=s[t];if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async getPackageWxmlAndWxsFiles(e){let t=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path);if(e!==config_1.MainPkg&&e!==config_1.FullPkg){const e=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path);t=t.concat(e)}const i=t.filter(e=>e.endsWith(".wxml")),s=t.filter(e=>e.endsWith(".wxs")),o=await this.getCodeByFileList(miniProgram,i.concat(s));return{wxmlFiles:i,wxsFiles:s,content:i.concat(s).reduce((e,t)=>{const i=o[t];if(!i)throw`lack of ${t} code`;if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async getPackageWxssFileList(e){let t=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path);if(e!==config_1.MainPkg&&e!==config_1.FullPkg){const e=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path);t=t.concat(e)}return t.filter(e=>e.endsWith(".wxss"))}async getPackageWxssFiles(e){const t=await this.getPackageWxssFileList(e),i=await this.getCodeByFileList(miniProgram,t);return{wxssFiles:t,content:t.reduce((e,t)=>{const s=i[t];if(!s)throw`lack of ${t} code`;if("error"in s)throw s.error;return e[t]=s.code,e["./"+t]=s.code,e},{})}}getWxssMap(e,t){t=(0,tools_1.normalizePath)(t),e===miniProgram?t=path_1.default.posix.join(this.project.miniprogramRoot,t):e===miniProgramPlugin&&(t=path_1.default.posix.join(this.project.pluginRoot,t));const i=this.devCodeCacheByPath.get(t);if(i&&!("error"in i))return i.map}async getMainPkgSortedJSFiles(){const e=await this.getConf(miniProgram),t=(await this.getPackageFiles(miniProgram,config_1.MainPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),i=[],s=[],o=[],r=[],a=[];let n=!1;const c={},l=t=>Object.keys(e.packages).find(e=>t.startsWith(e))||config_1.MainPkg;e.app.functionalPages&&t.forEach(e=>{if(e.startsWith("functional-pages/")){const t=e.replace(/\.js$/,"");if(c[t])return;c[t]=!0,a.push(encodeURI(t))}}),e.app.workers&&t.forEach(t=>{if(t.startsWith((0,tools_1.getWorkersPath)(e.app.workers))){const e=t.replace(/\.js$/,"");if(c[e])return;c[e]=!0,r.push(e)}});Object.keys(e.comps).filter(e=>l(e)===config_1.MainPkg).forEach(t=>{if((t.startsWith("miniprogram_npm/weui-miniprogram")||t.startsWith("weui-miniprogram"))&&e.app.useExtendedLib&&e.app.useExtendedLib.weui)return;if(c[t])return;c[t]=!0;const i=encodeURI(t);o.push(""+i)});Object.keys(e.pages).filter(e=>l(e)===config_1.MainPkg).forEach(e=>{if(c[e])return;c[e]=!0;const t=encodeURI(e);i.push(""+t)}),t.forEach(e=>{const t=e.replace(/\.js$/,"");c[t]||(c[t]=!0,"app.js"!==e?s.push(""+encodeURI(t)):n=!0)});const g=[...s,...o,...i];return n&&g.push("app"),{hasAppJS:n,allFiles:g,pageFiles:i,componentFiles:o,workerFiles:r,functionalPageFiles:a,otherFiles:s}}async getSubPkgSortedJSFiles(e){const t=await this.getConf(miniProgram),i=(await this.getPackageFiles(miniProgram,e)).map(e=>e.path).filter(e=>e.endsWith(".js")),s=[],o=[],r=[],a={},n=e=>Object.keys(t.packages).find(t=>e.startsWith(t))||config_1.MainPkg;Object.keys(t.comps).filter(t=>n(t)===e).forEach(e=>{if((e.startsWith("miniprogram_npm/weui-miniprogram")||e.startsWith("weui-miniprogram"))&&t.app.useExtendedLib&&t.app.useExtendedLib.weui)return;if(a[e])return;a[e]=!0;const i=encodeURI(e);r.push(""+i)});Object.keys(t.pages).filter(t=>n(t)===e).forEach(e=>{if(a[e])return;a[e]=!0;const t=encodeURI(e);s.push(""+t)});let c=t.packages[e].entry||"";c&&(c=path_1.default.join(e,c),c=c.replace(/\.js$/,"")),i.forEach(e=>{const t=e.replace(/\.js$/,"");a[t]||(a[t]=!0,t!==c&&o.push(""+encodeURI(t)))});const l=i.map(e=>""+encodeURI(e.replace(/\.js$/,"")));return{entryJS:c,allFiles:l,pageFiles:s,componentFiles:r,otherFiles:o}}async compileJSList(e){const t=this.project.type;let i=config_1.COMPILE_TYPE.miniProgram;i=e.root===this.project.miniprogramRoot?this.isGameType(t)?config_1.COMPILE_TYPE.miniGame:config_1.COMPILE_TYPE.miniProgram:this.isGameType(t)?config_1.COMPILE_TYPE.miniGamePlugin:miniProgramPlugin;const s=await this.getCodeByFileList(i,e.fileList),o=[];for(const e in s){const t=s[e];if("error"in t)throw t.error;o.push(Object.assign({filePath:e,code:t.code,map:t.map},t.jsTag))}return o}async compileJS(e){const t=this.project.type;let i;if(e.root===this.project.miniprogramRoot){i=(await this.getCodeByFileList(this.isGameType(t)?config_1.COMPILE_TYPE.miniGame:config_1.COMPILE_TYPE.miniProgram,[e.filePath]))[e.filePath]}else{i=(await this.getCodeByFileList(this.isGameType(t)?config_1.COMPILE_TYPE.miniGamePlugin:miniProgramPlugin,[e.filePath]))[e.filePath]}if(!i){const t=new Error(`summer-compiler miss ${e.root} js file, ${e.filePath}`);throw t.code="ENOENT",t}if("error"in i)throw i.error;return Object.assign({filePath:e.filePath,code:i.code,map:i.map},i.jsTag)}async compile(e){Date.now();const t=(await this.getPackageFiles(this.isGameType(this.project.type)?miniGame:miniProgram,config_1.FullPkg,e.resultType,e.useCache)).map(e=>e.path),i=await this.subProcessManager.runTask("compileNewLogic",Object.assign(Object.assign({},e),{fileList:t,analyzer:void 0}),this.onProgressUpdate),s=i.app,o=Object.keys(s).filter(e=>e.endsWith(".json"));this.onProgressUpdate(111,"doing","打包资源文件");const r=await this.compileOther(this.isGameType(this.project.type)?miniGame:miniProgram,e.resultType||"prod",o);let a={};if(this.isPluginType(this.project.type)){const t=i.plugin,o=Object.keys(t).filter(e=>e.endsWith(".json")),n=await this.compileOther(this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin,e.resultType||"prod",o);Object.keys(r).forEach(e=>{a[path_1.default.posix.join("miniprogram",e)]=r[e]}),Object.keys(n).forEach(e=>{a[path_1.default.posix.join("plugin",e)]=n[e]}),Object.keys(s).forEach(e=>{a[path_1.default.posix.join("miniprogram",e)]=s[e]}),Object.keys(t).forEach(e=>{a[path_1.default.posix.join("plugin",e)]=t[e]}),a["project.config.json"]=JSON.stringify({miniprogramRoot:"miniprogram",pluginRoot:"plugin",__compileDebugInfo__:{useSummer:!0}})}else a=Object.assign(Object.assign({},r),s),a["project.config.json"]=JSON.stringify({miniprogramRoot:"",__compileDebugInfo__:{useSummer:!0}});this.onProgressUpdate(111,"done","打包资源文件完成");for(const e of Object.keys(a))"object"==typeof a[e]&&"Buffer"===a[e].type&&(a[e]=Buffer.from(a[e].data));return a}async compileOther(e,t,i){const s=(0,tools_1.getSupportCodeFileExtSet)(this.project);s.delete(".json");const o=await(0,white_ext_list_1.getWhiteExtList)();let r=o.MiniProgramWhiteList;this.isGameType(this.project.type)&&(r=o.GameWhiteList);const a=this.isPluginType(e)?this.project.pluginRoot:this.project.miniprogramRoot,n=await this.filterFactory(t),c=this.project.getFileList(a,"").filter(t=>{const o=path_1.default.posix.extname(t),c=path_1.default.posix.relative(a,t);return!(!r.has(o)||s.has(o)||i.includes(c))&&n(e,t)===config_1.EFilterCode.Include}),l=await(0,common_1.compileOther)(this.project,c,{onProgressUpdate:()=>{}}),g={};for(const e in l){g[path_1.default.posix.relative(a,e)]=l[e]}return g}async compile2(e){const t=await this.subProcessManager.runTask("compile",e,(t,i,s)=>{var o;null===(o=e.onProgressUpdate)||void 0===o||o.call(e,{id:t.toString(),status:i,message:s})});for(const e of Object.keys(t))"object"==typeof t[e]&&"Buffer"===t[e].type&&(t[e]=Buffer.from(t[e].data));return t}async getPluginJSON(e=""){return(await this.getConf(this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin)).plugin}async getPluginPageJSON(e){const t=await this.getConf(miniProgramPlugin),i=t.pages[e]||t.comps[e];if(!i)throw new Error("summer-compiler 收集plugin json配置有遗漏, "+e);return i}async getPluginComponents(){const e=await this.getConf(miniProgramPlugin),t=new Set(Object.keys(e.pages).concat(Object.keys(e.comps)));return Array.from(t)}async getPluginJSFiles(){const e=this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin,t=(await this.getPackageFiles(e,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".js")),i=await this.getCodeByFileList(e,t);return{jsFiles:t,content:t.reduce((e,t)=>{const s=i[t];if(!s)throw`lack of ${t} code`;if("error"in s)throw s.error;return e[t]=s.code,e["./"+t]=s.code,e},{})}}async getPluginWxssFiles(){const e=(await this.getPackageFiles(miniProgramPlugin,config_1.FullPkg)).map(e=>e.path).filter(e=>e.endsWith(".wxss")),t=await this.getCodeByFileList(miniProgramPlugin,e);return{wxssFiles:e,content:e.reduce((e,i)=>{const s=t[i];if(!s)throw`lack of ${i} code`;if("error"in s)throw s.error;return e[i]=s.code,e["./"+i]=s.code,e},{})}}async getPluginWxmlAndWxsFiles(){const e=(await this.getPackageFiles(miniProgramPlugin,config_1.FullPkg)).map(e=>e.path),t=e.filter(e=>e.endsWith(".wxml")),i=e.filter(e=>e.endsWith(".wxs")),s=await this.getCodeByFileList(miniProgramPlugin,t.concat(i));return{wxmlFiles:t,wxsFiles:i,content:t.concat(i).reduce((e,t)=>{const i=s[t];if(!i)throw`lack of ${t} code`;if("error"in i)throw i.error;return e[t]=i.code,e["./"+t]=i.code,e},{})}}async checkThemeJSON(e){return(await this.getConf(miniProgram)).theme}setProxy(e){(0,request_1.setCiProxy)(e)}setLocale(e){this._locale!==e&&(this._locale=e,this.subProcessManager.runTask("setLocale",e))}async uglifyFileNames(e,t,i){return await(0,uglifyfilenames_1.uglifyFileNames)(e,t,i)}async getMPFileInfo(){return this.subProcessManager.runTask("getLocalFileList",miniProgram)}async getPluginFileInfo(){return this.subProcessManager.runTask("getLocalFileList",miniProgramPlugin)}async getCompAndPagesOfConf(){const e=await this.getConf(miniProgram);return{pages:e.pages,comps:e.comps}}async getFiltedFileListReason(e){const t=this.project.getFileList(this.project.miniprogramRoot),i=[],s=await this.filterFactory(e),o=this.isGameType(this.project.type)?miniGame:miniProgram;for(const e of t){const t=s(o,e);t!==config_1.EFilterCode.Include&&i.push({file:e,code:t})}if(this.isPluginType(this.project.type)){const e=this.project.getFileList(this.project.pluginRoot),t=this.isGameType(this.project.type)?miniGamePlugin:miniProgramPlugin;for(const o of e){const e=s(t,o);e!==config_1.EFilterCode.Include&&i.push({file:o,code:e})}}return i}}exports.SummerCompiler=SummerCompiler;
|