@hypequery/cli 1.10.0 → 1.10.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AA8BA,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA6BD,wBAAsB,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,iBAwMvE"}
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AA8BA,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA6BD,wBAAsB,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,iBAkQvE"}
@@ -65,7 +65,42 @@ export async function devCommand(file, options = {}) {
65
65
  logger.newline();
66
66
  let currentServer = null;
67
67
  let currentGateway = null;
68
+ let lifecycleOperation = Promise.resolve();
69
+ let shutdownRequested = false;
68
70
  const shouldWatch = options.watch !== false; // Default to true
71
+ const queueLifecycleOperation = (operation) => {
72
+ const queued = lifecycleOperation.then(operation, operation);
73
+ lifecycleOperation = queued.catch(() => undefined);
74
+ return queued;
75
+ };
76
+ const stopCurrentRuntime = async () => {
77
+ const gateway = currentGateway;
78
+ const server = currentServer;
79
+ // Clear references before awaiting teardown so a second signal or restart
80
+ // cannot stop the same resources twice.
81
+ currentGateway = null;
82
+ currentServer = null;
83
+ let teardownError;
84
+ if (gateway) {
85
+ try {
86
+ await gateway.shutdown();
87
+ }
88
+ catch (error) {
89
+ teardownError = error;
90
+ }
91
+ }
92
+ if (server) {
93
+ try {
94
+ await server.stop();
95
+ }
96
+ catch (error) {
97
+ teardownError ??= error;
98
+ }
99
+ }
100
+ if (teardownError) {
101
+ throw teardownError;
102
+ }
103
+ };
69
104
  const startServer = async () => {
70
105
  // Loading spinners for slow operations
71
106
  const compileSpinner = ora('Compiling queries...').start();
@@ -146,6 +181,16 @@ export async function devCommand(file, options = {}) {
146
181
  }
147
182
  }
148
183
  catch (error) {
184
+ // Gateway creation happens before serveDev so its mount can be passed to
185
+ // the server. If server startup (or any later setup) fails, tear down all
186
+ // resources acquired by this attempt before retrying or exiting.
187
+ try {
188
+ await stopCurrentRuntime();
189
+ }
190
+ catch (teardownError) {
191
+ const message = teardownError instanceof Error ? teardownError.message : String(teardownError);
192
+ logger.warn(`Failed to clean up dev server resources: ${message}`);
193
+ }
149
194
  // Stop spinners if they're still running
150
195
  if (compileSpinner.isSpinning) {
151
196
  compileSpinner.fail('Failed to compile queries');
@@ -172,26 +217,29 @@ export async function devCommand(file, options = {}) {
172
217
  }
173
218
  }
174
219
  };
175
- const restartServer = async () => {
176
- if (currentServer) {
220
+ const restartServer = () => queueLifecycleOperation(async () => {
221
+ if (shutdownRequested)
222
+ return;
223
+ if (currentServer || currentGateway) {
177
224
  logger.newline();
178
225
  logger.reload('File changed, restarting...');
179
226
  logger.newline();
180
- if (currentGateway)
181
- await currentGateway.shutdown();
182
- await currentServer.stop();
227
+ await stopCurrentRuntime();
183
228
  }
184
- await startServer();
185
- };
186
- const shutdown = async () => {
229
+ if (!shutdownRequested) {
230
+ await startServer();
231
+ }
232
+ });
233
+ const shutdown = () => {
234
+ if (shutdownRequested)
235
+ return lifecycleOperation;
236
+ shutdownRequested = true;
187
237
  logger.newline();
188
238
  logger.info('Shutting down dev server...');
189
- if (currentGateway)
190
- await currentGateway.shutdown();
191
- if (currentServer) {
192
- await currentServer.stop();
193
- }
194
- process.exit(0);
239
+ return queueLifecycleOperation(async () => {
240
+ await stopCurrentRuntime();
241
+ process.exit(0);
242
+ });
195
243
  };
196
244
  // Start initial server
197
245
  await startServer();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypequery/cli",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "Command-line interface for hypequery",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",