create-authhero 0.20.0 → 0.22.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.
@@ -32,6 +32,7 @@ const worker = spawn("wrangler", wranglerArgs, {
32
32
  });
33
33
 
34
34
  let workerUrl = "http://localhost:8787";
35
+ let workerReady = false;
35
36
 
36
37
  // Listen for the worker output to get the URL
37
38
  worker.stdout?.on("data", (data) => {
@@ -43,10 +44,53 @@ worker.stdout?.on("data", (data) => {
43
44
  if (urlMatch) {
44
45
  workerUrl = urlMatch[0].replace(/\/$/, ""); // Remove trailing slash
45
46
  }
47
+
48
+ // Detect when the worker is ready
49
+ if (output.includes("Ready on") || output.includes("Listening on")) {
50
+ workerReady = true;
51
+ }
46
52
  });
47
53
 
48
- // Wait for the worker to start
49
- await setTimeout(3000);
54
+ // Function to wait for worker to be ready with retries
55
+ async function waitForWorker(maxAttempts = 30, delayMs = 1000) {
56
+ for (let i = 0; i < maxAttempts; i++) {
57
+ try {
58
+ // Just check if the server responds (even with an error is fine)
59
+ const response = await fetch(workerUrl, {
60
+ signal: AbortSignal.timeout(2000)
61
+ });
62
+ // Any response means the server is up
63
+ return true;
64
+ } catch (e) {
65
+ // ECONNREFUSED means server not ready yet
66
+ if (e.cause?.code !== 'ECONNREFUSED') {
67
+ // Other errors might mean the server is actually responding
68
+ return true;
69
+ }
70
+ }
71
+
72
+ if (workerReady) {
73
+ // Give it a bit more time after wrangler reports ready
74
+ await setTimeout(500);
75
+ return true;
76
+ }
77
+
78
+ await setTimeout(delayMs);
79
+ if (i > 0 && i % 5 === 0) {
80
+ console.log(`Still waiting for worker... (attempt ${i + 1}/${maxAttempts})`);
81
+ }
82
+ }
83
+ return false;
84
+ }
85
+
86
+ console.log("Waiting for seed worker to start...");
87
+ const isReady = await waitForWorker();
88
+
89
+ if (!isReady) {
90
+ console.error("\n❌ Seed worker failed to start within timeout");
91
+ worker.kill();
92
+ process.exit(1);
93
+ }
50
94
 
51
95
  console.log(`\nMaking seed request to ${workerUrl}...`);
52
96