@donkeylabs/server 2.0.15 → 2.0.16

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/server.ts +10 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donkeylabs/server",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "type": "module",
5
5
  "description": "Type-safe plugin system for building RPC-style APIs with Bun",
6
6
  "main": "./src/index.ts",
package/src/server.ts CHANGED
@@ -210,6 +210,7 @@ export class AppServer {
210
210
  // Custom services registry
211
211
  private serviceFactories = new Map<string, ServiceFactory<any>>();
212
212
  private serviceRegistry: Record<string, any> = {};
213
+ private generateModeTimer?: ReturnType<typeof setTimeout>;
213
214
 
214
215
  constructor(options: ServerConfig) {
215
216
  // Port priority: explicit config > PORT env var > default 3000
@@ -500,15 +501,18 @@ export class AppServer {
500
501
  use(router: IRouter): this {
501
502
  this.routers.push(router);
502
503
 
503
- // Set up generate mode handler on first use() call
504
+ // Handle CLI type generation mode with debounced timer
504
505
  // This handles SvelteKit-style entry files that don't call start()
505
- if (!this.generateModeSetup && process.env.DONKEYLABS_GENERATE === "1") {
506
- this.generateModeSetup = true;
507
- // Use beforeExit to output routes after module finishes loading
508
- process.on("beforeExit", () => {
506
+ if (process.env.DONKEYLABS_GENERATE === "1") {
507
+ // Clear any existing timer and set a new one
508
+ // This ensures we wait for all use() calls to complete
509
+ if (this.generateModeTimer) {
510
+ clearTimeout(this.generateModeTimer);
511
+ }
512
+ this.generateModeTimer = setTimeout(() => {
509
513
  this.outputRoutesForGeneration();
510
514
  process.exit(0);
511
- });
515
+ }, 100); // 100ms debounce - waits for all route registrations
512
516
  }
513
517
 
514
518
  return this;