renview 0.0.1
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/LICENSE +21 -0
- package/bin/renview.exe +5 -0
- package/package.json +32 -0
- package/postinstall.mjs +116 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Firede
|
|
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/bin/renview.exe
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// postinstall 未运行时的占位桩:bin 链接先指向这里,postinstall 会把它替换成真正的原生二进制
|
|
3
|
+
console.error("renview: the postinstall script did not run, so the binary is missing.");
|
|
4
|
+
console.error("Reinstall without --ignore-scripts, or use: curl -fsSL https://renview.6636.tech/install | bash");
|
|
5
|
+
process.exit(1);
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "renview",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "帮助人类降低认知负担的代码审核工具",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bin": {
|
|
7
|
+
"renview": "./bin/renview.exe"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node ./postinstall.mjs"
|
|
11
|
+
},
|
|
12
|
+
"os": [
|
|
13
|
+
"darwin",
|
|
14
|
+
"linux",
|
|
15
|
+
"win32"
|
|
16
|
+
],
|
|
17
|
+
"cpu": [
|
|
18
|
+
"arm64",
|
|
19
|
+
"x64"
|
|
20
|
+
],
|
|
21
|
+
"optionalDependencies": {
|
|
22
|
+
"renview-darwin-arm64": "0.0.1",
|
|
23
|
+
"renview-darwin-x64": "0.0.1",
|
|
24
|
+
"renview-linux-x64": "0.0.1",
|
|
25
|
+
"renview-linux-arm64": "0.0.1",
|
|
26
|
+
"renview-windows-x64": "0.0.1"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/firede/renview.git"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* renview 壳包 postinstall:平台包(optionalDependencies,按 os/cpu 过滤安装)里的二进制
|
|
3
|
+
* 硬链接到 bin 桩位;optional dep 未装上时(--no-optional / yarn1 等)从 registry 下载兜底。
|
|
4
|
+
* 纯 node 无依赖,任何包管理器的安装期都能跑。
|
|
5
|
+
*/
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
import * as os from "node:os";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
|
|
14
|
+
const pkgDir = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const binPath = path.join(pkgDir, "bin", "renview.exe");
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
const version = require("./package.json").version;
|
|
18
|
+
|
|
19
|
+
const OS = { darwin: "darwin", linux: "linux", win32: "windows" };
|
|
20
|
+
const CPU = { arm64: "arm64", x64: "x64" };
|
|
21
|
+
|
|
22
|
+
function fail(message) {
|
|
23
|
+
console.error(`renview: ${message}`);
|
|
24
|
+
console.error("renview: 也可以改用安装脚本:curl -fsSL https://renview.6636.tech/install | bash");
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const platform = OS[process.platform];
|
|
29
|
+
const arch = CPU[process.arch];
|
|
30
|
+
if (!platform || !arch) fail(`unsupported platform: ${process.platform} ${process.arch}`);
|
|
31
|
+
if (platform === "windows" && arch !== "x64") fail("Windows arm64 is not supported yet; use WSL");
|
|
32
|
+
const platformPkg = `renview-${platform}-${arch}`;
|
|
33
|
+
const binName = platform === "windows" ? "renview.exe" : "renview";
|
|
34
|
+
|
|
35
|
+
function linkBinary(source) {
|
|
36
|
+
fs.rmSync(binPath, { force: true });
|
|
37
|
+
try {
|
|
38
|
+
fs.linkSync(source, binPath);
|
|
39
|
+
} catch {
|
|
40
|
+
fs.copyFileSync(source, binPath);
|
|
41
|
+
}
|
|
42
|
+
if (platform !== "windows") fs.chmodSync(binPath, 0o755);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** optional dep 已按 os/cpu 装上时,直接取其 bin 下的二进制 */
|
|
46
|
+
function fromOptionalDependency() {
|
|
47
|
+
try {
|
|
48
|
+
const depPkgJson = require.resolve(`${platformPkg}/package.json`);
|
|
49
|
+
const candidate = path.join(path.dirname(depPkgJson), "bin", binName);
|
|
50
|
+
return fs.existsSync(candidate) ? candidate : null;
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** optional dep 缺失时的兜底:从 registry 元数据取 tarball 地址,下载 + 校验 sha512 + 解压 */
|
|
57
|
+
async function fromRegistry() {
|
|
58
|
+
const registry = (process.env.npm_config_registry || "https://registry.npmjs.org").replace(
|
|
59
|
+
/\/+$/,
|
|
60
|
+
"",
|
|
61
|
+
);
|
|
62
|
+
const metaRes = await fetch(`${registry}/${platformPkg}/${version}`);
|
|
63
|
+
if (!metaRes.ok) {
|
|
64
|
+
fail(`platform package ${platformPkg}@${version} not found on ${registry}`);
|
|
65
|
+
}
|
|
66
|
+
const meta = await metaRes.json();
|
|
67
|
+
const url = meta?.dist?.tarball;
|
|
68
|
+
const integrity = meta?.dist?.integrity;
|
|
69
|
+
if (!url) fail(`registry metadata for ${platformPkg}@${version} has no tarball URL`);
|
|
70
|
+
|
|
71
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "renview-postinstall-"));
|
|
72
|
+
try {
|
|
73
|
+
const res = await fetch(url);
|
|
74
|
+
if (!res.ok) fail(`download failed: ${url} (HTTP ${res.status})`);
|
|
75
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
76
|
+
if (typeof integrity === "string" && integrity.startsWith("sha512-")) {
|
|
77
|
+
const actual = `sha512-${createHash("sha512").update(buf).digest("base64")}`;
|
|
78
|
+
if (actual !== integrity) fail(`integrity check failed for ${platformPkg}@${version}`);
|
|
79
|
+
}
|
|
80
|
+
const tgz = path.join(tmp, "pkg.tgz");
|
|
81
|
+
fs.writeFileSync(tgz, buf);
|
|
82
|
+
// win10+ 自带 bsdtar,macOS/Linux 必有 tar
|
|
83
|
+
execFileSync("tar", ["-xzf", tgz, "-C", tmp], { stdio: "ignore" });
|
|
84
|
+
const extracted = path.join(tmp, "package", "bin", binName);
|
|
85
|
+
if (!fs.existsSync(extracted)) fail(`tarball of ${platformPkg}@${version} has no bin/${binName}`);
|
|
86
|
+
linkBinary(extracted);
|
|
87
|
+
} finally {
|
|
88
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const local = fromOptionalDependency();
|
|
93
|
+
if (local) {
|
|
94
|
+
linkBinary(local);
|
|
95
|
+
} else {
|
|
96
|
+
console.warn(`renview: optional dependency ${platformPkg} not installed, downloading from registry…`);
|
|
97
|
+
try {
|
|
98
|
+
await fromRegistry();
|
|
99
|
+
} catch (e) {
|
|
100
|
+
fail(e instanceof Error ? e.message : String(e));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 装完验证一次:跑不起来(如 glibc 过旧)时尽早暴露,而不是留一个坏二进制
|
|
105
|
+
try {
|
|
106
|
+
const out = execFileSync(binPath, ["--version"], {
|
|
107
|
+
encoding: "utf8",
|
|
108
|
+
timeout: 15000,
|
|
109
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
110
|
+
}).trim();
|
|
111
|
+
if (out !== version) {
|
|
112
|
+
console.warn(`renview: installed binary reports version ${out}, expected ${version}`);
|
|
113
|
+
}
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.warn(`renview: installed binary failed to run: ${e instanceof Error ? e.message : e}`);
|
|
116
|
+
}
|