plum-e2e 2.9.9 → 2.9.12

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.
@@ -33,7 +33,8 @@ const {
33
33
  killPort,
34
34
  nodeReachable
35
35
  } = runnerProcess;
36
- const { generateToken, registerWithPrimary, detectLanIp, loadNodeConfig } = nodeRegister;
36
+ const { generateToken, registerWithPrimary, detectLanIp, loadNodeConfig, saveNodeConfig } =
37
+ nodeRegister;
37
38
 
38
39
  const API_URL = process.env.PLUM_API_URL || 'http://localhost:3001';
39
40
 
@@ -343,7 +344,6 @@ async function addRunner() {
343
344
  if (cancelled(urlInput)) return;
344
345
 
345
346
  const url = resolveNodeUrl(urlInput || defaultUrl);
346
- const local = isLocalUrl(url);
347
347
 
348
348
  const s = clack.spinner();
349
349
  s.start(`Registering "${name}" with the primary...`);
@@ -364,42 +364,60 @@ async function addRunner() {
364
364
  return;
365
365
  }
366
366
 
367
- // Verify the node actually answers before keeping the registration start a
368
- // local one here, expect a remote one to already be up. A failed check rolls
369
- // the registration back so no dead runner is left behind.
370
- let entry = null;
371
- let ok = false;
372
- if (local) {
373
- prepareNodeEnv();
374
- entry = startNode({ id, port, token });
375
- s.start(`Waiting for "${name}" to come up on port ${port}...`);
376
- ok = await nodeReachable(`http://localhost:${port}`, token, 20000);
377
- s.stop(ok ? pc.green(`"${name}" is up (pid ${entry.pid})`) : pc.red(`"${name}" did not start`));
378
- } else {
379
- s.start(`Checking for a Plum node at ${url}...`);
380
- ok = await nodeReachable(url, token, 8000);
381
- s.stop(ok ? pc.green(`"${name}" is reachable`) : pc.red(`No Plum node answered at ${url}`));
367
+ // A node whose URL points at another machine has to be started over there
368
+ // (`plum node start`), so registering it before it's up is normal just
369
+ // tell the operator what to run. Only a node we can start from here gets
370
+ // started + verified, and rolled back if it never comes up.
371
+ if (!isLocalUrl(url)) {
372
+ s.start(`Checking ${url}...`);
373
+ const up = await nodeReachable(url, token, 5000);
374
+ s.stop(
375
+ up
376
+ ? pc.green(`"${name}" registered and answering`)
377
+ : pc.yellow(`"${name}" registered no node answering there yet`)
378
+ );
379
+ if (!up) {
380
+ clack.log.info(
381
+ `Start it on that host:\n plum node start --name ${name} --url ${url} --port <port> ` +
382
+ `--primary ${API_URL} --token ${token}`
383
+ );
384
+ }
385
+ return;
382
386
  }
383
387
 
384
- if (ok) {
388
+ prepareNodeEnv();
389
+ if (findPidOnPort(Number(port))) await killPort(Number(port));
390
+ const entry = startNode({ id, port, token });
391
+ s.start(`Starting "${name}" on port ${port}...`);
392
+ const up = await nodeReachable(`http://localhost:${port}`, token, 20000);
393
+ s.stop(up ? pc.green(`"${name}" is up (pid ${entry.pid})`) : pc.red(`"${name}" did not start`));
394
+
395
+ if (up) {
396
+ // Persist the same way `plum node start` does, so `plum node stop`/
397
+ // `restart` and `plum update`'s restart sweep can find this node too.
398
+ saveNodeConfig(process.cwd(), {
399
+ ...loadNodeConfig(process.cwd()),
400
+ id,
401
+ name,
402
+ url,
403
+ token,
404
+ primary: API_URL,
405
+ browser: 'chromium',
406
+ port
407
+ });
408
+ globalRegistry.registerInstall('node', process.cwd());
385
409
  clack.log.success(pc.green(`Runner "${name}" is ready.`));
386
410
  return;
387
411
  }
388
412
 
389
- if (entry) stopNode(id, Number(port));
413
+ stopNode(id, Number(port));
390
414
  if (!reused) {
391
415
  try {
392
416
  await deleteRunner(id);
393
417
  } catch {}
394
418
  }
395
- if (entry?.logFile) clack.note(entry.logFile, 'Node log');
396
- clack.log.warn(
397
- pc.yellow(
398
- reused
399
- ? `"${name}" stays registered but is unreachable — check the port/URL.`
400
- : `"${name}" was not registered — check the port/URL and try again.`
401
- )
402
- );
419
+ if (entry.logFile) clack.note(entry.logFile, 'Node log');
420
+ clack.log.warn(pc.yellow(`"${name}" was not registered — check ${entry.logFile} and try again.`));
403
421
  }
404
422
 
405
423
  async function main() {
package/bin/plum.js CHANGED
@@ -725,6 +725,21 @@ async function nodeStart({ reconfig }) {
725
725
  const { statusOf } = runnerProcessLib();
726
726
  const existing = loadNodeConfig(process.cwd());
727
727
 
728
+ // One folder holds one node's config (.plum-node.json). Starting a
729
+ // different-named node here would overwrite it — orphaning the previous
730
+ // node's still-running process and losing the config needed to stop it.
731
+ const wantName = getFlag(process.argv.slice(3), '--name');
732
+ if (!reconfig && existing.name && wantName && wantName !== existing.name) {
733
+ clack.log.error(
734
+ `This folder is set up for node "${existing.name}". Run each node from its own folder:\n\n` +
735
+ ` mkdir -p ~/plum-nodes/${wantName} && cd ~/plum-nodes/${wantName}\n` +
736
+ ` plum node start --name ${wantName} …`
737
+ );
738
+ clack.outro(pc.red('Not started — use a fresh folder for this node.'));
739
+ process.exitCode = 1;
740
+ return;
741
+ }
742
+
728
743
  // Re-running `node start` on an already-running node used to spawn a second
729
744
  // process on the same port (orphaning the first) and re-register a duplicate
730
745
  // runner on the primary. Route to the same menu this command ends on anyway
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plum-e2e",
3
- "version": "2.9.9",
3
+ "version": "2.9.12",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/silverlunah/plum.git"