@donkeylabs/adapter-sveltekit 0.1.1 → 0.1.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donkeylabs/adapter-sveltekit",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "SvelteKit adapter for @donkeylabs/server - seamless SSR/browser API integration",
6
6
  "main": "./src/index.ts",
@@ -16,9 +16,9 @@ import {
16
16
  /** SvelteKit-specific generator options */
17
17
  export const svelteKitGeneratorOptions: ClientGeneratorOptions = {
18
18
  baseImport:
19
- 'import { UnifiedApiClientBase, type ApiClientOptions } from "@donkeylabs/adapter-sveltekit/client";',
19
+ 'import { UnifiedApiClientBase, type ClientOptions } from "@donkeylabs/adapter-sveltekit/client";',
20
20
  baseClass: "UnifiedApiClientBase",
21
- constructorSignature: "options?: ApiClientOptions",
21
+ constructorSignature: "options?: ClientOptions",
22
22
  constructorBody: "super(options);",
23
23
  factoryFunction: `/**
24
24
  * Create an API client instance
@@ -47,7 +47,7 @@ export const svelteKitGeneratorOptions: ClientGeneratorOptions = {
47
47
  * </script>
48
48
  * \`\`\`
49
49
  */
50
- export function createApi(options?: ApiClientOptions) {
50
+ export function createApi(options?: ClientOptions) {
51
51
  return new ApiClient(options);
52
52
  }`,
53
53
  };
package/src/vite.ts CHANGED
@@ -30,15 +30,22 @@ export interface DevPluginOptions {
30
30
  // Check if running with Bun runtime (bun --bun)
31
31
  const isBunRuntime = typeof globalThis.Bun !== "undefined";
32
32
 
33
- // Global reference to the app server for SSR direct calls
34
- let globalAppServer: any = null;
33
+ // Use globalThis to share server reference across module instances
34
+ // This is needed because SvelteKit SSR loads a separate module instance
35
+ declare global {
36
+ var __donkeylabs_dev_server__: any;
37
+ }
35
38
 
36
39
  /**
37
40
  * Get the global app server instance for SSR direct calls.
38
41
  * This allows hooks to access the server without HTTP.
39
42
  */
40
43
  export function getDevServer(): any {
41
- return globalAppServer;
44
+ return globalThis.__donkeylabs_dev_server__;
45
+ }
46
+
47
+ function setDevServer(server: any) {
48
+ globalThis.__donkeylabs_dev_server__ = server;
42
49
  }
43
50
 
44
51
  /**
@@ -82,7 +89,7 @@ export function donkeylabsDev(options: DevPluginOptions = {}): Plugin {
82
89
  console.log("[donkeylabs-dev] Starting in-process mode (Bun runtime detected)");
83
90
 
84
91
  try {
85
- const serverModule = await import(serverEntryResolved);
92
+ const serverModule = await import(/* @vite-ignore */ serverEntryResolved);
86
93
  appServer = serverModule.server || serverModule.default;
87
94
 
88
95
  if (!appServer) {
@@ -92,8 +99,8 @@ export function donkeylabsDev(options: DevPluginOptions = {}): Plugin {
92
99
  // Initialize without starting HTTP server
93
100
  await appServer.initialize();
94
101
  serverReady = true;
95
- // Set global reference for SSR direct calls
96
- globalAppServer = appServer;
102
+ // Set global reference for SSR direct calls (uses globalThis for cross-module sharing)
103
+ setDevServer(appServer);
97
104
  console.log("[donkeylabs-dev] Server initialized (in-process mode)");
98
105
  } catch (err) {
99
106
  console.error("[donkeylabs-dev] Failed to initialize server:", err);
@@ -347,6 +354,7 @@ export function donkeylabsDev(options: DevPluginOptions = {}): Plugin {
347
354
  if (appServer) {
348
355
  await appServer.shutdown?.();
349
356
  appServer = null;
357
+ setDevServer(null);
350
358
  }
351
359
  },
352
360
  };