hackmud-script-manager 0.21.1-2f94c60 → 0.21.1-3adcfa2
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 +46 -38
- package/bin/hsm.js +236 -245
- package/env.d.ts +314 -259
- package/generateTypeDeclaration.js +24 -23
- package/index.js +2 -3
- package/package.json +26 -24
- package/processScript/index.d.ts +12 -9
- package/processScript/index.js +87 -71
- package/processScript/minify.d.ts +11 -8
- package/processScript/minify.js +10 -10
- package/processScript/preprocess.d.ts +4 -2
- package/processScript/preprocess.js +7 -19
- package/processScript/transform.d.ts +8 -6
- package/processScript/transform.js +101 -24
- package/pull.d.ts +6 -4
- package/pull.js +1 -1
- package/push.d.ts +23 -18
- package/push.js +9 -7
- package/syncMacros.js +14 -15
- package/watch.d.ts +11 -7
- package/watch.js +6 -7
@@ -1,6 +1,5 @@
|
|
1
|
-
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
2
1
|
import { basename, resolve } from "path"
|
3
|
-
import
|
2
|
+
import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
|
4
3
|
async function generateTypeDeclaration(sourceDirectory, hackmudPath) {
|
5
4
|
const users = new Set()
|
6
5
|
if (hackmudPath)
|
@@ -11,33 +10,35 @@ async function generateTypeDeclaration(sourceDirectory, hackmudPath) {
|
|
11
10
|
allScripts = {},
|
12
11
|
allAnyScripts = {}
|
13
12
|
await Promise.all(
|
14
|
-
(await readDirectoryWithStats(sourceDirectory))
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
(await readDirectoryWithStats(sourceDirectory))
|
14
|
+
.filter(({ stats, name }) => !stats.isDirectory() || /^[a-z_][a-z\d_]{0,24}$/.test(name))
|
15
|
+
.map(async ({ stats, name }) => {
|
16
|
+
if (stats.isFile())
|
17
|
+
name.endsWith(".ts")
|
18
|
+
? name.endsWith(".d.ts") || wildScripts.push(basename(name, ".ts"))
|
19
|
+
: name.endsWith(".js") && wildAnyScripts.push(basename(name, ".js"))
|
20
|
+
else if (stats.isDirectory()) {
|
21
|
+
const scripts = [],
|
22
|
+
anyScripts = []
|
23
|
+
allScripts[name] = scripts
|
24
|
+
allAnyScripts[name] = anyScripts
|
25
|
+
users.add(name)
|
26
|
+
for (const child of await readDirectoryWithStats(resolve(sourceDirectory, name)))
|
27
|
+
child.stats.isFile() &&
|
28
|
+
(child.name.endsWith(".ts")
|
29
|
+
? name.endsWith(".d.ts") || scripts.push(basename(child.name, ".ts"))
|
30
|
+
: child.name.endsWith(".js") && anyScripts.push(basename(child.name, ".js")))
|
31
|
+
}
|
32
|
+
})
|
32
33
|
)
|
33
|
-
sourceDirectory = PathPosix.resolve(sourceDirectory)
|
34
34
|
let o = ""
|
35
|
-
for (const script of wildScripts)
|
35
|
+
for (const script of wildScripts)
|
36
|
+
o += `type $${script}$ = typeof import(${JSON.stringify(resolve(sourceDirectory, script))}).default\n`
|
36
37
|
o += "\n"
|
37
38
|
for (const user in allScripts) {
|
38
39
|
const scripts = allScripts[user]
|
39
40
|
for (const script of scripts)
|
40
|
-
o += `type $${user}$${script}$ = typeof import(
|
41
|
+
o += `type $${user}$${script}$ = typeof import(${JSON.stringify(resolve(sourceDirectory, user, script))}).default\n`
|
41
42
|
}
|
42
43
|
o +=
|
43
44
|
"\ntype ArrayRemoveFirst<A> = A extends [ infer FirstItem, ...infer Rest ] ? Rest : never\n\ntype Subscript<T extends (...args: any) => any> =\n\t(...args: ArrayRemoveFirst<Parameters<T>>) => ReturnType<T> | ScriptFailure\n\ntype WildFullsec = Record<string, () => ScriptFailure> & {\n"
|
package/index.js
CHANGED
@@ -5,9 +5,8 @@ export { pull } from "./pull.js"
|
|
5
5
|
export { push } from "./push.js"
|
6
6
|
export { syncMacros } from "./syncMacros.js"
|
7
7
|
export { watch } from "./watch.js"
|
8
|
-
import "@samual/lib/readDirectoryWithStats"
|
9
8
|
import "path"
|
10
|
-
import "
|
9
|
+
import "@samual/lib/readDirectoryWithStats"
|
11
10
|
import "@babel/generator"
|
12
11
|
import "@babel/parser"
|
13
12
|
import "@babel/plugin-proposal-decorators"
|
@@ -47,7 +46,7 @@ import "import-meta-resolve"
|
|
47
46
|
import "./processScript/transform.js"
|
48
47
|
import "@samual/lib/clearObject"
|
49
48
|
import "@samual/lib/copyFilePersistent"
|
49
|
+
import "fs/promises"
|
50
50
|
import "@samual/lib/AutoMap"
|
51
51
|
import "@samual/lib/writeFilePersistent"
|
52
|
-
import "fs/promises"
|
53
52
|
import "chokidar"
|
package/package.json
CHANGED
@@ -1,7 +1,22 @@
|
|
1
1
|
{
|
2
2
|
"name": "hackmud-script-manager",
|
3
|
-
"
|
3
|
+
"type": "module",
|
4
|
+
"version": "0.21.1-3adcfa2",
|
4
5
|
"description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
|
6
|
+
"author": "Samual Norman <me@samual.uk> (https://samual.uk/)",
|
7
|
+
"contributors": [
|
8
|
+
"Daniel Swann (https://github.com/danswann)",
|
9
|
+
"Longboyy",
|
10
|
+
"Helloman892",
|
11
|
+
"Sarah Klocke (https://sarahisweird.dev/)"
|
12
|
+
],
|
13
|
+
"license": "MIT",
|
14
|
+
"homepage": "https://github.com/samualtnorman/hackmud-script-manager#readme",
|
15
|
+
"repository": {
|
16
|
+
"type": "git",
|
17
|
+
"url": "https://github.com/samualtnorman/hackmud-script-manager.git"
|
18
|
+
},
|
19
|
+
"bugs": "https://github.com/samualtnorman/hackmud-script-manager/issues",
|
5
20
|
"keywords": [
|
6
21
|
"api",
|
7
22
|
"command-line",
|
@@ -17,18 +32,17 @@
|
|
17
32
|
"golf",
|
18
33
|
"golfer"
|
19
34
|
],
|
20
|
-
"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
"Daniel Swann (https://github.com/danswann)",
|
26
|
-
"Longboyy"
|
27
|
-
],
|
35
|
+
"exports": {
|
36
|
+
".": "./index.js",
|
37
|
+
"./*": "./*.js",
|
38
|
+
"./*.js": "./*.js"
|
39
|
+
},
|
28
40
|
"main": "index.js",
|
29
|
-
"
|
30
|
-
"
|
31
|
-
|
41
|
+
"bin": {
|
42
|
+
"hsm": "bin/hsm.js"
|
43
|
+
},
|
44
|
+
"peerDependencies": {
|
45
|
+
"typescript": "^5.4.5"
|
32
46
|
},
|
33
47
|
"dependencies": {
|
34
48
|
"@babel/generator": "^7.26.2",
|
@@ -74,18 +88,6 @@
|
|
74
88
|
"rollup": "^4.27.4",
|
75
89
|
"terser": "^5.36.0"
|
76
90
|
},
|
77
|
-
"peerDependencies": {
|
78
|
-
"typescript": "^5.4.5"
|
79
|
-
},
|
80
|
-
"type": "module",
|
81
|
-
"exports": {
|
82
|
-
".": "./index.js",
|
83
|
-
"./*": "./*.js",
|
84
|
-
"./*.js": "./*.js"
|
85
|
-
},
|
86
|
-
"bin": {
|
87
|
-
"hsm": "bin/hsm.js"
|
88
|
-
},
|
89
91
|
"engines": {
|
90
92
|
"node": "^18 || >=20"
|
91
93
|
}
|
package/processScript/index.d.ts
CHANGED
@@ -9,20 +9,23 @@ export type ProcessOptions = LaxPartial<{
|
|
9
9
|
/** the user going to be hosting this script (or set to `true` if not yet known) */ scriptUser: string | true;
|
10
10
|
filePath: string;
|
11
11
|
/** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
|
12
|
-
/**
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
/**
|
13
|
+
* when set to `true` forces use of quine cheats
|
14
|
+
*
|
15
|
+
* when set to `false` forces quine cheats not to be used
|
16
|
+
*
|
17
|
+
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
18
|
+
*/
|
18
19
|
forceQuineCheats: boolean;
|
19
20
|
rootFolderPath: string;
|
20
21
|
}> & {
|
21
22
|
scriptName: string | true;
|
22
23
|
};
|
23
|
-
/**
|
24
|
-
|
25
|
-
|
24
|
+
/**
|
25
|
+
* Minifies a given script
|
26
|
+
* @param code JavaScript or TypeScript code
|
27
|
+
* @param options {@link ProcessOptions details}
|
28
|
+
*/
|
26
29
|
export declare function processScript(code: string, { minify: shouldMinify, uniqueId, scriptUser, scriptName, filePath, mangleNames, forceQuineCheats, rootFolderPath }: ProcessOptions): Promise<{
|
27
30
|
script: string;
|
28
31
|
warnings: {
|
package/processScript/index.js
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
import
|
1
|
+
import { relative, isAbsolute, sep } from "path"
|
2
|
+
import dsiertos6nj44cs8y2rcgun4 from "@babel/generator"
|
2
3
|
import { parse } from "@babel/parser"
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import
|
9
|
-
import
|
10
|
-
import
|
11
|
-
import
|
12
|
-
import
|
13
|
-
import
|
14
|
-
import
|
15
|
-
import
|
16
|
-
import
|
17
|
-
import
|
18
|
-
import
|
4
|
+
import bcjqtivato78kt1v0tl1ohja from "@babel/plugin-proposal-decorators"
|
5
|
+
import rhuxh9nf8oetzi1qjywnj2v0 from "@babel/plugin-proposal-destructuring-private"
|
6
|
+
import kayhkwbrcstkzdi1hrb3v0a9 from "@babel/plugin-proposal-explicit-resource-management"
|
7
|
+
import n1qnb7uxjjmdwifj37mele67 from "@babel/plugin-transform-class-properties"
|
8
|
+
import vflgz56ruoe3wcxvuth7sgs7 from "@babel/plugin-transform-class-static-block"
|
9
|
+
import phxo5arpj0vr76xsql75r4fr from "@babel/plugin-transform-exponentiation-operator"
|
10
|
+
import d709y4gkoxcchn25ie9r2yve from "@babel/plugin-transform-json-strings"
|
11
|
+
import l4w6kwyf1jtufelbbei8i4q6 from "@babel/plugin-transform-logical-assignment-operators"
|
12
|
+
import xex42x0nbjgygwlehygjjphb from "@babel/plugin-transform-nullish-coalescing-operator"
|
13
|
+
import thdzndzajs932txypupmemsz from "@babel/plugin-transform-numeric-separator"
|
14
|
+
import sm6zemf0ik8u0pwy3skv0oto from "@babel/plugin-transform-object-rest-spread"
|
15
|
+
import s9fu7uuzegluj3pi1p7laaeb from "@babel/plugin-transform-optional-catch-binding"
|
16
|
+
import cbooko34m0nh69x8hehpf87h from "@babel/plugin-transform-optional-chaining"
|
17
|
+
import qmsl1cihjj5y69l0dezbqjh3 from "@babel/plugin-transform-private-property-in-object"
|
18
|
+
import plmjmoch3gyoifrx2t3iqpwc from "@babel/plugin-transform-unicode-sets-regex"
|
19
|
+
import jrpom318hon3bq0jzylo46gt from "@babel/traverse"
|
19
20
|
import t from "@babel/types"
|
20
21
|
import rollupPluginAlias from "@rollup/plugin-alias"
|
21
22
|
import { babel } from "@rollup/plugin-babel"
|
@@ -23,7 +24,6 @@ import rollupPluginCommonJS from "@rollup/plugin-commonjs"
|
|
23
24
|
import rollupPluginJSON from "@rollup/plugin-json"
|
24
25
|
import rollupPluginNodeResolve from "@rollup/plugin-node-resolve"
|
25
26
|
import { assert } from "@samual/lib/assert"
|
26
|
-
import { relative } from "path"
|
27
27
|
import prettier from "prettier"
|
28
28
|
import { rollup } from "rollup"
|
29
29
|
import { supportedExtensions } from "../constants.js"
|
@@ -38,9 +38,24 @@ import "acorn"
|
|
38
38
|
import "terser"
|
39
39
|
import "import-meta-resolve"
|
40
40
|
import "@samual/lib/clearObject"
|
41
|
-
const
|
42
|
-
|
43
|
-
|
41
|
+
const generate = dsiertos6nj44cs8y2rcgun4.default,
|
42
|
+
babelPluginProposalDecorators = bcjqtivato78kt1v0tl1ohja.default,
|
43
|
+
babelPluginProposalDestructuringPrivate = rhuxh9nf8oetzi1qjywnj2v0.default,
|
44
|
+
babelPluginProposalExplicitResourceManagement = kayhkwbrcstkzdi1hrb3v0a9.default,
|
45
|
+
babelPluginTransformClassProperties = n1qnb7uxjjmdwifj37mele67.default,
|
46
|
+
babelPluginTransformClassStaticBlock = vflgz56ruoe3wcxvuth7sgs7.default,
|
47
|
+
babelPluginTransformExponentiationOperator = phxo5arpj0vr76xsql75r4fr.default,
|
48
|
+
babelPluginTransformJsonStrings = d709y4gkoxcchn25ie9r2yve.default,
|
49
|
+
babelPluginTransformLogicalAssignmentOperators = l4w6kwyf1jtufelbbei8i4q6.default,
|
50
|
+
babelPluginTransformNullishCoalescingOperator = xex42x0nbjgygwlehygjjphb.default,
|
51
|
+
babelPluginTransformNumericSeparator = thdzndzajs932txypupmemsz.default,
|
52
|
+
babelPluginTransformObjectRestSpread = sm6zemf0ik8u0pwy3skv0oto.default,
|
53
|
+
babelPluginTransformOptionalCatchBinding = s9fu7uuzegluj3pi1p7laaeb.default,
|
54
|
+
babelPluginTransformOptionalChaining = cbooko34m0nh69x8hehpf87h.default,
|
55
|
+
babelPluginTransformPrivatePropertyInObject = qmsl1cihjj5y69l0dezbqjh3.default,
|
56
|
+
babelPluginTransformUnicodeSetsRegex = plmjmoch3gyoifrx2t3iqpwc.default,
|
57
|
+
traverse = jrpom318hon3bq0jzylo46gt.default,
|
58
|
+
{ format } = prettier
|
44
59
|
async function processScript(
|
45
60
|
code,
|
46
61
|
{
|
@@ -56,7 +71,7 @@ async function processScript(
|
|
56
71
|
rootFolderPath
|
57
72
|
}
|
58
73
|
) {
|
59
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
74
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:82:36")
|
60
75
|
const sourceCode = code
|
61
76
|
let autocomplete, statedSeclevel
|
62
77
|
const autocompleteMatch = /^function\s*\(.+\/\/(?<autocomplete>.+)/.exec(code)
|
@@ -117,30 +132,30 @@ async function processScript(
|
|
117
132
|
}
|
118
133
|
}
|
119
134
|
}
|
120
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:
|
135
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/index.ts:161:36")
|
121
136
|
const plugins = [
|
122
|
-
[babelPluginProposalDecorators
|
123
|
-
[babelPluginTransformClassProperties
|
124
|
-
[babelPluginTransformClassStaticBlock
|
125
|
-
[babelPluginTransformPrivatePropertyInObject
|
126
|
-
[babelPluginTransformLogicalAssignmentOperators
|
127
|
-
[babelPluginTransformNumericSeparator
|
128
|
-
[babelPluginTransformNullishCoalescingOperator
|
129
|
-
[babelPluginTransformOptionalChaining
|
130
|
-
[babelPluginTransformOptionalCatchBinding
|
131
|
-
[babelPluginTransformJsonStrings
|
132
|
-
[babelPluginTransformObjectRestSpread
|
133
|
-
[babelPluginTransformExponentiationOperator
|
134
|
-
[babelPluginTransformUnicodeSetsRegex
|
135
|
-
[babelPluginProposalDestructuringPrivate
|
136
|
-
[babelPluginProposalExplicitResourceManagement
|
137
|
+
[babelPluginProposalDecorators, { decoratorsBeforeExport: !0 }],
|
138
|
+
[babelPluginTransformClassProperties],
|
139
|
+
[babelPluginTransformClassStaticBlock],
|
140
|
+
[babelPluginTransformPrivatePropertyInObject],
|
141
|
+
[babelPluginTransformLogicalAssignmentOperators],
|
142
|
+
[babelPluginTransformNumericSeparator],
|
143
|
+
[babelPluginTransformNullishCoalescingOperator],
|
144
|
+
[babelPluginTransformOptionalChaining],
|
145
|
+
[babelPluginTransformOptionalCatchBinding],
|
146
|
+
[babelPluginTransformJsonStrings],
|
147
|
+
[babelPluginTransformObjectRestSpread],
|
148
|
+
[babelPluginTransformExponentiationOperator],
|
149
|
+
[babelPluginTransformUnicodeSetsRegex],
|
150
|
+
[babelPluginProposalDestructuringPrivate],
|
151
|
+
[babelPluginProposalExplicitResourceManagement]
|
137
152
|
]
|
138
153
|
let filePathResolved
|
139
154
|
if (filePath) {
|
140
155
|
filePathResolved = relative(".", filePath)
|
141
156
|
if (filePath.endsWith(".ts"))
|
142
157
|
plugins.push([
|
143
|
-
|
158
|
+
await import("@babel/plugin-transform-typescript").then(module => module.default),
|
144
159
|
{ allowDeclareFields: !0, optimizeConstEnums: !0 }
|
145
160
|
])
|
146
161
|
else {
|
@@ -153,22 +168,22 @@ async function processScript(
|
|
153
168
|
babelPluginProposalThrowExpressions,
|
154
169
|
babelPluginProposalRecordAndTuple
|
155
170
|
] = await Promise.all([
|
156
|
-
import("@babel/plugin-proposal-do-expressions"),
|
157
|
-
import("@babel/plugin-proposal-function-bind"),
|
158
|
-
import("@babel/plugin-proposal-function-sent"),
|
159
|
-
import("@babel/plugin-proposal-partial-application"),
|
160
|
-
import("@babel/plugin-proposal-pipeline-operator"),
|
161
|
-
import("@babel/plugin-proposal-throw-expressions"),
|
162
|
-
import("@babel/plugin-proposal-record-and-tuple")
|
171
|
+
import("@babel/plugin-proposal-do-expressions").then(module => module.default),
|
172
|
+
import("@babel/plugin-proposal-function-bind").then(module => module.default),
|
173
|
+
import("@babel/plugin-proposal-function-sent").then(module => module.default),
|
174
|
+
import("@babel/plugin-proposal-partial-application").then(module => module.default),
|
175
|
+
import("@babel/plugin-proposal-pipeline-operator").then(module => module.default),
|
176
|
+
import("@babel/plugin-proposal-throw-expressions").then(module => module.default),
|
177
|
+
import("@babel/plugin-proposal-record-and-tuple").then(module => module.default)
|
163
178
|
])
|
164
179
|
plugins.push(
|
165
|
-
[babelPluginProposalDoExpressions
|
166
|
-
[babelPluginProposalFunctionBind
|
167
|
-
[babelPluginProposalFunctionSent
|
168
|
-
[babelPluginProposalPartialApplication
|
169
|
-
[babelPluginProposalPipelineOperator
|
170
|
-
[babelPluginProposalThrowExpressions
|
171
|
-
[babelPluginProposalRecordAndTuple
|
180
|
+
[babelPluginProposalDoExpressions],
|
181
|
+
[babelPluginProposalFunctionBind],
|
182
|
+
[babelPluginProposalFunctionSent],
|
183
|
+
[babelPluginProposalPartialApplication],
|
184
|
+
[babelPluginProposalPipelineOperator, { proposal: "hack", topicToken: "%" }],
|
185
|
+
[babelPluginProposalThrowExpressions],
|
186
|
+
[babelPluginProposalRecordAndTuple, { syntaxType: "hash", importPolyfill: !0 }]
|
172
187
|
)
|
173
188
|
}
|
174
189
|
} else {
|
@@ -183,24 +198,24 @@ async function processScript(
|
|
183
198
|
babelPluginProposalThrowExpressions,
|
184
199
|
babelPluginProposalRecordAndTuple
|
185
200
|
] = await Promise.all([
|
186
|
-
import("@babel/plugin-transform-typescript"),
|
187
|
-
import("@babel/plugin-proposal-do-expressions"),
|
188
|
-
import("@babel/plugin-proposal-function-bind"),
|
189
|
-
import("@babel/plugin-proposal-function-sent"),
|
190
|
-
import("@babel/plugin-proposal-partial-application"),
|
191
|
-
import("@babel/plugin-proposal-pipeline-operator"),
|
192
|
-
import("@babel/plugin-proposal-throw-expressions"),
|
193
|
-
import("@babel/plugin-proposal-record-and-tuple")
|
201
|
+
import("@babel/plugin-transform-typescript").then(module => module.default),
|
202
|
+
import("@babel/plugin-proposal-do-expressions").then(module => module.default),
|
203
|
+
import("@babel/plugin-proposal-function-bind").then(module => module.default),
|
204
|
+
import("@babel/plugin-proposal-function-sent").then(module => module.default),
|
205
|
+
import("@babel/plugin-proposal-partial-application").then(module => module.default),
|
206
|
+
import("@babel/plugin-proposal-pipeline-operator").then(module => module.default),
|
207
|
+
import("@babel/plugin-proposal-throw-expressions").then(module => module.default),
|
208
|
+
import("@babel/plugin-proposal-record-and-tuple").then(module => module.default)
|
194
209
|
])
|
195
210
|
plugins.push(
|
196
|
-
[babelPluginTransformTypescript
|
197
|
-
[babelPluginProposalDoExpressions
|
198
|
-
[babelPluginProposalFunctionBind
|
199
|
-
[babelPluginProposalFunctionSent
|
200
|
-
[babelPluginProposalPartialApplication
|
201
|
-
[babelPluginProposalPipelineOperator
|
202
|
-
[babelPluginProposalThrowExpressions
|
203
|
-
[babelPluginProposalRecordAndTuple
|
211
|
+
[babelPluginTransformTypescript, { allowDeclareFields: !0, optimizeConstEnums: !0 }],
|
212
|
+
[babelPluginProposalDoExpressions],
|
213
|
+
[babelPluginProposalFunctionBind],
|
214
|
+
[babelPluginProposalFunctionSent],
|
215
|
+
[babelPluginProposalPartialApplication],
|
216
|
+
[babelPluginProposalPipelineOperator, { proposal: "hack", topicToken: "%" }],
|
217
|
+
[babelPluginProposalThrowExpressions],
|
218
|
+
[babelPluginProposalRecordAndTuple, { syntaxType: "hash", importPolyfill: !0 }]
|
204
219
|
)
|
205
220
|
}
|
206
221
|
const bundle = await rollup({
|
@@ -210,7 +225,8 @@ async function processScript(
|
|
210
225
|
{
|
211
226
|
name: "hackmud-script-manager",
|
212
227
|
async transform(code, id) {
|
213
|
-
if (!id.includes(
|
228
|
+
if (isAbsolute(id) && !id.includes(`${sep}node_modules${sep}`))
|
229
|
+
return (await preprocess(code, { uniqueId })).code
|
214
230
|
let program
|
215
231
|
traverse(parse(code, { sourceType: "module" }), {
|
216
232
|
Program(path) {
|
@@ -252,7 +268,7 @@ async function processScript(
|
|
252
268
|
traverse(file, {
|
253
269
|
MemberExpression({ node: memberExpression }) {
|
254
270
|
if (!memberExpression.computed) {
|
255
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:
|
271
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/index.ts:325:60")
|
256
272
|
if ("prototype" == memberExpression.property.name) {
|
257
273
|
memberExpression.computed = !0
|
258
274
|
memberExpression.property = t.stringLiteral("prototype")
|
@@ -3,16 +3,19 @@ import type { LaxPartial } from "@samual/lib";
|
|
3
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
|
-
/**
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
/**
|
7
|
+
* when set to `true` forces use of quine cheats
|
8
|
+
*
|
9
|
+
* when set to `false` forces quine cheats not to be used
|
10
|
+
*
|
11
|
+
* when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
|
12
|
+
*/
|
12
13
|
forceQuineCheats: boolean;
|
13
14
|
/** the comment inserted after the function signature */ autocomplete: string;
|
14
15
|
}>;
|
15
|
-
/**
|
16
|
-
|
16
|
+
/**
|
17
|
+
* @param file babel ast node representing a file containing transformed code
|
18
|
+
* @param options {@link MinifyOptions details}
|
19
|
+
*/
|
17
20
|
export declare function minify(file: File, { uniqueId, mangleNames, forceQuineCheats, autocomplete }?: MinifyOptions): Promise<string>;
|
18
21
|
export {};
|
package/processScript/minify.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import
|
2
|
-
import
|
1
|
+
import dsiertos6nj44cs8y2rcgun4 from "@babel/generator"
|
2
|
+
import jrpom318hon3bq0jzylo46gt from "@babel/traverse"
|
3
3
|
import t from "@babel/types"
|
4
4
|
import { assert } from "@samual/lib/assert"
|
5
5
|
import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
|
@@ -7,12 +7,12 @@ import { spliceString } from "@samual/lib/spliceString"
|
|
7
7
|
import { tokenizer, tokTypes } from "acorn"
|
8
8
|
import * as terser from "terser"
|
9
9
|
import { getReferencePathsToGlobal, includesIllegalString, replaceUnsafeStrings } from "./shared.js"
|
10
|
-
const
|
11
|
-
|
10
|
+
const generate = dsiertos6nj44cs8y2rcgun4.default,
|
11
|
+
traverse = jrpom318hon3bq0jzylo46gt.default,
|
12
12
|
minifyNumber = async number =>
|
13
13
|
/\$\((?<number>.+)\)/.exec((await terser.minify(`$(${number})`, { ecma: 2015 })).code).groups.number
|
14
14
|
async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQuineCheats, autocomplete } = {}) {
|
15
|
-
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/minify.ts:
|
15
|
+
assert(/^\w{11}$/.exec(uniqueId), "src/processScript/minify.ts:45:36")
|
16
16
|
let program
|
17
17
|
traverse(file, {
|
18
18
|
Program(path) {
|
@@ -52,7 +52,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
52
52
|
traverse(fileBeforeJSONValueReplacement, {
|
53
53
|
MemberExpression({ node: memberExpression }) {
|
54
54
|
if (!memberExpression.computed) {
|
55
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:
|
55
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:113:60")
|
56
56
|
if ("prototype" == memberExpression.property.name) {
|
57
57
|
memberExpression.computed = !0
|
58
58
|
memberExpression.property = t.identifier(`_${uniqueId}_PROTOTYPE_PROPERTY_`)
|
@@ -164,7 +164,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
164
164
|
},
|
165
165
|
MemberExpression({ node: memberExpression }) {
|
166
166
|
if (!memberExpression.computed) {
|
167
|
-
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:
|
167
|
+
assert("Identifier" == memberExpression.property.type, "src/processScript/minify.ts:248:62")
|
168
168
|
if (!(memberExpression.property.name.length < 3)) {
|
169
169
|
memberExpression.computed = !0
|
170
170
|
memberExpression.property = t.stringLiteral(memberExpression.property.name)
|
@@ -238,7 +238,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
238
238
|
})
|
239
239
|
await Promise.all(promises)
|
240
240
|
const functionDeclaration = file.program.body[0]
|
241
|
-
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:
|
241
|
+
assert("FunctionDeclaration" == functionDeclaration.type, "src/processScript/minify.ts:350:61")
|
242
242
|
if (jsonValues.length) {
|
243
243
|
hasComment = !0
|
244
244
|
if (1 == jsonValues.length)
|
@@ -358,7 +358,7 @@ async function minify(file, { uniqueId = "00000000000", mangleNames = !1, forceQ
|
|
358
358
|
)
|
359
359
|
}
|
360
360
|
if (1 == forceQuineCheats) return code
|
361
|
-
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:
|
361
|
+
assert(scriptBeforeJSONValueReplacement, "src/processScript/minify.ts:481:43")
|
362
362
|
return countHackmudCharacters(scriptBeforeJSONValueReplacement) <= countHackmudCharacters(code) + Number(hasComment)
|
363
363
|
? scriptBeforeJSONValueReplacement
|
364
364
|
: code
|
@@ -371,7 +371,7 @@ function parseObjectExpression(node, o) {
|
|
371
371
|
"Identifier" == property.key.type ||
|
372
372
|
"NumericLiteral" == property.key.type ||
|
373
373
|
"StringLiteral" == property.key.type,
|
374
|
-
"src/processScript/minify.ts:
|
374
|
+
"src/processScript/minify.ts:503:4"
|
375
375
|
)
|
376
376
|
if ("ArrayExpression" == property.value.type) {
|
377
377
|
const childArray = []
|
@@ -2,8 +2,10 @@ import type { LaxPartial } from "@samual/lib";
|
|
2
2
|
export type PreprocessOptions = LaxPartial<{
|
3
3
|
uniqueId: string;
|
4
4
|
}>;
|
5
|
-
/**
|
6
|
-
|
5
|
+
/**
|
6
|
+
* @param code source code for preprocessing
|
7
|
+
* @param options {@link PreprocessOptions details}
|
8
|
+
*/
|
7
9
|
export declare function preprocess(code: string, { uniqueId }?: PreprocessOptions): Promise<{
|
8
10
|
code: string;
|
9
11
|
}>;
|
@@ -1,26 +1,14 @@
|
|
1
|
-
import
|
1
|
+
import dsiertos6nj44cs8y2rcgun4 from "@babel/generator"
|
2
2
|
import { parse } from "@babel/parser"
|
3
|
-
import
|
3
|
+
import jrpom318hon3bq0jzylo46gt from "@babel/traverse"
|
4
4
|
import t from "@babel/types"
|
5
5
|
import { assert } from "@samual/lib/assert"
|
6
6
|
import { spliceString } from "@samual/lib/spliceString"
|
7
|
-
import { tokenizer, tokTypes } from "acorn"
|
8
7
|
import { resolve } from "import-meta-resolve"
|
9
|
-
const
|
10
|
-
|
11
|
-
SUBSCRIPT_PREFIXES = ["s", "fs", "4s", "hs", "3s", "ms", "2s", "ls", "1s", "ns", "0s"]
|
8
|
+
const generate = dsiertos6nj44cs8y2rcgun4.default,
|
9
|
+
traverse = jrpom318hon3bq0jzylo46gt.default
|
12
10
|
async function preprocess(code, { uniqueId = "00000000000" } = {}) {
|
13
|
-
assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts:
|
14
|
-
const tokensIterable = tokenizer(code, { ecmaVersion: "latest" })
|
15
|
-
for (const token of tokensIterable) {
|
16
|
-
assert("value" in token, "src/processScript/preprocess.ts:31:28")
|
17
|
-
if (token.type != tokTypes.privateId) continue
|
18
|
-
assert("string" == typeof token.value, "src/processScript/preprocess.ts:36:42")
|
19
|
-
if (!SUBSCRIPT_PREFIXES.includes(token.value)) continue
|
20
|
-
const nextToken = tokensIterable.getToken()
|
21
|
-
if (nextToken.type != tokTypes._in && nextToken.type != tokTypes.dot)
|
22
|
-
throw SyntaxError("Subscripts must be in the form of #fs.foo.bar")
|
23
|
-
}
|
11
|
+
assert(/^\w{11}$/.test(uniqueId), "src/processScript/preprocess.ts:20:36")
|
24
12
|
const sourceCode = code
|
25
13
|
let lengthBefore, file, program
|
26
14
|
do {
|
@@ -59,11 +47,11 @@ async function preprocess(code, { uniqueId = "00000000000" } = {}) {
|
|
59
47
|
})
|
60
48
|
break
|
61
49
|
} catch (error_) {
|
62
|
-
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:
|
50
|
+
assert(error_ instanceof SyntaxError, "src/processScript/preprocess.ts:64:42")
|
63
51
|
error = error_
|
64
52
|
}
|
65
53
|
if ("BABEL_PARSER_SYNTAX_ERROR" != error.code || "PrivateInExpectedIn" != error.reasonCode) {
|
66
|
-
console.
|
54
|
+
console.error(/.+/.exec(code.slice(error.pos))?.[0])
|
67
55
|
throw error
|
68
56
|
}
|
69
57
|
const codeSlice = code.slice(error.pos)
|
@@ -7,12 +7,14 @@ export type TransformOptions = LaxPartial<{
|
|
7
7
|
}> & {
|
8
8
|
scriptName: string | true;
|
9
9
|
};
|
10
|
-
/**
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
/**
|
11
|
+
* transform a given babel `File` to be hackmud compatible
|
12
|
+
*
|
13
|
+
* (returned File will need `postprocess()`ing)
|
14
|
+
* @param file babel ast node representing a file containing preprocessed code
|
15
|
+
* @param sourceCode the original untouched source code
|
16
|
+
* @param options {@link TransformOptions details}
|
17
|
+
*/
|
16
18
|
export declare function transform(file: File, sourceCode: string, { uniqueId, scriptUser, scriptName, seclevel }: TransformOptions): {
|
17
19
|
file: File;
|
18
20
|
seclevel: number;
|