@goxjs/goxjs 0.1.0
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 +48 -0
- package/bin/gox.js +27 -0
- package/binaries/darwin-arm64/gox +0 -0
- package/binaries/darwin-x64/gox +0 -0
- package/binaries/linux-arm64/gox +0 -0
- package/binaries/linux-x64/gox +0 -0
- package/binaries/windows-x64/gox.exe +0 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @goxjs/goxjs
|
|
2
|
+
|
|
3
|
+
> Gox JavaScript Runtime — 用 Go 从零实现的 JavaScript 运行时:词法分析 → 语法分析 → 字节码编译 → 栈式虚拟机执行。单二进制、零外部依赖。
|
|
4
|
+
|
|
5
|
+
本包把 Gox 的各平台二进制分发到 npm,安装后直接获得 `goxjs` 命令。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i -g @goxjs/goxjs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
**REPL:**
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
goxjs
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
Gox REPL (ES6 subset, no var)
|
|
23
|
+
Type :exit to quit, :help for help
|
|
24
|
+
|
|
25
|
+
> let x = 10
|
|
26
|
+
> [1, 2, 3].map(v => v * 2)
|
|
27
|
+
[2, 4, 6]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**运行脚本:**
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
goxjs app.js
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**免安装直接跑:**
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npx goxjs app.js
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
支持 ES6+ 语言子集(`let`/`const`、class、`async`/`await`、解构、模板字符串、ES 模块),内置 `Array` / `Map` / `Set` / `Promise` / `BigInt` / `Temporal` 等标准对象,以及 `fs` / `http` / `fetch` / `path` / `process` 等 Node 风格宿主 API。
|
|
43
|
+
|
|
44
|
+
完整文档与语言示例见 [GitHub 仓库](https://github.com/14752222/Gox)。
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
[Apache License 2.0](https://github.com/14752222/Gox/blob/main/LICENSE)
|
package/bin/gox.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// goxjs 命令入口: 检测平台后把参数原样转发给对应架构的 Gox 二进制。
|
|
3
|
+
var spawn = require('child_process').spawn;
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
// 二进制路径: 若未来拆出平台分包 (goxjs-darwin-arm64 等, 其 index.js 导出二进制路径)
|
|
7
|
+
// 则优先从分包取; 否则用本包自带的 binaries/ 目录。
|
|
8
|
+
var osName = process.platform === 'win32' ? 'windows' : process.platform;
|
|
9
|
+
var bin;
|
|
10
|
+
try {
|
|
11
|
+
bin = require('goxjs-' + process.platform + '-' + process.arch);
|
|
12
|
+
} catch (_) {
|
|
13
|
+
bin = path.join(__dirname, '..', 'binaries',
|
|
14
|
+
osName + '-' + process.arch,
|
|
15
|
+
process.platform === 'win32' ? 'gox.exe' : 'gox');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var child = spawn(bin, process.argv.slice(2), { stdio: 'inherit' });
|
|
19
|
+
child.on('error', function (err) {
|
|
20
|
+
console.error('goxjs: 无法启动平台二进制 (' + err.message + ')');
|
|
21
|
+
console.error('请尝试重新安装: npm i -g @goxjs/goxjs');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
});
|
|
24
|
+
child.on('close', function (code, signal) {
|
|
25
|
+
if (signal) process.kill(process.pid, signal);
|
|
26
|
+
else process.exit(code == null ? 0 : code);
|
|
27
|
+
});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@goxjs/goxjs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Gox — 用 Go 从零实现的 JavaScript 运行时(lexer → parser → 字节码 VM),单二进制零外部依赖",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/14752222/Gox.git"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"goxjs": "bin/gox.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/gox.js",
|
|
15
|
+
"binaries/"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=14"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"javascript",
|
|
22
|
+
"runtime",
|
|
23
|
+
"interpreter",
|
|
24
|
+
"bytecode-vm",
|
|
25
|
+
"go"
|
|
26
|
+
]
|
|
27
|
+
}
|