@ghl-ai/aw 0.1.57 → 0.1.58-beta.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.
@@ -1,72 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { spawnSync } from 'node:child_process';
3
- import { dirname, join } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
-
6
- const SELF_PATH = fileURLToPath(import.meta.url);
7
-
8
- export function detectPackageManager(selfPath = SELF_PATH) {
9
- const normalizedPath = String(selfPath || '').replace(/\\/g, '/');
10
- if (normalizedPath.includes('/.volta/')) return 'volta';
11
- if (normalizedPath.includes('/pnpm/')) return 'pnpm';
12
- return 'npm';
13
- }
14
-
15
- export function buildGlobalPackageInstall(packageSpec, options = {}) {
16
- const packageManager = options.packageManager || detectPackageManager(options.selfPath);
17
- if (packageManager === 'volta') {
18
- return { packageManager, command: 'volta', args: ['install', packageSpec] };
19
- }
20
- if (packageManager === 'pnpm') {
21
- return { packageManager, command: 'pnpm', args: ['add', '-g', packageSpec] };
22
- }
23
- return { packageManager: 'npm', command: 'npm', args: ['i', '-g', packageSpec] };
24
- }
25
-
26
- export function formatCommand({ command, args = [] }) {
27
- return [command, ...args].join(' ');
28
- }
29
-
30
- export function installGlobalPackage(packageSpec, options = {}) {
31
- const plan = buildGlobalPackageInstall(packageSpec, options);
32
- const result = spawnSync(plan.command, plan.args, {
33
- cwd: options.cwd,
34
- env: options.env || process.env,
35
- encoding: 'utf8',
36
- stdio: options.stdio || 'pipe',
37
- timeout: options.timeout || 5 * 60 * 1000,
38
- });
39
-
40
- return {
41
- ...plan,
42
- ok: result.status === 0,
43
- status: result.status,
44
- stdout: result.stdout || '',
45
- stderr: result.stderr || '',
46
- error: result.error || null,
47
- commandLine: formatCommand(plan),
48
- };
49
- }
50
-
51
- export function getNpmPrefixBin(options = {}) {
52
- const runner = options.runner || spawnSync;
53
- const result = runner('npm', ['prefix', '-g'], {
54
- env: options.env || process.env,
55
- encoding: 'utf8',
56
- stdio: 'pipe',
57
- timeout: options.timeout || 10_000,
58
- });
59
- if (result.status !== 0) return null;
60
- const prefix = String(result.stdout || '').trim();
61
- if (!prefix) return null;
62
- return join(prefix, process.platform === 'win32' ? '' : 'bin');
63
- }
64
-
65
- export function getAwPackageRoot(selfPath = SELF_PATH) {
66
- if (selfPath.endsWith('package-manager.mjs')) return dirname(selfPath);
67
- return dirname(selfPath);
68
- }
69
-
70
- export function executableExists(path) {
71
- return Boolean(path && existsSync(path));
72
- }