hackmud-script-manager 0.19.1-d57be2a → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,8 +21,8 @@ const { default: traverse } = babelTraverse,
21
21
  "Symbol",
22
22
  "BigInt"
23
23
  ]
24
- function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scriptName, seclevel = 4 }) {
25
- const topFunctionName = `_${uniqueID}_SCRIPT_`,
24
+ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scriptName, seclevel = 4 }) {
25
+ const topFunctionName = `_${uniqueId}_SCRIPT_`,
26
26
  exports = new Map(),
27
27
  liveExports = new Map()
28
28
  let program
@@ -43,22 +43,22 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
43
43
  for (const referencePath of getReferencePathsToGlobal("_SCRIPT_USER", program))
44
44
  if (null == scriptUser) {
45
45
  uniqueIdScriptUserNeeded = !0
46
- referencePath.replaceWith(t.identifier(`_${uniqueID}_SCRIPT_USER_`))
46
+ referencePath.replaceWith(t.identifier(`_${uniqueId}_SCRIPT_USER_`))
47
47
  } else
48
- referencePath.replaceWith(t.stringLiteral(1 == scriptUser ? `$${uniqueID}$SCRIPT_USER$` : scriptUser))
48
+ referencePath.replaceWith(t.stringLiteral(1 == scriptUser ? `$${uniqueId}$SCRIPT_USER$` : scriptUser))
49
49
  if (program.scope.hasGlobal("_SCRIPT_NAME"))
50
50
  for (const referencePath of getReferencePathsToGlobal("_SCRIPT_NAME", program))
51
- referencePath.replaceWith(t.stringLiteral(1 == scriptName ? `$${uniqueID}$SCRIPT_NAME$` : scriptName))
51
+ referencePath.replaceWith(t.stringLiteral(1 == scriptName ? `$${uniqueId}$SCRIPT_NAME$` : scriptName))
52
52
  if (program.scope.hasGlobal("_FULL_SCRIPT_NAME"))
53
53
  for (const referencePath of getReferencePathsToGlobal("_FULL_SCRIPT_NAME", program))
54
54
  if (1 == scriptUser || 1 == scriptName)
55
- referencePath.replaceWith(t.stringLiteral(`$${uniqueID}$FULL_SCRIPT_NAME$`))
55
+ referencePath.replaceWith(t.stringLiteral(`$${uniqueId}$FULL_SCRIPT_NAME$`))
56
56
  else if (null == scriptUser) {
57
57
  uniqueIdScriptUserNeeded = !0
58
58
  referencePath.replaceWith(
59
59
  t.binaryExpression(
60
60
  "+",
61
- t.identifier(`_${uniqueID}_SCRIPT_USER_`),
61
+ t.identifier(`_${uniqueId}_SCRIPT_USER_`),
62
62
  t.stringLiteral("." + scriptName)
63
63
  )
64
64
  )
@@ -96,7 +96,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
96
96
  "src/processScript/transform.ts:133:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
97
97
  )
98
98
  functionDotPrototypeIsReferencedMultipleTimes = !0
99
- referencePath.parentPath.replaceWith(t.identifier(`_${uniqueID}_FUNCTION_DOT_PROTOTYPE_`))
99
+ referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_FUNCTION_DOT_PROTOTYPE_`))
100
100
  }
101
101
  functionDotPrototypeIsReferencedMultipleTimes = !0
102
102
  }
@@ -137,10 +137,10 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
137
137
  `src/processScript/transform.ts:194:8 invalid db method "${databaseOpMethodName}", valid db methods are "${validDBMethods.join('", "')}"`
138
138
  )
139
139
  if ("CallExpression" == referencePath.parentPath.parentPath?.type)
140
- referencePath.parentPath.replaceWith(t.identifier(`$${uniqueID}$DB$${databaseOpMethodName}$`))
140
+ referencePath.parentPath.replaceWith(t.identifier(`$${uniqueId}$DB$${databaseOpMethodName}$`))
141
141
  else {
142
142
  referencePath.parentPath.replaceWith(
143
- t.identifier(`_${uniqueID}_CONSOLE_METHOD_${databaseOpMethodName}_`)
143
+ t.identifier(`_${uniqueId}_CONSOLE_METHOD_${databaseOpMethodName}_`)
144
144
  )
145
145
  neededDbMethodLets.add(databaseOpMethodName)
146
146
  }
@@ -149,17 +149,17 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
149
149
  if (program.scope.hasGlobal("$D"))
150
150
  for (const referencePath of getReferencePathsToGlobal("$D", program))
151
151
  if ("CallExpression" == referencePath.parentPath.type)
152
- referencePath.replaceWith(t.identifier(`$${uniqueID}$DEBUG$`))
152
+ referencePath.replaceWith(t.identifier(`$${uniqueId}$DEBUG$`))
153
153
  else {
154
- referencePath.replaceWith(t.identifier(`_${uniqueID}_DEBUG_`))
154
+ referencePath.replaceWith(t.identifier(`_${uniqueId}_DEBUG_`))
155
155
  needDebugLet = !0
156
156
  }
157
157
  if (program.scope.hasGlobal("$FMCL"))
158
158
  for (const referencePath of getReferencePathsToGlobal("$FMCL", program))
159
- referencePath.replaceWith(t.identifier(`$${uniqueID}$FMCL$`))
159
+ referencePath.replaceWith(t.identifier(`$${uniqueId}$FMCL$`))
160
160
  if (program.scope.hasGlobal("$G"))
161
161
  for (const referencePath of getReferencePathsToGlobal("$G", program))
162
- referencePath.replaceWith(t.identifier(`$${uniqueID}$GLOBAL$`))
162
+ referencePath.replaceWith(t.identifier(`$${uniqueId}$GLOBAL$`))
163
163
  if (program.scope.hasGlobal("_SECLEVEL"))
164
164
  for (const referencePath of getReferencePathsToGlobal("_SECLEVEL", program))
165
165
  referencePath.replaceWith(t.numericLiteral(seclevel))
@@ -169,7 +169,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
169
169
  if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
170
170
  assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:241:64")
171
171
  if ("getPrototypeOf" == referencePath.parent.property.name) {
172
- referencePath.parentPath.replaceWith(t.identifier(`_${uniqueID}_GET_PROTOTYPE_OF_`))
172
+ referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_GET_PROTOTYPE_OF_`))
173
173
  needGetPrototypeOf = !0
174
174
  }
175
175
  }
@@ -179,7 +179,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
179
179
  if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
180
180
  assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:256:64")
181
181
  referencePath.parentPath.replaceWith(
182
- t.identifier(`_${uniqueID}_CONSOLE_METHOD_${referencePath.parent.property.name}_`)
182
+ t.identifier(`_${uniqueId}_CONSOLE_METHOD_${referencePath.parent.property.name}_`)
183
183
  )
184
184
  consoleMethodsReferenced.add(referencePath.parent.property.name)
185
185
  }
@@ -269,16 +269,16 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
269
269
  )
270
270
  if (uniqueIdScriptUserNeeded) {
271
271
  const mainFunctionParams = mainFunction.params
272
- mainFunction.params = [t.restElement(t.identifier(`_${uniqueID}_PARAMS_`))]
272
+ mainFunction.params = [t.restElement(t.identifier(`_${uniqueId}_PARAMS_`))]
273
273
  mainFunction.body.body.unshift(
274
274
  t.variableDeclaration("let", [
275
- t.variableDeclarator(t.arrayPattern(mainFunctionParams), t.identifier(`_${uniqueID}_PARAMS_`)),
275
+ t.variableDeclarator(t.arrayPattern(mainFunctionParams), t.identifier(`_${uniqueId}_PARAMS_`)),
276
276
  t.variableDeclarator(
277
- t.arrayPattern([t.identifier(`_${uniqueID}_SCRIPT_USER_`)]),
277
+ t.arrayPattern([t.identifier(`_${uniqueId}_SCRIPT_USER_`)]),
278
278
  t.callExpression(
279
279
  t.memberExpression(
280
280
  t.memberExpression(
281
- t.memberExpression(t.identifier(`_${uniqueID}_PARAMS_`), t.numericLiteral(0), !0),
281
+ t.memberExpression(t.identifier(`_${uniqueId}_PARAMS_`), t.numericLiteral(0), !0),
282
282
  t.identifier("this_script")
283
283
  ),
284
284
  t.identifier("split")
@@ -338,7 +338,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
338
338
  assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:436:56")
339
339
  referencePath.replaceWith(
340
340
  t.memberExpression(
341
- t.identifier(`$${uniqueID}$GLOBAL$`),
341
+ t.identifier(`$${uniqueId}$GLOBAL$`),
342
342
  t.identifier(referencePath.node.name)
343
343
  )
344
344
  )
@@ -350,7 +350,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
350
350
  clearObject(node)
351
351
  Object.assign(
352
352
  node,
353
- t.memberExpression(t.identifier(`$${uniqueID}$GLOBAL$`), t.identifier(name))
353
+ t.memberExpression(t.identifier(`$${uniqueId}$GLOBAL$`), t.identifier(name))
354
354
  )
355
355
  }
356
356
  globalBlockPath.remove()
@@ -363,7 +363,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
363
363
  t.assignmentExpression(
364
364
  "=",
365
365
  t.memberExpression(
366
- t.identifier(`$${uniqueID}$GLOBAL$`),
366
+ t.identifier(`$${uniqueId}$GLOBAL$`),
367
367
  t.identifier(declarator.id.name)
368
368
  ),
369
369
  declarator.init
@@ -391,7 +391,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
391
391
  assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:502:55")
392
392
  referencePath.replaceWith(
393
393
  t.memberExpression(
394
- t.identifier(`$${uniqueID}$GLOBAL$`),
394
+ t.identifier(`$${uniqueId}$GLOBAL$`),
395
395
  t.identifier(referencePath.node.name)
396
396
  )
397
397
  )
@@ -405,7 +405,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
405
405
  t.assignmentExpression(
406
406
  "=",
407
407
  t.memberExpression(
408
- t.identifier(`$${uniqueID}$GLOBAL$`),
408
+ t.identifier(`$${uniqueId}$GLOBAL$`),
409
409
  t.identifier(globalBlockStatement.id.name)
410
410
  ),
411
411
  t.classExpression(
@@ -428,14 +428,14 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
428
428
  mainFunction.body.body.splice(
429
429
  hoistedGlobalBlockFunctions,
430
430
  0,
431
- t.ifStatement(t.unaryExpression("!", t.identifier(`$${uniqueID}$FMCL$`)), globalBlock)
431
+ t.ifStatement(t.unaryExpression("!", t.identifier(`$${uniqueId}$FMCL$`)), globalBlock)
432
432
  )
433
433
  }
434
434
  functionDotPrototypeIsReferencedMultipleTimes &&
435
435
  mainFunction.body.body.unshift(
436
436
  t.variableDeclaration("let", [
437
437
  t.variableDeclarator(
438
- t.identifier(`_${uniqueID}_FUNCTION_DOT_PROTOTYPE_`),
438
+ t.identifier(`_${uniqueId}_FUNCTION_DOT_PROTOTYPE_`),
439
439
  createGetFunctionPrototypeNode()
440
440
  )
441
441
  ])
@@ -445,7 +445,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
445
445
  t.variableDeclaration("let", [
446
446
  t.variableDeclarator(
447
447
  t.objectPattern([
448
- t.objectProperty(t.identifier("get"), t.identifier(`_${uniqueID}_DUNDER_PROTO_GETTER_`))
448
+ t.objectProperty(t.identifier("get"), t.identifier(`_${uniqueId}_DUNDER_PROTO_GETTER_`))
449
449
  ]),
450
450
  t.callExpression(
451
451
  t.memberExpression(t.identifier("Object"), t.identifier("getOwnPropertyDescriptor")),
@@ -456,7 +456,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
456
456
  )
457
457
  ),
458
458
  t.variableDeclarator(
459
- t.identifier(`_${uniqueID}_GET_PROTOTYPE_OF_`),
459
+ t.identifier(`_${uniqueId}_GET_PROTOTYPE_OF_`),
460
460
  t.callExpression(
461
461
  t.memberExpression(
462
462
  t.memberExpression(
@@ -467,7 +467,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
467
467
  ),
468
468
  t.identifier("bind")
469
469
  ),
470
- [t.identifier(`_${uniqueID}_DUNDER_PROTO_GETTER_`)]
470
+ [t.identifier(`_${uniqueId}_DUNDER_PROTO_GETTER_`)]
471
471
  )
472
472
  )
473
473
  ])
@@ -478,12 +478,12 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
478
478
  "let",
479
479
  [...consoleMethodsReferenced].map(name =>
480
480
  t.variableDeclarator(
481
- t.identifier(`_${uniqueID}_CONSOLE_METHOD_${name}_`),
481
+ t.identifier(`_${uniqueId}_CONSOLE_METHOD_${name}_`),
482
482
  t.arrowFunctionExpression(
483
483
  [t.restElement(t.identifier("args"))],
484
484
  t.unaryExpression(
485
485
  "void",
486
- t.callExpression(t.identifier(`$${uniqueID}$DEBUG$`), [t.identifier("args")])
486
+ t.callExpression(t.identifier(`$${uniqueId}$DEBUG$`), [t.identifier("args")])
487
487
  )
488
488
  )
489
489
  )
@@ -500,10 +500,10 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
500
500
  : "i" == name || "r" == name ? [t.identifier("a")]
501
501
  : [t.identifier("a"), t.identifier("b")]
502
502
  return t.variableDeclarator(
503
- t.identifier(`_${uniqueID}_CONSOLE_METHOD_${name}_`),
503
+ t.identifier(`_${uniqueId}_CONSOLE_METHOD_${name}_`),
504
504
  t.arrowFunctionExpression(
505
505
  getArgs(),
506
- t.callExpression(t.identifier(`$${uniqueID}$DB$${name}$`), getArgs())
506
+ t.callExpression(t.identifier(`$${uniqueId}$DB$${name}$`), getArgs())
507
507
  )
508
508
  )
509
509
  })
@@ -513,8 +513,8 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
513
513
  mainFunction.body.body.unshift(
514
514
  t.variableDeclaration("let", [
515
515
  t.variableDeclarator(
516
- t.identifier(`_${uniqueID}_DEBUG_`),
517
- t.callExpression(t.identifier(`$${uniqueID}$DEBUG$`), [t.identifier("a")])
516
+ t.identifier(`_${uniqueId}_DEBUG_`),
517
+ t.callExpression(t.identifier(`$${uniqueId}$DEBUG$`), [t.identifier("a")])
518
518
  )
519
519
  ])
520
520
  )
@@ -524,10 +524,10 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
524
524
  "let",
525
525
  [...neededSubscriptLets].map(name =>
526
526
  t.variableDeclarator(
527
- t.identifier(`_${uniqueID}_SUBSCRIPT_${name}_`),
527
+ t.identifier(`_${uniqueId}_SUBSCRIPT_${name}_`),
528
528
  t.arrowFunctionExpression(
529
529
  [t.restElement(t.identifier("args"))],
530
- t.callExpression(t.identifier(`$${uniqueID}$SUBSCRIPT$${name}$`), [
530
+ t.callExpression(t.identifier(`$${uniqueId}$SUBSCRIPT$${name}$`), [
531
531
  t.spreadElement(t.identifier("args"))
532
532
  ])
533
533
  )
@@ -566,7 +566,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
566
566
  ThisExpression(path) {
567
567
  methodReferencesThis = !0
568
568
  thisIsReferenced = !0
569
- path.replaceWith(t.identifier(`_${uniqueID}_THIS_`))
569
+ path.replaceWith(t.identifier(`_${uniqueId}_THIS_`))
570
570
  },
571
571
  Function: path => path.skip()
572
572
  },
@@ -577,7 +577,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
577
577
  classMethod.body.body.unshift(
578
578
  t.variableDeclaration("let", [
579
579
  t.variableDeclarator(
580
- t.identifier(`_${uniqueID}_THIS_`),
580
+ t.identifier(`_${uniqueId}_THIS_`),
581
581
  t.callExpression(t.memberExpression(t.super(), t.identifier("valueOf")), [])
582
582
  )
583
583
  ])
@@ -601,17 +601,17 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
601
601
  )
602
602
  superCalls[0].parentPath.replaceWith(
603
603
  t.variableDeclaration("let", [
604
- t.variableDeclarator(t.identifier(`_${uniqueID}_THIS_`), superCalls[0].node)
604
+ t.variableDeclarator(t.identifier(`_${uniqueId}_THIS_`), superCalls[0].node)
605
605
  ])
606
606
  )
607
607
  else {
608
608
  for (const path of superCalls)
609
609
  path.replaceWith(
610
- t.assignmentExpression("=", t.identifier(`_${uniqueID}_THIS_`), path.node)
610
+ t.assignmentExpression("=", t.identifier(`_${uniqueId}_THIS_`), path.node)
611
611
  )
612
612
  classMethod.body.body.unshift(
613
613
  t.variableDeclaration("let", [
614
- t.variableDeclarator(t.identifier(`_${uniqueID}_THIS_`))
614
+ t.variableDeclarator(t.identifier(`_${uniqueId}_THIS_`))
615
615
  ])
616
616
  )
617
617
  }
@@ -619,7 +619,7 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
619
619
  classMethod.body.body.unshift(
620
620
  t.variableDeclaration("let", [
621
621
  t.variableDeclarator(
622
- t.identifier(`_${uniqueID}_THIS_`),
622
+ t.identifier(`_${uniqueId}_THIS_`),
623
623
  t.callExpression(t.super(), [])
624
624
  )
625
625
  ])
@@ -682,12 +682,12 @@ function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scr
682
682
  if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
683
683
  referencePath.parentPath.parentPath.replaceWith(
684
684
  t.identifier(
685
- `$${uniqueID}$SUBSCRIPT$${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}$`
685
+ `$${uniqueId}$SUBSCRIPT$${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}$`
686
686
  )
687
687
  )
688
688
  else {
689
689
  const name = `${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}`
690
- referencePath.parentPath.parentPath.replaceWith(t.identifier(`_${uniqueID}_SUBSCRIPT_${name}_`))
690
+ referencePath.parentPath.parentPath.replaceWith(t.identifier(`_${uniqueId}_SUBSCRIPT_${name}_`))
691
691
  neededSubscriptLets.add(name)
692
692
  }
693
693
  }
package/push.js CHANGED
@@ -106,14 +106,14 @@ async function push(
106
106
  await Promise.all(
107
107
  [...pathsToUsers].map(async ([path, [...users]]) => {
108
108
  const scriptName = basename(path.slice(0, -3)),
109
- uniqueID = Math.floor(Math.random() * 2 ** 52)
109
+ uniqueId = Math.floor(Math.random() * 2 ** 52)
110
110
  .toString(36)
111
111
  .padStart(11, "0"),
112
112
  { script: minifiedCode } = await processScript(await readFile(path, { encoding: "utf8" }), {
113
113
  minify,
114
114
  scriptUser: !0,
115
115
  scriptName,
116
- uniqueID,
116
+ uniqueId,
117
117
  filePath: path,
118
118
  mangleNames,
119
119
  forceQuineCheats
@@ -124,8 +124,8 @@ async function push(
124
124
  writeFilePersistent(
125
125
  resolve(hackmudPath, user, `scripts/${scriptName}.js`),
126
126
  minifiedCode
127
- .replace(RegExp(`\\$${uniqueID}\\$SCRIPT_USER\\$`, "g"), user)
128
- .replace(RegExp(`\\$${uniqueID}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
127
+ .replace(RegExp(`\\$${uniqueId}\\$SCRIPT_USER\\$`, "g"), user)
128
+ .replace(RegExp(`\\$${uniqueId}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
129
129
  )
130
130
  )
131
131
  )
package/watch.js CHANGED
@@ -119,7 +119,7 @@ async function watch(
119
119
  onPush?.({ path, users: [], characterCount: 0, error: Error("no users to push to") })
120
120
  return
121
121
  }
122
- const uniqueID = Math.floor(Math.random() * 2 ** 52)
122
+ const uniqueId = Math.floor(Math.random() * 2 ** 52)
123
123
  .toString(36)
124
124
  .padStart(11, "0"),
125
125
  filePath = resolve(sourceDirectory, path)
@@ -129,7 +129,7 @@ async function watch(
129
129
  minify,
130
130
  scriptUser: !0,
131
131
  scriptName,
132
- uniqueID,
132
+ uniqueId,
133
133
  filePath,
134
134
  mangleNames,
135
135
  forceQuineCheats
@@ -144,8 +144,8 @@ async function watch(
144
144
  writeFilePersistent(
145
145
  resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
146
146
  minifiedCode
147
- .replace(RegExp(`\\$${uniqueID}\\$SCRIPT_USER\\$`, "g"), user)
148
- .replace(RegExp(`\\$${uniqueID}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
147
+ .replace(RegExp(`\\$${uniqueId}\\$SCRIPT_USER\\$`, "g"), user)
148
+ .replace(RegExp(`\\$${uniqueId}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
149
149
  )
150
150
  )
151
151
  )