@donkeylabs/adapter-sveltekit 0.1.0 → 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 +2 -2
- package/src/generator/index.ts +3 -3
- package/src/index.ts +4 -8
- package/src/vite.ts +18 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donkeylabs/adapter-sveltekit",
|
|
3
|
-
"version": "0.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",
|
|
@@ -55,4 +55,4 @@
|
|
|
55
55
|
"directory": "packages/adapter-sveltekit"
|
|
56
56
|
},
|
|
57
57
|
"license": "MIT"
|
|
58
|
-
}
|
|
58
|
+
}
|
package/src/generator/index.ts
CHANGED
|
@@ -16,9 +16,9 @@ import {
|
|
|
16
16
|
/** SvelteKit-specific generator options */
|
|
17
17
|
export const svelteKitGeneratorOptions: ClientGeneratorOptions = {
|
|
18
18
|
baseImport:
|
|
19
|
-
'import { UnifiedApiClientBase, type
|
|
19
|
+
'import { UnifiedApiClientBase, type ClientOptions } from "@donkeylabs/adapter-sveltekit/client";',
|
|
20
20
|
baseClass: "UnifiedApiClientBase",
|
|
21
|
-
constructorSignature: "options?:
|
|
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?:
|
|
50
|
+
export function createApi(options?: ClientOptions) {
|
|
51
51
|
return new ApiClient(options);
|
|
52
52
|
}`,
|
|
53
53
|
};
|
package/src/index.ts
CHANGED
|
@@ -26,9 +26,9 @@ export interface AdapterOptions {
|
|
|
26
26
|
* Path to your @donkeylabs/server entry file.
|
|
27
27
|
* This file should export a configured AppServer instance.
|
|
28
28
|
*
|
|
29
|
-
* @
|
|
29
|
+
* @default "./src/server/index.ts"
|
|
30
30
|
*/
|
|
31
|
-
serverEntry
|
|
31
|
+
serverEntry?: string;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Whether to precompress static assets with gzip/brotli.
|
|
@@ -49,19 +49,15 @@ export interface AdapterOptions {
|
|
|
49
49
|
development?: boolean;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export default function adapter(options: AdapterOptions): Adapter {
|
|
52
|
+
export default function adapter(options: AdapterOptions = {}): Adapter {
|
|
53
53
|
const {
|
|
54
54
|
out = "build",
|
|
55
|
-
serverEntry,
|
|
55
|
+
serverEntry = "./src/server/index.ts",
|
|
56
56
|
precompress = true,
|
|
57
57
|
envPrefix = "",
|
|
58
58
|
development = false,
|
|
59
59
|
} = options;
|
|
60
60
|
|
|
61
|
-
if (!serverEntry) {
|
|
62
|
-
throw new Error("@donkeylabs/adapter-sveltekit: serverEntry option is required");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
61
|
return {
|
|
66
62
|
name: "@donkeylabs/adapter-sveltekit",
|
|
67
63
|
|
package/src/vite.ts
CHANGED
|
@@ -16,9 +16,9 @@ export interface DevPluginOptions {
|
|
|
16
16
|
* Path to your @donkeylabs/server entry file.
|
|
17
17
|
* This file should export a configured AppServer instance.
|
|
18
18
|
*
|
|
19
|
-
* @
|
|
19
|
+
* @default "./src/server/index.ts"
|
|
20
20
|
*/
|
|
21
|
-
serverEntry
|
|
21
|
+
serverEntry?: string;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Port for the backend server (subprocess mode only).
|
|
@@ -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
|
-
//
|
|
34
|
-
|
|
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
|
|
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
|
/**
|
|
@@ -58,12 +65,8 @@ export function getDevServer(): any {
|
|
|
58
65
|
* ]
|
|
59
66
|
* });
|
|
60
67
|
*/
|
|
61
|
-
export function donkeylabsDev(options: DevPluginOptions): Plugin {
|
|
62
|
-
const { serverEntry, backendPort = 3001 } = options;
|
|
63
|
-
|
|
64
|
-
if (!serverEntry) {
|
|
65
|
-
throw new Error("donkeylabsDev: serverEntry option is required");
|
|
66
|
-
}
|
|
68
|
+
export function donkeylabsDev(options: DevPluginOptions = {}): Plugin {
|
|
69
|
+
const { serverEntry = "./src/server/index.ts", backendPort = 3001 } = options;
|
|
67
70
|
|
|
68
71
|
// State for subprocess mode
|
|
69
72
|
let backendProcess: ChildProcess | null = null;
|
|
@@ -86,7 +89,7 @@ export function donkeylabsDev(options: DevPluginOptions): Plugin {
|
|
|
86
89
|
console.log("[donkeylabs-dev] Starting in-process mode (Bun runtime detected)");
|
|
87
90
|
|
|
88
91
|
try {
|
|
89
|
-
const serverModule = await import(serverEntryResolved);
|
|
92
|
+
const serverModule = await import(/* @vite-ignore */ serverEntryResolved);
|
|
90
93
|
appServer = serverModule.server || serverModule.default;
|
|
91
94
|
|
|
92
95
|
if (!appServer) {
|
|
@@ -96,8 +99,8 @@ export function donkeylabsDev(options: DevPluginOptions): Plugin {
|
|
|
96
99
|
// Initialize without starting HTTP server
|
|
97
100
|
await appServer.initialize();
|
|
98
101
|
serverReady = true;
|
|
99
|
-
// Set global reference for SSR direct calls
|
|
100
|
-
|
|
102
|
+
// Set global reference for SSR direct calls (uses globalThis for cross-module sharing)
|
|
103
|
+
setDevServer(appServer);
|
|
101
104
|
console.log("[donkeylabs-dev] Server initialized (in-process mode)");
|
|
102
105
|
} catch (err) {
|
|
103
106
|
console.error("[donkeylabs-dev] Failed to initialize server:", err);
|
|
@@ -351,6 +354,7 @@ export function donkeylabsDev(options: DevPluginOptions): Plugin {
|
|
|
351
354
|
if (appServer) {
|
|
352
355
|
await appServer.shutdown?.();
|
|
353
356
|
appServer = null;
|
|
357
|
+
setDevServer(null);
|
|
354
358
|
}
|
|
355
359
|
},
|
|
356
360
|
};
|