"use strict";function findAllDescendant(e,n){let t;t=Array.isArray(e)?e:[e];const s=t.slice(0),o=[],a=[];for(;s.length>0;){const e=s.pop();o.push(e),e.childModules.forEach(e=>{s.indexOf(e)<0&&o.indexOf(e)<0&&(s.push(e),e.type===n&&a.push(e))})}return a}function findModsByType(e,n){var t;return(null===(t=null==e?void 0:e.graph)||void 0===t?void 0:t.modules.filter(e=>e.type===n))||[]}function findModByTypeAndPath(e,n,t){var s;return null===(s=e.graph)||void 0===s?void 0:s.modules.find(e=>e.type===n&&e.path===t)}function findPageMods(e,n){return(findModsByType(e,"Page")||[]).filter(e=>n.includes(e.path.replace(/\.json$/,"")))}function findGlobalCompMods(e){const n=findModByTypeAndPath(e,"MainPackage","app.json");return(null==n?void 0:n.childModules.filter(e=>"Component"===e.type))||[]}function getAllSubpackagePath(e){return findModsByType(e,"SubPackage").map(e=>e.path)}function innerGetSortedJSFiles(e,n){const t=new Set,s=new Set,o=new Set,a=[];for(const n of e){const e=n.findChild("Js");e&&(n.config?o.add(e.path):s.add(e.path),t.add(e.path),a.push(e))}const i=findAllDescendant(e.concat(n),"Component");for(const e of i.concat(n)){const n=e.findChild("Js");n&&(o.add(n.path),t.add(n.path),a.push(n))}const l=findAllDescendant(a,"Js");for(const e of l){const n=e.path;t.add(n)}return{allFiles:Array.from(t),pageFiles:Array.from(s),componentFiles:Array.from(o)}}function groupBySubpackage(e,n){const t=[],s={};for(const o of e){const e=n.find(e=>o.startsWith(e));e?(s[e]||(s[e]=[]),s[e].push(o)):t.push(o)}return{main:t,subs:s}}function partialGetSubPkgSortedJSFiles(e,n,t){const s=findPageMods(e,n),{allFiles:o,pageFiles:a,componentFiles:i}=innerGetSortedJSFiles(s,[]),l=getAllSubpackagePath(e);return{allFiles:groupBySubpackage(o,l).subs[t]||[],pageFiles:groupBySubpackage(a,l).subs[t]||[],componentFiles:groupBySubpackage(i,l).subs[t]||[]}}function partialGetMainPkgSortedJSFiles(e,n){const t=findPageMods(e,n),s=findGlobalCompMods(e),{allFiles:o,pageFiles:a,componentFiles:i}=innerGetSortedJSFiles(t,s);let l=!1;const p=findModByTypeAndPath(e,"Js","app.js");if(p){l=!0,o.push(p.path);const e=findAllDescendant([p],"Js");for(const n of e){const e=n.path;o.indexOf(e)<0&&o.push(e)}}const c=getAllSubpackagePath(e);return{hasAppJS:l,allFiles:groupBySubpackage(o,c).main,pageFiles:groupBySubpackage(a,c).main,componentFiles:groupBySubpackage(i,c).main}}function partialWholePkgGetSortedJSFiles(e,n){const t=findPageMods(e,n),s=findGlobalCompMods(e),{allFiles:o,pageFiles:a,componentFiles:i}=innerGetSortedJSFiles(t,s);let l=!1;const p=findModByTypeAndPath(e,"Js","app.js");if(p){l=!0,o.push(p.path);const e=findAllDescendant([p],"Js");for(const n of e){const e=n.path;o.indexOf(e)<0&&o.push(e)}}return{hasAppJS:l,allFiles:o,pageFiles:a,componentFiles:i}}function innerGetResourceFiles(e,n){let t=[];for(const s of e){const e=findAllDescendant(s,n);t=t.concat(e.map(e=>e.path))}return t}function partialGetWxmlAndWxsFiles(e,n,t){const s=findPageMods(e,n),o=findGlobalCompMods(e),a=innerGetResourceFiles(s.concat(o),"Wxml"),i=innerGetResourceFiles(s.concat(o),"Wxs"),l=getAllSubpackagePath(e),p=groupBySubpackage(a,l),c=groupBySubpackage(i,l);return{wxmlFiles:t?p.main.concat(p.subs[t]||[]):p.main,wxsFiles:t?c.main.concat(c.subs[t]||[]):c.main}}function partialGetWxssFiles(e,n,t){const s=findPageMods(e,n),o=findGlobalCompMods(e),a=innerGetResourceFiles(s.concat(o),"Wxss"),i=findModByTypeAndPath(e,"Wxss","app.wxss");if(i&&!a.includes(i.path)){a.push(i.path);const e=findAllDescendant(i,"Wxss");for(const n of e)a.includes(n.path)||a.push(n.path)}const l=groupBySubpackage(a,getAllSubpackagePath(e));return t?l.main.concat(l.subs[t]||[]):l.main}function partialGetCodeFiles(e,n){var t;const s=new Set,o=findModByTypeAndPath(e,"MainPackage","app.json");s.add("app.json");const a=new Set;function i(e){switch(a.add(e),e.type){case"Page":case"Component":case"Wxml":case"Wxss":case"Wxs":case"Js":case"Config":s.add(e.path)}for(const n of e.childModules)a.has(n)||i(n)}for(const e of null==o?void 0:o.childModules)if("Page"===e.type)n.includes(e.path.replace(/\.json$/,""))&&i(e);else if("SubPackage"===e.type)for(const t of e.childModules)n.includes(t.path.replace(/\.json$/,""))&&i(t);else i(e);return(null===(t=process.env)||void 0===t?void 0:t.isDevtools)&&console.log("[partial-compile] compile",s),Array.from(s)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.findAllDescendant=findAllDescendant,exports.partialGetSubPkgSortedJSFiles=partialGetSubPkgSortedJSFiles,exports.partialGetMainPkgSortedJSFiles=partialGetMainPkgSortedJSFiles,exports.partialWholePkgGetSortedJSFiles=partialWholePkgGetSortedJSFiles,exports.partialGetWxmlAndWxsFiles=partialGetWxmlAndWxsFiles,exports.partialGetWxssFiles=partialGetWxssFiles,exports.partialGetCodeFiles=partialGetCodeFiles;