hackmud-script-manager 0.20.4-c524114 → 0.20.4-c85594c
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -0
- package/bin/hsm.js +285 -260
- package/env.d.ts +353 -282
- package/generateTypeDeclaration.js +2 -1
- package/index.js +2 -1
- package/package.json +38 -38
- package/processScript/index.js +3 -3
- package/processScript/minify.js +14 -19
- package/processScript/postprocess.d.ts +1 -1
- package/processScript/postprocess.js +3 -3
- package/processScript/preprocess.js +5 -3
- package/processScript/transform.js +102 -96
- package/push.d.ts +9 -1
- package/push.js +36 -14
- package/watch.js +12 -9
@@ -1,5 +1,6 @@
|
|
1
1
|
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
2
2
|
import { basename, resolve } from "path"
|
3
|
+
import * as PathPosix from "path/posix"
|
3
4
|
async function generateTypeDeclaration(sourceDirectory, hackmudPath) {
|
4
5
|
const users = new Set()
|
5
6
|
if (hackmudPath)
|
@@ -29,7 +30,7 @@ async function generateTypeDeclaration(sourceDirectory, hackmudPath) {
|
|
29
30
|
}
|
30
31
|
})
|
31
32
|
)
|
32
|
-
sourceDirectory = resolve(sourceDirectory)
|
33
|
+
sourceDirectory = PathPosix.resolve(sourceDirectory)
|
33
34
|
let o = ""
|
34
35
|
for (const script of wildScripts) o += `type $${script}$ = typeof import("${sourceDirectory}/${script}").default\n`
|
35
36
|
o += "\n"
|
package/index.js
CHANGED
@@ -7,6 +7,7 @@ export { syncMacros } from "./syncMacros.js"
|
|
7
7
|
export { watch } from "./watch.js"
|
8
8
|
import "@samual/lib/readDirectoryWithStats"
|
9
9
|
import "path"
|
10
|
+
import "path/posix"
|
10
11
|
import "@babel/generator"
|
11
12
|
import "@babel/parser"
|
12
13
|
import "@babel/plugin-proposal-decorators"
|
@@ -45,7 +46,7 @@ import "import-meta-resolve"
|
|
45
46
|
import "./processScript/transform.js"
|
46
47
|
import "@samual/lib/clearObject"
|
47
48
|
import "@samual/lib/copyFilePersistent"
|
48
|
-
import "@samual/lib/
|
49
|
+
import "@samual/lib/AutoMap"
|
49
50
|
import "@samual/lib/writeFilePersistent"
|
50
51
|
import "fs/promises"
|
51
52
|
import "chokidar"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hackmud-script-manager",
|
3
|
-
"version": "0.20.4-
|
3
|
+
"version": "0.20.4-c85594c",
|
4
4
|
"description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
|
5
5
|
"keywords": [
|
6
6
|
"api",
|
@@ -31,50 +31,50 @@
|
|
31
31
|
"url": "https://github.com/samualtnorman/hackmud-script-manager.git"
|
32
32
|
},
|
33
33
|
"dependencies": {
|
34
|
-
"@babel/generator": "^7.
|
35
|
-
"@babel/parser": "^7.
|
36
|
-
"@babel/plugin-proposal-decorators": "^7.
|
37
|
-
"@babel/plugin-proposal-destructuring-private": "^7.
|
38
|
-
"@babel/plugin-proposal-do-expressions": "^7.
|
39
|
-
"@babel/plugin-proposal-explicit-resource-management": "^7.
|
40
|
-
"@babel/plugin-proposal-function-bind": "^7.
|
41
|
-
"@babel/plugin-proposal-function-sent": "^7.
|
42
|
-
"@babel/plugin-proposal-partial-application": "^7.
|
43
|
-
"@babel/plugin-proposal-pipeline-operator": "^7.
|
44
|
-
"@babel/plugin-proposal-record-and-tuple": "^7.
|
45
|
-
"@babel/plugin-proposal-throw-expressions": "^7.
|
46
|
-
"@babel/plugin-transform-class-properties": "^7.
|
47
|
-
"@babel/plugin-transform-class-static-block": "^7.
|
48
|
-
"@babel/plugin-transform-exponentiation-operator": "^7.
|
49
|
-
"@babel/plugin-transform-json-strings": "^7.
|
50
|
-
"@babel/plugin-transform-logical-assignment-operators": "^7.
|
51
|
-
"@babel/plugin-transform-nullish-coalescing-operator": "^7.
|
52
|
-
"@babel/plugin-transform-numeric-separator": "^7.
|
53
|
-
"@babel/plugin-transform-object-rest-spread": "^7.
|
54
|
-
"@babel/plugin-transform-optional-catch-binding": "^7.
|
55
|
-
"@babel/plugin-transform-optional-chaining": "^7.
|
56
|
-
"@babel/plugin-transform-private-property-in-object": "^7.
|
57
|
-
"@babel/plugin-transform-typescript": "^7.
|
58
|
-
"@babel/plugin-transform-unicode-sets-regex": "^7.
|
59
|
-
"@babel/traverse": "^7.
|
60
|
-
"@babel/types": "^7.
|
34
|
+
"@babel/generator": "^7.26.2",
|
35
|
+
"@babel/parser": "^7.26.2",
|
36
|
+
"@babel/plugin-proposal-decorators": "^7.25.9",
|
37
|
+
"@babel/plugin-proposal-destructuring-private": "^7.26.0",
|
38
|
+
"@babel/plugin-proposal-do-expressions": "^7.25.9",
|
39
|
+
"@babel/plugin-proposal-explicit-resource-management": "^7.25.9",
|
40
|
+
"@babel/plugin-proposal-function-bind": "^7.25.9",
|
41
|
+
"@babel/plugin-proposal-function-sent": "^7.25.9",
|
42
|
+
"@babel/plugin-proposal-partial-application": "^7.25.9",
|
43
|
+
"@babel/plugin-proposal-pipeline-operator": "^7.25.9",
|
44
|
+
"@babel/plugin-proposal-record-and-tuple": "^7.25.9",
|
45
|
+
"@babel/plugin-proposal-throw-expressions": "^7.25.9",
|
46
|
+
"@babel/plugin-transform-class-properties": "^7.25.9",
|
47
|
+
"@babel/plugin-transform-class-static-block": "^7.26.0",
|
48
|
+
"@babel/plugin-transform-exponentiation-operator": "^7.25.9",
|
49
|
+
"@babel/plugin-transform-json-strings": "^7.25.9",
|
50
|
+
"@babel/plugin-transform-logical-assignment-operators": "^7.25.9",
|
51
|
+
"@babel/plugin-transform-nullish-coalescing-operator": "^7.25.9",
|
52
|
+
"@babel/plugin-transform-numeric-separator": "^7.25.9",
|
53
|
+
"@babel/plugin-transform-object-rest-spread": "^7.25.9",
|
54
|
+
"@babel/plugin-transform-optional-catch-binding": "^7.25.9",
|
55
|
+
"@babel/plugin-transform-optional-chaining": "^7.25.9",
|
56
|
+
"@babel/plugin-transform-private-property-in-object": "^7.25.9",
|
57
|
+
"@babel/plugin-transform-typescript": "^7.25.9",
|
58
|
+
"@babel/plugin-transform-unicode-sets-regex": "^7.25.9",
|
59
|
+
"@babel/traverse": "^7.25.9",
|
60
|
+
"@babel/types": "^7.26.0",
|
61
61
|
"@bloomberg/record-tuple-polyfill": "^0.0.4",
|
62
62
|
"@rollup/plugin-babel": "^6.0.4",
|
63
|
-
"@rollup/plugin-commonjs": "^
|
63
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
64
64
|
"@rollup/plugin-json": "^6.1.0",
|
65
|
-
"@rollup/plugin-node-resolve": "^15.
|
66
|
-
"@samual/lib": "0.
|
67
|
-
"acorn": "^8.
|
65
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
66
|
+
"@samual/lib": "^0.13.0",
|
67
|
+
"acorn": "^8.14.0",
|
68
68
|
"chalk": "^5.3.0",
|
69
|
-
"chokidar": "^
|
70
|
-
"import-meta-resolve": "^4.
|
71
|
-
"prettier": "^3.
|
69
|
+
"chokidar": "^4.0.1",
|
70
|
+
"import-meta-resolve": "^4.1.0",
|
71
|
+
"prettier": "^3.3.3",
|
72
72
|
"proxy-polyfill": "^0.3.2",
|
73
|
-
"rollup": "^4.
|
74
|
-
"terser": "^5.
|
73
|
+
"rollup": "^4.27.4",
|
74
|
+
"terser": "^5.36.0"
|
75
75
|
},
|
76
76
|
"peerDependencies": {
|
77
|
-
"typescript": "5.4.5"
|
77
|
+
"typescript": "^5.4.5"
|
78
78
|
},
|
79
79
|
"type": "module",
|
80
80
|
"exports": {
|
package/processScript/index.js
CHANGED
@@ -204,6 +204,7 @@ async function processScript(
|
|
204
204
|
const bundle = await rollup({
|
205
205
|
input: filePathResolved,
|
206
206
|
plugins: [
|
207
|
+
rollupPluginJSON({ preferConst: !0 }),
|
207
208
|
{
|
208
209
|
name: "hackmud-script-manager",
|
209
210
|
async transform(code, id) {
|
@@ -227,8 +228,7 @@ async function processScript(
|
|
227
228
|
},
|
228
229
|
babel({ babelHelpers: "bundled", plugins, configFile: !1, extensions: supportedExtensions }),
|
229
230
|
rollupPluginCommonJS(),
|
230
|
-
rollupPluginNodeResolve({ extensions: supportedExtensions })
|
231
|
-
rollupPluginJSON()
|
231
|
+
rollupPluginNodeResolve({ extensions: supportedExtensions })
|
232
232
|
],
|
233
233
|
treeshake: { moduleSideEffects: !1 }
|
234
234
|
}),
|
@@ -323,7 +323,7 @@ async function processScript(
|
|
323
323
|
trailingComma: "none"
|
324
324
|
})
|
325
325
|
}
|
326
|
-
code = postprocess(code,
|
326
|
+
code = postprocess(code, uniqueId)
|
327
327
|
if (includesIllegalString(code))
|
328
328
|
throw Error(
|
329
329
|
'you found a weird edge case where I wasn\'t able to replace illegal strings like "SC$", please report thx'
|
package/processScript/minify.js
CHANGED
@@ -43,15 +43,6 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
43
43
|
)
|
44
44
|
}
|
45
45
|
}
|
46
|
-
const hashGReferencePaths = getReferencePathsToGlobal(`$${uniqueId}$GLOBAL$`, program)
|
47
|
-
if (hashGReferencePaths.length > 3) {
|
48
|
-
for (const path of hashGReferencePaths) path.replaceWith(t.identifier(`_${uniqueId}_G_`))
|
49
|
-
mainFunctionPath.node.body.body.unshift(
|
50
|
-
t.variableDeclaration("let", [
|
51
|
-
t.variableDeclarator(t.identifier(`_${uniqueId}_G_`), t.identifier(`$${uniqueId}$GLOBAL$`))
|
52
|
-
])
|
53
|
-
)
|
54
|
-
}
|
55
46
|
const jsonValues = []
|
56
47
|
let scriptBeforeJSONValueReplacement,
|
57
48
|
comment,
|
@@ -61,7 +52,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
61
52
|
traverse(fileBeforeJSONValueReplacement, {
|
62
53
|
MemberExpression({ node: memberExpression }) {
|
63
54
|
if (!memberExpression.computed) {
|
64
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:
|
55
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:115:60")
|
65
56
|
if ("prototype" == memberExpression.property.name) {
|
66
57
|
memberExpression.computed = !0
|
67
58
|
memberExpression.property = t.identifier(`_${uniqueId}_PROTOTYPE_PROPERTY_`)
|
@@ -136,7 +127,8 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
136
127
|
const promises = []
|
137
128
|
traverse(file, {
|
138
129
|
FunctionDeclaration(path) {
|
139
|
-
path.
|
130
|
+
const body = path.get("body")
|
131
|
+
body.traverse({
|
140
132
|
Function(path) {
|
141
133
|
"CallExpression" != path.parent.type && "callee" != path.parentKey && path.skip()
|
142
134
|
},
|
@@ -152,7 +144,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
152
144
|
path.replaceWith(t.identifier(`_${uniqueId}_JSON_VALUE_${jsonValues.push(o) - 1}_`))
|
153
145
|
}
|
154
146
|
})
|
155
|
-
|
147
|
+
body.traverse({
|
156
148
|
TemplateLiteral(path) {
|
157
149
|
if ("TaggedTemplateExpression" == path.parent.type) return
|
158
150
|
const templateLiteral = path.node
|
@@ -172,7 +164,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
172
164
|
},
|
173
165
|
MemberExpression({ node: memberExpression }) {
|
174
166
|
if (!memberExpression.computed) {
|
175
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:
|
167
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:249:62")
|
176
168
|
if (!(memberExpression.property.name.length < 3)) {
|
177
169
|
memberExpression.computed = !0
|
178
170
|
memberExpression.property = t.stringLiteral(memberExpression.property.name)
|
@@ -246,7 +238,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
246
238
|
})
|
247
239
|
await Promise.all(promises)
|
248
240
|
const functionDeclaration = file.program.body[0]
|
249
|
-
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:
|
241
|
+
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:354:61")
|
250
242
|
if (jsonValues.length) {
|
251
243
|
hasComment = !0
|
252
244
|
if (1 == jsonValues.length)
|
@@ -258,7 +250,10 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
258
250
|
t.memberExpression(
|
259
251
|
t.taggedTemplateExpression(
|
260
252
|
t.memberExpression(
|
261
|
-
t.callExpression(
|
253
|
+
t.callExpression(
|
254
|
+
t.identifier(`$${uniqueId}$4$SUBSCRIPT$scripts$quine$`),
|
255
|
+
[]
|
256
|
+
),
|
262
257
|
t.identifier("split")
|
263
258
|
),
|
264
259
|
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
@@ -282,7 +277,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
282
277
|
t.memberExpression(
|
283
278
|
t.taggedTemplateExpression(
|
284
279
|
t.memberExpression(
|
285
|
-
t.callExpression(t.identifier(`$${uniqueId}$SUBSCRIPT$scripts$quine$`), []),
|
280
|
+
t.callExpression(t.identifier(`$${uniqueId}$4$SUBSCRIPT$scripts$quine$`), []),
|
286
281
|
t.identifier("split")
|
287
282
|
),
|
288
283
|
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
@@ -307,7 +302,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
307
302
|
t.memberExpression(
|
308
303
|
t.taggedTemplateExpression(
|
309
304
|
t.memberExpression(
|
310
|
-
t.callExpression(t.identifier(`$${uniqueId}$SUBSCRIPT$scripts$quine$`), []),
|
305
|
+
t.callExpression(t.identifier(`$${uniqueId}$4$SUBSCRIPT$scripts$quine$`), []),
|
311
306
|
t.identifier("split")
|
312
307
|
),
|
313
308
|
t.templateLiteral([t.templateElement({ raw: "\t", cooked: "\t" }, !0)], [])
|
@@ -363,7 +358,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
363
358
|
)
|
364
359
|
}
|
365
360
|
if (1 == forceQuineCheats) return code
|
366
|
-
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:
|
361
|
+
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:485:43")
|
367
362
|
return (
|
368
363
|
countHackmudCharacters(scriptBeforeJSONValueReplacement) <=
|
369
364
|
countHackmudCharacters(code) + Number(hasComment)
|
@@ -379,7 +374,7 @@ function parseObjectExpression(node, o) {
|
|
379
374
|
"Identifier" == property.key.type ||
|
380
375
|
"NumericLiteral" == property.key.type ||
|
381
376
|
"StringLiteral" == property.key.type,
|
382
|
-
"src/processScript/minify.ts:
|
377
|
+
"src/processScript/minify.ts:507:4"
|
383
378
|
)
|
384
379
|
if ("ArrayExpression" == property.value.type) {
|
385
380
|
const childArray = []
|
@@ -1 +1 @@
|
|
1
|
-
export declare const postprocess: (code: string,
|
1
|
+
export declare const postprocess: (code: string, uniqueId: string) => string;
|
@@ -1,12 +1,12 @@
|
|
1
|
-
const postprocess = (code,
|
1
|
+
const postprocess = (code, uniqueId) =>
|
2
2
|
code
|
3
|
-
.replace(/^function\s
|
3
|
+
.replace(/^function\s*[\w$]+\(/, "function(")
|
4
4
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$SC_DOLLAR\\$`, "g"), "S\\C$")
|
5
5
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$DB_DOLLAR\\$`, "g"), "D\\B$")
|
6
6
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$D\\$`, "g"), "_\\_D_S")
|
7
7
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$FMCL\\$`, "g"), "_\\_FMCL_")
|
8
8
|
.replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$G\\$`, "g"), "_\\_G_")
|
9
|
-
.replace(RegExp(`\\$${uniqueId}\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, "g"),
|
9
|
+
.replace(RegExp(`\\$${uniqueId}\\$(\\d)\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, "g"), "#$1s.$2.$3")
|
10
10
|
.replace(RegExp(`\\$${uniqueId}\\$DEBUG\\$`, "g"), "#D")
|
11
11
|
.replace(RegExp(`\\$${uniqueId}\\$FMCL\\$`, "g"), "#FMCL")
|
12
12
|
.replace(RegExp(`\\$${uniqueId}\\$GLOBAL\\$`, "g"), "#G")
|
@@ -98,8 +98,10 @@ async function preprocess(code, { uniqueId = "00000000000" } = {}) {
|
|
98
98
|
t.stringLiteral(resolve("proxy-polyfill/src/proxy.js", import.meta.url).slice(7))
|
99
99
|
)
|
100
100
|
)
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
if (1 == program.node.body.length && "FunctionDeclaration" == program.node.body[0].type)
|
102
|
+
throw Error(
|
103
|
+
"Scripts that only contain a single function declaration are no longer supported.\nPrefix the function declaration with `export default`."
|
104
|
+
)
|
105
|
+
return { code: generate(file).code }
|
104
106
|
}
|
105
107
|
export { preprocess }
|