hackmud-script-manager-ng 0.0.0-stage → 0.26.4
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/.envrc +1 -0
- package/.github/FUNDING.yml +14 -0
- package/.github/workflows/publish.yml +27 -0
- package/.github/workflows/test.yml +18 -0
- package/.vscode/settings.json +55 -0
- package/CONTRIBUTING.md +68 -0
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/env.d.ts +1305 -0
- package/eslint.config.js +81 -0
- package/game-scripts-tests/array-rest-works.ts +6 -0
- package/game-scripts-tests/this_array_in_object.ts +16 -0
- package/game-scripts-tests/this_function_array.ts +9 -0
- package/game-scripts-tests/this_in_default_argument.ts +35 -0
- package/game-scripts-tests/this_in_lambda_in_object.ts +26 -0
- package/package.json +110 -3
- package/pnpm-workspace.yaml +2 -0
- package/rollup.config.js +69 -0
- package/scripts/dev.sh +3 -0
- package/scripts/emit-declarations.sh +3 -0
- package/scripts/emit-package-json.js +9 -0
- package/scripts/lint.sh +5 -0
- package/scripts/package.sh +7 -0
- package/scripts/update.sh +4 -0
- package/scripts/version-dev.js +14 -0
- package/src/bin/hsm.ts +754 -0
- package/src/constants.ts +2 -0
- package/src/env.d.ts +13 -0
- package/src/generateTypeDeclaration.ts +119 -0
- package/src/index.ts +13 -0
- package/src/processScript/__snapshots__/index.ts.snap +8 -0
- package/src/processScript/index.ts +474 -0
- package/src/processScript/minify.ts +594 -0
- package/src/processScript/postprocess.ts +19 -0
- package/src/processScript/preprocess.ts +130 -0
- package/src/processScript/shared.ts +33 -0
- package/src/processScript/transform.ts +978 -0
- package/src/pull.ts +20 -0
- package/src/push.ts +200 -0
- package/src/syncMacros.ts +53 -0
- package/src/tsconfig.json +14 -0
- package/src/watch.ts +258 -0
- package/tsconfig.json +23 -0
- package/vitest.config.ts +19 -0
package/eslint.config.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import antfu from "@antfu/eslint-config"
|
|
2
|
+
|
|
3
|
+
export default antfu(
|
|
4
|
+
{
|
|
5
|
+
formatters: true,
|
|
6
|
+
stylistic: { indent: "tab", quotes: "backtick" },
|
|
7
|
+
rules: {
|
|
8
|
+
"style/member-delimiter-style": "off",
|
|
9
|
+
"style/comma-dangle": [ "error", "never" ],
|
|
10
|
+
"style/array-bracket-spacing": [ "error", "always" ],
|
|
11
|
+
"unicorn/prefer-node-protocol": "off",
|
|
12
|
+
"unicorn/throw-new-error": "off",
|
|
13
|
+
"jsonc/array-bracket-spacing": [ "error", "always" ],
|
|
14
|
+
"unicorn/new-for-builtins": "off",
|
|
15
|
+
eqeqeq: "off",
|
|
16
|
+
"style/quote-props": [ "error", "as-needed" ],
|
|
17
|
+
"style/brace-style": [ "error", "1tbs" ],
|
|
18
|
+
"antfu/curly": "off",
|
|
19
|
+
"style/operator-linebreak": [ "error", "after", { overrides: { ":": "before" } } ],
|
|
20
|
+
"style/arrow-parens": [ "error", "as-needed" ],
|
|
21
|
+
"style/new-parens": [ "error", "never" ],
|
|
22
|
+
"antfu/consistent-list-newline": "off",
|
|
23
|
+
"antfu/top-level-function": "off",
|
|
24
|
+
"no-cond-assign": [ "error", "except-parens" ],
|
|
25
|
+
"style/multiline-ternary": "off",
|
|
26
|
+
"antfu/no-top-level-await": "off",
|
|
27
|
+
"node/prefer-global/process": [ "error", "always" ],
|
|
28
|
+
"ts/consistent-type-definitions": [ "error", "type" ],
|
|
29
|
+
"unicorn/prefer-number-properties": "off",
|
|
30
|
+
"style/indent": [ "error", "tab", { SwitchCase: 1, ignoredNodes: [ "ConditionalExpression" ] } ],
|
|
31
|
+
"style/indent-binary-ops": "off",
|
|
32
|
+
"yaml/flow-mapping-curly-spacing": [ "error", "always" ],
|
|
33
|
+
"yaml/flow-sequence-bracket-spacing": [ "error", "always" ],
|
|
34
|
+
"yaml/quotes": [ "error", { prefer: "double" } ],
|
|
35
|
+
"yaml/indent": [ "error", 2, { indentBlockSequences: false } ],
|
|
36
|
+
"style/padding-line-between-statements": [
|
|
37
|
+
"error",
|
|
38
|
+
{ blankLine: "always", prev: "multiline-const", next: "*" },
|
|
39
|
+
{ blankLine: "always", prev: "*", next: "multiline-const" },
|
|
40
|
+
{ blankLine: "always", prev: "multiline-export", next: "*" },
|
|
41
|
+
{ blankLine: "always", prev: "*", next: "multiline-export" },
|
|
42
|
+
{ blankLine: "always", prev: "multiline-expression", next: "*" },
|
|
43
|
+
{ blankLine: "always", prev: "*", next: "multiline-expression" },
|
|
44
|
+
{ blankLine: "always", prev: "multiline-let", next: "*" },
|
|
45
|
+
{ blankLine: "always", prev: "*", next: "multiline-let" },
|
|
46
|
+
{ blankLine: "always", prev: "block-like", next: "*" },
|
|
47
|
+
{ blankLine: "always", prev: "*", next: "block-like" },
|
|
48
|
+
{ blankLine: "always", prev: "do", next: "*" },
|
|
49
|
+
{ blankLine: "always", prev: "*", next: "do" },
|
|
50
|
+
{ blankLine: "always", prev: "export", next: "*" },
|
|
51
|
+
{ blankLine: "always", prev: "*", next: "export" },
|
|
52
|
+
{ blankLine: "always", prev: "for", next: "*" },
|
|
53
|
+
{ blankLine: "always", prev: "*", next: "for" },
|
|
54
|
+
{ blankLine: "always", prev: "function", next: "*" },
|
|
55
|
+
{ blankLine: "always", prev: "*", next: "function" },
|
|
56
|
+
{ blankLine: "always", prev: "if", next: "*" },
|
|
57
|
+
{ blankLine: "always", prev: "*", next: "if" },
|
|
58
|
+
{ blankLine: "always", prev: "let", next: "*" },
|
|
59
|
+
{ blankLine: "always", prev: "*", next: "let" },
|
|
60
|
+
{ blankLine: "always", prev: "const", next: "*" },
|
|
61
|
+
{ blankLine: "always", prev: "*", next: "const" },
|
|
62
|
+
{ blankLine: "always", prev: "import", next: "*" },
|
|
63
|
+
{ blankLine: "always", prev: "*", next: "import" },
|
|
64
|
+
{ blankLine: "never", prev: "singleline-const", next: "singleline-const" },
|
|
65
|
+
{ blankLine: "never", prev: "singleline-let", next: "singleline-let" },
|
|
66
|
+
{ blankLine: "never", prev: "singleline-let", next: "singleline-const" },
|
|
67
|
+
{ blankLine: "never", prev: "singleline-const", next: "singleline-let" },
|
|
68
|
+
{ blankLine: "never", prev: "singleline-export", next: "singleline-export" },
|
|
69
|
+
{ blankLine: "never", prev: "import", next: "import" },
|
|
70
|
+
{ blankLine: "any", prev: "case", next: "case" }
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
languageOptions: { parserOptions: { ecmaVersion: "latest" } }
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
files: [ "**/*.js" ],
|
|
77
|
+
rules: {
|
|
78
|
+
"style/quotes": [ "error", "double" ]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default ({ expect }: typeof import('vitest')) => {
|
|
2
|
+
const test = {
|
|
3
|
+
0: `test[0]`,
|
|
4
|
+
foo: [
|
|
5
|
+
function () {
|
|
6
|
+
return this[0]
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
bar() {
|
|
10
|
+
return this
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
expect(test.foo[0]!()).toBe(test.foo[0])
|
|
15
|
+
expect(test.bar()).toBe(test)
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export default ({ expect }: typeof import('vitest')) => {
|
|
2
|
+
class Foo {
|
|
3
|
+
declare foo: number
|
|
4
|
+
|
|
5
|
+
constructor() {
|
|
6
|
+
this.foo = 1
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
bar() {
|
|
10
|
+
return 2
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
baz(a = this.foo, b = this.bar()) {
|
|
14
|
+
return a + b
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const obj = {
|
|
19
|
+
foo: 1,
|
|
20
|
+
bar() {
|
|
21
|
+
return 2
|
|
22
|
+
},
|
|
23
|
+
baz(a = this.foo, b = this.bar()) {
|
|
24
|
+
return a + b
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const foo = (new Foo)
|
|
29
|
+
|
|
30
|
+
expect(foo.baz(3, 4)).toBe(7) // Is this the real life?
|
|
31
|
+
expect(foo.baz()).toBe(3) // Is this just fantasy?
|
|
32
|
+
|
|
33
|
+
expect(obj.baz(3, 4)).toBe(7) // Caught in a landslide
|
|
34
|
+
expect(obj.baz()).toBe(3) // No escape from reality
|
|
35
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Since this is the thing being tested, we need to disable the ESLint rule instead.
|
|
2
|
+
/* eslint-disable object-shorthand */
|
|
3
|
+
|
|
4
|
+
export default ({ expect }: typeof import('vitest')) => {
|
|
5
|
+
const myObject = {
|
|
6
|
+
a: 0,
|
|
7
|
+
b: function () {
|
|
8
|
+
this.a++
|
|
9
|
+
return this.a
|
|
10
|
+
},
|
|
11
|
+
c: function (value: number = this.a) {
|
|
12
|
+
this.a = value + 1
|
|
13
|
+
},
|
|
14
|
+
d: function ({ value = this.a }: { value?: number }) {
|
|
15
|
+
this.a = value + 1
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
expect(myObject.a).toBe(0)
|
|
20
|
+
myObject.b()
|
|
21
|
+
expect(myObject.a).toBe(1)
|
|
22
|
+
myObject.c()
|
|
23
|
+
expect(myObject.a).toBe(2)
|
|
24
|
+
myObject.d({})
|
|
25
|
+
expect(myObject.a).toBe(3)
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,113 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hackmud-script-manager-ng",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.26.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
|
+
"Edgar (https://edgl.dev)",
|
|
13
|
+
"Fayti1703",
|
|
14
|
+
"voxxus"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"homepage": "https://github.com/edg-l/hackmud-script-manager#readme",
|
|
18
|
+
"repository": "github:edg-l/hackmud-script-manager",
|
|
19
|
+
"bugs": "https://github.com/edg-l/hackmud-script-manager/issues",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"api",
|
|
22
|
+
"command-line",
|
|
23
|
+
"script",
|
|
24
|
+
"manager",
|
|
25
|
+
"minification",
|
|
26
|
+
"minifier",
|
|
27
|
+
"hackmd",
|
|
28
|
+
"hackmud",
|
|
29
|
+
"javascript",
|
|
30
|
+
"typescript",
|
|
31
|
+
"typescript-support",
|
|
32
|
+
"golf",
|
|
33
|
+
"golfer"
|
|
34
|
+
],
|
|
35
|
+
"exports": {
|
|
36
|
+
".": "./index.js",
|
|
37
|
+
"./*": "./*.js",
|
|
38
|
+
"./*.js": "./*.js"
|
|
39
|
+
},
|
|
40
|
+
"main": "index.js",
|
|
41
|
+
"bin": {
|
|
42
|
+
"hsm": "bin/hsm.js"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": "^18 || >=20",
|
|
46
|
+
"pnpm": "^9 || ^10"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"typescript": "^5.4.5"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@babel/generator": "^7.28.5",
|
|
53
|
+
"@babel/parser": "^7.28.5",
|
|
54
|
+
"@babel/plugin-proposal-decorators": "^7.28.0",
|
|
55
|
+
"@babel/plugin-proposal-destructuring-private": "^7.28.5",
|
|
56
|
+
"@babel/plugin-proposal-do-expressions": "^7.28.3",
|
|
57
|
+
"@babel/plugin-proposal-function-bind": "^7.27.1",
|
|
58
|
+
"@babel/plugin-proposal-function-sent": "^7.27.1",
|
|
59
|
+
"@babel/plugin-proposal-partial-application": "^7.27.1",
|
|
60
|
+
"@babel/plugin-proposal-pipeline-operator": "^7.27.1",
|
|
61
|
+
"@babel/plugin-proposal-record-and-tuple": "^7.27.1",
|
|
62
|
+
"@babel/plugin-proposal-throw-expressions": "^7.27.1",
|
|
63
|
+
"@babel/plugin-transform-class-properties": "^7.27.1",
|
|
64
|
+
"@babel/plugin-transform-class-static-block": "^7.28.3",
|
|
65
|
+
"@babel/plugin-transform-explicit-resource-management": "^7.28.0",
|
|
66
|
+
"@babel/plugin-transform-exponentiation-operator": "^7.28.5",
|
|
67
|
+
"@babel/plugin-transform-json-strings": "^7.27.1",
|
|
68
|
+
"@babel/plugin-transform-logical-assignment-operators": "^7.28.5",
|
|
69
|
+
"@babel/plugin-transform-nullish-coalescing-operator": "^7.27.1",
|
|
70
|
+
"@babel/plugin-transform-numeric-separator": "^7.27.1",
|
|
71
|
+
"@babel/plugin-transform-object-rest-spread": "^7.28.4",
|
|
72
|
+
"@babel/plugin-transform-optional-catch-binding": "^7.27.1",
|
|
73
|
+
"@babel/plugin-transform-optional-chaining": "^7.28.5",
|
|
74
|
+
"@babel/plugin-transform-private-property-in-object": "^7.27.1",
|
|
75
|
+
"@babel/plugin-transform-typescript": "^7.28.5",
|
|
76
|
+
"@babel/plugin-transform-unicode-sets-regex": "^7.27.1",
|
|
77
|
+
"@babel/traverse": "^7.28.5",
|
|
78
|
+
"@babel/types": "^7.28.5",
|
|
79
|
+
"@bloomberg/record-tuple-polyfill": "^0.0.4",
|
|
80
|
+
"@rollup/plugin-alias": "^5.1.1",
|
|
81
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
82
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
|
83
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
84
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
85
|
+
"@samual/lib": "^0.13.0",
|
|
86
|
+
"acorn": "^8.15.0",
|
|
87
|
+
"chalk": "^5.6.2",
|
|
88
|
+
"chokidar": "^4.0.3",
|
|
89
|
+
"import-meta-resolve": "^4.2.0",
|
|
90
|
+
"prettier": "^3.6.2",
|
|
91
|
+
"proxy-polyfill": "^0.3.2",
|
|
92
|
+
"rollup": "^4.53.1",
|
|
93
|
+
"terser": "^5.44.1"
|
|
94
|
+
},
|
|
95
|
+
"devDependencies": {
|
|
96
|
+
"@antfu/eslint-config": "^6.2.0",
|
|
97
|
+
"@babel/plugin-syntax-typescript": "^7.27.1",
|
|
98
|
+
"@paralleldrive/cuid2": "^2.2.2",
|
|
99
|
+
"@samual/rollup-config": "0.1.3-858c2de",
|
|
100
|
+
"@total-typescript/ts-reset": "^0.6.1",
|
|
101
|
+
"@types/babel__core": "^7.20.5",
|
|
102
|
+
"@types/babel__generator": "^7.27.0",
|
|
103
|
+
"@types/babel__traverse": "^7.28.0",
|
|
104
|
+
"@types/node": "~24.10.0",
|
|
105
|
+
"@types/semver": "^7.7.1",
|
|
106
|
+
"babel-plugin-here": "^1.0.2",
|
|
107
|
+
"eslint": "^9.39.1",
|
|
108
|
+
"eslint-plugin-format": "^1.0.2",
|
|
109
|
+
"semver": "^7.7.3",
|
|
110
|
+
"typescript": "5.7.3",
|
|
111
|
+
"vitest": "^4.0.8"
|
|
112
|
+
}
|
|
6
113
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!node_modules/.bin/rollup --config
|
|
2
|
+
import t from "@babel/types"
|
|
3
|
+
import { createId as cuid2 } from "@paralleldrive/cuid2"
|
|
4
|
+
import { assert } from "@samual/lib/assert"
|
|
5
|
+
import { rollupConfig } from "@samual/rollup-config"
|
|
6
|
+
|
|
7
|
+
const isModuleBroken = (/** @type {string} */ name) =>
|
|
8
|
+
name == "@babel/traverse" || name == "@babel/generator" || name.startsWith("@babel/plugin-")
|
|
9
|
+
|
|
10
|
+
export default rollupConfig({
|
|
11
|
+
babelOptions: {
|
|
12
|
+
plugins: [
|
|
13
|
+
{
|
|
14
|
+
name: "babel-has-broken-exports",
|
|
15
|
+
visitor: {
|
|
16
|
+
ImportDefaultSpecifier(path) {
|
|
17
|
+
const importDeclarationPath = path.parentPath
|
|
18
|
+
|
|
19
|
+
assert(importDeclarationPath.isImportDeclaration())
|
|
20
|
+
|
|
21
|
+
if (!isModuleBroken(importDeclarationPath.node.source.value))
|
|
22
|
+
return
|
|
23
|
+
|
|
24
|
+
const specifierName = path.node.local.name
|
|
25
|
+
const specifierNewName = cuid2()
|
|
26
|
+
|
|
27
|
+
path.node.local.name = specifierNewName
|
|
28
|
+
|
|
29
|
+
importDeclarationPath.insertAfter(t.variableDeclaration("const", [
|
|
30
|
+
t.variableDeclarator(
|
|
31
|
+
t.identifier(specifierName),
|
|
32
|
+
t.memberExpression(t.identifier(specifierNewName), t.identifier("default"))
|
|
33
|
+
)
|
|
34
|
+
]))
|
|
35
|
+
},
|
|
36
|
+
CallExpression(path) {
|
|
37
|
+
if (path.node.callee.type != "Import" || ((path.node.arguments[0]?.type != "StringLiteral" ||
|
|
38
|
+
!isModuleBroken(path.node.arguments[0].value)
|
|
39
|
+
) && (path.node.arguments[0]?.type != "TemplateLiteral" ||
|
|
40
|
+
!path.node.arguments[0].quasis[0] ||
|
|
41
|
+
!isModuleBroken(path.node.arguments[0].quasis[0].value.raw)
|
|
42
|
+
)))
|
|
43
|
+
return
|
|
44
|
+
|
|
45
|
+
path.replaceWith(t.callExpression(
|
|
46
|
+
t.memberExpression(
|
|
47
|
+
path.node,
|
|
48
|
+
t.identifier("then")
|
|
49
|
+
),
|
|
50
|
+
[
|
|
51
|
+
t.arrowFunctionExpression(
|
|
52
|
+
[
|
|
53
|
+
t.identifier("module")
|
|
54
|
+
],
|
|
55
|
+
t.memberExpression(
|
|
56
|
+
t.identifier("module"),
|
|
57
|
+
t.identifier("default")
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
]
|
|
61
|
+
))
|
|
62
|
+
|
|
63
|
+
path.skip()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
})
|
package/scripts/dev.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdirSync as makeDirectorySync, writeFileSync } from "fs"
|
|
3
|
+
import packageJson_ from "../package.json" with { type: "json" }
|
|
4
|
+
|
|
5
|
+
const { private: _, devDependencies, engines: { pnpm, ...engines }, ...packageJson } = packageJson_
|
|
6
|
+
|
|
7
|
+
makeDirectorySync("dist", { recursive: true })
|
|
8
|
+
writeFileSync("dist/package.json", JSON.stringify({ ...packageJson, engines }, undefined, "\t"))
|
|
9
|
+
process.exit()
|
package/scripts/lint.sh
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "child_process"
|
|
3
|
+
import * as semver from "semver"
|
|
4
|
+
import packageConfig from "../package.json" with { type: "json" }
|
|
5
|
+
|
|
6
|
+
const hash = spawnSync("git", [ "rev-parse", "--short", "HEAD" ], { encoding: "utf8" }).stdout.trim()
|
|
7
|
+
|
|
8
|
+
spawnSync(
|
|
9
|
+
"pnpm",
|
|
10
|
+
[ "version", `${semver.inc(/** @type {any} */ (packageConfig).version || "0.0.0", "patch")}-${hash}` ],
|
|
11
|
+
{ stdio: "inherit" }
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
process.exit()
|