hackmud-script-manager 0.19.1-98e81f8 → 0.19.1-bf4dc4a

Sign up to get free protection for your applications and to get access to all the features.
package/bin/hsm.js CHANGED
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { Cache } from "@samual/lib/Cache"
3
3
  import { assert } from "@samual/lib/assert"
4
+ import { catchError } from "@samual/lib/catchError"
4
5
  import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
6
+ import { getDeepObjectProperty } from "@samual/lib/getDeepObjectProperty"
7
+ import { isRecord } from "@samual/lib/isRecord"
8
+ import { setDeepObjectProperty } from "@samual/lib/setDeepObjectProperty"
5
9
  import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
6
10
  import { readFile, writeFile, mkdir, rmdir } from "fs/promises"
7
11
  import { homedir } from "os"
@@ -10,6 +14,7 @@ import { supportedExtensions } from "../constants.js"
10
14
  import { generateTypeDeclaration } from "../generateTypeDeclaration.js"
11
15
  import { pull } from "../pull.js"
12
16
  import { syncMacros } from "../syncMacros.js"
17
+ import "@samual/lib/readDirectoryWithStats"
13
18
  import "@samual/lib/copyFilePersistent"
14
19
  const configDirectoryPath = resolve(homedir(), ".config"),
15
20
  configFilePath = resolve(configDirectoryPath, "hsm.json"),
@@ -28,8 +33,8 @@ const configDirectoryPath = resolve(homedir(), ".config"),
28
33
  ),
29
34
  logHelp = () => {
30
35
  const pushCommandDescription = "Push scripts from a directory to hackmud user's scripts directories",
31
- mangleNamesOptionDescription = "Reduce character count further but lose function names in error call stacks"
32
- console.log(colourN("Version") + colourS(": ") + colourV("0.19.1-98e81f8"))
36
+ forceQuineCheatsOptionDescription = `Force quine cheats on. Use ${colourN("--force-quine-cheats")}=${colourV("false")} to force off`
37
+ console.log(colourN("Version") + colourS(": ") + colourV("0.19.1-bf4dc4a"))
33
38
  switch (commands[0]) {
34
39
  case "config":
35
40
  switch (commands[1]) {
@@ -56,18 +61,12 @@ const configDirectoryPath = resolve(homedir(), ".config"),
56
61
  )
57
62
  }
58
63
  break
59
- case "push":
60
- console.log(
61
- colourS(
62
- `\n${colourJ(pushCommandDescription)}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<directory> [<script user>.<script name>...]")}\n\n${colourA("Options:")}\n${colourN("--skip-minify")}\n Skip minification to produce a readable script\n${colourN("--mangle-names")}\n ${mangleNamesOptionDescription}\n${colourN("--force-quine-cheats")}\n Force quine cheats even if the character count is higher`
63
- )
64
- )
65
- break
66
64
  case "dev":
67
65
  case "watch":
66
+ case "push":
68
67
  console.log(
69
68
  colourS(
70
- `${colourN("Aliases")}: ${colourV("watch, dev")}\n\n${colourJ("Watch a directory and push a script when modified")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<directory> [<script user>.<script name>...]")}\n\n${colourA("Options:")}\n${colourN("--skip-minify")}\n Skip minification to produce a readable script\n${colourN("--mangle-names")}\n ${mangleNamesOptionDescription}\n${colourN("--type-declaration-path")}=${colourB("<path>")}\n Path to generate a type declaration file for the scripts\n${colourN("--force-quine-cheats")}\n Force quine cheats even if the character count is higher`
69
+ `\n${colourJ("push" == commands[0] ? pushCommandDescription : "Watch a directory and push a script when modified")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB('<directory> ["<script user>.<script name>"...]')}\n\n${colourA("Arguments:")}\n${colourB("<directory>")}\n The source directory containing your scripts\n${colourB("<script user>")}\n A user to push script(s) to. Can be set to wild card (${colourV("*")}) which will try\n and discover users to push to\n${colourB("<script name>")}\n Name of a script to push. Can be set to wild card (${colourV("*")}) to find all scripts\n\n${colourA("Options:")}\n${colourN("--no-minify")}\n Skip minification to produce a "readable" script\n${colourN("--mangle-names")}\n Reduce character count further but lose function names in error call stacks\n${colourN("--force-quine-cheats")}\n ${forceQuineCheatsOptionDescription}\n${"push" == commands[0] ? "" : `${colourN("--type-declaration-path")}=${colourB("<path>")}\n Path to generate a type declaration file for the scripts\n`}\n${colourA("Examples:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")}\n\tPushes all scripts found in ${colourV("src")} folder to all users\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("foo")}${colourV(".")}${colourL("bar")}\n Pushes a script named ${colourL("bar")} found in ${colourV("src")} folder to user ${userColours.get("foo")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("foo")}${colourV(".")}${colourL("bar")} ${colourC("baz")}${colourV(".")}${colourL("qux")}\n Multiple can be specified.\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("foo")}${colourV(".")}${colourL("*")}\n\tPushes all scripts found in ${colourV("src")} folder to user ${userColours.get("foo")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("*")}${colourV(".")}${colourL("foo")}\n\tPushes all scripts named ${colourL("foo")} found in ${colourV("src")} folder to all user\n${colourC("hsm")} ${colourL(commands[0])} ${colourV("src")} ${colourC("*")}${colourV(".")}${colourL("*")}\n\tPushes all scripts found in ${colourV("src")} folder to all users`
71
70
  )
72
71
  )
73
72
  break
@@ -82,7 +81,7 @@ const configDirectoryPath = resolve(homedir(), ".config"),
82
81
  case "golf":
83
82
  console.log(
84
83
  colourS(
85
- `${colourN("Aliases")}: ${colourV("minify, golf")}\n\n${colourJ("Minify a script file on the spot")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<target> [output path]")}\n\n${colourA("Options:")}\n${colourN("--skip-minify")}\n Skip minification to produce a readable script\n${colourN("--mangle-names")}\n ${mangleNamesOptionDescription}\n${colourN("--force-quine-cheats")}\n Force quine cheats even if the character count is higher\n${colourN("--watch")}\n Watch for changes`
84
+ `\n${colourJ("Minify a script file on the spot")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<target> [output path]")}\n\n${colourA("Options:")}\n${colourN("--no-minify")}\n Skip minification to produce a "readable" script\n${colourN("--mangle-names")}\n Reduce character count further but lose function names in error call stacks\n${colourN("--force-quine-cheats")}\n ${forceQuineCheatsOptionDescription}\n${colourN("--watch")}\n Watch for changes`
86
85
  )
87
86
  )
88
87
  break
@@ -92,7 +91,7 @@ const configDirectoryPath = resolve(homedir(), ".config"),
92
91
  case "gen-types":
93
92
  console.log(
94
93
  colourS(
95
- `${colourN("Aliases")}: ${colourV("generate-type-declaration, gen-type-declaration, gen-types, gen-dts")}\n\n${colourJ("Generate a type declaration file for a directory of scripts")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<directory> [output path]")}`
94
+ `${colourJ("Generate a type declaration file for a directory of scripts")}\n\n${colourA("Usage:")}\n${colourC("hsm")} ${colourL(commands[0])} ${colourB("<directory> [output path]")}`
96
95
  )
97
96
  )
98
97
  break
@@ -102,20 +101,27 @@ const configDirectoryPath = resolve(homedir(), ".config"),
102
101
  default:
103
102
  console.log(
104
103
  colourS(
105
- `\n${colourJ("Hackmud Script Manager")}\n\n${colourA("Commands:")}\n${colourL("push")}\n ${pushCommandDescription}\n${colourL("watch")}, ${colourL("dev")}\n Watch a directory and push a script when modified\n${colourL("minify")}, ${colourL("golf")}\n Minify a script file on the spot\n${colourL("generate-type-declaration")}, ${colourL("gen-type-declaration")}, ${colourL("gen-types")}, ${colourL("gen-dts")}\n Generate a type declaration file for a directory of scripts\n${colourL("sync-macros")}\n Sync macros across all hackmud users\n${colourL("config")}\n Modify and view the config file\n${colourL("pull")}\n Pull a script a from a hackmud user's script directory`
104
+ `\n${colourJ("Hackmud Script Manager")}\n\n${colourA("Commands:")}\n${colourL("push")}\n ${pushCommandDescription}\n${colourL("dev")}\n Watch a directory and push a script when modified\n${colourL("golf")}\n Minify a script file on the spot\n${colourL("gen-dts")}\n Generate a type declaration file for a directory of scripts\n${colourL("sync-macros")}\n Sync macros across all hackmud users\n${colourL("config")}\n Modify and view the config file\n${colourL("pull")}\n Pull a script a from a hackmud user's script directory`
106
105
  )
107
106
  )
108
107
  }
109
108
  },
110
- exploreObject = (object, keys, createPath = !1) => {
111
- for (const key of keys)
112
- object =
113
- createPath ?
114
- "object" == typeof object[key] ?
115
- object[key]
116
- : (object[key] = {})
117
- : object?.[key]
118
- return object
109
+ updateConfig = async config => {
110
+ const json = JSON.stringify(config, void 0, "\t")
111
+ configDidNotExist && log("Creating config file at " + configFilePath)
112
+ await writeFile(configFilePath, json).catch(async error => {
113
+ switch (error.code) {
114
+ case "EISDIR":
115
+ await rmdir(configFilePath)
116
+ break
117
+ case "ENOENT":
118
+ await mkdir(configDirectoryPath)
119
+ break
120
+ default:
121
+ throw error
122
+ }
123
+ await writeFile(configFilePath, json)
124
+ })
119
125
  },
120
126
  logInfo = ({ file, users, minLength, error }, hackmudPath) => {
121
127
  error ?
@@ -147,7 +153,7 @@ for (const argument of process.argv.slice(2))
147
153
  else for (const option of key.slice(1)) options.set(option, value)
148
154
  } else commands.push(argument)
149
155
  if ("v" == commands[0] || "version" == commands[0] || options.get("version") || options.get("v")) {
150
- console.log("0.19.1-98e81f8")
156
+ console.log("0.19.1-bf4dc4a")
151
157
  process.exit()
152
158
  }
153
159
  let configDidNotExist = !1
@@ -222,17 +228,20 @@ switch (commands[0]) {
222
228
  break
223
229
  }
224
230
  } else scripts.push("*.*")
225
- if (options.has("skip-minify") && options.has("mangle-names")) {
226
- logError(`Option ${colourN("--mangle-names")} is not compatible with ${colourN("--skip-minify")}\n`)
231
+ const optionsHasNoMinify = options.has("no-minify")
232
+ if ((optionsHasNoMinify || options.has("skip-minify")) && options.has("mangle-names")) {
233
+ logError(
234
+ `Options ${colourN("--mangle-names")} and ${colourN(optionsHasNoMinify ? "--no-minify" : "--skip-minify")} are incompatible\n`
235
+ )
227
236
  logHelp()
228
237
  break
229
238
  }
230
- const shouldSkipMinify = options.get("skip-minify")
239
+ const shouldSkipMinify = options.get("no-minify") || options.get("skip-minify")
231
240
  let shouldMinify
232
241
  if (null != shouldSkipMinify) {
233
242
  if ("boolean" != typeof shouldSkipMinify) {
234
243
  logError(
235
- `The value for ${colourN("--skip-minify")} must be ${colourV("true")} or ${colourV("false")}\n`
244
+ `The value for ${colourN(optionsHasNoMinify ? "--no-minify" : "--skip-minify")} must be ${colourV("true")} or ${colourV("false")}\n`
236
245
  )
237
246
  logHelp()
238
247
  break
@@ -292,17 +301,20 @@ switch (commands[0]) {
292
301
  break
293
302
  }
294
303
  } else scripts.push("*.*")
295
- if (options.has("skip-minify") && options.has("mangle-names")) {
296
- logError(`Option ${colourN("--mangle-names")} is not compatible with ${colourN("--skip-minify")}\n`)
304
+ const optionsHasNoMinify = options.has("no-minify")
305
+ if ((optionsHasNoMinify || options.has("skip-minify")) && options.has("mangle-names")) {
306
+ logError(
307
+ `Options ${colourN("--mangle-names")} and ${colourN(optionsHasNoMinify ? "--no-minify" : "--skip-minify")} are incompatible\n`
308
+ )
297
309
  logHelp()
298
310
  break
299
311
  }
300
- const shouldSkipMinify = options.get("skip-minify")
312
+ const shouldSkipMinify = options.get("no-minify") || options.get("skip-minify")
301
313
  let shouldMinify
302
314
  if (null != shouldSkipMinify) {
303
315
  if ("boolean" != typeof shouldSkipMinify) {
304
316
  logError(
305
- `The value for ${colourN("--skip-minify")} must be ${colourV("true")} or ${colourV("false")}\n`
317
+ `The value for ${colourN(optionsHasNoMinify ? "--no-minify" : "--skip-minify")} must be ${colourV("true")} or ${colourV("false")}\n`
306
318
  )
307
319
  logHelp()
308
320
  break
@@ -406,8 +418,14 @@ switch (commands[0]) {
406
418
  switch (commands[1]) {
407
419
  case "get":
408
420
  {
409
- const key = commands[2]
410
- key ? log(exploreObject(await configPromise, key.split("."))) : console.log(await configPromise)
421
+ const key = commands[2],
422
+ config = await configPromise
423
+ if (key) {
424
+ const [value, error] = catchError(() => getDeepObjectProperty(config, key.split(".")))
425
+ error ? logError("Could not get key " + colourV(key))
426
+ : "string" == typeof value ? log(value)
427
+ : console.log(value)
428
+ } else console.log(config)
411
429
  }
412
430
  break
413
431
  case "delete":
@@ -418,14 +436,16 @@ switch (commands[0]) {
418
436
  logHelp()
419
437
  break
420
438
  }
421
- const keyParts = key.split("."),
422
- pathName = keyParts
423
- .map(name => (/^[a-z_$][\w$]*$/i.test(name) ? name : JSON.stringify(name)))
424
- .join("."),
425
- lastKey = keyParts.pop(),
426
- config = await configPromise
427
- delete exploreObject(config, keyParts)?.[lastKey]
428
- log(`Removed ${colourV(pathName)} from config file`)
439
+ const keys = key.split("."),
440
+ lastKey = keys.pop(),
441
+ config = await configPromise,
442
+ object = getDeepObjectProperty(config, keys)
443
+ if (isRecord(object)) {
444
+ delete object[lastKey]
445
+ await updateConfig(config)
446
+ log(`Removed ${colourV(key)} from config file:`)
447
+ console.log(config)
448
+ } else log("Could not delete " + colourV(key))
429
449
  }
430
450
  break
431
451
  case "set":
@@ -437,49 +457,20 @@ switch (commands[0]) {
437
457
  logHelp()
438
458
  break
439
459
  }
440
- const keys = key.split("."),
441
- pathName = keys
442
- .map(name => (/^[a-z_$][\w$]*$/i.test(name) ? name : JSON.stringify(name)))
443
- .join(".")
444
460
  if (!value) {
445
- logError(`Must provide a value for the key ${pathName}\n`)
461
+ logError(`Must provide a value for the key ${colourV(key)}\n`)
446
462
  logHelp()
447
463
  break
448
464
  }
449
- const lastKey = keys.pop(),
450
- config = await configPromise
451
- if (keys.length || "hackmudPath" != lastKey) {
452
- let object = config
453
- for (const key of keys)
454
- if ("object" == typeof object[key]) object = object[key]
455
- else {
456
- object[key] = {}
457
- object = object[key]
458
- }
459
- object[lastKey] = value
460
- } else config.hackmudPath = resolve(value.startsWith("~/") ? homedir() + value.slice(1) : value)
465
+ const config = await configPromise
466
+ setDeepObjectProperty(config, key.split("."), value)
467
+ log(`Set ${colourV(key)} to ${colourV(value)}:`)
461
468
  console.log(config)
462
- await (async config => {
463
- const json = JSON.stringify(config, void 0, "\t")
464
- configDidNotExist && log("Creating config file at " + configFilePath)
465
- await writeFile(configFilePath, json).catch(async error => {
466
- switch (error.code) {
467
- case "EISDIR":
468
- await rmdir(configFilePath)
469
- break
470
- case "ENOENT":
471
- await mkdir(configDirectoryPath)
472
- break
473
- default:
474
- throw error
475
- }
476
- await writeFile(configFilePath, json)
477
- })
478
- })(config)
469
+ await updateConfig(config)
479
470
  }
480
471
  break
481
472
  default:
482
- commands[1] && logError(`Unknown command: ${JSON.stringify(commands[1])}\n`)
473
+ commands[1] && logError(`Unknown command: ${colourL(commands[1])}\n`)
483
474
  logHelp()
484
475
  }
485
476
  break
@@ -511,9 +502,11 @@ switch (commands[0]) {
511
502
  "scripts" == basename(resolve(target, "..")) && "hackmud" == basename(resolve(target, "../../..")) ?
512
503
  basename(resolve(target, "../.."))
513
504
  : "UNKNOWN",
514
- minify = !options.get("skip-minify")
515
- if (options.has("skip-minify") && options.has("mangle-names")) {
516
- logError(`Option ${colourN("--mangle-names")} would have no effect if minification is skipped\n`)
505
+ optionsHasNoMinify = options.has("no-minify")
506
+ if ((optionsHasNoMinify || options.has("skip-minify")) && options.has("mangle-names")) {
507
+ logError(
508
+ `Options ${colourN("--mangle-names")} and ${colourN(optionsHasNoMinify ? "--no-minify" : "--skip-minify")} are incompatible\n`
509
+ )
517
510
  logHelp()
518
511
  break
519
512
  }
@@ -548,7 +541,7 @@ switch (commands[0]) {
548
541
  async source => {
549
542
  const timeStart = performance.now(),
550
543
  { script, warnings } = await processScript(source, {
551
- minify,
544
+ minify: !(options.get("no-minify") || options.get("skip-minify")),
552
545
  scriptUser,
553
546
  scriptName,
554
547
  filePath: target,
@@ -584,7 +577,7 @@ switch (commands[0]) {
584
577
  }
585
578
  break
586
579
  default:
587
- commands[0] && logError(`Unknown command: ${JSON.stringify(commands[0])}\n`)
580
+ commands[0] && logError(`Unknown command: ${colourL(commands[0])}\n`)
588
581
  logHelp()
589
582
  }
590
583
  autoExit && process.exit()
@@ -1,31 +1,31 @@
1
- import { readdir } from "fs/promises"
1
+ import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
2
2
  import { basename, resolve } from "path"
3
3
  const generateTypeDeclaration = async (sourceDirectory, hackmudPath) => {
4
4
  const users = new Set()
5
5
  if (hackmudPath)
6
- for (const dirent of await readdir(hackmudPath, { withFileTypes: !0 }))
7
- dirent.isFile() && dirent.name.endsWith(".key") && users.add(basename(dirent.name, ".key"))
6
+ for (const { stats, name } of await readDirectoryWithStats(hackmudPath))
7
+ stats.isFile() && name.endsWith(".key") && users.add(basename(name, ".key"))
8
8
  const wildScripts = [],
9
9
  wildAnyScripts = [],
10
10
  allScripts = {},
11
11
  allAnyScripts = {}
12
12
  await Promise.all(
13
- (await readdir(sourceDirectory, { withFileTypes: !0 })).map(async dirent => {
14
- if (dirent.isFile())
15
- dirent.name.endsWith(".ts") ?
16
- dirent.name.endsWith(".d.ts") || wildScripts.push(basename(dirent.name, ".ts"))
17
- : dirent.name.endsWith(".js") && wildAnyScripts.push(basename(dirent.name, ".js"))
18
- else if (dirent.isDirectory()) {
13
+ (await readDirectoryWithStats(sourceDirectory)).map(async ({ stats, name }) => {
14
+ if (stats.isFile())
15
+ name.endsWith(".ts") ?
16
+ name.endsWith(".d.ts") || wildScripts.push(basename(name, ".ts"))
17
+ : name.endsWith(".js") && wildAnyScripts.push(basename(name, ".js"))
18
+ else if (stats.isDirectory()) {
19
19
  const scripts = [],
20
20
  anyScripts = []
21
- allScripts[dirent.name] = scripts
22
- allAnyScripts[dirent.name] = anyScripts
23
- users.add(dirent.name)
24
- for (const file of await readdir(resolve(sourceDirectory, dirent.name), { withFileTypes: !0 }))
25
- file.isFile() &&
26
- (file.name.endsWith(".ts") ?
27
- dirent.name.endsWith(".d.ts") || scripts.push(basename(file.name, ".ts"))
28
- : file.name.endsWith(".js") && anyScripts.push(basename(file.name, ".js")))
21
+ allScripts[name] = scripts
22
+ allAnyScripts[name] = anyScripts
23
+ users.add(name)
24
+ for (const child of await readDirectoryWithStats(resolve(sourceDirectory, name)))
25
+ child.stats.isFile() &&
26
+ (child.name.endsWith(".ts") ?
27
+ name.endsWith(".d.ts") || scripts.push(basename(child.name, ".ts"))
28
+ : child.name.endsWith(".js") && anyScripts.push(basename(child.name, ".js")))
29
29
  }
30
30
  })
31
31
  )
package/index.js CHANGED
@@ -5,7 +5,7 @@ export { pull } from "./pull.js"
5
5
  export { push } from "./push.js"
6
6
  export { syncMacros } from "./syncMacros.js"
7
7
  export { watch } from "./watch.js"
8
- import "fs/promises"
8
+ import "@samual/lib/readDirectoryWithStats"
9
9
  import "path"
10
10
  import "@babel/generator"
11
11
  import "@babel/parser"
@@ -47,4 +47,5 @@ import "@samual/lib/clearObject"
47
47
  import "@samual/lib/copyFilePersistent"
48
48
  import "@samual/lib/Cache"
49
49
  import "@samual/lib/writeFilePersistent"
50
+ import "fs/promises"
50
51
  import "chokidar"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.19.1-98e81f8",
3
+ "version": "0.19.1-bf4dc4a",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",
@@ -59,7 +59,7 @@
59
59
  "@rollup/plugin-commonjs": "^25.0.7",
60
60
  "@rollup/plugin-json": "^6.1.0",
61
61
  "@rollup/plugin-node-resolve": "^15.2.3",
62
- "@samual/lib": "^0.10.1",
62
+ "@samual/lib": "0.10.2-e64c5bc",
63
63
  "acorn": "^8.11.3",
64
64
  "chalk": "^5.3.0",
65
65
  "chokidar": "^3.6.0",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "engines": {
73
73
  "node": "^18 || >=20",
74
- "pnpm": "^8.15.7"
74
+ "pnpm": "^9.0.1"
75
75
  },
76
76
  "type": "module",
77
77
  "exports": {
@@ -29,7 +29,7 @@ import { supportedExtensions } from "../constants.js"
29
29
  import { minify } from "./minify.js"
30
30
  import { postprocess } from "./postprocess.js"
31
31
  import { preprocess } from "./preprocess.js"
32
- import { includesIllegalString, replaceUnsafeStrings } from "./shared.js"
32
+ import { getReferencePathsToGlobal, includesIllegalString, replaceUnsafeStrings } from "./shared.js"
33
33
  import { transform } from "./transform.js"
34
34
  import "@samual/lib/countHackmudCharacters"
35
35
  import "@samual/lib/spliceString"
@@ -206,7 +206,24 @@ const { format } = prettier,
206
206
  plugins: [
207
207
  {
208
208
  name: "hackmud-script-manager",
209
- transform: async code => (await preprocess(code, { uniqueID })).code
209
+ transform: async (code, id) => {
210
+ if (!id.includes("/node_modules/")) return (await preprocess(code, { uniqueID })).code
211
+ let program
212
+ traverse(parse(code, { sourceType: "module" }), {
213
+ Program(path) {
214
+ program = path
215
+ path.skip()
216
+ }
217
+ })
218
+ for (const referencePath of getReferencePathsToGlobal("JSON", program))
219
+ "MemberExpression" == referencePath.parentPath.node.type &&
220
+ "Identifier" == referencePath.parentPath.node.property.type &&
221
+ ("parse" == referencePath.parentPath.node.property.name ?
222
+ (referencePath.parentPath.node.property.name = "oparse")
223
+ : "stringify" == referencePath.parentPath.node.property.name &&
224
+ (referencePath.parentPath.node.property.name = "ostringify"))
225
+ return generate(program.node).code
226
+ }
210
227
  },
211
228
  babel({ babelHelpers: "bundled", plugins, configFile: !1, extensions: supportedExtensions }),
212
229
  rollupPluginCommonJS(),
@@ -357,7 +357,7 @@ const { default: generate } = babelGenerator,
357
357
  unsafe_undefined: !0,
358
358
  sequences: !1
359
359
  },
360
- format: { semicolons: !1 },
360
+ format: { semicolons: !1, wrap_func_args: !1 },
361
361
  keep_classnames: !mangleNames,
362
362
  keep_fnames: !mangleNames
363
363
  })
@@ -422,7 +422,7 @@ const { default: generate } = babelGenerator,
422
422
  if ("ArrayExpression" == element.type) {
423
423
  const childArray = []
424
424
  if (!parseArrayExpression(element, childArray)) return !1
425
- childArray.push(childArray)
425
+ o.push(childArray)
426
426
  } else if ("ObjectExpression" == element.type) {
427
427
  const childObject = {}
428
428
  if (!parseObjectExpression(element, childObject)) return !1
@@ -95,7 +95,7 @@ const { default: traverse } = babelTraverse,
95
95
  file.program.body.unshift(
96
96
  t.importDeclaration(
97
97
  [t.importDefaultSpecifier(t.identifier("Proxy"))],
98
- t.stringLiteral((await resolve("proxy-polyfill/src/proxy.js", import.meta.url)).slice(7))
98
+ t.stringLiteral(resolve("proxy-polyfill/src/proxy.js", import.meta.url).slice(7))
99
99
  )
100
100
  )
101
101
  return 1 == program.node.body.length && "FunctionDeclaration" == program.node.body[0].type ?