hackmud-script-manager 0.20.4-0e584dd → 0.20.4-1581594
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/bin/hsm.js +178 -233
- package/env.d.ts +104 -23
- package/generateTypeDeclaration.js +2 -1
- package/index.js +1 -0
- package/package.json +6 -2
- package/processScript/index.js +1 -1
- package/processScript/minify.js +18 -21
- package/processScript/postprocess.d.ts +1 -1
- package/processScript/postprocess.js +3 -3
- package/processScript/preprocess.js +5 -3
- package/processScript/transform.js +53 -40
- package/push.d.ts +9 -1
- package/push.js +33 -11
- package/watch.js +1 -0
@@ -101,29 +101,29 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
101
101
|
functionDotPrototypeIsReferencedMultipleTimes = !0
|
102
102
|
}
|
103
103
|
}
|
104
|
-
const neededSubscriptLets = new
|
104
|
+
const neededSubscriptLets = new Map()
|
105
105
|
let detectedSeclevel = 4
|
106
106
|
for (const fakeSubscriptObjectName of ["$fs", "$4s", "$s"])
|
107
|
-
program.scope.hasGlobal(fakeSubscriptObjectName) && processFakeSubscriptObject(fakeSubscriptObjectName)
|
107
|
+
program.scope.hasGlobal(fakeSubscriptObjectName) && processFakeSubscriptObject(fakeSubscriptObjectName, 4)
|
108
108
|
for (const fakeSubscriptObjectName of ["$hs", "$3s"])
|
109
109
|
if (program.scope.hasGlobal(fakeSubscriptObjectName)) {
|
110
110
|
detectedSeclevel = 3
|
111
|
-
processFakeSubscriptObject(fakeSubscriptObjectName)
|
111
|
+
processFakeSubscriptObject(fakeSubscriptObjectName, 3)
|
112
112
|
}
|
113
113
|
for (const fakeSubscriptObjectName of ["$ms", "$2s"])
|
114
114
|
if (program.scope.hasGlobal(fakeSubscriptObjectName)) {
|
115
115
|
detectedSeclevel = 2
|
116
|
-
processFakeSubscriptObject(fakeSubscriptObjectName)
|
116
|
+
processFakeSubscriptObject(fakeSubscriptObjectName, 2)
|
117
117
|
}
|
118
118
|
for (const fakeSubscriptObjectName of ["$ls", "$1s"])
|
119
119
|
if (program.scope.hasGlobal(fakeSubscriptObjectName)) {
|
120
120
|
detectedSeclevel = 1
|
121
|
-
processFakeSubscriptObject(fakeSubscriptObjectName)
|
121
|
+
processFakeSubscriptObject(fakeSubscriptObjectName, 1)
|
122
122
|
}
|
123
123
|
for (const fakeSubscriptObjectName of ["$ns", "$0s"])
|
124
124
|
if (program.scope.hasGlobal(fakeSubscriptObjectName)) {
|
125
125
|
detectedSeclevel = 0
|
126
|
-
processFakeSubscriptObject(fakeSubscriptObjectName)
|
126
|
+
processFakeSubscriptObject(fakeSubscriptObjectName, 0)
|
127
127
|
}
|
128
128
|
seclevel = Math.min(seclevel, detectedSeclevel)
|
129
129
|
const neededDbMethodLets = new Set()
|
@@ -157,9 +157,10 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
157
157
|
if (program.scope.hasGlobal("$FMCL"))
|
158
158
|
for (const referencePath of getReferencePathsToGlobal("$FMCL", program))
|
159
159
|
referencePath.replaceWith(t.identifier(`$${uniqueId}$FMCL$`))
|
160
|
-
|
160
|
+
let needG = program.scope.hasGlobal("$G")
|
161
|
+
if (needG)
|
161
162
|
for (const referencePath of getReferencePathsToGlobal("$G", program))
|
162
|
-
referencePath.replaceWith(t.identifier(
|
163
|
+
referencePath.replaceWith(t.identifier(`_${uniqueId}_G_`))
|
163
164
|
if (program.scope.hasGlobal("_SECLEVEL"))
|
164
165
|
for (const referencePath of getReferencePathsToGlobal("_SECLEVEL", program))
|
165
166
|
referencePath.replaceWith(t.numericLiteral(seclevel))
|
@@ -167,7 +168,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
167
168
|
if (program.scope.hasGlobal("Object"))
|
168
169
|
for (const referencePath of getReferencePathsToGlobal("Object", program))
|
169
170
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
170
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
171
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:243:64")
|
171
172
|
if ("getPrototypeOf" == referencePath.parent.property.name) {
|
172
173
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueId}_GET_PROTOTYPE_OF_`))
|
173
174
|
needGetPrototypeOf = !0
|
@@ -177,7 +178,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
177
178
|
if (program.scope.hasGlobal("console"))
|
178
179
|
for (const referencePath of getReferencePathsToGlobal("console", program))
|
179
180
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
180
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
181
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:258:64")
|
181
182
|
referencePath.parentPath.replaceWith(
|
182
183
|
t.identifier(`_${uniqueId}_CONSOLE_METHOD_${referencePath.parent.property.name}_`)
|
183
184
|
)
|
@@ -185,13 +186,13 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
185
186
|
}
|
186
187
|
const lastStatement = program.node.body.at(-1)
|
187
188
|
let exportDefaultName
|
188
|
-
assert(lastStatement, "src/processScript/transform.ts:
|
189
|
+
assert(lastStatement, "src/processScript/transform.ts:272:27 program is empty")
|
189
190
|
if ("ExportNamedDeclaration" == lastStatement.type) {
|
190
191
|
program.node.body.pop()
|
191
192
|
for (const specifier of lastStatement.specifiers) {
|
192
193
|
assert(
|
193
194
|
"ExportSpecifier" == specifier.type,
|
194
|
-
`src/processScript/transform.ts:
|
195
|
+
`src/processScript/transform.ts:278:51 ${specifier.type} is currently unsupported`
|
195
196
|
)
|
196
197
|
const exportedName =
|
197
198
|
"Identifier" == specifier.exported.type ? specifier.exported.name : specifier.exported.value
|
@@ -314,11 +315,11 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
314
315
|
let hoistedGlobalBlockFunctions = 0
|
315
316
|
for (const [globalBlockIndex, globalBlockStatement] of [...globalBlock.body.entries()].reverse())
|
316
317
|
if ("VariableDeclaration" == globalBlockStatement.type) {
|
317
|
-
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:
|
318
|
+
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:412:59")
|
318
319
|
const declarator = globalBlockStatement.declarations[0]
|
319
320
|
assert(
|
320
321
|
"Identifier" == declarator.id.type,
|
321
|
-
`src/processScript/transform.ts:
|
322
|
+
`src/processScript/transform.ts:416:51 declarator.id.type was "${declarator.id.type}"`
|
322
323
|
)
|
323
324
|
program.scope.crawl()
|
324
325
|
if (program.scope.hasGlobal(declarator.id.name)) {
|
@@ -333,15 +334,16 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
333
334
|
Object.keys(program.scope.globals).some(global => globalBlockVariables.has(global))
|
334
335
|
) {
|
335
336
|
const binding = program.scope.getBinding(declarator.id.name)
|
336
|
-
assert(binding, "src/processScript/transform.ts:
|
337
|
+
assert(binding, "src/processScript/transform.ts:435:23")
|
337
338
|
for (const referencePath of binding.referencePaths) {
|
338
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
339
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:438:56")
|
339
340
|
referencePath.replaceWith(
|
340
341
|
t.memberExpression(
|
341
|
-
t.identifier(
|
342
|
+
t.identifier(`_${uniqueId}_G_`),
|
342
343
|
t.identifier(referencePath.node.name)
|
343
344
|
)
|
344
345
|
)
|
346
|
+
needG = !0
|
345
347
|
}
|
346
348
|
for (const referencePath of binding.constantViolations)
|
347
349
|
if ("AssignmentExpression" == referencePath.node.type)
|
@@ -350,12 +352,13 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
350
352
|
clearObject(node)
|
351
353
|
Object.assign(
|
352
354
|
node,
|
353
|
-
t.memberExpression(t.identifier(
|
355
|
+
t.memberExpression(t.identifier(`_${uniqueId}_G_`), t.identifier(name))
|
354
356
|
)
|
357
|
+
needG = !0
|
355
358
|
}
|
356
359
|
globalBlockPath.remove()
|
357
360
|
globalBlockStatementPath.remove()
|
358
|
-
declarator.init
|
361
|
+
if (declarator.init) {
|
359
362
|
globalBlock.body.splice(
|
360
363
|
globalBlockIndex,
|
361
364
|
0,
|
@@ -363,13 +366,15 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
363
366
|
t.assignmentExpression(
|
364
367
|
"=",
|
365
368
|
t.memberExpression(
|
366
|
-
t.identifier(
|
369
|
+
t.identifier(`_${uniqueId}_G_`),
|
367
370
|
t.identifier(declarator.id.name)
|
368
371
|
),
|
369
372
|
declarator.init
|
370
373
|
)
|
371
374
|
)
|
372
375
|
)
|
376
|
+
needG = !0
|
377
|
+
}
|
373
378
|
} else {
|
374
379
|
globalBlockPath.remove()
|
375
380
|
globalBlockStatementPath.remove()
|
@@ -379,22 +384,20 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
379
384
|
} else globalBlockVariables.add(declarator.id.name)
|
380
385
|
} else if ("ClassDeclaration" == globalBlockStatement.type) {
|
381
386
|
program.scope.crawl()
|
382
|
-
assert(globalBlockStatement.id, "src/processScript/transform.ts:
|
387
|
+
assert(globalBlockStatement.id, "src/processScript/transform.ts:495:37")
|
383
388
|
if (program.scope.hasGlobal(globalBlockStatement.id.name)) {
|
384
389
|
globalBlock.body.splice(globalBlockIndex, 1)
|
385
390
|
const [globalBlockPath] = program.unshiftContainer("body", globalBlock),
|
386
391
|
[globalBlockStatementPath] = program.unshiftContainer("body", globalBlockStatement)
|
387
392
|
program.scope.crawl()
|
388
393
|
const binding = program.scope.getBinding(globalBlockStatement.id.name)
|
389
|
-
assert(binding, "src/processScript/transform.ts:
|
394
|
+
assert(binding, "src/processScript/transform.ts:507:22")
|
390
395
|
for (const referencePath of binding.referencePaths) {
|
391
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
396
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:510:55")
|
392
397
|
referencePath.replaceWith(
|
393
|
-
t.memberExpression(
|
394
|
-
t.identifier(`$${uniqueId}$GLOBAL$`),
|
395
|
-
t.identifier(referencePath.node.name)
|
396
|
-
)
|
398
|
+
t.memberExpression(t.identifier(`_${uniqueId}_G_`), t.identifier(referencePath.node.name))
|
397
399
|
)
|
400
|
+
needG = !0
|
398
401
|
}
|
399
402
|
globalBlockPath.remove()
|
400
403
|
globalBlockStatementPath.remove()
|
@@ -405,7 +408,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
405
408
|
t.assignmentExpression(
|
406
409
|
"=",
|
407
410
|
t.memberExpression(
|
408
|
-
t.identifier(
|
411
|
+
t.identifier(`_${uniqueId}_G_`),
|
409
412
|
t.identifier(globalBlockStatement.id.name)
|
410
413
|
),
|
411
414
|
t.classExpression(
|
@@ -417,6 +420,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
417
420
|
)
|
418
421
|
)
|
419
422
|
)
|
423
|
+
needG = !0
|
420
424
|
}
|
421
425
|
}
|
422
426
|
if (program.scope.hasGlobal("_EXPORTS"))
|
@@ -522,12 +526,12 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
522
526
|
mainFunction.body.body.unshift(
|
523
527
|
t.variableDeclaration(
|
524
528
|
"let",
|
525
|
-
[...neededSubscriptLets].map(name =>
|
529
|
+
[...neededSubscriptLets].map(([name, seclevel]) =>
|
526
530
|
t.variableDeclarator(
|
527
531
|
t.identifier(`_${uniqueId}_SUBSCRIPT_${name}_`),
|
528
532
|
t.arrowFunctionExpression(
|
529
533
|
[t.restElement(t.identifier("args"))],
|
530
|
-
t.callExpression(t.identifier(`$${uniqueId}$SUBSCRIPT$${name}$`), [
|
534
|
+
t.callExpression(t.identifier(`$${uniqueId}$${seclevel}$SUBSCRIPT$${name}$`), [
|
531
535
|
t.spreadElement(t.identifier("args"))
|
532
536
|
])
|
533
537
|
)
|
@@ -535,6 +539,12 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
535
539
|
)
|
536
540
|
)
|
537
541
|
)
|
542
|
+
needG &&
|
543
|
+
mainFunction.body.body.unshift(
|
544
|
+
t.variableDeclaration("let", [
|
545
|
+
t.variableDeclarator(t.identifier(`_${uniqueId}_G_`), t.identifier(`$${uniqueId}$GLOBAL$`))
|
546
|
+
])
|
547
|
+
)
|
538
548
|
traverse(file, {
|
539
549
|
BlockStatement({ node: blockStatement }) {
|
540
550
|
for (const [index, functionDeclaration] of blockStatement.body.entries())
|
@@ -555,7 +565,7 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
555
565
|
}
|
556
566
|
},
|
557
567
|
ClassBody({ node: classBody, scope, parent }) {
|
558
|
-
assert(t.isClass(parent), "src/processScript/transform.ts:
|
568
|
+
assert(t.isClass(parent), "src/processScript/transform.ts:688:30")
|
559
569
|
let thisIsReferenced = !1
|
560
570
|
for (const classMethod of classBody.body) {
|
561
571
|
if ("ClassMethod" != classMethod.type) continue
|
@@ -631,7 +641,9 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
631
641
|
VariableDeclaration({ node: variableDeclaration }) {
|
632
642
|
"const" == variableDeclaration.kind && (variableDeclaration.kind = "let")
|
633
643
|
},
|
634
|
-
ThisExpression: path =>
|
644
|
+
ThisExpression: path => {
|
645
|
+
path.replaceWith(t.identifier("undefined"))
|
646
|
+
},
|
635
647
|
BigIntLiteral(path) {
|
636
648
|
const bigIntAsNumber = Number(path.node.value)
|
637
649
|
path.replaceWith(
|
@@ -659,36 +671,37 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
|
|
659
671
|
t.identifier("prototype")
|
660
672
|
)
|
661
673
|
}
|
662
|
-
function processFakeSubscriptObject(fakeSubscriptObjectName) {
|
674
|
+
function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
|
663
675
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
664
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
676
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:804:60")
|
665
677
|
assert("Identifier" == referencePath.parent.property.type)
|
666
678
|
assert(
|
667
679
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
668
|
-
"src/processScript/transform.ts:
|
680
|
+
"src/processScript/transform.ts:806:81"
|
669
681
|
)
|
670
682
|
assert(
|
671
683
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
672
|
-
"src/processScript/transform.ts:
|
684
|
+
"src/processScript/transform.ts:807:83"
|
673
685
|
)
|
674
686
|
assert(
|
675
687
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
676
|
-
`src/processScript/transform.ts:
|
688
|
+
`src/processScript/transform.ts:811:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
677
689
|
)
|
678
690
|
assert(
|
679
691
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
680
|
-
`src/processScript/transform.ts:
|
692
|
+
`src/processScript/transform.ts:816:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
681
693
|
)
|
682
694
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
683
695
|
referencePath.parentPath.parentPath.replaceWith(
|
684
696
|
t.identifier(
|
685
|
-
`$${uniqueId}$SUBSCRIPT$${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}$`
|
697
|
+
`$${uniqueId}$${seclevel}$SUBSCRIPT$${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}$`
|
686
698
|
)
|
687
699
|
)
|
688
700
|
else {
|
689
701
|
const name = `${referencePath.parent.property.name}$${referencePath.parentPath.parentPath.node.property.name}`
|
690
702
|
referencePath.parentPath.parentPath.replaceWith(t.identifier(`_${uniqueId}_SUBSCRIPT_${name}_`))
|
691
|
-
neededSubscriptLets.
|
703
|
+
const maxSecLevel = Math.max(neededSubscriptLets.get(name) || 0, seclevel)
|
704
|
+
neededSubscriptLets.set(name, maxSecLevel)
|
692
705
|
}
|
693
706
|
}
|
694
707
|
}
|
package/push.d.ts
CHANGED
@@ -18,6 +18,14 @@ export type PushOptions = LaxPartial<{
|
|
18
18
|
*/
|
19
19
|
forceQuineCheats: boolean;
|
20
20
|
}>;
|
21
|
+
export declare class MissingSourceFolderError extends Error {
|
22
|
+
}
|
23
|
+
export declare class MissingHackmudFolderError extends Error {
|
24
|
+
}
|
25
|
+
export declare class NoUsersError extends Error {
|
26
|
+
}
|
27
|
+
export declare class NoScriptsError extends Error {
|
28
|
+
}
|
21
29
|
/** Push scripts from a source directory to the hackmud directory.
|
22
30
|
*
|
23
31
|
* Pushes files directly in the source folder to all users
|
@@ -25,4 +33,4 @@ export type PushOptions = LaxPartial<{
|
|
25
33
|
* @param hackmudPath directory created by hackmud containing user data including scripts
|
26
34
|
* @param options {@link PushOptions details}
|
27
35
|
* @returns array of info on pushed scripts */
|
28
|
-
export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<Info[]>;
|
36
|
+
export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<MissingSourceFolderError | MissingHackmudFolderError | NoUsersError | NoScriptsError | Info[]>;
|
package/push.js
CHANGED
@@ -42,32 +42,54 @@ import "./processScript/preprocess.js"
|
|
42
42
|
import "import-meta-resolve"
|
43
43
|
import "./processScript/transform.js"
|
44
44
|
import "@samual/lib/clearObject"
|
45
|
+
class MissingSourceFolderError extends Error {}
|
46
|
+
Object.defineProperty(MissingSourceFolderError.prototype, "name", { value: "MissingSourceFolderError" })
|
47
|
+
class MissingHackmudFolderError extends Error {}
|
48
|
+
Object.defineProperty(MissingHackmudFolderError.prototype, "name", { value: "MissingHackmudFolderError" })
|
49
|
+
class NoUsersError extends Error {}
|
50
|
+
Object.defineProperty(NoUsersError.prototype, "name", { value: "NoUsersError" })
|
51
|
+
class NoScriptsError extends Error {}
|
52
|
+
Object.defineProperty(NoScriptsError.prototype, "name", { value: "NoScriptsError" })
|
45
53
|
async function push(
|
46
54
|
sourcePath,
|
47
55
|
hackmudPath,
|
48
56
|
{ scripts = ["*.*"], onPush = () => {}, minify = !0, mangleNames = !1, forceQuineCheats } = {}
|
49
57
|
) {
|
50
58
|
const [sourceFolder, hackmudFolder] = await Promise.all([
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
59
|
+
readDirectoryWithStats(sourcePath).catch(error => {
|
60
|
+
if (error && "ENOENT" == error.code)
|
61
|
+
return new MissingSourceFolderError("There is no folder at " + sourcePath)
|
62
|
+
throw error
|
63
|
+
}),
|
64
|
+
readDirectoryWithStats(hackmudPath).catch(error => {
|
65
|
+
if (error && "ENOENT" == error.code)
|
66
|
+
return new MissingHackmudFolderError("There is no folder at " + hackmudPath)
|
67
|
+
throw error
|
68
|
+
})
|
69
|
+
])
|
70
|
+
if (sourceFolder instanceof Error) return sourceFolder
|
71
|
+
if (hackmudFolder instanceof Error) return hackmudFolder
|
72
|
+
const sourceFolderFolders = sourceFolder.filter(({ stats }) => stats.isDirectory()),
|
55
73
|
allUsers = new Set([
|
56
74
|
...scripts
|
57
|
-
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:
|
75
|
+
.map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:82:65"))
|
58
76
|
.filter(name => "*" != name),
|
59
77
|
...sourceFolderFolders.map(({ name }) => name),
|
60
78
|
...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
|
61
79
|
...hackmudFolder
|
62
80
|
.filter(({ stats, name }) => stats.isFile() && name.endsWith(".key"))
|
63
81
|
.map(({ name }) => name.slice(0, -4))
|
64
|
-
])
|
65
|
-
|
82
|
+
])
|
83
|
+
if (!allUsers.size)
|
84
|
+
return new NoUsersError(
|
85
|
+
"Could not find any users. Either provide the names of your users or log into a user in hackmud"
|
86
|
+
)
|
87
|
+
const usersToScriptsToPush = new Cache(_user => new Map()),
|
66
88
|
scriptNamesToUsers = new Cache(_scriptName => new Set())
|
67
89
|
for (const script of scripts) {
|
68
90
|
const [user, scriptName] = script.split(".")
|
69
|
-
assert(user, "src/push.ts:
|
70
|
-
assert(scriptName, "src/push.ts:
|
91
|
+
assert(user, "src/push.ts:105:16")
|
92
|
+
assert(scriptName, "src/push.ts:106:22")
|
71
93
|
"*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
|
72
94
|
}
|
73
95
|
const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
|
@@ -98,7 +120,7 @@ async function push(
|
|
98
120
|
for (const [scriptName, users] of scriptNamesToUsers)
|
99
121
|
for (const user of users)
|
100
122
|
if (!usersToScriptsToPush.get(user).has(scriptName))
|
101
|
-
|
123
|
+
return new NoScriptsError(`Could not find script ${user}.${scriptName} to push`)
|
102
124
|
const pathsToUsers = new Cache(_path => new Set())
|
103
125
|
for (const [user, scriptsToPush] of usersToScriptsToPush)
|
104
126
|
for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
|
@@ -135,4 +157,4 @@ async function push(
|
|
135
157
|
)
|
136
158
|
return allInfo
|
137
159
|
}
|
138
|
-
export { push }
|
160
|
+
export { MissingHackmudFolderError, MissingSourceFolderError, NoScriptsError, NoUsersError, push }
|
package/watch.js
CHANGED
@@ -9,6 +9,7 @@ import { extname, basename, resolve } from "path"
|
|
9
9
|
import { supportedExtensions } from "./constants.js"
|
10
10
|
import { generateTypeDeclaration } from "./generateTypeDeclaration.js"
|
11
11
|
import { processScript } from "./processScript/index.js"
|
12
|
+
import "path/posix"
|
12
13
|
import "@babel/generator"
|
13
14
|
import "@babel/parser"
|
14
15
|
import "@babel/plugin-proposal-decorators"
|