@jmanuelcorral/bond-app 0.3.1 → 0.3.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/app/mods/bond-settings/main.js +16 -8
- package/package.json +1 -1
- package/src/cli.ts +9 -2
- package/src/core/service-windows.ts +1 -1
- package/src/core/service.ts +2 -0
- package/src/core/setup-install.ts +79 -24
|
@@ -399,21 +399,29 @@ export default class BondSettings extends View {
|
|
|
399
399
|
|
|
400
400
|
/** `bond-app update` in a space of its own on this computer: bond-app, bond, mods and service. */
|
|
401
401
|
runUpdate() {
|
|
402
|
+
this.runInSpace("bond-app update", updateCommand(), "Actualizando bond-app: al terminar, el orquestador se reinicia.");
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* A bond-app command in a space of its own on this computer. Ajustes closes first: the space
|
|
407
|
+
* would open behind the dialog (and `diagnose --issue` asks there before sending anything).
|
|
408
|
+
*/
|
|
409
|
+
runInSpace(name, argv, message) {
|
|
410
|
+
const overlay = props()?.overlay;
|
|
402
411
|
try {
|
|
403
|
-
|
|
404
|
-
|
|
412
|
+
if (overlay) closeOverlay(overlay);
|
|
413
|
+
run("space.new", { name, machine: "", argv, focus: true });
|
|
414
|
+
notify({ title: name, body: message, level: "info" });
|
|
405
415
|
} catch (e) {
|
|
406
|
-
|
|
416
|
+
notify({ title: `No se pudo abrir «${name}»`, body: String(e?.message ?? e), level: "error" });
|
|
407
417
|
}
|
|
408
418
|
}
|
|
409
419
|
|
|
410
420
|
/** «Exportar diagnóstico» / «Abrir issue»: bond-app diagnose in a space of its own (works with the orchestrator down). */
|
|
411
421
|
runDiagnose(issue) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
this.error = `Diagnóstico: ${String(e?.message ?? e)}`;
|
|
416
|
-
}
|
|
422
|
+
this.runInSpace(issue ? "bond-app issue" : "bond-app diagnose", diagnoseCommand(issue), issue
|
|
423
|
+
? "Revisa lo que se va a enviar y contesta en ese espacio si abre la issue."
|
|
424
|
+
: "El zip queda en la carpeta de datos de bond-app; la ruta sale en ese espacio.");
|
|
417
425
|
}
|
|
418
426
|
|
|
419
427
|
diagnoseBlock() {
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -278,9 +278,15 @@ export async function handleStart(
|
|
|
278
278
|
setupDeps?: SetupDeps
|
|
279
279
|
): Promise<number> {
|
|
280
280
|
const overrides: Record<string, any> = {};
|
|
281
|
+
// Started by the user service itself (its unit/plist/task passes --as-service; launchd also
|
|
282
|
+
// names the job in XPC_SERVICE_NAME, for plists from before the flag): the service being
|
|
283
|
+
// «active» is this very process, not another one on the port (issue #5).
|
|
284
|
+
let asService = /(^|\.)bond-app\./.test(process.env.XPC_SERVICE_NAME ?? '');
|
|
281
285
|
for (let i = 0; i < args.length; i++) {
|
|
282
286
|
const arg = args[i];
|
|
283
|
-
if (arg === '--
|
|
287
|
+
if (arg === '--as-service') {
|
|
288
|
+
asService = true;
|
|
289
|
+
} else if (arg === '--port') {
|
|
284
290
|
const v = args[++i];
|
|
285
291
|
if (!v || v.startsWith('--')) throw new Error('--port requires a value');
|
|
286
292
|
overrides.port = parseInt(v, 10);
|
|
@@ -326,7 +332,7 @@ export async function handleStart(
|
|
|
326
332
|
dataDir: startDataDir,
|
|
327
333
|
deps: setupDeps?.serviceDeps,
|
|
328
334
|
});
|
|
329
|
-
if (svcStatus.active) {
|
|
335
|
+
if (svcStatus.active && !asService) {
|
|
330
336
|
console.error(
|
|
331
337
|
`bond-app: port ${startPort} is already in use by the bond-app user service (${svcStatus.serviceName}).`
|
|
332
338
|
);
|
|
@@ -974,6 +980,7 @@ Options:
|
|
|
974
980
|
--port <port> HTTP port to listen on (default: 3000 or $BOND_APP_PORT)
|
|
975
981
|
--host <host> Loopback interface to bind to (default: 127.0.0.1 or $BOND_APP_HOST)
|
|
976
982
|
--data-dir <path> Data directory for database and token (default: ~/.bond-app or $BOND_APP_DATA_DIR)
|
|
983
|
+
--as-service Started by the user service itself (its unit, plist or task passes it)
|
|
977
984
|
-h, --help Show this help
|
|
978
985
|
`);
|
|
979
986
|
}
|
|
@@ -59,7 +59,7 @@ function winQuote(arg: string): string {
|
|
|
59
59
|
export function buildTaskCommand(opts: WindowsServiceOptions = {}): string {
|
|
60
60
|
const nodePath = opts.nodePath ?? process.execPath;
|
|
61
61
|
const binPath = path.resolve(opts.binPath ?? path.join(repoRoot, 'bin', 'bond-app.js'));
|
|
62
|
-
const parts = [winQuote(nodePath), winQuote(binPath), 'start'];
|
|
62
|
+
const parts = [winQuote(nodePath), winQuote(binPath), 'start', '--as-service'];
|
|
63
63
|
if (opts.port !== undefined) {
|
|
64
64
|
parts.push('--port', String(opts.port));
|
|
65
65
|
}
|
package/src/core/service.ts
CHANGED
|
@@ -191,6 +191,7 @@ export function renderSystemdUnit(params: {
|
|
|
191
191
|
quoteSystemdArg(params.nodePath),
|
|
192
192
|
quoteSystemdArg(params.binPath),
|
|
193
193
|
'start',
|
|
194
|
+
'--as-service',
|
|
194
195
|
'--port',
|
|
195
196
|
String(params.port),
|
|
196
197
|
'--data-dir',
|
|
@@ -253,6 +254,7 @@ export function renderLaunchdPlist(params: {
|
|
|
253
254
|
params.nodePath,
|
|
254
255
|
params.binPath,
|
|
255
256
|
'start',
|
|
257
|
+
'--as-service',
|
|
256
258
|
'--port',
|
|
257
259
|
String(params.port),
|
|
258
260
|
'--data-dir',
|
|
@@ -88,6 +88,8 @@ export interface SetupOptions {
|
|
|
88
88
|
export interface SetupDeps {
|
|
89
89
|
fetch?: FetchLike;
|
|
90
90
|
runCommand?: (cmd: string, args: string[], timeoutMs?: number) => Promise<CommandOutput>;
|
|
91
|
+
/** Where the installed bond comes from (npm, Homebrew, its own binary); tests fake it. */
|
|
92
|
+
bondOrigin?: (runCommand: (cmd: string, args: string[], timeoutMs?: number) => Promise<CommandOutput>, platform: NodeJS.Platform) => Promise<BondOrigin>;
|
|
91
93
|
homeDir?: string;
|
|
92
94
|
dataDir?: string;
|
|
93
95
|
herdrAppHome?: string;
|
|
@@ -757,13 +759,16 @@ export async function runSetup(options: SetupOptions = {}): Promise<SetupResult>
|
|
|
757
759
|
steps.push({ id: 'bond', ok: true, skipped: true, detail });
|
|
758
760
|
bondVersion = targetBondVersion;
|
|
759
761
|
} else {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
762
|
+
// An old bond from Homebrew or its own binary is upgraded that way: npm would hit EEXIST.
|
|
763
|
+
const origin = bondRes.ok ? await (deps.bondOrigin ?? detectBondOrigin)(runCommand, platform) : { kind: 'none' as const, path: null };
|
|
764
|
+
const [bin, binArgs]: [string, string[]] = origin.kind === 'brew'
|
|
765
|
+
? ['brew', ['upgrade', BOND_BREW_FORMULA]]
|
|
766
|
+
: origin.kind === 'binary'
|
|
767
|
+
? ['bond', ['update']]
|
|
768
|
+
: ['npm', ['install', '-g', `@jmanuelcorral/bond@${targetBondVersion}`, NPM_PUBLIC_REGISTRY_ARG]];
|
|
769
|
+
const npmRes = await runCommand(bin, binArgs, 180_000);
|
|
765
770
|
if (!npmRes.ok) {
|
|
766
|
-
const fix =
|
|
771
|
+
const fix = `${bin} ${binArgs.join(' ')}`;
|
|
767
772
|
logStep('✗', 'bond CLI', npmRes.stderr.trim() || npmRes.error || 'npm install failed', fix);
|
|
768
773
|
steps.push({ id: 'bond', ok: false, detail: 'npm install failed' });
|
|
769
774
|
return { ok: false, dryRun, steps, record: null };
|
|
@@ -1099,29 +1104,34 @@ export async function runUpdate(options: UpdateOptions = {}): Promise<UpdateResu
|
|
|
1099
1104
|
|
|
1100
1105
|
log(`bond-app update (${normPlatform}${dryRun ? ', dry-run' : ''})`);
|
|
1101
1106
|
|
|
1102
|
-
// 1. Update
|
|
1103
|
-
//
|
|
1107
|
+
// 1. Update bond the way it was installed, first: up to 1.16.8 it shipped its own `bond-app`
|
|
1108
|
+
// bin, and npm would refuse to install bond-app over it (EEXIST). A bond from Homebrew
|
|
1109
|
+
// (jmanuelcorral/tap/bond) or bond's own binary is not npm's: `npm install -g` hits EEXIST
|
|
1110
|
+
// on its file. A failure here warns and goes on: bond-app still gets updated.
|
|
1111
|
+
const bondOrigin = await (deps.bondOrigin ?? detectBondOrigin)(runCommand, platform);
|
|
1112
|
+
const bondUpdate: [string, string[]] = bondOrigin.kind === 'brew'
|
|
1113
|
+
? ['brew', ['upgrade', BOND_BREW_FORMULA]]
|
|
1114
|
+
: bondOrigin.kind === 'binary'
|
|
1115
|
+
? ['bond', ['update']]
|
|
1116
|
+
: ['npm', ['install', '-g', '@jmanuelcorral/bond@latest', NPM_PUBLIC_REGISTRY_ARG]];
|
|
1117
|
+
const via = bondOrigin.kind === 'brew' ? 'Homebrew' : bondOrigin.kind === 'binary' ? `its own binary (${bondOrigin.path})` : 'npm';
|
|
1104
1118
|
if (dryRun) {
|
|
1105
|
-
const detail = `would run:
|
|
1119
|
+
const detail = `would run: ${bondUpdate[0]} ${bondUpdate[1].join(' ')} (bond from ${via})`;
|
|
1106
1120
|
logStep('✓', 'bond CLI', detail);
|
|
1107
1121
|
steps.push({ id: 'bond', ok: true, skipped: true, detail });
|
|
1108
1122
|
} else {
|
|
1109
|
-
const
|
|
1110
|
-
|
|
1111
|
-
[
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
const
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1123
|
+
const res = await runCommand(bondUpdate[0], bondUpdate[1], 180_000);
|
|
1124
|
+
if (!res.ok) {
|
|
1125
|
+
const fix = `${bondUpdate[0]} ${bondUpdate[1].join(' ')}`;
|
|
1126
|
+
logStep('!', 'bond CLI', `not updated (bond from ${via}): ${(res.stderr.trim() || res.error || 'failed').split('\n').slice(-3).join(' ')}`, fix);
|
|
1127
|
+
steps.push({ id: 'bond', ok: true, skipped: true, detail: `not updated (${via})` });
|
|
1128
|
+
} else {
|
|
1129
|
+
const verRes = await runCommand('bond', ['--version'], 10_000);
|
|
1130
|
+
const ver = verRes.ok ? extractSemver(verRes.stdout) : null;
|
|
1131
|
+
const detail = `${ver ? `updated to ${ver}` : 'updated'} (${via})`;
|
|
1132
|
+
logStep('✓', 'bond CLI', detail);
|
|
1133
|
+
steps.push({ id: 'bond', ok: true, detail });
|
|
1119
1134
|
}
|
|
1120
|
-
const verRes = await runCommand('bond', ['--version'], 10_000);
|
|
1121
|
-
const ver = verRes.ok ? extractSemver(verRes.stdout) : null;
|
|
1122
|
-
const detail = ver ? `updated to ${ver}` : 'updated';
|
|
1123
|
-
logStep('✓', 'bond CLI', detail);
|
|
1124
|
-
steps.push({ id: 'bond', ok: true, detail });
|
|
1125
1135
|
}
|
|
1126
1136
|
|
|
1127
1137
|
// 2. Update @jmanuelcorral/bond-app via npm (public registry)
|
|
@@ -1402,3 +1412,48 @@ export async function runUninstall(options: UninstallOptions = {}): Promise<Unin
|
|
|
1402
1412
|
log(' Note: herdr-app, hc and bond were not uninstalled (they may be used by other projects).');
|
|
1403
1413
|
return { ok: allOk, dryRun, purged, steps };
|
|
1404
1414
|
}
|
|
1415
|
+
|
|
1416
|
+
/** The Homebrew formula of bond (the jmanuelcorral tap). */
|
|
1417
|
+
export const BOND_BREW_FORMULA = 'jmanuelcorral/tap/bond';
|
|
1418
|
+
|
|
1419
|
+
export interface BondOrigin {
|
|
1420
|
+
kind: 'npm' | 'brew' | 'binary' | 'none';
|
|
1421
|
+
path: string | null;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
/**
|
|
1425
|
+
* Where the `bond` on PATH comes from, by its real path: Homebrew's Cellar, npm's global
|
|
1426
|
+
* node_modules, or bond's own binary (install.sh); none when there is no bond.
|
|
1427
|
+
*/
|
|
1428
|
+
export async function detectBondOrigin(
|
|
1429
|
+
runCommand: (cmd: string, args: string[], timeoutMs?: number) => Promise<CommandOutput>,
|
|
1430
|
+
platform: NodeJS.Platform
|
|
1431
|
+
): Promise<BondOrigin> {
|
|
1432
|
+
const exe = platform === 'win32' ? ['bond.cmd', 'bond.exe', 'bond'] : ['bond'];
|
|
1433
|
+
let found: string | null = null;
|
|
1434
|
+
for (const dir of String(process.env.PATH ?? '').split(path.delimiter)) {
|
|
1435
|
+
for (const name of exe) {
|
|
1436
|
+
const p = path.join(dir, name);
|
|
1437
|
+
if (dir && fs.existsSync(p)) {
|
|
1438
|
+
found = p;
|
|
1439
|
+
break;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
if (found) break;
|
|
1443
|
+
}
|
|
1444
|
+
if (!found) return { kind: 'none', path: null };
|
|
1445
|
+
let real = found;
|
|
1446
|
+
try {
|
|
1447
|
+
real = fs.realpathSync(found);
|
|
1448
|
+
} catch {}
|
|
1449
|
+
return { kind: classifyBondPath(real, (await runCommand('npm', ['root', '-g'], 15_000)).stdout.trim()), path: real };
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
/** brew when it lives in a Homebrew Cellar, npm when under npm's global root (or an npm package), else binary. */
|
|
1453
|
+
export function classifyBondPath(real: string, npmRoot: string): BondOrigin['kind'] {
|
|
1454
|
+
const r = real.replace(/\\/g, '/');
|
|
1455
|
+
if (/\/Cellar\/bond\//.test(r) || /\/homebrew\/Cellar\//i.test(r)) return 'brew';
|
|
1456
|
+
const root = npmRoot.replace(/\\/g, '/');
|
|
1457
|
+
if ((root && r.startsWith(`${root}/`)) || /\/node_modules\/@jmanuelcorral\/bond\//.test(r)) return 'npm';
|
|
1458
|
+
return 'binary';
|
|
1459
|
+
}
|