hackmud-script-manager 0.19.1-a81047f → 0.19.1-b040eb5
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/hsm.js +8 -7
- package/env.d.ts +1357 -0
- package/index.d.ts +2 -2
- package/package.json +4 -1
- package/processScript/index.d.ts +4 -3
- package/processScript/index.js +7 -7
- package/processScript/minify.d.ts +3 -3
- package/processScript/preprocess.d.ts +5 -4
- package/processScript/preprocess.js +2 -2
- package/processScript/transform.d.ts +5 -3
- package/processScript/transform.js +66 -38
- package/push.d.ts +5 -5
- package/push.js +83 -214
- package/syncMacros.js +1 -1
- package/watch.d.ts +3 -3
- package/watch.js +8 -8
package/index.d.ts
CHANGED
@@ -6,8 +6,8 @@ export { push } from "./push";
|
|
6
6
|
export { syncMacros } from "./syncMacros";
|
7
7
|
export { watch } from "./watch";
|
8
8
|
export type Info = {
|
9
|
-
|
9
|
+
path: string;
|
10
10
|
users: string[];
|
11
|
-
|
11
|
+
characterCount: number;
|
12
12
|
error: Error | undefined;
|
13
13
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hackmud-script-manager",
|
3
|
-
"version": "0.19.1-
|
3
|
+
"version": "0.19.1-b040eb5",
|
4
4
|
"description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
|
5
5
|
"keywords": [
|
6
6
|
"api",
|
@@ -69,6 +69,9 @@
|
|
69
69
|
"rollup": "^4.14.2",
|
70
70
|
"terser": "^5.30.3"
|
71
71
|
},
|
72
|
+
"peerDependencies": {
|
73
|
+
"typescript": "5.4.5"
|
74
|
+
},
|
72
75
|
"type": "module",
|
73
76
|
"exports": {
|
74
77
|
".": "./index.js",
|
package/processScript/index.d.ts
CHANGED
@@ -3,11 +3,10 @@ export { minify } from "./minify";
|
|
3
3
|
export { postprocess } from "./postprocess";
|
4
4
|
export { preprocess } from "./preprocess";
|
5
5
|
export { transform } from "./transform";
|
6
|
-
export type ProcessOptions = {
|
6
|
+
export type ProcessOptions = LaxPartial<{
|
7
7
|
/** whether to minify the given code */ minify: boolean;
|
8
8
|
/** 11 a-z 0-9 characters */ uniqueID: string;
|
9
9
|
/** the user going to be hosting this script (or set to `true` if not yet known) */ scriptUser: string | true;
|
10
|
-
/** the name of this script (or set to `true` if not yet known) */ scriptName: string | true;
|
11
10
|
filePath: string;
|
12
11
|
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
13
12
|
/** when set to `true` forces use of quine cheats
|
@@ -17,11 +16,13 @@ export type ProcessOptions = {
|
|
17
16
|
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
18
17
|
*/
|
19
18
|
forceQuineCheats: boolean;
|
19
|
+
}> & {
|
20
|
+
scriptName: string | true;
|
20
21
|
};
|
21
22
|
/** Minifies a given script
|
22
23
|
* @param code JavaScript or TypeScript code
|
23
24
|
* @param options {@link ProcessOptions details} */
|
24
|
-
export declare function processScript(code: string, { minify: shouldMinify, uniqueID, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }
|
25
|
+
export declare function processScript(code: string, { minify: shouldMinify, uniqueID, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }: ProcessOptions): Promise<{
|
25
26
|
script: string;
|
26
27
|
warnings: {
|
27
28
|
message: string;
|
package/processScript/index.js
CHANGED
@@ -47,14 +47,14 @@ async function processScript(
|
|
47
47
|
uniqueID = Math.floor(Math.random() * 2 ** 52)
|
48
48
|
.toString(36)
|
49
49
|
.padStart(11, "0"),
|
50
|
-
scriptUser
|
51
|
-
scriptName
|
50
|
+
scriptUser,
|
51
|
+
scriptName,
|
52
52
|
filePath,
|
53
53
|
mangleNames = !1,
|
54
54
|
forceQuineCheats
|
55
|
-
}
|
55
|
+
}
|
56
56
|
) {
|
57
|
-
assert(/^\w{11}$/.exec(uniqueID), "src/processScript/index.ts:
|
57
|
+
assert(/^\w{11}$/.exec(uniqueID), "src/processScript/index.ts:77:36")
|
58
58
|
const sourceCode = code
|
59
59
|
let autocomplete, statedSeclevel
|
60
60
|
const autocompleteMatch = /^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(code)
|
@@ -115,7 +115,7 @@ async function processScript(
|
|
115
115
|
}
|
116
116
|
}
|
117
117
|
}
|
118
|
-
assert(/^\w{11}$/.exec(uniqueID), "src/processScript/index.ts:
|
118
|
+
assert(/^\w{11}$/.exec(uniqueID), "src/processScript/index.ts:158:36")
|
119
119
|
const plugins = [
|
120
120
|
[babelPluginProposalDecorators.default, { decoratorsBeforeExport: !0 }],
|
121
121
|
[babelPluginTransformClassProperties.default],
|
@@ -249,7 +249,7 @@ async function processScript(
|
|
249
249
|
traverse(file, {
|
250
250
|
MemberExpression({ node: memberExpression }) {
|
251
251
|
if (!memberExpression.computed) {
|
252
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:
|
252
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:321:60")
|
253
253
|
if ("prototype" == memberExpression.property.name) {
|
254
254
|
memberExpression.computed = !0
|
255
255
|
memberExpression.property = t.stringLiteral("prototype")
|
@@ -279,7 +279,7 @@ async function processScript(
|
|
279
279
|
break
|
280
280
|
case "ObjectPattern":
|
281
281
|
for (const property of lValue.properties) {
|
282
|
-
assert("ObjectProperty" == property.type, "src/processScript/index.ts:
|
282
|
+
assert("ObjectProperty" == property.type, "src/processScript/index.ts:351:51")
|
283
283
|
renameVariables(property.value)
|
284
284
|
}
|
285
285
|
break
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { File } from "@babel/types";
|
2
2
|
import type { LaxPartial } from "@samual/lib";
|
3
|
-
type MinifyOptions = {
|
3
|
+
type MinifyOptions = LaxPartial<{
|
4
4
|
/** 11 a-z 0-9 characters */ uniqueID: string;
|
5
5
|
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
6
6
|
/** when set to `true` forces use of quine cheats
|
@@ -11,8 +11,8 @@ type MinifyOptions = {
|
|
11
11
|
*/
|
12
12
|
forceQuineCheats: boolean;
|
13
13
|
/** the comment inserted after the function signature */ autocomplete: string;
|
14
|
-
}
|
14
|
+
}>;
|
15
15
|
/** @param file babel ast node representing a file containing transformed code
|
16
16
|
* @param options {@link MinifyOptions details} */
|
17
|
-
export declare function minify(file: File, { uniqueID, mangleNames, forceQuineCheats, autocomplete }?:
|
17
|
+
export declare function minify(file: File, { uniqueID, mangleNames, forceQuineCheats, autocomplete }?: MinifyOptions): Promise<string>;
|
18
18
|
export {};
|
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import type { LaxPartial } from "@samual/lib";
|
2
|
+
export type PreprocessOptions = LaxPartial<{
|
3
|
+
uniqueID: string;
|
4
|
+
}>;
|
4
5
|
/** @param code source code for preprocessing
|
5
6
|
* @param options {@link PreprocessOptions details} */
|
6
|
-
export declare function preprocess(code: string, { uniqueID }?:
|
7
|
+
export declare function preprocess(code: string, { uniqueID }?: PreprocessOptions): Promise<{
|
7
8
|
code: string;
|
8
9
|
}>;
|
@@ -8,7 +8,7 @@ import { resolve } from "import-meta-resolve"
|
|
8
8
|
const { default: traverse } = babelTraverse,
|
9
9
|
{ default: generate } = babelGenerator
|
10
10
|
async function preprocess(code, { uniqueID = "00000000000" } = {}) {
|
11
|
-
assert(/^\w{11}$/.test(uniqueID), "src/processScript/preprocess.ts:
|
11
|
+
assert(/^\w{11}$/.test(uniqueID), "src/processScript/preprocess.ts:22:36")
|
12
12
|
const sourceCode = code
|
13
13
|
let lengthBefore, file, program
|
14
14
|
do {
|
@@ -47,7 +47,7 @@ async function preprocess(code, { uniqueID = "00000000000" } = {}) {
|
|
47
47
|
})
|
48
48
|
break
|
49
49
|
} catch (error_) {
|
50
|
-
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:
|
50
|
+
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:66:42")
|
51
51
|
error = error_
|
52
52
|
}
|
53
53
|
if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import type { File } from "@babel/types";
|
2
|
-
|
2
|
+
import type { LaxPartial } from "@samual/lib";
|
3
|
+
export type TransformOptions = LaxPartial<{
|
3
4
|
/** 11 a-z 0-9 characters */ uniqueID: string;
|
4
5
|
/** the user going to be hosting this script (or set to `true` if not yet known) */ scriptUser: string | true;
|
5
|
-
/** the name of this script (or set to `true` if not yet known) */ scriptName: string | true;
|
6
6
|
seclevel: number;
|
7
|
+
}> & {
|
8
|
+
scriptName: string | true;
|
7
9
|
};
|
8
10
|
/** transform a given babel `File` to be hackmud compatible
|
9
11
|
*
|
@@ -11,7 +13,7 @@ export type TransformOptions = {
|
|
11
13
|
* @param file babel ast node representing a file containing preprocessed code
|
12
14
|
* @param sourceCode the original untouched source code
|
13
15
|
* @param options {@link TransformOptions details} */
|
14
|
-
export declare function transform(file: File, sourceCode: string, { uniqueID, scriptUser, scriptName, seclevel }
|
16
|
+
export declare function transform(file: File, sourceCode: string, { uniqueID, scriptUser, scriptName, seclevel }: TransformOptions): {
|
15
17
|
file: File;
|
16
18
|
seclevel: number;
|
17
19
|
};
|
@@ -21,11 +21,7 @@ const { default: traverse } = babelTraverse,
|
|
21
21
|
"Symbol",
|
22
22
|
"BigInt"
|
23
23
|
]
|
24
|
-
function transform(
|
25
|
-
file,
|
26
|
-
sourceCode,
|
27
|
-
{ uniqueID = "00000000000", scriptUser = "UNKNOWN", scriptName = "UNKNOWN", seclevel = 4 } = {}
|
28
|
-
) {
|
24
|
+
function transform(file, sourceCode, { uniqueID = "00000000000", scriptUser, scriptName, seclevel = 4 }) {
|
29
25
|
const topFunctionName = `_${uniqueID}_SCRIPT_`,
|
30
26
|
exports = new Map(),
|
31
27
|
liveExports = new Map()
|
@@ -42,21 +38,31 @@ function transform(
|
|
42
38
|
if (program.scope.hasGlobal("_BUILD_DATE"))
|
43
39
|
for (const referencePath of getReferencePathsToGlobal("_BUILD_DATE", program))
|
44
40
|
referencePath.replaceWith(t.numericLiteral(Date.now()))
|
41
|
+
let uniqueIdScriptUserNeeded = !1
|
45
42
|
if (program.scope.hasGlobal("_SCRIPT_USER"))
|
46
43
|
for (const referencePath of getReferencePathsToGlobal("_SCRIPT_USER", program))
|
47
|
-
|
44
|
+
if (null == scriptUser) {
|
45
|
+
uniqueIdScriptUserNeeded = !0
|
46
|
+
referencePath.replaceWith(t.identifier(`_${uniqueID}_SCRIPT_USER_`))
|
47
|
+
} else
|
48
|
+
referencePath.replaceWith(t.stringLiteral(1 == scriptUser ? `$${uniqueID}$SCRIPT_USER$` : scriptUser))
|
48
49
|
if (program.scope.hasGlobal("_SCRIPT_NAME"))
|
49
50
|
for (const referencePath of getReferencePathsToGlobal("_SCRIPT_NAME", program))
|
50
51
|
referencePath.replaceWith(t.stringLiteral(1 == scriptName ? `$${uniqueID}$SCRIPT_NAME$` : scriptName))
|
51
52
|
if (program.scope.hasGlobal("_FULL_SCRIPT_NAME"))
|
52
53
|
for (const referencePath of getReferencePathsToGlobal("_FULL_SCRIPT_NAME", program))
|
53
|
-
|
54
|
-
t.stringLiteral(
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
if (1 == scriptUser || 1 == scriptName)
|
55
|
+
referencePath.replaceWith(t.stringLiteral(`$${uniqueID}$FULL_SCRIPT_NAME$`))
|
56
|
+
else if (null == scriptUser) {
|
57
|
+
uniqueIdScriptUserNeeded = !0
|
58
|
+
referencePath.replaceWith(
|
59
|
+
t.binaryExpression(
|
60
|
+
"+",
|
61
|
+
t.identifier(`_${uniqueID}_SCRIPT_USER_`),
|
62
|
+
t.stringLiteral("." + scriptName)
|
63
|
+
)
|
58
64
|
)
|
59
|
-
)
|
65
|
+
} else referencePath.replaceWith(t.stringLiteral(`${scriptUser}.${scriptName}`))
|
60
66
|
let functionDotPrototypeIsReferencedMultipleTimes = !1
|
61
67
|
if (program.scope.hasGlobal("Function")) {
|
62
68
|
const FunctionReferencePaths = getReferencePathsToGlobal("Function", program)
|
@@ -64,30 +70,30 @@ function transform(
|
|
64
70
|
const referencePath = FunctionReferencePaths[0]
|
65
71
|
assert(
|
66
72
|
"MemberExpression" == referencePath.parent.type,
|
67
|
-
"src/processScript/transform.ts:
|
73
|
+
"src/processScript/transform.ts:105:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
68
74
|
)
|
69
75
|
assert(
|
70
76
|
"Identifier" == referencePath.parent.property.type,
|
71
|
-
"src/processScript/transform.ts:
|
77
|
+
"src/processScript/transform.ts:110:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
72
78
|
)
|
73
79
|
assert(
|
74
80
|
"prototype" == referencePath.parent.property.name,
|
75
|
-
"src/processScript/transform.ts:
|
81
|
+
"src/processScript/transform.ts:115:8 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
76
82
|
)
|
77
83
|
referencePath.parentPath.replaceWith(createGetFunctionPrototypeNode())
|
78
84
|
} else {
|
79
85
|
for (const referencePath of FunctionReferencePaths) {
|
80
86
|
assert(
|
81
87
|
"MemberExpression" == referencePath.parent.type,
|
82
|
-
"src/processScript/transform.ts:
|
88
|
+
"src/processScript/transform.ts:123:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
83
89
|
)
|
84
90
|
assert(
|
85
91
|
"Identifier" == referencePath.parent.property.type,
|
86
|
-
"src/processScript/transform.ts:
|
92
|
+
"src/processScript/transform.ts:128:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
87
93
|
)
|
88
94
|
assert(
|
89
95
|
"prototype" == referencePath.parent.property.name,
|
90
|
-
"src/processScript/transform.ts:
|
96
|
+
"src/processScript/transform.ts:133:9 `Function` isn't available in hackmud, only `Function.prototype` is accessible"
|
91
97
|
)
|
92
98
|
functionDotPrototypeIsReferencedMultipleTimes = !0
|
93
99
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueID}_FUNCTION_DOT_PROTOTYPE_`))
|
@@ -123,12 +129,12 @@ function transform(
|
|
123
129
|
const neededDbMethodLets = new Set()
|
124
130
|
if (program.scope.hasGlobal("$db"))
|
125
131
|
for (const referencePath of getReferencePathsToGlobal("$db", program)) {
|
126
|
-
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:
|
127
|
-
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:
|
132
|
+
assert("MemberExpression" == referencePath.parentPath.node.type, "src/processScript/transform.ts:187:69")
|
133
|
+
assert("Identifier" == referencePath.parentPath.node.property.type, "src/processScript/transform.ts:188:72")
|
128
134
|
const databaseOpMethodName = referencePath.parentPath.node.property.name
|
129
135
|
assert(
|
130
136
|
validDBMethods.includes(databaseOpMethodName),
|
131
|
-
`src/processScript/transform.ts:
|
137
|
+
`src/processScript/transform.ts:194:8 invalid db method "${databaseOpMethodName}", valid db methods are "${validDBMethods.join('", "')}"`
|
132
138
|
)
|
133
139
|
if ("CallExpression" == referencePath.parentPath.parentPath?.type)
|
134
140
|
referencePath.parentPath.replaceWith(t.identifier(`$${uniqueID}$DB$${databaseOpMethodName}$`))
|
@@ -161,7 +167,7 @@ function transform(
|
|
161
167
|
if (program.scope.hasGlobal("Object"))
|
162
168
|
for (const referencePath of getReferencePathsToGlobal("Object", program))
|
163
169
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
164
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
170
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:241:64")
|
165
171
|
if ("getPrototypeOf" == referencePath.parent.property.name) {
|
166
172
|
referencePath.parentPath.replaceWith(t.identifier(`_${uniqueID}_GET_PROTOTYPE_OF_`))
|
167
173
|
needGetPrototypeOf = !0
|
@@ -171,7 +177,7 @@ function transform(
|
|
171
177
|
if (program.scope.hasGlobal("console"))
|
172
178
|
for (const referencePath of getReferencePathsToGlobal("console", program))
|
173
179
|
if ("MemberExpression" == referencePath.parent.type && !referencePath.parent.computed) {
|
174
|
-
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:
|
180
|
+
assert("Identifier" == referencePath.parent.property.type, "src/processScript/transform.ts:256:64")
|
175
181
|
referencePath.parentPath.replaceWith(
|
176
182
|
t.identifier(`_${uniqueID}_CONSOLE_METHOD_${referencePath.parent.property.name}_`)
|
177
183
|
)
|
@@ -179,13 +185,13 @@ function transform(
|
|
179
185
|
}
|
180
186
|
const lastStatement = program.node.body.at(-1)
|
181
187
|
let exportDefaultName
|
182
|
-
assert(lastStatement, "src/processScript/transform.ts:
|
188
|
+
assert(lastStatement, "src/processScript/transform.ts:270:27 program is empty")
|
183
189
|
if ("ExportNamedDeclaration" == lastStatement.type) {
|
184
190
|
program.node.body.pop()
|
185
191
|
for (const specifier of lastStatement.specifiers) {
|
186
192
|
assert(
|
187
193
|
"ExportSpecifier" == specifier.type,
|
188
|
-
`src/processScript/transform.ts:
|
194
|
+
`src/processScript/transform.ts:276:51 ${specifier.type} is currently unsupported`
|
189
195
|
)
|
190
196
|
const exportedName =
|
191
197
|
"Identifier" == specifier.exported.type ? specifier.exported.name : specifier.exported.value
|
@@ -261,6 +267,28 @@ function transform(
|
|
261
267
|
[t.identifier("context"), t.identifier("args")],
|
262
268
|
t.blockStatement([])
|
263
269
|
)
|
270
|
+
if (uniqueIdScriptUserNeeded) {
|
271
|
+
const mainFunctionParams = mainFunction.params
|
272
|
+
mainFunction.params = [t.restElement(t.identifier(`_${uniqueID}_PARAMS_`))]
|
273
|
+
mainFunction.body.body.unshift(
|
274
|
+
t.variableDeclaration("let", [
|
275
|
+
t.variableDeclarator(t.arrayPattern(mainFunctionParams), t.identifier(`_${uniqueID}_PARAMS_`)),
|
276
|
+
t.variableDeclarator(
|
277
|
+
t.arrayPattern([t.identifier(`_${uniqueID}_SCRIPT_USER_`)]),
|
278
|
+
t.callExpression(
|
279
|
+
t.memberExpression(
|
280
|
+
t.memberExpression(
|
281
|
+
t.memberExpression(t.identifier(`_${uniqueID}_PARAMS_`), t.numericLiteral(0), !0),
|
282
|
+
t.identifier("this_script")
|
283
|
+
),
|
284
|
+
t.identifier("split")
|
285
|
+
),
|
286
|
+
[t.stringLiteral(".")]
|
287
|
+
)
|
288
|
+
)
|
289
|
+
])
|
290
|
+
)
|
291
|
+
}
|
264
292
|
program.node.body = [mainFunction]
|
265
293
|
if (globalBlock.body.length) {
|
266
294
|
;(exports.size || liveExports.size) &&
|
@@ -286,11 +314,11 @@ function transform(
|
|
286
314
|
let hoistedGlobalBlockFunctions = 0
|
287
315
|
for (const [globalBlockIndex, globalBlockStatement] of [...globalBlock.body.entries()].reverse())
|
288
316
|
if ("VariableDeclaration" == globalBlockStatement.type) {
|
289
|
-
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:
|
317
|
+
assert(1 == globalBlockStatement.declarations.length, "src/processScript/transform.ts:410:59")
|
290
318
|
const declarator = globalBlockStatement.declarations[0]
|
291
319
|
assert(
|
292
320
|
"Identifier" == declarator.id.type,
|
293
|
-
`src/processScript/transform.ts:
|
321
|
+
`src/processScript/transform.ts:414:51 declarator.id.type was "${declarator.id.type}"`
|
294
322
|
)
|
295
323
|
program.scope.crawl()
|
296
324
|
if (program.scope.hasGlobal(declarator.id.name)) {
|
@@ -305,9 +333,9 @@ function transform(
|
|
305
333
|
Object.keys(program.scope.globals).some(global => globalBlockVariables.has(global))
|
306
334
|
) {
|
307
335
|
const binding = program.scope.getBinding(declarator.id.name)
|
308
|
-
assert(binding, "src/processScript/transform.ts:
|
336
|
+
assert(binding, "src/processScript/transform.ts:433:23")
|
309
337
|
for (const referencePath of binding.referencePaths) {
|
310
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
338
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:436:56")
|
311
339
|
referencePath.replaceWith(
|
312
340
|
t.memberExpression(
|
313
341
|
t.identifier(`$${uniqueID}$GLOBAL$`),
|
@@ -351,16 +379,16 @@ function transform(
|
|
351
379
|
} else globalBlockVariables.add(declarator.id.name)
|
352
380
|
} else if ("ClassDeclaration" == globalBlockStatement.type) {
|
353
381
|
program.scope.crawl()
|
354
|
-
assert(globalBlockStatement.id, "src/processScript/transform.ts:
|
382
|
+
assert(globalBlockStatement.id, "src/processScript/transform.ts:487:37")
|
355
383
|
if (program.scope.hasGlobal(globalBlockStatement.id.name)) {
|
356
384
|
globalBlock.body.splice(globalBlockIndex, 1)
|
357
385
|
const [globalBlockPath] = program.unshiftContainer("body", globalBlock),
|
358
386
|
[globalBlockStatementPath] = program.unshiftContainer("body", globalBlockStatement)
|
359
387
|
program.scope.crawl()
|
360
388
|
const binding = program.scope.getBinding(globalBlockStatement.id.name)
|
361
|
-
assert(binding, "src/processScript/transform.ts:
|
389
|
+
assert(binding, "src/processScript/transform.ts:499:22")
|
362
390
|
for (const referencePath of binding.referencePaths) {
|
363
|
-
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:
|
391
|
+
assert("Identifier" == referencePath.node.type, "src/processScript/transform.ts:502:55")
|
364
392
|
referencePath.replaceWith(
|
365
393
|
t.memberExpression(
|
366
394
|
t.identifier(`$${uniqueID}$GLOBAL$`),
|
@@ -527,7 +555,7 @@ function transform(
|
|
527
555
|
}
|
528
556
|
},
|
529
557
|
ClassBody({ node: classBody, scope, parent }) {
|
530
|
-
assert(t.isClass(parent), "src/processScript/transform.ts:
|
558
|
+
assert(t.isClass(parent), "src/processScript/transform.ts:669:30")
|
531
559
|
let thisIsReferenced = !1
|
532
560
|
for (const classMethod of classBody.body) {
|
533
561
|
if ("ClassMethod" != classMethod.type) continue
|
@@ -633,23 +661,23 @@ function transform(
|
|
633
661
|
}
|
634
662
|
function processFakeSubscriptObject(fakeSubscriptObjectName) {
|
635
663
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
636
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
664
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:783:60")
|
637
665
|
assert("Identifier" == referencePath.parent.property.type)
|
638
666
|
assert(
|
639
667
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
640
|
-
"src/processScript/transform.ts:
|
668
|
+
"src/processScript/transform.ts:785:81"
|
641
669
|
)
|
642
670
|
assert(
|
643
671
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
644
|
-
"src/processScript/transform.ts:
|
672
|
+
"src/processScript/transform.ts:786:83"
|
645
673
|
)
|
646
674
|
assert(
|
647
675
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
648
|
-
`src/processScript/transform.ts:
|
676
|
+
`src/processScript/transform.ts:790:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
649
677
|
)
|
650
678
|
assert(
|
651
679
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
652
|
-
`src/processScript/transform.ts:
|
680
|
+
`src/processScript/transform.ts:795:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
653
681
|
)
|
654
682
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
655
683
|
referencePath.parentPath.parentPath.replaceWith(
|
package/push.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { LaxPartial } from "@samual/lib";
|
2
2
|
import type { Info } from ".";
|
3
|
-
export type PushOptions = {
|
3
|
+
export type PushOptions = LaxPartial<{
|
4
4
|
/** whether to do the minify step (defaults to `true`) */ minify: boolean;
|
5
5
|
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
6
6
|
/** array of scripts in the format `foo.bar`
|
@@ -17,12 +17,12 @@ export type PushOptions = {
|
|
17
17
|
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
18
18
|
*/
|
19
19
|
forceQuineCheats: boolean;
|
20
|
-
}
|
20
|
+
}>;
|
21
21
|
/** Push scripts from a source directory to the hackmud directory.
|
22
22
|
*
|
23
23
|
* Pushes files directly in the source folder to all users
|
24
|
-
* @param
|
25
|
-
* @param
|
24
|
+
* @param sourcePath directory containing source code
|
25
|
+
* @param hackmudPath directory created by hackmud containing user data including scripts
|
26
26
|
* @param options {@link PushOptions details}
|
27
27
|
* @returns array of info on pushed scripts */
|
28
|
-
export declare function push(
|
28
|
+
export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats }?: PushOptions): Promise<Info[]>;
|