reroute-js 1.0.0-alpha.36 → 1.0.0-alpha.37
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/README.md +2 -0
- package/cli/bin.d.ts +1 -1
- package/cli/bin.js +129 -22
- package/cli/bin.js.map +9 -8
- package/cli/index.d.ts +1 -1
- package/cli/index.js +4 -4
- package/cli/index.js.map +4 -4
- package/cli/src/cli.d.ts +1 -1
- package/cli/src/commands/analyze.d.ts +1 -1
- package/cli/src/commands/build.d.ts +1 -1
- package/cli/src/commands/dev.d.ts +1 -1
- package/cli/src/commands/gen.d.ts +1 -1
- package/cli/src/commands/gen.d.ts.map +1 -1
- package/cli/src/commands/index.d.ts +1 -1
- package/cli/src/commands/init.d.ts +1 -1
- package/cli/src/commands/lib/assets.d.ts +1 -1
- package/cli/src/commands/lib/bundler.d.ts +1 -1
- package/cli/src/commands/lib/command.d.ts +1 -1
- package/cli/src/commands/lib/env.d.ts +1 -1
- package/cli/src/commands/lib/images.d.ts +1 -1
- package/cli/src/commands/lib/index.d.ts +1 -1
- package/cli/src/commands/lib/log.d.ts +1 -1
- package/cli/src/commands/lib/markdown/availability.d.ts +1 -1
- package/cli/src/commands/lib/markdown/index.d.ts +1 -1
- package/cli/src/commands/lib/markdown/processor.d.ts +1 -1
- package/cli/src/commands/lib/prerender.d.ts +1 -1
- package/cli/src/commands/lib/production.d.ts +1 -1
- package/cli/src/commands/lib/routes.d.ts +1 -1
- package/cli/src/commands/lib/server.d.ts +1 -1
- package/cli/src/commands/lib/ssr-strip.d.ts +33 -0
- package/cli/src/commands/lib/ssr-strip.d.ts.map +1 -0
- package/cli/src/commands/lib/static.d.ts +1 -1
- package/cli/src/commands/lib/streaming/analyzer.d.ts +1 -1
- package/cli/src/commands/lib/streaming/suspense.d.ts +1 -1
- package/cli/src/commands/lib/supervise.d.ts +1 -1
- package/cli/src/commands/lib/terminal-ui.d.ts +1 -1
- package/cli/src/commands/lib/theme.d.ts +1 -1
- package/cli/src/commands/lib/version.d.ts +1 -1
- package/cli/src/commands/lib/watch.d.ts +1 -1
- package/cli/src/commands/og.d.ts +1 -1
- package/cli/src/commands/start.d.ts +1 -1
- package/cli/src/commands/static-render.d.ts +1 -1
- package/cli/src/index.d.ts +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +10 -4
- package/core/index.js.map +5 -5
- package/core/src/app-paths.d.ts +1 -1
- package/core/src/bundler/hash.d.ts +1 -1
- package/core/src/bundler/index.d.ts +1 -1
- package/core/src/config.d.ts +1 -1
- package/core/src/content/discovery.d.ts +1 -1
- package/core/src/content/index.d.ts +1 -1
- package/core/src/content/metadata.d.ts +1 -1
- package/core/src/i18n/catalog.d.ts +1 -1
- package/core/src/i18n/discover.d.ts +1 -1
- package/core/src/i18n/index.d.ts +1 -1
- package/core/src/i18n/messages.d.ts +1 -1
- package/core/src/i18n/negotiate.d.ts +1 -1
- package/core/src/i18n/pathname.d.ts +1 -1
- package/core/src/i18n/resolve.d.ts +1 -1
- package/core/src/i18n/types.d.ts +1 -1
- package/core/src/image.d.ts +1 -1
- package/core/src/index.d.ts +1 -1
- package/core/src/llms/discovery.d.ts +1 -1
- package/core/src/llms/extractor.d.ts +1 -1
- package/core/src/llms/formatter.d.ts +1 -1
- package/core/src/llms/full-generator.d.ts +1 -1
- package/core/src/llms/index-generator.d.ts +1 -1
- package/core/src/llms/index.d.ts +1 -1
- package/core/src/og/discovery.d.ts +1 -1
- package/core/src/og/index.d.ts +1 -1
- package/core/src/og/meta.d.ts +1 -1
- package/core/src/og/render.d.ts +1 -1
- package/core/src/og/types.d.ts +1 -1
- package/core/src/robots/discovery.d.ts +1 -1
- package/core/src/robots/generator.d.ts +1 -1
- package/core/src/robots/index.d.ts +1 -1
- package/core/src/robots/policies.d.ts +1 -1
- package/core/src/rss/discovery.d.ts +1 -1
- package/core/src/rss/generator.d.ts +1 -1
- package/core/src/rss/index.d.ts +1 -1
- package/core/src/sitemap/discovery.d.ts +1 -1
- package/core/src/sitemap/generator.d.ts +1 -1
- package/core/src/sitemap/index.d.ts +1 -1
- package/core/src/ssr/index.d.ts +1 -1
- package/core/src/ssr/lib/cache.d.ts +1 -1
- package/core/src/ssr/lib/cleanup.d.ts +1 -1
- package/core/src/ssr/lib/collections.d.ts +1 -1
- package/core/src/ssr/lib/compression.d.ts +1 -1
- package/core/src/ssr/lib/compute/content.d.ts +1 -1
- package/core/src/ssr/lib/compute/index.d.ts +1 -1
- package/core/src/ssr/lib/compute/layouts.d.ts +1 -1
- package/core/src/ssr/lib/compute/routes.d.ts +1 -1
- package/core/src/ssr/lib/content-path.d.ts +1 -1
- package/core/src/ssr/lib/data.d.ts +1 -1
- package/core/src/ssr/lib/html.d.ts +7 -1
- package/core/src/ssr/lib/html.d.ts.map +1 -1
- package/core/src/ssr/lib/imports.d.ts +1 -1
- package/core/src/ssr/lib/index.d.ts +1 -1
- package/core/src/ssr/lib/layouts.d.ts +1 -1
- package/core/src/ssr/lib/metadata.d.ts +1 -1
- package/core/src/ssr/lib/mime.d.ts +1 -1
- package/core/src/ssr/lib/modules.d.ts +1 -1
- package/core/src/ssr/lib/path.d.ts +1 -1
- package/core/src/ssr/lib/preload.d.ts +1 -1
- package/core/src/ssr/lib/route-match.d.ts +1 -1
- package/core/src/ssr/lib/scripts/collections.d.ts +1 -1
- package/core/src/ssr/lib/scripts/data.d.ts +1 -1
- package/core/src/ssr/lib/scripts/escape.d.ts +1 -1
- package/core/src/ssr/lib/scripts/feeds.d.ts +1 -1
- package/core/src/ssr/lib/scripts/index.d.ts +1 -1
- package/core/src/ssr/lib/seed.d.ts +1 -1
- package/core/src/ssr/lib/serialize.d.ts +1 -1
- package/core/src/ssr/lib/setup.d.ts +1 -1
- package/core/src/ssr/lib/styles.d.ts +1 -1
- package/core/src/ssr/lib/template.d.ts +1 -1
- package/core/src/ssr/lib/types.d.ts +10 -2
- package/core/src/ssr/lib/types.d.ts.map +1 -1
- package/core/src/ssr/render.d.ts +1 -1
- package/core/src/ssr/stream.d.ts +1 -1
- package/core/src/ssr/stream.d.ts.map +1 -1
- package/elysia/index.d.ts +1 -1
- package/elysia/index.js +171 -124
- package/elysia/index.js.map +9 -9
- package/elysia/src/index.d.ts +1 -1
- package/elysia/src/libs/assets.d.ts +1 -1
- package/elysia/src/libs/cache.d.ts +1 -1
- package/elysia/src/libs/caching.d.ts +1 -1
- package/elysia/src/libs/devReload.d.ts +1 -1
- package/elysia/src/libs/http.d.ts +1 -1
- package/elysia/src/libs/i18n.d.ts +1 -1
- package/elysia/src/libs/image.d.ts +1 -1
- package/elysia/src/libs/index.d.ts +1 -1
- package/elysia/src/libs/llms.d.ts +1 -1
- package/elysia/src/libs/response.d.ts +1 -1
- package/elysia/src/libs/serving.d.ts +1 -1
- package/elysia/src/plugin.d.ts +1 -1
- package/elysia/src/plugin.d.ts.map +1 -1
- package/elysia/src/routes/artifacts.d.ts +1 -1
- package/elysia/src/routes/content.d.ts +1 -1
- package/elysia/src/routes/image.d.ts +1 -1
- package/elysia/src/routes/index.d.ts +1 -1
- package/elysia/src/routes/internal.d.ts +12 -2
- package/elysia/src/routes/internal.d.ts.map +1 -1
- package/elysia/src/routes/liveReloadClient.d.ts +1 -1
- package/elysia/src/routes/llms.d.ts +1 -1
- package/elysia/src/routes/og.d.ts +1 -1
- package/elysia/src/routes/redirects.d.ts +1 -1
- package/elysia/src/routes/robots.d.ts +1 -1
- package/elysia/src/routes/rss.d.ts +1 -1
- package/elysia/src/routes/search.d.ts +1 -1
- package/elysia/src/routes/sitemap.d.ts +1 -1
- package/elysia/src/routes/ssr.d.ts +1 -1
- package/elysia/src/routes/static.d.ts +1 -1
- package/elysia/src/routes/themeCssRefresh.d.ts +1 -1
- package/elysia/src/types.d.ts +1 -1
- package/package.json +1 -1
- package/react/index.d.ts +1 -1
- package/react/index.js +202 -188
- package/react/index.js.map +9 -9
- package/react/src/components/ClientOnly.d.ts +1 -1
- package/react/src/components/ContentRoute.d.ts +1 -1
- package/react/src/components/Image.d.ts +1 -1
- package/react/src/components/LazyRoute.d.ts +1 -1
- package/react/src/components/Link.d.ts +1 -1
- package/react/src/components/Link.d.ts.map +1 -1
- package/react/src/components/Markdown.d.ts +1 -1
- package/react/src/components/Outlet.d.ts +1 -1
- package/react/src/components/index.d.ts +1 -1
- package/react/src/hooks/index.d.ts +1 -1
- package/react/src/hooks/useContent.d.ts +1 -1
- package/react/src/hooks/useData.d.ts +1 -1
- package/react/src/hooks/useData.d.ts.map +1 -1
- package/react/src/hooks/useFeed.d.ts +1 -1
- package/react/src/hooks/useLayoutData.d.ts +1 -1
- package/react/src/hooks/useLayoutData.d.ts.map +1 -1
- package/react/src/hooks/useLlms.d.ts +1 -1
- package/react/src/hooks/useNavigate.d.ts +1 -1
- package/react/src/hooks/useParams.d.ts +1 -1
- package/react/src/hooks/useRouter.d.ts +1 -1
- package/react/src/hooks/useSearch.d.ts +1 -1
- package/react/src/hooks/useSearchParams.d.ts +1 -1
- package/react/src/hooks/useToc.d.ts +1 -1
- package/react/src/i18n/LocaleProvider.d.ts +1 -1
- package/react/src/i18n/helpers.d.ts +1 -1
- package/react/src/i18n/index.d.ts +1 -1
- package/react/src/index.d.ts +1 -1
- package/react/src/lib/bundle.d.ts +1 -1
- package/react/src/lib/collection.d.ts +1 -1
- package/react/src/lib/content.d.ts +1 -1
- package/react/src/lib/head.d.ts +37 -1
- package/react/src/lib/head.d.ts.map +1 -1
- package/react/src/lib/index.d.ts +1 -1
- package/react/src/lib/layouts.d.ts +1 -1
- package/react/src/lib/lazy-route.d.ts +1 -1
- package/react/src/lib/route-loader.d.ts +1 -1
- package/react/src/lib/static-data.d.ts +7 -1
- package/react/src/lib/static-data.d.ts.map +1 -1
- package/react/src/providers/ContentProvider.d.ts +1 -1
- package/react/src/providers/RerouteProvider.d.ts +1 -1
- package/react/src/providers/RouterProvider.d.ts +1 -1
- package/react/src/providers/RouterProvider.d.ts.map +1 -1
- package/react/src/providers/index.d.ts +1 -1
- package/react/src/types/any.d.ts +1 -1
- package/react/src/types/index.d.ts +1 -1
- package/react/src/types/router.d.ts +1 -1
- package/telemetry/react.d.ts +1 -1
- package/telemetry/react.js +2 -2
- package/telemetry/react.js.map +1 -1
- package/telemetry/server.d.ts +1 -1
- package/telemetry/server.js +2 -2
- package/telemetry/server.js.map +4 -4
- package/telemetry/src/react/api.d.ts +1 -1
- package/telemetry/src/react/context.d.ts +1 -1
- package/telemetry/src/react/index.d.ts +1 -1
- package/telemetry/src/react/telemetry.d.ts +1 -1
- package/telemetry/src/server/context.d.ts +1 -1
- package/telemetry/src/server/headers/extractor.d.ts +1 -1
- package/telemetry/src/server/headers/index.d.ts +1 -1
- package/telemetry/src/server/headers/presets.d.ts +1 -1
- package/telemetry/src/server/index.d.ts +1 -1
- package/telemetry/src/server/instrumentation.d.ts +1 -1
- package/telemetry/src/server/plugin.d.ts +1 -1
- package/telemetry/src/server/sourcemap.d.ts +1 -1
package/README.md
CHANGED
|
@@ -618,6 +618,8 @@ Files are loaded in order, with later files overriding earlier ones.
|
|
|
618
618
|
- ❌ `DATABASE_URL` - Server-only
|
|
619
619
|
- ❌ `SECRET_KEY` - Server-only
|
|
620
620
|
|
|
621
|
+
A route's or layout's `ssr` (`data`, `head`, `lang`, `sitemap`) is server code too: the browser bundle leaves it out, with every import only `ssr` uses, so a loader can import a database client or call `Bun` freely. Declare it as `export const ssr = …` (or `const ssr = …; export { ssr }`); a form the build can't leave out fails it. When the browser navigates, the server sends the page's head and lang, built as for a full page load (layouts, `meta`, content and `ssr.head`), with its data; the browser swaps the page's own head for it.
|
|
622
|
+
|
|
621
623
|
### TypeScript Support
|
|
622
624
|
|
|
623
625
|
For type safety, create a `env.d.ts` file:
|
package/cli/bin.d.ts
CHANGED
package/cli/bin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
3
|
/**
|
|
4
|
-
* reroute-js v1.0.0-alpha.
|
|
4
|
+
* reroute-js v1.0.0-alpha.37
|
|
5
5
|
*
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @copyright 2026 stewones <hi@stewan.io>
|
|
@@ -68,7 +68,7 @@ async function getVersionString() {
|
|
|
68
68
|
}
|
|
69
69
|
async function getVersion() {
|
|
70
70
|
if (true) {
|
|
71
|
-
return "1.0.0-alpha.
|
|
71
|
+
return "1.0.0-alpha.37";
|
|
72
72
|
}
|
|
73
73
|
const possiblePaths = [
|
|
74
74
|
path.join(import.meta.dir, "../../../../package.json"),
|
|
@@ -86,7 +86,7 @@ async function getVersion() {
|
|
|
86
86
|
}
|
|
87
87
|
async function getCommit() {
|
|
88
88
|
if (true) {
|
|
89
|
-
return "
|
|
89
|
+
return "6e28dd5";
|
|
90
90
|
}
|
|
91
91
|
return "dev";
|
|
92
92
|
}
|
|
@@ -2818,6 +2818,11 @@ function deduplicateMetaByProperty(headContent) {
|
|
|
2818
2818
|
}
|
|
2819
2819
|
return result;
|
|
2820
2820
|
}
|
|
2821
|
+
function markPageHead(head) {
|
|
2822
|
+
return `<!--reroute:head-->${head ? `
|
|
2823
|
+
${head}
|
|
2824
|
+
` : ""}<!--/reroute:head-->`;
|
|
2825
|
+
}
|
|
2821
2826
|
function deduplicateMetaTags(headContent) {
|
|
2822
2827
|
try {
|
|
2823
2828
|
let result = headContent;
|
|
@@ -4366,7 +4371,7 @@ async function renderSSRDocument(options) {
|
|
|
4366
4371
|
const combinedHead = dedent([
|
|
4367
4372
|
dedent(head) || "",
|
|
4368
4373
|
dedent(extraHead),
|
|
4369
|
-
dedent(setup2.metadataResult.perPageHead)
|
|
4374
|
+
markPageHead(dedent(setup2.metadataResult.perPageHead))
|
|
4370
4375
|
].filter(Boolean).join(`
|
|
4371
4376
|
`));
|
|
4372
4377
|
const i18nLocale = options.i18n?.enabled ? String(options.i18n.locale || "") : "";
|
|
@@ -6746,7 +6751,7 @@ async function renderSSRDocumentStream(options) {
|
|
|
6746
6751
|
const newAttrs = hasLang ? attrs.replace(/lang\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/i, `lang="${pageLang}"`) : `${attrs} lang="${pageLang}"`;
|
|
6747
6752
|
return `<html${newAttrs}>`;
|
|
6748
6753
|
});
|
|
6749
|
-
const extraHeadBase = setup2.bundlePreload + setup2.preloadExtraHead + setup2.metadataResult.perPageHead;
|
|
6754
|
+
const extraHeadBase = setup2.bundlePreload + setup2.preloadExtraHead + markPageHead(setup2.metadataResult.perPageHead);
|
|
6750
6755
|
if (/<title[\s\S]*?<\/title>/i.test(extraHeadBase)) {
|
|
6751
6756
|
headWithLang = headWithLang.replace(/<title[\s\S]*?<\/title>/i, "");
|
|
6752
6757
|
}
|
|
@@ -7167,6 +7172,7 @@ __export(exports_core, {
|
|
|
7167
7172
|
localizeHref: () => localizeHref,
|
|
7168
7173
|
looksLikeLocale: () => looksLikeLocale,
|
|
7169
7174
|
lookupMessage: () => lookupMessage,
|
|
7175
|
+
markPageHead: () => markPageHead,
|
|
7170
7176
|
markdownTwinPath: () => markdownTwinPath,
|
|
7171
7177
|
matchRoutePattern: () => matchRoutePattern,
|
|
7172
7178
|
matchRoutes: () => matchRoutes,
|
|
@@ -8237,6 +8243,87 @@ var init_routes2 = __esm(() => {
|
|
|
8237
8243
|
groupSegment = /^\(.+\)$/;
|
|
8238
8244
|
});
|
|
8239
8245
|
|
|
8246
|
+
// packages/cli/src/commands/lib/ssr-strip.ts
|
|
8247
|
+
function scriptLoader(path3) {
|
|
8248
|
+
if (path3.endsWith(".tsx"))
|
|
8249
|
+
return "tsx";
|
|
8250
|
+
if (path3.endsWith(".jsx"))
|
|
8251
|
+
return "jsx";
|
|
8252
|
+
if (path3.endsWith(".js") || path3.endsWith(".mjs"))
|
|
8253
|
+
return "js";
|
|
8254
|
+
return "ts";
|
|
8255
|
+
}
|
|
8256
|
+
function exportsSsr(code, loader) {
|
|
8257
|
+
try {
|
|
8258
|
+
return new Bun.Transpiler({ loader }).scan(code).exports.includes("ssr");
|
|
8259
|
+
} catch {
|
|
8260
|
+
return true;
|
|
8261
|
+
}
|
|
8262
|
+
}
|
|
8263
|
+
function bareImports(code) {
|
|
8264
|
+
return new Set(Array.from(code.matchAll(BARE_IMPORT), (match) => match[2]));
|
|
8265
|
+
}
|
|
8266
|
+
function exportSsrInline(code) {
|
|
8267
|
+
if (!SSR_DECLARATION.test(code))
|
|
8268
|
+
return code;
|
|
8269
|
+
let moved = false;
|
|
8270
|
+
const listed = code.replace(EXPORT_LIST, (statement, names) => {
|
|
8271
|
+
const list = names.split(",").map((name) => name.trim()).filter(Boolean);
|
|
8272
|
+
if (!list.includes("ssr"))
|
|
8273
|
+
return statement;
|
|
8274
|
+
moved = true;
|
|
8275
|
+
const rest = list.filter((name) => name !== "ssr");
|
|
8276
|
+
return rest.length > 0 ? `export { ${rest.join(", ")} };` : "";
|
|
8277
|
+
});
|
|
8278
|
+
return moved ? listed.replace(SSR_DECLARATION, "$1export const ssr") : code;
|
|
8279
|
+
}
|
|
8280
|
+
function stripSsr(code, loader, path3, development) {
|
|
8281
|
+
const stripped = new Bun.Transpiler({
|
|
8282
|
+
loader,
|
|
8283
|
+
trimUnusedImports: true,
|
|
8284
|
+
autoImportJSX: true,
|
|
8285
|
+
exports: { eliminate: ["ssr"] },
|
|
8286
|
+
tsconfig: {
|
|
8287
|
+
compilerOptions: {
|
|
8288
|
+
jsx: development ? "react-jsxdev" : "react-jsx",
|
|
8289
|
+
jsxImportSource: "react"
|
|
8290
|
+
}
|
|
8291
|
+
}
|
|
8292
|
+
}).transformSync(exportSsrInline(code));
|
|
8293
|
+
if (exportsSsr(stripped, "js") || SSR_DECLARATION.test(stripped)) {
|
|
8294
|
+
throw new Error(`[reroute] ${path3}: declare the route's ssr as \`export const ssr = …\` so the browser bundle can leave it out`);
|
|
8295
|
+
}
|
|
8296
|
+
const own = bareImports(code);
|
|
8297
|
+
return stripped.replace(BARE_IMPORT, (statement, _quote, specifier) => own.has(specifier) ? statement : "").replace(EMPTY_REEXPORT, "");
|
|
8298
|
+
}
|
|
8299
|
+
function ssrStripPlugin(options) {
|
|
8300
|
+
const roots = [options.routesDir, options.markdownDir].map((dir) => dir.replace(/[\\/]+$/, ""));
|
|
8301
|
+
const escaped = roots.map((dir) => dir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
8302
|
+
const filter = new RegExp(`^(?:${escaped.join("|")})[\\\\/].*\\.[cm]?[jt]sx?$`);
|
|
8303
|
+
return {
|
|
8304
|
+
name: "reroute-ssr-strip",
|
|
8305
|
+
setup(build) {
|
|
8306
|
+
build.onLoad({ filter }, async ({ path: path3 }) => {
|
|
8307
|
+
const code = await Bun.file(path3).text();
|
|
8308
|
+
const loader = scriptLoader(path3);
|
|
8309
|
+
if (!exportsSsr(code, loader))
|
|
8310
|
+
return { contents: code, loader };
|
|
8311
|
+
return {
|
|
8312
|
+
contents: stripSsr(code, loader, path3, options.development),
|
|
8313
|
+
loader: "js"
|
|
8314
|
+
};
|
|
8315
|
+
});
|
|
8316
|
+
}
|
|
8317
|
+
};
|
|
8318
|
+
}
|
|
8319
|
+
var BARE_IMPORT, EMPTY_REEXPORT, SSR_DECLARATION, EXPORT_LIST;
|
|
8320
|
+
var init_ssr_strip = __esm(() => {
|
|
8321
|
+
BARE_IMPORT = /^[ \t]*import\s*(["'])([^"'\n]+)\1;?[ \t]*$/gm;
|
|
8322
|
+
EMPTY_REEXPORT = /^[ \t]*export\s*\{\s*\}\s*from\s*(["'])[^"'\n]+\1;?[ \t]*$/gm;
|
|
8323
|
+
SSR_DECLARATION = /^([ \t]*)(?:const|let|var)\s+ssr\b/m;
|
|
8324
|
+
EXPORT_LIST = /^[ \t]*export\s*\{([^}]*)\}[ \t]*;?[ \t]*$/gm;
|
|
8325
|
+
});
|
|
8326
|
+
|
|
8240
8327
|
// packages/cli/src/commands/lib/streaming/analyzer.ts
|
|
8241
8328
|
import { dirname as dirname4, join as join10 } from "node:path";
|
|
8242
8329
|
function hasSSRDataExport(source) {
|
|
@@ -8787,24 +8874,36 @@ function getImportPath(filePath, streamingMap, routesImportBase) {
|
|
|
8787
8874
|
const pathWithoutExt = filePath.replace(/\.(tsx|ts)$/, "");
|
|
8788
8875
|
return `${routesImportBase}/${pathWithoutExt}`;
|
|
8789
8876
|
}
|
|
8877
|
+
async function routeFilesWithSsr(cwd, routesPath, tree) {
|
|
8878
|
+
const found = new Set;
|
|
8879
|
+
for (const { filePath } of [...tree.routes, ...tree.layouts]) {
|
|
8880
|
+
const source = /\.(md|mdx)$/.test(filePath) ? join14(cwd, ".reroute", "markdown", filePath.replace(/\.(md|mdx)$/, ".tsx")) : join14(routesPath, filePath);
|
|
8881
|
+
const code = await Bun.file(source).text().catch(() => {
|
|
8882
|
+
return;
|
|
8883
|
+
});
|
|
8884
|
+
if (code !== undefined && exportsSsr(code, scriptLoader(source)))
|
|
8885
|
+
found.add(filePath);
|
|
8886
|
+
}
|
|
8887
|
+
return found;
|
|
8888
|
+
}
|
|
8790
8889
|
function lazyRouteFallbackImport(config2) {
|
|
8791
8890
|
const value = config2.streaming?.defaultSkeleton;
|
|
8792
8891
|
if (typeof value !== "string" || value.trim().length === 0)
|
|
8793
8892
|
return;
|
|
8794
8893
|
return importFromReroute(value);
|
|
8795
8894
|
}
|
|
8796
|
-
function generateTypeScript(tree, streamingMap,
|
|
8895
|
+
function generateTypeScript(tree, streamingMap, clientSsr, routesImportBase, fallbackImport) {
|
|
8797
8896
|
const helperImport = fallbackImport ? `import { createLazyRoute } from 'reroute-js/react';
|
|
8798
8897
|
import LazyRouteFallback from '${fallbackImport}';` : "import { createLazyRoute } from 'reroute-js/react';";
|
|
8799
8898
|
const fallbackArgs = fallbackImport ? ", LazyRouteFallback" : "";
|
|
8800
8899
|
const ssrHelper = "const _ssr = (m: any) => m.ssr;";
|
|
8801
8900
|
const metaHelper = "const _meta = (m: any) => m.meta;";
|
|
8901
|
+
const ssrLine = (name) => clientSsr ? "" : `
|
|
8902
|
+
const ${name}SSR = _ssr(${name}Module);`;
|
|
8802
8903
|
const metaImports = [
|
|
8803
|
-
...tree.routes.map((r, i) => `import * as Route${i}Module from '${getImportPath(r.filePath, streamingMap, routesImportBase)}'
|
|
8804
|
-
const Route${i}SSR = _ssr(Route${i}Module);
|
|
8904
|
+
...tree.routes.map((r, i) => `import * as Route${i}Module from '${getImportPath(r.filePath, streamingMap, routesImportBase)}';${ssrLine(`Route${i}`)}
|
|
8805
8905
|
const Route${i}Meta = _meta(Route${i}Module);`),
|
|
8806
|
-
...tree.layouts.map((l, i) => `import * as Layout${i}Module from '${getImportPath(l.filePath, streamingMap, routesImportBase)}'
|
|
8807
|
-
const Layout${i}SSR = _ssr(Layout${i}Module);
|
|
8906
|
+
...tree.layouts.map((l, i) => `import * as Layout${i}Module from '${getImportPath(l.filePath, streamingMap, routesImportBase)}';${ssrLine(`Layout${i}`)}
|
|
8808
8907
|
const Layout${i}Meta = _meta(Layout${i}Module);`)
|
|
8809
8908
|
].join(`
|
|
8810
8909
|
`);
|
|
@@ -8837,7 +8936,7 @@ const Layout${i}Meta = _meta(Layout${i}Module);`)
|
|
|
8837
8936
|
component: Route${i},
|
|
8838
8937
|
params: ${JSON.stringify(r.params)},
|
|
8839
8938
|
isDynamic: ${r.isDynamic},
|
|
8840
|
-
ssr: Route${i}SSR,
|
|
8939
|
+
${clientSsr ? `hasSsr: ${clientSsr.has(r.filePath)}` : `ssr: Route${i}SSR`},
|
|
8841
8940
|
meta: Route${i}Meta,
|
|
8842
8941
|
} as const`;
|
|
8843
8942
|
}).join(`,
|
|
@@ -8855,8 +8954,8 @@ const Layout${i}Meta = _meta(Layout${i}Module);`)
|
|
|
8855
8954
|
return ` {
|
|
8856
8955
|
pattern: "${l.pattern}",
|
|
8857
8956
|
path: "${l.path}",${scope}
|
|
8858
|
-
component: Layout${i}
|
|
8859
|
-
ssr: Layout${i}SSR
|
|
8957
|
+
component: Layout${i},${clientSsr ? "" : `
|
|
8958
|
+
ssr: Layout${i}SSR,`}
|
|
8860
8959
|
meta: Layout${i}Meta,
|
|
8861
8960
|
} as const`;
|
|
8862
8961
|
}).join(`,
|
|
@@ -8874,8 +8973,8 @@ const Layout${i}Meta = _meta(Layout${i}Module);`)
|
|
|
8874
8973
|
// @ts-nocheck
|
|
8875
8974
|
|
|
8876
8975
|
${helperImport}
|
|
8877
|
-
|
|
8878
|
-
${ssrHelper}
|
|
8976
|
+
${clientSsr ? "" : `
|
|
8977
|
+
${ssrHelper}`}
|
|
8879
8978
|
${metaHelper}
|
|
8880
8979
|
|
|
8881
8980
|
${eagerImports}
|
|
@@ -8907,7 +9006,7 @@ export interface Route {
|
|
|
8907
9006
|
component: any;
|
|
8908
9007
|
params: string[];
|
|
8909
9008
|
isDynamic: boolean;
|
|
8910
|
-
ssr?: any;
|
|
9009
|
+
${clientSsr ? "hasSsr?: boolean;" : "ssr?: any;"}
|
|
8911
9010
|
meta?: any;
|
|
8912
9011
|
}
|
|
8913
9012
|
|
|
@@ -8958,7 +9057,7 @@ function matchPattern(route: Route, pathname: string): Record<string, string> |
|
|
|
8958
9057
|
return pathnameIndex === pathnameParts.length ? params : null;
|
|
8959
9058
|
}
|
|
8960
9059
|
|
|
8961
|
-
${
|
|
9060
|
+
${clientSsr ? "" : `// Set globals for compiled binary support (sitemap/RSS/robots discovery)
|
|
8962
9061
|
(globalThis as any).__REROUTE_ROUTES__ = routes;
|
|
8963
9062
|
(globalThis as any).__REROUTE_LAYOUTS__ = layouts;
|
|
8964
9063
|
(globalThis as any).__REROUTE_NOT_FOUND_ROUTES__ = notFoundRoutes;`}
|
|
@@ -9505,6 +9604,13 @@ async function buildEntrypointBundle(cwd, args = []) {
|
|
|
9505
9604
|
...getCommonBuildOptions(),
|
|
9506
9605
|
naming: getNamingConfig({ entry: "index.[hash].[ext]" }),
|
|
9507
9606
|
...bundleGraphOptions,
|
|
9607
|
+
plugins: [
|
|
9608
|
+
ssrStripPlugin({
|
|
9609
|
+
routesDir: join14(cwd, paths.routesDir),
|
|
9610
|
+
markdownDir: join14(cwd, ".reroute", "markdown"),
|
|
9611
|
+
development: !isProd
|
|
9612
|
+
})
|
|
9613
|
+
],
|
|
9508
9614
|
jsx: {
|
|
9509
9615
|
runtime: "automatic",
|
|
9510
9616
|
importSource: "react",
|
|
@@ -9689,8 +9795,8 @@ async function generate(cwd, args = [], options = {}) {
|
|
|
9689
9795
|
const tree = generateRouteTree(all.map((f) => f.replace(/\\/g, "/")));
|
|
9690
9796
|
const streamingAnalyses = streamingEnabled ? await buildStreamingWrappersForTree(cwd, routesPath, tree, config2) : new Map;
|
|
9691
9797
|
const fallbackImport = lazyRouteFallbackImport(config2);
|
|
9692
|
-
const serverRoutes = generateTypeScript(tree, streamingAnalyses,
|
|
9693
|
-
const clientRoutes = generateTypeScript(tree, streamingAnalyses,
|
|
9798
|
+
const serverRoutes = generateTypeScript(tree, streamingAnalyses, undefined, routesImportBase, fallbackImport);
|
|
9799
|
+
const clientRoutes = generateTypeScript(tree, streamingAnalyses, await routeFilesWithSsr(cwd, routesPath, tree), routesImportBase, fallbackImport);
|
|
9694
9800
|
await Bun.write(join14(cwd, OUTPUT_ROUTES), serverRoutes);
|
|
9695
9801
|
await Bun.write(join14(cwd, OUTPUT_ROUTES_CLIENT), clientRoutes);
|
|
9696
9802
|
});
|
|
@@ -10377,6 +10483,7 @@ var init_gen = __esm(() => {
|
|
|
10377
10483
|
init_images();
|
|
10378
10484
|
init_markdown();
|
|
10379
10485
|
init_routes2();
|
|
10486
|
+
init_ssr_strip();
|
|
10380
10487
|
init_analyzer();
|
|
10381
10488
|
init_suspense();
|
|
10382
10489
|
init_theme();
|
|
@@ -108731,7 +108838,7 @@ async function getVersionString2() {
|
|
|
108731
108838
|
}
|
|
108732
108839
|
async function getVersion2() {
|
|
108733
108840
|
if (true) {
|
|
108734
|
-
return "1.0.0-alpha.
|
|
108841
|
+
return "1.0.0-alpha.37";
|
|
108735
108842
|
}
|
|
108736
108843
|
const possiblePaths = [
|
|
108737
108844
|
path3.join(import.meta.dir, "../../../package.json"),
|
|
@@ -108748,10 +108855,10 @@ async function getVersion2() {
|
|
|
108748
108855
|
}
|
|
108749
108856
|
async function getCommit2() {
|
|
108750
108857
|
if (true) {
|
|
108751
|
-
return "
|
|
108858
|
+
return "6e28dd5";
|
|
108752
108859
|
}
|
|
108753
108860
|
return "dev";
|
|
108754
108861
|
}
|
|
108755
108862
|
main();
|
|
108756
108863
|
|
|
108757
|
-
//# debugId=
|
|
108864
|
+
//# debugId=E7D58218ED0BCE3D64756E2164756E21
|