@oj-bin/oj 0.1.13

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 (3) hide show
  1. package/README.md +52 -0
  2. package/package.json +16 -0
  3. package/postinstall.js +125 -0
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @oj-bin/oj
2
+
3
+ Prebuilt binaries for **only-js** (`oj`) — a low-code backend framework that embeds a
4
+ JavaScript/TypeScript runtime (V8, via `deno_core`) into Rust. Write business logic as
5
+ JS/TS handlers; Rust serves them over HTTP with injected globals (`db`, `kv`, `blob`,
6
+ `bus`, `es`, `fetch`, `WebSocket`, …).
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm i @oj-bin/oj
12
+ ```
13
+
14
+ A postinstall script copies the binaries for your platform into **`./bin/`** of the
15
+ directory where you ran `npm i`:
16
+
17
+ ```
18
+ bin/oj # main CLI (oj.exe on Windows)
19
+ bin/plugins/<triple>/ # backend plugin cdylibs (db/kv/blob/bus/es/auth)
20
+ bin/devkit/ # API manual + global.d.ts
21
+ ```
22
+
23
+ ```bash
24
+ ./bin/oj server -c config.yaml --api-path src
25
+ ```
26
+
27
+ ## Supported platforms
28
+
29
+ | platform | triple |
30
+ |---|---|
31
+ | linux x64 (glibc) | `x86_64-unknown-linux-gnu` |
32
+ | macOS arm64 | `aarch64-apple-darwin` |
33
+ | windows x64 (msvc) | `x86_64-pc-windows-msvc` |
34
+
35
+ Other platforms: download from
36
+ [GitHub Releases](https://github.com/everpan/only-js/releases) or build from source.
37
+
38
+ ## Notes
39
+
40
+ - **pnpm ≥ 10** does not run dependency lifecycle scripts by default; add to
41
+ `pnpm-workspace.yaml`:
42
+ ```yaml
43
+ onlyBuiltDependencies: ["@oj-bin/oj"]
44
+ ```
45
+ - If you install with `--ignore-scripts`, run the installer manually:
46
+ `node node_modules/@oj-bin/oj/postinstall.js`
47
+ - Global install (`npm i -g`) is **not** supported (binaries land in `./bin/` of the
48
+ current project). Use a project-local install or the GitHub Release archives.
49
+ - China mirrors: npmmirror syncs this package automatically —
50
+ `npm i @oj-bin/oj --registry=https://registry.npmmirror.com`
51
+
52
+ Repo & docs: <https://github.com/everpan/only-js>
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@oj-bin/oj",
3
+ "version": "0.1.13",
4
+ "description": "only-js (oj): low-code backend framework embedding a JS/TS runtime (V8) in Rust. Prebuilt binaries; install drops ./bin/oj + plugins + devkit into your project.",
5
+ "keywords": ["only-js", "oj", "low-code", "backend", "v8", "deno", "typescript"],
6
+ "homepage": "https://github.com/everpan/only-js",
7
+ "repository": { "type": "git", "url": "git+https://github.com/everpan/only-js.git" },
8
+ "engines": { "node": ">=16" },
9
+ "scripts": { "postinstall": "node postinstall.js" },
10
+ "optionalDependencies": {
11
+ "@oj-bin/oj-x86_64-unknown-linux-gnu": "0.1.13",
12
+ "@oj-bin/oj-aarch64-apple-darwin": "0.1.13",
13
+ "@oj-bin/oj-x86_64-pc-windows-msvc": "0.1.13"
14
+ },
15
+ "files": ["postinstall.js", "README.md"]
16
+ }
package/postinstall.js ADDED
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ // @oj-bin/oj postinstall —— 把匹配当前平台的子包内容拷到 <项目根>/bin/。
3
+ // 零依赖 CommonJS;可裸跑(--ignore-scripts / pnpm 用户的手动兜底):
4
+ // node node_modules/@oj-bin/oj/postinstall.js
5
+ // 约定:所有「装不上」路径都打印醒目警告并 exit 0 —— 绝不炸掉用户的 npm i。
6
+ 'use strict';
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ // platform-arch → triple 反向表。与 scripts/npm-publish.sh 的 os_cpu_of() 正向表
12
+ // 交叉维护:改一边必须改另一边。
13
+ const TRIPLES = {
14
+ 'linux-x64': 'x86_64-unknown-linux-gnu',
15
+ 'darwin-arm64': 'aarch64-apple-darwin',
16
+ 'win32-x64': 'x86_64-pc-windows-msvc',
17
+ };
18
+ const RELEASES = 'https://github.com/everpan/only-js/releases';
19
+ const TAG = '[@oj-bin/oj]';
20
+
21
+ function bail(msg) { // 装不上:醒目提示 + exit 0;stderr 不可用也要保证 exit 0
22
+ try { fs.writeSync(2, `${TAG} WARN: ${msg}\n`); } catch {}
23
+ process.exit(0);
24
+ }
25
+
26
+ // ---- 1. 支持面检测 ------------------------------------------------------
27
+ if (process.env.npm_config_global === 'true') {
28
+ bail(`不支持全局安装(npm i -g):本包落盘到 <cwd>/bin/,全局安装没有确定的项目根。\n` +
29
+ `请在项目内执行 npm i @oj-bin/oj,或从 ${RELEASES} 下载。`);
30
+ }
31
+
32
+ // ---- 2. 平台 → triple ----------------------------------------------------
33
+ const key = `${process.platform}-${process.arch}`;
34
+ const triple = TRIPLES[key];
35
+ if (!triple) {
36
+ bail(`暂无 ${key} 的预编译包(现有:${Object.keys(TRIPLES).join(', ')})。\n` +
37
+ `请从 ${RELEASES} 下载,或提 issue 请求该平台。`);
38
+ }
39
+
40
+ // ---- 3. 落盘根 -----------------------------------------------------------
41
+ // npm/pnpm/yarn classic 设 INIT_CWD;yarn berry 设 PROJECT_CWD;最后手段上溯三级
42
+ // (scoped 包多一层:<root>/node_modules/@oj-bin/oj → <root>,仅 npm 标准布局碰巧对)。
43
+ const up3 = path.resolve(__dirname, '..', '..', '..');
44
+ const installRoot = process.env.INIT_CWD || process.env.PROJECT_CWD || up3;
45
+
46
+ // --prefix / workspace 子目录哨兵:仅当本包确实处于 npm 标准布局
47
+ // (<root>/node_modules/@oj-bin/oj)且 INIT_CWD 与安装根不一致时才判定——
48
+ // pnpm/.pnpm、berry PnP 布局不套此启发式(它们的 INIT_CWD/PROJECT_CWD 可信)。
49
+ const up1 = path.basename(path.dirname(__dirname));
50
+ const up2 = path.basename(path.dirname(path.dirname(__dirname)));
51
+ let initCwdReal;
52
+ let up3Real;
53
+ if (process.env.INIT_CWD) {
54
+ try {
55
+ initCwdReal = fs.realpathSync(process.env.INIT_CWD);
56
+ up3Real = fs.realpathSync(up3);
57
+ } catch {
58
+ initCwdReal = path.resolve(process.env.INIT_CWD);
59
+ up3Real = up3;
60
+ }
61
+ }
62
+ if (process.env.INIT_CWD && up1 === '@oj-bin' && up2 === 'node_modules' &&
63
+ initCwdReal !== up3Real) {
64
+ bail(`安装根(${up3})与当前目录(${process.env.INIT_CWD})不一致(--prefix 或 workspace 子目录安装)。\n` +
65
+ `为避免装错位置已跳过。请进入目标项目目录重装,或手动执行:\n` +
66
+ ` node ${path.join(__dirname, 'postinstall.js')}`);
67
+ }
68
+
69
+ // ---- 4. 定位平台子包 -----------------------------------------------------
70
+ let subRoot;
71
+ try {
72
+ subRoot = path.dirname(require.resolve(`@oj-bin/oj-${triple}/package.json`));
73
+ } catch {
74
+ bail(`未安装平台子包 @oj-bin/oj-${triple}(可能被 --omit=optional / ignore-scripts 类配置排除)。\n` +
75
+ `请检查安装参数,或从 ${RELEASES} 下载。`);
76
+ }
77
+
78
+ // ---- 5. 拷贝:文件级「临时文件 + rename」原子替换 -------------------------
79
+ // unix:rename 可覆盖正在执行的 bin/oj(避免 ETXTBSY);
80
+ // Windows:已加载的旧 DLL 允许 rename 让位(不允许覆盖写)。
81
+ const destBin = path.join(installRoot, 'bin');
82
+
83
+ function installFile(src, dest) {
84
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
85
+ const tmp = `${dest}.tmp-${process.pid}`;
86
+ const old = `${dest}.old-${process.pid}`;
87
+ fs.copyFileSync(src, tmp);
88
+ try {
89
+ if (fs.existsSync(dest)) fs.renameSync(dest, old);
90
+ fs.renameSync(tmp, dest);
91
+ fs.rmSync(old, { force: true });
92
+ fs.chmodSync(dest, 0o755);
93
+ } catch (e) {
94
+ fs.rmSync(tmp, { force: true });
95
+ throw e;
96
+ }
97
+ }
98
+
99
+ function installTree(srcDir, rel) {
100
+ for (const name of fs.readdirSync(srcDir)) {
101
+ const s = path.join(srcDir, name);
102
+ const r = rel ? `${rel}/${name}` : name;
103
+ if (fs.statSync(s).isDirectory()) installTree(s, r);
104
+ else installFile(s, path.join(destBin, r));
105
+ }
106
+ }
107
+
108
+ let copied = 0;
109
+ try {
110
+ for (const entry of ['oj', 'oj.exe', 'plugins', 'devkit']) {
111
+ const s = path.join(subRoot, entry);
112
+ if (!fs.existsSync(s)) continue;
113
+ if (fs.statSync(s).isDirectory()) installTree(s, entry);
114
+ else installFile(s, path.join(destBin, entry));
115
+ copied++;
116
+ }
117
+ } catch (e) {
118
+ bail(`拷贝失败(${e.code || e.message})。若有正在运行的 oj,请先停止后重试:\n` +
119
+ ` node ${path.join(__dirname, 'postinstall.js')}`);
120
+ }
121
+ if (copied === 0) {
122
+ bail(`平台子包 @oj-bin/oj-${triple} 内容为空(${subRoot}),安装中止。`);
123
+ }
124
+
125
+ console.log(`${TAG} installed → ${destBin} (triple=${triple})`);