@maravilla-labs/preset-nitro 0.1.0

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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Nitro entry point for the Maravilla Runtime.
3
+ *
4
+ * This file is used as the Nitro server entry and runs inside the Deno V8 isolate.
5
+ * It imports the Nitro app and wires it to the globalThis.handleRequest contract.
6
+ *
7
+ * NOTE: This file is bundled by Nitro's build process (Rollup), not by our esbuild.
8
+ * The #internal imports are virtual modules resolved by Nitro at build time.
9
+ */
10
+ import '#internal/nitro/virtual/polyfill';
11
+ //# sourceMappingURL=entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,kCAAkC,CAAC"}
package/dist/entry.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Nitro entry point for the Maravilla Runtime.
3
+ *
4
+ * This file is used as the Nitro server entry and runs inside the Deno V8 isolate.
5
+ * It imports the Nitro app and wires it to the globalThis.handleRequest contract.
6
+ *
7
+ * NOTE: This file is bundled by Nitro's build process (Rollup), not by our esbuild.
8
+ * The #internal imports are virtual modules resolved by Nitro at build time.
9
+ */
10
+ // @ts-ignore - Nitro virtual module
11
+ import '#internal/nitro/virtual/polyfill';
12
+ // @ts-ignore - Nitro virtual module
13
+ const nitroApp = (await import('#internal/nitro/virtual/server')).default;
14
+ /**
15
+ * Main request handler for the Maravilla Runtime.
16
+ * Called by the runtime for each incoming HTTP request.
17
+ */
18
+ async function handleRequest(request) {
19
+ const url = new URL(request.url);
20
+ // Use Nitro's localFetch to process the request through the H3 stack.
21
+ // This invokes all Nitro middleware, server routes, and event handlers.
22
+ const response = await nitroApp.localFetch(url.pathname + url.search, {
23
+ method: request.method,
24
+ headers: request.headers,
25
+ body: request.body,
26
+ // Inject Maravilla platform services into the Nitro event context.
27
+ // Access in server routes via: event.context.platform
28
+ context: {
29
+ platform: globalThis.platform,
30
+ },
31
+ });
32
+ return response;
33
+ }
34
+ globalThis.handleRequest = handleRequest;
35
+ //# sourceMappingURL=entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,oCAAoC;AACpC,OAAO,kCAAkC,CAAC;AAE1C,oCAAoC;AACpC,MAAM,QAAQ,GAAG,CAAC,MAAM,MAAM,CAAC,gCAAgC,CAAC,CAAC,CAAC,OAAO,CAAC;AAE1E;;;GAGG;AACH,KAAK,UAAU,aAAa,CAAC,OAAgB;IAC3C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAEjC,sEAAsE;IACtE,wEAAwE;IACxE,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,EAAE;QACpE,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,mEAAmE;QACnE,sDAAsD;QACtD,OAAO,EAAE;YACP,QAAQ,EAAG,UAAkB,CAAC,QAAQ;SACvC;KACF,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAEA,UAAkB,CAAC,aAAa,GAAG,aAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createMaravillaPreset, type MaravillaPresetOptions } from './preset.js';
2
+ export { default } from './preset.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { createMaravillaPreset } from './preset.js';
2
+ export { default } from './preset.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAA+B,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The Maravilla Nitro preset definition.
3
+ *
4
+ * This is consumed by Nitro's preset system. Users configure it in:
5
+ *
6
+ * ```ts
7
+ * // nuxt.config.ts
8
+ * export default defineNuxtConfig({
9
+ * nitro: { preset: '@maravilla-labs/preset-nitro' }
10
+ * })
11
+ * ```
12
+ *
13
+ * or standalone Nitro:
14
+ *
15
+ * ```ts
16
+ * // nitro.config.ts
17
+ * export default defineNitroConfig({
18
+ * preset: '@maravilla-labs/preset-nitro'
19
+ * })
20
+ * ```
21
+ */
22
+ export interface MaravillaPresetOptions {
23
+ /** Output directory (default: '.maravilla') */
24
+ out?: string;
25
+ /** Environment variable prefix (default: 'PUBLIC_') */
26
+ envPrefix?: string;
27
+ }
28
+ /**
29
+ * Create a Nitro preset configuration object for Maravilla Runtime.
30
+ *
31
+ * Nitro presets are plain objects with specific shape. The `defineNitroPreset`
32
+ * helper is provided by nitropack but we define the shape manually to avoid
33
+ * requiring nitropack as a hard dependency at build time.
34
+ */
35
+ export declare function createMaravillaPreset(options?: MaravillaPresetOptions): {
36
+ entry: string;
37
+ node: boolean;
38
+ exportConditions: string[];
39
+ hooks: {
40
+ /**
41
+ * Called after Nitro compiles the server bundle.
42
+ * We use this to restructure output into .maravilla/ format
43
+ * and generate the platform manifest.
44
+ */
45
+ compiled(nitro: any): Promise<void>;
46
+ };
47
+ };
48
+ /**
49
+ * Default export: the preset object ready for use in nitro.config.ts or nuxt.config.ts
50
+ */
51
+ declare const _default: {
52
+ entry: string;
53
+ node: boolean;
54
+ exportConditions: string[];
55
+ hooks: {
56
+ /**
57
+ * Called after Nitro compiles the server bundle.
58
+ * We use this to restructure output into .maravilla/ format
59
+ * and generate the platform manifest.
60
+ */
61
+ compiled(nitro: any): Promise<void>;
62
+ };
63
+ };
64
+ export default _default;
65
+ //# sourceMappingURL=preset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../src/preset.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,sBAAsB;IACrC,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAID;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B;;;;;QAepE;;;;WAIG;wBACmB,GAAG;;EA2E9B;AAaD;;GAEG;;;;;;QA/FG;;;;WAIG;wBACmB,GAAG;;;AA2F/B,wBAAuC"}
package/dist/preset.js ADDED
@@ -0,0 +1,113 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { readFileSync, writeFileSync, cpSync, existsSync, rmSync, mkdirSync } from 'node:fs';
3
+ import { resolve, join } from 'node:path';
4
+ import { generateManifest, writeManifest, collectAssets, buildAndIntegrateFunctions, } from '@maravilla-labs/adapter-core';
5
+ const entryPath = fileURLToPath(new URL('./entry.js', import.meta.url));
6
+ /**
7
+ * Create a Nitro preset configuration object for Maravilla Runtime.
8
+ *
9
+ * Nitro presets are plain objects with specific shape. The `defineNitroPreset`
10
+ * helper is provided by nitropack but we define the shape manually to avoid
11
+ * requiring nitropack as a hard dependency at build time.
12
+ */
13
+ export function createMaravillaPreset(options = {}) {
14
+ const { out = '.maravilla', envPrefix = 'PUBLIC_' } = options;
15
+ return {
16
+ // Entry file that Nitro will use as the server entry
17
+ entry: entryPath,
18
+ // Runtime target configuration
19
+ node: false,
20
+ // ESM export conditions for worker environments
21
+ exportConditions: ['worker', 'webworker'],
22
+ // Build hooks for post-processing
23
+ hooks: {
24
+ /**
25
+ * Called after Nitro compiles the server bundle.
26
+ * We use this to restructure output into .maravilla/ format
27
+ * and generate the platform manifest.
28
+ */
29
+ async compiled(nitro) {
30
+ const rootDir = nitro.options.rootDir || process.cwd();
31
+ const nitroOutput = nitro.options.output?.dir || join(rootDir, '.output');
32
+ const serverOutput = nitro.options.output?.serverDir || join(nitroOutput, 'server');
33
+ const publicOutput = nitro.options.output?.publicDir || join(nitroOutput, 'public');
34
+ const outDir = resolve(rootDir, out);
35
+ // Clean previous output
36
+ if (existsSync(outDir))
37
+ rmSync(outDir, { recursive: true });
38
+ mkdirSync(outDir, { recursive: true });
39
+ console.log('[maravilla] Post-processing Nitro build output...');
40
+ // Copy server bundle to .maravilla/server.js
41
+ const serverEntry = join(serverOutput, 'index.mjs');
42
+ if (existsSync(serverEntry)) {
43
+ const serverCode = readFileSync(serverEntry, 'utf8');
44
+ writeFileSync(join(outDir, 'server.js'), serverCode);
45
+ console.log('[maravilla] Copied server bundle');
46
+ }
47
+ else {
48
+ console.warn(`[maravilla] Server entry not found at ${serverEntry}`);
49
+ }
50
+ // Copy public assets to .maravilla/static/
51
+ const staticDir = join(outDir, 'static');
52
+ if (existsSync(publicOutput)) {
53
+ cpSync(publicOutput, staticDir, { recursive: true });
54
+ console.log('[maravilla] Copied public assets to static/');
55
+ }
56
+ // Collect static assets
57
+ const staticAssets = collectAssets(staticDir);
58
+ // Detect prerendered pages
59
+ const prerenderedPaths = staticAssets
60
+ .filter(p => p.endsWith('.html'))
61
+ .map(p => {
62
+ if (p === '/index.html')
63
+ return '/';
64
+ return p.replace(/\.html$/, '').replace(/\/index$/, '/');
65
+ });
66
+ // Read Nitro's route rules for additional context
67
+ const routeRules = nitro.options.routeRules || {};
68
+ // Generate manifest
69
+ const manifest = generateManifest({
70
+ adapterName: '@maravilla-labs/preset-nitro',
71
+ prerenderedPaths,
72
+ staticAssets,
73
+ envPrefix,
74
+ features: {
75
+ ssr: true,
76
+ prerendering: prerenderedPaths.length > 0,
77
+ polyfill: true,
78
+ streaming: true,
79
+ compression: false,
80
+ },
81
+ extraMetadata: {
82
+ framework: detectFramework(nitro),
83
+ nitro_version: nitro.options._dependencies?.nitropack || 'unknown',
84
+ },
85
+ });
86
+ writeManifest(outDir, manifest);
87
+ // Build and integrate edge functions
88
+ await buildAndIntegrateFunctions(rootDir, outDir);
89
+ console.log(`[maravilla] Build complete. Output written to ${out}`);
90
+ console.log('[maravilla] Deploy with:');
91
+ console.log(`[maravilla] maravilla deploy ${out}`);
92
+ },
93
+ },
94
+ };
95
+ }
96
+ /**
97
+ * Detect which framework is using Nitro based on available hints.
98
+ */
99
+ function detectFramework(nitro) {
100
+ const deps = nitro.options._dependencies || {};
101
+ if (deps.nuxt)
102
+ return 'nuxt';
103
+ if (deps['solid-start'] || deps['@solidjs/start'])
104
+ return 'solid-start';
105
+ if (deps['@tanstack/start'])
106
+ return 'tanstack-start';
107
+ return 'nitro';
108
+ }
109
+ /**
110
+ * Default export: the preset object ready for use in nitro.config.ts or nuxt.config.ts
111
+ */
112
+ export default createMaravillaPreset();
113
+ //# sourceMappingURL=preset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset.js","sourceRoot":"","sources":["../src/preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAW,MAAM,WAAW,CAAC;AACnD,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,0BAA0B,GAC3B,MAAM,8BAA8B,CAAC;AA+BtC,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,YAAY,EAAE,M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
+ {
2
+ "name": "@maravilla-labs/preset-nitro",
3
+ "version": "0.1.0",
4
+ "description": "Nitro preset for Maravilla Runtime (supports Nuxt, SolidStart, TanStack Start)",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./entry": {
14
+ "import": "./dist/entry.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "dev": "tsc --watch",
23
+ "prepublishOnly": "npm run build"
24
+ },
25
+ "keywords": [
26
+ "nitro",
27
+ "nuxt",
28
+ "solidstart",
29
+ "tanstack",
30
+ "maravilla",
31
+ "edge",
32
+ "runtime",
33
+ "ssr",
34
+ "preset"
35
+ ],
36
+ "author": "SOLUTAS GmbH",
37
+ "license": "Proprietary",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/maravilla-labs/maravilla-runtime.git",
41
+ "directory": "packages/preset-nitro"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "peerDependencies": {
47
+ "nitropack": "^2.0.0",
48
+ "@maravilla-labs/functions": "*"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "@maravilla-labs/functions": {
52
+ "optional": true
53
+ },
54
+ "nitropack": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "dependencies": {
59
+ "@maravilla-labs/adapter-core": "workspace:*"
60
+ },
61
+ "devDependencies": {
62
+ "@types/node": "^20.0.0",
63
+ "typescript": "^5.0.0"
64
+ }
65
+ }