hackmud-script-manager 0.17.0 → 0.18.0-7338c14

Sign up to get free protection for your applications and to get access to all the features.
File without changes
package/bin/hsm.js CHANGED
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
- import e from"chalk";import{watch as o}from"chokidar";import s from"fs";import{homedir as t}from"os";import{resolve as n,basename as a,extname as c,dirname as i,relative as l}from"path";import{s as r}from"../constants-9bb78688.js";import{D as g,w as f}from"../writeFilePersistent-72dc81a3.js";import{generateTypeDeclaration as h}from"../generateTypeDeclaration.js";import{a as m}from"../assert-1556d989.js";import{syncMacros as p}from"../syncMacros.js";import{pull as u}from"../pull.js";import{c as d}from"../countHackmudCharacters-1e122984.js";const{readFile:b,rmdir:w,writeFile:k,mkdir:y}=s.promises,$=n(t(),".config"),j=n($,"hsm.json"),v=new Map,P=[];let C;const S=e.rgb(255,244,4),N=e.rgb(243,249,152),q=e.rgb(179,255,155),x=e.rgb(255,150,224),F=e.rgb(30,255,0),O=e.rgb(202,202,202),B=new g((e=>{let o=0;for(const s of e)o+=(o>>1)+o+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[S,N,q,x,F,O][o%6](e)}));for(const e of process.argv.slice(2))if("-"==e[0]){const[o,s]=e.split("=");let t=s;if(t)if("true"==t)t=!0;else if("false"==t)t=!1;else{const e=Number(t);isFinite(e)&&(t=e)}else t=!0;if("-"==e[1])v.set(o.slice(2),t);else for(const e of o.slice(1))v.set(e,t)}else P.push(e);function help(){switch(P[0]){case"config":switch(P[1]){case"get":console.log("hsm config get <key>");break;case"set":console.log("hsm config set <key> <value>");break;case"delete":console.log("hsm config delete <key>");break;default:console.log("hsm config <get, delete, set>")}break;case"push":console.log('hsm push <dir> [..."<script user>.<script name>"] [--skip-minify] [--mangle-names]');break;case"dev":case"watch":console.log(`hsm ${P[0]} <dir> [..."<script user>.<script name>"] [--skip-minify] [--mangle-names]`);break;case"pull":console.log("hsm pull <script user>.<script name>");break;case"minify":case"golf":console.log(`${a(process.argv[1])} ${P[0]} <target> [output]`);break;default:console.log("hsm <push, watch, pull, config, golf>")}}function version(){console.log("0.17.0")}async function getConfig(){return C||(C=await b(j,{encoding:"utf-8"}).then((e=>{let o;try{o=JSON.parse(e)}catch{return console.log("config file was corrupted, resetting"),{}}return o&&"object"==typeof o?o:(console.log("config file was corrupted, resetting"),{})}),(()=>(console.log(`creating config file at ${j}`),{}))))}function exploreObject(e,o,s=!1){for(const n of o){var t;e=s?"object"==typeof e[n]?e[n]:e[n]={}:null===(t=e)||void 0===t?void 0:t[n]}return e}function updateConfig(){if(C){const e=JSON.stringify(C,void 0,"\t");k(j,e).catch((async o=>{switch(o.code){case"EISDIR":await w(j);break;case"ENOENT":await y($);break;default:throw o}k(j,e)}))}}function onPushLogger({file:o,users:s,minLength:t,error:i}){i?console.log(`error "${e.bold(i.message)}" in ${e.bold(o)}`):console.log(`pushed ${e.bold(o)} to ${s.map((o=>e.bold(B.get(o)))).join(", ")} | ${e.bold(String(t))} chars | ${e.bold(`${n(C.hackmudPath,s[0],"scripts",a(o,c(o)))}.js`)}`)}(async()=>{if(v.get("version")||v.get("v"))version();else if(v.get("help")||v.get("h"))help();else{switch(P[0]){case"push":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=P[1];if(!o){console.error("specify the directory to watch"),help();break}const{push:s}=await import("../push.js"),t=e.hackmudPath,n=P.slice(2);n.length||n.push("*.*"),v.has("skip-minify")&&v.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");let a=v.get("force-quine-cheats");null!=a&&"boolean"!=typeof a&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),a=Boolean(a));(await s(o,t,{scripts:n,onPush:onPushLogger,minify:!v.get("skip-minify"),mangleNames:Boolean(v.get("mangle-names")),forceQuineCheats:a})).length||console.warn("couldn't find any scripts to push"),updateConfig()}break;case"dev":case"watch":{var s;if(!P[1]){console.error("specify the directory to watch"),help();break}const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const{watch:o}=await import("../watch.js"),t=P.slice(2);t.length||t.push("*.*"),v.has("skip-minify")&&v.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");let n=v.get("force-quine-cheats");null!=n&&"boolean"!=typeof n&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),n=Boolean(n)),o(P[1],e.hackmudPath,{scripts:t,onPush:onPushLogger,typeDeclarationPath:null===(s=v.get("type-declaration-path")||v.get("type-declaration")||v.get("dts")||v.get("gen-types"))||void 0===s?void 0:s.toString(),minify:!v.get("skip-minify"),mangleNames:Boolean(v.get("mangle-names")),onReady:()=>console.log("watching"),forceQuineCheats:n})}break;case"pull":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=P[1];if(!o){help();break}const s=P[2]||".",t=e.hackmudPath;try{await u(s,t,o)}catch{console.log("something went wrong, did you forget to #down the script?")}}break;case"sync-macros":{const{hackmudPath:e}=await getConfig();if(!e){console.log("you need to set hackmudPath in config before you can use this command");break}const{macrosSynced:o,usersSynced:s}=await p(e);console.log(`synced ${o} macros to ${s} users`)}break;case"generate-type-declaration":case"gen-type-declaration":case"gen-dts":case"gen-types":{const o=n(P[1]||"."),s=h(o,(await getConfig()).hackmudPath);let t=n(P[2]||"./player.d.ts");try{await k(t,s)}catch(e){if(m(e instanceof Error),"EISDIR"!=e.code)throw e;t=n(t,"player.d.ts"),await k(t,s)}console.log(`wrote type declaration to ${e.bold(t)}`)}break;case"config":switch(P[1]){case"get":P[2]?console.log(exploreObject(await getConfig(),P[2].split("."))):console.log(await getConfig());break;case"delete":if(P[2]){var t;const e=P[2].split("."),o=e.pop();if(!e.length){help();break}const s=await getConfig();null===(t=exploreObject(s,e))||void 0===t||delete t[o],console.log(s)}else console.log("Usage:\nhsm config delete <key>");break;case"set":if(P[2]&&P[3]){const e=P[2].split(".");if(!e.length){help();break}const o=e.pop(),s=await getConfig();if(e.length||"hackmudPath"!=o){let t=s;for(const o of e)"object"==typeof t[o]||(t[o]={}),t=t[o];t[o]=P[3]}else s.hackmudPath=n(P[3]);console.log(s)}else console.log("Usage:\nhsm config set <key> <value>");break;default:P[1]&&console.log("unknown command"),help()}break;case"help":case"h":help();break;case"version":case"v":version();break;case"golf":case"minify":{const s=P[1];if(!s){console.log(`Target required\nUsage: ${a(process.argv[1])} ${P[0]} <target> [output]`);break}const t=c(s);if(!r.includes(t)){console.log(`Unsupported file extension "${e.bold(t)}"\nSupported extensions are "${r.map((o=>e.bold(o))).join('", "')}"`);break}v.get("watch")?o(s,{awaitWriteFinish:{stabilityThreshold:100}}).on("ready",(()=>console.log(`watching ${s}`))).on("change",(()=>golfFile(s,t))):await golfFile(s,t)}break;default:P[0]&&console.log("unknown command"),help()}updateConfig()}async function golfFile(o,s){const{processScript:t}=await import("../processScript/index.js");await b(o,{encoding:"utf-8"}).then((async c=>{const r=a(o,s),g=r.endsWith(".src"),h=g?r.slice(0,-4):r;let m="UNKNOWN";"scripts"==a(n(o,".."))&&"hackmud"==a(n(o,"../../.."))&&(m=a(n(o,"../..")));const p=!v.get("skip-minify"),u=Boolean(v.get("mangle-names"));!p&&u&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");let b=v.get("force-quine-cheats");null!=b&&"boolean"!=typeof b&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),b=Boolean(b));const w=performance.now(),{script:k,warnings:y}=await t(c,{minify:p,scriptUser:m,scriptName:h,filePath:o,mangleNames:u,forceQuineCheats:b}),$=performance.now()-w;for(const{message:o,line:s}of y)console.log(`warning "${e.bold(o)}" on line ${e.bold(String(s))}`);let j;j=P[2]?P[2]:n(i(o),g?`${h}.js`:".js"==s?`${r}.min.js`:`${r}.js`);const C=d(k);await f(j,k).catch((async e=>{if(!P[2]||"EISDIR"!=e.code)throw e;j=n(j,`${a(o,s)}.js`),await f(j,k)})).then((()=>console.log(`wrote ${e.bold(C)} chars to ${e.bold(l(".",j))} | took ${Math.round(100*$)/100}ms`)),(e=>console.log(e.message)))}),(e=>console.log(e.message)))}})();
1
+ import e from"chalk";import{watch as o}from"chokidar";import s from"fs";import{homedir as t}from"os";import{resolve as a,basename as n,extname as i,dirname as r,relative as l}from"path";import{s as c}from"../transform-eee68ce3.js";import{g as p}from"../generateTypeDeclaration-8dd67882.js";import{a as g}from"../assert-22a7ef8a.js";import{p as f}from"../pull-9b44f235.js";import"../push-3c3e0dfc.js";import{s as m}from"../syncMacros-0bf3ed91.js";import"../watch-e580a6f9.js";import{D as h,w as u}from"../writeFilePersistent-0476afeb.js";import{c as d}from"../minify-fba250e4.js";import"@babel/traverse";import"@babel/types";import"../shared-eace5bd5.js";import"../index-73f8f8aa.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"../postprocess-164b44d3.js";import"../preprocess-67d17495.js";import"import-meta-resolve";import"../spliceString-0e6b5d6d.js";import"acorn";import"terser";const{readFile:b,rmdir:w,writeFile:y,mkdir:k}=s.promises,j=a(t(),".config"),v=a(j,"hsm.json"),$=new Map,P=[];let C;const S=e.rgb(255,244,4),N=e.rgb(243,249,152),x=e.rgb(179,255,155),q=e.rgb(255,150,224),F=e.rgb(30,255,0),O=e.rgb(202,202,202),B=new h((e=>{let o=0;for(const s of e)o+=(o>>1)+o+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[S,N,x,q,F,O][o%6](e)}));for(const e of process.argv.slice(2))if("-"==e[0]){const[o,s]=e.split("=");let t=s;if(t)if("true"==t)t=!0;else if("false"==t)t=!1;else{const e=Number(t);isFinite(e)&&(t=e)}else t=!0;if("-"==e[1])$.set(o.slice(2),t);else for(const e of o.slice(1))$.set(e,t)}else P.push(e);function help(){switch(P[0]){case"config":switch(P[1]){case"get":console.log("hsm config get <key>");break;case"set":console.log("hsm config set <key> <value>");break;case"delete":console.log("hsm config delete <key>");break;default:console.log("hsm config <get, delete, set>")}break;case"push":console.log('hsm push <dir> [..."<script user>.<script name>"] [--skip-minify] [--mangle-names]');break;case"dev":case"watch":console.log(`hsm ${P[0]} <dir> [..."<script user>.<script name>"] [--skip-minify] [--mangle-names]`);break;case"pull":console.log("hsm pull <script user>.<script name>");break;case"minify":case"golf":console.log(`${n(process.argv[1])} ${P[0]} <target> [output]`);break;default:console.log("hsm <push, watch, pull, config, golf>")}}function version(){console.log("0.18.0-7338c14")}async function getConfig(){return C||(C=await b(v,{encoding:"utf-8"}).then((e=>{let o;try{o=JSON.parse(e)}catch{return console.log("config file was corrupted, resetting"),{}}return o&&"object"==typeof o?o:(console.log("config file was corrupted, resetting"),{})}),(()=>(console.log(`creating config file at ${v}`),{}))))}function exploreObject(e,o,s=!1){for(const a of o){var t;e=s?"object"==typeof e[a]?e[a]:e[a]={}:null===(t=e)||void 0===t?void 0:t[a]}return e}function updateConfig(){if(C){const e=JSON.stringify(C,void 0,"\t");y(v,e).catch((async o=>{switch(o.code){case"EISDIR":await w(v);break;case"ENOENT":await k(j);break;default:throw o}y(v,e)}))}}function onPushLogger({file:o,users:s,minLength:t,error:r}){r?console.log(`error "${e.bold(r.message)}" in ${e.bold(o)}`):console.log(`pushed ${e.bold(o)} to ${s.map((o=>e.bold(B.get(o)))).join(", ")} | ${e.bold(String(t))} chars | ${e.bold(`${a(C.hackmudPath,s[0],"scripts",n(o,i(o)))}.js`)}`)}(async()=>{if($.get("version")||$.get("v"))version();else if($.get("help")||$.get("h"))help();else{switch(P[0]){case"push":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=P[1];if(!o){console.error("specify the directory to watch"),help();break}const{push:s}=await import("../push-3c3e0dfc.js"),t=e.hackmudPath,a=P.slice(2);a.length||a.push("*.*"),$.has("skip-minify")&&$.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");let n=$.get("force-quine-cheats");null!=n&&"boolean"!=typeof n&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),n=Boolean(n));(await s(o,t,{scripts:a,onPush:onPushLogger,minify:!$.get("skip-minify"),mangleNames:Boolean($.get("mangle-names")),forceQuineCheats:n})).length||console.warn("couldn't find any scripts to push"),updateConfig()}break;case"dev":case"watch":{var s;if(!P[1]){console.error("specify the directory to watch"),help();break}const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const{watch:o}=await import("../watch-e580a6f9.js"),t=P.slice(2);t.length||t.push("*.*"),$.has("skip-minify")&&$.has("mangle-names")&&console.warn("pointless specifying both --skip-minify and --mangle-names");let a=$.get("force-quine-cheats");null!=a&&"boolean"!=typeof a&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),a=Boolean(a)),o(P[1],e.hackmudPath,{scripts:t,onPush:onPushLogger,typeDeclarationPath:null===(s=$.get("type-declaration-path")||$.get("type-declaration")||$.get("dts")||$.get("gen-types"))||void 0===s?void 0:s.toString(),minify:!$.get("skip-minify"),mangleNames:Boolean($.get("mangle-names")),onReady:()=>console.log("watching"),forceQuineCheats:a})}break;case"pull":{const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const o=P[1];if(!o){help();break}const s=P[2]||".",t=e.hackmudPath;try{await f(s,t,o)}catch{console.log("something went wrong, did you forget to #down the script?")}}break;case"sync-macros":{const{hackmudPath:e}=await getConfig();if(!e){console.log("you need to set hackmudPath in config before you can use this command");break}const{macrosSynced:o,usersSynced:s}=await m(e);console.log(`synced ${o} macros to ${s} users`)}break;case"generate-type-declaration":case"gen-type-declaration":case"gen-dts":case"gen-types":{const o=a(P[1]||"."),s=await p(o,(await getConfig()).hackmudPath);let t=a(P[2]||"./player.d.ts");try{await y(t,s)}catch(e){if(g(e instanceof Error),"EISDIR"!=e.code)throw e;t=a(t,"player.d.ts"),await y(t,s)}console.log(`wrote type declaration to ${e.bold(t)}`)}break;case"config":switch(P[1]){case"get":P[2]?console.log(exploreObject(await getConfig(),P[2].split("."))):console.log(await getConfig());break;case"delete":if(P[2]){var t;const e=P[2].split("."),o=e.pop();if(!e.length){help();break}const s=await getConfig();null===(t=exploreObject(s,e))||void 0===t||delete t[o],console.log(s)}else console.log("Usage:\nhsm config delete <key>");break;case"set":if(P[2]&&P[3]){const e=P[2].split(".");if(!e.length){help();break}const o=e.pop(),s=await getConfig();if(e.length||"hackmudPath"!=o){let t=s;for(const o of e)"object"==typeof t[o]||(t[o]={}),t=t[o];t[o]=P[3]}else s.hackmudPath=a(P[3]);console.log(s)}else console.log("Usage:\nhsm config set <key> <value>");break;default:P[1]&&console.log("unknown command"),help()}break;case"help":case"h":help();break;case"version":case"v":version();break;case"golf":case"minify":{const s=P[1];if(!s){console.log(`Target required\nUsage: ${n(process.argv[1])} ${P[0]} <target> [output]`);break}const t=i(s);if(!c.includes(t)){console.log(`Unsupported file extension "${e.bold(t)}"\nSupported extensions are "${c.map((o=>e.bold(o))).join('", "')}"`);break}$.get("watch")?o(s,{awaitWriteFinish:{stabilityThreshold:100}}).on("ready",(()=>console.log(`watching ${s}`))).on("change",(()=>golfFile(s,t))):await golfFile(s,t)}break;default:P[0]&&console.log("unknown command"),help()}updateConfig()}async function golfFile(o,s){const{processScript:t}=await import("../index-73f8f8aa.js");await b(o,{encoding:"utf-8"}).then((async i=>{const c=n(o,s),p=c.endsWith(".src"),g=p?c.slice(0,-4):c;let f="UNKNOWN";"scripts"==n(a(o,".."))&&"hackmud"==n(a(o,"../../.."))&&(f=n(a(o,"../..")));const m=!$.get("skip-minify"),h=Boolean($.get("mangle-names"));!m&&h&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");let b=$.get("force-quine-cheats");null!=b&&"boolean"!=typeof b&&(console.warn("warning: `--force-quine-cheats` should be `true` or `false`"),b=Boolean(b));const w=performance.now(),{script:y,warnings:k}=await t(i,{minify:m,scriptUser:f,scriptName:g,filePath:o,mangleNames:h,forceQuineCheats:b}),j=performance.now()-w;for(const{message:o,line:s}of k)console.log(`warning "${e.bold(o)}" on line ${e.bold(String(s))}`);let v;v=P[2]?P[2]:a(r(o),p?`${g}.js`:".js"==s?`${c}.min.js`:`${c}.js`);const C=d(y);await u(v,y).catch((async e=>{if(!P[2]||"EISDIR"!=e.code)throw e;v=a(v,`${n(o,s)}.js`),await u(v,y)})).then((()=>console.log(`wrote ${e.bold(C)} chars to ${e.bold(l(".",v))} | took ${Math.round(100*j)/100}ms`)),(e=>console.log(e.message)))}),(e=>console.log(e.message)))}})();
@@ -0,0 +1 @@
1
+ import e from"fs";import{basename as t,resolve as n}from"path";const{readdir:s}=e.promises;async function generateTypeDeclaration(e,a){const i=new Set;if(a)for(const e of await s(a,{withFileTypes:!0}))e.isFile()&&e.name.endsWith(".key")&&i.add(t(e.name,".key"));const r=[],o=[],f={},c={};await Promise.all((await s(e,{withFileTypes:!0})).map((async a=>{if(a.isFile())a.name.endsWith(".ts")?a.name.endsWith(".d.ts")||r.push(t(a.name,".ts")):a.name.endsWith(".js")&&o.push(t(a.name,".js"));else if(a.isDirectory()){const r=[],o=[];f[a.name]=r,c[a.name]=o,i.add(a.name);for(const i of await s(n(e,a.name),{withFileTypes:!0}))i.isFile()&&(i.name.endsWith(".ts")?a.name.endsWith(".d.ts")||r.push(t(i.name,".ts")):i.name.endsWith(".js")&&o.push(t(i.name,".js")))}}))),e=n(e);let l="";for(const t of r)l+=`type $${t}$ = typeof import("${e}/${t}").default\n`;l+="\n";for(const t in f){const n=f[t];for(const s of n)l+=`type $${t}$${s}$ = typeof import("${e}/${t}/${s}").default\n`}l+="\ntype ArrayRemoveFirst<A> = A extends [ infer FirstItem, ...infer Rest ] ? Rest : never\n\ntype Subscript<T extends (...args: any) => any> =\n\t(...args: ArrayRemoveFirst<Parameters<T>>) => ReturnType<T> | ScriptFailure\n\ntype WildFullsec = Record<string, () => ScriptFailure> & {\n";for(const e of r)l+=`\t${e}: Subscript<$${e}$>\n`;for(const e of o)l+=`\t${e}: (...args: any) => any\n`;l+="}\n\ninterface PlayerFullsec {";let p=!0;for(const e of i){const t=f[e],n=c[e];if(t&&t.length||n&&n.length){if(p=!0,l+=`\n\t${e}: WildFullsec & {\n`,t)for(const n of t)l+=`\t\t${n}: Subscript<$${e}$${n}$>\n`;if(n)for(const e of n)l+=`\t\t${e}: (...args: any) => any\n`;l+="\t}"}else p&&(l+="\n",p=!1),l+=`\t${e}: WildFullsec`;l+="\n"}return l+="}\n",l}export{generateTypeDeclaration as g};
@@ -1 +1 @@
1
- import e from"fs";import{basename as t,resolve as n}from"path";const{readdir:s}=e.promises;async function generateTypeDeclaration(e,a){const i=new Set;if(a)for(const e of await s(a,{withFileTypes:!0}))e.isFile()&&e.name.endsWith(".key")&&i.add(t(e.name,".key"));const r=[],o=[],f={},c={};await Promise.all((await s(e,{withFileTypes:!0})).map((async a=>{if(a.isFile())a.name.endsWith(".ts")?a.name.endsWith(".d.ts")||r.push(t(a.name,".ts")):a.name.endsWith(".js")&&o.push(t(a.name,".js"));else if(a.isDirectory()){const r=[],o=[];f[a.name]=r,c[a.name]=o,i.add(a.name);for(const i of await s(n(e,a.name),{withFileTypes:!0}))i.isFile()&&(i.name.endsWith(".ts")?a.name.endsWith(".d.ts")||r.push(t(i.name,".ts")):i.name.endsWith(".js")&&o.push(t(i.name,".js")))}}))),e=n(e);let l="";for(const t of r)l+=`type $${t}$ = typeof import("${e}/${t}").default\n`;l+="\n";for(const t in f){const n=f[t];for(const s of n)l+=`type $${t}$${s}$ = typeof import("${e}/${t}/${s}").default\n`}l+="\ntype ArrayRemoveFirst<A> = A extends [ infer FirstItem, ...infer Rest ] ? Rest : never\n\ntype Subscript<T extends (...args: any) => any> =\n\t(...args: ArrayRemoveFirst<Parameters<T>>) => ReturnType<T> | ScriptFailure\n\ntype WildFullsec = Record<string, () => ScriptFailure> & {\n";for(const e of r)l+=`\t${e}: Subscript<$${e}$>\n`;for(const e of o)l+=`\t${e}: (...args: any) => any\n`;l+="}\n\ninterface PlayerFullsec {";let p=!0;for(const e of i){const t=f[e],n=c[e];if(t&&t.length||n&&n.length){if(p=!0,l+=`\n\t${e}: WildFullsec & {\n`,t)for(const n of t)l+=`\t\t${n}: Subscript<$${e}$${n}$>\n`;if(n)for(const e of n)l+=`\t\t${e}: (...args: any) => any\n`;l+="\t}"}else p&&(l+="\n",p=!1),l+=`\t${e}: WildFullsec`;l+="\n"}return l+="}\n",l}export{generateTypeDeclaration as default,generateTypeDeclaration};
1
+ export{g as default,g as generateTypeDeclaration}from"./generateTypeDeclaration-8dd67882.js";import"fs";import"path";
@@ -0,0 +1 @@
1
+ import e from"@babel/generator";import{parse as o}from"@babel/parser";import r from"@babel/plugin-proposal-class-properties";import a from"@babel/plugin-proposal-class-static-block";import s from"@babel/plugin-proposal-decorators";import l from"@babel/plugin-proposal-json-strings";import i from"@babel/plugin-proposal-logical-assignment-operators";import n from"@babel/plugin-proposal-nullish-coalescing-operator";import c from"@babel/plugin-proposal-numeric-separator";import u from"@babel/plugin-proposal-object-rest-spread";import f from"@babel/plugin-proposal-optional-catch-binding";import d from"@babel/plugin-proposal-optional-chaining";import b from"@babel/plugin-proposal-private-property-in-object";import g from"@babel/plugin-transform-exponentiation-operator";import h from"@babel/traverse";import y from"@babel/types";import w from"@rollup/plugin-babel";import k from"@rollup/plugin-commonjs";import x from"@rollup/plugin-json";import v from"@rollup/plugin-node-resolve";import{resolve as j}from"path";import S from"prettier";import{rollup as E}from"rollup";import{s as C,t as L}from"./transform-eee68ce3.js";export{t as transform}from"./transform-eee68ce3.js";import{m as $}from"./minify-fba250e4.js";export{m as minify}from"./minify-fba250e4.js";import{p as N}from"./postprocess-164b44d3.js";export{p as postprocess}from"./postprocess-164b44d3.js";import{p as I}from"./preprocess-67d17495.js";export{p as preprocess}from"./preprocess-67d17495.js";import{i as P,r as D}from"./shared-eace5bd5.js";import{a as _}from"./assert-22a7ef8a.js";import"acorn";import"terser";import"./spliceString-0e6b5d6d.js";import"import-meta-resolve";const{default:M}=w,{format:O}=S,{default:T}=e,{default:U}=h;async function processScript(e,{minify:t=!0,uniqueID:p=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),scriptUser:m="UNKNOWN",scriptName:h="UNKNOWN",filePath:w,mangleNames:S=!1,forceQuineCheats:W}={}){_(/^\w{11}$/.exec(p));const q=e;let V,F;const H=/^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(e);if(H)e=`export default ${e}`,({autocomplete:V}=H.groups);else for(const o of e.split("\n")){const e=/^\s*\/\/(?<commentContent>.+)/.exec(o);if(!e)break;const r=e.groups.commentContent.trim();if(r.startsWith("@autocomplete "))V=r.slice(14).trimStart();else if(r.startsWith("@seclevel ")){const e=r.slice(10).trimStart().toLowerCase();switch(e){case"fullsec":case"full":case"fs":case"4s":case"f":case"4":F=4;break;case"highsec":case"high":case"hs":case"3s":case"h":case"3":F=3;break;case"midsec":case"mid":case"ms":case"2s":case"m":case"2":F=2;break;case"lowsec":case"low":case"ls":case"1s":case"l":case"1":F=1;break;case"nullsec":case"null":case"ns":case"0s":case"n":case"0":F=0;break;default:throw new Error(`unrecognised seclevel "${e}"`)}}}_(/^\w{11}$/.exec(p));const z=[[s.default,{decoratorsBeforeExport:!0}],[r.default],[a.default],[b.default],[i.default],[c.default],[n.default],[d.default],[f.default],[l.default],[u.default],[g.default]];let K;if(w)if(K=j(w),w.endsWith(".ts"))z.push([(await import("@babel/plugin-transform-typescript")).default,{allowDeclareFields:!0,optimizeConstEnums:!0}]);else{const[e,o,r,a,t,p,s]=await Promise.all([import("@babel/plugin-proposal-do-expressions"),import("@babel/plugin-proposal-function-bind"),import("@babel/plugin-proposal-function-sent"),import("@babel/plugin-proposal-partial-application"),import("@babel/plugin-proposal-pipeline-operator"),import("@babel/plugin-proposal-throw-expressions"),import("@babel/plugin-proposal-record-and-tuple")]);z.push([e.default],[o.default],[r.default],[a.default],[t.default,{proposal:"hack",topicToken:"%"}],[p.default],[s.default,{syntaxType:"hash",importPolyfill:!0}])}else{K=`${p}.ts`;const[e,o,r,a,t,s,l,i]=await Promise.all([import("@babel/plugin-transform-typescript"),import("@babel/plugin-proposal-do-expressions"),import("@babel/plugin-proposal-function-bind"),import("@babel/plugin-proposal-function-sent"),import("@babel/plugin-proposal-partial-application"),import("@babel/plugin-proposal-pipeline-operator"),import("@babel/plugin-proposal-throw-expressions"),import("@babel/plugin-proposal-record-and-tuple")]);z.push([e.default,{allowDeclareFields:!0,optimizeConstEnums:!0}],[o.default],[r.default],[a.default],[t.default],[s.default,{proposal:"hack",topicToken:"%"}],[l.default],[i.default,{syntaxType:"hash",importPolyfill:!0}])}const Q=await E({input:K,plugins:[{name:"hackmud-script-manager",transform:async e=>(await I(e,{uniqueID:p})).code},M({babelHelpers:"bundled",plugins:z,configFile:!1,extensions:C}),k(),v({extensions:C}),x()],treeshake:{moduleSideEffects:!1}}),A=["NULLSEC","LOWSEC","MIDSEC","HIGHSEC","FULLSEC"];e=(await Q.generate({})).output[0].code;const{file:B,seclevel:G}=L(o(e,{sourceType:"module"}),q,{uniqueID:p,scriptUser:m,scriptName:h});if(null!=F&&G<F)throw new Error(`detected seclevel ${A[G]} is lower than stated seclevel ${A[F]}`);if(e=T(B).code,t?e=await $(B,{uniqueID:p,mangleNames:S,forceQuineCheats:W,autocomplete:V}):(U(B,{MemberExpression({node:e}){e.computed||(_("Identifier"==e.property.type),"prototype"==e.property.name?(e.computed=!0,e.property=y.stringLiteral("prototype")):"__proto__"==e.property.name?(e.computed=!0,e.property=y.stringLiteral("__proto__")):P(e.property.name)&&(e.computed=!0,e.property=y.stringLiteral(D(p,e.property.name))))},VariableDeclarator(e){!function renameVariables(o){switch(o.type){case"Identifier":P(o.name)&&e.scope.rename(o.name,`$${Math.floor(Math.random()*2**52).toString(36).padStart(11,"0")}`);break;case"ObjectPattern":for(const e of o.properties)_("ObjectProperty"==e.type),renameVariables(e.value);break;case"ArrayPattern":for(const e of o.elements)e&&renameVariables(e);break;default:throw new Error(`unknown lValue type "${o.type}"`)}}(e.node.id)},ObjectProperty({node:e}){"Identifier"==e.key.type&&P(e.key.name)&&(e.key=y.stringLiteral(D(p,e.key.name)),e.shorthand=!1)},StringLiteral({node:e}){e.value=D(p,e.value)},TemplateLiteral({node:e}){for(const o of e.quasis)o.value.cooked?(o.value.cooked=D(p,o.value.cooked),o.value.raw=o.value.cooked.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"$\\{")):o.value.raw=D(p,o.value.raw)},RegExpLiteral(e){e.node.pattern=D(p,e.node.pattern),delete e.node.extra}}),e=O(T(B,{comments:!1}).code,{parser:"babel",arrowParens:"avoid",semi:!1,trailingComma:"none"})),e=N(e,G,p),P(e))throw new Error('you found a weird edge case where I wasn\'t able to replace illegal strings like "SC$", please report thx');return{script:e,warnings:[]}}export{processScript as default,processScript};
package/index.js CHANGED
@@ -1 +1 @@
1
- export{s as supportedExtensions}from"./constants-9bb78688.js";export{generateTypeDeclaration}from"./generateTypeDeclaration.js";export{processScript}from"./processScript/index.js";export{pull}from"./pull.js";export{push}from"./push.js";export{syncMacros}from"./syncMacros.js";export{watch}from"./watch.js";import"fs";import"path";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./processScript/minify.js";import"acorn";import"terser";import"./processScript/shared.js";import"./assert-1556d989.js";import"./spliceString-2c6f214f.js";import"./countHackmudCharacters-1e122984.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";import"./writeFilePersistent-72dc81a3.js";import"chokidar";
1
+ export{s as supportedExtensions}from"./transform-eee68ce3.js";export{g as generateTypeDeclaration}from"./generateTypeDeclaration-8dd67882.js";export{processScript}from"./index-73f8f8aa.js";export{p as pull}from"./pull-9b44f235.js";export{push}from"./push-3c3e0dfc.js";export{s as syncMacros}from"./syncMacros-0bf3ed91.js";export{watch}from"./watch-e580a6f9.js";import"@babel/traverse";import"@babel/types";import"./shared-eace5bd5.js";import"./assert-22a7ef8a.js";import"fs";import"path";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./minify-fba250e4.js";import"acorn";import"terser";import"./spliceString-0e6b5d6d.js";import"./postprocess-164b44d3.js";import"./preprocess-67d17495.js";import"import-meta-resolve";import"./writeFilePersistent-0476afeb.js";import"chokidar";
@@ -0,0 +1 @@
1
+ import e from"@babel/generator";import t from"@babel/traverse";import r from"@babel/types";import{tokenizer as i,tokTypes as n}from"acorn";import*as a from"terser";import{g as o,i as s,r as p}from"./shared-eace5bd5.js";import{a as l}from"./assert-22a7ef8a.js";import{s as u}from"./spliceString-0e6b5d6d.js";function countHackmudCharacters(e){return e.replace(/\/\/.*/g,"").replace(/[ \t\n\r\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000]/g,"").length}const{default:c}=e,{default:f}=t;async function minify(e,{uniqueID:t="00000000000",mangleNames:i=!1,forceQuineCheats:n,autocomplete:d}={}){let m;if(l(/^\w{11}$/.exec(t)),f(e,{Program(e){m=e,e.skip()}}),m.scope.hasGlobal("_START"))for(const e of o("_START",m))e.replaceWith(r.identifier("_ST"));if(m.scope.hasGlobal("_TIMEOUT"))for(const e of o("_TIMEOUT",m))e.replaceWith(r.identifier("_TO"));const y=m.get("body.0");for(const e of[...y.node.params].reverse()){if("Identifier"==e.type){if(!y.scope.getBinding(e.name).referenced){y.node.params.pop();continue}}break}for(const e in m.scope.globals){if("arguments"==e||e.startsWith(`$${t}$`))continue;const i=o(e,m);if(!(5+e.length+i.length>=e.length*i.length)){for(const n of i)n.replaceWith(r.identifier(`_${t}_GLOBAL_${e}_`));y.node.body.body.unshift(r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_GLOBAL_${e}_`),r.identifier(e))]))}}const _=o(`$${t}$GLOBAL$`,m);if(_.length>3){for(const e of _)e.replaceWith(r.identifier(`_${t}_G_`));y.node.body.body.unshift(r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_G_`),r.identifier(`$${t}$GLOBAL$`))]))}const $=[];let g,E,b=!1;if(1!=n){const o=r.cloneNode(e);if(f(o,{MemberExpression({node:e}){e.computed||(l("Identifier"==e.property.type),"prototype"==e.property.name?(e.computed=!0,e.property=r.identifier(`_${t}_PROTOTYPE_PROPERTY_`)):"__proto__"==e.property.name?(e.computed=!0,e.property=r.identifier(`_${t}_PROTO_PROPERTY_`)):s(e.property.name)&&(e.computed=!0,e.property=r.stringLiteral(p(t,e.property.name))))},ObjectProperty({node:e}){"Identifier"==e.key.type&&s(e.key.name)&&(e.key=r.stringLiteral(p(t,e.key.name)),e.shorthand=!1)},StringLiteral({node:e}){e.value=p(t,e.value)},TemplateLiteral({node:e}){for(const r of e.quasis)r.value.cooked?(r.value.cooked=p(t,r.value.cooked),r.value.raw=r.value.cooked.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"$\\{")):r.value.raw=p(t,r.value.raw)},RegExpLiteral(e){e.node.pattern=p(t,e.node.pattern),delete e.node.extra}}),g=(await a.minify(c(o).code,{ecma:2015,compress:{passes:1/0,unsafe:!0,unsafe_arrows:!0,unsafe_comps:!0,unsafe_symbols:!0,unsafe_methods:!0,unsafe_proto:!0,unsafe_regexp:!0,unsafe_undefined:!0,sequences:!1},format:{semicolons:!1},keep_classnames:!i,keep_fnames:!i})).code.replace(new RegExp(`_${t}_PROTOTYPE_PROPERTY_`,"g"),'"prototype"').replace(new RegExp(`_${t}_PROTO_PROPERTY_`,"g"),'"__proto__"'),d&&(g=u(g,`//${d}\n`,getFunctionBodyStart(g)+1)),0==n)return g}let h,v=!1;{const i=[];f(e,{FunctionDeclaration(e){e.traverse({Function(e){"CallExpression"!=e.parent.type&&"callee"!=e.parentKey&&e.skip()},Loop(e){e.skip()},ObjectExpression(e){const i={};parseObjectExpression(e.node,i)&&e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${$.push(i)-1}_`))},ArrayExpression(e){const i=[];parseArrayExpression(e.node,i)&&e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${$.push(i)-1}_`))}}),e.traverse({TemplateLiteral(e){if("TaggedTemplateExpression"==e.parent.type)return;const t=e.node;let i=r.stringLiteral(t.quasis[0].value.cooked);for(let e=0;e<t.expressions.length;e++){const n=t.expressions[e],a=t.quasis[e+1];i=r.binaryExpression("+",i,n),a.value.cooked&&(i=r.binaryExpression("+",i,r.stringLiteral(a.value.cooked)))}e.replaceWith(i)},MemberExpression({node:e}){e.computed||(l("Identifier"==e.property.type),e.property.name.length<3||(e.computed=!0,e.property=r.stringLiteral(e.property.name)))},UnaryExpression(e){if("void"==e.node.operator)"NumericLiteral"!=e.node.argument.type||e.node.argument.value||(e.replaceWith(r.identifier(`_${t}_UNDEFINED_`)),b=!0);else if("-"==e.node.operator&&"NumericLiteral"==e.node.argument.type){const n=-e.node.argument.value;i.push((async()=>{if((await minifyNumber(n)).length<=3)return;"key"==e.parentKey&&"ObjectProperty"==e.parent.type&&(e.parent.computed=!0);let i=$.indexOf(n);-1==i&&(i+=$.push(n)),e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${i}_`))})()),e.skip()}},NullLiteral(e){let i=$.indexOf(null);-1==i&&(i+=$.push(null)),e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${i}_`))},NumericLiteral(e){i.push((async()=>{if((await minifyNumber(e.node.value)).length<=3)return;"key"==e.parentKey&&"ObjectProperty"==e.parent.type&&(e.parent.computed=!0);let i=$.indexOf(e.node.value);-1==i&&(i+=$.push(e.node.value)),e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${i}_`))})())},StringLiteral(e){if(e.node.value=p(t,e.node.value),JSON.stringify(e.node.value).includes("\\u00")||e.toString().length<4)return;"key"==e.parentKey&&"ObjectProperty"==e.parent.type&&(e.parent.computed=!0);let i=$.indexOf(e.node.value);-1==i&&(i+=$.push(e.node.value)),e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${i}_`))},ObjectProperty({node:e}){if(e.computed||"Identifier"!=e.key.type||e.key.name.length<4)return;let i=$.indexOf(e.key.name);-1==i&&(i+=$.push(e.key.name)),e.computed=!0,e.key=r.identifier(`_${t}_JSON_VALUE_${i}_`)},RegExpLiteral(e){e.node.pattern=p(t,e.node.pattern),delete e.node.extra}}),e.skip()}}),await Promise.all(i);const n=e.program.body[0];if(l("FunctionDeclaration"==n.type),$.length)if(v=!0,1==$.length)if("string"!=typeof $[0]||$[0].includes("\n")||$[0].includes("\t")){const e=r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_JSON_VALUE_0_`),r.callExpression(r.memberExpression(r.identifier("JSON"),r.identifier("parse")),[r.memberExpression(r.taggedTemplateExpression(r.memberExpression(r.callExpression(r.identifier(`$${t}$SUBSCRIPT$scripts$quine$`),[]),r.identifier("split")),r.templateLiteral([r.templateElement({raw:"\t",cooked:"\t"},!0)],[])),r.identifier(`$${t}$SPLIT_INDEX$`),!0)]))]);b&&e.declarations.push(r.variableDeclarator(r.identifier(`_${t}_UNDEFINED_`))),n.body.body.unshift(e),E=JSON.stringify($[0])}else{const e=r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_JSON_VALUE_0_`),r.memberExpression(r.taggedTemplateExpression(r.memberExpression(r.callExpression(r.identifier(`$${t}$SUBSCRIPT$scripts$quine$`),[]),r.identifier("split")),r.templateLiteral([r.templateElement({raw:"\t",cooked:"\t"},!0)],[])),r.identifier(`$${t}$SPLIT_INDEX$`),!0))]);b&&e.declarations.push(r.variableDeclarator(r.identifier(`_${t}_UNDEFINED_`))),n.body.body.unshift(e),E=$[0]}else{const e=r.variableDeclaration("let",[r.variableDeclarator(r.arrayPattern($.map(((e,i)=>r.identifier(`_${t}_JSON_VALUE_${i}_`)))),r.callExpression(r.memberExpression(r.identifier("JSON"),r.identifier("parse")),[r.memberExpression(r.taggedTemplateExpression(r.memberExpression(r.callExpression(r.identifier(`$${t}$SUBSCRIPT$scripts$quine$`),[]),r.identifier("split")),r.templateLiteral([r.templateElement({raw:"\t",cooked:"\t"},!0)],[])),r.identifier(`$${t}$SPLIT_INDEX$`),!0)]))]);b&&e.declarations.push(r.variableDeclarator(r.identifier(`_${t}_UNDEFINED_`))),n.body.body.unshift(e),E=JSON.stringify($)}else b&&n.body.body.unshift(r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_UNDEFINED_`))]));h=c(e).code}return h=(await a.minify(h,{ecma:2015,compress:{passes:1/0,unsafe:!0,unsafe_arrows:!0,unsafe_comps:!0,unsafe_symbols:!0,unsafe_methods:!0,unsafe_proto:!0,unsafe_regexp:!0,unsafe_undefined:!0,sequences:!1},format:{semicolons:!1},keep_classnames:!i,keep_fnames:!i})).code||"",null!=E&&(h=u(h,`${d?`//${d}\n`:""}\n//\t${E}\t\n`,getFunctionBodyStart(h)+1),h=h.replace(`$${t}$SPLIT_INDEX$`,await minifyNumber(h.split("\t").findIndex((e=>e==E))))),1==n?h:(l(g),countHackmudCharacters(g)<=countHackmudCharacters(h)+Number(v)?g:h)}function parseObjectExpression(e,t){if(!e.properties.length)return!1;for(const r of e.properties){if("ObjectProperty"!=r.type||r.computed)return!1;if(l("Identifier"==r.key.type||"NumericLiteral"==r.key.type||"StringLiteral"==r.key.type),"ArrayExpression"==r.value.type){const e=[];if(!parseArrayExpression(r.value,e))return!1;t["Identifier"==r.key.type?r.key.name:r.key.value]=e}else if("ObjectExpression"==r.value.type){const e={};if(!parseObjectExpression(r.value,e))return!1;t["Identifier"==r.key.type?r.key.name:r.key.value]=e}else if("NullLiteral"==r.value.type)t["Identifier"==r.key.type?r.key.name:r.key.value]=null;else if("BooleanLiteral"==r.value.type||"NumericLiteral"==r.value.type||"StringLiteral"==r.value.type)t["Identifier"==r.key.type?r.key.name:r.key.value]=r.value.value;else{if("TemplateLiteral"!=r.value.type||r.value.expressions.length)return!1;t["Identifier"==r.key.type?r.key.name:r.key.value]=r.value.quasis[0].value.cooked}}return!0}function parseArrayExpression(e,t){if(!e.elements.length)return!1;for(const r of e.elements){if(!r)return!1;if("ArrayExpression"==r.type){const e=[];if(!parseArrayExpression(r,e))return!1;e.push(e)}else if("ObjectExpression"==r.type){const e={};if(!parseObjectExpression(r,e))return!1;t.push(e)}else if("NullLiteral"==r.type)t.push(null);else if("BooleanLiteral"==r.type||"NumericLiteral"==r.type||"StringLiteral"==r.type)t.push(r.value);else{if("TemplateLiteral"!=r.type||r.expressions.length)return!1;t.push(r.quasis[0].value.cooked)}}return!0}async function minifyNumber(e){return/\$\((?<number>.+)\)/.exec((await a.minify(`$(${e})`,{ecma:2015})).code).groups.number}function getFunctionBodyStart(e){const t=i(e,{ecmaVersion:2015});t.getToken(),t.getToken(),t.getToken();let r=1;for(;r;){const e=t.getToken();e.type==n.parenL?r++:e.type==n.parenR&&r--}return t.getToken().start}export{countHackmudCharacters as c,minify as m};
package/package.json CHANGED
@@ -1,124 +1,125 @@
1
1
  {
2
- "name": "hackmud-script-manager",
3
- "version": "0.17.0",
4
- "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
- "keywords": [
6
- "api",
7
- "command-line",
8
- "script",
9
- "manager",
10
- "minification",
11
- "minifier",
12
- "hackmd",
13
- "hackmud",
14
- "javascipt",
15
- "typescipt",
16
- "typescript-support",
17
- "golf",
18
- "golfer"
19
- ],
20
- "homepage": "https://github.com/samualtnorman/hackmud-script-manager#readme",
21
- "bugs": "https://github.com/samualtnorman/hackmud-script-manager/issues",
22
- "license": "GPL-3.0-or-later",
23
- "author": "Samual Norman",
24
- "main": "index.js",
25
- "repository": {
26
- "type": "git",
27
- "url": "https://github.com/samualtnorman/hackmud-script-manager.git"
28
- },
29
- "dependencies": {
30
- "@babel/core": "^7.16.0",
31
- "@babel/generator": "^7.16.0",
32
- "@babel/parser": "^7.16.4",
33
- "@babel/plugin-proposal-class-properties": "^7.16.0",
34
- "@babel/plugin-proposal-class-static-block": "^7.16.0",
35
- "@babel/plugin-proposal-decorators": "^7.16.4",
36
- "@babel/plugin-proposal-do-expressions": "^7.16.0",
37
- "@babel/plugin-proposal-function-bind": "^7.16.0",
38
- "@babel/plugin-proposal-function-sent": "^7.16.0",
39
- "@babel/plugin-proposal-json-strings": "^7.16.0",
40
- "@babel/plugin-proposal-logical-assignment-operators": "^7.16.0",
41
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
42
- "@babel/plugin-proposal-numeric-separator": "^7.16.0",
43
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
44
- "@babel/plugin-proposal-optional-catch-binding": "^7.16.0",
45
- "@babel/plugin-proposal-optional-chaining": "^7.16.0",
46
- "@babel/plugin-proposal-partial-application": "^7.16.0",
47
- "@babel/plugin-proposal-pipeline-operator": "^7.16.0",
48
- "@babel/plugin-proposal-private-property-in-object": "^7.16.0",
49
- "@babel/plugin-proposal-record-and-tuple": "^7.16.0",
50
- "@babel/plugin-proposal-throw-expressions": "^7.16.0",
51
- "@babel/plugin-transform-exponentiation-operator": "^7.16.0",
52
- "@babel/plugin-transform-typescript": "^7.16.1",
53
- "@babel/traverse": "^7.16.3",
54
- "@babel/types": "^7.16.0",
55
- "@bloomberg/record-tuple-polyfill": "^0.0.4",
56
- "@rollup/plugin-babel": "^5.3.0",
57
- "@rollup/plugin-commonjs": "^21.0.1",
58
- "@rollup/plugin-json": "^4.1.0",
59
- "@rollup/plugin-node-resolve": "^13.0.6",
60
- "acorn": "^8.5.0",
61
- "chalk": "^5.0.0",
62
- "chokidar": "^3.5.2",
63
- "import-meta-resolve": "^1.1.1",
64
- "prettier": "^2.4.1",
65
- "proxy-polyfill": "^0.3.2",
66
- "rollup": "^2.60.0",
67
- "terser": "^5.10.0"
68
- },
69
- "devDependencies": {
70
- "@babel/preset-env": "^7.16.4",
71
- "@babel/preset-typescript": "^7.16.0",
72
- "@samual/lib": "^0.3.0",
73
- "@types/babel__core": "^7.1.16",
74
- "@types/node": "^12.20.37",
75
- "@types/prettier": "^2.4.2",
76
- "@types/semver": "^7.3.9",
77
- "@typescript-eslint/eslint-plugin": "^5.8.0",
78
- "@typescript-eslint/parser": "^5.8.1",
79
- "eslint": "^8.5.0",
80
- "eslint-plugin-array-func": "^3.1.7",
81
- "eslint-plugin-eslint-comments": "^3.2.0",
82
- "eslint-plugin-optimize-regex": "^1.2.1",
83
- "eslint-plugin-regexp": "^1.5.1",
84
- "eslint-plugin-unicorn": "^41.0.0",
85
- "eslint-plugin-write-good-comments": "^0.1.3",
86
- "latest-version": "^6.0.0",
87
- "rollup-plugin-preserve-shebang": "^1.0.1",
88
- "rollup-plugin-terser": "^7.0.2",
89
- "semver": "^7.3.5",
90
- "typescript": "^4.5.2"
91
- },
92
- "optionalDependencies": {
93
- "deasync": "^0.1.24"
94
- },
95
- "engines": {
96
- "node": "^12.20 || >=14"
97
- },
98
- "types": "index.d.ts",
99
- "type": "module",
100
- "exports": {
101
- ".": {
102
- "import": "./index.js",
103
- "require": "./index.cjs"
104
- },
105
- "./*": "./*",
106
- "./generateTypeDeclaration": "./generateTypeDeclaration.js",
107
- "./index": "./index.js",
108
- "./pull": "./pull.js",
109
- "./push": "./push.js",
110
- "./syncMacros": "./syncMacros.js",
111
- "./watch": "./watch.js",
112
- "./bin/hsm": "./bin/hsm.js",
113
- "./processScript/index": "./processScript/index.js",
114
- "./processScript": "./processScript/index.js",
115
- "./processScript/minify": "./processScript/minify.js",
116
- "./processScript/postprocess": "./processScript/postprocess.js",
117
- "./processScript/preprocess": "./processScript/preprocess.js",
118
- "./processScript/shared": "./processScript/shared.js",
119
- "./processScript/transform": "./processScript/transform.js"
120
- },
121
- "bin": {
122
- "hsm": "./bin/hsm.js"
123
- }
2
+ "name": "hackmud-script-manager",
3
+ "version": "0.18.0-7338c14",
4
+ "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
+ "keywords": [
6
+ "api",
7
+ "command-line",
8
+ "script",
9
+ "manager",
10
+ "minification",
11
+ "minifier",
12
+ "hackmd",
13
+ "hackmud",
14
+ "javascipt",
15
+ "typescipt",
16
+ "typescript-support",
17
+ "golf",
18
+ "golfer"
19
+ ],
20
+ "homepage": "https://github.com/samualtnorman/hackmud-script-manager#readme",
21
+ "bugs": "https://github.com/samualtnorman/hackmud-script-manager/issues",
22
+ "license": "GPL-3.0-or-later",
23
+ "author": "Samual Norman",
24
+ "main": "index.js",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/samualtnorman/hackmud-script-manager.git"
28
+ },
29
+ "dependencies": {
30
+ "@babel/core": "^7.16.0",
31
+ "@babel/generator": "^7.16.0",
32
+ "@babel/parser": "^7.16.4",
33
+ "@babel/plugin-proposal-class-properties": "^7.16.0",
34
+ "@babel/plugin-proposal-class-static-block": "^7.16.0",
35
+ "@babel/plugin-proposal-decorators": "^7.16.4",
36
+ "@babel/plugin-proposal-do-expressions": "^7.16.0",
37
+ "@babel/plugin-proposal-function-bind": "^7.16.0",
38
+ "@babel/plugin-proposal-function-sent": "^7.16.0",
39
+ "@babel/plugin-proposal-json-strings": "^7.16.0",
40
+ "@babel/plugin-proposal-logical-assignment-operators": "^7.16.0",
41
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
42
+ "@babel/plugin-proposal-numeric-separator": "^7.16.0",
43
+ "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
44
+ "@babel/plugin-proposal-optional-catch-binding": "^7.16.0",
45
+ "@babel/plugin-proposal-optional-chaining": "^7.16.0",
46
+ "@babel/plugin-proposal-partial-application": "^7.16.0",
47
+ "@babel/plugin-proposal-pipeline-operator": "^7.16.0",
48
+ "@babel/plugin-proposal-private-property-in-object": "^7.16.0",
49
+ "@babel/plugin-proposal-record-and-tuple": "^7.16.0",
50
+ "@babel/plugin-proposal-throw-expressions": "^7.16.0",
51
+ "@babel/plugin-transform-exponentiation-operator": "^7.16.0",
52
+ "@babel/plugin-transform-typescript": "^7.16.1",
53
+ "@babel/traverse": "^7.16.3",
54
+ "@babel/types": "^7.16.0",
55
+ "@bloomberg/record-tuple-polyfill": "^0.0.4",
56
+ "@rollup/plugin-babel": "^5.3.0",
57
+ "@rollup/plugin-commonjs": "^22.0.0",
58
+ "@rollup/plugin-json": "^4.1.0",
59
+ "@rollup/plugin-node-resolve": "^13.0.6",
60
+ "acorn": "^8.5.0",
61
+ "chalk": "^5.0.0",
62
+ "chokidar": "^3.5.2",
63
+ "import-meta-resolve": "^1.1.1",
64
+ "prettier": "^2.4.1",
65
+ "proxy-polyfill": "^0.3.2",
66
+ "rollup": "^2.60.0",
67
+ "terser": "^5.10.0"
68
+ },
69
+ "devDependencies": {
70
+ "@babel/preset-env": "^7.16.4",
71
+ "@babel/preset-typescript": "^7.16.0",
72
+ "@samual/lib": "^0.3.0",
73
+ "@types/babel__core": "^7.1.16",
74
+ "@types/babel__generator": "^7.6.4",
75
+ "@types/babel__traverse": "^7.17.1",
76
+ "@types/node": "14",
77
+ "@types/prettier": "^2.4.2",
78
+ "@types/semver": "^7.3.9",
79
+ "@typescript-eslint/eslint-plugin": "^5.8.0",
80
+ "@typescript-eslint/parser": "^5.8.1",
81
+ "eslint": "^8.5.0",
82
+ "eslint-plugin-array-func": "^3.1.7",
83
+ "eslint-plugin-eslint-comments": "^3.2.0",
84
+ "eslint-plugin-optimize-regex": "^1.2.1",
85
+ "eslint-plugin-regexp": "^1.5.1",
86
+ "eslint-plugin-unicorn": "^42.0.0",
87
+ "latest-version": "^6.0.0",
88
+ "rollup-plugin-preserve-shebang": "^1.0.1",
89
+ "rollup-plugin-terser": "^7.0.2",
90
+ "semver": "^7.3.5",
91
+ "typescript": "^4.5.2"
92
+ },
93
+ "optionalDependencies": {
94
+ "deasync": "^0.1.24"
95
+ },
96
+ "engines": {
97
+ "node": ">=14"
98
+ },
99
+ "types": "index.d.ts",
100
+ "type": "module",
101
+ "exports": {
102
+ ".": {
103
+ "import": "./index.js",
104
+ "require": "./index.cjs"
105
+ },
106
+ "./*": "./*",
107
+ "./generateTypeDeclaration": "./generateTypeDeclaration.js",
108
+ "./index": "./index.js",
109
+ "./pull": "./pull.js",
110
+ "./push": "./push.js",
111
+ "./syncMacros": "./syncMacros.js",
112
+ "./watch": "./watch.js",
113
+ "./bin/hsm": "./bin/hsm.js",
114
+ "./processScript/index": "./processScript/index.js",
115
+ "./processScript": "./processScript/index.js",
116
+ "./processScript/minify": "./processScript/minify.js",
117
+ "./processScript/postprocess": "./processScript/postprocess.js",
118
+ "./processScript/preprocess": "./processScript/preprocess.js",
119
+ "./processScript/shared": "./processScript/shared.js",
120
+ "./processScript/transform": "./processScript/transform.js"
121
+ },
122
+ "bin": {
123
+ "hsm": "./bin/hsm.js"
124
+ }
124
125
  }
@@ -0,0 +1 @@
1
+ function postprocess($,e,p){return $.replace(/^function\s*\w+\(/,"function(").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$SC_DOLLAR\\$`,"g"),"S\\C$").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$DB_DOLLAR\\$`,"g"),"D\\B$").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$D\\$`,"g"),"_\\_D_S").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$FMCL\\$`,"g"),"_\\_FMCL_").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$G\\$`,"g"),"_\\_G_").replace(new RegExp(`\\$${p}\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`,"g"),`#${"nlmhf"[e]}s.$1.$2`).replace(new RegExp(`\\$${p}\\$DEBUG\\$`,"g"),"#D").replace(new RegExp(`\\$${p}\\$FMCL\\$`,"g"),"#FMCL").replace(new RegExp(`\\$${p}\\$GLOBAL\\$`,"g"),"#G").replace(new RegExp(`\\$${p}\\$DB\\$(\\w+)\\$`,"g"),"#db.$1").replace(new RegExp(`\\$${p}\\$SLASH_SLASH\\$`,"g"),"/\\/").replace(new RegExp(`\\$${p}\\$NOT_A_SUBSCRIPT\\$(#[\\w\\.]+)\\(\\$`,"g"),"$1\\(").replace(new RegExp(`\\$${p}\\$NOT_A_DB_CALL\\$(\\w+)\\$`,"g"),"#db.$1\\(").replace(new RegExp(`\\$${p}\\$NOT_A_DEBUG_CALL\\$`,"g"),"#D\\(").replace(new RegExp(`\\$${p}\\$NOT_FMCL\\$`,"g"),"#\\FMCL").replace(new RegExp(`\\$${p}\\$NOT_G\\$`,"g"),"#\\G")}export{postprocess as p};
@@ -0,0 +1 @@
1
+ import e from"@babel/generator";import{parse as o}from"@babel/parser";import r from"@babel/traverse";import i from"@babel/types";import{resolve as t}from"import-meta-resolve";import{a as s}from"./assert-22a7ef8a.js";import{s as p}from"./spliceString-0e6b5d6d.js";const{default:l}=r,{default:n}=e;async function preprocess(e,{uniqueID:r="00000000000"}={}){s(/^\w{11}$/.test(r));const a=e;let c,f,d;do{c=e.length,e=e.replace(/^\s+/,"").replace(/^\/\/.*/,"").replace(/^\/\*[\s\S]*?\*\//,"")}while(e.length!=c);for(e=e.replace(/^function\s*\(/,"export default function (");;){let i;try{f=o(e,{plugins:["typescript",["decorators",{decoratorsBeforeExport:!0}],"doExpressions","functionBind","functionSent","partialApplication",["pipelineOperator",{proposal:"hack",topicToken:"%"}],"throwExpressions",["recordAndTuple",{syntaxType:"hash"}],"classProperties","classPrivateProperties","classPrivateMethods","logicalAssignment","numericSeparator","nullishCoalescingOperator","optionalChaining","optionalCatchBinding","objectRestSpread"],sourceType:"module"});break}catch(e){s(e instanceof SyntaxError),i=e}var m;if("BABEL_PARSER_SYNTAX_ERROR"!=i.code||"PrivateInExpectedIn"!=i.reasonCode)throw console.log(null===(m=/.+/.exec(e.slice(i.pos)))||void 0===m?void 0:m[0]),i;const t=e.slice(i.pos);let l;if(l=/^#[0-4fhmln]s\.scripts\.quine\(\)/.exec(t))e=p(e,JSON.stringify(a),i.pos,l[0].length);else if(l=/^#[0-4fhmln]?s\./.exec(t))e=p(e,"$",i.pos,1);else if(l=/^#D[^\w$]/.exec(t))e=p(e,"$",i.pos,1);else if(l=/^#FMCL/.exec(t))e=p(e,`$${r}$FMCL$`,i.pos,l[0].length);else if(l=/^#G/.exec(t))e=p(e,`$${r}$GLOBAL$`,i.pos,l[0].length);else{if(!(l=/^#db\./.exec(t)))throw i;e=p(e,"$",i.pos,1)}}l(f,{Program(e){d=e,e.skip()}});const u=d.scope.hasGlobal("Record"),h=d.scope.hasGlobal("Tuple");return(u||h)&&f.program.body.unshift(i.importDeclaration(u?h?[i.importSpecifier(i.identifier("Record"),i.identifier("Record")),i.importSpecifier(i.identifier("Tuple"),i.identifier("Tuple"))]:[i.importSpecifier(i.identifier("Record"),i.identifier("Record"))]:[i.importSpecifier(i.identifier("Tuple"),i.identifier("Tuple"))],i.stringLiteral("@bloomberg/record-tuple-polyfill"))),d.scope.hasGlobal("Proxy")&&f.program.body.unshift(i.importDeclaration([i.importDefaultSpecifier(i.identifier("Proxy"))],i.stringLiteral((await t("proxy-polyfill/src/proxy.js",import.meta.url)).slice(7)))),1==d.node.body.length&&"FunctionDeclaration"==d.node.body[0].type?{code:`export default ${n(f).code}`}:{code:n(f).code}}export{preprocess as p};
@@ -1 +1 @@
1
- import e from"@babel/generator";import{parse as o}from"@babel/parser";import r from"@babel/plugin-proposal-class-properties";import t from"@babel/plugin-proposal-class-static-block";import a from"@babel/plugin-proposal-decorators";import p from"@babel/plugin-proposal-json-strings";import s from"@babel/plugin-proposal-logical-assignment-operators";import l from"@babel/plugin-proposal-nullish-coalescing-operator";import i from"@babel/plugin-proposal-numeric-separator";import n from"@babel/plugin-proposal-object-rest-spread";import c from"@babel/plugin-proposal-optional-catch-binding";import m from"@babel/plugin-proposal-optional-chaining";import u from"@babel/plugin-proposal-private-property-in-object";import f from"@babel/plugin-transform-exponentiation-operator";import d from"@babel/traverse";import b from"@babel/types";import g from"@rollup/plugin-babel";import h from"@rollup/plugin-commonjs";import y from"@rollup/plugin-json";import w from"@rollup/plugin-node-resolve";import{resolve as k}from"path";import x from"prettier";import{rollup as j}from"rollup";import{s as v}from"../constants-9bb78688.js";import{minify as S}from"./minify.js";export{minify}from"./minify.js";import{postprocess as C}from"./postprocess.js";export{postprocess}from"./postprocess.js";import{preprocess as E}from"./preprocess.js";export{preprocess}from"./preprocess.js";import{includesIllegalString as L,replaceUnsafeStrings as $}from"./shared.js";import{transform as N}from"./transform.js";export{transform}from"./transform.js";import{a as I}from"../assert-1556d989.js";import"acorn";import"terser";import"../spliceString-2c6f214f.js";import"../countHackmudCharacters-1e122984.js";import"import-meta-resolve";const{default:P}=g,{format:D}=x,{default:_}=e,{default:M}=d;async function processScript(e,{minify:d=!0,uniqueID:g=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),scriptUser:x="UNKNOWN",scriptName:O="UNKNOWN",filePath:T,mangleNames:U=!1,forceQuineCheats:W}={}){I(/^\w{11}$/.exec(g));const q=e;let V,F;const H=/^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(e);if(H)e=`export default ${e}`,({autocomplete:V}=H.groups);else for(const o of e.split("\n")){const e=/^\s*\/\/(?<commentContent>.+)/.exec(o);if(!e)break;const r=e.groups.commentContent.trim();if(r.startsWith("@autocomplete "))V=r.slice(14).trimStart();else if(r.startsWith("@seclevel ")){const e=r.slice(10).trimStart().toLowerCase();switch(e){case"fullsec":case"full":case"fs":case"4s":case"f":case"4":F=4;break;case"highsec":case"high":case"hs":case"3s":case"h":case"3":F=3;break;case"midsec":case"mid":case"ms":case"2s":case"m":case"2":F=2;break;case"lowsec":case"low":case"ls":case"1s":case"l":case"1":F=1;break;case"nullsec":case"null":case"ns":case"0s":case"n":case"0":F=0;break;default:throw new Error(`unrecognised seclevel "${e}"`)}}}I(/^\w{11}$/.exec(g));const z=[[a.default,{decoratorsBeforeExport:!0}],[r.default],[t.default],[u.default],[s.default],[i.default],[l.default],[m.default],[c.default],[p.default],[n.default],[f.default]];let K;if(T)if(K=k(T),T.endsWith(".ts"))z.push([(await import("@babel/plugin-transform-typescript")).default,{allowDeclareFields:!0,optimizeConstEnums:!0}]);else{const[e,o,r,t,a,p,s]=await Promise.all([import("@babel/plugin-proposal-do-expressions"),import("@babel/plugin-proposal-function-bind"),import("@babel/plugin-proposal-function-sent"),import("@babel/plugin-proposal-partial-application"),import("@babel/plugin-proposal-pipeline-operator"),import("@babel/plugin-proposal-throw-expressions"),import("@babel/plugin-proposal-record-and-tuple")]);z.push([e.default],[o.default],[r.default],[t.default],[a.default,{proposal:"hack",topicToken:"%"}],[p.default],[s.default,{syntaxType:"hash",importPolyfill:!0}])}else{K=`${g}.ts`;const[e,o,r,t,a,p,s,l]=await Promise.all([import("@babel/plugin-transform-typescript"),import("@babel/plugin-proposal-do-expressions"),import("@babel/plugin-proposal-function-bind"),import("@babel/plugin-proposal-function-sent"),import("@babel/plugin-proposal-partial-application"),import("@babel/plugin-proposal-pipeline-operator"),import("@babel/plugin-proposal-throw-expressions"),import("@babel/plugin-proposal-record-and-tuple")]);z.push([e.default,{allowDeclareFields:!0,optimizeConstEnums:!0}],[o.default],[r.default],[t.default],[a.default],[p.default,{proposal:"hack",topicToken:"%"}],[s.default],[l.default,{syntaxType:"hash",importPolyfill:!0}])}const Q=await j({input:K,plugins:[{name:"hackmud-script-manager",transform:async e=>(await E(e,{uniqueID:g})).code},P({babelHelpers:"bundled",plugins:z,configFile:!1,extensions:v}),h(),w({extensions:v}),y()],treeshake:{moduleSideEffects:!1}}),A=["NULLSEC","LOWSEC","MIDSEC","HIGHSEC","FULLSEC"];e=(await Q.generate({})).output[0].code;const{file:B,seclevel:G}=N(o(e,{sourceType:"module"}),q,{uniqueID:g,scriptUser:x,scriptName:O});if(null!=F&&G<F)throw new Error(`detected seclevel ${A[G]} is lower than stated seclevel ${A[F]}`);if(e=_(B).code,d?e=await S(B,{uniqueID:g,mangleNames:U,forceQuineCheats:W,autocomplete:V}):(M(B,{MemberExpression({node:e}){e.computed||(I("Identifier"==e.property.type),"prototype"==e.property.name?(e.computed=!0,e.property=b.stringLiteral("prototype")):"__proto__"==e.property.name?(e.computed=!0,e.property=b.stringLiteral("__proto__")):L(e.property.name)&&(e.computed=!0,e.property=b.stringLiteral($(g,e.property.name))))},VariableDeclarator(e){!function renameVariables(o){switch(o.type){case"Identifier":L(o.name)&&e.scope.rename(o.name,`$${Math.floor(Math.random()*2**52).toString(36).padStart(11,"0")}`);break;case"ObjectPattern":for(const e of o.properties)I("ObjectProperty"==e.type),renameVariables(e.value);break;case"ArrayPattern":for(const e of o.elements)e&&renameVariables(e);break;default:throw new Error(`unknown lValue type "${o.type}"`)}}(e.node.id)},ObjectProperty({node:e}){"Identifier"==e.key.type&&L(e.key.name)&&(e.key=b.stringLiteral($(g,e.key.name)),e.shorthand=!1)},StringLiteral({node:e}){e.value=$(g,e.value)},TemplateLiteral({node:e}){for(const o of e.quasis)o.value.cooked?(o.value.cooked=$(g,o.value.cooked),o.value.raw=o.value.cooked.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"$\\{")):o.value.raw=$(g,o.value.raw)},RegExpLiteral(e){e.node.pattern=$(g,e.node.pattern),delete e.node.extra}}),e=D(_(B,{comments:!1}).code,{parser:"babel",arrowParens:"avoid",semi:!1,trailingComma:"none"})),e=C(e,G,g),L(e))throw new Error('you found a weird edge case where I wasn\'t able to replace illegal strings like "SC$", please report thx');return{script:e,warnings:[]}}export{processScript as default,processScript};
1
+ export{processScript as default,processScript}from"../index-73f8f8aa.js";export{m as minify}from"../minify-fba250e4.js";export{p as postprocess}from"../postprocess-164b44d3.js";export{p as preprocess}from"../preprocess-67d17495.js";export{t as transform}from"../transform-eee68ce3.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"path";import"prettier";import"rollup";import"../shared-eace5bd5.js";import"../assert-22a7ef8a.js";import"acorn";import"terser";import"../spliceString-0e6b5d6d.js";import"import-meta-resolve";
@@ -1 +1 @@
1
- import e from"@babel/generator";import t from"@babel/traverse";import r from"@babel/types";import{tokenizer as i,tokTypes as n}from"acorn";import*as a from"terser";import{getReferencePathsToGlobal as o,includesIllegalString as s,replaceUnsafeStrings as p}from"./shared.js";import{a as l}from"../assert-1556d989.js";import{s as u}from"../spliceString-2c6f214f.js";import{c}from"../countHackmudCharacters-1e122984.js";const{default:f}=e,{default:d}=t;async function minify(e,{uniqueID:t="00000000000",mangleNames:i=!1,forceQuineCheats:n,autocomplete:m}={}){let y;if(l(/^\w{11}$/.exec(t)),d(e,{Program(e){y=e,e.skip()}}),y.scope.hasGlobal("_START"))for(const e of o("_START",y))e.replaceWith(r.identifier("_ST"));if(y.scope.hasGlobal("_TIMEOUT"))for(const e of o("_TIMEOUT",y))e.replaceWith(r.identifier("_TO"));const _=y.get("body.0");for(const e of[..._.node.params].reverse()){if("Identifier"==e.type){if(!_.scope.getBinding(e.name).referenced){_.node.params.pop();continue}}break}for(const e in y.scope.globals){if("arguments"==e||e.startsWith(`$${t}$`))continue;const i=o(e,y);if(!(5+e.length+i.length>=e.length*i.length)){for(const n of i)n.replaceWith(r.identifier(`_${t}_GLOBAL_${e}_`));_.node.body.body.unshift(r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_GLOBAL_${e}_`),r.identifier(e))]))}}const $=o(`$${t}$GLOBAL$`,y);if($.length>3){for(const e of $)e.replaceWith(r.identifier(`_${t}_G_`));_.node.body.body.unshift(r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_G_`),r.identifier(`$${t}$GLOBAL$`))]))}const E=[];let g,b,v=!1;if(1!=n){const o=r.cloneNode(e);if(d(o,{MemberExpression({node:e}){e.computed||(l("Identifier"==e.property.type),"prototype"==e.property.name?(e.computed=!0,e.property=r.identifier(`_${t}_PROTOTYPE_PROPERTY_`)):"__proto__"==e.property.name?(e.computed=!0,e.property=r.identifier(`_${t}_PROTO_PROPERTY_`)):s(e.property.name)&&(e.computed=!0,e.property=r.stringLiteral(p(t,e.property.name))))},ObjectProperty({node:e}){"Identifier"==e.key.type&&s(e.key.name)&&(e.key=r.stringLiteral(p(t,e.key.name)),e.shorthand=!1)},StringLiteral({node:e}){e.value=p(t,e.value)},TemplateLiteral({node:e}){for(const r of e.quasis)r.value.cooked?(r.value.cooked=p(t,r.value.cooked),r.value.raw=r.value.cooked.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"$\\{")):r.value.raw=p(t,r.value.raw)},RegExpLiteral(e){e.node.pattern=p(t,e.node.pattern),delete e.node.extra}}),g=(await a.minify(f(o).code,{ecma:2015,compress:{passes:1/0,unsafe:!0,unsafe_arrows:!0,unsafe_comps:!0,unsafe_symbols:!0,unsafe_methods:!0,unsafe_proto:!0,unsafe_regexp:!0,unsafe_undefined:!0,sequences:!1},format:{semicolons:!1},keep_classnames:!i,keep_fnames:!i})).code.replace(new RegExp(`_${t}_PROTOTYPE_PROPERTY_`,"g"),'"prototype"').replace(new RegExp(`_${t}_PROTO_PROPERTY_`,"g"),'"__proto__"'),m&&(g=u(g,`//${m}\n`,getFunctionBodyStart(g)+1)),0==n)return g}let h,x=!1;{const i=[];d(e,{FunctionDeclaration(e){e.traverse({Function(e){"CallExpression"!=e.parent.type&&"callee"!=e.parentKey&&e.skip()},Loop(e){e.skip()},ObjectExpression(e){const i={};parseObjectExpression(e.node,i)&&e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${E.push(i)-1}_`))},ArrayExpression(e){const i=[];parseArrayExpression(e.node,i)&&e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${E.push(i)-1}_`))}}),e.traverse({TemplateLiteral(e){if("TaggedTemplateExpression"==e.parent.type)return;const t=e.node;let i=r.stringLiteral(t.quasis[0].value.cooked);for(let e=0;e<t.expressions.length;e++){const n=t.expressions[e],a=t.quasis[e+1];i=r.binaryExpression("+",i,n),a.value.cooked&&(i=r.binaryExpression("+",i,r.stringLiteral(a.value.cooked)))}e.replaceWith(i)},MemberExpression({node:e}){e.computed||(l("Identifier"==e.property.type),e.property.name.length<3||(e.computed=!0,e.property=r.stringLiteral(e.property.name)))},UnaryExpression(e){if("void"==e.node.operator)"NumericLiteral"!=e.node.argument.type||e.node.argument.value||(e.replaceWith(r.identifier(`_${t}_UNDEFINED_`)),v=!0);else if("-"==e.node.operator&&"NumericLiteral"==e.node.argument.type){const n=-e.node.argument.value;i.push((async()=>{if((await minifyNumber(n)).length<=3)return;"key"==e.parentKey&&"ObjectProperty"==e.parent.type&&(e.parent.computed=!0);let i=E.indexOf(n);-1==i&&(i+=E.push(n)),e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${i}_`))})()),e.skip()}},NullLiteral(e){let i=E.indexOf(null);-1==i&&(i+=E.push(null)),e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${i}_`))},BooleanLiteral(e){let i=E.indexOf(e.node.value);-1==i&&(i+=E.push(e.node.value)),e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${i}_`))},NumericLiteral(e){i.push((async()=>{if((await minifyNumber(e.node.value)).length<=3)return;"key"==e.parentKey&&"ObjectProperty"==e.parent.type&&(e.parent.computed=!0);let i=E.indexOf(e.node.value);-1==i&&(i+=E.push(e.node.value)),e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${i}_`))})())},StringLiteral(e){if(e.node.value=p(t,e.node.value),JSON.stringify(e.node.value).includes("\\u00")||e.toString().length<4)return;"key"==e.parentKey&&"ObjectProperty"==e.parent.type&&(e.parent.computed=!0);let i=E.indexOf(e.node.value);-1==i&&(i+=E.push(e.node.value)),e.replaceWith(r.identifier(`_${t}_JSON_VALUE_${i}_`))},ObjectProperty({node:e}){if(e.computed||"Identifier"!=e.key.type||e.key.name.length<4)return;let i=E.indexOf(e.key.name);-1==i&&(i+=E.push(e.key.name)),e.computed=!0,e.key=r.identifier(`_${t}_JSON_VALUE_${i}_`)},RegExpLiteral(e){e.node.pattern=p(t,e.node.pattern),delete e.node.extra}}),e.skip()}}),await Promise.all(i);const n=e.program.body[0];if(l("FunctionDeclaration"==n.type),E.length)if(x=!0,1==E.length)if("string"!=typeof E[0]||E[0].includes("\n")||E[0].includes("\t")){const e=r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_JSON_VALUE_0_`),r.callExpression(r.memberExpression(r.identifier("JSON"),r.identifier("parse")),[r.memberExpression(r.taggedTemplateExpression(r.memberExpression(r.callExpression(r.identifier(`$${t}$SUBSCRIPT$scripts$quine$`),[]),r.identifier("split")),r.templateLiteral([r.templateElement({raw:"\t",cooked:"\t"},!0)],[])),r.identifier(`$${t}$SPLIT_INDEX$`),!0)]))]);v&&e.declarations.push(r.variableDeclarator(r.identifier(`_${t}_UNDEFINED_`))),n.body.body.unshift(e),b=JSON.stringify(E[0])}else{const e=r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_JSON_VALUE_0_`),r.memberExpression(r.taggedTemplateExpression(r.memberExpression(r.callExpression(r.identifier(`$${t}$SUBSCRIPT$scripts$quine$`),[]),r.identifier("split")),r.templateLiteral([r.templateElement({raw:"\t",cooked:"\t"},!0)],[])),r.identifier(`$${t}$SPLIT_INDEX$`),!0))]);v&&e.declarations.push(r.variableDeclarator(r.identifier(`_${t}_UNDEFINED_`))),n.body.body.unshift(e),b=E[0]}else{const e=r.variableDeclaration("let",[r.variableDeclarator(r.arrayPattern(E.map(((e,i)=>r.identifier(`_${t}_JSON_VALUE_${i}_`)))),r.callExpression(r.memberExpression(r.identifier("JSON"),r.identifier("parse")),[r.memberExpression(r.taggedTemplateExpression(r.memberExpression(r.callExpression(r.identifier(`$${t}$SUBSCRIPT$scripts$quine$`),[]),r.identifier("split")),r.templateLiteral([r.templateElement({raw:"\t",cooked:"\t"},!0)],[])),r.identifier(`$${t}$SPLIT_INDEX$`),!0)]))]);v&&e.declarations.push(r.variableDeclarator(r.identifier(`_${t}_UNDEFINED_`))),n.body.body.unshift(e),b=JSON.stringify(E)}else v&&n.body.body.unshift(r.variableDeclaration("let",[r.variableDeclarator(r.identifier(`_${t}_UNDEFINED_`))]));h=f(e).code}return h=(await a.minify(h,{ecma:2015,compress:{passes:1/0,unsafe:!0,unsafe_arrows:!0,unsafe_comps:!0,unsafe_symbols:!0,unsafe_methods:!0,unsafe_proto:!0,unsafe_regexp:!0,unsafe_undefined:!0,sequences:!1},format:{semicolons:!1},keep_classnames:!i,keep_fnames:!i})).code||"",null!=b&&(h=u(h,`${m?`//${m}\n`:""}\n//\t${b}\t\n`,getFunctionBodyStart(h)+1),h=h.replace(`$${t}$SPLIT_INDEX$`,await minifyNumber(h.split("\t").findIndex((e=>e==b))))),1==n?h:(l(g),c(g)<=c(h)+Number(x)?g:h)}function parseObjectExpression(e,t){if(!e.properties.length)return!1;for(const r of e.properties){if("ObjectProperty"!=r.type||r.computed)return!1;if(l("Identifier"==r.key.type||"NumericLiteral"==r.key.type||"StringLiteral"==r.key.type),"ArrayExpression"==r.value.type){const e=[];if(!parseArrayExpression(r.value,e))return!1;t["Identifier"==r.key.type?r.key.name:r.key.value]=e}else if("ObjectExpression"==r.value.type){const e={};if(!parseObjectExpression(r.value,e))return!1;t["Identifier"==r.key.type?r.key.name:r.key.value]=e}else if("NullLiteral"==r.value.type)t["Identifier"==r.key.type?r.key.name:r.key.value]=null;else if("BooleanLiteral"==r.value.type||"NumericLiteral"==r.value.type||"StringLiteral"==r.value.type)t["Identifier"==r.key.type?r.key.name:r.key.value]=r.value.value;else{if("TemplateLiteral"!=r.value.type||r.value.expressions.length)return!1;t["Identifier"==r.key.type?r.key.name:r.key.value]=r.value.quasis[0].value.cooked}}return!0}function parseArrayExpression(e,t){if(!e.elements.length)return!1;for(const r of e.elements){if(!r)return!1;if("ArrayExpression"==r.type){const e=[];if(!parseArrayExpression(r,e))return!1;e.push(e)}else if("ObjectExpression"==r.type){const e={};if(!parseObjectExpression(r,e))return!1;t.push(e)}else if("NullLiteral"==r.type)t.push(null);else if("BooleanLiteral"==r.type||"NumericLiteral"==r.type||"StringLiteral"==r.type)t.push(r.value);else{if("TemplateLiteral"!=r.type||r.expressions.length)return!1;t.push(r.quasis[0].value.cooked)}}return!0}async function minifyNumber(e){return/\$\((?<number>.+)\)/.exec((await a.minify(`$(${e})`,{ecma:2015})).code).groups.number}function getFunctionBodyStart(e){const t=i(e,{ecmaVersion:2015});t.getToken(),t.getToken(),t.getToken();let r=1;for(;r;){const e=t.getToken();e.type==n.parenL?r++:e.type==n.parenR&&r--}return t.getToken().start}export{minify as default,minify};
1
+ export{m as default,m as minify}from"../minify-fba250e4.js";import"@babel/generator";import"@babel/traverse";import"@babel/types";import"acorn";import"terser";import"../shared-eace5bd5.js";import"../assert-22a7ef8a.js";import"../spliceString-0e6b5d6d.js";
@@ -1 +1 @@
1
- function postprocess($,e,p){return $.replace(/^function\s*\w+\(/,"function(").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$SC_DOLLAR\\$`,"g"),"S\\C$").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$DB_DOLLAR\\$`,"g"),"D\\B$").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$D\\$`,"g"),"_\\_D_S").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$FMCL\\$`,"g"),"_\\_FMCL_").replace(new RegExp(`\\$${p}\\$\\\\(?:\\\\)?\\$G\\$`,"g"),"_\\_G_").replace(new RegExp(`\\$${p}\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`,"g"),`#${"nlmhf"[e]}s.$1.$2`).replace(new RegExp(`\\$${p}\\$DEBUG\\$`,"g"),"#D").replace(new RegExp(`\\$${p}\\$FMCL\\$`,"g"),"#FMCL").replace(new RegExp(`\\$${p}\\$GLOBAL\\$`,"g"),"#G").replace(new RegExp(`\\$${p}\\$DB\\$(\\w+)\\$`,"g"),"#db.$1").replace(new RegExp(`\\$${p}\\$SLASH_SLASH\\$`,"g"),"/\\/").replace(new RegExp(`\\$${p}\\$NOT_A_SUBSCRIPT\\$(#[\\w\\.]+)\\(\\$`,"g"),"$1\\(").replace(new RegExp(`\\$${p}\\$NOT_A_DB_CALL\\$(\\w+)\\$`,"g"),"#db.$1\\(").replace(new RegExp(`\\$${p}\\$NOT_A_DEBUG_CALL\\$`,"g"),"#D\\(").replace(new RegExp(`\\$${p}\\$NOT_FMCL\\$`,"g"),"#\\FMCL").replace(new RegExp(`\\$${p}\\$NOT_G\\$`,"g"),"#\\G")}export{postprocess as default,postprocess};
1
+ export{p as default,p as postprocess}from"../postprocess-164b44d3.js";
@@ -1 +1 @@
1
- import e from"@babel/generator";import{parse as o}from"@babel/parser";import r from"@babel/traverse";import i from"@babel/types";import{resolve as t}from"import-meta-resolve";import{a as s}from"../assert-1556d989.js";import{s as p}from"../spliceString-2c6f214f.js";const{default:l}=r,{default:n}=e;async function preprocess(e,{uniqueID:r="00000000000"}={}){s(/^\w{11}$/.test(r));const a=e;let c,f,d;do{c=e.length,e=e.replace(/^\s+/,"").replace(/^\/\/.*/,"").replace(/^\/\*[\s\S]*?\*\//,"")}while(e.length!=c);for(e=e.replace(/^function\s*\(/,"export default function (");;){let i;try{f=o(e,{plugins:["typescript",["decorators",{decoratorsBeforeExport:!0}],"doExpressions","functionBind","functionSent","partialApplication",["pipelineOperator",{proposal:"hack",topicToken:"%"}],"throwExpressions",["recordAndTuple",{syntaxType:"hash"}],"classProperties","classPrivateProperties","classPrivateMethods","logicalAssignment","numericSeparator","nullishCoalescingOperator","optionalChaining","optionalCatchBinding","objectRestSpread"],sourceType:"module"});break}catch(e){s(e instanceof SyntaxError),i=e}var m;if("BABEL_PARSER_SYNTAX_ERROR"!=i.code||"PrivateInExpectedIn"!=i.reasonCode)throw console.log(null===(m=/.+/.exec(e.slice(i.pos)))||void 0===m?void 0:m[0]),i;const t=e.slice(i.pos);let l;if(l=/^#[0-4fhmln]s\.scripts\.quine\(\)/.exec(t))e=p(e,JSON.stringify(a),i.pos,l[0].length);else if(l=/^#[0-4fhmln]?s\./.exec(t))e=p(e,"$",i.pos,1);else if(l=/^#D[^\w$]/.exec(t))e=p(e,"$",i.pos,1);else if(l=/^#FMCL/.exec(t))e=p(e,`$${r}$FMCL$`,i.pos,l[0].length);else if(l=/^#G/.exec(t))e=p(e,`$${r}$GLOBAL$`,i.pos,l[0].length);else{if(!(l=/^#db\./.exec(t)))throw i;e=p(e,"$",i.pos,1)}}l(f,{Program(e){d=e,e.skip()}});const u=d.scope.hasGlobal("Record"),h=d.scope.hasGlobal("Tuple");return(u||h)&&f.program.body.unshift(i.importDeclaration(u?h?[i.importSpecifier(i.identifier("Record"),i.identifier("Record")),i.importSpecifier(i.identifier("Tuple"),i.identifier("Tuple"))]:[i.importSpecifier(i.identifier("Record"),i.identifier("Record"))]:[i.importSpecifier(i.identifier("Tuple"),i.identifier("Tuple"))],i.stringLiteral("@bloomberg/record-tuple-polyfill"))),d.scope.hasGlobal("Proxy")&&f.program.body.unshift(i.importDeclaration([i.importDefaultSpecifier(i.identifier("Proxy"))],i.stringLiteral((await t("proxy-polyfill/src/proxy.js",import.meta.url)).slice(7)))),1==d.node.body.length&&"FunctionDeclaration"==d.node.body[0].type?{code:`export default ${n(f).code}`}:{code:n(f).code}}export{preprocess as default,preprocess};
1
+ export{p as default,p as preprocess}from"../preprocess-67d17495.js";import"@babel/generator";import"@babel/parser";import"@babel/traverse";import"@babel/types";import"import-meta-resolve";import"../assert-22a7ef8a.js";import"../spliceString-0e6b5d6d.js";
@@ -1 +1 @@
1
- import e from"@babel/types";import{e as $}from"../assert-1556d989.js";function getReferencePathsToGlobal(r,a){const[l]=a.unshiftContainer("body",e.variableDeclaration("let",[e.variableDeclarator(e.identifier(r))]));a.scope.crawl();const n=$(a.scope.getBinding(r));return l.remove(),n.referencePaths}function includesIllegalString(e){return e.includes("SC$")||e.includes("DB$")||e.includes("__D_S")||e.includes("__FMCL_")||e.includes("__G_")}function replaceUnsafeStrings(e,$){return $.replace(/SC\$/g,`$${e}$\\$SC_DOLLAR$`).replace(/DB\$/g,`$${e}$\\$DB_DOLLAR$`).replace(/__D_S/g,`$${e}$\\$D$`).replace(/__FMCL_/g,`$${e}$\\$FMCL$`).replace(/__G_/g,`$${e}$\\$G$`).replace(/\/\//g,`$${e}$SLASH_SLASH$`).replace(/#[0-4fhmln]?s(?:\.[_a-z][\d_a-z]{0,24}){2}\(/g,`$${e}$NOT_A_SUBSCRIPT$$$&$`).replace(/#db\.(?<methodName>[irfu]|u1|us|ObjectId)\(/g,`$${e}$NOT_A_DB_CALL$$$1$`).replace(/#D\(/g,`$${e}$NOT_A_DEBUG_CALL$`).replace(/#FMCL/g,`$${e}$NOT_FMCL$`).replace(/#G/g,`$${e}$NOT_G$`)}export{getReferencePathsToGlobal,includesIllegalString,replaceUnsafeStrings};
1
+ export{g as getReferencePathsToGlobal,i as includesIllegalString,r as replaceUnsafeStrings}from"../shared-eace5bd5.js";import"@babel/types";import"../assert-22a7ef8a.js";
@@ -1 +1 @@
1
- import e from"@babel/traverse";import t from"@babel/types";import{v as i}from"../constants-9bb78688.js";import{getReferencePathsToGlobal as r}from"./shared.js";import{a as n}from"../assert-1556d989.js";function clearObject(e,t){for(const t of Object.getOwnPropertyNames(e))delete e[t];for(const t of Object.getOwnPropertySymbols(e))delete e[t];void 0!==t&&Object.setPrototypeOf(e,t)}const{default:o}=e,a=["Map","Set","Date","JSON","Math","Array","Error","isNaN","Number","Object","RegExp","String","Symbol","BigInt"];function transform(e,s,{uniqueID:p="00000000000",scriptUser:c="UNKNOWN",scriptName:l="UNKNOWN",seclevel:d=4}={}){const f=`_${p}_SCRIPT_`,b=new Map,y=new Map;let m;if(o(e,{Program(e){m=e,e.skip()}}),m.scope.hasGlobal("_SOURCE"))for(const e of r("_SOURCE",m))e.replaceWith(t.stringLiteral(s));if(m.scope.hasGlobal("_BUILD_DATE"))for(const e of r("_BUILD_DATE",m))e.replaceWith(t.numericLiteral(Date.now()));if(m.scope.hasGlobal("_SCRIPT_USER"))for(const e of r("_SCRIPT_USER",m))1==c?e.replaceWith(t.stringLiteral(`$${p}$SCRIPT_USER$`)):e.replaceWith(t.stringLiteral(c));if(m.scope.hasGlobal("_SCRIPT_NAME"))for(const e of r("_SCRIPT_NAME",m))1==l?e.replaceWith(t.stringLiteral(`$${p}$SCRIPT_NAME$`)):e.replaceWith(t.stringLiteral(l));if(m.scope.hasGlobal("_FULL_SCRIPT_NAME"))for(const e of r("_FULL_SCRIPT_NAME",m))1==c||1==l?e.replaceWith(t.stringLiteral(`$${p}$FULL_SCRIPT_NAME$`)):e.replaceWith(t.stringLiteral(`${c}.${l}`));let $=!1;if(m.scope.hasGlobal("Function")){const e=r("Function",m);if(1==e.length){const t=e[0];n("MemberExpression"==t.parent.type,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),n("Identifier"==t.parent.property.type,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),n("prototype"==t.parent.property.name,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),t.parentPath.replaceWith(createGetFunctionPrototypeNode())}else{for(const i of e)n("MemberExpression"==i.parent.type,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),n("Identifier"==i.parent.property.type,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),n("prototype"==i.parent.property.name,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),$=!0,i.parentPath.replaceWith(t.identifier(`_${p}_FUNCTION_DOT_PROTOTYPE_`));$=!0}}let h=4;for(const e of["$fs","$4s","$s"])m.scope.hasGlobal(e)&&processFakeSubscriptObject(e);for(const e of["$hs","$3s"])m.scope.hasGlobal(e)&&(h=3,processFakeSubscriptObject(e));for(const e of["$ms","$2s"])m.scope.hasGlobal(e)&&(h=2,processFakeSubscriptObject(e));for(const e of["$ls","$1s"])m.scope.hasGlobal(e)&&(h=1,processFakeSubscriptObject(e));for(const e of["$ns","$0s"])m.scope.hasGlobal(e)&&(h=0,processFakeSubscriptObject(e));if(d=Math.min(d,h),m.scope.hasGlobal("$db"))for(const e of r("$db",m)){var E;n("MemberExpression"==e.parentPath.node.type),n("Identifier"==e.parentPath.node.property.type);const r=e.parentPath.node.property.name;n(i.includes(r),`invalid db method "${r}", valid db methods are "${i.join('", "')}"`),"CallExpression"==(null===(E=e.parentPath.parentPath)||void 0===E?void 0:E.type)?e.parentPath.replaceWith(t.identifier(`$${p}$DB$${r}$`)):"ObjectId"==r?e.parentPath.replaceWith(t.arrowFunctionExpression([],t.callExpression(t.identifier(`$${p}$DB$${r}$`),[]))):"i"==r||"r"==r?e.parentPath.replaceWith(t.arrowFunctionExpression([t.identifier("a")],t.callExpression(t.identifier(`$${p}$DB$${r}$`),[t.identifier("a")]))):e.parentPath.replaceWith(t.arrowFunctionExpression([t.identifier("a"),t.identifier("b")],t.callExpression(t.identifier(`$${p}$DB$${r}$`),[t.identifier("a"),t.identifier("b")])))}if(m.scope.hasGlobal("$D"))for(const e of r("$D",m))"CallExpression"==e.parentPath.type?e.replaceWith(t.identifier(`$${p}$DEBUG$`)):e.replaceWith(t.arrowFunctionExpression([t.identifier("a")],t.callExpression(t.identifier(`$${p}$DEBUG$`),[t.identifier("a")])));if(m.scope.hasGlobal("$FMCL"))for(const e of r("$FMCL",m))e.replaceWith(t.identifier(`$${p}$FMCL$`));if(m.scope.hasGlobal("$G"))for(const e of r("$G",m))e.replaceWith(t.identifier(`$${p}$GLOBAL$`));if(m.scope.hasGlobal("_SECLEVEL"))for(const e of r("_SECLEVEL",m))e.replaceWith(t.numericLiteral(d));let _=!1,u=!1;if(m.scope.hasGlobal("Object"))for(const e of r("Object",m))"MemberExpression"!=e.parent.type||e.parent.computed||(n("Identifier"==e.parent.property.type),"getPrototypeOf"==e.parent.property.name?(e.parentPath.replaceWith(t.identifier(`_${p}_GET_PROTOTYPE_OF_`)),_=!0):"setPrototypeOf"==e.parent.property.name&&(e.parentPath.replaceWith(t.identifier(`_${p}_SET_PROTOTYPE_OF_`)),u=!0));const P=m.node.body[m.node.body.length-1];let O;if(n(P,"program is empty"),"ExportNamedDeclaration"==P.type){m.node.body.pop();for(const e of P.specifiers){n("ExportSpecifier"==e.type,`${e.type} is currently unsupported`);const t="Identifier"==e.exported.type?e.exported.name:e.exported.value;"default"==t?O=e.local.name:b.set(e.local.name,t)}}const x=t.blockStatement([]);let S;for(const e of m.node.body)if("VariableDeclaration"==e.type)for(const i of e.declarations)if("Identifier"!=i.id.type||i.id.name!=O||!i.init||"FunctionExpression"!=i.init.type&&"ArrowFunctionExpression"!=i.init.type||i.init.async||i.init.generator){for(const r in t.getBindingIdentifiers(i.id))r==O&&(S=t.functionDeclaration(t.identifier(f),[t.identifier("context"),t.identifier("args")],t.blockStatement([t.returnStatement(t.callExpression(t.identifier(O),[]))]))),"const"!=e.kind&&b.has(r)&&(y.set(r,b.get(r)),b.delete(r)),x.body.push(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(r))]));i.init&&x.body.push(t.expressionStatement(t.assignmentExpression("=",i.id,i.init)))}else S=t.functionDeclaration(t.identifier(f),i.init.params,"BlockStatement"==i.init.body.type?i.init.body:t.blockStatement([t.returnStatement(i.init.body)]));else"FunctionDeclaration"==e.type?e.id.name==O?S=e:x.body.push(t.variableDeclaration("let",[t.variableDeclarator(e.id,t.functionExpression(void 0,e.params,e.body,e.generator,e.async))])):x.body.push(e);if(S||(S=t.functionDeclaration(t.identifier(f),[t.identifier("context"),t.identifier("args")],t.blockStatement([]))),m.node.body=[S],x.body.length){(b.size||y.size)&&S.body.body.push(t.returnStatement(t.objectExpression([...[...b].map((([e,i])=>t.objectProperty(t.identifier(i),t.identifier(e)))),...[...y].map((([e,i])=>t.objectMethod("get",t.identifier(i),[],t.blockStatement([t.returnStatement(t.identifier(e))]))))]))),m.scope.crawl();const e=new Set;let i=0;for(const[r,o]of[...x.body.entries()].reverse())if("VariableDeclaration"==o.type){n(1==o.declarations.length);const a=o.declarations[0];if(n("Identifier"==a.id.type,`declarator.id.type was "${a.id.type}"`),m.scope.crawl(),m.scope.hasGlobal(a.id.name)){x.body.splice(r,1);const[s]=m.unshiftContainer("body",x),[c]=m.unshiftContainer("body",o);if(m.scope.crawl(),!a.init||"FunctionExpression"!=a.init.type&&"ArrowFunctionExpression"!=a.init.type||Object.keys(m.scope.globals).some((t=>e.has(t)))){const e=m.scope.getBinding(a.id.name);n(e);for(const i of e.referencePaths)n("Identifier"==i.node.type),i.replaceWith(t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(i.node.name)));for(const i of e.constantViolations)if("AssignmentExpression"==i.node.type)for(const[e,r]of Object.entries(t.getBindingIdentifiers(i.node)))e==a.id.name&&(clearObject(r),Object.assign(r,t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(e))));s.remove(),c.remove(),a.init&&x.body.splice(r,0,t.expressionStatement(t.assignmentExpression("=",t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(a.id.name)),a.init)))}else s.remove(),c.remove(),S.body.body.unshift(o),i++}else e.add(a.id.name)}else if("ClassDeclaration"==o.type&&(m.scope.crawl(),m.scope.hasGlobal(o.id.name))){x.body.splice(r,1);const[e]=m.unshiftContainer("body",x),[i]=m.unshiftContainer("body",o);m.scope.crawl();const a=m.scope.getBinding(o.id.name);n(a);for(const e of a.referencePaths)n("Identifier"==e.node.type),e.replaceWith(t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(e.node.name)));e.remove(),i.remove(),x.body.splice(r,0,t.expressionStatement(t.assignmentExpression("=",t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(o.id.name)),t.classExpression(void 0,o.superClass,o.body,o.decorators))))}if(m.scope.hasGlobal("_EXPORTS"))for(const e of r("_EXPORTS",m))e.replaceWith(t.arrayExpression([...b.keys(),...y.keys()].map((e=>t.stringLiteral(e)))));x.body.length&&S.body.body.splice(i,0,t.ifStatement(t.unaryExpression("!",t.identifier(`$${p}$FMCL$`)),x))}return $&&S.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_FUNCTION_DOT_PROTOTYPE_`),createGetFunctionPrototypeNode())])),u&&S.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_SET_PROTOTYPE_OF_`),t.callExpression(t.memberExpression(t.memberExpression(t.identifier("Object"),t.identifier("call")),t.identifier("bind")),[t.identifier(`_${p}_DUNDER_PROTO_SETTER_`)]))])),_&&S.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_GET_PROTOTYPE_OF_`),t.callExpression(t.memberExpression(t.memberExpression(t.identifier("Object"),t.identifier("call")),t.identifier("bind")),[t.identifier(`_${p}_DUNDER_PROTO_GETTER_`)]))])),(_||u)&&S.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.objectPattern(_?u?[t.objectProperty(t.identifier("get"),t.identifier(`_${p}_DUNDER_PROTO_GETTER_`)),t.objectProperty(t.identifier("set"),t.identifier(`_${p}_DUNDER_PROTO_SETTER_`))]:[t.objectProperty(t.identifier("get"),t.identifier(`_${p}_DUNDER_PROTO_GETTER_`))]:[t.objectProperty(t.identifier("set"),t.identifier(`_${p}_DUNDER_PROTO_SETTER_`))]),t.callExpression(t.memberExpression(t.identifier("Object"),t.identifier("getOwnPropertyDescriptor")),[t.memberExpression(t.identifier("Object"),t.identifier("prototype")),t.stringLiteral("__proto__")]))])),o(e,{BlockStatement({node:e}){for(const[i,r]of e.body.entries())"FunctionDeclaration"!=r.type||r.generator||(e.body.splice(i,1),e.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(r.id,t.arrowFunctionExpression(r.params,r.body,r.async))])))},ClassBody({node:e,scope:i,parent:r}){n(t.isClass(r));let a=!1;for(const r of e.body){if("ClassMethod"!=r.type)continue;let e=!1;if(o(r.body,{ThisExpression(i){e=!0,a=!0,i.replaceWith(t.identifier(`_${p}_THIS_`))},Function(e){e.skip()}},i),e)if("constructor"!=r.kind)r.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_THIS_`),t.callExpression(t.memberExpression(t.super(),t.identifier("valueOf")),[]))]));else{const e=[];if(o(r.body,{CallExpression(t){"Super"==t.node.callee.type&&e.push(t)}},i),e.length)if(1==e.length&&"ExpressionStatement"==e[0].parent.type&&e[0].parentPath.parentPath.parent==r)e[0].parentPath.replaceWith(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_THIS_`),e[0].node)]));else{for(const i of e)i.replaceWith(t.assignmentExpression("=",t.identifier(`_${p}_THIS_`),i.node));r.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_THIS_`))]))}else r.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_THIS_`),t.callExpression(t.super(),[]))]))}}!r.superClass&&a&&(r.superClass=t.identifier("Object"))},VariableDeclaration({node:e}){"const"==e.kind&&(e.kind="let")},ThisExpression(e){e.replaceWith(t.identifier("undefined"))},BigIntLiteral(e){const i=Number(e.node.value);BigInt(i)==BigInt(e.node.value)?e.replaceWith(t.callExpression(t.identifier("BigInt"),[t.numericLiteral(i)])):e.replaceWith(t.callExpression(t.identifier("BigInt"),[t.stringLiteral(e.node.value)]))}}),{file:e,seclevel:d};function processFakeSubscriptObject(e){for(const a of r(e,m)){var i,o;n("MemberExpression"==a.parent.type),n("Identifier"==a.parent.property.type),n("MemberExpression"==(null===(i=a.parentPath.parentPath)||void 0===i?void 0:i.node.type)),n("Identifier"==a.parentPath.parentPath.node.property.type),n(/^[_a-z][\d_a-z]{0,24}$/.test(a.parent.property.name),`invalid user "${a.parent.property.name}" in subscript`),n(/^[_a-z][\d_a-z]{0,24}$/.test(a.parentPath.parentPath.node.property.name),`invalid script name "${a.parentPath.parentPath.node.property.name}" in subscript`),"CallExpression"==(null===(o=a.parentPath.parentPath.parentPath)||void 0===o?void 0:o.type)?a.parentPath.parentPath.replaceWith(t.identifier(`$${p}$SUBSCRIPT$${a.parent.property.name}$${a.parentPath.parentPath.node.property.name}$`)):a.parentPath.parentPath.replaceWith(t.arrowFunctionExpression([t.restElement(t.identifier("args"))],t.callExpression(t.identifier(`$${p}$SUBSCRIPT$${a.parent.property.name}$${a.parentPath.parentPath.node.property.name}$`),[t.spreadElement(t.identifier("args"))])))}}function createGetFunctionPrototypeNode(){for(const e of a)if(!m.scope.hasOwnBinding(e))return t.memberExpression(t.memberExpression(t.identifier(e),t.identifier("constructor")),t.identifier("prototype"));return t.memberExpression(t.memberExpression(t.arrowFunctionExpression([t.identifier("_")],t.identifier("_")),t.identifier("constructor")),t.identifier("prototype"))}}export{transform as default,transform};
1
+ export{t as default,t as transform}from"../transform-eee68ce3.js";import"@babel/traverse";import"@babel/types";import"../shared-eace5bd5.js";import"../assert-22a7ef8a.js";
@@ -0,0 +1 @@
1
+ import{dirname as t,resolve as r}from"path";import i from"fs";const{mkdir:s,copyFile:o}=i.promises;async function pull(i,e,a){const[c,n]=a.split(".");if(!c||!n)throw new Error('`script` argument must be in "user.name" format');await function copyFilePersistent(r,i,e){return o(r,i,e).catch((async a=>{if("ENOENT"!=a.code)throw a;await s(t(i),{recursive:!0}),await o(r,i,e)}))}(r(e,c,"scripts",`${n}.js`),r(i,c,`${n}.js`))}export{pull as p};
package/pull.js CHANGED
@@ -1 +1 @@
1
- import{dirname as t,resolve as r}from"path";import i from"fs";const{mkdir:s,copyFile:o}=i.promises;async function pull(i,e,a){const[c,n]=a.split(".");if(!c||!n)throw new Error('`script` argument must be in "user.name" format');await function copyFilePersistent(r,i,e){return o(r,i,e).catch((async a=>{if("ENOENT"!=a.code)throw a;await s(t(i),{recursive:!0}),await o(r,i,e)}))}(r(e,c,"scripts",`${n}.js`),r(i,c,`${n}.js`))}export{pull as default,pull};
1
+ export{p as default,p as pull}from"./pull-9b44f235.js";import"path";import"fs";
@@ -0,0 +1 @@
1
+ import e from"fs";import{resolve as i,extname as t,basename as a}from"path";import{s as r}from"./transform-eee68ce3.js";import{processScript as s}from"./index-73f8f8aa.js";import{D as o,w as p}from"./writeFilePersistent-0476afeb.js";import{c as n}from"./minify-fba250e4.js";import"@babel/traverse";import"@babel/types";import"./shared-eace5bd5.js";import"./assert-22a7ef8a.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./postprocess-164b44d3.js";import"./preprocess-67d17495.js";import"import-meta-resolve";import"./spliceString-0e6b5d6d.js";import"acorn";import"terser";const{readFile:l,readdir:m}=e.promises;async function push(e,c,{scripts:f=["*.*"],onPush:u=(()=>{}),minify:g=!0,mangleNames:d=!1,forceQuineCheats:b}={}){const h=new o((e=>new Set)),w=new Set,$=new Set;let y=!1;for(const e of f){const[i,t]=e.split(".");i&&"*"!=i?t&&"*"!=t?h.get(i).add(t):w.add(i):t&&"*"!=t?$.add(t):y=!0}const j=new o((e=>new Set)),P=[],S=new o((e=>new Set));let N;if($.size||y){const t=await m(i(c),{withFileTypes:!0}),a=new Set([...(N=await m(i(e),{withFileTypes:!0})).filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isFile()&&e.name.endsWith(".key"))).map((e=>e.name.slice(0,-4))),...h.keys(),...w]);if(y)for(const e of a)w.add(e);else for(const e of a){const i=h.get(e);for(const e of $)i.add(e)}}return await Promise.all([...w].map((async o=>{await m(i(e,o),{withFileTypes:!0}).then((async m=>{await Promise.all(m.map((async m=>{if(m.name.endsWith(".d.ts"))return;const f=t(m.name);if(m.isFile()&&r.includes(f)){const t=a(m.name,f),r=i(e,o,m.name),{script:h}=await s(await l(r,{encoding:"utf-8"}),{minify:g,scriptUser:o,scriptName:t,filePath:r,mangleNames:d,forceQuineCheats:b}),w={file:`${o}/${m.name}`,users:[o],minLength:n(h),error:void 0};S.get(o).add(t),P.push(w),await p(i(c,o,`scripts/${t}.js`),h),u(w)}})))}),(e=>{if("ENOENT"!=e.code)throw e}))}))),await Promise.all([...h].map((async([t,a])=>{w.has(t)||await Promise.all([...a].map((async a=>{let o,m,f;for(const s of r)try{m=`${a}${s}`,o=await l(f=i(e,t,m),{encoding:"utf-8"});break}catch{}if(o){const{script:e}=await s(o,{minify:g,scriptUser:t,scriptName:a,filePath:f,mangleNames:d,forceQuineCheats:b}),r={file:`${t}/${m}`,users:[t],minLength:n(e),error:void 0};P.push(r),await p(i(c,t,"scripts",`${a}.js`),e),u(r)}else j.get(a).add(t)})))}))),await(w.size?Promise.all((N||await m(i(e),{withFileTypes:!0})).map((async o=>{if(o.name.endsWith(".d.ts"))return;const m=t(o.name);if(!o.isFile()||!r.includes(m))return;const f=a(o.name,m),h=[...w,...j.get(f)].filter((e=>!S.get(e).has(f)));if(!h.length)return;const $=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),y=i(e,o.name),{script:N}=await s(await l(y,{encoding:"utf-8"}),{minify:g,scriptUser:!0,scriptName:f,uniqueID:$,filePath:y,mangleNames:d,forceQuineCheats:b}),F={file:o.name,users:h,minLength:n(N),error:void 0};await Promise.all(h.map((e=>p(i(c,e,`scripts/${f}.js`),N.replace(new RegExp(`\\$${$}\\$SCRIPT_USER\\$`,"g"),e).replace(new RegExp(`\\$${$}\\$FULL_SCRIPT_NAME\\$`,"g"),`${e}.${f}`))))),P.push(F),u(F)}))):Promise.all([...j].map((async([t,a])=>{let o,m,f;for(const a of r)try{m=`${t}${a}`,o=await l(f=i(e,m),{encoding:"utf-8"});break}catch{}if(o){const e=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),{script:r}=await s(o,{minify:g,scriptUser:!0,scriptName:t,uniqueID:e,filePath:f,mangleNames:d,forceQuineCheats:b}),l={file:m,users:[...a],minLength:n(r),error:void 0};await Promise.all([...a].map((a=>p(i(c,a,`scripts/${t}.js`),r.replace(new RegExp(`\\$${e}\\$SCRIPT_USER\\$`,"g"),a).replace(new RegExp(`\\$${e}\\$FULL_SCRIPT_NAME\\$`,"g"),`${a}.${t}`))))),P.push(l),u(l)}})))),P}export{push as default,push};
package/push.js CHANGED
@@ -1 +1 @@
1
- import e from"fs";import{resolve as i,extname as t,basename as r}from"path";import{s as a}from"./constants-9bb78688.js";import{processScript as s}from"./processScript/index.js";import{D as o,w as p}from"./writeFilePersistent-72dc81a3.js";import{c as n}from"./countHackmudCharacters-1e122984.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./processScript/minify.js";import"acorn";import"terser";import"./processScript/shared.js";import"./assert-1556d989.js";import"./spliceString-2c6f214f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";const{readFile:l,readdir:m}=e.promises;async function push(e,c,{scripts:f=["*.*"],onPush:u=(()=>{}),minify:g=!0,mangleNames:d=!1,forceQuineCheats:h}={}){const b=new o((e=>new Set)),w=new Set,$=new Set;let y=!1;for(const e of f){const[i,t]=e.split(".");i&&"*"!=i?t&&"*"!=t?b.get(i).add(t):w.add(i):t&&"*"!=t?$.add(t):y=!0}const S=new o((e=>new Set)),j=[],P=new o((e=>new Set));let N;if($.size||y){const t=await m(i(c),{withFileTypes:!0}),r=new Set([...(N=await m(i(e),{withFileTypes:!0})).filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isDirectory())).map((e=>e.name)),...t.filter((e=>e.isFile()&&e.name.endsWith(".key"))).map((e=>e.name.slice(0,-4))),...b.keys(),...w]);if(y)for(const e of r)w.add(e);else for(const e of r){const i=b.get(e);for(const e of $)i.add(e)}}return await Promise.all([...w].map((async o=>{await m(i(e,o),{withFileTypes:!0}).then((async m=>{await Promise.all(m.map((async m=>{if(m.name.endsWith(".d.ts"))return;const f=t(m.name);if(m.isFile()&&a.includes(f)){const t=r(m.name,f),a=i(e,o,m.name),{script:b}=await s(await l(a,{encoding:"utf-8"}),{minify:g,scriptUser:o,scriptName:t,filePath:a,mangleNames:d,forceQuineCheats:h}),w={file:`${o}/${m.name}`,users:[o],minLength:n(b),error:void 0};P.get(o).add(t),j.push(w),await p(i(c,o,`scripts/${t}.js`),b),u(w)}})))}),(e=>{if("ENOENT"!=e.code)throw e}))}))),await Promise.all([...b].map((async([t,r])=>{w.has(t)||await Promise.all([...r].map((async r=>{let o,m,f;for(const s of a)try{m=`${r}${s}`,o=await l(f=i(e,t,m),{encoding:"utf-8"});break}catch{}if(o){const{script:e}=await s(o,{minify:g,scriptUser:t,scriptName:r,filePath:f,mangleNames:d,forceQuineCheats:h}),a={file:`${t}/${m}`,users:[t],minLength:n(e),error:void 0};j.push(a),await p(i(c,t,"scripts",`${r}.js`),e),u(a)}else S.get(r).add(t)})))}))),await(w.size?Promise.all((N||await m(i(e),{withFileTypes:!0})).map((async o=>{if(o.name.endsWith(".d.ts"))return;const m=t(o.name);if(!o.isFile()||!a.includes(m))return;const f=r(o.name,m),b=[...w,...S.get(f)].filter((e=>!P.get(e).has(f)));if(!b.length)return;const $=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),y=i(e,o.name),{script:N}=await s(await l(y,{encoding:"utf-8"}),{minify:g,scriptUser:!0,scriptName:f,uniqueID:$,filePath:y,mangleNames:d,forceQuineCheats:h}),F={file:o.name,users:b,minLength:n(N),error:void 0};await Promise.all(b.map((e=>p(i(c,e,`scripts/${f}.js`),N.replace(new RegExp(`\\$${$}\\$SCRIPT_USER\\$`,"g"),e).replace(new RegExp(`\\$${$}\\$FULL_SCRIPT_NAME\\$`,"g"),`${e}.${f}`))))),j.push(F),u(F)}))):Promise.all([...S].map((async([t,r])=>{let o,m,f;for(const r of a)try{m=`${t}${r}`,o=await l(f=i(e,m),{encoding:"utf-8"});break}catch{}if(o){const e=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),{script:a}=await s(o,{minify:g,scriptUser:!0,scriptName:t,uniqueID:e,filePath:f,mangleNames:d,forceQuineCheats:h}),l={file:m,users:[...r],minLength:n(a),error:void 0};await Promise.all([...r].map((r=>p(i(c,r,`scripts/${t}.js`),a.replace(new RegExp(`\\$${e}\\$SCRIPT_USER\\$`,"g"),r).replace(new RegExp(`\\$${e}\\$FULL_SCRIPT_NAME\\$`,"g"),`${r}.${t}`))))),j.push(l),u(l)}})))),j}export{push as default,push};
1
+ export{push as default,push}from"./push-3c3e0dfc.js";import"fs";import"path";import"./transform-eee68ce3.js";import"@babel/traverse";import"@babel/types";import"./shared-eace5bd5.js";import"./assert-22a7ef8a.js";import"./index-73f8f8aa.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./minify-fba250e4.js";import"acorn";import"terser";import"./spliceString-0e6b5d6d.js";import"./postprocess-164b44d3.js";import"./preprocess-67d17495.js";import"import-meta-resolve";import"./writeFilePersistent-0476afeb.js";
@@ -0,0 +1 @@
1
+ import e from"@babel/types";import{e as $}from"./assert-22a7ef8a.js";function getReferencePathsToGlobal(r,a){const[l]=a.unshiftContainer("body",e.variableDeclaration("let",[e.variableDeclarator(e.identifier(r))]));a.scope.crawl();const n=$(a.scope.getBinding(r));return l.remove(),n.referencePaths}function includesIllegalString(e){return e.includes("SC$")||e.includes("DB$")||e.includes("__D_S")||e.includes("__FMCL_")||e.includes("__G_")}function replaceUnsafeStrings(e,$){return $.replace(/SC\$/g,`$${e}$\\$SC_DOLLAR$`).replace(/DB\$/g,`$${e}$\\$DB_DOLLAR$`).replace(/__D_S/g,`$${e}$\\$D$`).replace(/__FMCL_/g,`$${e}$\\$FMCL$`).replace(/__G_/g,`$${e}$\\$G$`).replace(/\/\//g,`$${e}$SLASH_SLASH$`).replace(/#[0-4fhmln]?s(?:\.[_a-z][\d_a-z]{0,24}){2}\(/g,`$${e}$NOT_A_SUBSCRIPT$$$&$`).replace(/#db\.(?<methodName>[irfu]|u1|us|ObjectId)\(/g,`$${e}$NOT_A_DB_CALL$$$1$`).replace(/#D\(/g,`$${e}$NOT_A_DEBUG_CALL$`).replace(/#FMCL/g,`$${e}$NOT_FMCL$`).replace(/#G/g,`$${e}$NOT_G$`)}export{getReferencePathsToGlobal as g,includesIllegalString as i,replaceUnsafeStrings as r};
@@ -0,0 +1 @@
1
+ import e from"fs";import{extname as s,basename as t,resolve as a}from"path";const{readFile:o,readdir:n,stat:r,writeFile:c}=e.promises;async function syncMacros(e){const i=await n(e,{withFileTypes:!0}),m=new Map,l=[];await Promise.all(i.map((async n=>{if(n.isFile())switch(s(n.name)){case".macros":{const[s,t]=await Promise.all([o(a(e,n.name),{encoding:"utf-8"}).then((e=>e.split("\n"))),r(a(e,n.name)).then((({mtime:e})=>e))]);for(let e=0;e<s.length/2-1;e++){const a=s[2*e],o=m.get(a);(!o||t>o.date)&&m.set(a,{date:t,macro:s[2*e+1]})}}break;case".key":l.push(t(n.name,".key"))}})));let f="",p=0;for(const[e,{macro:s}]of[...m].sort((([e],[s])=>(e>s)-(e<s))))s[0]==s[0].toLowerCase()&&(f+=`${e}\n${s}\n`,p++);for(const s of l)c(a(e,`${s}.macros`),f);return{macrosSynced:p,usersSynced:l.length}}export{syncMacros as s};
package/syncMacros.js CHANGED
@@ -1 +1 @@
1
- import e from"fs";import{extname as a,basename as s,resolve as t}from"path";const{readFile:o,readdir:n,stat:r,writeFile:c}=e.promises;async function syncMacros(e){const i=await n(e,{withFileTypes:!0}),m=new Map,l=[];await Promise.all(i.map((async n=>{if(n.isFile())switch(a(n.name)){case".macros":{const[a,s]=await Promise.all([o(t(e,n.name),{encoding:"utf-8"}).then((e=>e.split("\n"))),r(t(e,n.name)).then((({mtime:e})=>e))]);for(let e=0;e<a.length/2-1;e++){const t=a[2*e],o=m.get(t);(!o||s>o.date)&&m.set(t,{date:s,macro:a[2*e+1]})}}break;case".key":l.push(s(n.name,".key"))}})));let f="",p=0;for(const[e,{macro:a}]of[...m].sort((([e],[a])=>(e>a)-(e<a))))a[0]==a[0].toLowerCase()&&(f+=`${e}\n${a}\n`,p++);for(const a of l)c(t(e,`${a}.macros`),f);return{macrosSynced:p,usersSynced:l.length}}export{syncMacros as default,syncMacros};
1
+ export{s as default,s as syncMacros}from"./syncMacros-0bf3ed91.js";import"fs";import"path";
@@ -0,0 +1 @@
1
+ import e from"@babel/traverse";import t from"@babel/types";import{g as i}from"./shared-eace5bd5.js";import{a as r}from"./assert-22a7ef8a.js";const n=[".js",".ts"],o=["i","r","f","u","u1","us","ObjectId"];function clearObject(e,t){for(const t of Object.getOwnPropertyNames(e))delete e[t];for(const t of Object.getOwnPropertySymbols(e))delete e[t];void 0!==t&&Object.setPrototypeOf(e,t)}const{default:a}=e,s=["Map","Set","Date","JSON","Math","Array","Error","isNaN","Number","Object","RegExp","String","Symbol","BigInt"];function transform(e,n,{uniqueID:p="00000000000",scriptUser:c="UNKNOWN",scriptName:l="UNKNOWN",seclevel:d=4}={}){const f=`_${p}_SCRIPT_`,b=new Map,y=new Map;let $;if(a(e,{Program(e){$=e,e.skip()}}),$.scope.hasGlobal("_SOURCE"))for(const e of i("_SOURCE",$))e.replaceWith(t.stringLiteral(n));if($.scope.hasGlobal("_BUILD_DATE"))for(const e of i("_BUILD_DATE",$))e.replaceWith(t.numericLiteral(Date.now()));if($.scope.hasGlobal("_SCRIPT_USER"))for(const e of i("_SCRIPT_USER",$))1==c?e.replaceWith(t.stringLiteral(`$${p}$SCRIPT_USER$`)):e.replaceWith(t.stringLiteral(c));if($.scope.hasGlobal("_SCRIPT_NAME"))for(const e of i("_SCRIPT_NAME",$))1==l?e.replaceWith(t.stringLiteral(`$${p}$SCRIPT_NAME$`)):e.replaceWith(t.stringLiteral(l));if($.scope.hasGlobal("_FULL_SCRIPT_NAME"))for(const e of i("_FULL_SCRIPT_NAME",$))1==c||1==l?e.replaceWith(t.stringLiteral(`$${p}$FULL_SCRIPT_NAME$`)):e.replaceWith(t.stringLiteral(`${c}.${l}`));let m=!1;if($.scope.hasGlobal("Function")){const e=i("Function",$);if(1==e.length){const t=e[0];r("MemberExpression"==t.parent.type,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),r("Identifier"==t.parent.property.type,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),r("prototype"==t.parent.property.name,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),t.parentPath.replaceWith(createGetFunctionPrototypeNode())}else{for(const i of e)r("MemberExpression"==i.parent.type,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),r("Identifier"==i.parent.property.type,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),r("prototype"==i.parent.property.name,"`Function` isn't available in hackmud, only `Function.prototype` is accessible"),m=!0,i.parentPath.replaceWith(t.identifier(`_${p}_FUNCTION_DOT_PROTOTYPE_`));m=!0}}let h=4;for(const e of["$fs","$4s","$s"])$.scope.hasGlobal(e)&&processFakeSubscriptObject(e);for(const e of["$hs","$3s"])$.scope.hasGlobal(e)&&(h=3,processFakeSubscriptObject(e));for(const e of["$ms","$2s"])$.scope.hasGlobal(e)&&(h=2,processFakeSubscriptObject(e));for(const e of["$ls","$1s"])$.scope.hasGlobal(e)&&(h=1,processFakeSubscriptObject(e));for(const e of["$ns","$0s"])$.scope.hasGlobal(e)&&(h=0,processFakeSubscriptObject(e));if(d=Math.min(d,h),$.scope.hasGlobal("$db"))for(const e of i("$db",$)){var E;r("MemberExpression"==e.parentPath.node.type),r("Identifier"==e.parentPath.node.property.type);const i=e.parentPath.node.property.name;r(o.includes(i),`invalid db method "${i}", valid db methods are "${o.join('", "')}"`),"CallExpression"==(null===(E=e.parentPath.parentPath)||void 0===E?void 0:E.type)?e.parentPath.replaceWith(t.identifier(`$${p}$DB$${i}$`)):"ObjectId"==i?e.parentPath.replaceWith(t.arrowFunctionExpression([],t.callExpression(t.identifier(`$${p}$DB$${i}$`),[]))):"i"==i||"r"==i?e.parentPath.replaceWith(t.arrowFunctionExpression([t.identifier("a")],t.callExpression(t.identifier(`$${p}$DB$${i}$`),[t.identifier("a")]))):e.parentPath.replaceWith(t.arrowFunctionExpression([t.identifier("a"),t.identifier("b")],t.callExpression(t.identifier(`$${p}$DB$${i}$`),[t.identifier("a"),t.identifier("b")])))}if($.scope.hasGlobal("$D"))for(const e of i("$D",$))"CallExpression"==e.parentPath.type?e.replaceWith(t.identifier(`$${p}$DEBUG$`)):e.replaceWith(t.arrowFunctionExpression([t.identifier("a")],t.callExpression(t.identifier(`$${p}$DEBUG$`),[t.identifier("a")])));if($.scope.hasGlobal("$FMCL"))for(const e of i("$FMCL",$))e.replaceWith(t.identifier(`$${p}$FMCL$`));if($.scope.hasGlobal("$G"))for(const e of i("$G",$))e.replaceWith(t.identifier(`$${p}$GLOBAL$`));if($.scope.hasGlobal("_SECLEVEL"))for(const e of i("_SECLEVEL",$))e.replaceWith(t.numericLiteral(d));let _=!1,u=!1;if($.scope.hasGlobal("Object"))for(const e of i("Object",$))"MemberExpression"!=e.parent.type||e.parent.computed||(r("Identifier"==e.parent.property.type),"getPrototypeOf"==e.parent.property.name?(e.parentPath.replaceWith(t.identifier(`_${p}_GET_PROTOTYPE_OF_`)),_=!0):"setPrototypeOf"==e.parent.property.name&&(e.parentPath.replaceWith(t.identifier(`_${p}_SET_PROTOTYPE_OF_`)),u=!0));const P=$.node.body[$.node.body.length-1];let O;if(r(P,"program is empty"),"ExportNamedDeclaration"==P.type){$.node.body.pop();for(const e of P.specifiers){r("ExportSpecifier"==e.type,`${e.type} is currently unsupported`);const t="Identifier"==e.exported.type?e.exported.name:e.exported.value;"default"==t?O=e.local.name:b.set(e.local.name,t)}}const x=t.blockStatement([]);let S;for(const e of $.node.body)if("VariableDeclaration"==e.type)for(const i of e.declarations)if("Identifier"!=i.id.type||i.id.name!=O||!i.init||"FunctionExpression"!=i.init.type&&"ArrowFunctionExpression"!=i.init.type||i.init.async||i.init.generator){for(const r in t.getBindingIdentifiers(i.id))r==O&&(S=t.functionDeclaration(t.identifier(f),[t.identifier("context"),t.identifier("args")],t.blockStatement([t.returnStatement(t.callExpression(t.identifier(O),[]))]))),"const"!=e.kind&&b.has(r)&&(y.set(r,b.get(r)),b.delete(r)),x.body.push(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(r))]));i.init&&x.body.push(t.expressionStatement(t.assignmentExpression("=",i.id,i.init)))}else S=t.functionDeclaration(t.identifier(f),i.init.params,"BlockStatement"==i.init.body.type?i.init.body:t.blockStatement([t.returnStatement(i.init.body)]));else"FunctionDeclaration"==e.type?e.id.name==O?S=e:x.body.push(t.variableDeclaration("let",[t.variableDeclarator(e.id,t.functionExpression(void 0,e.params,e.body,e.generator,e.async))])):x.body.push(e);if(S||(S=t.functionDeclaration(t.identifier(f),[t.identifier("context"),t.identifier("args")],t.blockStatement([]))),$.node.body=[S],x.body.length){(b.size||y.size)&&S.body.body.push(t.returnStatement(t.objectExpression([...[...b].map((([e,i])=>t.objectProperty(t.identifier(i),t.identifier(e)))),...[...y].map((([e,i])=>t.objectMethod("get",t.identifier(i),[],t.blockStatement([t.returnStatement(t.identifier(e))]))))]))),$.scope.crawl();const e=new Set;let n=0;for(const[i,o]of[...x.body.entries()].reverse())if("VariableDeclaration"==o.type){r(1==o.declarations.length);const a=o.declarations[0];if(r("Identifier"==a.id.type,`declarator.id.type was "${a.id.type}"`),$.scope.crawl(),$.scope.hasGlobal(a.id.name)){x.body.splice(i,1);const[s]=$.unshiftContainer("body",x),[c]=$.unshiftContainer("body",o);if($.scope.crawl(),!a.init||"FunctionExpression"!=a.init.type&&"ArrowFunctionExpression"!=a.init.type||Object.keys($.scope.globals).some((t=>e.has(t)))){const e=$.scope.getBinding(a.id.name);r(e);for(const i of e.referencePaths)r("Identifier"==i.node.type),i.replaceWith(t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(i.node.name)));for(const i of e.constantViolations)if("AssignmentExpression"==i.node.type)for(const[e,r]of Object.entries(t.getBindingIdentifiers(i.node)))e==a.id.name&&(clearObject(r),Object.assign(r,t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(e))));s.remove(),c.remove(),a.init&&x.body.splice(i,0,t.expressionStatement(t.assignmentExpression("=",t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(a.id.name)),a.init)))}else s.remove(),c.remove(),S.body.body.unshift(o),n++}else e.add(a.id.name)}else if("ClassDeclaration"==o.type&&($.scope.crawl(),$.scope.hasGlobal(o.id.name))){x.body.splice(i,1);const[e]=$.unshiftContainer("body",x),[n]=$.unshiftContainer("body",o);$.scope.crawl();const a=$.scope.getBinding(o.id.name);r(a);for(const e of a.referencePaths)r("Identifier"==e.node.type),e.replaceWith(t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(e.node.name)));e.remove(),n.remove(),x.body.splice(i,0,t.expressionStatement(t.assignmentExpression("=",t.memberExpression(t.identifier(`$${p}$GLOBAL$`),t.identifier(o.id.name)),t.classExpression(void 0,o.superClass,o.body,o.decorators))))}if($.scope.hasGlobal("_EXPORTS"))for(const e of i("_EXPORTS",$))e.replaceWith(t.arrayExpression([...b.keys(),...y.keys()].map((e=>t.stringLiteral(e)))));x.body.length&&S.body.body.splice(n,0,t.ifStatement(t.unaryExpression("!",t.identifier(`$${p}$FMCL$`)),x))}return m&&S.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_FUNCTION_DOT_PROTOTYPE_`),createGetFunctionPrototypeNode())])),u&&S.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_SET_PROTOTYPE_OF_`),t.callExpression(t.memberExpression(t.memberExpression(t.identifier("Object"),t.identifier("call")),t.identifier("bind")),[t.identifier(`_${p}_DUNDER_PROTO_SETTER_`)]))])),_&&S.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_GET_PROTOTYPE_OF_`),t.callExpression(t.memberExpression(t.memberExpression(t.identifier("Object"),t.identifier("call")),t.identifier("bind")),[t.identifier(`_${p}_DUNDER_PROTO_GETTER_`)]))])),(_||u)&&S.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.objectPattern(_?u?[t.objectProperty(t.identifier("get"),t.identifier(`_${p}_DUNDER_PROTO_GETTER_`)),t.objectProperty(t.identifier("set"),t.identifier(`_${p}_DUNDER_PROTO_SETTER_`))]:[t.objectProperty(t.identifier("get"),t.identifier(`_${p}_DUNDER_PROTO_GETTER_`))]:[t.objectProperty(t.identifier("set"),t.identifier(`_${p}_DUNDER_PROTO_SETTER_`))]),t.callExpression(t.memberExpression(t.identifier("Object"),t.identifier("getOwnPropertyDescriptor")),[t.memberExpression(t.identifier("Object"),t.identifier("prototype")),t.stringLiteral("__proto__")]))])),a(e,{BlockStatement({node:e}){for(const[i,r]of e.body.entries())"FunctionDeclaration"!=r.type||r.generator||(e.body.splice(i,1),e.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(r.id,t.arrowFunctionExpression(r.params,r.body,r.async))])))},ClassBody({node:e,scope:i,parent:n}){r(t.isClass(n));let o=!1;for(const r of e.body){if("ClassMethod"!=r.type)continue;let e=!1;if(a(r.body,{ThisExpression(i){e=!0,o=!0,i.replaceWith(t.identifier(`_${p}_THIS_`))},Function(e){e.skip()}},i),e)if("constructor"!=r.kind)r.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_THIS_`),t.callExpression(t.memberExpression(t.super(),t.identifier("valueOf")),[]))]));else{const e=[];if(a(r.body,{CallExpression(t){"Super"==t.node.callee.type&&e.push(t)}},i),e.length)if(1==e.length&&"ExpressionStatement"==e[0].parent.type&&e[0].parentPath.parentPath.parent==r)e[0].parentPath.replaceWith(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_THIS_`),e[0].node)]));else{for(const i of e)i.replaceWith(t.assignmentExpression("=",t.identifier(`_${p}_THIS_`),i.node));r.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_THIS_`))]))}else r.body.body.unshift(t.variableDeclaration("let",[t.variableDeclarator(t.identifier(`_${p}_THIS_`),t.callExpression(t.super(),[]))]))}}!n.superClass&&o&&(n.superClass=t.identifier("Object"))},VariableDeclaration({node:e}){"const"==e.kind&&(e.kind="let")},ThisExpression(e){e.replaceWith(t.identifier("undefined"))},BigIntLiteral(e){const i=Number(e.node.value);BigInt(i)==BigInt(e.node.value)?e.replaceWith(t.callExpression(t.identifier("BigInt"),[t.numericLiteral(i)])):e.replaceWith(t.callExpression(t.identifier("BigInt"),[t.stringLiteral(e.node.value)]))}}),{file:e,seclevel:d};function processFakeSubscriptObject(e){for(const a of i(e,$)){var n,o;r("MemberExpression"==a.parent.type),r("Identifier"==a.parent.property.type),r("MemberExpression"==(null===(n=a.parentPath.parentPath)||void 0===n?void 0:n.node.type)),r("Identifier"==a.parentPath.parentPath.node.property.type),r(/^[_a-z][\d_a-z]{0,24}$/.test(a.parent.property.name),`invalid user "${a.parent.property.name}" in subscript`),r(/^[_a-z][\d_a-z]{0,24}$/.test(a.parentPath.parentPath.node.property.name),`invalid script name "${a.parentPath.parentPath.node.property.name}" in subscript`),"CallExpression"==(null===(o=a.parentPath.parentPath.parentPath)||void 0===o?void 0:o.type)?a.parentPath.parentPath.replaceWith(t.identifier(`$${p}$SUBSCRIPT$${a.parent.property.name}$${a.parentPath.parentPath.node.property.name}$`)):a.parentPath.parentPath.replaceWith(t.arrowFunctionExpression([t.restElement(t.identifier("args"))],t.callExpression(t.identifier(`$${p}$SUBSCRIPT$${a.parent.property.name}$${a.parentPath.parentPath.node.property.name}$`),[t.spreadElement(t.identifier("args"))])))}}function createGetFunctionPrototypeNode(){for(const e of s)if(!$.scope.hasOwnBinding(e))return t.memberExpression(t.memberExpression(t.identifier(e),t.identifier("constructor")),t.identifier("prototype"));return t.memberExpression(t.memberExpression(t.arrowFunctionExpression([t.identifier("_")],t.identifier("_")),t.identifier("constructor")),t.identifier("prototype"))}}export{n as s,transform as t};
@@ -0,0 +1 @@
1
+ import{watch as e}from"chokidar";import r from"fs";import{extname as t,basename as i,resolve as o}from"path";import{s as a}from"./transform-eee68ce3.js";import{g as s}from"./generateTypeDeclaration-8dd67882.js";import{processScript as n}from"./index-73f8f8aa.js";import{D as p,w as l}from"./writeFilePersistent-0476afeb.js";import{a as c}from"./assert-22a7ef8a.js";import{c as m}from"./minify-fba250e4.js";import"@babel/traverse";import"@babel/types";import"./shared-eace5bd5.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./postprocess-164b44d3.js";import"./preprocess-67d17495.js";import"import-meta-resolve";import"./spliceString-0e6b5d6d.js";import"acorn";import"terser";const{readFile:f,readdir:d,writeFile:u}=r.promises;async function watch(r,h,{scripts:g=["*.*"],onPush:w,minify:b=!0,mangleNames:y=!1,typeDeclarationPath:j,onReady:D,forceQuineCheats:T}={}){if(!g.length)throw new Error("scripts option was an empty array");const $=new p((e=>new Set)),v=new Set,F=new Set;let S=!1;for(const e of g){const[r,t]=e.split(".");r&&"*"!=r?t&&"*"!=t?$.get(t).add(r):v.add(r):t&&"*"!=t?F.add(t):S=!0}const E=e(["*.ts","*.js"],{depth:1,cwd:r,awaitWriteFinish:{stabilityThreshold:100},ignored:"*.d.ts"}).on("change",(async e=>{if(e.endsWith(".d.ts"))return;const s=t(e);if(!a.includes(s))return;const u=i(e,s);if(e==i(e)){if(!(S||v.size||F.has(u)||$.has(u)))return;const s=new p((e=>[]));await Promise.all((await d(r,{withFileTypes:!0})).map((async e=>{if(e.isDirectory())for(const n of await d(o(r,e.name),{withFileTypes:!0})){if(!n.isFile())continue;const r=t(n.name);a.includes(r)&&s.get(i(n.name,r)).push(e.name)}})));const g=new Set;if(S||F.has(u)){for(const e of await d(o(r),{withFileTypes:!0}))e.isDirectory()&&g.add(e.name);for(const e of await d(o(h),{withFileTypes:!0}))e.isDirectory()?g.add(e.name):e.isFile()&&e.name.endsWith(".key")&&g.add(e.name.slice(0,-4));for(const e of $.values())for(const r of e)g.add(r)}for(const e of v)g.add(e);for(const e of $.get(u))g.add(e);const j=[...g].filter((e=>!s.has(e)));if(!j.length)return void(null==w||w({file:e,users:[],minLength:0,error:new Error("no users to push to")}));const D=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),E=o(r,e);let P;try{({script:P}=await n(await f(E,{encoding:"utf-8"}),{minify:b,scriptUser:!0,scriptName:u,uniqueID:D,filePath:E,mangleNames:y,forceQuineCheats:T}))}catch(r){return c(r instanceof Error),void(null==w||w({file:e,users:[],minLength:0,error:r}))}return await Promise.all(j.map((e=>l(o(h,e,`scripts/${u}.js`),P.replace(new RegExp(`\\$${D}\\$SCRIPT_USER\\$`,"g"),e).replace(new RegExp(`\\$${D}\\$FULL_SCRIPT_NAME\\$`,"g"),`${e}.${u}`))))),void(null==w||w({file:e,users:j,minLength:m(P),error:void 0}))}const g=i(o(e,".."));if(!(S||v.size||F.has(u)||$.get(u).has(g)))return;const j=o(r,e),D=await f(j,{encoding:"utf-8"});let E;try{({script:E}=await n(D,{minify:b,scriptUser:g,scriptName:u,filePath:j,mangleNames:y,forceQuineCheats:T}))}catch(r){return c(r instanceof Error),void(null==w||w({file:e,users:[],minLength:0,error:r}))}await l(o(h,g,"scripts",`${u}.js`),E),null==w||w({file:e,users:[g],minLength:m(E),error:void 0})}));if(D&&E.on("ready",D),!j)return;let P=j;async function writeTypeDeclaration(){const e=await s(r,h);try{await u(P,e)}catch(r){if(c(r instanceof Error),"EISDIR"!=r.code)throw r;P=o(P,"player.d.ts"),await u(P,e)}}await writeTypeDeclaration(),E.on("add",writeTypeDeclaration),E.on("unlink",writeTypeDeclaration)}export{watch as default,watch};
package/watch.js CHANGED
@@ -1 +1 @@
1
- import{watch as r}from"chokidar";import t from"fs";import{extname as e,basename as o,resolve as i}from"path";import{s as a}from"./constants-9bb78688.js";import{generateTypeDeclaration as s}from"./generateTypeDeclaration.js";import{processScript as n}from"./processScript/index.js";import{D as p,w as l}from"./writeFilePersistent-72dc81a3.js";import{a as c}from"./assert-1556d989.js";import{c as m}from"./countHackmudCharacters-1e122984.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./processScript/minify.js";import"acorn";import"terser";import"./processScript/shared.js";import"./spliceString-2c6f214f.js";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"import-meta-resolve";import"./processScript/transform.js";const{readFile:f,readdir:u,writeFile:d}=t.promises;async function watch(t,h,{scripts:g=["*.*"],onPush:w,minify:b=!0,mangleNames:y=!1,typeDeclarationPath:j,onReady:S,forceQuineCheats:D}={}){if(!g.length)throw new Error("scripts option was an empty array");const T=new p((r=>new Set)),$=new Set,v=new Set;let F=!1;for(const r of g){const[t,e]=r.split(".");t&&"*"!=t?e&&"*"!=e?T.get(e).add(t):$.add(t):e&&"*"!=e?v.add(e):F=!0}const E=r(["*.ts","*.js"],{depth:1,cwd:t,awaitWriteFinish:{stabilityThreshold:100},ignored:"*.d.ts"}).on("change",(async r=>{if(r.endsWith(".d.ts"))return;const s=e(r);if(!a.includes(s))return;const d=o(r,s);if(r==o(r)){if(!(F||$.size||v.has(d)||T.has(d)))return;const s=new p((r=>[]));await Promise.all((await u(t,{withFileTypes:!0})).map((async r=>{if(r.isDirectory())for(const n of await u(i(t,r.name),{withFileTypes:!0})){if(!n.isFile())continue;const t=e(n.name);a.includes(t)&&s.get(o(n.name,t)).push(r.name)}})));const g=new Set;if(F||v.has(d)){for(const r of await u(i(t),{withFileTypes:!0}))r.isDirectory()&&g.add(r.name);for(const r of await u(i(h),{withFileTypes:!0}))r.isDirectory()?g.add(r.name):r.isFile()&&r.name.endsWith(".key")&&g.add(r.name.slice(0,-4));for(const r of T.values())for(const t of r)g.add(t)}for(const r of $)g.add(r);for(const r of T.get(d))g.add(r);const j=[...g].filter((r=>!s.has(r)));if(!j.length)return void(null==w||w({file:r,users:[],minLength:0,error:new Error("no users to push to")}));const S=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),E=i(t,r);let P;try{({script:P}=await n(await f(E,{encoding:"utf-8"}),{minify:b,scriptUser:!0,scriptName:d,uniqueID:S,filePath:E,mangleNames:y,forceQuineCheats:D}))}catch(t){return c(t instanceof Error),void(null==w||w({file:r,users:[],minLength:0,error:t}))}return await Promise.all(j.map((r=>l(i(h,r,`scripts/${d}.js`),P.replace(new RegExp(`\\$${S}\\$SCRIPT_USER\\$`,"g"),r).replace(new RegExp(`\\$${S}\\$FULL_SCRIPT_NAME\\$`,"g"),`${r}.${d}`))))),void(null==w||w({file:r,users:j,minLength:m(P),error:void 0}))}const g=o(i(r,".."));if(!(F||$.size||v.has(d)||T.get(d).has(g)))return;const j=i(t,r),S=await f(j,{encoding:"utf-8"});let E;try{({script:E}=await n(S,{minify:b,scriptUser:g,scriptName:d,filePath:j,mangleNames:y,forceQuineCheats:D}))}catch(t){return c(t instanceof Error),void(null==w||w({file:r,users:[],minLength:0,error:t}))}await l(i(h,g,"scripts",`${d}.js`),E),null==w||w({file:r,users:[g],minLength:m(E),error:void 0})}));if(S&&E.on("ready",S),!j)return;let P=j;async function writeTypeDeclaration(){const r=await s(t,h);try{await d(P,r)}catch(t){if(c(t instanceof Error),"EISDIR"!=t.code)throw t;P=i(P,"player.d.ts"),await d(P,r)}}await writeTypeDeclaration(),E.on("add",writeTypeDeclaration),E.on("unlink",writeTypeDeclaration)}export{watch as default,watch};
1
+ export{watch as default,watch}from"./watch-e580a6f9.js";import"chokidar";import"fs";import"path";import"./transform-eee68ce3.js";import"@babel/traverse";import"@babel/types";import"./shared-eace5bd5.js";import"./assert-22a7ef8a.js";import"./generateTypeDeclaration-8dd67882.js";import"./index-73f8f8aa.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-transform-exponentiation-operator";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"prettier";import"rollup";import"./minify-fba250e4.js";import"acorn";import"terser";import"./spliceString-0e6b5d6d.js";import"./postprocess-164b44d3.js";import"./preprocess-67d17495.js";import"import-meta-resolve";import"./writeFilePersistent-0476afeb.js";
@@ -1 +0,0 @@
1
- const s=[".js",".ts"],t=["i","r","f","u","u1","us","ObjectId"];export{s,t as v};
@@ -1 +0,0 @@
1
- function countHackmudCharacters(u){return u.replace(/\/\/.*/g,"").replace(/[ \t\n\r\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000]/g,"").length}export{countHackmudCharacters as c};