@zap-js/client 0.1.5 → 0.1.6

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.
@@ -76,6 +76,22 @@ export async function serveCommand(options) {
76
76
  process.exit(1);
77
77
  }
78
78
  }
79
+ /**
80
+ * Wait for Rust server to create RPC socket file
81
+ */
82
+ async function waitForRpcSocket(socketPath) {
83
+ const rpcSocketPath = socketPath + '.rpc';
84
+ const maxWait = 10000; // 10 seconds
85
+ const checkInterval = 100; // 100ms
86
+ const startTime = Date.now();
87
+ while (Date.now() - startTime < maxWait) {
88
+ if (existsSync(rpcSocketPath)) {
89
+ return;
90
+ }
91
+ await new Promise(resolve => setTimeout(resolve, checkInterval));
92
+ }
93
+ throw new Error(`RPC socket not ready within ${maxWait}ms`);
94
+ }
79
95
  async function runProductionServer(binPath, options, workDir, prodConfig) {
80
96
  const port = parseInt(options.port || prodConfig?.server?.port?.toString() || '3000');
81
97
  const host = options.host || prodConfig?.server?.host || '0.0.0.0';
@@ -96,12 +112,6 @@ async function runProductionServer(binPath, options, workDir, prodConfig) {
96
112
  const ipcServer = new IpcServer(socketPath);
97
113
  await ipcServer.start();
98
114
  cliLogger.succeedSpinner('ipc', 'IPC server started');
99
- // Initialize RPC client for bidirectional IPC communication
100
- // This allows TypeScript route handlers to call Rust functions via rpc.call()
101
- cliLogger.spinner('rpc', 'Initializing RPC client...');
102
- const { initRpcClient } = await import('../../runtime/rpc-client.js');
103
- await initRpcClient(socketPath + '.rpc');
104
- cliLogger.succeedSpinner('rpc', 'RPC client initialized');
105
115
  // Load and register route handlers
106
116
  const routes = await loadRouteHandlers(ipcServer, workDir);
107
117
  // Build Rust server configuration
@@ -149,6 +159,26 @@ async function runProductionServer(binPath, options, workDir, prodConfig) {
149
159
  ZAP_ENV: 'production',
150
160
  },
151
161
  });
162
+ // Wait for Rust server to create RPC socket, then initialize RPC client
163
+ cliLogger.spinner('rpc', 'Waiting for RPC server...');
164
+ try {
165
+ await waitForRpcSocket(socketPath);
166
+ // Initialize RPC client for bidirectional IPC communication
167
+ // This allows TypeScript route handlers to call Rust functions via rpc.call()
168
+ const { initRpcClient } = await import('../../runtime/rpc-client.js');
169
+ await initRpcClient(socketPath + '.rpc');
170
+ cliLogger.succeedSpinner('rpc', 'RPC client connected');
171
+ }
172
+ catch (err) {
173
+ cliLogger.failSpinner('rpc', 'Failed to connect RPC client');
174
+ const message = err instanceof Error ? err.message : String(err);
175
+ cliLogger.error(message);
176
+ cleanup(ipcServer, tempConfigPath);
177
+ if (!rustProcess.killed) {
178
+ rustProcess.kill();
179
+ }
180
+ process.exit(1);
181
+ }
152
182
  let started = false;
153
183
  rustProcess.stdout?.on('data', (data) => {
154
184
  const output = data.toString();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zap-js/client",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "High-performance fullstack React framework - Client package",
5
5
  "homepage": "https://github.com/saint0x/zapjs",
6
6
  "repository": {
@@ -74,9 +74,9 @@
74
74
  "ws": "^8.16.0"
75
75
  },
76
76
  "optionalDependencies": {
77
- "@zap-js/darwin-arm64": "0.1.5",
78
- "@zap-js/darwin-x64": "0.1.5",
79
- "@zap-js/linux-x64": "0.1.5"
77
+ "@zap-js/darwin-arm64": "0.1.6",
78
+ "@zap-js/darwin-x64": "0.1.6",
79
+ "@zap-js/linux-x64": "0.1.6"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "react": "^18.0.0",