nstantpage-agent 0.5.8 → 0.5.9

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.
@@ -582,18 +582,35 @@ async function startAdditionalProject(projectId, opts) {
582
582
  // Ensure ports are clear for this project before starting
583
583
  cleanupPreviousAgent(projectId, allocated.apiPort, allocated.devPort);
584
584
  await new Promise(r => setTimeout(r, 50));
585
- // ── Phase 1: Fetch files + start API server in parallel ──────────
585
+ // ── Phase 1: API server + file fetch + tunnel connect (all parallel) ──
586
586
  progress('fetching-files', 'Fetching project files...');
587
587
  const localServer = new LocalServer({
588
588
  projectDir, projectId,
589
589
  apiPort: allocated.apiPort, devPort: allocated.devPort,
590
590
  });
591
- // Start API server immediately (doesn't need project files)
591
+ const tunnel = new TunnelClient({
592
+ gatewayUrl: opts.gatewayUrl,
593
+ token: opts.token,
594
+ projectId,
595
+ apiPort: allocated.apiPort,
596
+ devPort: allocated.devPort,
597
+ });
598
+ // Launch API server, tunnel, and file fetch all in parallel
592
599
  const apiServerPromise = localServer.start().then(() => {
593
600
  timings['api-server'] = Date.now() - t0;
594
601
  console.log(chalk.green(` ✓ API server on port ${allocated.apiPort} (${timings['api-server']}ms)`));
595
602
  });
596
- // Fetch project files concurrently with API server start
603
+ const tunnelPromise = (async () => {
604
+ try {
605
+ await tunnel.connect();
606
+ timings['tunnel'] = Date.now() - t0;
607
+ console.log(chalk.green(` ✓ Tunnel connected for project ${projectId} (${timings['tunnel']}ms)`));
608
+ }
609
+ catch (err) {
610
+ console.log(chalk.yellow(` ⚠ Tunnel: ${err.message}`));
611
+ tunnel.startBackgroundReconnect();
612
+ }
613
+ })();
597
614
  const fileStart = Date.now();
598
615
  try {
599
616
  await fetchProjectFiles(opts.backendUrl, projectId, projectDir, opts.token);
@@ -604,7 +621,7 @@ async function startAdditionalProject(projectId, opts) {
604
621
  console.log(chalk.yellow(` ⚠ Could not fetch files: ${err.message}`));
605
622
  progress('fetching-files', `Warning: ${err.message}`);
606
623
  }
607
- // Wait for API server before proceeding
624
+ // Wait for API server before proceeding (tunnel can keep connecting in background)
608
625
  await apiServerPromise;
609
626
  progress('starting-server', `API server ready`);
610
627
  // ── Phase 2: Install deps (if needed) ────────────────────────────
@@ -630,30 +647,7 @@ async function startAdditionalProject(projectId, opts) {
630
647
  else {
631
648
  progress('installing-deps', 'Dependencies already installed (cached)');
632
649
  }
633
- // ── Phase 3: Start dev server + connect tunnel in parallel ───────
634
- const tunnel = new TunnelClient({
635
- gatewayUrl: opts.gatewayUrl,
636
- token: opts.token,
637
- projectId,
638
- apiPort: allocated.apiPort,
639
- devPort: allocated.devPort,
640
- });
641
- // Connect tunnel immediately (don't wait for dev server — tunnel is needed for status updates)
642
- const tunnelPromise = (async () => {
643
- progress('connecting', 'Connecting tunnel to gateway...');
644
- try {
645
- await tunnel.connect();
646
- timings['tunnel'] = Date.now() - t0;
647
- console.log(chalk.green(` ✓ Tunnel connected for project ${projectId} (${timings['tunnel']}ms)`));
648
- progress('connecting', 'Tunnel connected');
649
- }
650
- catch (err) {
651
- console.log(chalk.yellow(` ⚠ Tunnel: ${err.message}`));
652
- tunnel.startBackgroundReconnect();
653
- progress('connecting', `Warning: ${err.message} — reconnecting`);
654
- }
655
- })();
656
- // Start dev server in parallel with tunnel connection
650
+ // ── Phase 3: Start dev server ────────────────────────────────────
657
651
  if (!opts.noDev) {
658
652
  if (installer.areDependenciesInstalled()) {
659
653
  progress('starting-dev', 'Starting dev server...');
@@ -675,7 +669,7 @@ async function startAdditionalProject(projectId, opts) {
675
669
  progress('starting-dev', 'Skipped — dependencies not installed');
676
670
  }
677
671
  }
678
- // Wait for tunnel to be connected
672
+ // Ensure tunnel is connected before declaring ready
679
673
  await tunnelPromise;
680
674
  // Register project with backend (non-blocking)
681
675
  fetch(`${opts.backendUrl}/api/agent/register`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nstantpage-agent",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "Local development agent for nstantpage.com — run your projects locally, preview in the cloud. Replaces cloud containers for faster builds.",
5
5
  "type": "module",
6
6
  "bin": {