@maravilla-labs/adapter-sveltekit 0.1.5 → 0.1.9

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Adapter } from '@sveltejs/kit';
2
- export interface AdapterOptions {
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAW,MAAM,eAAe,CAAC;AAEtD,MAAM,WAAW,cAAc;IAC7B,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;AAQD,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAkOrE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,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;AAgCD,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAkOrE"}
package/dist/index.js CHANGED
@@ -1,18 +1,35 @@
1
- import { readFileSync, writeFileSync, existsSync, readdirSync, statSync } from 'node:fs';
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
- import { buildFunctions, integrateWithManifest } from '@maravilla-labs/functions';
6
- function get_files_path() {
7
- const currentModulePath = fileURLToPath(import.meta.url);
8
- const currentDir = dirname(currentModulePath);
9
- return resolve(currentDir);
3
+ async function loadFunctionsAPI() {
4
+ const fallbacks = [
5
+ '@maravilla-labs/functions', // normal dependency when published/installed
6
+ '../../functions/dist/index.js', // workspace built output
7
+ '../../functions/src/index.ts', // workspace source fallback
8
+ ];
9
+ for (const spec of fallbacks) {
10
+ try {
11
+ const mod = await import(spec);
12
+ if (mod.buildFunctions && mod.integrateWithManifest) {
13
+ return { buildFunctions: mod.buildFunctions, integrateWithManifest: mod.integrateWithManifest };
14
+ }
15
+ }
16
+ catch (_) { /* try next */ }
17
+ }
18
+ // No available implementation; return safe shims
19
+ return {
20
+ buildFunctions: async () => null,
21
+ integrateWithManifest: async () => { },
22
+ };
10
23
  }
24
+ // Inline worker template to avoid requiring separate worker.js file at runtime
25
+ const INLINE_WORKER_TEMPLATE = `// Maravilla Runtime Worker for SvelteKit\n// This runs inside the Deno isolate with access to platform APIs\n\nimport { Server } from '__SERVER__';\nimport { manifest, prerendered, base } from '__MANIFEST__';\n\n// Initialize the SvelteKit server\nconst server = new Server(manifest);\n\n// Initialize server with platform-specific read function\nconst initialized = server.init({\n env: globalThis.platform?.env || {},\n read: async (file) => {\n // For now, return empty stream for any file read attempts\n // This is a placeholder until we implement proper static file serving\n console.log('Read function called for file:', file);\n \n // Return an empty ReadableStream to prevent errors\n return new ReadableStream({\n start(controller) {\n // Just close the stream immediately\n controller.close();\n }\n });\n }\n});\n\n/**\n * Main request handler for the Maravilla runtime\n * This function is called by the runtime for each incoming request\n */\nasync function handleRequest(request) {\n // Ensure server is initialized\n await initialized;\n\n // Convert the incoming request object to a standard Request\n const url = new URL(request.url, 'http://localhost');\n \n // Prepare the body - handle different types\n let requestBody = undefined;\n if (request.body !== null && request.body !== undefined) {\n // If body is already a string, use it directly\n if (typeof request.body === 'string') {\n requestBody = request.body;\n } else {\n // Otherwise stringify it\n requestBody = JSON.stringify(request.body);\n }\n }\n \n // Create a standard Request object\n const webRequest = new Request(url.toString(), {\n method: request.method,\n headers: request.headers || {},\n body: requestBody\n });\n\n // Check if this is a static asset request\n const pathname = url.pathname;\n const stripped_pathname = pathname.replace(/\\\/$/, '');\n\n // Debug: verify URL.pathname setter works for data requests\n if (pathname.endsWith('/__data.json') || pathname.endsWith('.html__data.json')) {\n try {\n const test = new URL(url.toString());\n const before = test.pathname;\n const candidate = pathname.endsWith('/__data.json')\n ? pathname.slice(0, -'/__data.json'.length)\n : pathname.slice(0, -'.html__data.json'.length) + '.html';\n test.pathname = candidate;\n console.log('Data URL normalization test', { before, candidate, after: test.pathname, href: test.href });\n } catch (e) {\n console.error('Data URL normalization error', e);\n }\n }\n \n // Check if path is prerendered\n if (prerendered.has(pathname)) {\n // For prerendered pages, we could serve from static storage\n // but for now, let SvelteKit handle it\n }\n\n // Handle trailing slash redirects for prerendered pages\n const location = pathname.at(-1) === '/' ? stripped_pathname : pathname + '/';\n if (location && prerendered.has(location)) {\n return new Response('', {\n status: 308,\n headers: {\n location: location + url.search\n }\n });\n }\n\n // Let SvelteKit handle the request\n try {\n console.log('SvelteKit server.respond called with:', {\n url: webRequest.url,\n method: webRequest.method,\n hasBody: requestBody !== undefined,\n platform: {\n hasEnv: !!globalThis.platform?.env,\n hasKv: !!globalThis.platform?.kv,\n hasDb: !!globalThis.platform?.db\n }\n });\n \n const response = await server.respond(webRequest, {\n platform: {\n // Expose Maravilla platform APIs to SvelteKit\n env: globalThis.platform?.env || {},\n context: {\n waitUntil: (promise) => {\n // In Maravilla, we can queue background work\n if (globalThis.platform?.queue) {\n globalThis.platform.queue.send({ type: 'background', promise });\n }\n },\n passThroughOnException: () => {\n // Not applicable in Maravilla runtime\n }\n },\n // Expose platform services\n kv: globalThis.platform?.kv,\n db: globalThis.platform?.db,\n storage: globalThis.platform?.storage,\n queue: globalThis.platform?.queue\n },\n getClientAddress: () => {\n // Get client IP from request headers\n const forwarded = webRequest.headers.get('x-forwarded-for');\n if (forwarded) {\n return forwarded.split(',')[0].trim();\n }\n return request.headers?.['x-real-ip'] || '127.0.0.1';\n }\n });\n\n // Log response details\n if (response.status >= 400) {\n console.error('SvelteKit returned error:', {\n status: response.status,\n statusText: response.statusText,\n url: webRequest.url\n });\n }\n\n // Return the response in a format the runtime expects\n return response;\n } catch (error) {\n console.error('Error in server.respond:', error);\n console.error('Error stack:', error.stack);\n throw error;\n }\n}\n\n// Export for the Maravilla runtime\nglobalThis.handleRequest = handleRequest;`;
11
26
  export default function adapter(options = {}) {
12
27
  const { out = '.maravilla', precompress = false, envPrefix = 'PUBLIC_', polyfill = true, include = [], exclude = [], external = [] } = options;
13
28
  return {
14
- name: '@solutas/adapter-sveltekit',
29
+ name: '@maravilla-labs/adapter-sveltekit',
15
30
  async adapt(builder) {
31
+ // Resolve functions tooling (works both in monorepo dev and published package usage)
32
+ const { buildFunctions, integrateWithManifest } = await loadFunctionsAPI();
16
33
  const tmp = builder.getBuildDirectory('adapter-maravilla');
17
34
  // Clean output directories
18
35
  builder.rimraf(out);
@@ -41,10 +58,7 @@ export default function adapter(options = {}) {
41
58
  `export const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});`,
42
59
  `export const base = ${JSON.stringify(builder.config.kit.paths.base)};`
43
60
  ].join('\n\n'));
44
- // Create the worker entry point
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
61
+ const worker_code = INLINE_WORKER_TEMPLATE
48
62
  .replace('__SERVER__', './index.js')
49
63
  .replace('__MANIFEST__', './manifest.js');
50
64
  writeFileSync(`${tmp}/worker.js`, worker_code);
@@ -82,20 +96,23 @@ export default function adapter(options = {}) {
82
96
  return;
83
97
  const files = readdirSync(dir);
84
98
  for (const file of files) {
85
- const fullPath = join(dir, file);
99
+ const fullPath = `${dir}/${file}`;
86
100
  const relativePath = prefix ? `${prefix}/${file}` : file;
87
- if (statSync(fullPath).isDirectory()) {
88
- collectAssets(fullPath, relativePath);
89
- }
90
- else {
91
- staticAssets.push(`/${relativePath}`);
101
+ try {
102
+ if (statSync(fullPath).isDirectory()) {
103
+ collectAssets(fullPath, relativePath);
104
+ }
105
+ else {
106
+ staticAssets.push(`/${relativePath}`);
107
+ }
92
108
  }
109
+ catch (_) { }
93
110
  }
94
111
  };
95
112
  collectAssets(static_directory);
96
113
  // Check for functions directory and build if present
97
114
  // Look for functions in the project root
98
- const functionsDir = join(process.cwd(), 'functions');
115
+ const functionsDir = `${process.cwd()}/functions`;
99
116
  let functionsManifest = null;
100
117
  if (existsSync(functionsDir)) {
101
118
  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,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,cAAc,E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,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,6 +1,6 @@
1
1
  {
2
2
  "name": "@maravilla-labs/adapter-sveltekit",
3
- "version": "0.1.5",
3
+ "version": "0.1.9",
4
4
  "description": "SvelteKit adapter for Maravilla Runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -10,11 +10,8 @@
10
10
  "dist/index.js.map",
11
11
  "dist/index.d.ts",
12
12
  "dist/index.d.ts.map",
13
- "dist/worker.js",
14
13
  "dist/merge-functions.js",
15
- "dist/worker.js.map",
16
- "dist/merge-functions.js.map",
17
- "src/worker.js"
14
+ "dist/merge-functions.js.map"
18
15
  ],
19
16
  "scripts": {
20
17
  "build": "tsc",
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;