hackmud-script-manager 0.21.1 → 0.21.2-8993a56

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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # Hackmud Script Manager
2
2
  Command made for [Hackmud Scripting Environment](https://github.com/samualtnorman/hackmud-environment), which is a scripting environment for hackmud with minification, autocompletes / intellisense, and TypeScript support.
3
3
 
4
+ Join [our Discord server](https://discord.gg/RSa4Sc6pNA)!
5
+
4
6
  [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/R6R0XN5CX)
5
7
 
6
8
  You can read about how HSM works [in my blog post](https://samual.uk/blog/js-code-transformation-niche-environment/).
package/bin/hsm.js CHANGED
@@ -11,7 +11,6 @@ import { generateTypeDeclaration } from "../generateTypeDeclaration.js"
11
11
  import { pull } from "../pull.js"
12
12
  import { syncMacros } from "../syncMacros.js"
13
13
  import "@samual/lib/readDirectoryWithStats"
14
- import "path/posix"
15
14
  import "@samual/lib/copyFilePersistent"
16
15
  const formatOption = name => colourN(`-${1 == name.length ? "" : "-"}${name}`),
17
16
  options = new Map(),
@@ -64,7 +63,7 @@ if (process.version.startsWith("v21.")) {
64
63
  )
65
64
  }
66
65
  if ("v" == commands[0] || "version" == commands[0] || popOption("version", "v")?.value) {
67
- console.log("0.21.1")
66
+ console.log("0.21.2-8993a56")
68
67
  process.exit()
69
68
  }
70
69
  let warnedDeprecatedEmitDtsAlias = !1
@@ -412,7 +411,7 @@ function logHelp() {
412
411
  default:
413
412
  console.log(
414
413
  colourS(
415
- `${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.1")}\n\n${colourA("Commands:")}\n${colourL("push")}\n ${pushCommandDescription}\n${colourL("minify")}\n Minify a script file on the spot\n${colourL("emit-dts")}\n Generate a type declaration file for a directory of scripts\n${colourL("sync-macros")}\n Sync macros across all hackmud users\n${colourL("pull")}\n Pull a script a from a hackmud user's script directory\n\n${colourA("Options:")}\n${colourN("--help")}\n Can be used on any command e.g. ${colourC("hsm")} ${colourL("push")} ${colourN("--help")} to show helpful information`
414
+ `${colourJ("Hackmud Script Manager")}\n${colourN("Version") + colourS(": ") + colourV("0.21.2-8993a56")}\n\n${colourA("Commands:")}\n${colourL("push")}\n ${pushCommandDescription}\n${colourL("minify")}\n Minify a script file on the spot\n${colourL("emit-dts")}\n Generate a type declaration file for a directory of scripts\n${colourL("sync-macros")}\n Sync macros across all hackmud users\n${colourL("pull")}\n Pull a script a from a hackmud user's script directory\n\n${colourA("Options:")}\n${colourN("--help")}\n Can be used on any command e.g. ${colourC("hsm")} ${colourL("push")} ${colourN("--help")} to show helpful information`
416
415
  )
417
416
  )
418
417
  }
package/env.d.ts CHANGED
@@ -189,7 +189,7 @@ type Fullsec = Subscripts & PlayerFullsec & {
189
189
 
190
190
  /** @returns A random element from `array`, selected with a random number generated using `rng`
191
191
  * (defaults to `Math.random`). */
192
- sample: (array: any[], rng?: ()=>number) => any
192
+ sample: <T>(array: T[], rng?: ()=>number) => T
193
193
 
194
194
  /** @returns Whether two MongoDB `ObjectId`s are equivalent. */ are_ids_eq: (id1: any, id2: any) => boolean
195
195
  /** Convert a MongoDB `ObjectId` to a string. */ id_to_str: (id: string | {$oid: string}) => any
@@ -270,7 +270,7 @@ type Fullsec = Subscripts & PlayerFullsec & {
270
270
  map: <T, U>(array: T[], callback: (index: number, value: T) => U) => U[]
271
271
 
272
272
  /** @returns A new object derived from `obj` with only the keys specified in `keys`. */
273
- pick: (obj: object, keys: string[]) => any
273
+ pick: <TObj extends object, TKeys extends keyof TObj>(obj: TObj, keys: TKeys[]) => { [K in TKeys]: TObj[K] }
274
274
 
275
275
  /** @returns An array with the elements from `array` in a random order. */ shuffle: <T>(array: T[]) => T[]
276
276
 
@@ -298,7 +298,7 @@ type Fullsec = Subscripts & PlayerFullsec & {
298
298
  security_level_names: [ "NULLSEC", "LOWSEC", "MIDSEC", "HIGHSEC", "FULLSEC" ]
299
299
 
300
300
  /** @returns The string name of a numeric security level. */
301
- get_security_level_name: (security_level: number) => any
301
+ get_security_level_name: (security_level: number) => string
302
302
 
303
303
  /** @param result The return value of a call to `$db.i()` or `$db.r()`.
304
304
  * @param nModified The expected value of `result.nModified`.
@@ -699,7 +699,7 @@ type Nullsec = Lowsec & PlayerNullsec & {
699
699
  // database
700
700
  type MongoPrimitive = null | boolean | number | Date | string
701
701
  type MongoValue = MongoPrimitive | MongoValue[] | MongoObject
702
- type MongoObject = { [k: string]: MongoValue, [k: `$${string}`]: never }
702
+ type MongoObject = { [k: string]: MongoValue }
703
703
  type MongoQueryValue = MongoPrimitive | MongoQueryValue[] | MongoQueryObject
704
704
 
705
705
  type MongoQueryObject =
@@ -755,11 +755,16 @@ type MongoQuerySelector<T extends MongoValue> = Partial<
755
755
 
756
756
  type MongoQuery<T extends MongoObject> = { [K in keyof T]?: T[K] | MongoQuerySelector<T[K]> } & { _id?: MongoId }
757
757
 
758
- type MongoUpdateOperators<T extends MongoObject> = Partial<{
758
+ type MongoUpdateArrayOperatorUniversalModifiers<T> = { $each?: T extends [] ? T : T[] }
759
+
760
+ type MongoUpdateArrayOperatorModifiers<T> = MongoUpdateArrayOperatorUniversalModifiers<T> &
761
+ { $position?: number, $slice?: number, $sort?: 1 | -1 }
762
+
763
+ type MongoUpdateCommand<T extends MongoObject> = Partial<{
759
764
  /* Universal operators */
760
- $set: Partial<Record<string, MongoCommandValue> & T>
761
- $setOnInsert: Partial<Record<string, MongoCommandValue> & T>
762
- $unset: Partial<Record<string, ""> & T>
765
+ $set: Partial<Record<(string & {}) | keyof T, MongoCommandValue>>
766
+ $setOnInsert: Partial<Record<(string & {}) | keyof T, MongoCommandValue>>
767
+ $unset: Partial<Record<(string & {}) | keyof T, "">>
763
768
 
764
769
  $rename: Partial<Record<string, string> & { [key in keyof T]: string }>
765
770
 
@@ -792,13 +797,6 @@ type MongoUpdateOperators<T extends MongoObject> = Partial<{
792
797
  $pullAll: Record<string, MongoCommandValue> & { [K in keyof T as T[K] extends [] ? K : never]?: T[K] }
793
798
  }>
794
799
 
795
- type MongoUpdateArrayOperatorUniversalModifiers<T> = { $each?: T extends [] ? T : T[] }
796
-
797
- type MongoUpdateArrayOperatorModifiers<T> = MongoUpdateArrayOperatorUniversalModifiers<T> &
798
- { $position?: number, $slice?: number, $sort?: 1 | -1 }
799
-
800
- type MongoUpdateCommand<Schema extends MongoObject> = MongoUpdateOperators<Schema>
801
-
802
800
  type SortOrder = { [key: string]: 1 | -1 | SortOrder }
803
801
 
804
802
  type Cursor<T> = {
@@ -1,6 +1,5 @@
1
1
  import { readDirectoryWithStats } from "@samual/lib/readDirectoryWithStats"
2
2
  import { basename, resolve } from "path"
3
- import * as PathPosix from "path/posix"
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)).map(async ({ stats, name }) => {
15
- if (stats.isFile())
16
- name.endsWith(".ts")
17
- ? name.endsWith(".d.ts") || wildScripts.push(basename(name, ".ts"))
18
- : name.endsWith(".js") && wildAnyScripts.push(basename(name, ".js"))
19
- else if (stats.isDirectory()) {
20
- const scripts = [],
21
- anyScripts = []
22
- allScripts[name] = scripts
23
- allAnyScripts[name] = anyScripts
24
- users.add(name)
25
- for (const child of await readDirectoryWithStats(resolve(sourceDirectory, name)))
26
- child.stats.isFile() &&
27
- (child.name.endsWith(".ts")
28
- ? name.endsWith(".d.ts") || scripts.push(basename(child.name, ".ts"))
29
- : child.name.endsWith(".js") && anyScripts.push(basename(child.name, ".js")))
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) o += `type $${script}$ = typeof import("${sourceDirectory}/${script}").default\n`
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("${sourceDirectory}/${user}/${script}").default\n`
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
@@ -7,7 +7,6 @@ export { syncMacros } from "./syncMacros.js"
7
7
  export { watch } from "./watch.js"
8
8
  import "@samual/lib/readDirectoryWithStats"
9
9
  import "path"
10
- import "path/posix"
11
10
  import "@babel/generator"
12
11
  import "@babel/parser"
13
12
  import "@babel/plugin-proposal-decorators"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hackmud-script-manager",
3
- "version": "0.21.1",
3
+ "version": "0.21.2-8993a56",
4
4
  "description": "Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.",
5
5
  "keywords": [
6
6
  "api",
@@ -23,7 +23,9 @@
23
23
  "author": "Samual Norman <me@samual.uk> (https://samual.uk/)",
24
24
  "contributors": [
25
25
  "Daniel Swann (https://github.com/danswann)",
26
- "Longboyy"
26
+ "Longboyy",
27
+ "Helloman892",
28
+ "Sarah Klocke (https://sarahisweird.dev/)"
27
29
  ],
28
30
  "main": "index.js",
29
31
  "repository": {
@@ -23,7 +23,7 @@ import rollupPluginCommonJS from "@rollup/plugin-commonjs"
23
23
  import rollupPluginJSON from "@rollup/plugin-json"
24
24
  import rollupPluginNodeResolve from "@rollup/plugin-node-resolve"
25
25
  import { assert } from "@samual/lib/assert"
26
- import { relative } from "path"
26
+ import { relative, isAbsolute, sep } from "path"
27
27
  import prettier from "prettier"
28
28
  import { rollup } from "rollup"
29
29
  import { supportedExtensions } from "../constants.js"
@@ -210,7 +210,8 @@ async function processScript(
210
210
  {
211
211
  name: "hackmud-script-manager",
212
212
  async transform(code, id) {
213
- if (!id.includes("/node_modules/")) return (await preprocess(code, { uniqueId })).code
213
+ if (isAbsolute(id) && !id.includes(`${sep}node_modules${sep}`))
214
+ return (await preprocess(code, { uniqueId })).code
214
215
  let program
215
216
  traverse(parse(code, { sourceType: "module" }), {
216
217
  Program(path) {
@@ -595,7 +595,9 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
595
595
  thisIsReferenced = !0
596
596
  path.replaceWith(t.identifier(`_${uniqueId}_THIS_`))
597
597
  },
598
- Function: path => path.skip()
598
+ Function(path) {
599
+ "ArrowFunctionExpression" != path.node.type && path.skip()
600
+ }
599
601
  },
600
602
  scope
601
603
  )
@@ -682,23 +684,23 @@ function transform(file, sourceCode, { uniqueId = "00000000000", scriptUser, scr
682
684
  }
683
685
  function processFakeSubscriptObject(fakeSubscriptObjectName, seclevel) {
684
686
  for (const referencePath of getReferencePathsToGlobal(fakeSubscriptObjectName, program)) {
685
- assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:807:60")
687
+ assert("MemberExpression" == referencePath.parent.type, "src/processScript/transform.ts:811:60")
686
688
  assert("Identifier" == referencePath.parent.property.type)
687
689
  assert(
688
690
  "MemberExpression" == referencePath.parentPath.parentPath?.node.type,
689
- "src/processScript/transform.ts:809:81"
691
+ "src/processScript/transform.ts:813:81"
690
692
  )
691
693
  assert(
692
694
  "Identifier" == referencePath.parentPath.parentPath.node.property.type,
693
- "src/processScript/transform.ts:810:83"
695
+ "src/processScript/transform.ts:814:83"
694
696
  )
695
697
  assert(
696
698
  /^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parent.property.name),
697
- `src/processScript/transform.ts:814:8 invalid user "${referencePath.parent.property.name}" in subscript`
699
+ `src/processScript/transform.ts:818:8 invalid user "${referencePath.parent.property.name}" in subscript`
698
700
  )
699
701
  assert(
700
702
  /^[_a-z][\d_a-z]{0,24}$/.test(referencePath.parentPath.parentPath.node.property.name),
701
- `src/processScript/transform.ts:819:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
703
+ `src/processScript/transform.ts:823:8 invalid script name "${referencePath.parentPath.parentPath.node.property.name}" in subscript`
702
704
  )
703
705
  if ("CallExpression" == referencePath.parentPath.parentPath.parentPath?.type)
704
706
  referencePath.parentPath.parentPath.replaceWith(
package/watch.js CHANGED
@@ -9,7 +9,6 @@ import { extname, basename, resolve } from "path"
9
9
  import { supportedExtensions } from "./constants.js"
10
10
  import { generateTypeDeclaration } from "./generateTypeDeclaration.js"
11
11
  import { processScript } from "./processScript/index.js"
12
- import "path/posix"
13
12
  import "@babel/generator"
14
13
  import "@babel/parser"
15
14
  import "@babel/plugin-proposal-decorators"