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.
- 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 +113 -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/.envrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PATH_add $PWD/node_modules/.bin
|
|
@@ -0,0 +1,14 @@
|
|
|
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']
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
}
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Contributing Guide
|
|
2
|
+
|
|
3
|
+
If you get stuck, message me on discord `@samualn`.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- [Git](https://git-scm.com/)
|
|
8
|
+
- **Windows:** Make sure you install Git Bash with it
|
|
9
|
+
- [Clone this repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)
|
|
10
|
+
- [PNPM](https://pnpm.io/)
|
|
11
|
+
- **Optional:** [`direnv`](https://direnv.net/)
|
|
12
|
+
|
|
13
|
+
## Linux Users
|
|
14
|
+
|
|
15
|
+
1. Open this cloned repository in a terminal
|
|
16
|
+
2. Run `pnpm install`
|
|
17
|
+
3. Modify your `PATH`
|
|
18
|
+
- If you have `direnv`, run `direnv allow` if you havn't already
|
|
19
|
+
- Otherwise run `export PATH=$PWD/node_modules/.bin:$PATH`
|
|
20
|
+
4. Run `scripts/package.sh` to compile everything and build the NPM package in `dist`
|
|
21
|
+
|
|
22
|
+
## Windows Users
|
|
23
|
+
|
|
24
|
+
1. Open this cloned repository in Git Bash
|
|
25
|
+
2. Run `pnpm install`
|
|
26
|
+
3. Run `export PATH=$PWD/node_modules/.bin:$PATH`
|
|
27
|
+
4. Run `scripts/package.sh` to compile everything and build the NPM package in `dist`
|
|
28
|
+
|
|
29
|
+
## Tips and Tricks
|
|
30
|
+
|
|
31
|
+
Run `./rollup.config.js` to only recompile.
|
|
32
|
+
|
|
33
|
+
### Run the Development Version of HSM
|
|
34
|
+
|
|
35
|
+
You can run the development version of HSM by running `node dist/bin/hsm.js`. You can pass it arguments just like you normally would e.g. `node dist/bin/hsm.js --version`.
|
|
36
|
+
|
|
37
|
+
### Install the Development Version of the NPM Package in Another Project
|
|
38
|
+
|
|
39
|
+
In the other project (e.g. testing with Hackmud Scripting Environment) run `pnpm add ~/path/to/hackmud-script-manager/dist`.
|
|
40
|
+
|
|
41
|
+
## Tests
|
|
42
|
+
|
|
43
|
+
Tests can be run by running `vitest run` (assuming you have followed above setup instructions).
|
|
44
|
+
|
|
45
|
+
There is currently not enforcement on writing unit tests but if you are going to, the test you write MUST be failing.
|
|
46
|
+
You CANNOT add passing tests. If you are also writing a fix for a new test, ensure that the fix is in a seperate commit
|
|
47
|
+
AFTER the commit the test is added in. This ensures that someone else can checkout the commit with the newly added test
|
|
48
|
+
and verify that it is failing, checkout the commit where the fix is implemented, and verify that the test is now
|
|
49
|
+
passing.
|
|
50
|
+
|
|
51
|
+
The files in the `game-scripts-test/` folder are the input for testing `processScript()`. They are read by the vitest
|
|
52
|
+
block at the bottom of `src/processScript/index.ts` where they are transformed and evaluated. Support for testing
|
|
53
|
+
subscripts and other preprocessor-related stuff is not yet implemented. If one of these tests is failing, you will see
|
|
54
|
+
the path outputed like so:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
❯ src/processScript/index.ts (1 test | 1 failed) 6ms
|
|
58
|
+
× game-scripts-tests/this_function_array.ts 6ms
|
|
59
|
+
→ expected undefined to be [ [Function] ] // Object.is equality
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Notice `game-scripts-tests/this_function_array.ts`.
|
|
63
|
+
|
|
64
|
+
The naming convention uses underscores instead of dashes as if it was the name of a real hackmud script (which cannot
|
|
65
|
+
contain dashes).
|
|
66
|
+
|
|
67
|
+
If you need to know what the test scripts look like after being transformed, look for a symbol named
|
|
68
|
+
`DEBUG_LOG_PROCESSED_SCRIPTS` in this project and set it to `true`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Samual Norman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
## Note: This is a somewhat updated fork of https://github.com/samualtnorman/hackmud-script-manager#readme published at hackmud-script-manager-next
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Changes:
|
|
4
|
+
|
|
5
|
+
- Fixed expose_balance and expose_access_log return types
|
|
6
|
+
- Added delist arg to market.sell
|
|
7
|
+
- Added marks scripts
|
|
8
|
+
|
|
9
|
+
Feel free to make a PR with improvements.
|
|
10
|
+
|
|
11
|
+
# Hackmud Script Manager
|
|
12
|
+
|
|
13
|
+
Command made for [Hackmud Scripting Environment](https://github.com/edg-l/hackmud-environment), which is a scripting environment for hackmud with minification, autocompletes / intellisense, and TypeScript support.
|
|
14
|
+
|
|
15
|
+
Join [our Discord server](https://discord.gg/RSa4Sc6pNA)!
|
|
16
|
+
|
|
17
|
+
You can read about how HSM works [in my blog post](https://samual.uk/blog/js-code-transformation-niche-environment/).
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
1. [Install Node.js](https://nodejs.org/en/download)
|
|
22
|
+
2. Run `npm install -g hackmud-script-manager`
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
1. Run `#dir` in game, then `cd` to that folder
|
|
27
|
+
2. Name your source script file to `<name>.src.js`
|
|
28
|
+
3. Run `hsm minify <name>.src.js` and it will create a minified script file called `<name>.js`
|
|
29
|
+
|
|
30
|
+
> **NOTE:** If you get an error message that looks like this:
|
|
31
|
+
>
|
|
32
|
+
> ```
|
|
33
|
+
> [...]\AppData\Local\pnpm\hsm.ps1 cannot be loaded because running scripts is disabled on this system. [...]
|
|
34
|
+
> ```
|
|
35
|
+
>
|
|
36
|
+
> You will need to run `Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser` in PowerShell as an administrator. For more information, see [Microsoft's page about Execution Policies](https://learn.microsoft.com/en-gb/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4).
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+

|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- Minification
|
|
45
|
+
- This includes auto quine cheating.
|
|
46
|
+
- Supported types are null, numbers, strings, and JSON compatible objects and arrays.
|
|
47
|
+
- Non JSON compatible object keys are quine cheated.
|
|
48
|
+
- Member expressions are converted to index notation so the index string can be quine cheated.
|
|
49
|
+
- And template literals are converted to string concatenation so the strings can be quine cheated.
|
|
50
|
+
- Global variable aliasing.
|
|
51
|
+
- Convert function declarations to arrow function assigned to variable hoisted to the top of the block (`function foo() { ... }` -> `let foo = () => ...`).
|
|
52
|
+
- Convert `_START` and `_TIMEOUT` to `_ST` and `_TO`.
|
|
53
|
+
- Remove unused parameters from the main function expression.
|
|
54
|
+
- Modern Javascript Syntax and Features
|
|
55
|
+
- [Exponentiation Operator](https://babeljs.io/docs/en/babel-plugin-transform-exponentiation-operator), [Object Rest Spread](https://babeljs.io/docs/en/babel-plugin-proposal-object-rest-spread), [Optional Catch Binding](https://babeljs.io/docs/en/babel-plugin-proposal-optional-catch-binding), [JSON strings](https://babeljs.io/docs/en/babel-plugin-proposal-json-strings), [Nullish Coalescing Operator](https://babeljs.io/docs/en/babel-plugin-proposal-nullish-coalescing-operator), [Optional Chaining](https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining), [Logical Assignment Operators](https://babeljs.io/docs/en/babel-plugin-proposal-logical-assignment-operators), [Numeric Seperators](https://babeljs.io/docs/en/babel-plugin-proposal-numeric-separator), [Class Properties](https://babeljs.io/docs/en/babel-plugin-proposal-class-properties), [Class Static Block](https://babeljs.io/docs/en/babel-plugin-proposal-class-static-block), [Private Property `in` Object](https://babeljs.io/docs/en/babel-plugin-proposal-private-property-in-object).
|
|
56
|
+
- Bigint literals are converted to `BigInt()` calls.
|
|
57
|
+
- Hackmud already supports all modern regular expression features.
|
|
58
|
+
- Future JavaScript Syntax and Features
|
|
59
|
+
- Warning: TypeScript doesn't support any of these features and these features may change or not actually make it into JavaScript.
|
|
60
|
+
- [Decorators](https://babeljs.io/docs/en/babel-plugin-proposal-decorators), [Do Expressions](https://babeljs.io/docs/en/babel-plugin-proposal-do-expressions), [Function Bind](https://babeljs.io/docs/en/babel-plugin-proposal-function-bind), [Function Sent](https://babeljs.io/docs/en/babel-plugin-proposal-function-sent), [Partial Application](https://babeljs.io/docs/en/babel-plugin-proposal-partial-application), [Pipeline Operator](https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator) (using the hack proposal and `%` as the topic token), [Throw Expression](https://babeljs.io/docs/en/babel-plugin-proposal-throw-expressions), [Record and Tuple](https://babeljs.io/docs/en/babel-plugin-proposal-record-and-tuple) (hash `#` syntax type).
|
|
61
|
+
- TypeScript Support
|
|
62
|
+
- This command/module does **not** do type checking, it simply removes type annotations so you'll need to rely on your IDE or run `tsc` seperatly with `noEmit`.
|
|
63
|
+
- And “Cool” Unnecessary Features.
|
|
64
|
+
- Variables declared outside the main function expression automatically become `#G` global variables.
|
|
65
|
+
- Any code outside the function expression will only run once per top level script execution (`#FMCL`).
|
|
66
|
+
- Basic seclevel verification.
|
|
67
|
+
- Declaring `// @seclevel HIGHSEC` or any other seclevel before all of your code stops you from accidentally using `#ls.` or `#ns.`.
|
|
68
|
+
- Import `node_modules` modules into your script using `import { foo } from "bar"` syntax.
|
|
69
|
+
- `_SOURCE` is replaced with a string of the source code of the script it's in.
|
|
70
|
+
- `_BUILD_DATE` is replaced with a unix timestamp (`Date.now()`) of the build date of the script.
|
|
71
|
+
- `_SCRIPT_USER` is replaced with a string of the user the script was pushed to.
|
|
72
|
+
- This saves characters compared to `context.this_script.split(".")[0]`.
|
|
73
|
+
- `_SCRIPT_SUBNAME` is like `_SCRIPT_USER` but for the name of the script.
|
|
74
|
+
- Saves characters compared to `context.this_script.split(".")[1]`.
|
|
75
|
+
- `_FULL_SCRIPT_NAME` is replaced with what would be in `context.this_script`.
|
|
76
|
+
- Subscript and `#db` methods names are verified.
|
|
77
|
+
- All references to preprocessor syntax functions not being called are turned into arrow function wrappers e.g. `let debug = #D;` -> `let debug = v => #D(v);`.
|
|
78
|
+
- `_SECLEVEL` is replaced with a number (`0` to `4`) representing the seclevel of the script.
|
|
79
|
+
- And Neat Weird Fixes
|
|
80
|
+
- Like `.__proto__` and `.prototype` being converted to `["__proto__"]` and `["prototype"]`.
|
|
81
|
+
- Illegal and unsafe strings.
|
|
82
|
+
- Appearences of `_SC` and friends are either renamed or have an escape inserted so that script is legal.
|
|
83
|
+
- Preprocessor syntax in strings are escaped so hackmud doesn't recognise them as preprocessor syntax.
|
|
84
|
+
- And appearences of `//` in strings and regexes have a backslash inserted between to stop hackmud's overagressive comment remover from removing half the line of code.
|
|
85
|
+
- Classes are actually usable now, this module replaces instances of `this` with a variable referencing what would be `this`.
|
|
86
|
+
- `Function.prototype` can be referenced (but only the `.prototype` property, nothing else).
|
|
87
|
+
- `Object.getPrototypeOf` and `Object.setPrototypeOf` are replaced with equivalent functions.
|