openaihub 1.1.0 → 1.1.2
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/lib/config.js +2 -0
- package/lib/install.js +37 -8
- package/package.json +2 -1
- package/runtime/openaihub-windows.zip +0 -0
package/lib/config.js
CHANGED
|
@@ -5,6 +5,7 @@ const path = require('node:path');
|
|
|
5
5
|
|
|
6
6
|
const packageRoot = path.resolve(__dirname, '..');
|
|
7
7
|
const runtimeRoot = path.join(os.homedir(), '.openaihub', 'npm-runtime');
|
|
8
|
+
const bundledRuntimeRoot = path.join(packageRoot, 'runtime');
|
|
8
9
|
|
|
9
10
|
const packageInfo = require(path.join(packageRoot, 'package.json'));
|
|
10
11
|
|
|
@@ -35,6 +36,7 @@ module.exports = {
|
|
|
35
36
|
packageName: packageInfo.name,
|
|
36
37
|
packageVersion: packageInfo.version,
|
|
37
38
|
packageRoot,
|
|
39
|
+
bundledRuntimeRoot,
|
|
38
40
|
runtimeRoot,
|
|
39
41
|
getTagName,
|
|
40
42
|
getPlatformConfig
|
package/lib/install.js
CHANGED
|
@@ -8,6 +8,7 @@ const path = require('node:path');
|
|
|
8
8
|
const { spawn } = require('node:child_process');
|
|
9
9
|
|
|
10
10
|
const {
|
|
11
|
+
bundledRuntimeRoot,
|
|
11
12
|
packageVersion,
|
|
12
13
|
runtimeRoot,
|
|
13
14
|
getPlatformConfig,
|
|
@@ -115,6 +116,20 @@ async function acquireLock(lockPath, timeoutMs = 60000) {
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
|
|
119
|
+
async function removePathWithRetry(targetPath, attempts = 5, delayMs = 400) {
|
|
120
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
121
|
+
try {
|
|
122
|
+
await fsp.rm(targetPath, { recursive: true, force: true });
|
|
123
|
+
return;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (!error || !['EBUSY', 'EPERM', 'ENOTEMPTY'].includes(error.code) || attempt === attempts) {
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs * attempt));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
118
133
|
async function extractArchive(archivePath, extractRoot, extractKind) {
|
|
119
134
|
if (extractKind === 'zip' && process.platform === 'win32') {
|
|
120
135
|
await runCommand('powershell.exe', [
|
|
@@ -152,11 +167,17 @@ function findExecutable(extractRoot, executableName) {
|
|
|
152
167
|
async function ensureInstalled(options = {}) {
|
|
153
168
|
const { quiet = false, force = false } = options;
|
|
154
169
|
const platformConfig = getPlatformConfig();
|
|
155
|
-
const
|
|
170
|
+
const runtimeBaseDir = path.join(runtimeRoot, platformConfig.runtimeKey);
|
|
171
|
+
const runtimeDir = path.join(runtimeBaseDir, packageVersion);
|
|
156
172
|
const executablePath = path.join(runtimeDir, platformConfig.executableRelativePath);
|
|
173
|
+
const bundledArchivePath = path.join(bundledRuntimeRoot, platformConfig.assetName);
|
|
174
|
+
const versionMarkerPath = path.join(runtimeDir, 'version.txt');
|
|
157
175
|
|
|
158
|
-
if (!force && fs.existsSync(executablePath)) {
|
|
159
|
-
|
|
176
|
+
if (!force && fs.existsSync(executablePath) && fs.existsSync(versionMarkerPath)) {
|
|
177
|
+
const installedVersion = fs.readFileSync(versionMarkerPath, 'utf8').trim();
|
|
178
|
+
if (installedVersion === packageVersion) {
|
|
179
|
+
return { executablePath, runtimeDir, downloaded: false };
|
|
180
|
+
}
|
|
160
181
|
}
|
|
161
182
|
|
|
162
183
|
const tempRoot = await fsp.mkdtemp(path.join(os.tmpdir(), 'openaihub-npm-'));
|
|
@@ -177,10 +198,17 @@ async function ensureInstalled(options = {}) {
|
|
|
177
198
|
await fsp.mkdir(extractRoot, { recursive: true });
|
|
178
199
|
await fsp.mkdir(stageRoot, { recursive: true });
|
|
179
200
|
|
|
180
|
-
if (
|
|
181
|
-
|
|
201
|
+
if (fs.existsSync(bundledArchivePath)) {
|
|
202
|
+
if (!quiet) {
|
|
203
|
+
log(`Using bundled runtime archive ${platformConfig.assetName}...`);
|
|
204
|
+
}
|
|
205
|
+
await fsp.copyFile(bundledArchivePath, archivePath);
|
|
206
|
+
} else {
|
|
207
|
+
if (!quiet) {
|
|
208
|
+
log(`Downloading ${platformConfig.assetName}...`);
|
|
209
|
+
}
|
|
210
|
+
await withRetry(() => downloadFile(platformConfig.assetDownloadUrl, archivePath), 3, 'Runtime download');
|
|
182
211
|
}
|
|
183
|
-
await withRetry(() => downloadFile(platformConfig.assetDownloadUrl, archivePath), 3, 'Runtime download');
|
|
184
212
|
|
|
185
213
|
if (!quiet) {
|
|
186
214
|
log('Extracting runtime...');
|
|
@@ -193,8 +221,9 @@ async function ensureInstalled(options = {}) {
|
|
|
193
221
|
}
|
|
194
222
|
|
|
195
223
|
await fsp.cp(extractedRuntimeRoot, stageRoot, { recursive: true, force: true });
|
|
196
|
-
await fsp.
|
|
197
|
-
await
|
|
224
|
+
await fsp.writeFile(path.join(stageRoot, 'version.txt'), `${packageVersion}\n`, 'utf8');
|
|
225
|
+
await removePathWithRetry(runtimeDir);
|
|
226
|
+
await fsp.mkdir(runtimeBaseDir, { recursive: true });
|
|
198
227
|
await fsp.rename(stageRoot, runtimeDir);
|
|
199
228
|
|
|
200
229
|
if (!quiet) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openaihub",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "OpenAI Hub CLI installer and launcher",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"os": [
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"bin",
|
|
21
21
|
"lib",
|
|
22
|
+
"runtime",
|
|
22
23
|
"scripts",
|
|
23
24
|
"README.md"
|
|
24
25
|
],
|
|
Binary file
|