commit dbc6115f02446ea7ae4b9f62c89b1072b7acf433 Author: msojocs Date: Mon May 2 22:15:34 2022 +0800 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13d38fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.bin + +node_modules \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dceb788 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# 微信小程序编译器 + + diff --git a/generatemd5.js b/generatemd5.js new file mode 100644 index 0000000..c1b55f1 --- /dev/null +++ b/generatemd5.js @@ -0,0 +1,85 @@ +const path = require('path') +const fs = require('fs') +const crypto = require('crypto') +const os = require('os') +const child_process = require('child_process') +let platform = process.argv[2] + +let exeList = [] +const macExeList = [ + 'wcc', + 'wcsc', + 'wcc.bin', + 'wcsc.bin' +] +const winExeList = [ + 'wcc.exe', + 'wcsc.exe' +] +if(platform === 'darwin') { + exeList = macExeList; +} else if(platform === 'win32') { + exeList= winExeList; +} else { + exeList = macExeList.concat(winExeList) +} + + + +function generate(vendorPath) { + let dirList = fs.readdirSync(vendorPath) + + let libs = {} + dirList.forEach((item) => { + if (item == 'dev' || item == 'quickstart' || item == 'beta') { + return + } + + let itemPath = path.join(vendorPath, item) + let stat = fs.statSync(itemPath) + if (stat.isDirectory()) { + let fileList = fs.readdirSync(itemPath) + + let md5Info = {} + fileList.forEach((file) => { + if (fs.statSync(path.join(itemPath, file)).isFile()) { + let fileData = fs.readFileSync(path.join(itemPath, file)) + let md5sum = crypto.createHash('md5') + md5sum.update(fileData) + md5Info[file] = md5sum.digest('hex') + } + }) + + libs[item] = md5Info + } + }) + + let oldConfig = JSON.parse(fs.readFileSync(path.join(vendorPath, 'config.json'), 'utf8')) + for (var key in oldConfig.libs) { + // libs[key] = Object.assign({}, oldConfig.libs[key], libs[key]) + oldConfig.libs[key] = Object.assign({}, oldConfig.libs[key], libs[key]) + } + + // let newLib = {} + // let keys = Object.keys(libs) + // keys.sort() + // for (var i = 0; i < keys.length; i++) { + // let key = keys[i] + // newLib[key] = libs[key] + // } + + // 更新 + oldConfig.configVersion = Date.now() + + for (let key in exeList) { + let file = exeList[key] + let fileData = fs.readFileSync(path.join(vendorPath, file)) + let md5sum = crypto.createHash('md5') + md5sum.update(fileData) + oldConfig[file] = md5sum.digest('hex') + } + + fs.writeFileSync(path.join(vendorPath, 'config.json'), JSON.stringify(oldConfig, null, '\t')) +} + +generate(__dirname) diff --git a/nodejs/wcc b/nodejs/wcc new file mode 100755 index 0000000..634ee9d --- /dev/null +++ b/nodejs/wcc @@ -0,0 +1,599 @@ +#!/usr/bin/env node +// wcc.exe md5 = "33807bac814b4b639d98be3270bdc56c" +const version = "20220426"; +const { spawn } = require("child_process"); +const path = require("path"); +const fs = require("fs"); +const args = process.argv.slice(2); +const funcName = args[args.indexOf("-gn") + 1]; +const debugWXS = args.includes("-ds"); +let hasDeps = false; +const wccPath = path.resolve(__dirname, "./wcc.bin"); +const DEBUG_OUTPUT = process.env["WX_DEBUG_COMPILER_OUTPUT"]; +const COMMON_PREFIX = + "var __wxAppData=__wxAppData||{};var __wxAppCode__=__wxAppCode__||{};var global=global||{};var __WXML_GLOBAL__=__WXML_GLOBAL__||{entrys:{},defines:{},modules:{},ops:[],wxs_nf_init:undefined,total_ops:0};var Component=Component||function(){};var definePlugin=definePlugin||function(){};var requirePlugin=requirePlugin||function(){};var Behavior=Behavior||function(){};var __vd_version_info__=__vd_version_info__||{};var __GWX_GLOBAL__=__GWX_GLOBAL__||{};var __globalThis=(typeof __vd_version_info__!=='undefined'&&typeof __vd_version_info__.globalThis!=='undefined')?__vd_version_info__.globalThis:(typeof window!=='undefined'?window:globalThis);if(this&&this.__g===undefined)Object.defineProperty(this,\u0022__g\u0022,{configurable:false,enumerable:false,writable:false,value:function(){function D(e,t){if(typeof t!=\u0022undefined\u0022)e.children.push(t)}function S(e){if(typeof e!=\u0022undefined\u0022)return{tag:\u0022virtual\u0022,wxKey:e,children:[]};return{tag:\u0022virtual\u0022,children:[]}}function v(e){$gwxc++;if($gwxc>=16e3){throw\u0022Dom limit exceeded, please check if there's any mistake you've made.\u0022}return{tag:\u0022wx-\u0022+e,attr:{},children:[],n:[],raw:{},generics:{}}}function e(e,t){t&&e.properities.push(t)}function t(e,t,r){return typeof e[r]!=\u0022undefined\u0022?e[r]:t[r]}function u(e){console.warn(\u0022WXMLRT_\u0022+g+\u0022:\u0022+e)}function r(e,t){u(t+\u0022:-1:-1:-1: Template `\u0022+e+\u0022` is being called recursively, will be stop.\u0022)}var s=console.warn;var n=console.log;function o(){function e(){}e.prototype={hn:function(e,t){if(typeof e==\u0022object\u0022){var r=0;var n=false,o=false;for(var a in e){n=n|a===\u0022__value__\u0022;o=o|a===\u0022__wxspec__\u0022;r++;if(r>2)break}return r==2&&n&&o&&(t||e.__wxspec__!==\u0022m\u0022||this.hn(e.__value__)===\u0022h\u0022)?\u0022h\u0022:\u0022n\u0022}return\u0022n\u0022},nh:function(e,t){return{__value__:e,__wxspec__:t?t:true}},rv:function(e){return this.hn(e,true)===\u0022n\u0022?e:this.rv(e.__value__)},hm:function(e){if(typeof e==\u0022object\u0022){var t=0;var r=false,n=false;for(var o in e){r=r|o===\u0022__value__\u0022;n=n|o===\u0022__wxspec__\u0022;t++;if(t>2)break}return t==2&&r&&n&&(e.__wxspec__===\u0022m\u0022||this.hm(e.__value__))}return false}};return new e}var A=o();function T(e){var t=e.split(\u0022\u005cn \u0022+\u0022 \u0022+\u0022 \u0022+\u0022 \u0022);for(var r=0;r=\u0022:case\u0022<=\u0022:case\u0022>\u0022:case\u0022<\u0022:case\u0022<<\u0022:case\u0022>>\u0022:p=x(e[1],t,r,n,o,a);u=x(e[2],t,r,n,o,a);l=M&&(A.hn(p)===\u0022h\u0022||A.hn(u)===\u0022h\u0022);switch(i){case\u0022+\u0022:f=A.rv(p)+A.rv(u);break;case\u0022*\u0022:f=A.rv(p)*A.rv(u);break;case\u0022/\u0022:f=A.rv(p)/A.rv(u);break;case\u0022%\u0022:f=A.rv(p)%A.rv(u);break;case\u0022|\u0022:f=A.rv(p)|A.rv(u);break;case\u0022^\u0022:f=A.rv(p)^A.rv(u);break;case\u0022&\u0022:f=A.rv(p)&A.rv(u);break;case\u0022===\u0022:f=A.rv(p)===A.rv(u);break;case\u0022==\u0022:f=A.rv(p)==A.rv(u);break;case\u0022!=\u0022:f=A.rv(p)!=A.rv(u);break;case\u0022!==\u0022:f=A.rv(p)!==A.rv(u);break;case\u0022>=\u0022:f=A.rv(p)>=A.rv(u);break;case\u0022<=\u0022:f=A.rv(p)<=A.rv(u);break;case\u0022>\u0022:f=A.rv(p)>A.rv(u);break;case\u0022<\u0022:f=A.rv(p)>\u0022:f=A.rv(p)>>A.rv(u);break;default:break}return l?A.nh(f,\u0022c\u0022):f;break;case\u0022-\u0022:p=e.length===3?x(e[1],t,r,n,o,a):0;u=e.length===3?x(e[2],t,r,n,o,a):x(e[1],t,r,n,o,a);l=M&&(A.hn(p)===\u0022h\u0022||A.hn(u)===\u0022h\u0022);f=l?A.rv(p)-A.rv(u):p-u;return l?A.nh(f,\u0022c\u0022):f;break;case\u0022!\u0022:p=x(e[1],t,r,n,o,a);l=M&&A.hn(p)==\u0022h\u0022;f=!A.rv(p);return l?A.nh(f,\u0022c\u0022):f;case\u0022~\u0022:p=x(e[1],t,r,n,o,a);l=M&&A.hn(p)==\u0022h\u0022;f=~A.rv(p);return l?A.nh(f,\u0022c\u0022):f;default:s(\u0022unrecognized op\u0022+i)}}function x(e,t,r,n,o,a){var i=e[0];var p=false;if(typeof a!==\u0022undefined\u0022)o.ap=a;if(typeof i===\u0022object\u0022){var u=i[0];var l,f,v,c,s,y,b,d,h,_,g;switch(u){case 2:return m(e,t,r,n,o);break;case 4:return x(e[1],t,r,n,o,p);break;case 5:switch(e.length){case 2:l=x(e[1],t,r,n,o,p);return M?[l]:[A.rv(l)];return[l];break;case 1:return[];break;default:l=x(e[1],t,r,n,o,p);v=x(e[2],t,r,n,o,p);l.push(M?v:A.rv(v));return l;break}break;case 6:l=x(e[1],t,r,n,o);var w=o.ap;h=A.hn(l)===\u0022h\u0022;f=h?A.rv(l):l;o.is_affected|=h;if(M){if(f===null||typeof f===\u0022undefined\u0022){return h?A.nh(undefined,\u0022e\u0022):undefined}v=x(e[2],t,r,n,o,p);_=A.hn(v)===\u0022h\u0022;c=_?A.rv(v):v;o.ap=w;o.is_affected|=_;if(c===null||typeof c===\u0022undefined\u0022||c===\u0022__proto__\u0022||c===\u0022prototype\u0022||c===\u0022caller\u0022){return h||_?A.nh(undefined,\u0022e\u0022):undefined}y=f[c];if(typeof y===\u0022function\u0022&&!w)y=undefined;g=A.hn(y)===\u0022h\u0022;o.is_affected|=g;return h||_?g?y:A.nh(y,\u0022e\u0022):y}else{if(f===null||typeof f===\u0022undefined\u0022){return undefined}v=x(e[2],t,r,n,o,p);_=A.hn(v)===\u0022h\u0022;c=_?A.rv(v):v;o.ap=w;o.is_affected|=_;if(c===null||typeof c===\u0022undefined\u0022||c===\u0022__proto__\u0022||c===\u0022prototype\u0022||c===\u0022caller\u0022){return undefined}y=f[c];if(typeof y===\u0022function\u0022&&!w)y=undefined;g=A.hn(y)===\u0022h\u0022;o.is_affected|=g;return g?A.rv(y):y}case 7:switch(e[1][0]){case 11:o.is_affected|=A.hn(n)===\u0022h\u0022;return n;case 3:b=A.rv(r);d=A.rv(t);v=e[1][1];if(n&&n.f&&n.f.hasOwnProperty(v)){l=n.f;o.ap=true}else{l=b&&b.hasOwnProperty(v)?r:d&&d.hasOwnProperty(v)?t:undefined}if(M){if(l){h=A.hn(l)===\u0022h\u0022;f=h?A.rv(l):l;y=f[v];g=A.hn(y)===\u0022h\u0022;o.is_affected|=h||g;y=h&&!g?A.nh(y,\u0022e\u0022):y;return y}}else{if(l){h=A.hn(l)===\u0022h\u0022;f=h?A.rv(l):l;y=f[v];g=A.hn(y)===\u0022h\u0022;o.is_affected|=h||g;return A.rv(y)}}return undefined}break;case 8:l={};l[e[1]]=x(e[2],t,r,n,o,p);return l;break;case 9:l=x(e[1],t,r,n,o,p);v=x(e[2],t,r,n,o,p);function O(e,t,r){var n,o;h=A.hn(e)===\u0022h\u0022;_=A.hn(t)===\u0022h\u0022;f=A.rv(e);c=A.rv(t);for(var a in c){if(r||!f.hasOwnProperty(a)){f[a]=M?_?A.nh(c[a],\u0022e\u0022):c[a]:A.rv(c[a])}}return e}var s=l;var j=true;if(typeof e[1][0]===\u0022object\u0022&&e[1][0][0]===10){l=v;v=s;j=false}if(typeof e[1][0]===\u0022object\u0022&&e[1][0][0]===10){var P={};return O(O(P,l,j),v,j)}else return O(l,v,j);break;case 10:l=x(e[1],t,r,n,o,p);l=M?l:A.rv(l);return l;break;case 12:var P;l=x(e[1],t,r,n,o);if(!o.ap){return M&&A.hn(l)===\u0022h\u0022?A.nh(P,\u0022f\u0022):P}var w=o.ap;v=x(e[2],t,r,n,o,p);o.ap=w;h=A.hn(l)===\u0022h\u0022;_=N(v);f=A.rv(l);c=A.rv(v);snap_bb=K(c,\u0022nv_\u0022);try{P=typeof f===\u0022function\u0022?K(f.apply(null,snap_bb)):undefined}catch(t){t.message=t.message.replace(/nv_/g,\u0022\u0022);t.stack=t.stack.substring(0,t.stack.indexOf(\u0022\u005cn\u0022,t.stack.lastIndexOf(\u0022at nv_\u0022)));t.stack=t.stack.replace(/\u005csnv_/g,\u0022 \u0022);t.stack=T(t.stack);if(n.debugInfo){t.stack+=\u0022\u005cn \u0022+\u0022 \u0022+\u0022 \u0022+\u0022 at \u0022+n.debugInfo[0]+\u0022:\u0022+n.debugInfo[1]+\u0022:\u0022+n.debugInfo[2];console.error(t)}P=undefined}return M&&(_||h)?A.nh(P,\u0022f\u0022):P}}else{if(i===3||i===1)return e[1];else if(i===11){var l=\u0022\u0022;for(var D=1;D=0;o--){if(r[e].i[o]&&n[r[e].i[o]][t])return n[r[e].i[o]][t]}for(var o=r[e].ti.length-1;o>=0;o--){var a=ne(r[e].ti[o],r,e);if(a&&n[a][t])return n[a][t]}var i=ae(r,e);for(var o=0;o=0;p--)if(r[e].j[p]){for(var a=r[r[e].j[p]].ti.length-1;a>=0;a--){var u=ne(r[r[e].j[p]].ti[a],r,e);if(u&&n[u][t]){return n[u][t]}}}}function ae(e,t){if(!t)return[];if($gaic[t]){return $gaic[t]}var r=[],n=[],o=0,a=0,i={},p={};n.push(t);p[t]=true;a++;while(o + ele.startsWith("./miniprogram_npm") || + ele.startsWith("../") || + ele.startsWith("./page") + ); + } + for (let key in pageConfig) { + if (pageConfig[key].deps.length > 0) { + for (let dep of pageConfig[key].deps) { + let index = x.indexOf(dep); + if (index < 0) { + continue; + } + // x + if (!t_x.includes(dep)) t_x.push(dep); + } + } + } + let i = 1; + for (let dep of t_x) { + if (dep.startsWith("../")) continue; + + // d_ + const d_Exp = `d_\\[x\\[${x.indexOf( + dep + )}\\]\\]={}\n[\\s\\S]*?e_\\[x\\[${x.indexOf( + dep + )}\\]\\]={f:m\\d+,j:\\[.*?\\],i:\\[.*?\\],ti:\\[(.*?)\\],ic:\\[.*?\\]}\n`; + + let m0 = source.match(new RegExp(d_Exp)); + let m0_str = m0[0]; + const depIndex = m0[1].match(/\d+/g); + if (depIndex) { + for (let index of depIndex) { + m0_str = m0_str.replace( + new RegExp(`x\\[${index}\\]`, "g"), + `x[${t_x.indexOf(x[index])}]` + ); + } + } + // process.stderr.write(dep + '=====' + x.indexOf(dep) + "-" + t_x.indexOf(dep) + '\n') + dep_d_ += + m0_str + .replace( + new RegExp(`x\\[${x.indexOf(dep)}\\]`, "g"), + `x[${t_x.indexOf(dep)}]` + ) + .replace( + new RegExp(`\\${funcName}\\_\\d+`, "g"), + `${funcName}_${i}` + ) + .replace(/m\d+/g, `m${i - 1}`) + // .replace('={f', `=e_[x[${t_x.indexOf(dep)}]]||{f`) + "\n"; + DEBUG_OUTPUT && + process.stderr.write("dep_d_: " + dep_d_ + "\n"); + let gz_name = m0_str.match(/var z=gz(.*?)\(\)/)[1]; + // process.stderr.write("get funcName - " + t[0].match(/var z=gz(.*?)\(\)/)[1] + "\n") + // gz + const exp = `function gz\\${gz_name}\\(\\)\\{[\\s\\S]*?__WXML_GLOBAL__\\.ops_cached\\.\\${gz_name}\n}`; + DEBUG_OUTPUT && + process.stderr.write("COMMON=====" + dep + "----" + exp + "\n"); + const gz = source.match(new RegExp(exp)); + dep_gz += + gz[0].replace( + new RegExp(`\\${funcName}\\_\\d+`, "g"), + `${funcName}_${i}` + ) + "\n"; + i++; + } + dep_x += t_x.length > 0 ? `'${t_x.join("','")}'` : ''; + dep_x += `];`; + return { + dep_x, + dep_gz, + dep_d_ + } +} +function genFunctionContent_LLW(wxmlName, config = {}, source, x) { + // 起始 + let content = `var cs = cs || [];\u000a${config.funcName}${FUNC_PREFIX}`; + + // cs + const cs = source.match(/var cs([\s\S]*?)function gz/); + content += + "var cs = cs || [];" + + cs[1].replace(new RegExp(`\\${funcName}`, "g"), config.funcName); + + // template 检测 模板处理位于二者之间: d_[x[index]]={} ---{template}-- var m0; x[index]中index为wxml在x数组中的索引, m0中数字为当前函数代码 + const templateReg = source.match(new RegExp(`d_\\[x\\[${x.indexOf(`./${wxmlName}.wxml`)}\\]\\]=\\{\\}\n([\\s\\S]*?)\nvar m${config.num}=`)) + if(templateReg) + DEBUG_OUTPUT && process.stderr.write(templateReg[1] + '\n------\n') + else + DEBUG_OUTPUT && process.stderr.write('无匹配\n------\n') + + // gz函数 + const exp = `function gz\\${funcName}_${ + config.num + 1 + }\\(\\)\\{[\\s\\S]*?_WXML_GLOBAL__\\.ops_cached\\.\\${funcName}_${ + config.num + 1 + }\n}`; + let gz = source.match(new RegExp(exp)); + gz = gz[0].replace( + new RegExp(`\\${funcName}\\_\\d+`, "g"), + `${config.funcName}_1` + ); + content += gz; + + // debug + let debug = source.match( + new RegExp( + `\\n__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*?\\nvar` + ) + ); + debug = debug[0] + .substring(0, debug[0].length - 3) + .replace(new RegExp(`\\${funcName}`, "g"), config.funcName); + content += debug; + + // m0 --- m{num} + content += `var x=['./${wxmlName}.wxml'`; + const m0Exp = `var m${config.num}=function\\(e,s,r,gg\\){[\\s\\S]*e_\\[x\\[(\\d+)\\]\\]={f:m${config.num},j:\\[.*?\\],i:\\[.*?\\],ti:\\[(.*?)\\],ic:\\[.*?\\]}`; + let m0 = source.match(new RegExp(m0Exp)); + let m0_str = m0[0].replace(new RegExp(`m${config.num}`, "g"), "m0"); + const cur_x = m0[1]; // cur_x与config.num不一定相同 + m0_str = m0_str.replace(new RegExp(`x\\[${cur_x}\\]`, "g"), "x[0]"); + const depIndex = m0[2].match(/\d+/g); + if (depIndex) { + let i = 1; + for (let index of depIndex) { + content += `,'${x[index]}'`; + m0_str = m0_str.replace( + new RegExp(`x\\[${index}\\]`, "g"), + `x[${i++}]` + ); + } + } + content += `];d_[x[0]]={}\u000a`; + templateReg && (content += templateReg[1].replace( + new RegExp(`\\${funcName}\\_\\d+`, "g"), + `${config.funcName}_1` + ) + '\n') + m0_str = m0_str.replace(new RegExp(`x\\[${config.num}\\]`, "g"), "x[0]"); + content += m0_str.replace( + new RegExp(`\\${funcName}\\_\\d+`, "g"), + `${config.funcName}_1` + ) + // .replace('={f', `=e_[x[0]]||{f`); + + // path + content += `\u000aif(path&&e_[path]){\u000aouterGlobal.__wxml_comp_version__=0.02\u000areturn function(env,dd,global){$gwxc=0;var root={\u0022tag\u0022:\u0022wx-page\u0022};root.children=[]\u000a;g=\u0022${config.funcName}\u0022;var main=e_[path].f\u000acs=[]\u000aif (typeof global===\u0022undefined\u0022)global={};global.f=$gdc(f_[path],\u0022\u0022,1);\u000aif(typeof(outerGlobal.__webview_engine_version__)!='undefined'&&outerGlobal.__webview_engine_version__+1e-6>=0.02+1e-6&&outerGlobal.__mergeData__)\u000a{\u000aenv=outerGlobal.__mergeData__(env,dd);\u000a}\u000atry{\u000amain(env,{},root,global);\u000a_tsd(root)\u000aif(typeof(outerGlobal.__webview_engine_version__)=='undefined'|| outerGlobal.__webview_engine_version__+1e-6<0.01+1e-6){return _ev(root);}\u000a}catch(err){\u000aconsole.log(cs, env);\u000aconsole.log(err)\u000athrow err\u000a}\u000a;g=\u0022\u0022;\u000areturn root;\u000a}\u000a}\u000a}\u000a}`; + // end + content += `(__g.a,__g.b,__g.c,__g.d,__g.e,__g.f,__g.g,__g.h,__g.i,__g.j,__g.k,__g.l,__g.m,__g.n,__g.o,__g.p,__g.q,__g.r,__g.s,__g.t,__g.u,__g.v,__g.w,__g.x,__g.y,__g.z,__g.A,__g.B,__g.C,__g.D,__g.E,__g.F,__g.G,__g.H,__g.I,__g.J,__g.K,__g.L,__g.M,__g.N,__g.O,__g.P,__g.Q,__g.R,__g.S,__g.T,__g.U,__g.V,__g.W,__g.X,__g.Y,__g.Z,__g.aa);if(__vd_version_info__.delayedGwx||false)${config.funcName}();`; + // content = content.replace(new RegExp(`\\${funcName}_${config.num+1}`, 'g'), `${config.funcName}_1`) + // console.log(content) + return content; +} +// genFunctionContent_LLW END +function genCommonContent_LLW(source, pageConfig, x = []) { + let common = + COMMON_PREFIX + + "/*v0.5vv_20200413_syb_scopedata*/__globalThis.__wcc_version__='v0.5vv_20200413_syb_scopedata';__globalThis.__wcc_version_info__={\u0022customComponents\u0022:true,\u0022fixZeroRpx\u0022:true,\u0022propValueDeepCopy\u0022:false};\u000avar $gwxc\u000avar $gaic={}\u000avar outerGlobal=typeof __globalThis==='undefined'?window:__globalThis;var cs = cs || [];\u000a" + + funcName + + "=function(_,_v,_n,_p,_s,_wp,_wl,$gwn,$gwl,$gwh,wh,$gstack,$gwrt,gra,grb,TestTest,wfor,_ca,_da,_r,_rz,_o,_oz,_1,_1z,_2,_2z,_m,_mz,nv_getDate,nv_getRegExp,nv_console,nv_parseInt,nv_parseFloat,nv_isNaN,nv_isFinite,nv_decodeURI,nv_decodeURIComponent,nv_encodeURI,nv_encodeURIComponent,$gdc,nv_JSON,_af,_gv,_ai,_grp,_gd,_gapi,$ixc,_ic,_w,_ev,_tsd){return function(path,global){\u000aif(typeof global==='undefined'){if (typeof __GWX_GLOBAL__==='undefined')global={};else global=__GWX_GLOBAL__;}if(typeof __WXML_GLOBAL__ === 'undefined') {__WXML_GLOBAL__={};\u000a}__WXML_GLOBAL__.modules = __WXML_GLOBAL__.modules || {};\u000a"; + // 函数名不是$gwx的时候,需要初始化操作 + if (funcName !== "$gwx") common += "$gwx('init', global);\u000a"; + common += + "var e_={}\u000aif(typeof(global.entrys)==='undefined')global.entrys={};e_=global.entrys;\u000avar d_={}\u000aif(typeof(global.defines)==='undefined')global.defines={};d_=global.defines;\u000avar f_={}\u000aif(typeof(global.modules)==='undefined')global.modules={};f_=global.modules || {};\u000avar p_={}\u000a"; + // cs + const cs = source.match(/var cs([\s\S]*?)function gz/); + common += "var cs = cs || [];" + cs[1]; + + const depsData = parseDeps(source, x, pageConfig) + common += depsData.dep_gz; + // nv_require + const nv_require = source.match( + new RegExp( + `(__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*)var x=\\[` + ) + ); + common += nv_require[1]; + + common += depsData.dep_x + depsData.dep_d_; + common += + "if(path&&e_[path]){\u000aouterGlobal.__wxml_comp_version__=0.02\u000areturn function(env,dd,global){$gwxc=0;var root={\u0022tag\u0022:\u0022wx-page\u0022};root.children=[]\u000a;g=\u0022" + + funcName + + "\u0022;var main=e_[path].f\u000acs=[]\u000aif (typeof global===\u0022undefined\u0022)global={};global.f=$gdc(f_[path],\u0022\u0022,1);\u000aif(typeof(outerGlobal.__webview_engine_version__)!='undefined'&&outerGlobal.__webview_engine_version__+1e-6>=0.02+1e-6&&outerGlobal.__mergeData__)\u000a{\u000aenv=outerGlobal.__mergeData__(env,dd);\u000a}\u000atry{\u000amain(env,{},root,global);\u000a_tsd(root)\u000aif(typeof(outerGlobal.__webview_engine_version__)=='undefined'|| outerGlobal.__webview_engine_version__+1e-6<0.01+1e-6){return _ev(root);}\u000a}catch(err){\u000aconsole.log(cs, env);\u000aconsole.log(err)\u000athrow err\u000a}\u000a;g=\u0022\u0022;\u000areturn root;\u000a}\u000a}\u000a}\u000a}(__g.a,__g.b,__g.c,__g.d,__g.e,__g.f,__g.g,__g.h,__g.i,__g.j,__g.k,__g.l,__g.m,__g.n,__g.o,__g.p,__g.q,__g.r,__g.s,__g.t,__g.u,__g.v,__g.w,__g.x,__g.y,__g.z,__g.A,__g.B,__g.C,__g.D,__g.E,__g.F,__g.G,__g.H,__g.I,__g.J,__g.K,__g.L,__g.M,__g.N,__g.O,__g.P,__g.Q,__g.R,__g.S,__g.T,__g.U,__g.V,__g.W,__g.X,__g.Y,__g.Z,__g.aa);if(__vd_version_info__.delayedGwx||true)" + + funcName + + "();;var __WXML_DEP__=__WXML_DEP__||{};"; + // 追加引用 + let common_end = '' + for (let key in pageConfig) { + if (pageConfig[key].deps.length > 0) { + common_end += `__WXML_DEP__["./${key}.wxml"]=["${pageConfig[ + key + ].deps.join('","')}",];`; + } + } + common += common_end + return common; +} +// genCommonContent_LLW END +function genFunctionContent_LLA(wxmlName, config = {}, source, x) { + // 起始 + let content = `var cs = cs || [];\u000a${config.funcName}${FUNC_PREFIX}`; + + // cs + const cs = source.match(/var cs([\s\S]*?)function gz/); + content += + "var cs = cs || [];" + + cs[1].replace(new RegExp(`\\${funcName}`, "g"), config.funcName); + + // template 检测 模板处理位于二者之间: d_[x[index]]={} ---{template}-- var m0; x[index]中index为wxml在x数组中的索引, m0中数字为当前函数代码 + const templateReg = source.match(new RegExp(`d_\\[x\\[${x.indexOf(`./${wxmlName}.wxml`)}\\]\\]=\\{\\}\n([\\s\\S]*?)\nvar m${config.num}=`)) + if(templateReg) + DEBUG_OUTPUT && process.stderr.write(templateReg[1] + '\n------\n') + else + DEBUG_OUTPUT && process.stderr.write('无匹配\n------\n') + + DEBUG_OUTPUT && process.stderr.write(`wxmlName: ${wxmlName} debugWXS: ${!!debugWXS}, hasDeps: ${!!hasDeps}, templateReg: ${!!templateReg}\n${JSON.stringify(x)} ${JSON.stringify(config)}\n\n`) + // gz函数 + let gz; + if (!debugWXS && !hasDeps && !templateReg) { + const exp = `function gz\\${funcName}_${ + config.num + 1 + }\\(\\)\\{[\\s\\S]*?\\)\\}`; + gz = source.match(new RegExp(exp)); + gz = + gz[0].replace( + new RegExp(`\\${funcName}\\_\\d+`, "g"), + `${config.funcName}_1` + ) + + `\u000a})(__WXML_GLOBAL__.ops_cached.${config.funcName}_1);return __WXML_GLOBAL__.ops_cached.${config.funcName}_1\u000a}`; + } else { + // gz函数2 + const exp = `function gz\\${funcName}_${ + config.num + 1 + }\\(\\)\\{[\\s\\S]*?__WXML_GLOBAL__\\.ops_cached\\.\\${funcName}_${ + config.num + 1 + }\n}`; + gz = source.match(new RegExp(exp)); + gz = gz[0].replace( + new RegExp(`\\${funcName}\\_\\d+`, "g"), + `${config.funcName}_1` + ); + } + content += gz; + + // debug + let debug = source.match( + new RegExp( + `\\n__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*?\\nvar` + ) + ); + debug = debug[0] + .substring(0, debug[0].length - 3) + .replace(new RegExp(`\\${funcName}`, "g"), config.funcName); + content += debug; + + // m0 --- m{num} + content += `var x=['./${wxmlName}.wxml'`; + if (!debugWXS && !hasDeps && !templateReg) { + content += `];d_[x[0]]={}\u000a`; + // e_[x[0]]|| + content += `var m0=function(e,s,r,gg){\u000avar z=gz${config.funcName}_1()\u000areturn r\u000a}\u000ae_[x[0]]={f:m0,j:[],i:[],ti:[],ic:[]}`; + } else { + // m0 --- m{num} + const m0Exp = `var m${config.num}=function\\(e,s,r,gg\\){[\\s\\S]*e_\\[x\\[(\\d+)\\]\\]={f:m${config.num},j:\\[.*?\\],i:\\[.*?\\],ti:\\[(.*?)\\],ic:\\[.*?\\]}`; + let m0 = source.match(new RegExp(m0Exp)); + let m0_str = m0[0].replace(new RegExp(`m${config.num}`, "g"), "m0"); + const cur_x = m0[1]; // cur_x与config.num不一定相同 + m0_str = m0_str.replace(new RegExp(`x\\[${cur_x}\\]`, "g"), "x[0]"); + const depIndex = m0[2].match(/\d+/g); + if (depIndex) { + let i = 1; + for (let index of depIndex) { + content += `,'${x[index]}'`; + m0_str = m0_str.replace( + new RegExp(`x\\[${index}\\]`, "g"), + `x[${i++}]` + ); + } + } + content += `];d_[x[0]]={}\u000a`; + templateReg && (content += templateReg[1].replace( + new RegExp(`\\${funcName}\\_\\d+`, "g"), + `${config.funcName}_1` + ) + '\n') + m0_str = m0_str.replace( + new RegExp(`x\\[${config.num}\\]`, "g"), + "x[0]" + ) + // .replace('={f', '=e_[x[0]]||{f'); + content += m0_str.replace( + new RegExp(`\\${funcName}\\_\\d+`, "g"), + `${config.funcName}_1` + ); + } + + // path + content += `\u000aif(path&&e_[path]){\u000areturn function(env,dd,global){$gwxc=0;var root={\u0022tag\u0022:\u0022wx-page\u0022};root.children=[]\u000a;g=\u0022${config.funcName}\u0022;var main=e_[path].f\u000acs=[]\u000aif (typeof global===\u0022undefined\u0022)global={};global.f=$gdc(f_[path],\u0022\u0022,1);\u000atry{\u000amain(env,{},root,global);\u000a_tsd(root)\u000a}catch(err){\u000aconsole.log(cs, env);\u000aconsole.log(err)\u000athrow err\u000a}\u000a;g=\u0022\u0022;\u000areturn root;\u000a}\u000a}\u000a}\u000a}(__g.a,__g.b,__g.c,__g.d,__g.e,__g.f,__g.g,__g.h,__g.i,__g.j,__g.k,__g.l,__g.m,__g.n,__g.o,__g.p,__g.q,__g.r,__g.s,__g.t,__g.u,__g.v,__g.w,__g.x,__g.y,__g.z,__g.A,__g.B,__g.C,__g.D,__g.E,__g.F,__g.G,__g.H,__g.I,__g.J,__g.K,__g.L,__g.M,__g.N,__g.O,__g.P,__g.Q,__g.R,__g.S,__g.T,__g.U,__g.V,__g.W,__g.X,__g.Y,__g.Z,__g.aa);if(__vd_version_info__.delayedGwx||false)${config.funcName}();`; + + // console.log(content) + return content; +} +// genFunctionContent_LLA END +function genCommonContent_LLA(source, pageConfig, x) { + let common = + COMMON_PREFIX + + "/*v0.5vv_20200413_syb_scopedata*/global.__wcc_version__='v0.5vv_20200413_syb_scopedata';global.__wcc_version_info__={\u0022customComponents\u0022:true,\u0022fixZeroRpx\u0022:true,\u0022propValueDeepCopy\u0022:false};\u000avar $gwxc\u000avar $gaic={}\u000avar cs = cs || [];\u000a" + + funcName + + "=function(_,_v,_n,_p,_s,_wp,_wl,$gwn,$gwl,$gwh,wh,$gstack,$gwrt,gra,grb,TestTest,wfor,_ca,_da,_r,_rz,_o,_oz,_1,_1z,_2,_2z,_m,_mz,nv_getDate,nv_getRegExp,nv_console,nv_parseInt,nv_parseFloat,nv_isNaN,nv_isFinite,nv_decodeURI,nv_decodeURIComponent,nv_encodeURI,nv_encodeURIComponent,$gdc,nv_JSON,_af,_gv,_ai,_grp,_gd,_gapi,$ixc,_ic,_w,_ev,_tsd){return function(path,global){\u000aif(typeof global==='undefined'){if (typeof __GWX_GLOBAL__==='undefined')global={};else global=__GWX_GLOBAL__;}if(typeof __WXML_GLOBAL__ === 'undefined') {__WXML_GLOBAL__={};\u000a}__WXML_GLOBAL__.modules = __WXML_GLOBAL__.modules || {};\u000a"; + // 函数名不是$gwx的时候,需要初始化操作 + if (funcName !== "$gwx") common += "$gwx('init', global);\u000a"; + common += + "var e_={}\u000aif(typeof(global.entrys)==='undefined')global.entrys={};e_=global.entrys;\u000avar d_={}\u000aif(typeof(global.defines)==='undefined')global.defines={};d_=global.defines;\u000avar f_={}\u000aif(typeof(global.modules)==='undefined')global.modules={};f_=global.modules || {};\u000avar p_={}\u000a"; + // cs + const cs = source.match(/var cs([\s\S]*?)function gz/); + common += "var cs = cs || [];" + cs[1]; + + const depsData = parseDeps(source, x, pageConfig) + common += depsData.dep_gz; + // nv_require + const nv_require = source.match( + new RegExp( + `(__WXML_GLOBAL__\\.ops_set\\.\\${funcName}=[\\s\\S]*)var x=\\[` + ) + ); + common += nv_require[1]; + + common += depsData.dep_x + depsData.dep_d_; + common += + "if(path&&e_[path]){\u000areturn function(env,dd,global){$gwxc=0;var root={\u0022tag\u0022:\u0022wx-page\u0022};root.children=[]\u000a;g=\u0022" + + funcName + + "\u0022;var main=e_[path].f\u000acs=[]\u000aif (typeof global===\u0022undefined\u0022)global={};global.f=$gdc(f_[path],\u0022\u0022,1);\u000atry{\u000amain(env,{},root,global);\u000a_tsd(root)\u000a}catch(err){\u000aconsole.log(cs, env);\u000aconsole.log(err)\u000athrow err\u000a}\u000a;g=\u0022\u0022;\u000areturn root;\u000a}\u000a}\u000a}\u000a}(__g.a,__g.b,__g.c,__g.d,__g.e,__g.f,__g.g,__g.h,__g.i,__g.j,__g.k,__g.l,__g.m,__g.n,__g.o,__g.p,__g.q,__g.r,__g.s,__g.t,__g.u,__g.v,__g.w,__g.x,__g.y,__g.z,__g.A,__g.B,__g.C,__g.D,__g.E,__g.F,__g.G,__g.H,__g.I,__g.J,__g.K,__g.L,__g.M,__g.N,__g.O,__g.P,__g.Q,__g.R,__g.S,__g.T,__g.U,__g.V,__g.W,__g.X,__g.Y,__g.Z,__g.aa);if(__vd_version_info__.delayedGwx||true)" + + funcName + + "();;var __WXML_DEP__=__WXML_DEP__||{};"; + // 追加引用 + let common_end = '' + for (let key in pageConfig) { + if (pageConfig[key].deps.length > 0) { + common_end += `__WXML_DEP__["./${key}.wxml"]=["${pageConfig[ + key + ].deps.join('","')}",];`; + } + } + common += common_end + return common; +} +// genCommonContent_LLA END +if (args.includes("-llw")) { + const argss = args.filter((e) => e != "-llw"); + const wcc = spawn(wccPath, argss, { + cwd: process.cwd(), + }); + const spwanData = [], + errData = []; + wcc.stdout.on("data", (e) => { + spwanData.push(e); + }); + wcc.stderr.on("data", (e) => { + errData.push(e); + }); + wcc.on("close", (n) => { + if (0 === n) { + const str = Buffer.concat(spwanData).toString(); + // 获取Linux wcc的输出数据,用于分析 + DEBUG_OUTPUT && + fs.writeFileSync(`${DEBUG_OUTPUT}/linux_output.js`, str); + const resultObj = { + generateFunctionContent: { + __COMMON__: null, + }, + generateFunctionName: { + __COMMON__: funcName, + }, + }; + // 取分割符 + const split_mark = argss[argss.indexOf("--split") + 1]; + // ./miniprogram_npm/miniprogram-barrage/index>_<4685./m + const needArr = argss + .filter( + (arg) => arg.includes(split_mark) && arg.startsWith("./") + )[0] + .split(split_mark); + // 获取x数组并解析 + const indexArr = eval(str.match(/var x=(\[.*\]);/)[1]); + const pageConfig = {}; + let i = 0; + indexArr.forEach((ele, index) => { + // 非 ../ 开头 + if (!ele.startsWith("../")) { + // a/b/c -> {} + pageConfig[ele.substring(2, ele.length - 5)] = { + funcName: `${funcName}_XC_${i}`, + num: i, + deps: [], + }; + i++; + } + }); + // 获取所有依赖 _ai函数 被引入的文件, 文件 + const deps = str.matchAll( + /_ai\(.*?,x\[(\d+)\],.*?,x\[(\d+)\],\d+,\d+\)/g + ); + // 处理依赖 + for (let dep of deps) { + const target = indexArr[dep[2]]; + pageConfig[target.substring(2, target.length - 5)].deps.unshift( + "./" + path.join(path.dirname(target), indexArr[dep[1]]) + ); + } + // 生成函数内容 + for (let key in pageConfig) { + if (needArr.includes(`./${key}`)) { + resultObj.generateFunctionName[key] = + pageConfig[key].funcName; + resultObj.generateFunctionContent[key] = + genFunctionContent_LLW( + key, + pageConfig[key], + str, + indexArr + ); + } + } + // 生成common + resultObj.generateFunctionContent.__COMMON__ = genCommonContent_LLW( + str, + pageConfig, + indexArr + ); + + let result = JSON.stringify(resultObj); + result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) { + let c; + switch ($0) { + case "\\n": + c = "\n"; + break; + case "\\t": + c = "\t"; + break; + + default: + c = $0[1]; + break; + } + return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0"); + }); + process.stdout.write(result); + } else { + const err = Buffer.concat(errData).toString(); + process.stderr.write(err); + DEBUG_OUTPUT && + fs.writeFileSync(`${DEBUG_OUTPUT}/linux_err.js`, err); + process.exitCode = n; + } + }); +} else if (args.includes("-lla")) { + const argss = args.filter((e) => e != "-lla"); + const wcc = spawn(wccPath, argss, { + cwd: process.cwd(), + }); + const spwanData = [], + errData = []; + wcc.stdout.on("data", (e) => { + spwanData.push(e); + }); + wcc.stderr.on("data", (e) => { + errData.push(e); + }); + wcc.on("close", (n) => { + if (0 === n) { + let str = Buffer.concat(spwanData).toString(); + // 获取Linux wcc的输出数据,用于分析 + DEBUG_OUTPUT && + fs.writeFileSync(`${DEBUG_OUTPUT}/linux_output.js`, str); + const resultObj = { + generateFunctionContent: { + __COMMON__: null, + }, + generateFunctionName: { + __COMMON__: funcName, + }, + }; + const split_mark = argss[argss.indexOf("--split") + 1]; + const needArr = argss + .filter( + (arg) => arg.includes(split_mark) && arg.startsWith("./") + )[0] + .split(split_mark); + const indexArr = eval(str.match(/var x=(\[.*\]);/)[1]); + const pageConfig = {}; + let i = 0; + indexArr.forEach((ele, index) => { + if (!ele.startsWith("../")) { + pageConfig[ele.substring(2, ele.length - 5)] = { + funcName: `${funcName}_XC_${i}`, + num: i, + deps: [], + }; + i++; + } + }); + // 引入解析 + const deps = str.matchAll( + /_ai\(.*?,x\[(\d+)\],.*?,x\[(\d+)\],\d+,\d+\)/g + ); + for (let dep of deps) { + hasDeps = true; + // console.log(dep[1]) // 被引用文件下标 + // console.log(dep[2]) // 引用文件下标 + const target = indexArr[dep[2]]; + pageConfig[target.substring(2, target.length - 5)].deps.unshift( + "./" + path.join(path.dirname(target), indexArr[dep[1]]) + ); + } + for (let key in pageConfig) { + if (needArr.includes("./" + key)) { + resultObj.generateFunctionName[key] = + pageConfig[key].funcName; + resultObj.generateFunctionContent[key] = + genFunctionContent_LLA( + key, + pageConfig[key], + str, + indexArr + ); + } + } + + resultObj.generateFunctionContent.__COMMON__ = genCommonContent_LLA( + str, + pageConfig, + indexArr + ); + + let result = JSON.stringify(resultObj); + result = result.replace(/\\[\s\S]{1}/gi, function ($0, $1, $2) { + let c; + switch ($0) { + case "\\n": + c = "\n"; + break; + case "\\t": + c = "\t"; + break; + + default: + c = $0[1]; + break; + } + return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0"); + }); + + process.stdout.write(result); + } else { + const err = Buffer.concat(errData).toString(); + process.stderr.write(err); + DEBUG_OUTPUT && + fs.writeFileSync(`${DEBUG_OUTPUT}/linux_err.js`, err); + process.exitCode = n; + } + }); +} else { + const wcc = spawn(wccPath, args, { + cwd: process.cwd(), + stdio: "inherit", + }); + wcc.on("close", (code) => { + process.exitCode = code; + }); +} diff --git a/nodejs/wcsc b/nodejs/wcsc new file mode 100755 index 0000000..38a46ee --- /dev/null +++ b/nodejs/wcsc @@ -0,0 +1,81 @@ +#!/usr/bin/env node +// wcsc.exe md5 = "d45f45f109afa238cd83c8ad1d0e2a5e" +const version = "20220423"; +const { spawn } = require("child_process"); +const fs = require("fs"); +const path = require("path"); +const args = process.argv.slice(2); +const wcscPath = path.resolve(__dirname, "./wcsc.bin"); +const DEBUG_OUTPUT = process.env["WX_DEBUG_COMPILER_OUTPUT"]; + +function encode1(s) { + return encodeURI(s).replace( + /%(u[0-9A-F]{4})|(%[0-9A-F]{2})/gm, + function ($0, $1, $2) { + return ($1 && "\\" + $1.toLowerCase()) || decodeURI($2); + } + ); +} +if (args.includes("-ll")) { + const wcsc = spawn(wcscPath, args, { + cwd: process.cwd(), + }); + const spwanData = [], + errData = []; + wcsc.stdout.on("data", (e) => { + spwanData.push(e); + }); + wcsc.stderr.on("data", (e) => { + errData.push(e); + }); + wcsc.on("close", (n) => { + if (0 === n) { + let str = Buffer.concat(spwanData).toString(); + DEBUG_OUTPUT && + fs.writeFileSync(`${DEBUG_OUTPUT}/linux_output.js`, str); + const resultSplit = str.split("="); + const tempObj = {}; + for ( + let i = 0, total = resultSplit.length; + i < total && resultSplit[i + 1]; + i += 2 + ) { + // a=b ---> a: b + const key = resultSplit[i]; + if (key === "version") continue; + tempObj[key] = resultSplit[i + 1].replace( + /[^\\]((\\x[\da-f]{2}|\\u[\da-f]{4})){1,}/g, + function ($0, $1, $2) { + return eval('"' + $0 + '"'); + } + ); + } + const resultObj = { + common: tempObj.comm, + pageWxss: {}, + }; + for (const key in tempObj) { + if (key.endsWith(".wxss")) { + resultObj.pageWxss[key] = tempObj[key]; + } + } + let result = JSON.stringify(resultObj); + result = result.replace(/\\\\/g, "\\"); + process.stdout.write(result); + } else { + const err = Buffer.concat(errData).toString(); + DEBUG_OUTPUT && + fs.writeFileSync(`${DEBUG_OUTPUT}/linux_err.js`, err); + process.stderr.write(err); + process.exitCode = n; + } + }); +} else { + const wcsc = spawn(wcscPath, args, { + cwd: process.cwd(), + stdio: "inherit", + }); + wcsc.on("close", (code) => { + process.exitCode = code; + }); +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..ed32076 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,221 @@ +{ + "name": "wx-compiler", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "miniprogram-compiler": "^0.2.1" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmmirror.com/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmmirror.com/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, + "node_modules/glob": { + "version": "7.2.0", + "resolved": "https://registry.npmmirror.com/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmmirror.com/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmmirror.com/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/miniprogram-compiler": { + "version": "0.2.1", + "resolved": "https://registry.npmmirror.com/miniprogram-compiler/-/miniprogram-compiler-0.2.1.tgz", + "integrity": "sha512-AHQgJFTnVPMcVBUUdKHlCRC3guK212XkWME0awMQiUgpzp/eIbb3jgFdkl3ib9nDbbEK+m2fSBs0++vwetWJ9Q==", + "dependencies": { + "glob": "^7.1.3", + "unescape-js": "^1.1.1" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmmirror.com/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmmirror.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/string.fromcodepoint": { + "version": "0.2.1", + "resolved": "https://registry.npmmirror.com/string.fromcodepoint/-/string.fromcodepoint-0.2.1.tgz", + "integrity": "sha512-n69H31OnxSGSZyZbgBlvYIXlrMhJQ0dQAX1js1QDhpaUH6zmU3QYlj07bCwCNlPOu3oRXIubGPl2gDGnHsiCqg==" + }, + "node_modules/unescape-js": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/unescape-js/-/unescape-js-1.1.4.tgz", + "integrity": "sha512-42SD8NOQEhdYntEiUQdYq/1V/YHwr1HLwlHuTJB5InVVdOSbgI6xu8jK5q65yIzuFCfczzyDF/7hbGzVbyCw0g==", + "dependencies": { + "string.fromcodepoint": "^0.2.1" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + } + }, + "dependencies": { + "balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmmirror.com/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmmirror.com/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, + "glob": { + "version": "7.2.0", + "resolved": "https://registry.npmmirror.com/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmmirror.com/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmmirror.com/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmmirror.com/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "miniprogram-compiler": { + "version": "0.2.1", + "resolved": "https://registry.npmmirror.com/miniprogram-compiler/-/miniprogram-compiler-0.2.1.tgz", + "integrity": "sha512-AHQgJFTnVPMcVBUUdKHlCRC3guK212XkWME0awMQiUgpzp/eIbb3jgFdkl3ib9nDbbEK+m2fSBs0++vwetWJ9Q==", + "requires": { + "glob": "^7.1.3", + "unescape-js": "^1.1.1" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmmirror.com/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmmirror.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==" + }, + "string.fromcodepoint": { + "version": "0.2.1", + "resolved": "https://registry.npmmirror.com/string.fromcodepoint/-/string.fromcodepoint-0.2.1.tgz", + "integrity": "sha512-n69H31OnxSGSZyZbgBlvYIXlrMhJQ0dQAX1js1QDhpaUH6zmU3QYlj07bCwCNlPOu3oRXIubGPl2gDGnHsiCqg==" + }, + "unescape-js": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/unescape-js/-/unescape-js-1.1.4.tgz", + "integrity": "sha512-42SD8NOQEhdYntEiUQdYq/1V/YHwr1HLwlHuTJB5InVVdOSbgI6xu8jK5q65yIzuFCfczzyDF/7hbGzVbyCw0g==", + "requires": { + "string.fromcodepoint": "^0.2.1" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ba51587 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "miniprogram-compiler": "^0.2.1" + } +} diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..c3bb83f --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,4 @@ +linux_output.js +node_output.json +node_stderr.json +wine_output.json \ No newline at end of file diff --git a/test/node-modules/.gitignore b/test/node-modules/.gitignore new file mode 100644 index 0000000..3ab4cd1 --- /dev/null +++ b/test/node-modules/.gitignore @@ -0,0 +1,2 @@ +data +*.txt \ No newline at end of file diff --git a/test/node-modules/.vscode/launch.json b/test/node-modules/.vscode/launch.json new file mode 100644 index 0000000..f0f69e7 --- /dev/null +++ b/test/node-modules/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "nwjs", + "request": "launch", + "name": "Launch NWjs", + "nwjsVersion": "any", + "webRoot": "${workspaceFolder}", + "reloadAfterAttached": true, + "userDataDir": "${workspaceFolder}/data", + "runtimeExecutable": "/mnt/disk2/wechat-web-devtools-linux/cache/wechat_devtools_1.05.2204180_x64/wechatdevtools.exe" + } + ] +} \ No newline at end of file diff --git a/test/node-modules/README.MD b/test/node-modules/README.MD new file mode 100644 index 0000000..6242310 --- /dev/null +++ b/test/node-modules/README.MD @@ -0,0 +1,12 @@ +# NODE模块的编译器测试目录 + +## 代码存放位置 + +wine版存放于 `node_modules/wcc_wine` +linux版存放于 `node_modules/wcc_linux` + + +## 生成代码 +wine版按 `./vscode/launch.json` 配置执行nwjs生成 `wine.txt` 结尾的文件 +linux版执行 `wcc_test.js` `wcsc_test.js` 生成 `linux.txt` 结尾的文件 + diff --git a/test/node-modules/index.html b/test/node-modules/index.html new file mode 100644 index 0000000..fbf86b4 --- /dev/null +++ b/test/node-modules/index.html @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/test/node-modules/index.js b/test/node-modules/index.js new file mode 100644 index 0000000..111b6b8 --- /dev/null +++ b/test/node-modules/index.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node +require('./wcc_test') +require('./wcsc_test') \ No newline at end of file diff --git a/test/node-modules/package.json b/test/node-modules/package.json new file mode 100644 index 0000000..3ab5363 --- /dev/null +++ b/test/node-modules/package.json @@ -0,0 +1,16 @@ +{ + "forceVendor": true, + "name": "nw_test", + "main": "index.html", + "productName": "test", + "appname": "nw_test", + "version": "1.0", + "window": { + "frame": true + }, + "chromium-args": "--no-sandbox --ignore-gpu-blacklist --register-pepper-plugins=./node_modules/mpv.js/build/Release/mpvjs.node;application/x-mpvjs", + "dependencies": { + "mpv.js": "^0.3.0", + "spdlog": "^0.13.6" + } + } \ No newline at end of file diff --git a/test/node-modules/wcc_test.js b/test/node-modules/wcc_test.js new file mode 100755 index 0000000..2127e23 --- /dev/null +++ b/test/node-modules/wcc_test.js @@ -0,0 +1,180 @@ +#!/usr/bin/env node + +const fs = require('fs') +const path = require('path') +const MODE = typeof nw === 'object' ? 'wine' : 'linux' +const wcc_options = [] +const wcc_options1 = { + "files": ["./miniprogram_npm/miniprogram-barrage/index.wxml", "./miniprogram_npm/miniprogram-recycle-view/recycle-item.wxml", "./miniprogram_npm/miniprogram-recycle-view/recycle-view.wxml", "./miniprogram_npm/wxml-to-canvas/index.wxml", "./page/API/index.wxml", "./page/API/components/set-tab-bar/set-tab-bar.wxml", "./page/cloud/index.wxml", "./page/common/foot.wxml", "./page/common/head.wxml", "./page/component/index.wxml", "./page/extend/index.wxml"], + "debugWXS": false, + "debug": true, + "genfuncname": "$gwx", + "isCut": true, + "wxmlCompileConfig": "9>_<1027./miniprogram_npm/miniprogram-barrage/index.wxml>_<10270>_<1027./miniprogram_npm/miniprogram-recycle-view/recycle-item.wxml>_<10270>_<1027./miniprogram_npm/miniprogram-recycle-view/recycle-view.wxml>_<10270>_<1027./miniprogram_npm/wxml-to-canvas/index.wxml>_<10270>_<1027./page/API/index.wxml>_<10271>_<1027set-tab-bar>_<1027./page/API/components/set-tab-bar/set-tab-bar.wxml>_<10270>_<1027./page/cloud/index.wxml>_<10270>_<1027./page/component/index.wxml>_<10270>_<1027./page/extend/index.wxml>_<10270", + "wxmlCompileConfigSplit": ">_<1027", + "replaceContent": { + "./packageComponent/pages/camera-scan-code/camera-scan-code.wxml": "\n\n\n\n