hackmud-script-manager 0.20.4-03d5600 → 0.20.4-06a037b
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 +46 -28
- package/env.d.ts +315 -310
- package/index.js +1 -1
- package/package.json +39 -39
- package/processScript/index.js +2 -2
- package/processScript/preprocess.js +5 -3
- package/processScript/transform.js +66 -73
- package/push.js +4 -4
- package/watch.js +8 -7
package/index.js
CHANGED
@@ -46,7 +46,7 @@ import "import-meta-resolve"
|
|
46
46
|
import "./processScript/transform.js"
|
47
47
|
import "@samual/lib/clearObject"
|
48
48
|
import "@samual/lib/copyFilePersistent"
|
49
|
-
import "@samual/lib/
|
49
|
+
import "@samual/lib/AutoMap"
|
50
50
|
import "@samual/lib/writeFilePersistent"
|
51
51
|
import "fs/promises"
|
52
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-06a037b",
|
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": {
|
@@ -86,6 +86,6 @@
|
|
86
86
|
"hsm": "bin/hsm.js"
|
87
87
|
},
|
88
88
|
"engines": {
|
89
|
-
"node": "^18 || >=
|
89
|
+
"node": "^18 || ^20 || >=22"
|
90
90
|
}
|
91
91
|
}
|
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
|
}),
|
@@ -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 }
|
@@ -22,9 +22,7 @@ const { default: traverse } = babelTraverse,
|
|
22
22
|
"BigInt"
|
23
23
|
]
|
24
24
|
function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scriptName, seclevel = 4 }) {
|
25
|
-
const topFunctionName = `_${uniqueId}_SCRIPT_
|
26
|
-
exports = new Map(),
|
27
|
-
liveExports = new Map()
|
25
|
+
const topFunctionName = `_${uniqueId}_SCRIPT_`
|
28
26
|
let program
|
29
27
|
traverse(file, {
|
30
28
|
Program(path) {
|
@@ -70,30 +68,30 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
70
68
|
const referencePath = FunctionReferencePaths[0]
|
71
69
|
assert(
|
72
70
|
"MemberExpression" == referencePath.parent.type,
|
73
|
-
"src/processScript/transform.ts:
|
71
|
+
"src/processScript/transform.ts:103:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
74
72
|
)
|
75
73
|
assert(
|
76
74
|
"Identifier" == referencePath.parent.property.type,
|
77
|
-
"src/processScript/transform.ts:
|
75
|
+
"src/processScript/transform.ts:108:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
78
76
|
)
|
79
77
|
assert(
|
80
78
|
"prototype" == referencePath.parent.property.name,
|
81
|
-
"src/processScript/transform.ts:
|
79
|
+
"src/processScript/transform.ts:113:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
82
80
|
)
|
83
81
|
referencePath.parentPath.replaceWith(createGetFunctionPrototypeNode())
|
84
82
|
} else {
|
85
83
|
for (const referencePath of FunctionReferencePaths) {
|
86
84
|
assert(
|
87
85
|
"MemberExpression" == referencePath.parent.type,
|
88
|
-
"src/processScript/transform.ts:
|
86
|
+
"src/processScript/transform.ts:121:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
89
87
|
)
|
90
88
|
assert(
|
91
89
|
"Identifier" == referencePath.parent.property.type,
|
92
|
-
"src/processScript/transform.ts:
|
90
|
+
"src/processScript/transform.ts:126:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
93
91
|
)
|
94
92
|
assert(
|
95
93
|
"prototype" == referencePath.parent.property.name,
|
96
|
-
"src/processScript/transform.ts:
|
94
|
+
"src/processScript/transform.ts:131:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
97
95
|
)
|
98
96
|
functionDotPrototypeIsReferencedMultipleTimes = !0
|
99
97
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_FUNCTION_DOT_PROTOTYPE_`))
|
@@ -129,12 +127,12 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
129
127
|
const neededDbMethodLets = new Set()
|
130
128
|
if (program.scope.hasGlobal("$db"))
|
131
129
|
for (const referencePath of getReferencePathsToGlobal("$db", program)) {
|
132
|
-
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:
|
133
|
-
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:
|
130
|
+
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:185:69")
|
131
|
+
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:186:72")
|
134
132
|
const databaseOpMethodName = referencePath.parentPath.node.property.name
|
135
133
|
assert(
|
136
134
|
validDBMethods.includes(databaseOpMethodName),
|
137
|
-
`src/processScript/transform.ts:
|
135
|
+
`src/processScript/transform.ts:192:8 invalid db method "${databaseOpMethodName}", valid db methods are "${validDBMethods.join('", "')}"`
|
138
136
|
)
|
139
137
|
if ("CallExpression" == referencePath.parentPath.parentPath?.type)
|
140
138
|
referencePath.parentPath.replaceWith(t.identifier(`$${uniqueId}$DB$${databaseOpMethodName}$`))
|
@@ -164,21 +162,25 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
164
162
|
if (program.scope.hasGlobal("_SECLEVEL"))
|
165
163
|
for (const referencePath of getReferencePathsToGlobal("_SECLEVEL", program))
|
166
164
|
referencePath.replaceWith(t.numericLiteral(seclevel))
|
167
|
-
let needGetPrototypeOf = !1
|
165
|
+
let needGetPrototypeOf = !1,
|
166
|
+
needHasOwn = !1
|
168
167
|
if (program.scope.hasGlobal("Object"))
|
169
168
|
for (const referencePath of getReferencePathsToGlobal("Object", program))
|
170
169
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
171
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
170
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:242:64")
|
172
171
|
if ("getPrototypeOf" == referencePath.parent.property.name) {
|
173
172
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_GET_PROTOTYPE_OF_`))
|
174
173
|
needGetPrototypeOf = !0
|
174
|
+
} else if ("hasOwn" == referencePath.parent.property.name) {
|
175
|
+
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_HAS_OWN_`))
|
176
|
+
needHasOwn = !0
|
175
177
|
}
|
176
178
|
}
|
177
179
|
const consoleMethodsReferenced = new Set()
|
178
180
|
if (program.scope.hasGlobal("console"))
|
179
181
|
for (const referencePath of getReferencePathsToGlobal("console", program))
|
180
182
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
181
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
183
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:260:64")
|
182
184
|
referencePath.parentPath.replaceWith(
|
183
185
|
t.identifier(`_${uniqueId}_CONSOLE_METHOD_${referencePath.parent.property.name}_`)
|
184
186
|
)
|
@@ -186,19 +188,20 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
186
188
|
}
|
187
189
|
const lastStatement = program.node.body.at(-1)
|
188
190
|
let exportDefaultName
|
189
|
-
assert(lastStatement, "src/processScript/transform.ts:
|
191
|
+
assert(lastStatement, "src/processScript/transform.ts:274:27 program is empty")
|
190
192
|
if ("ExportNamedDeclaration" == lastStatement.type) {
|
191
193
|
program.node.body.pop()
|
192
194
|
for (const specifier of lastStatement.specifiers) {
|
193
195
|
assert(
|
194
196
|
"ExportSpecifier" == specifier.type,
|
195
|
-
`src/processScript/transform.ts:
|
197
|
+
`src/processScript/transform.ts:280:51 ${specifier.type} is currently unsupported`
|
196
198
|
)
|
197
|
-
|
198
|
-
"
|
199
|
-
|
200
|
-
|
201
|
-
|
199
|
+
if (
|
200
|
+
"default" !=
|
201
|
+
("Identifier" == specifier.exported.type ? specifier.exported.name : specifier.exported.value)
|
202
|
+
)
|
203
|
+
throw Error("Only default exports are supported")
|
204
|
+
exportDefaultName = specifier.local.name
|
202
205
|
}
|
203
206
|
}
|
204
207
|
const globalBlock = t.blockStatement([])
|
@@ -224,10 +227,6 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
224
227
|
t.returnStatement(t.callExpression(t.identifier(exportDefaultName), []))
|
225
228
|
])
|
226
229
|
))
|
227
|
-
if ("const" != statement.kind && exports.has(identifierName)) {
|
228
|
-
liveExports.set(identifierName, exports.get(identifierName))
|
229
|
-
exports.delete(identifierName)
|
230
|
-
}
|
231
230
|
globalBlock.body.push(
|
232
231
|
t.variableDeclaration("let", [t.variableDeclarator(t.identifier(identifierName))])
|
233
232
|
)
|
@@ -292,34 +291,16 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
292
291
|
}
|
293
292
|
program.node.body = [mainFunction]
|
294
293
|
if (globalBlock.body.length) {
|
295
|
-
;(exports.size || liveExports.size) &&
|
296
|
-
mainFunction.body.body.push(
|
297
|
-
t.returnStatement(
|
298
|
-
t.objectExpression([
|
299
|
-
...[...exports].map(([local, exported]) =>
|
300
|
-
t.objectProperty(t.identifier(exported), t.identifier(local))
|
301
|
-
),
|
302
|
-
...[...liveExports].map(([local, exported]) =>
|
303
|
-
t.objectMethod(
|
304
|
-
"get",
|
305
|
-
t.identifier(exported),
|
306
|
-
[],
|
307
|
-
t.blockStatement([t.returnStatement(t.identifier(local))])
|
308
|
-
)
|
309
|
-
)
|
310
|
-
])
|
311
|
-
)
|
312
|
-
)
|
313
294
|
program.scope.crawl()
|
314
295
|
const globalBlockVariables = new Set()
|
315
296
|
let hoistedGlobalBlockFunctions = 0
|
316
297
|
for (const [globalBlockIndex, globalBlockStatement] of [...globalBlock.body.entries()].reverse())
|
317
298
|
if ("VariableDeclaration" == globalBlockStatement.type) {
|
318
|
-
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:
|
299
|
+
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:394:59")
|
319
300
|
const declarator = globalBlockStatement.declarations[0]
|
320
301
|
assert(
|
321
302
|
"Identifier" == declarator.id.type,
|
322
|
-
`src/processScript/transform.ts:
|
303
|
+
`src/processScript/transform.ts:398:51 declarator.id.type was "${declarator.id.type}"`
|
323
304
|
)
|
324
305
|
program.scope.crawl()
|
325
306
|
if (program.scope.hasGlobal(declarator.id.name)) {
|
@@ -334,9 +315,9 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
334
315
|
Object.keys(program.scope.globals).some(global => globalBlockVariables.has(global))
|
335
316
|
) {
|
336
317
|
const binding = program.scope.getBinding(declarator.id.name)
|
337
|
-
assert(binding, "src/processScript/transform.ts:
|
318
|
+
assert(binding, "src/processScript/transform.ts:417:23")
|
338
319
|
for (const referencePath of binding.referencePaths) {
|
339
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
320
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:420:56")
|
340
321
|
referencePath.replaceWith(
|
341
322
|
t.memberExpression(
|
342
323
|
t.identifier(`_${uniqueId}_G_`),
|
@@ -384,16 +365,16 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
384
365
|
} else globalBlockVariables.add(declarator.id.name)
|
385
366
|
} else if ("ClassDeclaration" == globalBlockStatement.type) {
|
386
367
|
program.scope.crawl()
|
387
|
-
assert(globalBlockStatement.id, "src/processScript/transform.ts:
|
368
|
+
assert(globalBlockStatement.id, "src/processScript/transform.ts:477:37")
|
388
369
|
if (program.scope.hasGlobal(globalBlockStatement.id.name)) {
|
389
370
|
globalBlock.body.splice(globalBlockIndex, 1)
|
390
371
|
const [globalBlockPath] = program.unshiftContainer("body", globalBlock),
|
391
372
|
[globalBlockStatementPath] = program.unshiftContainer("body", globalBlockStatement)
|
392
373
|
program.scope.crawl()
|
393
374
|
const binding = program.scope.getBinding(globalBlockStatement.id.name)
|
394
|
-
assert(binding, "src/processScript/transform.ts:
|
375
|
+
assert(binding, "src/processScript/transform.ts:489:22")
|
395
376
|
for (const referencePath of binding.referencePaths) {
|
396
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
377
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:492:55")
|
397
378
|
referencePath.replaceWith(
|
398
379
|
t.memberExpression(t.identifier(`_${uniqueId}_G_`), t.identifier(referencePath.node.name))
|
399
380
|
)
|
@@ -423,11 +404,6 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
423
404
|
needG = !0
|
424
405
|
}
|
425
406
|
}
|
426
|
-
if (program.scope.hasGlobal("_EXPORTS"))
|
427
|
-
for (const referencePath of getReferencePathsToGlobal("_EXPORTS", program))
|
428
|
-
referencePath.replaceWith(
|
429
|
-
t.arrayExpression([...exports.keys(), ...liveExports.keys()].map(name => t.stringLiteral(name)))
|
430
|
-
)
|
431
407
|
globalBlock.body.length &&
|
432
408
|
mainFunction.body.body.splice(
|
433
409
|
hoistedGlobalBlockFunctions,
|
@@ -476,6 +452,31 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
476
452
|
)
|
477
453
|
])
|
478
454
|
)
|
455
|
+
needHasOwn &&
|
456
|
+
mainFunction.body.body.unshift(
|
457
|
+
t.variableDeclaration("let", [
|
458
|
+
t.variableDeclarator(
|
459
|
+
t.identifier(`_${uniqueId}_HAS_OWN_`),
|
460
|
+
t.callExpression(
|
461
|
+
t.memberExpression(
|
462
|
+
t.memberExpression(
|
463
|
+
t.identifier(
|
464
|
+
globalFunctionsUnder7Characters.find(name => !program.scope.hasOwnBinding(name))
|
465
|
+
),
|
466
|
+
t.identifier("call")
|
467
|
+
),
|
468
|
+
t.identifier("bind")
|
469
|
+
),
|
470
|
+
[
|
471
|
+
t.memberExpression(
|
472
|
+
t.memberExpression(t.identifier("Object"), t.identifier("prototype")),
|
473
|
+
t.identifier("hasOwnProperty")
|
474
|
+
)
|
475
|
+
]
|
476
|
+
)
|
477
|
+
)
|
478
|
+
])
|
479
|
+
)
|
479
480
|
consoleMethodsReferenced.size &&
|
480
481
|
mainFunction.body.body.unshift(
|
481
482
|
t.variableDeclaration(
|
@@ -565,7 +566,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
565
566
|
}
|
566
567
|
},
|
567
568
|
ClassBody({ node: classBody, scope, parent }) {
|
568
|
-
assert(t.isClass(parent), "src/processScript/transform.ts:
|
569
|
+
assert(t.isClass(parent), "src/processScript/transform.ts:687:30")
|
569
570
|
let thisIsReferenced = !1
|
570
571
|
for (const classMethod of classBody.body) {
|
571
572
|
if ("ClassMethod" != classMethod.type) continue
|
@@ -657,39 +658,31 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
657
658
|
})
|
658
659
|
return { file, seclevel }
|
659
660
|
function createGetFunctionPrototypeNode() {
|
660
|
-
|
661
|
-
if (!program.scope.hasOwnBinding(globalFunction))
|
662
|
-
return t.memberExpression(
|
663
|
-
t.memberExpression(t.identifier(globalFunction), t.identifier("constructor")),
|
664
|
-
t.identifier("prototype")
|
665
|
-
)
|
661
|
+
const name = globalFunctionsUnder7Characters.find(name => !program.scope.hasOwnBinding(name))
|
666
662
|
return t.memberExpression(
|
667
|
-
t.
|
668
|
-
|
669
|
-
t.identifier("constructor")
|
670
|
-
),
|
671
|
-
t.identifier("prototype")
|
663
|
+
name ? t.identifier(name) : t.arrowFunctionExpression([t.identifier("_")], t.identifier("_")),
|
664
|
+
t.identifier("__proto__")
|
672
665
|
)
|
673
666
|
}
|
674
667
|
function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
|
675
668
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
676
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
669
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:793:60")
|
677
670
|
assert("Identifier" == referencePath.parent.property.type)
|
678
671
|
assert(
|
679
672
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
680
|
-
"src/processScript/transform.ts:
|
673
|
+
"src/processScript/transform.ts:795:81"
|
681
674
|
)
|
682
675
|
assert(
|
683
676
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
684
|
-
"src/processScript/transform.ts:
|
677
|
+
"src/processScript/transform.ts:796:83"
|
685
678
|
)
|
686
679
|
assert(
|
687
680
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
688
|
-
`src/processScript/transform.ts:
|
681
|
+
`src/processScript/transform.ts:800:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
689
682
|
)
|
690
683
|
assert(
|
691
684
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
692
|
-
`src/processScript/transform.ts:
|
685
|
+
`src/processScript/transform.ts:805:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
693
686
|
)
|
694
687
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
695
688
|
referencePath.parentPath.parentPath.replaceWith(
|
package/push.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { AutoMap } from "@samual/lib/AutoMap"
|
2
2
|
import { ensure, assert } from "@samual/lib/assert"
|
3
3
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
4
4
|
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
@@ -84,8 +84,8 @@ async function push(
|
|
84
84
|
return new NoUsersError(
|
85
85
|
"Could not find any users. Either provide the names of your users or log into a user in hackmud"
|
86
86
|
)
|
87
|
-
const usersToScriptsToPush = new
|
88
|
-
scriptNamesToUsers = new
|
87
|
+
const usersToScriptsToPush = new AutoMap(_user => new Map()),
|
88
|
+
scriptNamesToUsers = new AutoMap(_scriptName => new Set())
|
89
89
|
for (const script of scripts) {
|
90
90
|
const [user, scriptName] = script.split(".")
|
91
91
|
assert(user, "src/push.ts:105:16")
|
@@ -121,7 +121,7 @@ async function push(
|
|
121
121
|
for (const user of users)
|
122
122
|
if (!usersToScriptsToPush.get(user).has(scriptName))
|
123
123
|
return new NoScriptsError(`Could not find script ${user}.${scriptName} to push`)
|
124
|
-
const pathsToUsers = new
|
124
|
+
const pathsToUsers = new AutoMap(_path => new Set())
|
125
125
|
for (const [user, scriptsToPush] of usersToScriptsToPush)
|
126
126
|
for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
|
127
127
|
const allInfo = []
|
package/watch.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import { AutoMap } from "@samual/lib/AutoMap"
|
2
2
|
import { assert } from "@samual/lib/assert"
|
3
3
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
4
4
|
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
5
5
|
import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
|
6
6
|
import { watch as watch$1 } from "chokidar"
|
7
|
-
import { readFile, writeFile } from "fs/promises"
|
7
|
+
import { stat, readFile, writeFile } from "fs/promises"
|
8
8
|
import { extname, basename, resolve } from "path"
|
9
9
|
import { supportedExtensions } from "./constants.js"
|
10
10
|
import { generateTypeDeclaration } from "./generateTypeDeclaration.js"
|
@@ -59,7 +59,8 @@ async function watch(
|
|
59
59
|
} = {}
|
60
60
|
) {
|
61
61
|
if (!scripts.length) throw Error("scripts option was an empty array")
|
62
|
-
|
62
|
+
if (!(await stat(sourceDirectory)).isDirectory()) throw Error("Target folder must be a folder")
|
63
|
+
const scriptNamesToUsers = new AutoMap(_scriptName => new Set()),
|
63
64
|
wildScriptUsers = new Set(),
|
64
65
|
wildUserScripts = new Set()
|
65
66
|
let pushEverything = !1
|
@@ -91,7 +92,7 @@ async function watch(
|
|
91
92
|
)
|
92
93
|
)
|
93
94
|
return
|
94
|
-
const scriptNamesToUsersToSkip = new
|
95
|
+
const scriptNamesToUsersToSkip = new AutoMap(_scriptName => [])
|
95
96
|
await Promise.all(
|
96
97
|
(await readDirectoryWithStats(sourceDirectory)).map(async ({ stats, name, path }) => {
|
97
98
|
if (stats.isDirectory())
|
@@ -136,7 +137,7 @@ async function watch(
|
|
136
137
|
forceQuineCheats
|
137
138
|
}))
|
138
139
|
} catch (error) {
|
139
|
-
assert(error instanceof Error, "src/watch.ts:
|
140
|
+
assert(error instanceof Error, "src/watch.ts:146:36")
|
140
141
|
onPush?.({ path, users: [], characterCount: 0, error })
|
141
142
|
return
|
142
143
|
}
|
@@ -181,7 +182,7 @@ async function watch(
|
|
181
182
|
forceQuineCheats
|
182
183
|
}))
|
183
184
|
} catch (error) {
|
184
|
-
assert(error instanceof Error, "src/watch.ts:
|
185
|
+
assert(error instanceof Error, "src/watch.ts:182:35")
|
185
186
|
onPush?.({ path, users: [], characterCount: 0, error })
|
186
187
|
return
|
187
188
|
}
|
@@ -196,7 +197,7 @@ async function watch(
|
|
196
197
|
try {
|
197
198
|
await writeFile(typeDeclarationPath, typeDeclaration)
|
198
199
|
} catch (error) {
|
199
|
-
assert(error instanceof Error, "src/watch.ts:
|
200
|
+
assert(error instanceof Error, "src/watch.ts:215:35")
|
200
201
|
if ("EISDIR" != error.code) throw error
|
201
202
|
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
202
203
|
await writeFile(typeDeclarationPath, typeDeclaration)
|