xhs-mp-project 1.6.0 → 1.7.1
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/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const utils: {
|
|
2
|
-
transformAppJson: (
|
|
2
|
+
transformAppJson: (_: string, miniprogramDir: string, extJsonPath?: string) => {
|
|
3
3
|
legacyAppJSON: any;
|
|
4
4
|
appJSON: import("./project").IAppJSON;
|
|
5
5
|
};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("path"),e=require("clone"),n=require("fs-extra"),s=require("json-to-ast"),o=require("lodash"),i=require("events"),a=require("process");function r(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var c=r(t),p=r(n);require("crypto"),require("net");const h=(t,e=100)=>{let n=null;return function(...s){(!n||Date.now()-n>e)&&(n=Date.now(),t.apply(this,s))}},l=(t="")=>t.split(c.sep).join(c.posix.sep),u=(t="")=>t.split(c.sep).join(c.posix.sep),g=(...t)=>u(c.join(...t)),d=(...t)=>u(c.resolve(...t)),m=c.posix.sep,f=t=>{if(!u(t).includes(m))return"/";const e=u(t).split(m).filter(Boolean);return e.slice(0,e.length-1).join(m)};require("util").inspect.custom;const j=(t,e)=>{const n=new Error(["\n<xhsml!",`[error:文件内容错误]:[file:${null==t?void 0:t.trim()}]`,e,"!xhsml>\n"].join("\n"));throw n.stack=void 0,n},P=(t,e)=>t===e||(!(!t.startsWith(e)||!t.replace(e,"").startsWith("/"))||!(!e.startsWith(t)||!e.replace(t,"").startsWith("/"))),J=(t,e)=>{const n=t=>(j(e,t),{pages:[],subPackages:[]}),s=t.pages;if(!("pages"in t))return n("缺少 pages 字段");if(t.pages.length<=0)return n("pages 不能为空");if(t.window){if(t.window.navigationBarTextStyle&&!["black","white"].includes(t.window.navigationBarTextStyle))return n("window.navigationBarTextStyle 错误: 仅支持 black / white");if(t.window.backgroundTextStyle&&!["dark","light"].includes(t.window.backgroundTextStyle))return n("window.backgroundTextStyle 错误: 仅支持 dark / light");if(t.window.navigationStyle&&!["default","custom"].includes(t.window.navigationStyle))return n("window.navigationStyle 错误: 仅支持 default / custom")}if(t.tabBar){if(!t.tabBar.list)return n("tabBar.list 不能为空");if(t.tabBar.list.length<2)return n("tabBar.list 错误: tabBar.list 需至少包含 2 项");if(t.tabBar.list.length>5)return n("tabBar.list 错误: tabBar.list 不能超过 5 项");for(const{pagePath:e}of t.tabBar.list){if(!e)return n('tabBar.list 错误: "pagePath" 不能为空');if(!s.includes(e))return n(`tabBar.list 错误: "${e}" 不在 "pages" 内`)}}if(t.subPackages.length){const e=[],o=[];for(let s=0;s<t.subPackages.length;s++){if("string"!=typeof t.subPackages[s].root)return n(`subPackages[${s}].root 字段类型需为 string`);if(t.subPackages[s].name){const e=o.indexOf(t.subPackages[s].name);if(e>-1)return n(`subPackages[${s}] 与 subPackages[${e}] 的 name 相同`);o.push(t.subPackages[s].name)}e.push(t.subPackages[s].root)}for(let o=0;o<e.length;o++){if(!e[o])return n(`subPackages[${o}].root 不能为空`);if(!t.subPackages[o].pages)return n(`subPackages[${o}].pages 不能为空`);const i=s.findIndex((t=>P(t,e[o])));if(i>-1)return n(`pages[${i}] 与 subPackages[${o}] 存在包含关系`);for(let t=o+1;t<e.length;t++)if(P(e[o],e[t]))return n(`subPackages[${o}] 与 subPackages[${t}] 存在包含关系`)}}return t.networkTimeout&&"object"!=typeof t.networkTimeout?n("networkTimeout 字段需为 object"):t},v=["window","networkTimeout","tabBar"],y=(t,e,n)=>{if(!((t,e,n)=>{var s;const o=t=>{j(n,t)},i=t.pages;if(e.pages)for(const t of e.pages)if(!i.includes(t))return o(`page 错误: "${t}" 不在 app.json 内`),!1;if(e.extPages)for(const t of Object.keys(e.extPages))if(!i.includes(t))return o(`extPages 错误: "${t}" 不在 app.json 内`),!1;if(null===(s=null==e?void 0:e.tabBar)||void 0===s?void 0:s.list){if(e.tabBar.list.length<2)return o("tabBar.list 错误: tabBar.list 需至少包含 2 项"),!1;for(const{pagePath:t}of e.tabBar.list){if(!t)return o('tabBar.list 错误: "pagePath" 不能为空'),!1;if(!i.includes(t))return o(`tabBar.list 错误: "${t}" 不在 app.json 内`),!1}}return!0})(t,e,n))return t;for(const[n,s]of Object.entries(e))if("extPages"!==n)if("object"==typeof s&&v.includes(n)){const e=Array.isArray(s);t[`${n}`]=t[`${n}`]||(e?[]:{}),t[`${n}`]=e?[...new Set([...t[`${n}`],...s])]:{...t[`${n}`],...s}}else t[`${n}`]=s;return t},b=t=>{try{const e=n.readFileSync(`${t}`,"utf-8");return s(e,{loc:!0,source:t}),JSON.parse(e)}catch(e){return j(t||e.source,e.message),{pages:[]}}};let x=1;const C=(e,s,o,i)=>{if(i.startsWith("/"))return g(s,i).replace(`${s}/`,"");if(i.startsWith("."))return g(s,t.dirname(o),i).replace(`${s}/`,"");if(n.existsSync(`${g(s,i)}.js`))return g(s,i).replace(`${s}/`,"");if(i.startsWith("plugin://"))return console.log("小红书小程序暂不支持插件:",i),"";const a=b(`${e}/package.json`),r=Object.keys(a.dependencies||[]).find((t=>i.includes(t)))||"",c=i.replace(r,""),p=b(`${e}/node_modules/${r}/package.json`);let h=p.miniprogram||p.main;try{h=h.endsWith(".js")?h.replace(/.js$/,""):h;const s=t.join(e,"node_modules",r,h,c).replace(`${e}/`,"");return n.existsSync(`${e}/${s}.${`${process.env.__platform}ml`.trim()}`)?s:`${s}/index`}catch(t){throw new Error(`组件路径不正确:${i}`)}},k=/\.|\/|\.\/|\.\.\//g,$=(t,e,s,o)=>{if(!Object.keys(t.componentsMap).includes(o))if(n.existsSync(`${s}/${o}.json`)){const n=b(`${s}/${o}.json`);if(t.componentsMap[o]=n,t.componentsMap[o].index=x++,n.componentPlaceholder){const i=n.componentPlaceholder;for(const[n,a]of Object.entries(i)){let r;r=k.test(a)?C(e,s,o,a):a,i[n]=r,k.test(a)&&$(t,e,s,r)}t.componentsMap[o].componentPlaceholder=i}if(n.usingComponents)for(const[i,a]of Object.entries(n.usingComponents)){const r=C(e,s,o,a);n.usingComponents[i]=r,$(t,e,s,r)}}else console.error(`cann't no found ${s}/${o}.json`)},w=(t,e,s,o,i)=>t.map((t=>{var a,r;let c={path:t};const p=d(s,`${c.path}.json`);if(n.existsSync(p)){let t=b(p);if((null===(a=o.extPages)||void 0===a?void 0:a[`${c.path}`])&&(t={...t,...null===(r=o.extPages)||void 0===r?void 0:r[`${c.path}`]}),c={...c,...t},c.componentPlaceholder)for(const[t,n]of Object.entries(c.componentPlaceholder))if(k.test(n)){const o=C(e,s,c.path,n);c.componentPlaceholder[t]=o,$(i,e,s,o)}if(c.usingComponents)for(const[t,n]of Object.entries(c.usingComponents)){const o=C(e,s,c.path,n);c.usingComponents[t]=o,$(i,e,s,o)}}return c})),S=(t,n,s)=>{x=1;const o=d(n,"app.json");let i=b(o);i.subPackages=i.subPackages||i.subpackages||[],i=J(i,o);const a=s?b(`${s}/ext.json`):{};if((null==a?void 0:a.extEnable)&&(i=y(i,a,`${s}/ext.json`)),i.componentsMap={},i.usingComponents)for(const[e,s]of Object.entries(i.usingComponents)){const o=C(t,n,"",s);i.usingComponents[e]=o,$(i,t,n,o)}i.pages=w(i.pages,t,n,a,i),i.subPackages=i.subPackages.map((e=>{const s=e.pages.map((t=>g(e.root,t)));return{...e,pages:w(s,t,n,a,i)}})),i.xhsVersionStrategy={classCalc:"v1",pageNotFoundMigration:!0,animationEventTriggerPatchPerfix:"xhs_animate_",renderEventDelegation:!0,canvasToTempFilePath:"v1",allowLazyAppJs:!0};const r=e(i);Reflect.deleteProperty(r,"subPackages");const c=i.subPackages.reduce(((t,e)=>[...t,...e.pages]),[]);return r.pages=c?[...r.pages,...c]:r.pages,{legacyAppJSON:r,appJSON:i}},_="baba:changeExtJsonPath",O="baba:changeExtJson",D="miniprogram",E="minigame",N=t=>{t=u(t);const e=d(t,"game.json");let n=b(e);return n.subPackages=n.subPackages||n.subpackages||[],n.pages=[],n.subPackages=n.subPackages.map((t=>{let e=u(`${t.root}`).replace(/^\/+|\/+$/g,"");e=/\.(ts|js)$/.test(e)?e.replace(/\.(ts|js)$/,""):g(e,"game");const n={rawRoot:`${t.root}`,entry:e,dirname:f(e)};return{...t,...n}})),J(n,e)?{appJSON:n}:{appJSON:{pages:[],subPackages:[]}}};class M{constructor(t){this.project=t}}const B=(t,e)=>{const n=t.pages.find((t=>t.path===e))||{};return(null==n?void 0:n.usingComponents)?n.usingComponents:{}},q=(t,e)=>{let n=[];((null==t?void 0:t.subPackages)||[]).forEach((t=>{n=n.concat(t.pages)}));const s=n.find((t=>t.path===e))||{};return(null==s?void 0:s.usingComponents)||{}},A=t=>(null==t?void 0:t.usingComponents)||{};const T=(t,e)=>{var n;const s=t.componentsMap||{};return(null===(n=null==s?void 0:s[e])||void 0===n?void 0:n.usingComponents)||{}},R=require("chokidar"),z={description:"项目配置文件",packOptions:{ignore:[]},appid:"testappid",miniprogramRoot:"."};class F extends i.EventEmitter{constructor(t){super(),this._projectJson="project.config.json",this._appJson="app.json",this._extJson="ext.json",this._projectPath="",this._extJsonDir="",this._canUploadExtJson=!1,this._appMode=D,this._isLazyload=!1,this._customEntry="",this.jsonDependencies=[],this.onProjectConfigJsonChange=h((()=>{var t,e,n,s;const{projectConfig:i}=this.snapshot,a=b(this.projectJsonPath);this._projectJsonContent=a,this.snapshot.projectConfig=o.cloneDeep(a),this.emit("project-config-json-changed",{oldData:i,newData:a}),(null==i?void 0:i.libVersion)!==(null==a?void 0:a.libVersion)&&this.emit("lib-version-changed",{oldData:null==i?void 0:i.libVersion,newData:null==a?void 0:a.libVersion}),(null===(t=null==i?void 0:i.setting)||void 0===t?void 0:t.enableSimulatorV2)!==(null===(e=null==a?void 0:a.setting)||void 0===e?void 0:e.enableSimulatorV2)&&this.emit("simulator-mode-changed",{oldData:null===(n=null==i?void 0:i.setting)||void 0===n?void 0:n.enableSimulatorV2,newData:null===(s=null==a?void 0:a.setting)||void 0===s?void 0:s.enableSimulatorV2})}),100),this.onProjectPrivateJsonChange=h((()=>{const{customEntry:t}=this.snapshot;this.updateCustomEntry();const e=this._customEntry;this.snapshot.customEntry=e,this.emit("project-private-json-changed"),this.emit("custom-entry-changed",{oldData:t,newData:e})}),100),this.onAppJsonChange=h((()=>{const{appJson:t}=this.snapshot,e=b(this.entryJsonPath);this._appJsonContent=e,this.snapshot.appJson=o.cloneDeep(e),this.emit("app-json-changed",{oldData:t,newData:e})}),100),this.onExtJsonChange=h((()=>{const{extJson:t}=this.snapshot,e=b(this.extJsonPath).ext||{};this._extJsonContent=e,this.snapshot.extJson=o.cloneDeep(e),this.emit(O,{oldData:t,newData:e})}),100),this.getCustomEntry=t=>{var e,n,s,o;const i={pathName:"",query:"",entry:"",item:{}};try{if(!p.existsSync(t))return i;const a=b(t),r=(null===(n=null===(e=null==a?void 0:a.condition)||void 0===e?void 0:e.miniprogram)||void 0===n?void 0:n.current)||-1,c=null===(o=null===(s=null==a?void 0:a.condition)||void 0===s?void 0:s.miniprogram)||void 0===o?void 0:o.list;if(-1===r)return i;const h=c.filter((t=>t.id===r))[0];return h?(i.pathName=h.pathName,i.query=h.query,"halfPageNativeFunctionalized"===h.launchMode&&(i.query=h.query+="&runtime_mode=2"),i.entry=i.query?`${i.pathName}?${i.query}`:`${i.pathName}`,i):i}catch(t){return console.log("getCustomEntry error: ",t),i}},this.getCompileEntryPage=()=>{var t,e,n,s,o;const i=this.projectPrivateConfigJsonPath,a={path:"",query:"",launchMode:"default"};if(!p.existsSync(i))return a;const r=b(i),c=null===(e=null===(t=null==r?void 0:r.condition)||void 0===t?void 0:t.miniprogram)||void 0===e?void 0:e.current,h=null===(o=null===(s=null===(n=null==r?void 0:r.condition)||void 0===n?void 0:n.miniprogram)||void 0===s?void 0:s.list)||void 0===o?void 0:o.filter((t=>t.id===c))[0];return h?{path:h.pathName,query:h.query.trim(),launchMode:h.launchMode}:a};const{watch:e}=t;let n=t.projectPath;if(c.isAbsolute(n)||(n=c.join(a.cwd(),n)),this.checker=new M(this),this._projectPath=l(n),this._extJsonDir=p.existsSync(this.extJsonPath)?this.projectPath:"",this._appMode=p.existsSync(c.posix.join(this._projectPath,"game.json"))?E:D,this.jsonDependencieMap=new Set([c.normalize(this.entryJsonPath)]),this._isLazyload="requiredComponents"===this.appJsonContent.lazyCodeLoading,this.updateCustomEntry(),this._appMode===D){const{legacyAppJSON:t,appJSON:e}=S(this.projectPath,this.miniprogramDir,this.extJsonDir);this.appJSON=e,this.legacyAppJSON=t,this.updateAppJson()}else{const{appJSON:t}=N(this.projectPath);this.appJSON=t,this.legacyAppJSON={}}e&&this.watchProject()}get projectPath(){return this._projectPath}get projectJsonPath(){return c.resolve(this._projectPath,this._projectJson)}get miniprogramRoot(){return this.projectJsonContent.miniprogramRoot||""}get projectMiniprogramPath(){const t=l(c.join(this.projectPath,this.miniprogramRoot));return t.endsWith("/")?t.slice(0,-1):t}get miniprogramDir(){const t=l(c.join(this.projectPath,this.miniprogramRoot));return t.endsWith("/")?t.slice(0,-1):t}get appMode(){return this._appMode}get lazyload(){return this._isLazyload}get projectJsonContent(){return p.pathExistsSync(this.projectJsonPath)?(this._projectJsonContent||(this._projectJsonContent=b(this.projectJsonPath)),this._projectJsonContent):{}}set projectJsonContent(t){this._projectJsonContent=t,p.writeJSONSync(this.projectJsonPath,t,{spaces:2})}get projectPrivateConfigJsonPath(){return c.resolve(this._projectPath,"project.private.config.json")}get entryJson(){return this.appMode===D?"app.json":"game.json"}get entryJsonPath(){if(!p.existsSync(this.projectJsonPath))return"";const t=b(this.projectJsonPath);let e=".";return t.miniprogramRoot&&(e=t.miniprogramRoot),c.resolve(this._projectPath,e,this.entryJson)}get appJsonContent(){if(!this.entryJsonPath||!p.existsSync(this.entryJsonPath))throw new Error(`打开项目失败: ${this.entryJson}不存在`);return this._appJsonContent||(this._appJsonContent=b(this.entryJsonPath)),this._appJsonContent}get extJsonPath(){return c.resolve(this._projectPath,this._extJson)}get extJsonContent(){return this.extJsonPath&&p.existsSync(this.extJsonPath)?(this._extJsonContent||(this._extJsonContent=b(this.extJsonPath).ext||{}),this._extJsonContent):{}}get extJsonDir(){return this._extJsonDir}set extJsonDir(t){this.extJsonDir!==t&&(this._extJsonDir=t,this.emit(_))}get canUploadExtJson(){return this._canUploadExtJson}get customEntry(){return this._customEntry}get projectAppId(){let t="";try{t=this.projectJsonContent.appid}catch(t){console.log("get projectAppId error:",t)}if(!t)throw new Error("appid can not be empty!!!");return t}watchProject(){this.snapshot=o.cloneDeep({projectConfig:this.projectJsonContent,appJson:this.appJsonContent,extJson:this.extJsonContent,customEntry:this._customEntry});const t=R.watch(this.projectPath,{persistent:!0,ignoreInitial:!0,ignored:/node_modules/});return t.on("change",(t=>{this.onFileChange("change",t)})).on("add",(t=>{this.onFileChange("add",t)})).on("unlink",(t=>{this.onFileChange("unlink",t)})),t}onFileChange(t,e){const n=c.relative(this.projectPath,e);"change"===t&&("project.config.json"===n?this.onProjectConfigJsonChange():"project.private.config.json"===n?this.onProjectPrivateJsonChange():"ext.json"===n?this.onExtJsonChange():"app.json"===n&&this.onAppJsonChange()),this.emit("onFileChange",{eventName:t,filePath:e,relativePath:n})}checkFileExist(){if(!this._projectPath)return;const t=this.projectJsonPath;p.existsSync(t)||p.writeJSONSync(this.projectJsonPath,z,{spaces:2})}updateCustomEntry(){const t=this.getCustomEntry(this.projectPrivateConfigJsonPath),e=(null==t?void 0:t.entry)||"";this._customEntry=e}get settings(){var t;return{minified:!0,urlCheck:!0,useNewCompiler:!1,enableV2:!1,...(null===(t=this.projectJsonContent)||void 0===t?void 0:t.setting)||{}}}changeCompileSetting(t){const e=this.projectJsonContent;e.setting?e.setting={...e.setting,...t}:e.setting=t,this.projectJsonContent=e}createDefaultProjectConfig(t){const e={description:"项目配置文件",setting:{urlCheck:!0,minified:!0},compileType:"miniprogram",libVersion:"latest",appid:"wx93e095ba089dbfb5",projectname:c.basename(t)},n=c.resolve(t,this._projectJson);p.writeJSONSync(n,e,{spaces:2})}changeExtJsonPermission(t){this._canUploadExtJson=t,t&&p.existsSync(this.extJsonPath)?this.extJsonDir=this.projectPath:this.extJsonDir=""}getSubPackages(){return this.appJSON.subPackages||[]}isFileInMainPkg(t){return this.getSubPackages().every((e=>!t.startsWith(`${e}/`)))}isFileInSubpackage(t){return this.getSubPackages().some((e=>t.startsWith(`${e}/`)))}getComponentsMap(){return this.appJSON.componentsMap||{}}getPages(){return this.appJSON.pages||[]}isPkgPage(t,e){let n=[];n="xhs-main"===t?this.appJsonContent.pages||[]:t.pages||[];const s=c.extname(e);return n.some((t=>`${t}${s}`===e))}getPageDependComponentPaths(t,e){const n=function(t){var e,n;if(!(null==t?void 0:t.subPackages)||!(null==t?void 0:t.subPackages.length))return!1;let s=!1;try{s=!("string"==typeof(null===(n=null===(e=null==t?void 0:t.subPackages)||void 0===e?void 0:e[0].pages)||void 0===n?void 0:n[0]))}catch(t){}return s}(this.appJSON),s=((t,e,n=!1,s=!0)=>{try{const o=new Set;let i={};i=s?{...n?{}:A(e),...B(e,t),...q(e,t)}:{...A(e),...B(e,t)};const a=t=>{for(const n in t)if(t[n]){const s=t[n];if(o.has(s))continue;o.add(s);const i=T(e,s);i&&Object.keys(i).length&&a(i)}};return a(i),Array.from(o)}catch(t){return console.error("parse page depend components has error happen"),[]}})(t,this.appJSON,e,n);return s}formatGameAppJSON(t){return t.map((t=>{let e=u(`${t.root}`).replace(/^\/+|\/+$/g,"");if(/\.(ts|js)$/.test(e)){const t=e.split("/").filter(Boolean);e=t.slice(0,t.length-1).join("/")}return{root:e}}))}static deSerialize(t){return new F(t)}updateAppJson(){const{legacyAppJSON:t}=this;for(const e of t.pages)this.jsonDependencieMap.add(c.normalize(`${this.projectPath}/${e.path}.json`));for(const e of Object.keys(t.componentsMap))this.jsonDependencieMap.add(c.normalize(`${this.projectPath}/${e}.json`));this.jsonDependencies=Array.from(this.jsonDependencieMap)}}const W={transformAppJson:S,transformGameJson:N,pureAppJSON:(t,e="v1")=>{var n,s;const i=o.cloneDeep(t);if("v1"===e&&(i.subPackages=(null===(n=i.subPackages)||void 0===n?void 0:n.map((t=>{const{entry:e,dirname:n,name:s,independent:o,rawRoot:i}=t;return{independent:o,root:n,path:e,rawRoot:i,name:s,pages:[{path:e}]}})))||[],i.pages=[{path:"/"}]),"v0"===e){const t=null===(s=i.subPackages)||void 0===s?void 0:s.map((t=>({path:t.entry})));Reflect.deleteProperty(i,"subPackages"),i.pages=[{path:"/"},...t]}return Reflect.deleteProperty(i,"subpackages"),i.compileType="minigame",i}};exports.Project=F,exports.utils=W;
|
|
1
|
+
"use strict";var t=require("path"),e=require("clone"),n=require("fs-extra"),s=require("json-to-ast"),o=require("lodash"),r=require("events"),i=require("process");function a(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var c=a(t),p=a(n);require("crypto"),require("net");const u=(t,e=100)=>{let n=null;return function(...s){(!n||Date.now()-n>e)&&(n=Date.now(),t.apply(this,s))}},l=(t="")=>t.split(c.sep).join(c.posix.sep),h=(t="")=>t.split(c.sep).join(c.posix.sep),g=(...t)=>h(c.join(...t)),d=(...t)=>h(c.resolve(...t)),m=c.posix.sep,f=t=>{if(!h(t).includes(m))return"/";const e=h(t).split(m).filter(Boolean);return e.slice(0,e.length-1).join(m)};require("util").inspect.custom;const P=(t,e)=>{const n=new Error(["\n<xhsml!",`[error:文件内容错误]:[file:${null==t?void 0:t.trim()}]`,e,"!xhsml>\n"].join("\n"));throw n.stack=void 0,n};function j(t,e){if(!Array.isArray(t))return e("pages 字段需为 array");for(let n=0;n<t.length;n++){const s=t[n];if(s.startsWith("/"))return e(`pages[${n}] 不应该以 '/' 开头`);if(s.startsWith("."))return e(`pages[${n}] 不应该以 '.' 开头`)}}const b=(t,e)=>t===e||(!(!t.startsWith(e)||!t.replace(e,"").startsWith("/"))||!(!e.startsWith(t)||!e.replace(t,"").startsWith("/")));function y(t,e,n){var s,o;if(!Array.isArray(t))return n("subPackages 字段需为 array");const r=[],i=[];for(let e=0;e<t.length;e++){if("string"!=typeof(null===(o=null===(s=t[e].root)||void 0===s?void 0:s.trim)||void 0===o?void 0:o.call(s)))return n(`subPackages[${e}].root 字段类型需为 string`);const a=t[e].root;if(a.startsWith("/"))return n(`subPackages[${e}].root 不应该以 '/' 开头`);if(a.startsWith("."))return n(`subPackages[${e}].root 不应该以 '.' 开头`);if(!Array.isArray(t[e].pages))return n(`subPackages[${e}].pages 类型需为array`);for(let s=0;s<t[e].pages.length;s++){const o=t[e].pages[s];if(o.startsWith("/"))return n(`subPackages[${e}].pages[${s}] 不应该以 '/' 开头`);if(o.startsWith("."))return n(`subPackages[${e}].pages[${s}] 不应该以 '.' 开头`)}if(t[e].name){const s=i.indexOf(t[e].name);if(s>-1)return n(`subPackages[${e}] 与 subPackages[${s}] 的 name 相同`);i.push(t[e].name)}r.push(t[e].root)}for(let t=0;t<r.length;t++){const s=e.findIndex((e=>b(e,r[t])));if(s>-1)return n(`pages[${s}] 与 subPackages[${t}] 存在包含关系`);for(let e=t+1;e<r.length;e++)if(b(r[t],r[e]))return n(`subPackages[${t}] 与 subPackages[${e}] 存在包含关系`)}}function v(t,e){return x(t)?null==t.navigationBarTextStyle||["black","white"].includes(t.navigationBarTextStyle)?null==t.backgroundTextStyle||["dark","light"].includes(t.backgroundTextStyle)?null==t.navigationStyle||["default","custom"].includes(t.navigationStyle)?void 0:e("window.navigationStyle 错误: 仅支持 default / custom"):e("window.backgroundTextStyle 错误: 仅支持 dark / light"):e("window.navigationBarTextStyle 错误: 仅支持 black / white"):e("window 字段需为 object")}function J(t,e){var n;if(!x(t))return e("tabBar 字段需为 object");if(!Array.isArray(null==t?void 0:t.list))return e("tabBar.list 字段需为 array");if(!(null===(n=null==t?void 0:t.list)||void 0===n?void 0:n.length))return e("tabBar.list 不能为空");if(t.list.length<2)return e("tabBar.list 错误: tabBar.list 需至少包含 2 项");if(t.list.length>5)return e("tabBar.list 错误: tabBar.list 不能超过 5 项");for(let n=0;n<t.list.length;n++){const{pagePath:s}=t.list[n];if(!s)return e(`tabBar.list[${n}] 错误: "pagePath" 不能为空`);if(s.startsWith("/"))return e(`tabBar.list[${n}].pagePath 不应该以 '/' 开头`);if(s.startsWith("."))return e(`tabBar.list[${n}].pagePath 不应该以 '.' 开头`)}}function k(t,e){if(!x(t))return e("usingComponents 字段需为 object")}function $(t,e){if(!x(t))return e("networkTimeout 字段需为 object");const n=["request","connectSocket","uploadFile","downloadFile"];for(const s of n)if(null!=t[s]&&"number"!=typeof t[s])return e(`networkTimeout.${s} 字段需为 number`)}function x(t){return Boolean(t&&"[object Object]"===Object.prototype.toString.call(t))}const C=["window","networkTimeout","tabBar"],S=(t,e,n)=>{if(!((t,e,n)=>{const s=t=>P(n,t),o=t.pages;if("pages"in e){j(e.pages,s);for(const t of e.pages)if(!o.includes(t))return s(`page 错误: "${t}" 不在 app.json 内`)}if("extPages"in e){if(!x(e.extPages))return s("extPages 字段需为 object");for(const t of Object.keys(e.extPages))if(!o.includes(t))return s(`extPages 错误: "${t}" 不在 app.json 内`)}if(("subpackages"in e||"subPackages"in e)&&y(e.subpackages||e.subPackages,e.pages?e.pages:o,s),"tabBar"in e){if(!x(e.tabBar))return s("tabBar 字段需为 object");if("list"in e.tabBar){J(e.tabBar,s);for(const{pagePath:t}of e.tabBar.list)if(!o.includes(t))return s(`tabBar.list 错误: "${t}" 不在 app.json 内`)}}return"window"in e&&v(e.window,s),"networkTimeout"in e&&$(e.networkTimeout,s),"usingComponents"in e&&k(e.usingComponents,s),!0})(t,e,n))return t;for(const[n,s]of Object.entries(e))if("extPages"!==n)if("object"==typeof s&&C.includes(n)){const e=Array.isArray(s);t[n]=t[n]||(e?[]:{}),t[n]=e?[...new Set([...t[n],...s])]:{...t[n],...s}}else t[n]=s;return t},w=t=>{try{const e=n.readFileSync(`${t}`,"utf-8");return s(e,{loc:!0,source:t}),JSON.parse(e)}catch(e){return P(t||e.source,e.message),{pages:[]}}};let _=1;function O(t,e="Component"){return!(!n.existsSync(`${t}.js`)&&!n.existsSync(`${t}.ts`))&&("Component"!==e||n.existsSync(`${t}.json`))}const D=t=>"Page"===t?`${t}路径不正确,请检查目标路径是否存在(js|ts)、xhsml文件`:`${t}路径不正确,请检查目标路径是否存在(js|ts)、xhsml、json文件,且json中需设置component字段为true`,E=(e,s,o)=>{if(s.startsWith("plugin://"))return P(o,`小红书小程序暂不支持插件:${s}`);function r(t){return t.replace(`${e}/`,"")}let i="";if(s.startsWith("/")&&O(i=g(e,s)))return r(i);if(s.startsWith(".")&&O(i=d(t.dirname(o),s)))return r(i);if(O(i=d(e,s)))return r(i);if(O(i=d(t.dirname(o),s)))return r(i);const a=((t,e)=>{try{const s=`${t}/package.json`;if(n.existsSync(s)){const o=w(s),r=Object.keys(o.dependencies||[]).find((t=>e.includes(t)))||"",i=`${t}/node_modules/${r}/package.json`;if(n.existsSync(i)){const n=e.replace(r,"").replace(/^\//,""),s=w(i);let o=s.miniprogram||s.main||"";o=/\.(ts|js)$/.test(o)?o.replace(/\.(js|ts)$/,""):o;let a=(n||o||"").trim();const c=g(t,"node_modules",r,a).replace(`${t}/`,"");if(O(`${t}/${c}`))return c;if(O(`${t}/${c}/index`))return`${c}/index`}}}catch(t){}})(e,s);return a||P(o,`${D("Component")}:${s}`)},N=/\.|\/|\.\/|\.\.\//g,A=(t,e,n,s)=>{const o={};for(const[r,i]of Object.entries(t)){let t;N.test(i)?(t=E(n,i,s),q(e,n,t)):t=i,o[r]=t}return o},B=(t,e,n,s)=>{const o={};for(const[r,i]of Object.entries(t)){const t=E(n,i,s);o[r]=t,q(e,n,t)}return o},M=t=>!(!t||"[object Object]"!==Object.prototype.toString.call(t))&&Boolean(Object.keys(t).length),q=(t,e,n)=>{if(Object.keys(t.componentsMap).includes(n))return;const s=d(e,`${n}.json`),o=w(s);t.componentsMap[n]=o,t.componentsMap[n].index=_++,M(o.componentPlaceholder)?o.componentPlaceholder=A(o.componentPlaceholder,t,e,s):Reflect.deleteProperty(o,"componentPlaceholder"),M(o.usingComponents)?o.usingComponents=B(o.usingComponents,t,e,s):Reflect.deleteProperty(o,"usingComponents")},T=(t,e,s,o)=>t.map((t=>{var r,i;let a={path:t};const c=d(e,`${a.path}.json`);if(n.existsSync(c)){let t=w(c);(null===(r=s.extPages)||void 0===r?void 0:r[`${a.path}`])&&(t={...t,...null===(i=s.extPages)||void 0===i?void 0:i[`${a.path}`]}),a={...a,...t},M(a.componentPlaceholder)?a.componentPlaceholder=A(a.componentPlaceholder,o,e,c):Reflect.deleteProperty(a,"componentPlaceholder"),M(a.usingComponents)?a.usingComponents=B(a.usingComponents,o,e,c):Reflect.deleteProperty(a,"usingComponents")}return a})),W=(t,n,s)=>{_=1;const o=d(n,"app.json");let r=w(o);r.subPackages=r.subPackages||r.subpackages||[],r=((t,e)=>{const n=t=>P(e,t);if(!("pages"in t))return n("缺少 pages 字段");if(!Array.isArray(t.pages))return n("pages 字段需为 array");if(t.pages.length<=0)return n("pages 不能为空");if(j(t.pages,n),"tabBar"in t){J(t.tabBar,n);for(const{pagePath:e}of t.tabBar.list)if(!t.pages.includes(e))return n(`tabBar.list 错误: "${e}" 不在 "pages" 内`)}return("subpackages"in t||"subPackages"in t)&&y(t.subPackages||t.subpackages,t.pages,n),"window"in t&&v(t.window,n),"networkTimeout"in t&&$(t.networkTimeout,n),"usingComponents"in t&&k(t.usingComponents,n),t})(r,o);const i=s?w(`${s}/ext.json`):{};(null==i?void 0:i.extEnable)&&(r=S(r,i,`${s}/ext.json`)),r.componentsMap={},M(r.usingComponents)?r.usingComponents=B(r.usingComponents,r,n,o):Reflect.deleteProperty(r,"usingComponents"),r.pages.map(((t,e)=>{if(!O(d(n,t),"Page"))return P(o,`${D("Page")}:${t} in pages[${e}]`)})),r.pages=T(r.pages,n,i,r),r.subPackages=r.subPackages.map(((t,e)=>{const s=t.pages.map(((s,r)=>{const i=g(t.root,s);return O(d(n,i),"Page")?i:P(o,`${D("Page")}:${s} in subPackages[${e}].pages[${r}]`)}));return{...t,pages:T(s,n,i,r)}})),r.xhsVersionStrategy={classCalc:"v1",pageNotFoundMigration:!0,animationEventTriggerPatchPerfix:"xhs_animate_",renderEventDelegation:!0,canvasToTempFilePath:"v1",allowLazyAppJs:!0};const a=e(r);Reflect.deleteProperty(a,"subPackages");const c=r.subPackages.reduce(((t,e)=>[...t,...e.pages]),[]);return a.pages=c?[...a.pages,...c]:a.pages,{legacyAppJSON:a,appJSON:r}},R="baba:changeExtJsonPath",F="baba:changeExtJson",z="miniprogram",V="minigame",I=t=>{t=h(t);const e=d(t,"game.json");let s=w(e);return s.subPackages=s.subPackages||s.subpackages||[],s.pages=[],s.subPackages=s.subPackages.map((t=>{let e=h(`${t.root}`).replace(/^\/+|\/+$/g,"");e=/\.(ts|js)$/.test(e)?e.replace(/\.(ts|js)$/,""):g(e,"game");const n={rawRoot:`${t.root}`,entry:e,dirname:f(e)};return{...t,...n}})),((t,e,s)=>{var o,r,i;const a=t=>(P(s||"game.json",t),!1);if(t.subPackages.length)for(let s=0;s<t.subPackages.length;s++){const{name:c,root:p,entry:u,dirname:l}=t.subPackages[s];if("string"!=typeof c)return a(`subPackages[${s}].name 字段类型需为 string`);if("string"!=typeof p)return a(`subPackages[${s}].root 字段类型需为 string`);if(!(null===(o=null==c?void 0:c.trim)||void 0===o?void 0:o.call(c)))return a(`subPackages[${s}].name 不能为空`);if(!(null===(r=null==p?void 0:p.trim)||void 0===r?void 0:r.call(p)))return a(`subPackages[${s}].root 不能为空`);if(!(null===(i=null==u?void 0:u.trim)||void 0===i?void 0:i.call(u)))return a(`subPackages[${s}].root 不能为 ${p}`);if("/"===l)return a(`subPackages[${s}].root 不能在根目录下 ${p}`);const h=g(e,u);if(!n.existsSync(`${h}.js`)&&!n.existsSync(`${h}.ts`))return a(`未找到 subPackages[${s}].root 对应的 ${u}.(js|ts)`);for(let e=s+1;e<t.subPackages.length;e++){const{name:n,entry:o,dirname:r}=t.subPackages[e];if(c===n)return a(`subPackages[${s}].name 和 subPackages[${e}].name 相同`);if(u===o)return a(`subPackages[${s}].root 和 subPackages[${e}].root 指向相同文件`);if(l===r)return a(`subPackages[${s}].root 和 subPackages[${e}].root 在同一目录下`);if(l.startsWith(`${r}/`)||r.startsWith(`${l}/`))return a(`subPackages[${s}].root 和 subPackages[${e}].root 目录层级存在包含关系`)}}return t.networkTimeout&&"object"!=typeof t.networkTimeout?a("networkTimeout 字段需为 object"):!t.workers||"workers"===t.workers||"object"==typeof t.workers||a("workers 字段需为 string | object")})(s,t,e)?{appJSON:s}:{appJSON:{pages:[],subPackages:[]}}};class L{constructor(t){this.project=t}}const U=(t,e)=>{const n=t.pages.find((t=>t.path===e))||{};return(null==n?void 0:n.usingComponents)?n.usingComponents:{}},G=(t,e)=>{let n=[];((null==t?void 0:t.subPackages)||[]).forEach((t=>{n=n.concat(t.pages)}));const s=n.find((t=>t.path===e))||{};return(null==s?void 0:s.usingComponents)||{}},H=t=>(null==t?void 0:t.usingComponents)||{};const K=(t,e)=>{var n;const s=t.componentsMap||{};return(null===(n=null==s?void 0:s[e])||void 0===n?void 0:n.usingComponents)||{}},Q=require("chokidar"),X={description:"项目配置文件",packOptions:{ignore:[]},appid:"testappid",miniprogramRoot:"."};class Y extends r.EventEmitter{constructor(t){super(),this._projectJson="project.config.json",this._appJson="app.json",this._extJson="ext.json",this._projectPath="",this._extJsonDir="",this._canUploadExtJson=!1,this._appMode=z,this._isLazyload=!1,this._customEntry="",this.jsonDependencies=[],this.onProjectConfigJsonChange=u((()=>{var t,e,n,s;const{projectConfig:r}=this.snapshot,i=w(this.projectJsonPath);this._projectJsonContent=i,this.snapshot.projectConfig=o.cloneDeep(i),this.emit("project-config-json-changed",{oldData:r,newData:i}),(null==r?void 0:r.libVersion)!==(null==i?void 0:i.libVersion)&&this.emit("lib-version-changed",{oldData:null==r?void 0:r.libVersion,newData:null==i?void 0:i.libVersion}),(null===(t=null==r?void 0:r.setting)||void 0===t?void 0:t.enableSimulatorV2)!==(null===(e=null==i?void 0:i.setting)||void 0===e?void 0:e.enableSimulatorV2)&&this.emit("simulator-mode-changed",{oldData:null===(n=null==r?void 0:r.setting)||void 0===n?void 0:n.enableSimulatorV2,newData:null===(s=null==i?void 0:i.setting)||void 0===s?void 0:s.enableSimulatorV2})}),100),this.onProjectPrivateJsonChange=u((()=>{const{customEntry:t}=this.snapshot;this.updateCustomEntry();const e=this._customEntry;this.snapshot.customEntry=e,this.emit("project-private-json-changed"),this.emit("custom-entry-changed",{oldData:t,newData:e})}),100),this.onAppJsonChange=u((()=>{const{appJson:t}=this.snapshot,e=w(this.entryJsonPath);this._appJsonContent=e,this.snapshot.appJson=o.cloneDeep(e),this.emit("app-json-changed",{oldData:t,newData:e})}),100),this.onExtJsonChange=u((()=>{const{extJson:t}=this.snapshot,e=w(this.extJsonPath).ext||{};this._extJsonContent=e,this.snapshot.extJson=o.cloneDeep(e),this.emit(F,{oldData:t,newData:e})}),100),this.getCustomEntry=t=>{var e,n,s,o;const r={pathName:"",query:"",entry:"",item:{}};try{if(!p.existsSync(t))return r;const i=w(t),a=(null===(n=null===(e=null==i?void 0:i.condition)||void 0===e?void 0:e.miniprogram)||void 0===n?void 0:n.current)||-1,c=null===(o=null===(s=null==i?void 0:i.condition)||void 0===s?void 0:s.miniprogram)||void 0===o?void 0:o.list;if(-1===a)return r;const u=c.filter((t=>t.id===a))[0];return u?(r.pathName=u.pathName,r.query=u.query,"halfPageNativeFunctionalized"===u.launchMode&&(r.query=u.query+="&runtime_mode=2"),r.entry=r.query?`${r.pathName}?${r.query}`:`${r.pathName}`,r):r}catch(t){return console.log("getCustomEntry error: ",t),r}},this.getCompileEntryPage=()=>{var t,e,n,s,o;const r=this.projectPrivateConfigJsonPath,i={path:"",query:"",launchMode:"default"};if(!p.existsSync(r))return i;const a=w(r),c=null===(e=null===(t=null==a?void 0:a.condition)||void 0===t?void 0:t.miniprogram)||void 0===e?void 0:e.current,u=null===(o=null===(s=null===(n=null==a?void 0:a.condition)||void 0===n?void 0:n.miniprogram)||void 0===s?void 0:s.list)||void 0===o?void 0:o.filter((t=>t.id===c))[0];return u?{path:u.pathName,query:u.query.trim(),launchMode:u.launchMode}:i};const{watch:e}=t;let n=t.projectPath;if(c.isAbsolute(n)||(n=c.join(i.cwd(),n)),this.checker=new L(this),this._projectPath=l(n),this._extJsonDir=p.existsSync(this.extJsonPath)?this.projectPath:"",this._appMode=p.existsSync(c.posix.join(this._projectPath,"game.json"))?V:z,this.jsonDependencieMap=new Set([c.normalize(this.entryJsonPath)]),this._isLazyload="requiredComponents"===this.appJsonContent.lazyCodeLoading,this.updateCustomEntry(),this._appMode===z){const{legacyAppJSON:t,appJSON:e}=W(this.projectPath,this.miniprogramDir,this.extJsonDir);this.appJSON=e,this.legacyAppJSON=t,this.updateAppJson()}else{const{appJSON:t}=I(this.projectPath);this.appJSON=t,this.legacyAppJSON={}}e&&this.watchProject()}get projectPath(){return this._projectPath}get projectJsonPath(){return c.resolve(this._projectPath,this._projectJson)}get miniprogramRoot(){return this.projectJsonContent.miniprogramRoot||""}get projectMiniprogramPath(){const t=l(c.join(this.projectPath,this.miniprogramRoot));return t.endsWith("/")?t.slice(0,-1):t}get miniprogramDir(){const t=l(c.join(this.projectPath,this.miniprogramRoot));return t.endsWith("/")?t.slice(0,-1):t}get appMode(){return this._appMode}get lazyload(){return this._isLazyload}get projectJsonContent(){return p.pathExistsSync(this.projectJsonPath)?(this._projectJsonContent||(this._projectJsonContent=w(this.projectJsonPath)),this._projectJsonContent):{}}set projectJsonContent(t){this._projectJsonContent=t,p.writeJSONSync(this.projectJsonPath,t,{spaces:2})}get projectPrivateConfigJsonPath(){return c.resolve(this._projectPath,"project.private.config.json")}get entryJson(){return this.appMode===z?"app.json":"game.json"}get entryJsonPath(){if(!p.existsSync(this.projectJsonPath))return"";const t=w(this.projectJsonPath);let e=".";return t.miniprogramRoot&&(e=t.miniprogramRoot),c.resolve(this._projectPath,e,this.entryJson)}get appJsonContent(){if(!this.entryJsonPath||!p.existsSync(this.entryJsonPath))throw new Error(`打开项目失败: ${this.entryJson}不存在`);return this._appJsonContent||(this._appJsonContent=w(this.entryJsonPath)),this._appJsonContent}get extJsonPath(){return c.resolve(this._projectPath,this._extJson)}get extJsonContent(){return this.extJsonPath&&p.existsSync(this.extJsonPath)?(this._extJsonContent||(this._extJsonContent=w(this.extJsonPath).ext||{}),this._extJsonContent):{}}get extJsonDir(){return this._extJsonDir}set extJsonDir(t){this.extJsonDir!==t&&(this._extJsonDir=t,this.emit(R))}get canUploadExtJson(){return this._canUploadExtJson}get customEntry(){return this._customEntry}get projectAppId(){let t="";try{t=this.projectJsonContent.appid}catch(t){console.log("get projectAppId error:",t)}if(!t)throw new Error("appid can not be empty!!!");return t}watchProject(){this.snapshot=o.cloneDeep({projectConfig:this.projectJsonContent,appJson:this.appJsonContent,extJson:this.extJsonContent,customEntry:this._customEntry});const t=Q.watch(this.projectPath,{persistent:!0,ignoreInitial:!0,ignored:/node_modules/});return t.on("change",(t=>{this.onFileChange("change",t)})).on("add",(t=>{this.onFileChange("add",t)})).on("unlink",(t=>{this.onFileChange("unlink",t)})),t}onFileChange(t,e){const n=c.relative(this.projectPath,e);"change"===t&&("project.config.json"===n?this.onProjectConfigJsonChange():"project.private.config.json"===n?this.onProjectPrivateJsonChange():"ext.json"===n?this.onExtJsonChange():"app.json"===n&&this.onAppJsonChange()),this.emit("onFileChange",{eventName:t,filePath:e,relativePath:n})}checkFileExist(){if(!this._projectPath)return;const t=this.projectJsonPath;p.existsSync(t)||p.writeJSONSync(this.projectJsonPath,X,{spaces:2})}updateCustomEntry(){const t=this.getCustomEntry(this.projectPrivateConfigJsonPath),e=(null==t?void 0:t.entry)||"";this._customEntry=e}get settings(){var t;return{minified:!0,urlCheck:!0,useNewCompiler:!1,enableV2:!1,...(null===(t=this.projectJsonContent)||void 0===t?void 0:t.setting)||{}}}changeCompileSetting(t){const e=this.projectJsonContent;e.setting?e.setting={...e.setting,...t}:e.setting=t,this.projectJsonContent=e}createDefaultProjectConfig(t){const e={description:"项目配置文件",setting:{urlCheck:!0,minified:!0},compileType:"miniprogram",libVersion:"latest",appid:"wx93e095ba089dbfb5",projectname:c.basename(t)},n=c.resolve(t,this._projectJson);p.writeJSONSync(n,e,{spaces:2})}changeExtJsonPermission(t){this._canUploadExtJson=t,t&&p.existsSync(this.extJsonPath)?this.extJsonDir=this.projectPath:this.extJsonDir=""}getSubPackages(){return this.appJSON.subPackages||[]}isFileInMainPkg(t){return this.getSubPackages().every((e=>!t.startsWith(`${e}/`)))}isFileInSubpackage(t){return this.getSubPackages().some((e=>t.startsWith(`${e}/`)))}getComponentsMap(){return this.appJSON.componentsMap||{}}getPages(){return this.appJSON.pages||[]}isPkgPage(t,e){let n=[];n="xhs-main"===t?this.appJsonContent.pages||[]:t.pages||[];const s=c.extname(e);return n.some((t=>`${t}${s}`===e))}getPageDependComponentPaths(t,e){const n=function(t){var e,n;if(!(null==t?void 0:t.subPackages)||!(null==t?void 0:t.subPackages.length))return!1;let s=!1;try{s=!("string"==typeof(null===(n=null===(e=null==t?void 0:t.subPackages)||void 0===e?void 0:e[0].pages)||void 0===n?void 0:n[0]))}catch(t){}return s}(this.appJSON),s=((t,e,n=!1,s=!0)=>{try{const o=new Set;let r={};r=s?{...n?{}:H(e),...U(e,t),...G(e,t)}:{...H(e),...U(e,t)};const i=t=>{for(const n in t)if(t[n]){const s=t[n];if(o.has(s))continue;o.add(s);const r=K(e,s);r&&Object.keys(r).length&&i(r)}};return i(r),Array.from(o)}catch(t){return console.error("parse page depend components has error happen"),[]}})(t,this.appJSON,e,n);return s}formatGameAppJSON(t){return t.map((t=>{let e=h(`${t.root}`).replace(/^\/+|\/+$/g,"");if(/\.(ts|js)$/.test(e)){const t=e.split("/").filter(Boolean);e=t.slice(0,t.length-1).join("/")}return{root:e}}))}static deSerialize(t){return new Y(t)}updateAppJson(){const{legacyAppJSON:t}=this;for(const e of t.pages)this.jsonDependencieMap.add(c.normalize(`${this.projectPath}/${e.path}.json`));for(const e of Object.keys(t.componentsMap))this.jsonDependencieMap.add(c.normalize(`${this.projectPath}/${e}.json`));this.jsonDependencies=Array.from(this.jsonDependencieMap)}}const Z={transformAppJson:W,transformGameJson:I,pureAppJSON:(t,e="v1")=>{var n,s;const r=o.cloneDeep(t);if("v1"===e&&(r.subPackages=(null===(n=r.subPackages)||void 0===n?void 0:n.map((t=>{const{entry:e,dirname:n,name:s,independent:o,rawRoot:r}=t;return{independent:o,root:n,path:e,rawRoot:r,name:s,pages:[{path:e}]}})))||[],r.pages=[{path:"/"}]),"v0"===e){const t=null===(s=r.subPackages)||void 0===s?void 0:s.map((t=>({path:t.entry})));Reflect.deleteProperty(r,"subPackages"),r.pages=[{path:"/"},...t]}return Reflect.deleteProperty(r,"subpackages"),r.compileType="minigame",r}};exports.Project=Y,exports.utils=Z;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IAppJSON } from '../../types';
|
|
2
2
|
export declare const PATH_REG: RegExp;
|
|
3
|
-
export declare const transformAppJson: (
|
|
3
|
+
export declare const transformAppJson: (_: string, miniprogramDir: string, extJsonPath?: string) => {
|
|
4
4
|
legacyAppJSON: any;
|
|
5
5
|
appJSON: IAppJSON;
|
|
6
6
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function validatePages(pages: any, emitError: Function): any;
|
|
2
|
+
export declare const isPackagesPathCrossed: (p1: any, p2: any) => boolean;
|
|
3
|
+
export declare function validateSubPackages(subPackages: any, pages: string[], emitError: Function): any;
|
|
4
|
+
export declare function validateWindow(window: any, emitError: Function): any;
|
|
5
|
+
export declare function validateTabBar(tabBar: any, emitError: Function): any;
|
|
6
|
+
export declare function validateUsingComponents(usingComponents: any, emitError: Function): any;
|
|
7
|
+
export declare function validateNetworkTimeout(networkTimeout: any, emitError: Function): any;
|
|
8
|
+
export declare function isObject(data: unknown): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xhs-mp-project",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"author": "",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"xhs-mp-utils": "1.
|
|
17
|
+
"xhs-mp-utils": "1.7.1",
|
|
18
18
|
"chokidar": "^3.6.0",
|
|
19
19
|
"fs-extra": "^11.2.0",
|
|
20
20
|
"lodash": "^4.17.21",
|