hackmud-script-manager 0.13.0-c14e977 → 0.13.0-c461329

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/.gitattributes +1 -0
  2. package/.github/workflows/codeql-analysis.yml +39 -0
  3. package/.github/workflows/publish.yml +42 -0
  4. package/.vscode/settings.json +6 -0
  5. package/babel.config.json +6 -0
  6. package/package.json +17 -23
  7. package/rollup.config.js +110 -0
  8. package/scripts/build-package-json.js +36 -0
  9. package/scripts/jsconfig.json +5 -0
  10. package/scripts/version-dev.js +25 -0
  11. package/src/bin/hsm.ts +505 -0
  12. package/src/constants.json +3 -0
  13. package/src/generateTypings.ts +116 -0
  14. package/src/index.ts +19 -0
  15. package/src/modules.d.ts +5 -0
  16. package/src/processScript/index.ts +198 -0
  17. package/src/processScript/minify.ts +529 -0
  18. package/src/processScript/postprocess.ts +38 -0
  19. package/src/processScript/preprocess.ts +146 -0
  20. package/src/processScript/transform.ts +760 -0
  21. package/src/pull.ts +16 -0
  22. package/src/push.ts +314 -0
  23. package/src/syncMacros.ts +52 -0
  24. package/src/test.ts +59 -0
  25. package/src/tsconfig.json +20 -0
  26. package/src/watch.ts +156 -0
  27. package/tsconfig.json +12 -0
  28. package/assert-1b7dada8.js +0 -1
  29. package/bin/hsm.d.ts +0 -2
  30. package/bin/hsm.js +0 -2
  31. package/generateTypings.d.ts +0 -2
  32. package/generateTypings.js +0 -1
  33. package/index.d.ts +0 -15
  34. package/index.js +0 -1
  35. package/processScript/compile.d.ts +0 -17
  36. package/processScript/compile.js +0 -1
  37. package/processScript/index.d.ts +0 -30
  38. package/processScript/index.js +0 -1
  39. package/processScript/minify.d.ts +0 -7
  40. package/processScript/minify.js +0 -1
  41. package/processScript/postProcess.d.ts +0 -2
  42. package/processScript/postProcess.js +0 -1
  43. package/processScript/preProcess.d.ts +0 -15
  44. package/processScript/preProcess.js +0 -1
  45. package/pull.d.ts +0 -9
  46. package/pull.js +0 -1
  47. package/push.d.ts +0 -26
  48. package/push.js +0 -1
  49. package/spliceString-2c6f214f.js +0 -1
  50. package/syncMacros.d.ts +0 -5
  51. package/syncMacros.js +0 -1
  52. package/test.d.ts +0 -6
  53. package/test.js +0 -1
  54. package/watch.d.ts +0 -14
  55. package/watch.js +0 -1
package/index.js DELETED
@@ -1 +0,0 @@
1
- export{generateTypings}from"./generateTypings.js";export{processScript}from"./processScript/index.js";export{pull}from"./pull.js";export{push,s as supportedExtensions,t as test,a as watch}from"./push.js";export{syncMacros}from"./syncMacros.js";import"fs";import"path";import"@babel/generator";import"./assert-1b7dada8.js";import"./processScript/minify.js";import"@babel/parser";import"@babel/traverse";import"@babel/types";import"./spliceString-2c6f214f.js";import"acorn";import"terser";import"perf_hooks";import"./processScript/compile.js";import"@babel/core";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";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-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";import"./processScript/postProcess.js";import"./processScript/preProcess.js";import"chokidar";
@@ -1,17 +0,0 @@
1
- import t from "@babel/types";
2
- export declare type CompileOptions = {
3
- /** 11 a-z 0-9 characters */
4
- uniqueID: string;
5
- /** the unprocessed source code (defaults to the given `code` parameter) */
6
- sourceCode: string;
7
- /** the user the script will be uploaded to (or set to `true` if it is not yet known) */
8
- scriptUser: string | true;
9
- /** the name of this script (or set to `true` if it is not yet known) */
10
- scriptName: string | true;
11
- };
12
- /**
13
- * @param code the preprocessed code to be compiled into hackmud compatible code
14
- * @param options {@link CompileOptions details}
15
- */
16
- export declare function compile(code: string, { uniqueID, sourceCode, scriptUser, scriptName }?: Partial<CompileOptions>): Promise<t.File>;
17
- export default compile;
@@ -1 +0,0 @@
1
- import{transformAsync as e}from"@babel/core";import t from"@babel/plugin-proposal-class-properties";import i from"@babel/plugin-proposal-class-static-block";import o from"@babel/plugin-proposal-decorators";import r from"@babel/plugin-proposal-do-expressions";import a from"@babel/plugin-proposal-function-bind";import n from"@babel/plugin-proposal-function-sent";import l from"@babel/plugin-proposal-json-strings";import s from"@babel/plugin-proposal-logical-assignment-operators";import p from"@babel/plugin-proposal-nullish-coalescing-operator";import c from"@babel/plugin-proposal-numeric-separator";import d from"@babel/plugin-proposal-object-rest-spread";import f from"@babel/plugin-proposal-optional-catch-binding";import b from"@babel/plugin-proposal-optional-chaining";import u from"@babel/plugin-proposal-partial-application";import m from"@babel/plugin-proposal-pipeline-operator";import h from"@babel/plugin-proposal-private-property-in-object";import y from"@babel/plugin-proposal-record-and-tuple";import g from"@babel/plugin-proposal-throw-expressions";import $ from"@babel/plugin-transform-exponentiation-operator";import _ from"@babel/plugin-transform-typescript";import x,{NodePath as E,Hub as T}from"@babel/traverse";import D from"@babel/types";import{a as v,e as P}from"../assert-1b7dada8.js";const{default:S}=x;async function compile(x,{uniqueID:P="00000000000",sourceCode:I=x,scriptUser:G="UNKNOWN",scriptName:R="UNKNOWN"}={}){v(P.match(/^\w{11}$/));const C=(await e(x,{plugins:[[_.default],[o.default,{decoratorsBeforeExport:!0}],[r.default],[a.default],[n.default],[u.default],[m.default,{proposal:"hack",topicToken:"%"}],[g.default],[y.default,{syntaxType:"hash"}],[t.default],[i.default],[h.default],[s.default],[c.default],[p.default],[b.default],[f.default],[l.default],[d.default],[$.default]],code:!1,ast:!0,configFile:!1})).ast,L=`_SCRIPT_${P}_`,W=new Map,B=new Map,M=E.get({container:C,hub:new T,key:"program",parent:C,parentPath:null});if(M.scope.hasGlobal("_START"))for(const e of getReferencePathsToGlobal("_START",M))e.replaceWith(D.identifier("_ST"));if(M.scope.hasGlobal("_TIMEOUT"))for(const e of getReferencePathsToGlobal("_START",M))e.replaceWith(D.identifier("_TO"));if(M.scope.hasGlobal("_SOURCE"))for(const e of getReferencePathsToGlobal("_SOURCE",M))e.replaceWith(D.stringLiteral(I));if(M.scope.hasGlobal("_BUILD_TIME"))for(const e of getReferencePathsToGlobal("_BUILD_TIME",M))e.replaceWith(D.numericLiteral(Date.now()));if(M.scope.hasGlobal("_SCRIPT_USER"))for(const e of getReferencePathsToGlobal("_SCRIPT_USER",M))1==G?e.replaceWith(D.stringLiteral(`$${P}$SCRIPT_USER`)):e.replaceWith(D.stringLiteral(G));if(M.scope.hasGlobal("_SCRIPT_NAME"))for(const e of getReferencePathsToGlobal("_SCRIPT_NAME",M))1==R?e.replaceWith(D.stringLiteral(`$${P}$SCRIPT_NAME`)):e.replaceWith(D.stringLiteral(R));if(M.scope.hasGlobal("_FULL_SCRIPT_NAME"))for(const e of getReferencePathsToGlobal("_FULL_SCRIPT_NAME",M))1==G||1==R?e.replaceWith(D.stringLiteral(`$${P}$FULL_SCRIPT_NAME`)):e.replaceWith(D.stringLiteral(`${G}.${R}`));for(const e of["$fs","$hs","$ms","$ls","$ns","$4s","$3s","$2s","$1s","$0s"])if(M.scope.hasGlobal(e))for(const t of getReferencePathsToGlobal(e,M)){var k,N;v("MemberExpression"==t.parent.type),v("Identifier"==t.parent.property.type),v("MemberExpression"==(null===(k=t.parentPath.parentPath)||void 0===k?void 0:k.node.type)),v("Identifier"==(null===(N=t.parentPath.parentPath)||void 0===N?void 0:N.node.property.type)),t.parentPath.parentPath.replaceWith(D.identifier(`$${P}$SUBSCRIPT$${t.parent.property.name}$${t.parentPath.parentPath.node.property.name}`))}if(M.scope.hasGlobal("$db"))for(const e of getReferencePathsToGlobal("$db",M))v("MemberExpression"==e.parentPath.node.type),v("Identifier"==e.parentPath.node.property.type),e.parentPath.replaceWith(D.identifier(`$${P}$DB$${e.parentPath.node.property.name}`));if(M.scope.hasGlobal("$D"))for(const e of getReferencePathsToGlobal("$D",M))e.replaceWith(D.identifier(`$${P}$DEBUG`));if(M.scope.hasGlobal("$FMCL"))for(const e of getReferencePathsToGlobal("$FMCL",M))e.replaceWith(D.identifier(`$${P}$FMCL`));if(M.scope.hasGlobal("$G"))for(const e of getReferencePathsToGlobal("$G",M))e.replaceWith(D.identifier(`$${P}$GLOBAL`));const U=D.blockStatement([]);let F;const w=[];for(const e of M.node.body)if("ExportDefaultDeclaration"==e.type)F&&U.body.push(D.variableDeclaration("let",[D.variableDeclarator(F.id,D.functionExpression(null,F.params,F.body,F.generator,F.async))])),"FunctionDeclaration"==e.declaration.type||"FunctionExpression"==e.declaration.type||"ArrowFunctionExpression"==e.declaration.type?F=D.functionDeclaration(D.identifier(L),e.declaration.params,"BlockStatement"==e.declaration.body.type?e.declaration.body:D.blockStatement([D.returnStatement(e.declaration.body)])):(v(D.isExpression(e.declaration)),F=D.functionDeclaration(D.identifier(L),[D.identifier("context"),D.identifier("args")],D.blockStatement([D.returnStatement(D.callExpression(e.declaration,[]))])));else if("ExportNamedDeclaration"==e.type){if(e.declaration)if("VariableDeclaration"==e.declaration.type)for(const t of e.declaration.declarations)v("Identifier"==t.id.type,"global variable declarations using destructure syntax is currently unsupported"),"const"==e.declaration.kind?W.set(t.id.name,t.id.name):B.set(t.id.name,t.id.name),U.body.push(D.variableDeclaration("let",[D.variableDeclarator(t.id,t.init)]));else{v("id"in e.declaration&&e.declaration.id,`unsupported export type "${e.declaration.type}"`);const t="Identifier"==e.declaration.id.type?e.declaration.id.name:e.declaration.id.value;W.set(t,t),U.body.push(e.declaration)}else if(e.specifiers)for(const t of e.specifiers)v("ExportSpecifier"==t.type,`${t.type} is currently unsupported`),w.includes(t.local.name)?B.set(t.local.name,"Identifier"==t.exported.type?t.exported.name:t.exported.value):W.set(t.local.name,"Identifier"==t.exported.type?t.exported.name:t.exported.value)}else if("VariableDeclaration"==e.type)for(const t of e.declarations)v("Identifier"==t.id.type,"global variable declarations using destructure syntax is currently unsupported"),"const"!=e.kind&&(W.has(t.id.name)?(B.set(t.id.name,W.get(t.id.name)),W.delete(t.id.name)):w.push(t.id.name)),U.body.push(D.variableDeclaration("let",[D.variableDeclarator(t.id,t.init)]));else"FunctionDeclaration"==e.type?F||e.async||e.generator?U.body.push(D.variableDeclaration("let",[D.variableDeclarator(e.id,D.functionExpression(null,e.params,e.body,e.generator,e.async))])):F=e:U.body.push(e);if(F||(F=D.functionDeclaration(D.identifier(L),[D.identifier("context"),D.identifier("args")],D.blockStatement([]))),M.node.body=[F],U.body.length){M.scope.crawl();for(const[e,t]of U.body.entries())if("VariableDeclaration"==t.type){const i=t.declarations[0];if(v("Identifier"==i.id.type,"global variable declarations using destructure syntax is currently unsupported"),M.scope.crawl(),M.scope.hasGlobal(i.id.name)){U.body.splice(e,1);const[o]=M.unshiftContainer("body",U),[r]=M.unshiftContainer("body",t);M.scope.crawl();const a=M.scope.getBinding(i.id.name);v(a);for(const e of a.referencePaths)v("Identifier"==e.node.type),e.replaceWith(D.memberExpression(D.identifier("$G"),D.identifier(e.node.name)));o.remove(),r.remove(),i.init&&U.body.splice(e,0,D.expressionStatement(D.assignmentExpression("=",D.memberExpression(D.identifier("$G"),D.identifier(i.id.name)),i.init)))}}else if("ClassDeclaration"==t.type&&(M.scope.crawl(),M.scope.hasGlobal(t.id.name))){U.body.splice(e,1);const[i]=M.unshiftContainer("body",U),[o]=M.unshiftContainer("body",t);M.scope.crawl();const r=M.scope.getBinding(t.id.name);v(r);for(const e of r.referencePaths)v("Identifier"==e.node.type),e.replaceWith(D.memberExpression(D.identifier("$G"),D.identifier(e.node.name)));i.remove(),o.remove(),U.body.splice(e,0,D.expressionStatement(D.assignmentExpression("=",D.memberExpression(D.identifier("$G"),D.identifier(t.id.name)),D.classExpression(null,t.superClass,t.body,t.decorators))))}(W.size||B.size)&&(U.body.push(D.expressionStatement(D.assignmentExpression("=",D.memberExpression(D.identifier("$G"),D.identifier("_")),D.callExpression(D.memberExpression(D.identifier("Object"),D.identifier("freeze")),[D.objectExpression([...[...W].map((([e,t])=>D.objectProperty(D.identifier(t),D.identifier(e)))),...[...B].map((([e,t])=>D.objectMethod("get",D.identifier(t),[],D.blockStatement([D.returnStatement(D.identifier(e))]))))])])))),F.body.body.push(D.returnStatement(D.memberExpression(D.identifier("$G"),D.identifier("_"))))),F.body.body.unshift(D.ifStatement(D.unaryExpression("!",D.identifier("$FMCL")),U))}S(C,{BlockStatement({node:e}){for(const[t,i]of e.body.entries())"FunctionDeclaration"!=i.type||i.generator||(e.body.splice(t,1),e.body.unshift(D.variableDeclaration("let",[D.variableDeclarator(i.id,D.arrowFunctionExpression(i.params,i.body,i.async))])))},ClassBody({node:e,scope:t,parent:i}){v(D.isClass(i));let o=!1;for(const i of e.body){if("ClassMethod"!=i.type)continue;let e=!1;if(S(i.body,{ThisExpression(t){e=!0,o=!0,t.replaceWith(D.identifier(`_THIS_${P}_`))},Function(e){e.skip()}},t),e)if("constructor"!=i.kind)i.body.body.unshift(D.variableDeclaration("let",[D.variableDeclarator(D.identifier(`_THIS_${P}_`),D.callExpression(D.memberExpression(D.super(),D.identifier("valueOf")),[]))]));else{const e=[];if(S(i.body,{CallExpression(t){"Super"==t.node.callee.type&&e.push(t)}},t),e.length)if(1==e.length&&"ExpressionStatement"==e[0].parent.type&&e[0].parentPath.parentPath.parent==i)e[0].parentPath.replaceWith(D.variableDeclaration("let",[D.variableDeclarator(D.identifier(`_THIS_${P}_`),e[0].node)]));else{for(const t of e)t.replaceWith(D.assignmentExpression("=",D.identifier(`_THIS_${P}_`),t.node));i.body.body.unshift(D.variableDeclaration("let",[D.variableDeclarator(D.identifier(`_THIS_${P}_`))]))}else i.body.body.unshift(D.variableDeclaration("let",[D.variableDeclarator(D.identifier(`_THIS_${P}_`),D.callExpression(D.super(),[]))]))}}!i.superClass&&o&&(i.superClass=D.identifier("Object"))},VariableDeclaration({node:e}){"const"==e.kind&&(e.kind="let")},ThisExpression(e){e.replaceWith(D.identifier(`_UNDEFINED_${P}_`))},BigIntLiteral(e){const t=Number(e.node.value);BigInt(t)==BigInt(e.node.value)?e.replaceWith(D.callExpression(D.identifier("BigInt"),[D.numericLiteral(t)])):e.replaceWith(D.callExpression(D.identifier("BigInt"),[D.stringLiteral(e.node.value)]))}});const A=M.get("body.0").scope;for(const e of[...F.params].reverse()){if("Identifier"==e.type){if(!A.getBinding(e.name).referenced){F.params.pop();continue}}break}for(const e in M.scope.globals){if(e.startsWith(`$${P}`))continue;const t=getReferencePathsToGlobal(e,M);if(!(5+e.length+t.length>=e.length*t.length)){for(const i of t)i.replaceWith(D.identifier(`_GLOBAL_${e}_${P}_`));F.body.body.unshift(D.variableDeclaration("let",[D.variableDeclarator(D.identifier(`_GLOBAL_${e}_${P}_`),D.identifier(e))]))}}return C}function getReferencePathsToGlobal(e,t){const[i]=t.unshiftContainer("body",D.variableDeclaration("let",[D.variableDeclarator(D.identifier(e))]));t.scope.crawl();const o=P(t.scope.getBinding(e));return i.remove(),o.referencePaths}export{compile,compile as default};
@@ -1,30 +0,0 @@
1
- export { compile } from "./compile";
2
- export { minify } from "./minify";
3
- export { postProcess } from "./postProcess";
4
- export { preProcess } from "./preProcess";
5
- export declare type ProcessOptions = {
6
- /** whether to minify the given code */
7
- minify: boolean;
8
- /** 11 a-z 0-9 characters */
9
- uniqueID: string;
10
- /** the user the script will be uploaded to (or set to `true` if it is not yet known) */
11
- scriptUser: string | true;
12
- /** the name of this script (or set to `true` if it is not yet known) */
13
- scriptName: string | true;
14
- };
15
- /**
16
- * Minifies a given script
17
- *
18
- * @param code JavaScript or TypeScript code
19
- * @param options {@link ProcessOptions details}
20
- */
21
- export declare function processScript(code: string, { minify: shouldMinify, uniqueID, scriptUser, scriptName }?: Partial<ProcessOptions>): Promise<{
22
- srcLength: number;
23
- script: string;
24
- warnings: {
25
- message: string;
26
- line: number;
27
- }[];
28
- timeTook: number;
29
- }>;
30
- export default processScript;
@@ -1 +0,0 @@
1
- import o from"@babel/generator";import{a as p}from"../assert-1b7dada8.js";import"fs";import"path";import{g as r,minify as i}from"./minify.js";export{minify}from"./minify.js";import{performance as t}from"perf_hooks";import{compile as e}from"./compile.js";export{compile}from"./compile.js";import{postProcess as s}from"./postProcess.js";export{postProcess}from"./postProcess.js";import{preProcess as a}from"./preProcess.js";export{preProcess}from"./preProcess.js";import"@babel/parser";import"@babel/traverse";import"@babel/types";import"../spliceString-2c6f214f.js";import"acorn";import"terser";import"@babel/core";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";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-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";const{default:l}=o;async function processScript(o,{minify:n=!0,uniqueID:m=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),scriptUser:c="UNKNOWN",scriptName:b="UNKNOWN"}={}){var u;p(m.match(/^\w{11}$/));const g=t.now(),f=o;let d,j,h;({autocomplete:d,code:o,seclevel:j,semicolons:h}=a(o,{uniqueID:m})),o=l(await e(o,{uniqueID:m,sourceCode:f,scriptUser:c,scriptName:b})).code;let w=r(o.replace(/^function\s*\w+\(/,"function("))-((null===(u=o.match(/;/g))||void 0===u?void 0:u.length)||0)+h;return n&&(o=await i(o,d,m)),{srcLength:w,script:o=s(o,j,m),warnings:[],timeTook:t.now()-g}}export{processScript as default,processScript};
@@ -1,7 +0,0 @@
1
- /**
2
- * @param code compiled code and/or hackmud compatible code
3
- * @param autocomplete the comment inserted after the function signature
4
- * @param uniqueID 11 a-z 0-9 characters
5
- */
6
- export declare function minify(code: string, autocomplete: string, uniqueID?: string): Promise<string>;
7
- export default minify;
@@ -1 +0,0 @@
1
- import e from"@babel/generator";import{parse as t}from"@babel/parser";import r from"@babel/traverse";import i from"@babel/types";import{a as n}from"../assert-1b7dada8.js";import"fs";import"path";import{s as a}from"../spliceString-2c6f214f.js";import{tokenizer as s,tokTypes as o}from"acorn";import*as p from"terser";function getHackmudCharacterCount(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:l}=e,{default:u}=r;async function minify(e,r,s="00000000000"){n(s.match(/^\w{11}$/));const o=[];let c,f=!1;e=(await p.minify(e,{ecma:2015,parse:{bare_returns:!0},compress:{passes:1/0,unsafe:!0,booleans:!1,sequences:!1}})).code||"";{const r=await t(e);u(r,{MemberExpression({node:e}){e.computed||(n("Identifier"==e.property.type),"prototype"==e.property.name?(e.computed=!0,e.property=i.identifier(`_PROTOTYPE_PROPERTY_${s}_`)):"__proto__"==e.property.name&&(e.computed=!0,e.property=i.identifier(`_PROTO_PROPERTY_${s}_`)))}}),c=(await p.minify(l(r).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}})).code.replace(new RegExp(`_PROTOTYPE_PROPERTY_${s}_`,"g"),'"prototype"').replace(new RegExp(`_PROTO_PROPERTY_${s}_`,"g"),'"__proto__"')}let d=null,m=!1;{const r=await t(e),a=[];u(r,{FunctionDeclaration(e){e.traverse({Function(e){"CallExpression"!=e.parent.type&&"callee"!=e.parentKey&&e.skip()},Loop(e){e.skip()},ObjectExpression(e){const t={};parseObjectExpression(e.node,t)&&e.replaceWith(i.identifier(`_JSON_VALUE_${o.push(t)-1}_${s}_`))},ArrayExpression(e){const t=[];parseArrayExpression(e.node,t)&&e.replaceWith(i.identifier(`_JSON_VALUE_${o.push(t)-1}_${s}_`))}}),e.traverse({TemplateLiteral(e){const t=e.node;let r=i.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];r=i.binaryExpression("+",r,n),a.value.cooked&&(r=i.binaryExpression("+",r,i.stringLiteral(a.value.cooked)))}e.replaceWith(r)},MemberExpression({node:e}){e.computed||(n("Identifier"==e.property.type),e.property.name.length<3||(e.computed=!0,e.property=i.stringLiteral(e.property.name)))},UnaryExpression(e){"void"!=e.node.operator||"NumericLiteral"!=e.node.argument.type||e.node.argument.value||(e.replaceWith(i.identifier(`_UNDEFINED_${s}_`)),f=!0)},NullLiteral(e){let t=o.indexOf(null);-1==t&&(t+=o.push(null)),e.replaceWith(i.identifier(`_JSON_VALUE_${t}_${s}_`))},BooleanLiteral(e){let t=o.indexOf(e.node.value);-1==t&&(t+=o.push(e.node.value)),e.replaceWith(i.identifier(`_JSON_VALUE_${t}_${s}_`))},NumericLiteral(e){a.push((async()=>{if((await minifyNumber(e.node.value)).length<=3)return;"key"==e.parentKey&&"ObjectProperty"==e.parent.type&&(e.parent.computed=!0);let t=o.indexOf(e.node.value);-1==t&&(t+=o.push(e.node.value)),e.replaceWith(i.identifier(`_JSON_VALUE_${t}_${s}_`))})())},StringLiteral(e){if(e.node.value.includes("\0")||e.node.value.length<2)return;"key"==e.parentKey&&"ObjectProperty"==e.parent.type&&(e.parent.computed=!0);let t=o.indexOf(e.node.value);-1==t&&(t+=o.push(e.node.value)),e.replaceWith(i.identifier(`_JSON_VALUE_${t}_${s}_`))},ObjectProperty({node:e}){if(e.computed||"Identifier"!=e.key.type||e.key.name.length<4)return;let t=o.indexOf(e.key.name);-1==t&&(t+=o.push(e.key.name)),e.computed=!0,e.key=i.identifier(`_JSON_VALUE_${t}_${s}_`)}}),e.skip()}}),await Promise.all(a);const[p]=r.program.body;if(n("FunctionDeclaration"==p.type),o.length)if(m=!0,1==o.length)if("string"!=typeof o[0]||o[0].includes("\n")||o[0].includes("\t")){const e=i.variableDeclaration("let",[i.variableDeclarator(i.identifier(`_JSON_VALUE_0_${s}_`),i.callExpression(i.memberExpression(i.identifier("JSON"),i.identifier("parse")),[i.memberExpression(i.taggedTemplateExpression(i.memberExpression(i.callExpression(i.identifier(`$${s}$SUBSCRIPT$scripts$quine`),[]),i.identifier("split")),i.templateLiteral([i.templateElement({raw:"\t",cooked:"\t"},!0)],[])),i.identifier(`$${s}$SPLIT_INDEX`),!0)]))]);f&&e.declarations.push(i.variableDeclarator(i.identifier(`_UNDEFINED_${s}_`))),p.body.body.unshift(e),d=JSON.stringify(o[0])}else{const e=i.variableDeclaration("let",[i.variableDeclarator(i.identifier(`_JSON_VALUE_0_${s}_`),i.memberExpression(i.taggedTemplateExpression(i.memberExpression(i.callExpression(i.identifier(`$${s}$SUBSCRIPT$scripts$quine`),[]),i.identifier("split")),i.templateLiteral([i.templateElement({raw:"\t",cooked:"\t"},!0)],[])),i.identifier(`$${s}$SPLIT_INDEX`),!0))]);f&&e.declarations.push(i.variableDeclarator(i.identifier(`_UNDEFINED_${s}_`))),p.body.body.unshift(e),d=o[0]}else{const e=i.variableDeclaration("let",[i.variableDeclarator(i.arrayPattern(o.map(((e,t)=>i.identifier(`_JSON_VALUE_${t}_${s}_`)))),i.callExpression(i.memberExpression(i.identifier("JSON"),i.identifier("parse")),[i.memberExpression(i.taggedTemplateExpression(i.memberExpression(i.callExpression(i.identifier(`$${s}$SUBSCRIPT$scripts$quine`),[]),i.identifier("split")),i.templateLiteral([i.templateElement({raw:"\t",cooked:"\t"},!0)],[])),i.identifier(`$${s}$SPLIT_INDEX`),!0)]))]);f&&e.declarations.push(i.variableDeclarator(i.identifier(`_UNDEFINED_${s}_`))),p.body.body.unshift(e),d=JSON.stringify(o)}else f&&p.body.body.unshift(i.variableDeclaration("let",[i.variableDeclarator(i.identifier(`_UNDEFINED_${s}_`))]));e=l(r).code}if(e=(await p.minify(e,{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}})).code||"",null!=d){e=a(e,`${r?`//${r}\n`:""}\n//\t${d}\t\n`,getFunctionBodyStart(e)+1);for(const[t,r]of e.split("\t").entries())if(r==d){e=e.replace(`$${s}$SPLIT_INDEX`,await minifyNumber(t));break}}return getHackmudCharacterCount(c)<=getHackmudCharacterCount(e)+Number(m)&&(e=c,r&&(e=a(e,`//${r}\n`,getFunctionBodyStart(e)+1))),e}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(n("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)return!1;t["Identifier"==r.key.type?r.key.name:r.key.value]=r.value.value}}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)return!1;t.push(r.value)}}return!0}async function minifyNumber(e){return(await p.minify(`$(${e})`,{ecma:2015})).code.match(/\$\((.+)\)/)[1]}function getFunctionBodyStart(e){const t=s(e,{ecmaVersion:2015});t.getToken(),t.getToken(),t.getToken();let r=1;for(;r;){const e=t.getToken();e.type==o.parenL?r++:e.type==o.parenR&&r--}return t.getToken().start}export{minify as default,getHackmudCharacterCount as g,minify};
@@ -1,2 +0,0 @@
1
- export declare function postProcess(code: string, seclevel: number, uniqueID: string): string;
2
- export default postProcess;
@@ -1 +0,0 @@
1
- import"fs";import"path";import{s as e}from"../spliceString-2c6f214f.js";function*findMatches(e,t){let s;for(;s=e.exec(t);)yield{index:s.index,match:s[0]}}function postProcess(t,s,r){t=t.replace(/^function\s*\w+\(/,"function(");for(const{index:n,match:c}of[...findMatches(new RegExp(`\\$${r}\\$[\\w$]+`,"g"),t)].reverse()){const[r,...o]=c.slice(13).split("$");switch(r){case"SUBSCRIPT":t=e(t,`#${"nlmhf"[s]}s.${o[0]}.${o[1]}`,n,n+c.length);break;case"DEBUG":t=e(t,"#D",n,n+c.length);break;case"FMCL":t=e(t,"#FMCL",n,n+c.length);break;case"GLOBAL":t=e(t,"#GLOBAL",n,n+c.length);break;case"DB":t=e(t,`#db.${o[0]}`,n,n+c.length);break;default:throw new Error(`unknown preprocessor directive type "${r}"`)}}return t}export{postProcess as default,postProcess};
@@ -1,15 +0,0 @@
1
- export declare type PreprocessOptions = {
2
- /** 11 a-z 0-9 characters */
3
- uniqueID: string;
4
- };
5
- /**
6
- * @param code source code to be preprocessed
7
- * @param options {@link PreprocessOptions details}
8
- */
9
- export declare function preProcess(code: string, { uniqueID }?: Partial<PreprocessOptions>): {
10
- semicolons: number;
11
- autocomplete: string;
12
- seclevel: number;
13
- code: string;
14
- };
15
- export default preProcess;
@@ -1 +0,0 @@
1
- import{parse as e}from"@babel/parser";import{a as s}from"../assert-1b7dada8.js";import"fs";import"path";import{s as t}from"../spliceString-2c6f214f.js";function preProcess(o,{uniqueID:a="00000000000"}={}){var l,r;let c,i,n;if(s(a.match(/^\w{11}$/)),[,c,o,i]=o.match(/((?:^\s*\/\/.*\n)*)\s*((?:.+?\/\/\s*(.+?)\s*$)?[^]*)/m),o.match(/(?:SC|DB)\$/))throw new Error("SC$ and DB$ are protected and cannot appear in a script");for(const e of c.split("\n")){let[,s,t]=e.match(/^\s*\/\/\s*(?:@autocomplete\s*([^\s].*?)|@seclevel\s*([^\s].*?))\s*$/)||[];s?i=s:t&&(t.match(/^(?:fullsec|f|4|fs|full)$/i)?n=4:t.match(/^(?:highsec|h|3|hs|high)$/i)?n=3:t.match(/^(?:midsec|m|2|ms|mid)$/i)?n=2:t.match(/^(?:lowsec|l|1|ls|low)$/i)?n=1:t.match(/^(?:nullsec|n|0|ns|null)$/i)&&(n=0))}let p=4;o.match(/[#$][n0]s\.[a-z_][a-z_0-9]{0,24}\.[a-z_][a-z_0-9]{0,24}\(/)?p=0:o.match(/[#$][l1]s\.[a-z_][a-z_0-9]{0,24}\.[a-z_][a-z_0-9]{0,24}\(/)?p=1:o.match(/[#$][m2]s\.[a-z_][a-z_0-9]{0,24}\.[a-z_][a-z_0-9]{0,24}\(/)?p=2:o.match(/[#$][h3]s\.[a-z_][a-z_0-9]{0,24}\.[a-z_][a-z_0-9]{0,24}\(/)&&(p=3);const h=["NULLSEC","LOWSEC","MIDSEC","HIGHSEC","FULLSEC"];if(null==n)n=p;else if(p<n)throw new Error(`detected seclevel ${h[p]} is lower than stated seclevel ${h[n]}`);const m=null!==(l=null===(r=o.match(/;/g))||void 0===r?void 0:r.length)&&void 0!==l?l:0,$=o;let f;for(o=o.replace(/^function\s*\(/,"export default function (");;){let l;try{f=e(o,{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),l=e}var d;if("BABEL_PARSER_SYNTAX_ERROR"!=l.code||"PrivateInExpectedIn"!=l.reasonCode)throw console.log(null===(d=o.slice(l.pos).match(/.+/))||void 0===d?void 0:d[0]),l;const r=o.slice(l.pos);let c;if(c=r.match(/^#[fhmln43210]s\.scripts\.quine\(\)/))o=t(o,JSON.stringify($),l.pos,l.pos+c[0].length);else if(c=r.match(/^#[fhmln43210]?s\.([a-z_][a-z_0-9]{0,24})\.([a-z_][a-z_0-9]{0,24})\(/))o=t(o,`$${a}$SUBSCRIPT$${c[1]}$${c[2]}(`,l.pos,l.pos+c[0].length);else if(c=r.match(/^#D\(/))o=t(o,`$${a}$DEBUG(`,l.pos,l.pos+c[0].length);else if(c=r.match(/^#FMCL/))o=t(o,`$${a}$FMCL`,l.pos,l.pos+c[0].length);else if(c=r.match(/^#G/))o=t(o,`$${a}$GLOBAL`,l.pos,l.pos+c[0].length);else{if(!(c=r.match(/^#db\.(i|r|f|u|u1|us|ObjectId)\(/)))throw l;o=t(o,`$${a}$DB$${c[1]}(`,l.pos,l.pos+c[0].length)}}return{semicolons:m,autocomplete:i,seclevel:n,code:o}}export{preProcess as default,preProcess};
package/pull.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * Copies script from hackmud to local source folder.
3
- *
4
- * @param sourceFolderPath path to folder containing source files
5
- * @param hackmudPath path to hackmud directory
6
- * @param script script to pull in `user.name` format
7
- */
8
- export declare function pull(sourceFolderPath: string, hackmudPath: string, script: string): Promise<void>;
9
- export default pull;
package/pull.js DELETED
@@ -1 +0,0 @@
1
- import{promises as t}from"fs";import{dirname as i,resolve as s}from"path";const{mkdir:c,copyFile:o}=t;async function pull(t,r,a){const[p,e]=a.split(".");await function copyFilePersistent(t,s,r){return o(t,s,r).catch((async a=>{if("ENOENT"!=a.code)throw a;await c(i(s),{recursive:!0}),await o(t,s,r)}))}(s(r,p,"scripts",`${e}.js`),s(t,p,`${e}.js`))}export{pull as default,pull};
package/push.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { Info } from ".";
2
- interface PushOptions {
3
- /**
4
- * array of scripts in the format `foo.bar`
5
- *
6
- * also accepts wild card e.g. `*.bar` or `foo.*`
7
- *
8
- * pushes everything by default
9
- */
10
- scripts: string | string[];
11
- /** callback when a script is pushed */
12
- onPush: (info: Info) => void;
13
- /** whether to do the minify step (defaults to `true`) */
14
- minify: boolean;
15
- }
16
- /**
17
- * Push scripts from a source directory to the hackmud directory.
18
- *
19
- * Files directly in the source folder are pushed to all users
20
- * @param sourceDirectory directory containing source code
21
- * @param hackmudDirectory directory created by hackmud containing user data including scripts
22
- * @param options {@link PushOptions details}
23
- * @returns array of info on pushed scripts
24
- */
25
- export declare function push(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify }?: Partial<PushOptions>): Promise<Info[]>;
26
- export default push;
package/push.js DELETED
@@ -1 +0,0 @@
1
- import{generateTypings as e}from"./generateTypings.js";import{processScript as t}from"./processScript/index.js";import"./pull.js";import i,{promises as s}from"fs";import{dirname as r,resolve as a,extname as n,basename as o}from"path";import{g as p}from"./processScript/minify.js";import"./syncMacros.js";import{watch as l}from"chokidar";import"@babel/generator";import"./assert-1b7dada8.js";import"perf_hooks";import"./processScript/compile.js";import"@babel/core";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";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-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";import"@babel/traverse";import"@babel/types";import"./processScript/postProcess.js";import"./spliceString-2c6f214f.js";import"./processScript/preProcess.js";import"@babel/parser";import"acorn";import"terser";class DynamicMap extends Map{constructor(e){super(),this.fallbackHandler=e}get(e){if(super.has(e))return super.get(e);const t=this.fallbackHandler(e);return super.set(e,t),t}}function forEachParallel(e,t){const i=[];for(const s of e)i.push(t(s));return Promise.all(i)}const{writeFile:c,mkdir:m}=s;function writeFilePersistent(e,t,i){return c(e,t,i).catch((async s=>{if("ENOENT"!=s.code)throw s;await m(r(e),{recursive:!0}),await c(e,t,i)}))}const{readFile:u,readdir:f}=s;async function push(e,i,{scripts:s="*.*",onPush:r=(e=>{}),minify:l=!0}={}){"string"==typeof s&&(s=[s]);const c=new DynamicMap((e=>new Set)),m=new Set,h=new Set;let g=!1;for(const e of s){const[t,i]=e.split(".");t&&"*"!=t?i&&"*"!=i?c.get(t).add(i):m.add(t):i&&"*"!=i?h.add(i):g=!0}const w=new DynamicMap((e=>new Set)),d=[],y=new DynamicMap((e=>new Set));let $;if(h.size||g){const t=await f(a(i),{withFileTypes:!0}),s=new Set([...($=await f(a(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()&&".key"==n(e.name))).map((e=>e.name.slice(0,-4))),...c.keys(),...m]);if(g)for(const e of s)m.add(e);else for(const e of s){const t=c.get(e);for(const e of h)t.add(e)}}return await forEachParallel(m,(async s=>{await f(a(e,s),{withFileTypes:!0}).then((async c=>{await forEachParallel(c,(async c=>{const m=n(c.name);if(c.isFile()&&b.includes(m)){const n=o(c.name,m),{srcLength:f,script:h}=await t(await u(a(e,s,c.name),{encoding:"utf-8"}),{minify:l,scriptUser:s,scriptName:n}),g={file:`${s}/${c.name}`,users:[s],minLength:p(h),error:null,srcLength:f};y.get(s).add(n),d.push(g),await writeFilePersistent(a(i,s,`scripts/${n}.js`),h),r(g)}}))}),(e=>{if("ENOENT"!=e.code)throw e}))})),await forEachParallel(c,(async([s,n])=>{m.has(s)||await forEachParallel(n,(async n=>{let o,c;for(const t of b)try{c=`${n}${t}`,o=await u(a(e,s,c),{encoding:"utf-8"});break}catch{}if(o){const{srcLength:e,script:m}=await t(o,{minify:l,scriptUser:s,scriptName:n}),u={file:`${s}/${c}`,users:[s],minLength:p(m),error:null,srcLength:e};d.push(u),await writeFilePersistent(a(i,s,"scripts",`${n}.js`),m),r(u)}else w.get(n).add(s)}))})),m.size?await forEachParallel($||await f(a(e),{withFileTypes:!0}),(async s=>{const c=n(s.name);if(!s.isFile()||!b.includes(c))return;const f=o(s.name,c),h=[...m,...w.get(f)].filter((e=>!y.get(e).has(f)));if(!h.length)return;const g=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),{srcLength:$,script:F}=await t(await u(a(e,s.name),{encoding:"utf-8"}),{minify:l,scriptUser:!0,scriptName:f,uniqueID:g}),P={file:s.name,users:h,minLength:p(F),error:null,srcLength:$};await forEachParallel(h,(e=>writeFilePersistent(a(i,e,`scripts/${f}.js`),F.replace(new RegExp(`$${g}$SCRIPT_USER`,"g"),e).replace(new RegExp(`$${g}$FULL_SCRIPT_NAME`,"g"),`${e}.${f}`)))),d.push(P),r(P)})):await forEachParallel(w,(async([s,n])=>{let o,c;for(const t of b)try{c=`${s}${t}`,o=await u(a(e,c),{encoding:"utf-8"});break}catch{}if(o){const e=Math.floor(Math.random()*2**52).toString(36).padStart(11,"0"),{srcLength:m,script:u}=await t(o,{minify:l,scriptUser:!0,scriptName:s,uniqueID:e}),f={file:c,users:[...n],minLength:p(u),error:null,srcLength:m};await forEachParallel(n,(t=>writeFilePersistent(a(i,t,`scripts/${s}.js`),u.replace(new RegExp(`$${e}$SCRIPT_USER`,"g"),t).replace(new RegExp(`$${e}$FULL_SCRIPT_NAME`,"g"),`${t}.${s}`)))),d.push(f),r(f)}})),d}const{readFile:h,readdir:g}=i.promises;async function test(e){const i=[],s=[];for(const r of await g(e,{withFileTypes:!0}))r.isDirectory()?i.push(g(a(e,r.name),{withFileTypes:!0}).then((i=>{const o=[];for(const p of i)p.isFile()&&b.includes(n(p.name))&&o.push(h(a(e,r.name,p.name),{encoding:"utf-8"}).then(t).then((({warnings:e})=>s.push(...e.map((({message:e,line:t})=>({file:`${r.name}/${p.name}`,message:e,line:t})))))));return Promise.all(o)}))):r.isFile()&&b.includes(n(r.name))&&i.push(h(a(e,r.name),{encoding:"utf-8"}).then(t).then((({warnings:e})=>s.push(...e.map((({message:e,line:t})=>({file:r.name,message:e,line:t})))))));return await Promise.all(i),s}const{readFile:w,readdir:d}=s;function watch(i,s,r,c,m,{genTypes:u}={}){const f=l("",{depth:1,cwd:i,awaitWriteFinish:{stabilityThreshold:100}}).on("change",(async e=>{const l=n(e);if(b.includes(l)){const u=o(e,l);if(e==o(e)){if(!c.length||c.includes(u)){const l=await w(a(i,e),{encoding:"utf-8"}),c=new Map,f=[];for(const e of await d(i,{withFileTypes:!0}))e.isDirectory()&&f.push(d(a(i,e.name),{withFileTypes:!0}).then((t=>{for(const i of t){if(!i.isFile())continue;const t=n(i.name);if(!b.includes(t))continue;const s=o(i.name,t),r=c.get(s);r?r.push(e.name):c.set(s,[e.name])}})));await Promise.all(f);let h=null;const{script:g,srcLength:y}=await t(l).catch((e=>(h=e,{script:"",srcLength:0}))),$={file:e,users:[],minLength:0,error:h,srcLength:y},F=[];if(!h)if(g){const e=c.get(u)||[];$.minLength=p(g),r.length||(r=(await d(s,{withFileTypes:!0})).filter((e=>e.isFile()&&".key"==n(e.name))).map((e=>o(e.name,".key"))));for(const t of r)e.includes(t)||($.users.push(t),F.push(writeFilePersistent(a(s,t,"scripts",`${u}.js`),g)))}else $.error=new Error("processed script was empty");m&&(await Promise.all(F),m($))}}else{const n=o(a(e,".."));if((!r.length||r.includes(n))&&(!c.length||c.includes(u))){const r=await w(a(i,e),{encoding:"utf-8"});let o=null;const{script:l,srcLength:c}=await t(r).catch((e=>(o=e,{script:"",srcLength:0}))),f={file:e,users:[n],minLength:0,error:o,srcLength:c};o||(l?(f.minLength=p(l),await writeFilePersistent(a(s,n,"scripts",`${u}.js`),l)):f.error=new Error("processed script was empty")),null==m||m(f)}}}}));u&&(e(i,a(i,u),s),f.on("add",(()=>e(i,a(i,u),s))),f.on("unlink",(()=>e(i,a(i,u),s))))}const b=[".js",".ts"];export{DynamicMap as D,watch as a,push as default,push,b as s,test as t,writeFilePersistent as w};
@@ -1 +0,0 @@
1
- function spliceString(i,e,s,c=0){return i.slice(0,s)+e+i.slice(s+c)}export{spliceString as s};
package/syncMacros.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export declare function syncMacros(hackmudPath: string): Promise<{
2
- macrosSynced: number;
3
- usersSynced: number;
4
- }>;
5
- export default syncMacros;
package/syncMacros.js DELETED
@@ -1 +0,0 @@
1
- import{promises as e}from"fs";import{extname as t,basename as a,resolve as o}from"path";const{readFile:s,readdir:n,stat:r,writeFile:c}=e;async function syncMacros(e){const i=await n(e,{withFileTypes:!0}),m=new Map,f=[];for(const n of i)if(n.isFile())switch(t(n.name)){case".macros":{const t=(await s(o(e,n.name),{encoding:"utf-8"})).split("\n"),a=(await r(o(e,n.name))).mtime;for(let e=0;e<t.length/2-1;e++){const o=t[2*e],s=m.get(o);(!s||a>s.date)&&m.set(o,{date:a,macro:t[2*e+1]})}}break;case".key":f.push(a(n.name,".key"))}let l="",d=0;for(const[e,{macro:t}]of[...m].sort((([e],[t])=>(e>t)-(e<t))))t[0]==t[0].toLowerCase()&&(l+=`${e}\n${t}\n`,d++);for(const t of f)c(o(e,t+".macros"),l);return{macrosSynced:d,usersSynced:f.length}}export{syncMacros as default,syncMacros};
package/test.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare function test(srcPath: string): Promise<{
2
- file: string;
3
- message: string;
4
- line: number;
5
- }[]>;
6
- export default test;
package/test.js DELETED
@@ -1 +0,0 @@
1
- import"fs";import"path";export{t as default,t as test}from"./push.js";import"./processScript/index.js";import"./generateTypings.js";import"./pull.js";import"./processScript/minify.js";import"@babel/generator";import"@babel/parser";import"@babel/traverse";import"@babel/types";import"./assert-1b7dada8.js";import"./spliceString-2c6f214f.js";import"acorn";import"terser";import"./syncMacros.js";import"chokidar";import"perf_hooks";import"./processScript/compile.js";import"@babel/core";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";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-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";import"./processScript/postProcess.js";import"./processScript/preProcess.js";
package/watch.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { Info } from ".";
2
- /**
3
- * Watches target file or folder for updates and builds and pushes updated file.
4
- *
5
- * @param srcDir path to folder containing source files
6
- * @param hackmudDir path to hackmud directory
7
- * @param users users to push to (pushes to all if empty)
8
- * @param scripts scripts to push from (pushes from all if empty)
9
- * @param onPush function that's called after each script has been built and written
10
- */
11
- export declare function watch(srcDir: string, hackmudDir: string, users: string[], scripts: string[], onPush?: (info: Info) => void, { genTypes }?: {
12
- genTypes?: string | undefined;
13
- }): void;
14
- export default watch;
package/watch.js DELETED
@@ -1 +0,0 @@
1
- import"fs";import"path";import"./processScript/minify.js";export{a as default,a as watch}from"./push.js";import"chokidar";import"./processScript/index.js";import"./generateTypings.js";import"@babel/generator";import"@babel/parser";import"@babel/traverse";import"@babel/types";import"./assert-1b7dada8.js";import"./spliceString-2c6f214f.js";import"acorn";import"terser";import"./pull.js";import"./syncMacros.js";import"perf_hooks";import"./processScript/compile.js";import"@babel/core";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";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-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";import"./processScript/postProcess.js";import"./processScript/preProcess.js";