@kosli/cli 2.13.1-SNAPSHOT-b45c7e65 → 2.13.1-SNAPSHOT-b45c7e67
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/bin/kosli +111 -13
- package/package.json +13 -9
package/bin/kosli
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
const { spawnSync } = require("child_process");
|
|
5
5
|
const path = require("path");
|
|
6
|
+
const https = require("https");
|
|
7
|
+
const http = require("http");
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const os = require("os");
|
|
6
10
|
|
|
7
11
|
const platform = process.platform;
|
|
8
12
|
const arch = process.arch;
|
|
@@ -23,24 +27,118 @@ if (!SUPPORTED[platform] || !SUPPORTED[platform][arch]) {
|
|
|
23
27
|
|
|
24
28
|
const packageName = `@kosli/cli-${platform}-${arch}`;
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
// Try the optional platform package first (installed via npm install / npm install -g)
|
|
31
|
+
let resolvedBinaryPath = null;
|
|
27
32
|
try {
|
|
28
33
|
const packageDir = path.dirname(
|
|
29
34
|
require.resolve(`${packageName}/package.json`)
|
|
30
35
|
);
|
|
31
36
|
const binaryName = platform === "win32" ? "kosli.exe" : "kosli";
|
|
32
|
-
|
|
33
|
-
} catch (
|
|
34
|
-
|
|
35
|
-
`[kosli] Error: platform package ${packageName} is not installed.\n` +
|
|
36
|
-
`[kosli] Try reinstalling: npm install -g @kosli/cli\n`
|
|
37
|
-
);
|
|
38
|
-
process.exit(1);
|
|
37
|
+
resolvedBinaryPath = path.join(packageDir, "bin", binaryName);
|
|
38
|
+
} catch (_) {
|
|
39
|
+
// Optional dep not present — will fall back to on-demand download below (npx case)
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
process.
|
|
42
|
+
async function run() {
|
|
43
|
+
const binaryPath = resolvedBinaryPath ?? await getOrDownloadBinary();
|
|
44
|
+
|
|
45
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
|
|
46
|
+
if (result.error) {
|
|
47
|
+
process.stderr.write(`[kosli] Error: failed to run binary: ${result.error.message}\n`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
process.exit(result.status ?? 1);
|
|
45
51
|
}
|
|
46
|
-
|
|
52
|
+
|
|
53
|
+
async function getOrDownloadBinary() {
|
|
54
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
|
|
55
|
+
const version = pkg.version;
|
|
56
|
+
|
|
57
|
+
if (!version || version === "0.0.0") {
|
|
58
|
+
process.stderr.write(
|
|
59
|
+
`[kosli] Error: package version is "${version}" — cannot determine which binary to download.\n` +
|
|
60
|
+
`[kosli] Try: npm install -g @kosli/cli\n`
|
|
61
|
+
);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const binaryName = platform === "win32" ? "kosli.exe" : "kosli";
|
|
66
|
+
|
|
67
|
+
// Cache under ~/.cache/kosli/<version>/<platform>-<arch>/kosli[.exe]
|
|
68
|
+
const cacheDir = path.join(os.homedir(), ".cache", "kosli", version, `${platform}-${arch}`);
|
|
69
|
+
const cachedBinary = path.join(cacheDir, binaryName);
|
|
70
|
+
|
|
71
|
+
if (fs.existsSync(cachedBinary)) {
|
|
72
|
+
return cachedBinary;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Build GitHub release download URL
|
|
76
|
+
// npm platform → goreleaser OS/arch naming
|
|
77
|
+
const goOs = { darwin: "darwin", linux: "linux", win32: "windows" }[platform];
|
|
78
|
+
const goArch = { x64: "amd64", arm64: "arm64", arm: "armv6" }[arch];
|
|
79
|
+
const ext = platform === "win32" ? "zip" : "tar.gz";
|
|
80
|
+
const versionNoV = version.replace(/^v/, "");
|
|
81
|
+
const archiveName = `kosli_${versionNoV}_${goOs}_${goArch}.${ext}`;
|
|
82
|
+
const downloadUrl = `https://github.com/kosli-dev/cli/releases/download/v${versionNoV}/${archiveName}`;
|
|
83
|
+
|
|
84
|
+
process.stderr.write(`[kosli] Downloading ${archiveName}...\n`);
|
|
85
|
+
|
|
86
|
+
const tmpFile = path.join(os.tmpdir(), `kosli-download-${process.pid}.${ext}`);
|
|
87
|
+
try {
|
|
88
|
+
await downloadToFile(downloadUrl, tmpFile);
|
|
89
|
+
|
|
90
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
91
|
+
|
|
92
|
+
// Extract just the binary from the archive.
|
|
93
|
+
// The binary sits at the archive root (no wrapping directory).
|
|
94
|
+
// `tar` on Linux/macOS handles tar.gz; bsdtar (Windows 10+) handles both tar.gz and zip.
|
|
95
|
+
const tarFlags = ext === "tar.gz" ? ["-xzf"] : ["-xf"];
|
|
96
|
+
const tarResult = spawnSync(
|
|
97
|
+
"tar",
|
|
98
|
+
[...tarFlags, tmpFile, binaryName, "-C", cacheDir],
|
|
99
|
+
{ stdio: ["ignore", "ignore", "pipe"] }
|
|
100
|
+
);
|
|
101
|
+
if (tarResult.status !== 0 || !fs.existsSync(cachedBinary)) {
|
|
102
|
+
const detail = tarResult.stderr ? tarResult.stderr.toString().trim() : "unknown error";
|
|
103
|
+
throw new Error(`Extraction failed: ${detail}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (platform !== "win32") {
|
|
107
|
+
fs.chmodSync(cachedBinary, 0o755);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return cachedBinary;
|
|
111
|
+
} finally {
|
|
112
|
+
try { fs.unlinkSync(tmpFile); } catch (_) {}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function downloadToFile(url, dest) {
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
function get(url) {
|
|
119
|
+
const mod = url.startsWith("https://") ? https : http;
|
|
120
|
+
mod.get(url, (res) => {
|
|
121
|
+
if ([301, 302, 307, 308].includes(res.statusCode)) {
|
|
122
|
+
res.resume();
|
|
123
|
+
return get(res.headers.location);
|
|
124
|
+
}
|
|
125
|
+
if (res.statusCode !== 200) {
|
|
126
|
+
res.resume();
|
|
127
|
+
return reject(new Error(`HTTP ${res.statusCode} from ${url}`));
|
|
128
|
+
}
|
|
129
|
+
const file = fs.createWriteStream(dest);
|
|
130
|
+
res.pipe(file);
|
|
131
|
+
file.on("finish", () => file.close(resolve));
|
|
132
|
+
file.on("error", (err) => { fs.unlink(dest, () => {}); reject(err); });
|
|
133
|
+
res.on("error", reject);
|
|
134
|
+
}).on("error", reject);
|
|
135
|
+
}
|
|
136
|
+
get(url);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
run().catch((err) => {
|
|
141
|
+
process.stderr.write(`[kosli] Error: ${err.message}\n`);
|
|
142
|
+
process.stderr.write(`[kosli] Try: npm install -g @kosli/cli\n`);
|
|
143
|
+
process.exit(1);
|
|
144
|
+
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosli/cli",
|
|
3
|
-
"version": "2.13.1-SNAPSHOT-
|
|
3
|
+
"version": "2.13.1-SNAPSHOT-b45c7e67",
|
|
4
4
|
"description": "CLI client for reporting compliance events to https://kosli.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Kosli Inc. <hello@kosli.com>",
|
|
7
7
|
"homepage": "https://kosli.com",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/kosli-dev/cli.git"
|
|
10
|
+
"url": "git+https://github.com/kosli-dev/cli.git",
|
|
11
|
+
"directory": "npm/wrapper"
|
|
11
12
|
},
|
|
12
13
|
"bugs": {
|
|
13
14
|
"url": "https://github.com/kosli-dev/cli/issues"
|
|
@@ -19,6 +20,9 @@
|
|
|
19
20
|
"supply-chain",
|
|
20
21
|
"devops"
|
|
21
22
|
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
22
26
|
"bin": {
|
|
23
27
|
"kosli": "bin/kosli"
|
|
24
28
|
},
|
|
@@ -30,13 +34,13 @@
|
|
|
30
34
|
"postinstall": "node install.js"
|
|
31
35
|
},
|
|
32
36
|
"optionalDependencies": {
|
|
33
|
-
"@kosli/cli-darwin-arm64": "2.13.1-SNAPSHOT-
|
|
34
|
-
"@kosli/cli-darwin-x64": "2.13.1-SNAPSHOT-
|
|
35
|
-
"@kosli/cli-linux-arm": "2.13.1-SNAPSHOT-
|
|
36
|
-
"@kosli/cli-linux-arm64": "2.13.1-SNAPSHOT-
|
|
37
|
-
"@kosli/cli-linux-x64": "2.13.1-SNAPSHOT-
|
|
38
|
-
"@kosli/cli-win32-arm64": "2.13.1-SNAPSHOT-
|
|
39
|
-
"@kosli/cli-win32-x64": "2.13.1-SNAPSHOT-
|
|
37
|
+
"@kosli/cli-darwin-arm64": "2.13.1-SNAPSHOT-b45c7e67",
|
|
38
|
+
"@kosli/cli-darwin-x64": "2.13.1-SNAPSHOT-b45c7e67",
|
|
39
|
+
"@kosli/cli-linux-arm": "2.13.1-SNAPSHOT-b45c7e67",
|
|
40
|
+
"@kosli/cli-linux-arm64": "2.13.1-SNAPSHOT-b45c7e67",
|
|
41
|
+
"@kosli/cli-linux-x64": "2.13.1-SNAPSHOT-b45c7e67",
|
|
42
|
+
"@kosli/cli-win32-arm64": "2.13.1-SNAPSHOT-b45c7e67",
|
|
43
|
+
"@kosli/cli-win32-x64": "2.13.1-SNAPSHOT-b45c7e67"
|
|
40
44
|
},
|
|
41
45
|
"publishConfig": {
|
|
42
46
|
"registry": "https://registry.npmjs.org",
|