hackmud-script-manager-ng 0.26.4 → 0.26.6

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 (69) hide show
  1. package/bin/hsm.d.ts +2 -0
  2. package/bin/hsm.js +493 -0
  3. package/constants.d.ts +2 -0
  4. package/constants.js +3 -0
  5. package/generateTypeDeclaration.d.ts +1 -0
  6. package/generateTypeDeclaration.js +70 -0
  7. package/index.d.ts +16 -0
  8. package/index.js +52 -0
  9. package/package.json +9 -25
  10. package/processScript/index.d.ts +34 -0
  11. package/processScript/index.js +362 -0
  12. package/processScript/minify.d.ts +20 -0
  13. package/processScript/minify.js +431 -0
  14. package/processScript/postprocess.d.ts +1 -0
  15. package/processScript/postprocess.js +21 -0
  16. package/processScript/preprocess.d.ts +11 -0
  17. package/processScript/preprocess.js +107 -0
  18. package/processScript/shared.d.ts +5 -0
  19. package/processScript/shared.js +32 -0
  20. package/processScript/transform.d.ts +24 -0
  21. package/processScript/transform.js +803 -0
  22. package/pull.d.ts +7 -0
  23. package/pull.js +11 -0
  24. package/push.d.ts +42 -0
  25. package/push.js +164 -0
  26. package/syncMacros.d.ts +4 -0
  27. package/syncMacros.js +42 -0
  28. package/watch.d.ts +19 -0
  29. package/watch.js +220 -0
  30. package/.envrc +0 -1
  31. package/.github/FUNDING.yml +0 -14
  32. package/.github/workflows/publish.yml +0 -27
  33. package/.github/workflows/test.yml +0 -18
  34. package/.vscode/settings.json +0 -55
  35. package/CONTRIBUTING.md +0 -68
  36. package/eslint.config.js +0 -81
  37. package/game-scripts-tests/array-rest-works.ts +0 -6
  38. package/game-scripts-tests/this_array_in_object.ts +0 -16
  39. package/game-scripts-tests/this_function_array.ts +0 -9
  40. package/game-scripts-tests/this_in_default_argument.ts +0 -35
  41. package/game-scripts-tests/this_in_lambda_in_object.ts +0 -26
  42. package/pnpm-workspace.yaml +0 -2
  43. package/rollup.config.js +0 -69
  44. package/scripts/dev.sh +0 -3
  45. package/scripts/emit-declarations.sh +0 -3
  46. package/scripts/emit-package-json.js +0 -9
  47. package/scripts/lint.sh +0 -5
  48. package/scripts/package.sh +0 -7
  49. package/scripts/update.sh +0 -4
  50. package/scripts/version-dev.js +0 -14
  51. package/src/bin/hsm.ts +0 -754
  52. package/src/constants.ts +0 -2
  53. package/src/env.d.ts +0 -13
  54. package/src/generateTypeDeclaration.ts +0 -119
  55. package/src/index.ts +0 -13
  56. package/src/processScript/__snapshots__/index.ts.snap +0 -8
  57. package/src/processScript/index.ts +0 -474
  58. package/src/processScript/minify.ts +0 -594
  59. package/src/processScript/postprocess.ts +0 -19
  60. package/src/processScript/preprocess.ts +0 -130
  61. package/src/processScript/shared.ts +0 -33
  62. package/src/processScript/transform.ts +0 -978
  63. package/src/pull.ts +0 -20
  64. package/src/push.ts +0 -200
  65. package/src/syncMacros.ts +0 -53
  66. package/src/tsconfig.json +0 -14
  67. package/src/watch.ts +0 -258
  68. package/tsconfig.json +0 -23
  69. package/vitest.config.ts +0 -19
package/pull.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copies script from hackmud to local source folder.
3
+ * @param sourceFolderPath path to folder containing source files
4
+ * @param hackmudPath path to hackmud directory
5
+ * @param script to pull in `user.name` format
6
+ */
7
+ export declare function pull(sourceFolderPath: string, hackmudPath: string, script: string): Promise<void>;
package/pull.js ADDED
@@ -0,0 +1,11 @@
1
+ import { resolve } from "path"
2
+ import { copyFilePersistent } from "@samual/lib/copyFilePersistent"
3
+ async function pull(sourceFolderPath, hackmudPath, script) {
4
+ const [user, name] = script.split(".")
5
+ if (!user || !name) throw Error('`script` argument must be in "user.name" format')
6
+ await copyFilePersistent(
7
+ resolve(hackmudPath, user, "scripts", name + ".js"),
8
+ resolve(sourceFolderPath, user, name + ".js")
9
+ )
10
+ }
11
+ export { pull }
package/push.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type { LaxPartial } from "@samual/lib";
2
+ import type { Info } from ".";
3
+ export type PushOptions = LaxPartial<{
4
+ /** whether to do the minify step (defaults to `true`) */ minify: boolean;
5
+ /** whether to mangle function and class names (defaults to `false`) */ mangleNames: boolean;
6
+ /**
7
+ * array of scripts in the format `foo.bar`
8
+ *
9
+ * also accepts wild card (`*`) e.g. `*.bar` or `foo.*`
10
+ *
11
+ * pushes everything by default (`*.*`)
12
+ */
13
+ scripts: string[];
14
+ /** callback called on script push */ onPush: (info: Info) => void;
15
+ /**
16
+ * when set to `true` forces use of quine cheats
17
+ *
18
+ * when set to `false` forces quine cheats not to be used
19
+ *
20
+ * when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
21
+ */
22
+ forceQuineCheats: boolean;
23
+ rootFolderPath: string;
24
+ }>;
25
+ export declare class MissingSourceFolderError extends Error {
26
+ }
27
+ export declare class MissingHackmudFolderError extends Error {
28
+ }
29
+ export declare class NoUsersError extends Error {
30
+ }
31
+ export declare class NoScriptsError extends Error {
32
+ }
33
+ /**
34
+ * Push scripts from a source directory to the hackmud directory.
35
+ *
36
+ * Pushes files directly in the source folder to all users
37
+ * @param sourcePath directory containing source code
38
+ * @param hackmudPath directory created by hackmud containing user data including scripts
39
+ * @param options {@link PushOptions details}
40
+ * @returns array of info on pushed scripts
41
+ */
42
+ export declare function push(sourcePath: string, hackmudPath: string, { scripts, onPush, minify, mangleNames, forceQuineCheats, rootFolderPath }?: PushOptions): Promise<MissingSourceFolderError | MissingHackmudFolderError | NoUsersError | NoScriptsError | Info[]>;
package/push.js ADDED
@@ -0,0 +1,164 @@
1
+ import { readFile } from "fs/promises"
2
+ import { basename, resolve } from "path"
3
+ import { ensure, assert } from "@samual/lib/assert"
4
+ import { AutoMap } from "@samual/lib/AutoMap"
5
+ import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
6
+ import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
7
+ import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
8
+ import { processScript } from "./processScript/index.js"
9
+ import "@babel/generator"
10
+ import "@babel/parser"
11
+ import "@babel/plugin-proposal-decorators"
12
+ import "@babel/plugin-proposal-destructuring-private"
13
+ import "@babel/plugin-transform-class-properties"
14
+ import "@babel/plugin-transform-class-static-block"
15
+ import "@babel/plugin-transform-explicit-resource-management"
16
+ import "@babel/plugin-transform-exponentiation-operator"
17
+ import "@babel/plugin-transform-json-strings"
18
+ import "@babel/plugin-transform-logical-assignment-operators"
19
+ import "@babel/plugin-transform-nullish-coalescing-operator"
20
+ import "@babel/plugin-transform-numeric-separator"
21
+ import "@babel/plugin-transform-object-rest-spread"
22
+ import "@babel/plugin-transform-optional-catch-binding"
23
+ import "@babel/plugin-transform-optional-chaining"
24
+ import "@babel/plugin-transform-private-property-in-object"
25
+ import "@babel/plugin-transform-unicode-sets-regex"
26
+ import "@babel/traverse"
27
+ import "@babel/types"
28
+ import "@rollup/plugin-alias"
29
+ import "@rollup/plugin-babel"
30
+ import "@rollup/plugin-commonjs"
31
+ import "@rollup/plugin-json"
32
+ import "@rollup/plugin-node-resolve"
33
+ import "prettier"
34
+ import "rollup"
35
+ import "./constants.js"
36
+ import "./processScript/minify.js"
37
+ import "@samual/lib/spliceString"
38
+ import "acorn"
39
+ import "terser"
40
+ import "./processScript/shared.js"
41
+ import "./processScript/postprocess.js"
42
+ import "./processScript/preprocess.js"
43
+ import "import-meta-resolve"
44
+ import "./processScript/transform.js"
45
+ import "@samual/lib/clearObject"
46
+ class MissingSourceFolderError extends Error {}
47
+ Object.defineProperty(MissingSourceFolderError.prototype, "name", { value: "MissingSourceFolderError" })
48
+ class MissingHackmudFolderError extends Error {}
49
+ Object.defineProperty(MissingHackmudFolderError.prototype, "name", { value: "MissingHackmudFolderError" })
50
+ class NoUsersError extends Error {}
51
+ Object.defineProperty(NoUsersError.prototype, "name", { value: "NoUsersError" })
52
+ class NoScriptsError extends Error {}
53
+ Object.defineProperty(NoScriptsError.prototype, "name", { value: "NoScriptsError" })
54
+ async function push(
55
+ sourcePath,
56
+ hackmudPath,
57
+ { scripts = ["*.*"], onPush = () => {}, minify = !0, mangleNames = !1, forceQuineCheats, rootFolderPath } = {}
58
+ ) {
59
+ const [sourceFolder, hackmudFolder] = await Promise.all([
60
+ readDirectoryWithStats(sourcePath).catch(error => {
61
+ if (error && "ENOENT" == error.code)
62
+ return new MissingSourceFolderError("There is no folder at " + sourcePath)
63
+ throw error
64
+ }),
65
+ readDirectoryWithStats(hackmudPath).catch(error => {
66
+ if (error && "ENOENT" == error.code)
67
+ return new MissingHackmudFolderError("There is no folder at " + hackmudPath)
68
+ throw error
69
+ })
70
+ ])
71
+ if (sourceFolder instanceof Error) return sourceFolder
72
+ if (hackmudFolder instanceof Error) return hackmudFolder
73
+ const sourceFolderFolders = sourceFolder.filter(
74
+ ({ name, stats }) => stats.isDirectory() && /^[a-z_][a-z\d_]{0,24}$/.test(name)
75
+ ),
76
+ allUsers = new Set([
77
+ ...scripts
78
+ .map(scriptName => ensure(scriptName.split(".")[0], "src/push.ts:94:65"))
79
+ .filter(name => "*" != name),
80
+ ...sourceFolderFolders.map(({ name }) => name),
81
+ ...hackmudFolder.filter(({ stats }) => stats.isDirectory()).map(({ name }) => name),
82
+ ...hackmudFolder
83
+ .filter(({ stats, name }) => stats.isFile() && name.endsWith(".key"))
84
+ .map(({ name }) => name.slice(0, -4))
85
+ ])
86
+ if (!allUsers.size)
87
+ return new NoUsersError(
88
+ "Could not find any users. Either provide the names of your users or log into a user in hackmud"
89
+ )
90
+ const usersToScriptsToPush = new AutoMap(_user => new Map()),
91
+ scriptNamesToUsers = new AutoMap(_scriptName => new Set())
92
+ for (const script of scripts) {
93
+ const [user, scriptName] = script.split(".")
94
+ assert(user, "src/push.ts:117:16")
95
+ assert(scriptName, "src/push.ts:118:22")
96
+ "*" == user ? scriptNamesToUsers.set(scriptName, allUsers) : scriptNamesToUsers.get(scriptName).add(user)
97
+ }
98
+ const sourceFolderFiles = sourceFolder.filter(({ stats }) => stats.isFile()),
99
+ wildScriptUsers_ = scriptNamesToUsers.get("*")
100
+ scriptNamesToUsers.delete("*")
101
+ for (const { name, path } of [
102
+ ...sourceFolderFiles.filter(({ name }) => name.endsWith(".js")),
103
+ ...sourceFolderFiles.filter(({ name }) => name.endsWith(".ts"))
104
+ ]) {
105
+ const scriptName = name.slice(0, -3)
106
+ for (const user of [...wildScriptUsers_, ...scriptNamesToUsers.get(scriptName)])
107
+ usersToScriptsToPush.get(user).set(scriptName, path)
108
+ }
109
+ await Promise.all(
110
+ sourceFolderFolders.map(async ({ name: user, path }) => {
111
+ const files = (await readDirectoryWithStats(path)).filter(({ stats }) => stats.isFile()),
112
+ scriptFiles = [
113
+ ...files.filter(({ name }) => name.endsWith(".js")),
114
+ ...files.filter(({ name }) => name.endsWith(".ts"))
115
+ ]
116
+ for (const { name, path } of scriptFiles) {
117
+ const scriptName = name.slice(0, -3)
118
+ ;[...wildScriptUsers_, ...scriptNamesToUsers.get(scriptName)].includes(user) &&
119
+ usersToScriptsToPush.get(user).set(scriptName, path)
120
+ }
121
+ })
122
+ )
123
+ for (const [scriptName, users] of scriptNamesToUsers)
124
+ for (const user of users)
125
+ if (!usersToScriptsToPush.get(user).has(scriptName))
126
+ return new NoScriptsError(`Could not find script ${user}.${scriptName} to push`)
127
+ const pathsToUsers = new AutoMap(_path => new Set())
128
+ for (const [user, scriptsToPush] of usersToScriptsToPush)
129
+ for (const path of scriptsToPush.values()) pathsToUsers.get(path).add(user)
130
+ const allInfo = []
131
+ await Promise.all(
132
+ [...pathsToUsers].map(async ([path, [...users]]) => {
133
+ const scriptName = basename(path.slice(0, -3)),
134
+ uniqueId = Math.floor(Math.random() * 2 ** 52)
135
+ .toString(36)
136
+ .padStart(11, "0"),
137
+ { script: minifiedCode, warnings } = await processScript(await readFile(path, { encoding: "utf8" }), {
138
+ minify,
139
+ scriptUser: !0,
140
+ scriptName,
141
+ uniqueId,
142
+ filePath: path,
143
+ mangleNames,
144
+ forceQuineCheats,
145
+ rootFolderPath
146
+ }),
147
+ info = { path, users, characterCount: countHackmudCharacters(minifiedCode), error: void 0, warnings }
148
+ await Promise.all(
149
+ users.map(user =>
150
+ writeFilePersistent(
151
+ resolve(hackmudPath, user, `scripts/${scriptName}.js`),
152
+ minifiedCode
153
+ .replace(RegExp(`\\$${uniqueId}\\$SCRIPT_USER\\$`, "g"), user)
154
+ .replace(RegExp(`\\$${uniqueId}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
155
+ )
156
+ )
157
+ )
158
+ allInfo.push(info)
159
+ onPush(info)
160
+ })
161
+ )
162
+ return allInfo
163
+ }
164
+ export { MissingHackmudFolderError, MissingSourceFolderError, NoScriptsError, NoUsersError, push }
@@ -0,0 +1,4 @@
1
+ export declare function syncMacros(hackmudPath: string): Promise<{
2
+ macrosSynced: number;
3
+ usersSynced: number;
4
+ }>;
package/syncMacros.js ADDED
@@ -0,0 +1,42 @@
1
+ import { readFile, stat, writeFile } from "fs/promises"
2
+ import { extname, basename, resolve } from "path"
3
+ import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
4
+ async function syncMacros(hackmudPath) {
5
+ const files = await readDirectoryWithStats(hackmudPath),
6
+ macros = new Map(),
7
+ users = []
8
+ await Promise.all(
9
+ files.map(async file => {
10
+ if (file.stats.isFile())
11
+ switch (extname(file.name)) {
12
+ case ".macros": {
13
+ const [lines, date] = await Promise.all([
14
+ readFile(resolve(hackmudPath, file.name), { encoding: "utf8" }).then(file =>
15
+ file.split(/\r?\n/)
16
+ ),
17
+ stat(resolve(hackmudPath, file.name)).then(({ mtime }) => mtime)
18
+ ])
19
+ for (let index = 0; 2 * index + 1 < lines.length; index++) {
20
+ const macroName = lines[2 * index],
21
+ currentMacro = macros.get(macroName)
22
+ ;(!currentMacro || date > currentMacro.date) &&
23
+ macros.set(macroName, { date, macro: lines[2 * index + 1] })
24
+ }
25
+ break
26
+ }
27
+ case ".key":
28
+ users.push(basename(file.name, ".key"))
29
+ }
30
+ })
31
+ )
32
+ let macroFile = "",
33
+ macrosSynced = 0
34
+ for (const [name, { macro }] of [...macros].sort(([a], [b]) => (a > b) - (a < b)))
35
+ if (macro[0] == macro[0].toLowerCase()) {
36
+ macroFile += `${name}\n${macro}\n`
37
+ macrosSynced++
38
+ }
39
+ await Promise.all(users.map(async user => writeFile(resolve(hackmudPath, user + ".macros"), macroFile)))
40
+ return { macrosSynced, usersSynced: users.length }
41
+ }
42
+ export { syncMacros }
package/watch.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { LaxPartial } from "@samual/lib";
2
+ import type { PushOptions } from "./push";
3
+ export type WatchOptions = PushOptions & LaxPartial<{
4
+ /**
5
+ * if provided, will write typescript type declarations for all the scripts on every change detected
6
+ *
7
+ * writing the type declarations enables interscript type checking and autocompletetes for the args
8
+ */
9
+ typeDeclarationPath: string;
10
+ onReady: () => void;
11
+ rootFolderPath: string;
12
+ }>;
13
+ /**
14
+ * Watches target file or folder for updates and builds and pushes updated file.
15
+ * @param sourceDirectory path to folder containing source files
16
+ * @param hackmudDirectory path to hackmud directory
17
+ * @param options {@link WatchOptions details} and {@link PushOptions more details}
18
+ */
19
+ export declare function watch(sourceDirectory: string, hackmudDirectory: string, { scripts, onPush, minify, mangleNames, typeDeclarationPath: typeDeclarationPath_, onReady, forceQuineCheats, rootFolderPath }?: WatchOptions): Promise<void>;
package/watch.js ADDED
@@ -0,0 +1,220 @@
1
+ import { stat, readFile, writeFile } from "fs/promises"
2
+ import { extname, basename, resolve } from "path"
3
+ import { assert } from "@samual/lib/assert"
4
+ import { AutoMap } from "@samual/lib/AutoMap"
5
+ import { countHackmudCharacters } from "@samual/lib/countHackmudCharacters"
6
+ import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
7
+ import { writeFilePersistent } from "@samual/lib/writeFilePersistent"
8
+ import { watch as watch$1 } from "chokidar"
9
+ import { supportedExtensions } from "./constants.js"
10
+ import { generateTypeDeclaration } from "./generateTypeDeclaration.js"
11
+ import { processScript } from "./processScript/index.js"
12
+ import "@babel/generator"
13
+ import "@babel/parser"
14
+ import "@babel/plugin-proposal-decorators"
15
+ import "@babel/plugin-proposal-destructuring-private"
16
+ import "@babel/plugin-transform-class-properties"
17
+ import "@babel/plugin-transform-class-static-block"
18
+ import "@babel/plugin-transform-explicit-resource-management"
19
+ import "@babel/plugin-transform-exponentiation-operator"
20
+ import "@babel/plugin-transform-json-strings"
21
+ import "@babel/plugin-transform-logical-assignment-operators"
22
+ import "@babel/plugin-transform-nullish-coalescing-operator"
23
+ import "@babel/plugin-transform-numeric-separator"
24
+ import "@babel/plugin-transform-object-rest-spread"
25
+ import "@babel/plugin-transform-optional-catch-binding"
26
+ import "@babel/plugin-transform-optional-chaining"
27
+ import "@babel/plugin-transform-private-property-in-object"
28
+ import "@babel/plugin-transform-unicode-sets-regex"
29
+ import "@babel/traverse"
30
+ import "@babel/types"
31
+ import "@rollup/plugin-alias"
32
+ import "@rollup/plugin-babel"
33
+ import "@rollup/plugin-commonjs"
34
+ import "@rollup/plugin-json"
35
+ import "@rollup/plugin-node-resolve"
36
+ import "prettier"
37
+ import "rollup"
38
+ import "./processScript/minify.js"
39
+ import "@samual/lib/spliceString"
40
+ import "acorn"
41
+ import "terser"
42
+ import "./processScript/shared.js"
43
+ import "./processScript/postprocess.js"
44
+ import "./processScript/preprocess.js"
45
+ import "import-meta-resolve"
46
+ import "./processScript/transform.js"
47
+ import "@samual/lib/clearObject"
48
+ async function watch(
49
+ sourceDirectory,
50
+ hackmudDirectory,
51
+ {
52
+ scripts = ["*.*"],
53
+ onPush,
54
+ minify = !0,
55
+ mangleNames = !1,
56
+ typeDeclarationPath: typeDeclarationPath_,
57
+ onReady,
58
+ forceQuineCheats,
59
+ rootFolderPath
60
+ } = {}
61
+ ) {
62
+ if (!scripts.length) throw Error("scripts option was an empty array")
63
+ if (!(await stat(sourceDirectory)).isDirectory()) throw Error("Target folder must be a folder")
64
+ const scriptNamesToUsers = new AutoMap(_scriptName => new Set()),
65
+ wildScriptUsers = new Set(),
66
+ wildUserScripts = new Set()
67
+ let pushEverything = !1
68
+ for (const fullScriptName of scripts) {
69
+ const [user, scriptName] = fullScriptName.split(".")
70
+ user && "*" != user
71
+ ? scriptName && "*" != scriptName
72
+ ? scriptNamesToUsers.get(scriptName).add(user)
73
+ : wildScriptUsers.add(user)
74
+ : scriptName && "*" != scriptName
75
+ ? wildUserScripts.add(scriptName)
76
+ : (pushEverything = !0)
77
+ }
78
+ const watcher = watch$1(".", {
79
+ cwd: sourceDirectory,
80
+ awaitWriteFinish: { stabilityThreshold: 100 },
81
+ ignored: (path, stats) =>
82
+ !!stats?.isFile() && !(path.endsWith(".js") || (path.endsWith(".ts") && !path.endsWith(".d.ts")))
83
+ }).on("change", async path => {
84
+ if (path.endsWith(".d.ts")) return
85
+ const extension = extname(path)
86
+ if (!supportedExtensions.includes(extension)) return
87
+ const scriptName = basename(path, extension)
88
+ if (path == basename(path)) {
89
+ if (
90
+ !(
91
+ pushEverything ||
92
+ wildScriptUsers.size ||
93
+ wildUserScripts.has(scriptName) ||
94
+ scriptNamesToUsers.has(scriptName)
95
+ )
96
+ )
97
+ return
98
+ const scriptNamesToUsersToSkip = new AutoMap(_scriptName => [])
99
+ await Promise.all(
100
+ (await readDirectoryWithStats(sourceDirectory)).map(async ({ stats, name, path }) => {
101
+ if (stats.isDirectory())
102
+ for (const child of await readDirectoryWithStats(path))
103
+ if (child.stats.isFile()) {
104
+ const fileExtension = extname(child.name)
105
+ supportedExtensions.includes(fileExtension) &&
106
+ scriptNamesToUsersToSkip.get(basename(child.name, fileExtension)).push(name)
107
+ }
108
+ })
109
+ )
110
+ const usersToPushToSet = new Set()
111
+ if (pushEverything || wildUserScripts.has(scriptName)) {
112
+ for (const { stats, name } of await readDirectoryWithStats(sourceDirectory))
113
+ stats.isDirectory() && usersToPushToSet.add(name)
114
+ for (const { stats, name } of await readDirectoryWithStats(hackmudDirectory))
115
+ stats.isDirectory()
116
+ ? usersToPushToSet.add(name)
117
+ : stats.isFile() && name.endsWith(".key") && usersToPushToSet.add(name.slice(0, -4))
118
+ for (const users of scriptNamesToUsers.values()) for (const user of users) usersToPushToSet.add(user)
119
+ }
120
+ for (const user of wildScriptUsers) usersToPushToSet.add(user)
121
+ for (const user of scriptNamesToUsers.get(scriptName)) usersToPushToSet.add(user)
122
+ const usersToPushTo = [...usersToPushToSet].filter(user => !scriptNamesToUsersToSkip.has(user))
123
+ if (!usersToPushTo.length) {
124
+ onPush?.({ path, users: [], characterCount: 0, error: Error("no users to push to"), warnings: [] })
125
+ return
126
+ }
127
+ const uniqueId = Math.floor(Math.random() * 2 ** 52)
128
+ .toString(36)
129
+ .padStart(11, "0"),
130
+ filePath = resolve(sourceDirectory, path)
131
+ let minifiedCode, warnings
132
+ try {
133
+ ;({ script: minifiedCode, warnings } = await processScript(
134
+ await readFile(filePath, { encoding: "utf8" }),
135
+ {
136
+ minify,
137
+ scriptUser: !0,
138
+ scriptName,
139
+ uniqueId,
140
+ filePath,
141
+ mangleNames,
142
+ forceQuineCheats,
143
+ rootFolderPath
144
+ }
145
+ ))
146
+ } catch (error) {
147
+ assert(error instanceof Error, "src/watch.ts:165:36")
148
+ onPush?.({ path, users: [], characterCount: 0, error, warnings: [] })
149
+ return
150
+ }
151
+ await Promise.all(
152
+ usersToPushTo.map(user =>
153
+ writeFilePersistent(
154
+ resolve(hackmudDirectory, user, `scripts/${scriptName}.js`),
155
+ minifiedCode
156
+ .replace(RegExp(`\\$${uniqueId}\\$SCRIPT_USER\\$`, "g"), user)
157
+ .replace(RegExp(`\\$${uniqueId}\\$FULL_SCRIPT_NAME\\$`, "g"), `${user}.${scriptName}`)
158
+ )
159
+ )
160
+ )
161
+ onPush?.({
162
+ path,
163
+ users: usersToPushTo,
164
+ characterCount: countHackmudCharacters(minifiedCode),
165
+ error: void 0,
166
+ warnings
167
+ })
168
+ return
169
+ }
170
+ const user = basename(resolve(path, ".."))
171
+ if (
172
+ !(
173
+ pushEverything ||
174
+ wildScriptUsers.size ||
175
+ wildUserScripts.has(scriptName) ||
176
+ scriptNamesToUsers.get(scriptName).has(user)
177
+ )
178
+ )
179
+ return
180
+ const sourceDirectoryResolved = resolve(sourceDirectory),
181
+ filePath = resolve(sourceDirectoryResolved, path),
182
+ sourceCode = await readFile(filePath, { encoding: "utf8" })
183
+ let script, warnings
184
+ try {
185
+ ;({ script, warnings } = await processScript(sourceCode, {
186
+ minify,
187
+ scriptUser: user,
188
+ scriptName,
189
+ filePath,
190
+ mangleNames,
191
+ forceQuineCheats,
192
+ rootFolderPath
193
+ }))
194
+ } catch (error) {
195
+ assert(error instanceof Error, "src/watch.ts:212:35")
196
+ onPush?.({ path, users: [], characterCount: 0, error, warnings: [] })
197
+ return
198
+ }
199
+ await writeFilePersistent(resolve(hackmudDirectory, user, "scripts", scriptName + ".js"), script)
200
+ onPush?.({ path, users: [user], characterCount: countHackmudCharacters(script), error: void 0, warnings })
201
+ })
202
+ onReady && watcher.on("ready", onReady)
203
+ if (!typeDeclarationPath_) return
204
+ let typeDeclarationPath = typeDeclarationPath_
205
+ const writeTypeDeclaration = async () => {
206
+ const typeDeclaration = await generateTypeDeclaration(sourceDirectory, hackmudDirectory)
207
+ try {
208
+ await writeFile(typeDeclarationPath, typeDeclaration)
209
+ } catch (error) {
210
+ assert(error instanceof Error, "src/watch.ts:245:35")
211
+ if ("EISDIR" != error.code) throw error
212
+ typeDeclarationPath = resolve(typeDeclarationPath, "player.d.ts")
213
+ await writeFile(typeDeclarationPath, typeDeclaration)
214
+ }
215
+ }
216
+ await writeTypeDeclaration()
217
+ watcher.on("add", writeTypeDeclaration)
218
+ watcher.on("unlink", writeTypeDeclaration)
219
+ }
220
+ export { watch }
package/.envrc DELETED
@@ -1 +0,0 @@
1
- PATH_add $PWD/node_modules/.bin
@@ -1,14 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: [ samualtnorman ] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
- patreon: # Replace with a single Patreon username
5
- open_collective: # Replace with a single Open Collective username
6
- ko_fi: samualn # Replace with a single Ko-fi username
7
- tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
- community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
- liberapay: # Replace with a single Liberapay username
10
- issuehunt: # Replace with a single IssueHunt username
11
- lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12
- polar: # Replace with a single Polar username
13
- buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
14
- custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
@@ -1,27 +0,0 @@
1
- name: Publish
2
- on: { push: { branches: [ main, "0.20" ] }, release: { types: [ created ] } }
3
-
4
- permissions:
5
- contents: read
6
-
7
- jobs:
8
- publish:
9
- name: Publish
10
- runs-on: ubuntu-latest
11
-
12
- steps:
13
- - { name: Checkout, uses: actions/checkout@v6 }
14
- - { name: Setup Node.js environment, uses: actions/setup-node@v6, with: { node-version: 24 } }
15
- - { name: Setup pnpm, uses: pnpm/action-setup@v4, with: { run_install: true } }
16
- - run: git config --global user.email github-action@users.noreply.github.com
17
- - run: git config --global user.name "Github Action"
18
- - run: pnpm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
19
- - run: export PATH=$PWD/node_modules/.bin:$PATH
20
-
21
- - name: Publish dev
22
- if: github.event_name == 'push' || github.event_name == 'pull_request'
23
- run: scripts/version-dev.js && scripts/package.sh && cd dist && pnpm publish --no-git-checks --tag dev
24
-
25
- - name: Publish release
26
- if: github.event_name == 'release'
27
- run: scripts/package.sh && cd dist && pnpm publish --no-git-checks
@@ -1,18 +0,0 @@
1
- name: Test
2
- on: { push: { branches: [ "*" ] }, pull_request: { branches: [ "*" ] } }
3
-
4
- permissions:
5
- contents: read
6
-
7
- jobs:
8
- test:
9
- runs-on: ubuntu-latest
10
-
11
- steps:
12
- - { name: Checkout, uses: actions/checkout@v6 }
13
- - { name: Setup Node.js environment, uses: actions/setup-node@v6, with: { node-version: 24 } }
14
- - { name: Setup pnpm, uses: pnpm/action-setup@v4, with: { run_install: true } }
15
- - run: echo $PWD/node_modules/.bin:$PATH > $GITHUB_PATH
16
- - run: scripts/package.sh
17
- - run: scripts/lint.sh
18
- - run: npx vitest run
@@ -1,55 +0,0 @@
1
- {
2
- "typescript.tsdk": "node_modules/typescript/lib",
3
- "files.insertFinalNewline": true,
4
- "files.trimFinalNewlines": true,
5
- "files.trimTrailingWhitespace": true,
6
- // Disable the default formatter, use eslint instead
7
- "prettier.enable": false,
8
- "editor.formatOnSave": false,
9
-
10
- // Auto fix
11
- "editor.codeActionsOnSave": {
12
- "source.fixAll.eslint": "explicit",
13
- "source.organizeImports": "never"
14
- },
15
-
16
- // Silent the stylistic rules in you IDE, but still auto fix them
17
- "eslint.rules.customizations": [
18
- { "rule": "style/*", "severity": "off", "fixable": true },
19
- { "rule": "format/*", "severity": "off", "fixable": true },
20
- { "rule": "*-indent", "severity": "off", "fixable": true },
21
- { "rule": "*-spacing", "severity": "off", "fixable": true },
22
- { "rule": "*-spaces", "severity": "off", "fixable": true },
23
- { "rule": "*-order", "severity": "off", "fixable": true },
24
- { "rule": "*-dangle", "severity": "off", "fixable": true },
25
- { "rule": "*-newline", "severity": "off", "fixable": true },
26
- { "rule": "*quotes", "severity": "off", "fixable": true },
27
- { "rule": "*semi", "severity": "off", "fixable": true }
28
- ],
29
-
30
- // Enable eslint for all supported languages
31
- "eslint.validate": [
32
- "javascript",
33
- "javascriptreact",
34
- "typescript",
35
- "typescriptreact",
36
- "vue",
37
- "html",
38
- "markdown",
39
- "json",
40
- "json5",
41
- "jsonc",
42
- "yaml",
43
- "toml",
44
- "xml",
45
- "gql",
46
- "graphql",
47
- "astro",
48
- "svelte",
49
- "css",
50
- "less",
51
- "scss",
52
- "pcss",
53
- "postcss"
54
- ]
55
- }