hackmud-script-manager 0.20.4-550e28d → 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/README.md +4 -0
- package/bin/hsm.js +161 -72
- package/env.d.ts +325 -317
- package/index.d.ts +3 -0
- package/index.js +2 -1
- package/package.json +39 -38
- 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 +71 -41
- package/push.js +12 -9
- package/watch.js +29 -28
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -27,6 +27,7 @@ import "@babel/plugin-transform-private-property-in-object"
|
|
27
27
|
import "@babel/plugin-transform-unicode-sets-regex"
|
28
28
|
import "@babel/traverse"
|
29
29
|
import "@babel/types"
|
30
|
+
import "@rollup/plugin-alias"
|
30
31
|
import "@rollup/plugin-babel"
|
31
32
|
import "@rollup/plugin-commonjs"
|
32
33
|
import "@rollup/plugin-json"
|
@@ -46,7 +47,7 @@ import "import-meta-resolve"
|
|
46
47
|
import "./processScript/transform.js"
|
47
48
|
import "@samual/lib/clearObject"
|
48
49
|
import "@samual/lib/copyFilePersistent"
|
49
|
-
import "@samual/lib/
|
50
|
+
import "@samual/lib/AutoMap"
|
50
51
|
import "@samual/lib/writeFilePersistent"
|
51
52
|
import "fs/promises"
|
52
53
|
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-66e0e13",
|
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,51 @@
|
|
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
|
+
"@rollup/plugin-alias": "^5.1.1",
|
62
63
|
"@rollup/plugin-babel": "^6.0.4",
|
63
|
-
"@rollup/plugin-commonjs": "^
|
64
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
64
65
|
"@rollup/plugin-json": "^6.1.0",
|
65
|
-
"@rollup/plugin-node-resolve": "^15.
|
66
|
-
"@samual/lib": "0.
|
67
|
-
"acorn": "^8.
|
66
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
67
|
+
"@samual/lib": "^0.13.0",
|
68
|
+
"acorn": "^8.14.0",
|
68
69
|
"chalk": "^5.3.0",
|
69
|
-
"chokidar": "^
|
70
|
-
"import-meta-resolve": "^4.
|
71
|
-
"prettier": "^3.
|
70
|
+
"chokidar": "^4.0.1",
|
71
|
+
"import-meta-resolve": "^4.1.0",
|
72
|
+
"prettier": "^3.3.3",
|
72
73
|
"proxy-polyfill": "^0.3.2",
|
73
|
-
"rollup": "^4.
|
74
|
-
"terser": "^5.
|
74
|
+
"rollup": "^4.27.4",
|
75
|
+
"terser": "^5.36.0"
|
75
76
|
},
|
76
77
|
"peerDependencies": {
|
77
|
-
"typescript": "5.4.5"
|
78
|
+
"typescript": "^5.4.5"
|
78
79
|
},
|
79
80
|
"type": "module",
|
80
81
|
"exports": {
|
package/processScript/index.d.ts
CHANGED
@@ -16,16 +16,16 @@ export type ProcessOptions = LaxPartial<{
|
|
16
16
|
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
17
17
|
*/
|
18
18
|
forceQuineCheats: boolean;
|
19
|
+
rootFolderPath: string;
|
19
20
|
}> & {
|
20
21
|
scriptName: string | true;
|
21
22
|
};
|
22
23
|
/** Minifies a given script
|
23
24
|
* @param code JavaScript or TypeScript code
|
24
25
|
* @param options {@link ProcessOptions details} */
|
25
|
-
export declare function processScript(code: string, { minify: shouldMinify, uniqueId, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats }: ProcessOptions): Promise<{
|
26
|
+
export declare function processScript(code: string, { minify: shouldMinify, uniqueId, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats, rootFolderPath }: ProcessOptions): Promise<{
|
26
27
|
script: string;
|
27
28
|
warnings: {
|
28
29
|
message: string;
|
29
|
-
line: number;
|
30
30
|
}[];
|
31
31
|
}>;
|
package/processScript/index.js
CHANGED
@@ -17,12 +17,13 @@ import babelPluginTransformPrivatePropertyInObject from "@babel/plugin-transform
|
|
17
17
|
import babelPluginTransformUnicodeSetsRegex from "@babel/plugin-transform-unicode-sets-regex"
|
18
18
|
import babelTraverse from "@babel/traverse"
|
19
19
|
import t from "@babel/types"
|
20
|
+
import rollupPluginAlias from "@rollup/plugin-alias"
|
20
21
|
import { babel } from "@rollup/plugin-babel"
|
21
22
|
import rollupPluginCommonJS from "@rollup/plugin-commonjs"
|
22
23
|
import rollupPluginJSON from "@rollup/plugin-json"
|
23
24
|
import rollupPluginNodeResolve from "@rollup/plugin-node-resolve"
|
24
25
|
import { assert } from "@samual/lib/assert"
|
25
|
-
import {
|
26
|
+
import { relative } from "path"
|
26
27
|
import prettier from "prettier"
|
27
28
|
import { rollup } from "rollup"
|
28
29
|
import { supportedExtensions } from "../constants.js"
|
@@ -51,10 +52,11 @@ async function processScript(
|
|
51
52
|
scriptName,
|
52
53
|
filePath,
|
53
54
|
mangleNames = !1,
|
54
|
-
forceQuineCheats
|
55
|
+
forceQuineCheats,
|
56
|
+
rootFolderPath
|
55
57
|
}
|
56
58
|
) {
|
57
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
59
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:81:36")
|
58
60
|
const sourceCode = code
|
59
61
|
let autocomplete, statedSeclevel
|
60
62
|
const autocompleteMatch = /^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(code)
|
@@ -115,7 +117,7 @@ async function processScript(
|
|
115
117
|
}
|
116
118
|
}
|
117
119
|
}
|
118
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
120
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:162:36")
|
119
121
|
const plugins = [
|
120
122
|
[babelPluginProposalDecorators.default, { decoratorsBeforeExport: !0 }],
|
121
123
|
[babelPluginTransformClassProperties.default],
|
@@ -135,7 +137,7 @@ async function processScript(
|
|
135
137
|
]
|
136
138
|
let filePathResolved
|
137
139
|
if (filePath) {
|
138
|
-
filePathResolved =
|
140
|
+
filePathResolved = relative(".", filePath)
|
139
141
|
if (filePath.endsWith(".ts"))
|
140
142
|
plugins.push([
|
141
143
|
(await import("@babel/plugin-transform-typescript")).default,
|
@@ -201,9 +203,11 @@ async function processScript(
|
|
201
203
|
[babelPluginProposalRecordAndTuple.default, { syntaxType: "hash", importPolyfill: !0 }]
|
202
204
|
)
|
203
205
|
}
|
206
|
+
console.debug("src/processScript/index.ts:256:16", supportedExtensions)
|
204
207
|
const bundle = await rollup({
|
205
208
|
input: filePathResolved,
|
206
209
|
plugins: [
|
210
|
+
rollupPluginJSON({ preferConst: !0 }),
|
207
211
|
{
|
208
212
|
name: "hackmud-script-manager",
|
209
213
|
async transform(code, id) {
|
@@ -228,13 +232,13 @@ async function processScript(
|
|
228
232
|
babel({ babelHelpers: "bundled", plugins, configFile: !1, extensions: supportedExtensions }),
|
229
233
|
rollupPluginCommonJS(),
|
230
234
|
rollupPluginNodeResolve({ extensions: supportedExtensions }),
|
231
|
-
|
235
|
+
!!rootFolderPath && rollupPluginAlias({ entries: [{ find: /^\//, replacement: rootFolderPath + "/" }] })
|
232
236
|
],
|
233
237
|
treeshake: { moduleSideEffects: !1 }
|
234
238
|
}),
|
235
239
|
seclevelNames = ["NULLSEC", "LOWSEC", "MIDSEC", "HIGHSEC", "FULLSEC"]
|
236
240
|
code = (await bundle.generate({})).output[0].code
|
237
|
-
const { file, seclevel } = transform(parse(code, { sourceType: "module" }), sourceCode, {
|
241
|
+
const { file, seclevel, warnings } = transform(parse(code, { sourceType: "module" }), sourceCode, {
|
238
242
|
uniqueId,
|
239
243
|
scriptUser,
|
240
244
|
scriptName
|
@@ -249,7 +253,7 @@ async function processScript(
|
|
249
253
|
traverse(file, {
|
250
254
|
MemberExpression({ node: memberExpression }) {
|
251
255
|
if (!memberExpression.computed) {
|
252
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:
|
256
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:328:60")
|
253
257
|
if ("prototype" == memberExpression.property.name) {
|
254
258
|
memberExpression.computed = !0
|
255
259
|
memberExpression.property = t.stringLiteral("prototype")
|
@@ -279,7 +283,7 @@ async function processScript(
|
|
279
283
|
break
|
280
284
|
case "ObjectPattern":
|
281
285
|
for (const property of lValue.properties) {
|
282
|
-
assert("ObjectProperty" == property.type, "src/processScript/index.ts:
|
286
|
+
assert("ObjectProperty" == property.type, "src/processScript/index.ts:358:51")
|
283
287
|
renameVariables(property.value)
|
284
288
|
}
|
285
289
|
break
|
@@ -328,6 +332,6 @@ async function processScript(
|
|
328
332
|
throw Error(
|
329
333
|
'you found a weird edge case where I wasn\'t able to replace illegal strings like "SC$", please report thx'
|
330
334
|
)
|
331
|
-
return { script: code, warnings
|
335
|
+
return { script: code, warnings }
|
332
336
|
}
|
333
337
|
export { minify, postprocess, preprocess, processScript, transform }
|
@@ -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:23: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:67:42")
|
51
51
|
error = error_
|
52
52
|
}
|
53
53
|
if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
|
@@ -16,4 +16,7 @@ export type TransformOptions = LaxPartial<{
|
|
16
16
|
export declare function transform(file: File, sourceCode: string, { uniqueId, scriptUser, scriptName, seclevel }: TransformOptions): {
|
17
17
|
file: File;
|
18
18
|
seclevel: number;
|
19
|
+
warnings: {
|
20
|
+
message: string;
|
21
|
+
}[];
|
19
22
|
};
|
@@ -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,41 +665,33 @@ 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
|
-
|
633
|
-
if (!program.scope.hasOwnBinding(globalFunction))
|
634
|
-
return t.memberExpression(
|
635
|
-
t.memberExpression(t.identifier(globalFunction), t.identifier("constructor")),
|
636
|
-
t.identifier("prototype")
|
637
|
-
)
|
670
|
+
const name = globalFunctionsUnder7Characters.find(name => !program.scope.hasOwnBinding(name))
|
638
671
|
return t.memberExpression(
|
639
|
-
t.
|
640
|
-
|
641
|
-
t.identifier("constructor")
|
642
|
-
),
|
643
|
-
t.identifier("prototype")
|
672
|
+
name ? t.identifier(name) : t.arrowFunctionExpression([t.identifier("_")], t.identifier("_")),
|
673
|
+
t.identifier("__proto__")
|
644
674
|
)
|
645
675
|
}
|
646
676
|
function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
|
647
677
|
for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
|
648
|
-
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:
|
678
|
+
assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:801:60")
|
649
679
|
assert("Identifier" == referencePath.parent.property.type)
|
650
680
|
assert(
|
651
681
|
"MemberExpression" == referencePath.parentPath.parentPath?.node.type,
|
652
|
-
"src/processScript/transform.ts:
|
682
|
+
"src/processScript/transform.ts:803:81"
|
653
683
|
)
|
654
684
|
assert(
|
655
685
|
"Identifier" == referencePath.parentPath.parentPath.node.property.type,
|
656
|
-
"src/processScript/transform.ts:
|
686
|
+
"src/processScript/transform.ts:804:83"
|
657
687
|
)
|
658
688
|
assert(
|
659
689
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
|
660
|
-
`src/processScript/transform.ts:
|
690
|
+
`src/processScript/transform.ts:808:8 invalid user "${referencePath.parent.property.name}" in subscript`
|
661
691
|
)
|
662
692
|
assert(
|
663
693
|
/^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
|
664
|
-
`src/processScript/transform.ts:
|
694
|
+
`src/processScript/transform.ts:813:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
|
665
695
|
)
|
666
696
|
if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
|
667
697
|
referencePath.parentPath.parentPath.replaceWith(
|
package/push.js
CHANGED
@@ -1,10 +1,10 @@
|
|
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"
|
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"
|
@@ -84,8 +85,8 @@ async function push(
|
|
84
85
|
return new NoUsersError(
|
85
86
|
"Could not find any users. Either provide the names of your users or log into a user in hackmud"
|
86
87
|
)
|
87
|
-
const usersToScriptsToPush = new
|
88
|
-
scriptNamesToUsers = new
|
88
|
+
const usersToScriptsToPush = new AutoMap(_user => new Map()),
|
89
|
+
scriptNamesToUsers = new AutoMap(_scriptName => new Set())
|
89
90
|
for (const script of scripts) {
|
90
91
|
const [user, scriptName] = script.split(".")
|
91
92
|
assert(user, "src/push.ts:105:16")
|
@@ -121,26 +122,28 @@ async function push(
|
|
121
122
|
for (const user of users)
|
122
123
|
if (!usersToScriptsToPush.get(user).has(scriptName))
|
123
124
|
return new NoScriptsError(`Could not find script ${user}.${scriptName} to push`)
|
124
|
-
const pathsToUsers = new
|
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(
|