@themoltnet/cli 1.28.0 → 1.30.0

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/install.js +59 -25
  2. package/package.json +7 -7
package/install.js CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const https = require('https');
5
4
  const fs = require('fs');
6
5
  const path = require('path');
7
6
  const zlib = require('zlib');
8
7
  const { execFileSync } = require('child_process');
9
8
 
10
9
  const VERSION = require('./package.json').version;
10
+ const WORKSPACE_PLATFORM_ROOT = path.resolve(__dirname, 'npm');
11
+ const FETCH_TIMEOUT_MS = 15_000;
11
12
 
12
13
  function getBinaryName() {
13
14
  return process.platform === 'win32' ? 'moltnet.exe' : 'moltnet';
@@ -17,20 +18,47 @@ function getPlatformPackageName() {
17
18
  return `@themoltnet/cli-${process.platform}-${process.arch}`;
18
19
  }
19
20
 
20
- // Case 1 (happy path): the platform package was installed via
21
- // optionalDependencies. bin/moltnet.js resolves the binary in place at
22
- // runtime, so install.js has nothing to do.
23
- function tryPlatformPackage() {
21
+ function resolvePlatformPackage() {
24
22
  const pkgName = getPlatformPackageName();
25
23
  try {
26
24
  const pkgDir = path.dirname(require.resolve(`${pkgName}/package.json`));
27
- const binaryPath = path.join(pkgDir, 'bin', getBinaryName());
28
- if (fs.existsSync(binaryPath)) {
29
- return binaryPath;
30
- }
25
+ return {
26
+ binaryPath: path.join(pkgDir, 'bin', getBinaryName()),
27
+ isWorkspacePackage:
28
+ pkgDir === WORKSPACE_PLATFORM_ROOT ||
29
+ pkgDir.startsWith(`${WORKSPACE_PLATFORM_ROOT}${path.sep}`),
30
+ pkgDir,
31
+ };
31
32
  } catch {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ // Case 1 (happy path): the platform package was installed via
38
+ // optionalDependencies. bin/moltnet.js resolves the binary in place at
39
+ // runtime, so install.js has nothing to do.
40
+ function tryPlatformPackage() {
41
+ const resolvedPackage = resolvePlatformPackage();
42
+ if (!resolvedPackage) {
32
43
  // Platform package not installed (e.g. --no-optional, yarn v1 optional bug)
44
+ return null;
45
+ }
46
+
47
+ if (fs.existsSync(resolvedPackage.binaryPath)) {
48
+ return resolvedPackage.binaryPath;
49
+ }
50
+
51
+ // In this monorepo, workspace platform packages resolve during `pnpm install`
52
+ // before their release artifacts exist in the checkout. That should not
53
+ // trigger a registry fetch; the fallback is only for published installs.
54
+ if (resolvedPackage.isWorkspacePackage) {
55
+ console.log(
56
+ `Skipping moltnet binary download for workspace package ${getPlatformPackageName()} ` +
57
+ `(${resolvedPackage.pkgDir})`
58
+ );
59
+ return resolvedPackage.binaryPath;
33
60
  }
61
+
34
62
  return null;
35
63
  }
36
64
 
@@ -39,24 +67,30 @@ function fetch(url, maxRedirects = 5) {
39
67
  if (maxRedirects <= 0) {
40
68
  return reject(new Error('Too many redirects'));
41
69
  }
42
- https
43
- .get(url, { headers: { 'User-Agent': 'themoltnet-cli' } }, (res) => {
44
- if (
45
- res.statusCode >= 300 &&
46
- res.statusCode < 400 &&
47
- res.headers.location
48
- ) {
49
- return resolve(fetch(res.headers.location, maxRedirects - 1));
50
- }
51
- if (res.statusCode !== 200) {
52
- return reject(new Error(`HTTP ${res.statusCode} fetching ${url}`));
70
+ const controller = new AbortController();
71
+ const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
72
+ globalThis
73
+ .fetch(url, {
74
+ headers: { 'User-Agent': 'themoltnet-cli' },
75
+ redirect: 'follow',
76
+ signal: controller.signal,
77
+ })
78
+ .then(async (response) => {
79
+ clearTimeout(timeout);
80
+ if (!response.ok) {
81
+ throw new Error(`HTTP ${response.status} fetching ${url}`);
53
82
  }
54
- const chunks = [];
55
- res.on('data', (chunk) => chunks.push(chunk));
56
- res.on('end', () => resolve(Buffer.concat(chunks)));
57
- res.on('error', reject);
83
+ return Buffer.from(await response.arrayBuffer());
58
84
  })
59
- .on('error', reject);
85
+ .then(resolve)
86
+ .catch((err) => {
87
+ clearTimeout(timeout);
88
+ if (err.name === 'AbortError') {
89
+ reject(new Error(`Request timed out after ${FETCH_TIMEOUT_MS}ms`));
90
+ return;
91
+ }
92
+ reject(err);
93
+ });
60
94
  });
61
95
  }
62
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@themoltnet/cli",
3
- "version": "1.28.0",
3
+ "version": "1.30.0",
4
4
  "description": "CLI for MoltNet — AI agent identity and autonomy network",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,12 +20,12 @@
20
20
  "node": ">=18"
21
21
  },
22
22
  "optionalDependencies": {
23
- "@themoltnet/cli-darwin-arm64": "1.28.0",
24
- "@themoltnet/cli-linux-arm64": "1.28.0",
25
- "@themoltnet/cli-darwin-x64": "1.28.0",
26
- "@themoltnet/cli-win32-arm64": "1.28.0",
27
- "@themoltnet/cli-linux-x64": "1.28.0",
28
- "@themoltnet/cli-win32-x64": "1.28.0"
23
+ "@themoltnet/cli-darwin-x64": "1.30.0",
24
+ "@themoltnet/cli-win32-arm64": "1.30.0",
25
+ "@themoltnet/cli-darwin-arm64": "1.30.0",
26
+ "@themoltnet/cli-win32-x64": "1.30.0",
27
+ "@themoltnet/cli-linux-arm64": "1.30.0",
28
+ "@themoltnet/cli-linux-x64": "1.30.0"
29
29
  },
30
30
  "scripts": {
31
31
  "postinstall": "node install.js"