@maravilla-labs/adapter-sveltekit 0.1.4 → 0.1.7
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/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -19
- package/dist/index.js.map +1 -1
- package/package.json +10 -5
- package/src/worker.js +0 -157
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Adapter } from '@sveltejs/kit';
|
|
2
|
-
|
|
2
|
+
interface AdapterOptions {
|
|
3
3
|
out?: string;
|
|
4
4
|
precompress?: boolean;
|
|
5
5
|
envPrefix?: string;
|
|
@@ -9,4 +9,5 @@ export interface AdapterOptions {
|
|
|
9
9
|
external?: string[];
|
|
10
10
|
}
|
|
11
11
|
export default function adapter(options?: AdapterOptions): Adapter;
|
|
12
|
+
export {};
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,eAAe,CAAC;AAEtD,UAAU,cAAc;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAKD,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAgOrE"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import { dirname, join, resolve } from 'node:path';
|
|
1
|
+
import { writeFileSync, existsSync, readdirSync, statSync } from 'node:fs';
|
|
4
2
|
import * as esbuild from 'esbuild';
|
|
5
3
|
import { buildFunctions, integrateWithManifest } from '@maravilla-labs/functions';
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const currentDir = dirname(currentModulePath);
|
|
9
|
-
return resolve(currentDir);
|
|
10
|
-
}
|
|
4
|
+
// Inline worker template to avoid requiring separate worker.js file at runtime
|
|
5
|
+
const INLINE_WORKER_TEMPLATE = `// Inlined Maravilla Runtime Worker for SvelteKit\nimport { Server } from '__SERVER__';\nimport { manifest, prerendered, base } from '__MANIFEST__';\nconst server = new Server(manifest);\nconst initialized = server.init({\n env: globalThis.platform?.env || {},\n read: async (file) => {\n console.log('Read function called for file:', file);\n return new ReadableStream({ start(controller) { controller.close(); } });\n }\n});\nasync function handleRequest(request) {\n await initialized;\n const url = new URL(request.url, 'http://localhost');\n let requestBody = undefined;\n if (request.body !== null && request.body !== undefined) {\n if (typeof request.body === 'string') { requestBody = request.body; } else { requestBody = JSON.stringify(request.body); }\n }\n const webRequest = new Request(url.toString(), { method: request.method, headers: request.headers || {}, body: requestBody });\n const pathname = url.pathname;\n const stripped_pathname = pathname.replace(/\/$/, '');\n if (pathname.endsWith('/__data.json') || pathname.endsWith('.html__data.json')) {\n try { const test = new URL(url.toString()); const before = test.pathname; const candidate = pathname.endsWith('/__data.json') ? pathname.slice(0, -'/__data.json'.length) : pathname.slice(0, -'.html__data.json'.length) + '.html'; test.pathname = candidate; console.log('Data URL normalization test', { before, candidate, after: test.pathname, href: test.href }); } catch (e) { console.error('Data URL normalization error', e); }\n }\n if (prerendered.has(pathname)) { }\n const location = pathname.at(-1) === '/' ? stripped_pathname : pathname + '/';\n if (location && prerendered.has(location)) { return new Response('', { status: 308, headers: { location: location + url.search } }); }\n try {\n console.log('SvelteKit server.respond called with:', { url: webRequest.url, method: webRequest.method, hasBody: requestBody !== undefined, platform: { hasEnv: !!globalThis.platform?.env, hasKv: !!globalThis.platform?.kv, hasDb: !!globalThis.platform?.db } });\n const response = await server.respond(webRequest, { platform: { env: globalThis.platform?.env || {}, context: { waitUntil: (promise) => { if (globalThis.platform?.queue) { globalThis.platform.queue.send({ type: 'background', promise }); } }, passThroughOnException: () => {} }, kv: globalThis.platform?.kv, db: globalThis.platform?.db, storage: globalThis.platform?.storage, queue: globalThis.platform?.queue }, getClientAddress: () => { const forwarded = webRequest.headers.get('x-forwarded-for'); if (forwarded) { return forwarded.split(',')[0].trim(); } return request.headers?.['x-real-ip'] || '127.0.0.1'; } });\n if (response.status >= 400) { console.error('SvelteKit returned error:', { status: response.status, statusText: response.statusText, url: webRequest.url }); }\n return response;\n } catch (error) { console.error('Error in server.respond:', error); console.error('Error stack:', error.stack); throw error; }\n}\n// Export for the Maravilla runtime\nglobalThis.handleRequest = handleRequest;`;
|
|
11
6
|
export default function adapter(options = {}) {
|
|
12
7
|
const { out = '.maravilla', precompress = false, envPrefix = 'PUBLIC_', polyfill = true, include = [], exclude = [], external = [] } = options;
|
|
13
8
|
return {
|
|
@@ -41,10 +36,7 @@ export default function adapter(options = {}) {
|
|
|
41
36
|
`export const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});`,
|
|
42
37
|
`export const base = ${JSON.stringify(builder.config.kit.paths.base)};`
|
|
43
38
|
].join('\n\n'));
|
|
44
|
-
|
|
45
|
-
const files_path = get_files_path();
|
|
46
|
-
const worker_template = readFileSync(join(files_path, 'worker.js'), 'utf-8');
|
|
47
|
-
const worker_code = worker_template
|
|
39
|
+
const worker_code = INLINE_WORKER_TEMPLATE
|
|
48
40
|
.replace('__SERVER__', './index.js')
|
|
49
41
|
.replace('__MANIFEST__', './manifest.js');
|
|
50
42
|
writeFileSync(`${tmp}/worker.js`, worker_code);
|
|
@@ -82,20 +74,23 @@ export default function adapter(options = {}) {
|
|
|
82
74
|
return;
|
|
83
75
|
const files = readdirSync(dir);
|
|
84
76
|
for (const file of files) {
|
|
85
|
-
const fullPath =
|
|
77
|
+
const fullPath = `${dir}/${file}`;
|
|
86
78
|
const relativePath = prefix ? `${prefix}/${file}` : file;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
try {
|
|
80
|
+
if (statSync(fullPath).isDirectory()) {
|
|
81
|
+
collectAssets(fullPath, relativePath);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
staticAssets.push(`/${relativePath}`);
|
|
85
|
+
}
|
|
92
86
|
}
|
|
87
|
+
catch (_) { }
|
|
93
88
|
}
|
|
94
89
|
};
|
|
95
90
|
collectAssets(static_directory);
|
|
96
91
|
// Check for functions directory and build if present
|
|
97
92
|
// Look for functions in the project root
|
|
98
|
-
const functionsDir =
|
|
93
|
+
const functionsDir = `${process.cwd()}/functions`;
|
|
99
94
|
let functionsManifest = null;
|
|
100
95
|
if (existsSync(functionsDir)) {
|
|
101
96
|
builder.log.minor('Building edge functions from: ' + functionsDir);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAalF,+EAA+E;AAC/E,MAAM,sBAAsB,GAAG,0gGAA0gG,CAAC;AAE1iG,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,UAA0B,EAAE;IA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,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;gBAChE,cAAc,CAAC,GAAG,CAAC,CAAC;YACtB,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,qCAAqC,GAAG,EAAE,CAAC,CAAC;YAC9D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YAClC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,QAAQ,EAAE;YACR,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;SACjB;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maravilla-labs/adapter-sveltekit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "SvelteKit adapter for Maravilla Runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist",
|
|
10
|
-
"
|
|
9
|
+
"dist/index.js",
|
|
10
|
+
"dist/index.js.map",
|
|
11
|
+
"dist/index.d.ts",
|
|
12
|
+
"dist/index.d.ts.map",
|
|
13
|
+
"dist/merge-functions.js",
|
|
14
|
+
"dist/merge-functions.js.map"
|
|
11
15
|
],
|
|
12
16
|
"scripts": {
|
|
13
17
|
"build": "tsc",
|
|
14
18
|
"dev": "tsc --watch",
|
|
15
|
-
"test": "vitest"
|
|
19
|
+
"test": "vitest",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
16
21
|
},
|
|
17
22
|
"keywords": [
|
|
18
23
|
"sveltekit",
|
|
@@ -42,6 +47,6 @@
|
|
|
42
47
|
},
|
|
43
48
|
"dependencies": {
|
|
44
49
|
"@maravilla-labs/functions": "latest",
|
|
45
|
-
"esbuild": "^0.
|
|
50
|
+
"esbuild": "^0.25.0"
|
|
46
51
|
}
|
|
47
52
|
}
|
package/src/worker.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
// Maravilla Runtime Worker for SvelteKit
|
|
2
|
-
// This runs inside the Deno isolate with access to platform APIs
|
|
3
|
-
|
|
4
|
-
import { Server } from '__SERVER__';
|
|
5
|
-
import { manifest, prerendered, base } from '__MANIFEST__';
|
|
6
|
-
|
|
7
|
-
// Initialize the SvelteKit server
|
|
8
|
-
const server = new Server(manifest);
|
|
9
|
-
|
|
10
|
-
// Initialize server with platform-specific read function
|
|
11
|
-
const initialized = server.init({
|
|
12
|
-
env: globalThis.platform?.env || {},
|
|
13
|
-
read: async (file) => {
|
|
14
|
-
// For now, return empty stream for any file read attempts
|
|
15
|
-
// This is a placeholder until we implement proper static file serving
|
|
16
|
-
console.log('Read function called for file:', file);
|
|
17
|
-
|
|
18
|
-
// Return an empty ReadableStream to prevent errors
|
|
19
|
-
return new ReadableStream({
|
|
20
|
-
start(controller) {
|
|
21
|
-
// Just close the stream immediately
|
|
22
|
-
controller.close();
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Main request handler for the Maravilla runtime
|
|
30
|
-
* This function is called by the runtime for each incoming request
|
|
31
|
-
*/
|
|
32
|
-
async function handleRequest(request) {
|
|
33
|
-
// Ensure server is initialized
|
|
34
|
-
await initialized;
|
|
35
|
-
|
|
36
|
-
// Convert the incoming request object to a standard Request
|
|
37
|
-
const url = new URL(request.url, 'http://localhost');
|
|
38
|
-
|
|
39
|
-
// Prepare the body - handle different types
|
|
40
|
-
let requestBody = undefined;
|
|
41
|
-
if (request.body !== null && request.body !== undefined) {
|
|
42
|
-
// If body is already a string, use it directly
|
|
43
|
-
if (typeof request.body === 'string') {
|
|
44
|
-
requestBody = request.body;
|
|
45
|
-
} else {
|
|
46
|
-
// Otherwise stringify it
|
|
47
|
-
requestBody = JSON.stringify(request.body);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Create a standard Request object
|
|
52
|
-
const webRequest = new Request(url.toString(), {
|
|
53
|
-
method: request.method,
|
|
54
|
-
headers: request.headers || {},
|
|
55
|
-
body: requestBody
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// Check if this is a static asset request
|
|
59
|
-
const pathname = url.pathname;
|
|
60
|
-
const stripped_pathname = pathname.replace(/\/$/, '');
|
|
61
|
-
|
|
62
|
-
// Debug: verify URL.pathname setter works for data requests
|
|
63
|
-
if (pathname.endsWith('/__data.json') || pathname.endsWith('.html__data.json')) {
|
|
64
|
-
try {
|
|
65
|
-
const test = new URL(url.toString());
|
|
66
|
-
const before = test.pathname;
|
|
67
|
-
const candidate = pathname.endsWith('/__data.json')
|
|
68
|
-
? pathname.slice(0, -'/__data.json'.length)
|
|
69
|
-
: pathname.slice(0, -'.html__data.json'.length) + '.html';
|
|
70
|
-
test.pathname = candidate;
|
|
71
|
-
console.log('Data URL normalization test', { before, candidate, after: test.pathname, href: test.href });
|
|
72
|
-
} catch (e) {
|
|
73
|
-
console.error('Data URL normalization error', e);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Check if path is prerendered
|
|
78
|
-
if (prerendered.has(pathname)) {
|
|
79
|
-
// For prerendered pages, we could serve from static storage
|
|
80
|
-
// but for now, let SvelteKit handle it
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Handle trailing slash redirects for prerendered pages
|
|
84
|
-
const location = pathname.at(-1) === '/' ? stripped_pathname : pathname + '/';
|
|
85
|
-
if (location && prerendered.has(location)) {
|
|
86
|
-
return new Response('', {
|
|
87
|
-
status: 308,
|
|
88
|
-
headers: {
|
|
89
|
-
location: location + url.search
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Let SvelteKit handle the request
|
|
95
|
-
try {
|
|
96
|
-
console.log('SvelteKit server.respond called with:', {
|
|
97
|
-
url: webRequest.url,
|
|
98
|
-
method: webRequest.method,
|
|
99
|
-
hasBody: requestBody !== undefined,
|
|
100
|
-
platform: {
|
|
101
|
-
hasEnv: !!globalThis.platform?.env,
|
|
102
|
-
hasKv: !!globalThis.platform?.kv,
|
|
103
|
-
hasDb: !!globalThis.platform?.db
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const response = await server.respond(webRequest, {
|
|
108
|
-
platform: {
|
|
109
|
-
// Expose Maravilla platform APIs to SvelteKit
|
|
110
|
-
env: globalThis.platform?.env || {},
|
|
111
|
-
context: {
|
|
112
|
-
waitUntil: (promise) => {
|
|
113
|
-
// In Maravilla, we can queue background work
|
|
114
|
-
if (globalThis.platform?.queue) {
|
|
115
|
-
globalThis.platform.queue.send({ type: 'background', promise });
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
passThroughOnException: () => {
|
|
119
|
-
// Not applicable in Maravilla runtime
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
// Expose platform services
|
|
123
|
-
kv: globalThis.platform?.kv,
|
|
124
|
-
db: globalThis.platform?.db,
|
|
125
|
-
storage: globalThis.platform?.storage,
|
|
126
|
-
queue: globalThis.platform?.queue
|
|
127
|
-
},
|
|
128
|
-
getClientAddress: () => {
|
|
129
|
-
// Get client IP from request headers
|
|
130
|
-
const forwarded = webRequest.headers.get('x-forwarded-for');
|
|
131
|
-
if (forwarded) {
|
|
132
|
-
return forwarded.split(',')[0].trim();
|
|
133
|
-
}
|
|
134
|
-
return request.headers?.['x-real-ip'] || '127.0.0.1';
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Log response details
|
|
139
|
-
if (response.status >= 400) {
|
|
140
|
-
console.error('SvelteKit returned error:', {
|
|
141
|
-
status: response.status,
|
|
142
|
-
statusText: response.statusText,
|
|
143
|
-
url: webRequest.url
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Return the response in a format the runtime expects
|
|
148
|
-
return response;
|
|
149
|
-
} catch (error) {
|
|
150
|
-
console.error('Error in server.respond:', error);
|
|
151
|
-
console.error('Error stack:', error.stack);
|
|
152
|
-
throw error;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Export for the Maravilla runtime
|
|
157
|
-
globalThis.handleRequest = handleRequest;
|