@maravilla-labs/adapter-react-router 0.2.5 → 0.2.6
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/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +25 -2
- package/dist/vite-plugin.js.map +1 -1
- package/dist/worker-template.d.ts +1 -1
- package/dist/worker-template.d.ts.map +1 -1
- package/dist/worker-template.js +13 -1
- package/dist/worker-template.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAUL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAGtC,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,yBAA8B,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAUL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAGtC,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,yBAA8B,GAAG,MAAM,CAgKpF"}
|
package/dist/vite-plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { writeFileSync, mkdirSync, cpSync, existsSync, rmSync } from 'node:fs';
|
|
2
|
-
import { resolve, join } from 'node:path';
|
|
2
|
+
import { resolve, join, sep } from 'node:path';
|
|
3
3
|
import { bundleServerEntry, analyzeBundle, generateManifest, writeManifest, collectAssets, buildAndIntegrateFunctions, buildAndIntegrateEvents, buildAndIntegrateWorkflows, loadMaravillaConfig, } from '@maravilla-labs/adapter-core';
|
|
4
4
|
import { WORKER_TEMPLATE } from './worker-template.js';
|
|
5
5
|
/**
|
|
@@ -7,7 +7,17 @@ import { WORKER_TEMPLATE } from './worker-template.js';
|
|
|
7
7
|
* a Maravilla Runtime bundle in `.maravilla/`.
|
|
8
8
|
*/
|
|
9
9
|
export function maravillaReactRouter(options = {}) {
|
|
10
|
-
|
|
10
|
+
// React Router v7 runs its own Vite SSR build BEFORE this adapter hooks in
|
|
11
|
+
// (`closeBundle`, `enforce: 'post'`). Two physical build outputs live on
|
|
12
|
+
// disk: React Router's intermediate (server/, client/) and this adapter's
|
|
13
|
+
// final artifact. Staging React Router's output under node_modules keeps
|
|
14
|
+
// the final artifact free to own `build/` — matching the SvelteKit-style
|
|
15
|
+
// convention `maravilla deploy build`. Users MUST set
|
|
16
|
+
// buildDirectory: 'node_modules/.maravilla-rr-staging'
|
|
17
|
+
// in their `react-router.config.ts` for these defaults to align. If they
|
|
18
|
+
// leave React Router at its own default (`build`), the collision guard in
|
|
19
|
+
// `closeBundle` below fails fast with a helpful message.
|
|
20
|
+
const { out = 'build', serverBuildPath = 'node_modules/.maravilla-rr-staging/server', clientBuildPath = 'node_modules/.maravilla-rr-staging/client', serverBuildFile = 'index.js', envPrefix = 'PUBLIC_', polyfill = true, include = [], exclude = [], external = [], precompress = false, } = options;
|
|
11
21
|
let root;
|
|
12
22
|
return {
|
|
13
23
|
name: '@maravilla-labs/adapter-react-router',
|
|
@@ -28,6 +38,19 @@ export function maravillaReactRouter(options = {}) {
|
|
|
28
38
|
}
|
|
29
39
|
const outDir = resolve(root, out);
|
|
30
40
|
const tmpDir = resolve(root, 'node_modules/.maravilla-tmp');
|
|
41
|
+
// Collision guard: if the user configured React Router's build output
|
|
42
|
+
// to live inside the adapter's output directory, the `rmSync(outDir)`
|
|
43
|
+
// below would wipe the adapter's own input before it could read it.
|
|
44
|
+
// Fail fast with a clear message instead of silently deleting.
|
|
45
|
+
const serverResolved = resolve(root, serverBuildPath);
|
|
46
|
+
const clientResolved = resolve(root, clientBuildPath);
|
|
47
|
+
if (serverResolved.startsWith(outDir + sep) ||
|
|
48
|
+
clientResolved.startsWith(outDir + sep)) {
|
|
49
|
+
throw new Error(`[maravilla] React Router's build output (${serverBuildPath} / ${clientBuildPath}) ` +
|
|
50
|
+
`lives inside the adapter output directory (${out}). The adapter would wipe its own input. ` +
|
|
51
|
+
`Set \`react-router.config.ts\` 'buildDirectory' to 'node_modules/.maravilla-rr-staging' ` +
|
|
52
|
+
`(or leave serverBuildPath / clientBuildPath at their new defaults, which match).`);
|
|
53
|
+
}
|
|
31
54
|
// Clean output
|
|
32
55
|
if (existsSync(outDir))
|
|
33
56
|
rmSync(outDir, { recursive: true });
|
package/dist/vite-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,E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AAC"}
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* all imports at bundle time. Lazy initialization in handleRequest avoids
|
|
10
10
|
* top-level await.
|
|
11
11
|
*/
|
|
12
|
-
export declare const WORKER_TEMPLATE = "// Maravilla Runtime Worker Polyfills\n// Shared across all framework adapters\n\nconst originalFetch = globalThis.fetch;\nconst OriginalRequest = globalThis.Request;\n\nclass EnhancedRequest extends OriginalRequest {\n constructor(input, init) {\n if (typeof input === 'string') {\n try {\n super(input, init);\n } catch (e) {\n if (globalThis.location && e.message && e.message.includes('relative')) {\n try {\n const absoluteUrl = new URL(input, globalThis.location.href);\n super(absoluteUrl.href, init);\n } catch (e2) {\n throw e;\n }\n } else {\n throw e;\n }\n }\n return;\n }\n\n if (input && typeof input === 'object' && !(input instanceof OriginalRequest)) {\n const url = input.url || input.href || input.toString();\n if (!url) {\n throw new TypeError('Request must have a URL');\n }\n const newInit = {\n method: input.method || init?.method || 'GET',\n headers: input.headers || init?.headers,\n body: input.body || init?.body,\n mode: input.mode || init?.mode,\n credentials: input.credentials || init?.credentials,\n cache: input.cache || init?.cache,\n redirect: input.redirect || init?.redirect,\n referrer: input.referrer || init?.referrer,\n referrerPolicy: input.referrerPolicy || init?.referrerPolicy,\n integrity: input.integrity || init?.integrity,\n keepalive: input.keepalive || init?.keepalive,\n signal: input.signal || init?.signal,\n ...init\n };\n super(url, newInit);\n return;\n }\n\n super(input, init);\n }\n}\n\nglobalThis.Request = EnhancedRequest;\n\nglobalThis.fetch = function enhancedFetch(input, init) {\n let request;\n\n if (input instanceof Request) {\n request = input;\n } else if (typeof input === 'string') {\n if (input.startsWith('http://') || input.startsWith('https://')) {\n request = new Request(input, init);\n } else if (globalThis.location) {\n try {\n const absoluteUrl = new URL(input, globalThis.location.href);\n request = new Request(absoluteUrl.href, init);\n } catch (e) {\n console.error('Failed to resolve relative URL:', input, 'against', globalThis.location.href);\n throw e;\n }\n } else {\n console.error('Cannot resolve relative URL without globalThis.location:', input);\n throw new Error('Cannot resolve relative URL without a base URL');\n }\n } else if (input && typeof input === 'object') {\n request = new Request(input, init);\n } else {\n throw new TypeError('First argument must be a string, Request, or URL');\n }\n\n return originalFetch(request);\n};\n\n\n// Import the React Router server build (resolved by esbuild at bundle time)\nimport * as build from '__SERVER_BUILD__';\nimport { createRequestHandler } from 'react-router';\n\n// Lazy-init the handler on first request (avoids top-level await)\nlet handler;\n\nasync function handleRequest(request) {\n if (!handler) {\n handler = createRequestHandler(build, 'production');\n }\n\n // Re-apply polyfills if needed (worker reuse)\n if (globalThis.Request !== EnhancedRequest) {\n globalThis.Request = EnhancedRequest;\n globalThis.fetch = enhancedFetch;\n }\n\n // Build the load context that React Router passes to loaders/actions.\n // Users access this via: export async function loader({ context }) { ... }\n const loadContext = {\n platform: globalThis.platform,\n env: globalThis.platform?.env || {},\n kv: globalThis.platform?.kv,\n db: globalThis.platform?.db,\n storage: globalThis.platform?.storage,\n queue: globalThis.platform?.queue,\n };\n\n try {\n const response = await handler(
|
|
12
|
+
export declare const WORKER_TEMPLATE = "// Maravilla Runtime Worker Polyfills\n// Shared across all framework adapters\n\nconst originalFetch = globalThis.fetch;\nconst OriginalRequest = globalThis.Request;\n\nclass EnhancedRequest extends OriginalRequest {\n constructor(input, init) {\n if (typeof input === 'string') {\n try {\n super(input, init);\n } catch (e) {\n if (globalThis.location && e.message && e.message.includes('relative')) {\n try {\n const absoluteUrl = new URL(input, globalThis.location.href);\n super(absoluteUrl.href, init);\n } catch (e2) {\n throw e;\n }\n } else {\n throw e;\n }\n }\n return;\n }\n\n if (input && typeof input === 'object' && !(input instanceof OriginalRequest)) {\n const url = input.url || input.href || input.toString();\n if (!url) {\n throw new TypeError('Request must have a URL');\n }\n const newInit = {\n method: input.method || init?.method || 'GET',\n headers: input.headers || init?.headers,\n body: input.body || init?.body,\n mode: input.mode || init?.mode,\n credentials: input.credentials || init?.credentials,\n cache: input.cache || init?.cache,\n redirect: input.redirect || init?.redirect,\n referrer: input.referrer || init?.referrer,\n referrerPolicy: input.referrerPolicy || init?.referrerPolicy,\n integrity: input.integrity || init?.integrity,\n keepalive: input.keepalive || init?.keepalive,\n signal: input.signal || init?.signal,\n ...init\n };\n super(url, newInit);\n return;\n }\n\n super(input, init);\n }\n}\n\nglobalThis.Request = EnhancedRequest;\n\nglobalThis.fetch = function enhancedFetch(input, init) {\n let request;\n\n if (input instanceof Request) {\n request = input;\n } else if (typeof input === 'string') {\n if (input.startsWith('http://') || input.startsWith('https://')) {\n request = new Request(input, init);\n } else if (globalThis.location) {\n try {\n const absoluteUrl = new URL(input, globalThis.location.href);\n request = new Request(absoluteUrl.href, init);\n } catch (e) {\n console.error('Failed to resolve relative URL:', input, 'against', globalThis.location.href);\n throw e;\n }\n } else {\n console.error('Cannot resolve relative URL without globalThis.location:', input);\n throw new Error('Cannot resolve relative URL without a base URL');\n }\n } else if (input && typeof input === 'object') {\n request = new Request(input, init);\n } else {\n throw new TypeError('First argument must be a string, Request, or URL');\n }\n\n return originalFetch(request);\n};\n\n\n// Import the React Router server build (resolved by esbuild at bundle time)\nimport * as build from '__SERVER_BUILD__';\nimport { createRequestHandler } from 'react-router';\n\n// Lazy-init the handler on first request (avoids top-level await)\nlet handler;\n\nasync function handleRequest(request) {\n if (!handler) {\n handler = createRequestHandler(build, 'production');\n }\n\n // Re-apply polyfills if needed (worker reuse)\n if (globalThis.Request !== EnhancedRequest) {\n globalThis.Request = EnhancedRequest;\n globalThis.fetch = enhancedFetch;\n }\n\n // React Router v7's singleFetchAction hard-invariants on request.signal\n // being an AbortSignal. The runtime attaches one when it constructs the\n // Request (crates/runtime/src/worker_core/streaming_js.rs), but that\n // signal can be lost across the custom Request polyfill's re-construction\n // paths or React Router's internal single-fetch wrapping. Guarantee one\n // here at the last mile \u2014 keeping the controller on a local const so its\n // signal isn't GC'd out from under us mid-handler.\n const abortController = new AbortController();\n const requestForHandler = request.signal\n ? request\n : new Request(request, { signal: abortController.signal });\n\n // Build the load context that React Router passes to loaders/actions.\n // Users access this via: export async function loader({ context }) { ... }\n const loadContext = {\n platform: globalThis.platform,\n env: globalThis.platform?.env || {},\n kv: globalThis.platform?.kv,\n db: globalThis.platform?.db,\n storage: globalThis.platform?.storage,\n queue: globalThis.platform?.queue,\n };\n\n try {\n const response = await handler(requestForHandler, loadContext);\n console.log('[maravilla] Response status:', response.status);\n if (response.status >= 500) {\n const body = await response.clone().text();\n console.error('[maravilla] 500 response body:', body || '(empty)');\n }\n return response;\n } catch (error) {\n console.error('[maravilla] handleRequest error:', error?.message || error);\n console.error('[maravilla] stack:', error?.stack || 'no stack');\n throw error;\n }\n}\n\nglobalThis.handleRequest = handleRequest;\n";
|
|
13
13
|
//# sourceMappingURL=worker-template.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-template.d.ts","sourceRoot":"","sources":["../src/worker-template.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"worker-template.d.ts","sourceRoot":"","sources":["../src/worker-template.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,o8JA2D3B,CAAC"}
|
package/dist/worker-template.js
CHANGED
|
@@ -30,6 +30,18 @@ async function handleRequest(request) {
|
|
|
30
30
|
globalThis.fetch = enhancedFetch;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// React Router v7's singleFetchAction hard-invariants on request.signal
|
|
34
|
+
// being an AbortSignal. The runtime attaches one when it constructs the
|
|
35
|
+
// Request (crates/runtime/src/worker_core/streaming_js.rs), but that
|
|
36
|
+
// signal can be lost across the custom Request polyfill's re-construction
|
|
37
|
+
// paths or React Router's internal single-fetch wrapping. Guarantee one
|
|
38
|
+
// here at the last mile — keeping the controller on a local const so its
|
|
39
|
+
// signal isn't GC'd out from under us mid-handler.
|
|
40
|
+
const abortController = new AbortController();
|
|
41
|
+
const requestForHandler = request.signal
|
|
42
|
+
? request
|
|
43
|
+
: new Request(request, { signal: abortController.signal });
|
|
44
|
+
|
|
33
45
|
// Build the load context that React Router passes to loaders/actions.
|
|
34
46
|
// Users access this via: export async function loader({ context }) { ... }
|
|
35
47
|
const loadContext = {
|
|
@@ -42,7 +54,7 @@ async function handleRequest(request) {
|
|
|
42
54
|
};
|
|
43
55
|
|
|
44
56
|
try {
|
|
45
|
-
const response = await handler(
|
|
57
|
+
const response = await handler(requestForHandler, loadContext);
|
|
46
58
|
console.log('[maravilla] Response status:', response.status);
|
|
47
59
|
if (response.status >= 500) {
|
|
48
60
|
const body = await response.clone().text();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-template.js","sourceRoot":"","sources":["../src/worker-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,gBAAgB
|
|
1
|
+
{"version":3,"file":"worker-template.js","sourceRoot":"","sources":["../src/worker-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2DjD,CAAC"}
|