@onkernel/cli 0.10.0 → 0.10.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.
Files changed (2) hide show
  1. package/lib.js +61 -9
  2. package/package.json +20 -19
package/lib.js CHANGED
@@ -6,8 +6,18 @@ const path = require("path");
6
6
  const JSZip = require("jszip");
7
7
  const tar = require("tar");
8
8
  const axios = require("axios");
9
+ const ProxyAgent = require("proxy-agent");
9
10
  const { spawnSync } = require("child_process");
10
11
 
12
+ const proxyUrl =
13
+ process.env.HTTPS_PROXY ||
14
+ process.env.https_proxy ||
15
+ process.env.HTTP_PROXY ||
16
+ process.env.http_proxy ||
17
+ null;
18
+
19
+ const agent = proxyUrl ? new ProxyAgent(proxyUrl) : undefined;
20
+
11
21
  const getArchive = () => {
12
22
  let target = `${process.platform}-${process.arch}`;
13
23
  const archive = archives[target];
@@ -19,31 +29,61 @@ const getArchive = () => {
19
29
 
20
30
  const binDir = path.join(__dirname, "bin");
21
31
 
22
- async function extractTar(tarPath, binaries, dir) {
32
+ async function extractTar(tarPath, binaries, dir, wrappedIn) {
23
33
  try {
34
+ const filesToExtract = wrappedIn
35
+ ? binaries.map((bin) =>
36
+ path.join(wrappedIn, bin).replace(/\\/g, "/"),
37
+ )
38
+ : binaries;
39
+
24
40
  await tar.x({
25
41
  file: tarPath,
26
42
  cwd: dir,
27
- filter: (path) => binaries.includes(path),
43
+ filter: (path) => filesToExtract.includes(path),
28
44
  });
29
- console.log(`Successfully extracted binaries to "${dir}"`);
45
+
46
+ // If wrapped, move files from wrapped directory to bin directory
47
+ if (wrappedIn) {
48
+ const wrappedDir = path.join(dir, wrappedIn);
49
+ for (const binary of binaries) {
50
+ const srcPath = path.join(wrappedDir, binary);
51
+ const destPath = path.join(dir, binary);
52
+ if (fs.existsSync(srcPath)) {
53
+ fs.renameSync(srcPath, destPath);
54
+ }
55
+ }
56
+ // Clean up empty wrapped directory
57
+ try {
58
+ fs.rmSync(wrappedDir, { recursive: true, force: true });
59
+ } catch (err) {
60
+ // Ignore cleanup errors
61
+ }
62
+ }
63
+
64
+ console.log(`Successfully extracted ${binaries} to "${dir}"`);
30
65
  } catch (err) {
31
66
  throw new Error(`Extraction failed: ${err.message}`);
32
67
  }
33
68
  }
34
69
 
35
- async function extractZip(zipPath, binaries, dir) {
70
+ async function extractZip(zipPath, binaries, dir, wrappedIn) {
36
71
  try {
37
72
  const zipData = fs.readFileSync(zipPath);
38
73
  const zip = await JSZip.loadAsync(zipData);
74
+
39
75
  for (const binary of binaries) {
40
- if (!zip.files[binary]) {
76
+ const binaryPath = wrappedIn
77
+ ? path.join(wrappedIn, binary).replace(/\\/g, "/")
78
+ : binary;
79
+
80
+ if (!zip.files[binaryPath]) {
41
81
  throw new Error(
42
- `Error: ${binary} does not exist in ${zipPath}`,
82
+ `Error: ${binaryPath} does not exist in ${zipPath}`,
43
83
  );
44
84
  }
45
85
 
46
- const content = await zip.files[binary].async("nodebuffer");
86
+ const content = await zip.files[binaryPath].async("nodebuffer");
47
87
  if (!fs.existsSync(dir)) {
48
88
  fs.mkdirSync(dir, { recursive: true });
49
89
  }
@@ -94,11 +134,21 @@ const install = async () => {
94
134
  fs.chmodSync(bin, 0o755);
95
135
  return;
96
136
  case "zip":
97
- return extractZip(archivePath, archive.bins, binDir);
137
+ return extractZip(
138
+ archivePath,
139
+ archive.bins,
140
+ binDir,
141
+ archive.wrappedIn,
142
+ );
98
143
  case "tar":
99
144
  case "tar.gz":
100
145
  case "tgz":
101
- return extractTar(archivePath, archive.bins, binDir);
146
+ return extractTar(
147
+ archivePath,
148
+ archive.bins,
149
+ binDir,
150
+ archive.wrappedIn,
151
+ );
102
152
  case "tar.zst":
103
153
  case "tzst":
104
154
  case "tar.xz":
@@ -140,6 +190,8 @@ const download = async (url, filename) => {
140
190
  url: url,
141
191
  responseType: "stream",
142
192
  timeout: 300000, // 5min
193
+ httpAgent: agent,
194
+ httpsAgent: agent,
143
195
  });
144
196
 
145
197
  const writer = fs.createWriteStream(filename);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onkernel/cli",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Kernel CLI",
5
5
  "scripts": {
6
6
  "postinstall": "node install.js",
@@ -29,79 +29,80 @@
29
29
  "dependencies": {
30
30
  "axios": "^1.8.2",
31
31
  "jszip": "^3.10.1",
32
+ "proxy-agent": "^6.5.0",
32
33
  "tar": "^7.4.3"
33
34
  },
34
35
  "archives": {
35
36
  "darwin-arm64": {
36
- "name": "kernel_0.10.0_darwin_arm64.tar.gz",
37
- "url": "https://github.com/onkernel/cli/releases/download/v0.10.0/kernel_0.10.0_darwin_arm64.tar.gz",
37
+ "name": "kernel_0.10.1_darwin_arm64.tar.gz",
38
+ "url": "https://github.com/onkernel/cli/releases/download/v0.10.1/kernel_0.10.1_darwin_arm64.tar.gz",
38
39
  "bins": [
39
40
  "kernel"
40
41
  ],
41
42
  "format": "tar.gz",
42
43
  "checksum": {
43
44
  "algorithm": "sha256",
44
- "digest": "b230200efd876777345d705e60ed44e064ee85dd28040ded956c4c4b8f3b9360"
45
+ "digest": "7c8d3028baca527d42bd99f52bf48d21f8470a9680664ca69436b6093a5583a3"
45
46
  }
46
47
  },
47
48
  "darwin-x64": {
48
- "name": "kernel_0.10.0_darwin_amd64.tar.gz",
49
- "url": "https://github.com/onkernel/cli/releases/download/v0.10.0/kernel_0.10.0_darwin_amd64.tar.gz",
49
+ "name": "kernel_0.10.1_darwin_amd64.tar.gz",
50
+ "url": "https://github.com/onkernel/cli/releases/download/v0.10.1/kernel_0.10.1_darwin_amd64.tar.gz",
50
51
  "bins": [
51
52
  "kernel"
52
53
  ],
53
54
  "format": "tar.gz",
54
55
  "checksum": {
55
56
  "algorithm": "sha256",
56
- "digest": "7d95facb8f7d61b88d9116ed91e33941855f1f316ceffcd49e1215fd48f07615"
57
+ "digest": "34c0d640c4285bba4e27ad0d7ec3e8fbe3ad859cd7cdf115d12871e200c67114"
57
58
  }
58
59
  },
59
60
  "linux-arm64": {
60
- "name": "kernel_0.10.0_linux_arm64.tar.gz",
61
- "url": "https://github.com/onkernel/cli/releases/download/v0.10.0/kernel_0.10.0_linux_arm64.tar.gz",
61
+ "name": "kernel_0.10.1_linux_arm64.tar.gz",
62
+ "url": "https://github.com/onkernel/cli/releases/download/v0.10.1/kernel_0.10.1_linux_arm64.tar.gz",
62
63
  "bins": [
63
64
  "kernel"
64
65
  ],
65
66
  "format": "tar.gz",
66
67
  "checksum": {
67
68
  "algorithm": "sha256",
68
- "digest": "400c1262d5556e9930e4894e4b1865085681f37fc82e4dee6c8f13cc65e717bc"
69
+ "digest": "0a47a1e0292c96635d932b582b9054fd639ec30bd400dd76de20144f6f60f629"
69
70
  }
70
71
  },
71
72
  "linux-x64": {
72
- "name": "kernel_0.10.0_linux_amd64.tar.gz",
73
- "url": "https://github.com/onkernel/cli/releases/download/v0.10.0/kernel_0.10.0_linux_amd64.tar.gz",
73
+ "name": "kernel_0.10.1_linux_amd64.tar.gz",
74
+ "url": "https://github.com/onkernel/cli/releases/download/v0.10.1/kernel_0.10.1_linux_amd64.tar.gz",
74
75
  "bins": [
75
76
  "kernel"
76
77
  ],
77
78
  "format": "tar.gz",
78
79
  "checksum": {
79
80
  "algorithm": "sha256",
80
- "digest": "ceeebb892a8e71a7288afc1eb990b2af8b4405db23c205ee19515e0a3e6d6db4"
81
+ "digest": "724e9403c571237dfab1eff0adc56a806b51ca00f6a4e25ca6b1cd117c1836e4"
81
82
  }
82
83
  },
83
84
  "win32-arm64": {
84
- "name": "kernel_0.10.0_windows_arm64.tar.gz",
85
- "url": "https://github.com/onkernel/cli/releases/download/v0.10.0/kernel_0.10.0_windows_arm64.tar.gz",
85
+ "name": "kernel_0.10.1_windows_arm64.tar.gz",
86
+ "url": "https://github.com/onkernel/cli/releases/download/v0.10.1/kernel_0.10.1_windows_arm64.tar.gz",
86
87
  "bins": [
87
88
  "kernel.exe"
88
89
  ],
89
90
  "format": "tar.gz",
90
91
  "checksum": {
91
92
  "algorithm": "sha256",
92
- "digest": "da408a28b2faca29eefb1a409530a9c9dfb8d7ef40c286b8046822c7a72502b2"
93
+ "digest": "cbd77fc981bd2e4f83314eafe3399caf97a7b9e21d3c19717633a680dc1d2c6d"
93
94
  }
94
95
  },
95
96
  "win32-x64": {
96
- "name": "kernel_0.10.0_windows_amd64.tar.gz",
97
- "url": "https://github.com/onkernel/cli/releases/download/v0.10.0/kernel_0.10.0_windows_amd64.tar.gz",
97
+ "name": "kernel_0.10.1_windows_amd64.tar.gz",
98
+ "url": "https://github.com/onkernel/cli/releases/download/v0.10.1/kernel_0.10.1_windows_amd64.tar.gz",
98
99
  "bins": [
99
100
  "kernel.exe"
100
101
  ],
101
102
  "format": "tar.gz",
102
103
  "checksum": {
103
104
  "algorithm": "sha256",
104
- "digest": "32366beec54a73500670d6efdb6257a207e9e12de9b1781751d0fce64c0c8b9d"
105
+ "digest": "dca0c309789cf7dd79f5c52c360cdbea82092d0f6589a569a2fb07ec7d0e1f1c"
105
106
  }
106
107
  }
107
108
  }