hackmud-script-manager-ng 0.0.0-stage → 0.26.5

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.
Files changed (44) hide show
  1. package/.envrc +1 -0
  2. package/.github/FUNDING.yml +14 -0
  3. package/.github/workflows/publish.yml +27 -0
  4. package/.github/workflows/test.yml +18 -0
  5. package/.vscode/settings.json +55 -0
  6. package/CONTRIBUTING.md +68 -0
  7. package/LICENSE +21 -0
  8. package/README.md +86 -2
  9. package/env.d.ts +1305 -0
  10. package/eslint.config.js +81 -0
  11. package/game-scripts-tests/array-rest-works.ts +6 -0
  12. package/game-scripts-tests/this_array_in_object.ts +16 -0
  13. package/game-scripts-tests/this_function_array.ts +9 -0
  14. package/game-scripts-tests/this_in_default_argument.ts +35 -0
  15. package/game-scripts-tests/this_in_lambda_in_object.ts +26 -0
  16. package/package.json +113 -3
  17. package/pnpm-workspace.yaml +2 -0
  18. package/rollup.config.js +69 -0
  19. package/scripts/dev.sh +3 -0
  20. package/scripts/emit-declarations.sh +3 -0
  21. package/scripts/emit-package-json.js +9 -0
  22. package/scripts/lint.sh +5 -0
  23. package/scripts/package.sh +7 -0
  24. package/scripts/update.sh +4 -0
  25. package/scripts/version-dev.js +14 -0
  26. package/src/bin/hsm.ts +754 -0
  27. package/src/constants.ts +2 -0
  28. package/src/env.d.ts +13 -0
  29. package/src/generateTypeDeclaration.ts +119 -0
  30. package/src/index.ts +13 -0
  31. package/src/processScript/__snapshots__/index.ts.snap +8 -0
  32. package/src/processScript/index.ts +474 -0
  33. package/src/processScript/minify.ts +594 -0
  34. package/src/processScript/postprocess.ts +19 -0
  35. package/src/processScript/preprocess.ts +130 -0
  36. package/src/processScript/shared.ts +33 -0
  37. package/src/processScript/transform.ts +978 -0
  38. package/src/pull.ts +20 -0
  39. package/src/push.ts +200 -0
  40. package/src/syncMacros.ts +53 -0
  41. package/src/tsconfig.json +14 -0
  42. package/src/watch.ts +258 -0
  43. package/tsconfig.json +23 -0
  44. package/vitest.config.ts +19 -0
@@ -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,6 @@
1
+ export default ({ expect }: typeof import('vitest')) => {
2
+ const array = [ 1, 2, 3, 4, 5 ]
3
+ const [ x, ...rest ] = array;
4
+ expect(x).toBe(1)
5
+ expect(rest).toStrictEqual([ 2, 3, 4, 5 ])
6
+ }
@@ -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,9 @@
1
+ export default ({ expect }: typeof import('vitest')) => {
2
+ const array = [
3
+ function (this: any) {
4
+ return this
5
+ }
6
+ ]
7
+
8
+ expect(array[0]!()).toBe(array)
9
+ }
@@ -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,116 @@
1
1
  {
2
2
  "name": "hackmud-script-manager-ng",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "type": "module",
4
+ "version": "0.26.5",
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://git.gay/voxxus/hackmud-script-manager",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://git.gay/voxxus/hackmud-script-manager"
21
+ },
22
+ "bugs": "https://git.gay/voxxus/hackmud-script-manager/issues",
23
+ "keywords": [
24
+ "api",
25
+ "command-line",
26
+ "script",
27
+ "manager",
28
+ "minification",
29
+ "minifier",
30
+ "hackmd",
31
+ "hackmud",
32
+ "javascript",
33
+ "typescript",
34
+ "typescript-support",
35
+ "golf",
36
+ "golfer"
37
+ ],
38
+ "exports": {
39
+ ".": "./index.js",
40
+ "./*": "./*.js",
41
+ "./*.js": "./*.js"
42
+ },
43
+ "main": "index.js",
44
+ "bin": {
45
+ "hsm": "bin/hsm.js"
46
+ },
47
+ "engines": {
48
+ "node": "^18 || >=20",
49
+ "pnpm": "^9 || ^10"
50
+ },
51
+ "peerDependencies": {
52
+ "typescript": "^5.4.5"
53
+ },
54
+ "dependencies": {
55
+ "@babel/generator": "^7.28.5",
56
+ "@babel/parser": "^7.28.5",
57
+ "@babel/plugin-proposal-decorators": "^7.28.0",
58
+ "@babel/plugin-proposal-destructuring-private": "^7.28.5",
59
+ "@babel/plugin-proposal-do-expressions": "^7.28.3",
60
+ "@babel/plugin-proposal-function-bind": "^7.27.1",
61
+ "@babel/plugin-proposal-function-sent": "^7.27.1",
62
+ "@babel/plugin-proposal-partial-application": "^7.27.1",
63
+ "@babel/plugin-proposal-pipeline-operator": "^7.27.1",
64
+ "@babel/plugin-proposal-record-and-tuple": "^7.27.1",
65
+ "@babel/plugin-proposal-throw-expressions": "^7.27.1",
66
+ "@babel/plugin-transform-class-properties": "^7.27.1",
67
+ "@babel/plugin-transform-class-static-block": "^7.28.3",
68
+ "@babel/plugin-transform-explicit-resource-management": "^7.28.0",
69
+ "@babel/plugin-transform-exponentiation-operator": "^7.28.5",
70
+ "@babel/plugin-transform-json-strings": "^7.27.1",
71
+ "@babel/plugin-transform-logical-assignment-operators": "^7.28.5",
72
+ "@babel/plugin-transform-nullish-coalescing-operator": "^7.27.1",
73
+ "@babel/plugin-transform-numeric-separator": "^7.27.1",
74
+ "@babel/plugin-transform-object-rest-spread": "^7.28.4",
75
+ "@babel/plugin-transform-optional-catch-binding": "^7.27.1",
76
+ "@babel/plugin-transform-optional-chaining": "^7.28.5",
77
+ "@babel/plugin-transform-private-property-in-object": "^7.27.1",
78
+ "@babel/plugin-transform-typescript": "^7.28.5",
79
+ "@babel/plugin-transform-unicode-sets-regex": "^7.27.1",
80
+ "@babel/traverse": "^7.28.5",
81
+ "@babel/types": "^7.28.5",
82
+ "@bloomberg/record-tuple-polyfill": "^0.0.4",
83
+ "@rollup/plugin-alias": "^5.1.1",
84
+ "@rollup/plugin-babel": "^6.0.4",
85
+ "@rollup/plugin-commonjs": "^28.0.1",
86
+ "@rollup/plugin-json": "^6.1.0",
87
+ "@rollup/plugin-node-resolve": "^16.0.3",
88
+ "@samual/lib": "^0.13.0",
89
+ "acorn": "^8.15.0",
90
+ "chalk": "^5.6.2",
91
+ "chokidar": "^4.0.3",
92
+ "import-meta-resolve": "^4.2.0",
93
+ "prettier": "^3.6.2",
94
+ "proxy-polyfill": "^0.3.2",
95
+ "rollup": "^4.53.1",
96
+ "terser": "^5.44.1"
97
+ },
98
+ "devDependencies": {
99
+ "@antfu/eslint-config": "^6.2.0",
100
+ "@babel/plugin-syntax-typescript": "^7.27.1",
101
+ "@paralleldrive/cuid2": "^2.2.2",
102
+ "@samual/rollup-config": "0.1.3-858c2de",
103
+ "@total-typescript/ts-reset": "^0.6.1",
104
+ "@types/babel__core": "^7.20.5",
105
+ "@types/babel__generator": "^7.27.0",
106
+ "@types/babel__traverse": "^7.28.0",
107
+ "@types/node": "~24.10.0",
108
+ "@types/semver": "^7.7.1",
109
+ "babel-plugin-here": "^1.0.2",
110
+ "eslint": "^9.39.1",
111
+ "eslint-plugin-format": "^1.0.2",
112
+ "semver": "^7.7.3",
113
+ "typescript": "5.7.3",
114
+ "vitest": "^4.0.8"
115
+ }
6
116
  }
@@ -0,0 +1,2 @@
1
+ onlyBuiltDependencies:
2
+ - esbuild
@@ -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,3 @@
1
+ #!/bin/sh
2
+ set -ex
3
+ ./rollup.config.js --watch
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ set -ex
3
+ npx tsc --project src --declaration --emitDeclarationOnly --noEmit false --outDir dist
@@ -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()
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ set -ex
3
+ npx tsc
4
+ npx tsc --project src
5
+ npx eslint
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ set -ex
3
+ rm -rf dist
4
+ ./rollup.config.js
5
+ scripts/emit-declarations.sh
6
+ scripts/emit-package-json.js
7
+ cp LICENSE README.md env.d.ts dist
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ set -ex
3
+ pnpm update --latest !@types/node
4
+ pnpm update @types/node
@@ -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()