Skip to content

Commit 1898d24

Browse files
committed
I made these changes ages ago, I don't know
1 parent f6380a1 commit 1898d24

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

index.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readdir as readDir, writeFile, unlink, mkdir as mkDir, readFile, copyFile } from "fs/promises"
1+
import { readdir as readDir, writeFile, mkdir as mkDir, readFile, copyFile } from "fs/promises"
22
import { watch as watchDir } from "chokidar"
33
import { minify } from "terser"
44
import { resolve as resolvePath, basename, extname } from "path"
@@ -219,29 +219,33 @@ export async function pull(srcPath: string, hackmudPath: string, script: string)
219219
* @param script JavaScript or TypeScript code
220220
*/
221221
export async function minifyScript(script: string) {
222-
const uid = Date.now().toString(36)
222+
// const uid = Date.now().toString(36)
223223
const autocompleteMatch = script.match(/^(?:\/\/ @autocomplete (.+)|function(?: \w+| )?\([^\)]*\)\s*{\s*\/\/(.+))\n/)
224-
const scriptLines = script.split("\n")
224+
// const scriptLines = script.split("\n")
225225

226-
for (let i = 0; i < scriptLines.length; i++) {
227-
const line = scriptLines[i]
226+
// for (let i = 0; i < scriptLines.length; i++) {
227+
// const line = scriptLines[i]
228228

229-
if (/\s*function\s*\(/.exec(line)?.index == 0)
230-
break
229+
// if (/\s*function\s*\(/.exec(line)?.index == 0)
230+
// break
231231

232-
if (!(!line || /[^\s]/.exec(line) == null || /\s*\/\//.exec(line)?.index == 0)) {
233-
scriptLines.splice(i, 0, "function (context, args) {")
234-
scriptLines.push("}")
235-
break
236-
}
237-
}
232+
// if (!(!line || /[^\s]/.exec(line) == null || /\s*\/\//.exec(line)?.index == 0)) {
233+
// scriptLines.splice(i, 0, "function (context, args) {")
234+
// scriptLines.push("}")
235+
// break
236+
// }
237+
// }
238+
239+
// script = scriptLines.join("\n")
238240

239-
script = scriptLines.join("\n")
241+
// // preprocessing
242+
// script = script
243+
// .replace(/function(?: \w+| )?\(/, `function script_${uid}(`)
244+
// .replace(/#[\w.]+\(/g, a => a.replace("#", `_hash_${uid}_`).replace(/\./g, `_dot_${uid}_`))
240245

241-
// preprocessing
242246
script = script
243-
.replace(/function(?: \w+| )?\(/, `function script_${uid}(`)
244-
.replace(/#[\w.]+\(/g, a => a.replace("#", `_hash_${uid}_`).replace(/\./g, `_dot_${uid}_`))
247+
.replace("export ", "")
248+
.replace(/\$([\w.]+\()/g, a => "$" + a.slice(1).replace(/\./g, "$"))
245249

246250
// compilation
247251
script = transpileModule(script, {
@@ -276,11 +280,15 @@ export async function minifyScript(script: string) {
276280
printWidth: Infinity
277281
})
278282

279-
// postprocessing
283+
// // postprocessing
284+
// script = script
285+
// .replace(`script_${uid}`, "")
286+
// .replace(new RegExp(`_hash_${uid}_`, "g"), "#")
287+
// .replace(new RegExp(`_dot_${uid}_`, "g"), ".")
288+
280289
script = script
281-
.replace(`script_${uid}`, "")
282-
.replace(new RegExp(`_hash_${uid}_`, "g"), "#")
283-
.replace(new RegExp(`_dot_${uid}_`, "g"), ".")
290+
.replace(/\$[\w\$]+\(/g, a => a.replace("$", "#").replace(/\$/g, "."))
291+
.replace(/function ?\w+\(/, "function (")
284292

285293
if (autocompleteMatch)
286294
return script.replace(/function \(.*\) \{/, `$& // ${(autocompleteMatch[1] || autocompleteMatch[2]).trim()}`)

lib/hsm.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import { homedir as homeDir } from "os"
44
import { pull, push, watch } from ".."
55
import { redBright, yellowBright, greenBright, blueBright, cyanBright, magentaBright, bold, dim } from "ansi-colors"
66

7-
interface LooseObject<T = any> {
8-
[key: string]: T | undefined
9-
}
10-
117
// let o = ""
128

139
// for (let key in c) {
@@ -37,10 +33,10 @@ const commands: string[] = []
3733
// }
3834
// }
3935

40-
let config: LooseObject & Partial<{
36+
let config: Record<string, any> & Partial<{
4137
hackmudPath: string
4238
defaultUser: string
43-
users: LooseObject<{
39+
users: Record<string, {
4440
colour: string
4541
}>
4642
}> | undefined

0 commit comments

Comments
 (0)