hackmud-script-manager 0.20.4-52a588b → 0.20.4-66e0e13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/hsm.js +144 -66
- package/env.d.ts +197 -192
- package/index.d.ts +3 -0
- package/index.js +1 -0
- package/package.json +3 -2
- package/processScript/index.d.ts +2 -2
- package/processScript/index.js +14 -10
- package/processScript/preprocess.js +2 -2
- package/processScript/transform.d.ts +3 -0
- package/processScript/transform.js +68 -30
- package/push.js +8 -5
- package/watch.js +24 -24
@@ -22,7 +22,8 @@ const { default: traverse } = babelTraverse,
|
|
22
22
|
"BigInt"
|
23
23
|
]
|
24
24
|
function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scriptName, seclevel = 4 }) {
|
25
|
-
const
|
25
|
+
const warnings = [],
|
26
|
+
topFunctionName = `_${uniqueId}_SCRIPT_`
|
26
27
|
let program
|
27
28
|
traverse(file, {
|
28
29
|
Program(path) {
|
@@ -44,9 +45,17 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
44
45
|
referencePath.replaceWith(t.identifier(`_${uniqueId}_SCRIPT_USER_`))
|
45
46
|
} else
|
46
47
|
referencePath.replaceWith(t.stringLiteral(1 == scriptUser ? `$${uniqueId}$SCRIPT_USER$` : scriptUser))
|
47
|
-
if (program.scope.hasGlobal("_SCRIPT_NAME"))
|
48
|
+
if (program.scope.hasGlobal("_SCRIPT_NAME")) {
|
49
|
+
warnings.push({
|
50
|
+
message:
|
51
|
+
"Global _SCRIPT_NAME is deprecated and will be removed in the next minor release of HSM, use _SCRIPT_SUBNAME instead"
|
52
|
+
})
|
48
53
|
for (const referencePath of getReferencePathsToGlobal("_SCRIPT_NAME", program))
|
49
54
|
referencePath.replaceWith(t.stringLiteral(1 == scriptName ? `$${uniqueId}$SCRIPT_NAME$` : scriptName))
|
55
|
+
}
|
56
|
+
if (program.scope.hasGlobal("_SCRIPT_SUBNAME"))
|
57
|
+
for (const referencePath of getReferencePathsToGlobal("_SCRIPT_SUBNAME", program))
|
58
|
+
referencePath.replaceWith(t.stringLiteral(1 == scriptName ? `$${uniqueId}$SCRIPT_NAME$` : scriptName))
|
50
59
|
if (program.scope.hasGlobal("_FULL_SCRIPT_NAME"))
|
51
60
|
for (const referencePath of getReferencePathsToGlobal("_FULL_SCRIPT_NAME", program))
|
52
61
|
if (1 == scriptUser || 1 == scriptName)
|
@@ -68,30 +77,30 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
68
77
|
const referencePath = FunctionReferencePaths[0]
|
69
78
|
assert(
|
70
79
|
"MemberExpression" == referencePath.parent.type,
|
71
|
-
"src/processScript/transform.ts:
|
80
|
+
"src/processScript/transform.ts:111:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
72
81
|
)
|
73
82
|
assert(
|
74
83
|
"Identifier" == referencePath.parent.property.type,
|
75
|
-
"src/processScript/transform.ts:
|
84
|
+
"src/processScript/transform.ts:116:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
76
85
|
)
|
77
86
|
assert(
|
78
87
|
"prototype" == referencePath.parent.property.name,
|
79
|
-
"src/processScript/transform.ts:
|
88
|
+
"src/processScript/transform.ts:121:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
80
89
|
)
|
81
90
|
referencePath.parentPath.replaceWith(createGetFunctionPrototypeNode())
|
82
91
|
} else {
|
83
92
|
for (const referencePath of FunctionReferencePaths) {
|
84
93
|
assert(
|
85
94
|
"MemberExpression" == referencePath.parent.type,
|
86
|
-
"src/processScript/transform.ts:
|
95
|
+
"src/processScript/transform.ts:129:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
87
96
|
)
|
88
97
|
assert(
|
89
98
|
"Identifier" == referencePath.parent.property.type,
|
90
|
-
"src/processScript/transform.ts:
|
99
|
+
"src/processScript/transform.ts:134:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
91
100
|
)
|
92
101
|
assert(
|
93
102
|
"prototype" == referencePath.parent.property.name,
|
94
|
-
"src/processScript/transform.ts:
|
103
|
+
"src/processScript/transform.ts:139:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
95
104
|
)
|
96
105
|
functionDotPrototypeIsReferencedMultipleTimes = !0
|
97
106
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_FUNCTION_DOT_PROTOTYPE_`))
|
@@ -127,12 +136,12 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
127
136
|
const neededDbMethodLets = new Set()
|
128
137
|
if (program.scope.hasGlobal("$db"))
|
129
138
|
for (const referencePath of getReferencePathsToGlobal("$db", program)) {
|
130
|
-
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:
|
131
|
-
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:
|
139
|
+
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:193:69")
|
140
|
+
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:194:72")
|
132
141
|
const databaseOpMethodName = referencePath.parentPath.node.property.name
|
133
142
|
assert(
|
134
143
|
validDBMethods.includes(databaseOpMethodName),
|
135
|
-
`src/processScript/transform.ts:
|
144
|
+
`src/processScript/transform.ts:200:8 invalid db method "${databaseOpMethodName}", valid db methods are "${validDBMethods.join('", "')}"`
|
136
145
|
)
|
137
146
|
if ("CallExpression" == referencePath.parentPath.parentPath?.type)
|
138
147
|
referencePath.parentPath.replaceWith(t.identifier(`$${uniqueId}$DB$${databaseOpMethodName}$`))
|
@@ -162,21 +171,25 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
162
171
|
if (program.scope.hasGlobal("_SECLEVEL"))
|
163
172
|
for (const referencePath of getReferencePathsToGlobal("_SECLEVEL", program))
|
164
173
|
referencePath.replaceWith(t.numericLiteral(seclevel))
|
165
|
-
let needGetPrototypeOf = !1
|
174
|
+
let needGetPrototypeOf = !1,
|
175
|
+
needHasOwn = !1
|
166
176
|
if (program.scope.hasGlobal("Object"))
|
167
177
|
for (const referencePath of getReferencePathsToGlobal("Object", program))
|
168
178
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
169
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
179
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:250:64")
|
170
180
|
if ("getPrototypeOf" == referencePath.parent.property.name) {
|
171
181
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_GET_PROTOTYPE_OF_`))
|
172
182
|
needGetPrototypeOf = !0
|
183
|
+
} else if ("hasOwn" == referencePath.parent.property.name) {
|
184
|
+
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_HAS_OWN_`))
|
185
|
+
needHasOwn = !0
|
173
186
|
}
|
174
187
|
}
|
175
188
|
const consoleMethodsReferenced = new Set()
|
176
189
|
if (program.scope.hasGlobal("console"))
|
177
190
|
for (const referencePath of getReferencePathsToGlobal("console", program))
|
178
191
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
179
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
192
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:268:64")
|
180
193
|
referencePath.parentPath.replaceWith(
|
181
194
|
t.identifier(`_${uniqueId}_CONSOLE_METHOD_${referencePath.parent.property.name}_`)
|
182
195
|
)
|
@@ -184,13 +197,13 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
184
197
|
}
|
185
198
|
const lastStatement = program.node.body.at(-1)
|
186
199
|
let exportDefaultName
|
187
|
-
assert(lastStatement, "src/processScript/transform.ts:
|
200
|
+
assert(lastStatement, "src/processScript/transform.ts:282:27 program is empty")
|
188
201
|
if ("ExportNamedDeclaration" == lastStatement.type) {
|
189
202
|
program.node.body.pop()
|
190
203
|
for (const specifier of lastStatement.specifiers) {
|
191
204
|
assert(
|
192
205
|
"ExportSpecifier" == specifier.type,
|
193
|
-
`src/processScript/transform.ts:
|
206
|
+
`src/processScript/transform.ts:288:51 ${specifier.type} is currently unsupported`
|
194
207
|
)
|
195
208
|
if (
|
196
209
|
"default" !=
|
@@ -292,11 +305,11 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
292
305
|
let hoistedGlobalBlockFunctions = 0
|
293
306
|
for (const [globalBlockIndex, globalBlockStatement] of [...globalBlock.body.entries()].reverse())
|
294
307
|
if ("VariableDeclaration" == globalBlockStatement.type) {
|
295
|
-
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:
|
308
|
+
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:402:59")
|
296
309
|
const declarator = globalBlockStatement.declarations[0]
|
297
310
|
assert(
|
298
311
|
"Identifier" == declarator.id.type,
|
299
|
-
`src/processScript/transform.ts:
|
312
|
+
`src/processScript/transform.ts:406:51 declarator.id.type was "${declarator.id.type}"`
|
300
313
|
)
|
301
314
|
program.scope.crawl()
|
302
315
|
if (program.scope.hasGlobal(declarator.id.name)) {
|
@@ -311,9 +324,9 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
311
324
|
Object.keys(program.scope.globals).some(global => globalBlockVariables.has(global))
|
312
325
|
) {
|
313
326
|
const binding = program.scope.getBinding(declarator.id.name)
|
314
|
-
assert(binding, "src/processScript/transform.ts:
|
327
|
+
assert(binding, "src/processScript/transform.ts:425:23")
|
315
328
|
for (const referencePath of binding.referencePaths) {
|
316
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
329
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:428:56")
|
317
330
|
referencePath.replaceWith(
|
318
331
|
t.memberExpression(
|
319
332
|
t.identifier(`_${uniqueId}_G_`),
|
@@ -361,16 +374,16 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
361
374
|
} else globalBlockVariables.add(declarator.id.name)
|
362
375
|
} else if ("ClassDeclaration" == globalBlockStatement.type) {
|
363
376
|
program.scope.crawl()
|
364
|
-
assert(globalBlockStatement.id, "src/processScript/transform.ts:
|
377
|
+
assert(globalBlockStatement.id, "src/processScript/transform.ts:485:37")
|
365
378
|
if (program.scope.hasGlobal(globalBlockStatement.id.name)) {
|
366
379
|
globalBlock.body.splice(globalBlockIndex, 1)
|
367
380
|
const [globalBlockPath] = program.unshiftContainer("body", globalBlock),
|
368
381
|
[globalBlockStatementPath] = program.unshiftContainer("body", globalBlockStatement)
|
369
382
|
program.scope.crawl()
|
370
383
|
const binding = program.scope.getBinding(globalBlockStatement.id.name)
|
371
|
-
assert(binding, "src/processScript/transform.ts:
|
384
|
+
assert(binding, "src/processScript/transform.ts:497:22")
|
372
385
|
for (const referencePath of binding.referencePaths) {
|
373
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
386
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:500:55")
|
374
387
|
referencePath.replaceWith(
|
375
388
|
t.memberExpression(t.identifier(`_${uniqueId}_G_`), t.identifier(referencePath.node.name))
|
376
389
|
)
|
@@ -448,6 +461,31 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
448
461
|
)
|
449
462
|
])
|
450
463
|
)
|
464
|
+
needHasOwn &&
|
465
|
+
mainFunction.body.body.unshift(
|
466
|
+
t.variableDeclaration("let", [
|
467
|
+
t.variableDeclarator(
|
468
|
+
t.identifier(`_${uniqueId}_HAS_OWN_`),
|
469
|
+
t.callExpression(
|
470
|
+
t.memberExpression(
|
471
|
+
t.memberExpression(
|
472
|
+
t.identifier(
|
473
|
+
globalFunctionsUnder7Characters.find(name => !program.scope.hasOwnBinding(name))
|
474
|
+
),
|
475
|
+
t.identifier("call")
|
476
|
+
),
|
477
|
+
t.identifier("bind")
|
478
|
+
),
|
479
|
+
[
|
480
|
+
t.memberExpression(
|
481
|
+
t.memberExpression(t.identifier("Object"), t.identifier("prototype")),
|
482
|
+
t.identifier("hasOwnProperty")
|
483
|
+
)
|
484
|
+
]
|
485
|
+
)
|
486
|
+
)
|
487
|
+
])
|
488
|
+
)
|
451
489
|
consoleMethodsReferenced.size &&
|
452
490
|
mainFunction.body.body.unshift(
|
453
491
|
t.variableDeclaration(
|
@@ -537,7 +575,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
537
575
|
}
|
538
576
|
},
|
539
577
|
ClassBody({ node: classBody, scope, parent }) {
|
540
|
-
assert(t.isClass(parent), "src/processScript/transform.ts:
|
578
|
+
assert(t.isClass(parent), "src/processScript/transform.ts:695:30")
|
541
579
|
let thisIsReferenced = !1
|
542
580
|
for (const classMethod of classBody.body) {
|
543
581
|
if ("ClassMethod" != classMethod.type) continue
|
@@ -627,7 +665,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
627
665
|
)
|
628
666
|
}
|
629
667
|
})
|
630
|
-
return { file, seclevel }
|
668
|
+
return { file, seclevel, warnings }
|
631
669
|
function createGetFunctionPrototypeNode() {
|
632
670
|
const name = globalFunctionsUnder7Characters.find(name => !program.scope.hasOwnBinding(name))
|
633
671
|
return t.memberExpression(
|
@@ -637,23 +675,23 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
637
675
|
}
|
638
676
|
function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
|
639
677
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
640
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
678
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:801:60")
|
641
679
|
assert("Identifier" == referencePath.parent.property.type)
|
642
680
|
assert(
|
643
681
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
644
|
-
"src/processScript/transform.ts:
|
682
|
+
"src/processScript/transform.ts:803:81"
|
645
683
|
)
|
646
684
|
assert(
|
647
685
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
648
|
-
"src/processScript/transform.ts:
|
686
|
+
"src/processScript/transform.ts:804:83"
|
649
687
|
)
|
650
688
|
assert(
|
651
689
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
652
|
-
`src/processScript/transform.ts:
|
690
|
+
`src/processScript/transform.ts:808:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
653
691
|
)
|
654
692
|
assert(
|
655
693
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
656
|
-
`src/processScript/transform.ts:
|
694
|
+
`src/processScript/transform.ts:813:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
657
695
|
)
|
658
696
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
659
697
|
referencePath.parentPath.parentPath.replaceWith(
|
package/push.js
CHANGED
@@ -4,7 +4,7 @@ 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 { readFile } from "fs/promises"
|
7
|
-
import {
|
7
|
+
import { resolve, basename } from "path"
|
8
8
|
import { processScript } from "./processScript/index.js"
|
9
9
|
import "@babel/generator"
|
10
10
|
import "@babel/parser"
|
@@ -25,6 +25,7 @@ import "@babel/plugin-transform-private-property-in-object"
|
|
25
25
|
import "@babel/plugin-transform-unicode-sets-regex"
|
26
26
|
import "@babel/traverse"
|
27
27
|
import "@babel/types"
|
28
|
+
import "@rollup/plugin-alias"
|
28
29
|
import "@rollup/plugin-babel"
|
29
30
|
import "@rollup/plugin-commonjs"
|
30
31
|
import "@rollup/plugin-json"
|
@@ -124,23 +125,25 @@ async function push(
|
|
124
125
|
const pathsToUsers = new AutoMap(_path => new Set())
|
125
126
|
for (const [user, scriptsToPush] of usersToScriptsToPush)
|
126
127
|
for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
|
127
|
-
const allInfo = []
|
128
|
+
const allInfo = [],
|
129
|
+
sourcePathResolved = resolve(sourcePath)
|
128
130
|
await Promise.all(
|
129
131
|
[...pathsToUsers].map(async ([path, [...users]]) => {
|
130
132
|
const scriptName = basename(path.slice(0, -3)),
|
131
133
|
uniqueId = Math.floor(Math.random() * 2 ** 52)
|
132
134
|
.toString(36)
|
133
135
|
.padStart(11, "0"),
|
134
|
-
{ script: minifiedCode } = await processScript(await readFile(path, { encoding: "utf8" }), {
|
136
|
+
{ script: minifiedCode, warnings } = await processScript(await readFile(path, { encoding: "utf8" }), {
|
135
137
|
minify,
|
136
138
|
scriptUser: !0,
|
137
139
|
scriptName,
|
138
140
|
uniqueId,
|
139
141
|
filePath: path,
|
140
142
|
mangleNames,
|
141
|
-
forceQuineCheats
|
143
|
+
forceQuineCheats,
|
144
|
+
rootFolderPath: sourcePathResolved
|
142
145
|
}),
|
143
|
-
info = { path, users, characterCount: countHackmudCharacters(minifiedCode), error: void 0 }
|
146
|
+
info = { path, users, characterCount: countHackmudCharacters(minifiedCode), error: void 0, warnings }
|
144
147
|
await Promise.all(
|
145
148
|
users.map(user =>
|
146
149
|
writeFilePersistent(
|
package/watch.js
CHANGED
@@ -29,6 +29,7 @@ import "@babel/plugin-transform-private-property-in-object"
|
|
29
29
|
import "@babel/plugin-transform-unicode-sets-regex"
|
30
30
|
import "@babel/traverse"
|
31
31
|
import "@babel/types"
|
32
|
+
import "@rollup/plugin-alias"
|
32
33
|
import "@rollup/plugin-babel"
|
33
34
|
import "@rollup/plugin-commonjs"
|
34
35
|
import "@rollup/plugin-json"
|
@@ -73,10 +74,11 @@ async function watch(
|
|
73
74
|
: scriptName && "*" != scriptName ? wildUserScripts.add(scriptName)
|
74
75
|
: (pushEverything = !0)
|
75
76
|
}
|
76
|
-
const watcher = watch$1(
|
77
|
+
const watcher = watch$1(".", {
|
77
78
|
cwd: sourceDirectory,
|
78
79
|
awaitWriteFinish: { stabilityThreshold: 100 },
|
79
|
-
ignored:
|
80
|
+
ignored: (path, stats) =>
|
81
|
+
!!stats?.isFile() && !(path.endsWith(".js") || (path.endsWith(".ts") && !path.endsWith(".d.ts")))
|
80
82
|
}).on("change", async path => {
|
81
83
|
if (path.endsWith(".d.ts")) return
|
82
84
|
const extension = extname(path)
|
@@ -118,27 +120,22 @@ async function watch(
|
|
118
120
|
for (const user of scriptNamesToUsers.get(scriptName)) usersToPushToSet.add(user)
|
119
121
|
const usersToPushTo = [...usersToPushToSet].filter(user => !scriptNamesToUsersToSkip.has(user))
|
120
122
|
if (!usersToPushTo.length) {
|
121
|
-
onPush?.({ path, users: [], characterCount: 0, error: Error("no users to push to") })
|
123
|
+
onPush?.({ path, users: [], characterCount: 0, error: Error("no users to push to"), warnings: [] })
|
122
124
|
return
|
123
125
|
}
|
124
126
|
const uniqueId = Math.floor(Math.random() * 2 ** 52)
|
125
127
|
.toString(36)
|
126
128
|
.padStart(11, "0"),
|
127
129
|
filePath = resolve(sourceDirectory, path)
|
128
|
-
let minifiedCode
|
130
|
+
let minifiedCode, warnings
|
129
131
|
try {
|
130
|
-
;({ script: minifiedCode } = await processScript(
|
131
|
-
|
132
|
-
scriptUser: !0,
|
133
|
-
|
134
|
-
uniqueId,
|
135
|
-
filePath,
|
136
|
-
mangleNames,
|
137
|
-
forceQuineCheats
|
138
|
-
}))
|
132
|
+
;({ script: minifiedCode, warnings } = await processScript(
|
133
|
+
await readFile(filePath, { encoding: "utf8" }),
|
134
|
+
{ minify, scriptUser: !0, scriptName, uniqueId, filePath, mangleNames, forceQuineCheats }
|
135
|
+
))
|
139
136
|
} catch (error) {
|
140
|
-
assert(error instanceof Error, "src/watch.ts:
|
141
|
-
onPush?.({ path, users: [], characterCount: 0, error })
|
137
|
+
assert(error instanceof Error, "src/watch.ts:149:36")
|
138
|
+
onPush?.({ path, users: [], characterCount: 0, error, warnings: [] })
|
142
139
|
return
|
143
140
|
}
|
144
141
|
await Promise.all(
|
@@ -155,7 +152,8 @@ async function watch(
|
|
155
152
|
path,
|
156
153
|
users: usersToPushTo,
|
157
154
|
characterCount: countHackmudCharacters(minifiedCode),
|
158
|
-
error: void 0
|
155
|
+
error: void 0,
|
156
|
+
warnings
|
159
157
|
})
|
160
158
|
return
|
161
159
|
}
|
@@ -169,25 +167,27 @@ async function watch(
|
|
169
167
|
)
|
170
168
|
)
|
171
169
|
return
|
172
|
-
const
|
170
|
+
const sourceDirectoryResolved = resolve(sourceDirectory),
|
171
|
+
filePath = resolve(sourceDirectoryResolved, path),
|
173
172
|
sourceCode = await readFile(filePath, { encoding: "utf8" })
|
174
|
-
let script
|
173
|
+
let script, warnings
|
175
174
|
try {
|
176
|
-
;({ script } = await processScript(sourceCode, {
|
175
|
+
;({ script, warnings } = await processScript(sourceCode, {
|
177
176
|
minify,
|
178
177
|
scriptUser: user,
|
179
178
|
scriptName,
|
180
179
|
filePath,
|
181
180
|
mangleNames,
|
182
|
-
forceQuineCheats
|
181
|
+
forceQuineCheats,
|
182
|
+
rootFolderPath: sourceDirectoryResolved
|
183
183
|
}))
|
184
184
|
} catch (error) {
|
185
|
-
assert(error instanceof Error, "src/watch.ts:
|
186
|
-
onPush?.({ path, users: [], characterCount: 0, error })
|
185
|
+
assert(error instanceof Error, "src/watch.ts:196:35")
|
186
|
+
onPush?.({ path, users: [], characterCount: 0, error, warnings: [] })
|
187
187
|
return
|
188
188
|
}
|
189
189
|
await writeFilePersistent(resolve(hackmudDirectory, user, "scripts", scriptName + ".js"), script)
|
190
|
-
onPush?.({ path, users: [user], characterCount: countHackmudCharacters(script), error: void 0 })
|
190
|
+
onPush?.({ path, users: [user], characterCount: countHackmudCharacters(script), error: void 0, warnings })
|
191
191
|
})
|
192
192
|
onReady && watcher.on("ready", onReady)
|
193
193
|
if (!typeDeclarationPath_) return
|
@@ -197,7 +197,7 @@ async function watch(
|
|
197
197
|
try {
|
198
198
|
await writeFile(typeDeclarationPath, typeDeclaration)
|
199
199
|
} catch (error) {
|
200
|
-
assert(error instanceof Error, "src/watch.ts:
|
200
|
+
assert(error instanceof Error, "src/watch.ts:229:35")
|
201
201
|
if ("EISDIR" != error.code) throw error
|
202
202
|
typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
|
203
203
|
await writeFile(typeDeclarationPath, typeDeclaration)
|