reroute-js 1.0.0-alpha.24 → 1.0.0-alpha.26
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/cli/bin.d.ts +1 -1
- package/cli/bin.js +570 -97
- package/cli/bin.js.map +19 -14
- package/cli/index.d.ts +1 -1
- package/cli/index.js +8 -5
- package/cli/index.js.map +6 -5
- package/cli/src/cli.d.ts +1 -1
- package/cli/src/commands/analyze.d.ts +1 -1
- package/cli/src/commands/build.d.ts +5 -2
- package/cli/src/commands/build.d.ts.map +1 -1
- package/cli/src/commands/dev.d.ts +1 -1
- package/cli/src/commands/dev.d.ts.map +1 -1
- package/cli/src/commands/gen.d.ts +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 +4 -3
- package/cli/src/commands/lib/env.d.ts.map +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 +40 -0
- package/cli/src/commands/lib/prerender.d.ts.map +1 -0
- package/cli/src/commands/lib/production.d.ts +1 -1
- package/cli/src/commands/lib/server.d.ts +1 -1
- package/cli/src/commands/lib/static.d.ts +86 -0
- package/cli/src/commands/lib/static.d.ts.map +1 -0
- 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 +23 -0
- package/cli/src/commands/lib/supervise.d.ts.map +1 -0
- 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 -6
- package/cli/src/commands/lib/watch.d.ts.map +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 +18 -0
- package/cli/src/commands/static-render.d.ts.map +1 -0
- package/cli/src/index.d.ts +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +35 -24
- package/core/index.js.map +8 -8
- 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/pathname.d.ts.map +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 +8 -1
- package/core/src/og/discovery.d.ts.map +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/content-path.d.ts.map +1 -1
- package/core/src/ssr/lib/data.d.ts +1 -1
- package/core/src/ssr/lib/html.d.ts +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 +6 -1
- package/core/src/ssr/lib/layouts.d.ts.map +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/data.d.ts.map +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/styles.d.ts.map +1 -1
- package/core/src/ssr/lib/template.d.ts +1 -1
- package/core/src/ssr/lib/types.d.ts +1 -1
- package/core/src/ssr/render.d.ts +1 -1
- package/core/src/ssr/stream.d.ts +1 -1
- package/elysia/index.d.ts +1 -1
- package/elysia/index.js +107 -46
- package/elysia/index.js.map +11 -11
- 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 +25 -3
- package/elysia/src/libs/devReload.d.ts.map +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 +7 -1
- 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 +106 -43
- package/react/index.js.map +11 -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 +2 -2
- 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 +11 -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/helpers.d.ts.map +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 +1 -1
- package/react/src/lib/index.d.ts +2 -1
- package/react/src/lib/index.d.ts.map +1 -1
- package/react/src/lib/layouts.d.ts +16 -0
- package/react/src/lib/layouts.d.ts.map +1 -0
- package/react/src/lib/lazy-route.d.ts +1 -1
- package/react/src/lib/lazy-route.d.ts.map +1 -1
- package/react/src/lib/route-loader.d.ts +1 -1
- package/react/src/lib/static-data.d.ts +25 -0
- package/react/src/lib/static-data.d.ts.map +1 -0
- 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 +28 -2
- 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 +9 -1
- package/react/src/types/router.d.ts.map +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 +6 -3
- package/telemetry/server.js.map +6 -5
- 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/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.26
|
|
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.26";
|
|
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 "f166380";
|
|
90
90
|
}
|
|
91
91
|
return "dev";
|
|
92
92
|
}
|
|
@@ -789,7 +789,7 @@ function parseContentPath(pathname, availableLocales = [], collections) {
|
|
|
789
789
|
collection,
|
|
790
790
|
name: third,
|
|
791
791
|
locale,
|
|
792
|
-
routingPathname: `/${collection}
|
|
792
|
+
routingPathname: `/${[collection, ...parts.slice(2)].join("/")}`,
|
|
793
793
|
pathname: normalized
|
|
794
794
|
};
|
|
795
795
|
}
|
|
@@ -797,7 +797,7 @@ function parseContentPath(pathname, availableLocales = [], collections) {
|
|
|
797
797
|
return {
|
|
798
798
|
collection,
|
|
799
799
|
name: second,
|
|
800
|
-
routingPathname: `/${
|
|
800
|
+
routingPathname: `/${parts.join("/")}`,
|
|
801
801
|
pathname: normalized
|
|
802
802
|
};
|
|
803
803
|
}
|
|
@@ -1782,14 +1782,14 @@ function resolveContentPathParts(pathname) {
|
|
|
1782
1782
|
name: parts[2],
|
|
1783
1783
|
locale,
|
|
1784
1784
|
key: contentKey(parts[0], parts[2], locale, defaultLocale),
|
|
1785
|
-
routingPathname: `/${parts[0]
|
|
1785
|
+
routingPathname: `/${[parts[0], ...parts.slice(2)].join("/")}`
|
|
1786
1786
|
};
|
|
1787
1787
|
}
|
|
1788
1788
|
return {
|
|
1789
1789
|
collection: parts[0],
|
|
1790
1790
|
name: parts[1],
|
|
1791
1791
|
key: `${parts[0]}:${parts[1]}`,
|
|
1792
|
-
routingPathname: `/${parts
|
|
1792
|
+
routingPathname: `/${parts.join("/")}`
|
|
1793
1793
|
};
|
|
1794
1794
|
}
|
|
1795
1795
|
var init_content_path = __esm(() => {
|
|
@@ -1902,15 +1902,16 @@ var init_content2 = __esm(() => {
|
|
|
1902
1902
|
});
|
|
1903
1903
|
|
|
1904
1904
|
// packages/core/src/ssr/lib/layouts.ts
|
|
1905
|
+
function layoutCovers(pattern, pathname) {
|
|
1906
|
+
const base = pattern.replace(/\/+$/, "");
|
|
1907
|
+
if (base === "")
|
|
1908
|
+
return true;
|
|
1909
|
+
return pathname === base || pathname.startsWith(`${base}/`);
|
|
1910
|
+
}
|
|
1905
1911
|
function getMatchingLayouts(pathname, layouts) {
|
|
1906
1912
|
if (!Array.isArray(layouts))
|
|
1907
1913
|
return [];
|
|
1908
|
-
return layouts.filter((layout) => {
|
|
1909
|
-
const pattern = String(layout?.pattern || "/");
|
|
1910
|
-
if (pattern === "/")
|
|
1911
|
-
return true;
|
|
1912
|
-
return pathname.startsWith(pattern);
|
|
1913
|
-
}).sort((a, b) => {
|
|
1914
|
+
return layouts.filter((layout) => layoutCovers(String(layout?.pattern || "/"), pathname)).sort((a, b) => {
|
|
1914
1915
|
const aDepth = getPatternDepth(a?.pattern);
|
|
1915
1916
|
const bDepth = getPatternDepth(b?.pattern);
|
|
1916
1917
|
return aDepth - bDepth;
|
|
@@ -2928,11 +2929,20 @@ async function collectOGCandidatePaths(currentDir, parts, depth, pathsToTry, all
|
|
|
2928
2929
|
pathsToTry.push(join2(currentDir, "[og].tsx"));
|
|
2929
2930
|
}
|
|
2930
2931
|
}
|
|
2932
|
+
function ogRoutesDirs(clientDir, appRoutesDir) {
|
|
2933
|
+
const dirs = [join2(clientDir, "routes")];
|
|
2934
|
+
if (appRoutesDir && PRODUCTION_CLIENT_DIR.test(clientDir)) {
|
|
2935
|
+
dirs.push(join2(clientDir.replace(PRODUCTION_CLIENT_DIR, ""), appRoutesDir));
|
|
2936
|
+
}
|
|
2937
|
+
return dirs;
|
|
2938
|
+
}
|
|
2931
2939
|
async function findOGImageForPath(pathname, clientDir) {
|
|
2932
2940
|
const parts = pathname.split("/").filter(Boolean).filter((p) => !p.startsWith("__reroute"));
|
|
2933
|
-
const
|
|
2941
|
+
const appRoutesDir = PRODUCTION_CLIENT_DIR.test(clientDir) ? resolveAppPaths(await loadConfig(clientDir.replace(PRODUCTION_CLIENT_DIR, ""))).routesDir : undefined;
|
|
2934
2942
|
const pathsToTry = [];
|
|
2935
|
-
|
|
2943
|
+
for (const routesDir of ogRoutesDirs(clientDir, appRoutesDir)) {
|
|
2944
|
+
await collectOGCandidatePaths(routesDir, parts, 0, pathsToTry, true);
|
|
2945
|
+
}
|
|
2936
2946
|
const uniquePaths = [...new Set(pathsToTry)];
|
|
2937
2947
|
for (const path2 of uniquePaths) {
|
|
2938
2948
|
try {
|
|
@@ -2973,10 +2983,13 @@ function extractParamsFromPath(pathname, ogPath, clientDir) {
|
|
|
2973
2983
|
}
|
|
2974
2984
|
return params;
|
|
2975
2985
|
}
|
|
2976
|
-
var CATCH_ALL_ROUTE_DIRECTORY, DYNAMIC_ROUTE_DIRECTORY;
|
|
2986
|
+
var CATCH_ALL_ROUTE_DIRECTORY, DYNAMIC_ROUTE_DIRECTORY, PRODUCTION_CLIENT_DIR;
|
|
2977
2987
|
var init_discovery2 = __esm(() => {
|
|
2988
|
+
init_app_paths();
|
|
2989
|
+
init_config();
|
|
2978
2990
|
CATCH_ALL_ROUTE_DIRECTORY = /^\[\.\.\.([^\]]+)\]$/;
|
|
2979
2991
|
DYNAMIC_ROUTE_DIRECTORY = /^\[(?:\.\.\.)?[^\]]+\]$/;
|
|
2992
|
+
PRODUCTION_CLIENT_DIR = /[\\/]\.reroute[\\/]?$/;
|
|
2980
2993
|
});
|
|
2981
2994
|
|
|
2982
2995
|
// packages/core/src/og/meta.ts
|
|
@@ -3863,7 +3876,8 @@ function createDataScript(ssrData, errorMsg, pathname, browserTelemetryConfig, t
|
|
|
3863
3876
|
const duplicatedData = duplicateQueryParamData(ssrData);
|
|
3864
3877
|
const dataJson = escapeJsonForScript(JSON.stringify(duplicatedData));
|
|
3865
3878
|
const keysJson = escapeJsonForScript(JSON.stringify(Object.keys(ssrData)));
|
|
3866
|
-
|
|
3879
|
+
const pathJson = escapeJsonForScript(JSON.stringify(pathname ?? null));
|
|
3880
|
+
script += `<script>(function(){try{var w=(typeof window!=='undefined'?window:globalThis);var d=Object.assign({},${dataJson});var k=${keysJson};var p=${pathJson};var h=Object.prototype.hasOwnProperty;var s=w.location?w.location.search:'';if(p?(s?(h.call(d,p)?!h.call(d,p+s):false):false):false){d[p+s]=d[p];k.push(p+s);}w.__REROUTE_DATA__=Object.assign({},w.__REROUTE_DATA__||{},d);try{w.dispatchEvent(new CustomEvent('__reroute_data__',{detail:{keys:k}}));}catch(e){}}catch(e){}})();</script>`;
|
|
3867
3881
|
} catch (error) {
|
|
3868
3882
|
console.error("[reroute] Failed to serialize SSR data:", error);
|
|
3869
3883
|
}
|
|
@@ -3913,6 +3927,7 @@ var init_scripts = __esm(() => {
|
|
|
3913
3927
|
// packages/core/src/ssr/lib/styles.ts
|
|
3914
3928
|
import { createHash } from "node:crypto";
|
|
3915
3929
|
import { readdirSync } from "node:fs";
|
|
3930
|
+
import { resolve } from "node:path";
|
|
3916
3931
|
function themeCssHash(css) {
|
|
3917
3932
|
return createHash("sha1").update(css).digest("hex").slice(0, 8);
|
|
3918
3933
|
}
|
|
@@ -3923,12 +3938,7 @@ function themeLink(href) {
|
|
|
3923
3938
|
return `<link rel="stylesheet" href="${href}" data-reroute="theme">`;
|
|
3924
3939
|
}
|
|
3925
3940
|
function bundlesDirs(clientDir) {
|
|
3926
|
-
return [
|
|
3927
|
-
join2(clientDir, "..", ".reroute", "bundles"),
|
|
3928
|
-
join2(clientDir, "..", "..", ".reroute", "bundles"),
|
|
3929
|
-
join2(clientDir, "..", "..", "..", ".reroute", "bundles"),
|
|
3930
|
-
join2(clientDir, "..", "..", "..", "..", ".reroute", "bundles")
|
|
3931
|
-
];
|
|
3941
|
+
return [1, 2, 3, 4].map((levels) => resolve(clientDir, ...Array(levels).fill(".."), ".reroute", "bundles"));
|
|
3932
3942
|
}
|
|
3933
3943
|
async function readFileIfExists(path2) {
|
|
3934
3944
|
if (!await Bun.file(path2).exists())
|
|
@@ -6782,11 +6792,11 @@ async function streamSSRContent(writer, encoder, ctx) {
|
|
|
6782
6792
|
const reactStream = await streamPromise;
|
|
6783
6793
|
if (streamError)
|
|
6784
6794
|
throw streamError;
|
|
6785
|
-
const streamTimeoutPromise = new Promise((
|
|
6795
|
+
const streamTimeoutPromise = new Promise((resolve2) => {
|
|
6786
6796
|
timeoutId = setTimeout(() => {
|
|
6787
6797
|
console.warn(`[reroute] Stream timeout after ${STREAM_TIMEOUT_MS}ms for ${ctx.pathname}, forcing close`);
|
|
6788
6798
|
streamTimedOut = true;
|
|
6789
|
-
|
|
6799
|
+
resolve2({ done: true, value: undefined });
|
|
6790
6800
|
}, STREAM_TIMEOUT_MS);
|
|
6791
6801
|
});
|
|
6792
6802
|
const reader = reactStream.getReader();
|
|
@@ -7102,6 +7112,7 @@ __export(exports_core, {
|
|
|
7102
7112
|
isCompressible: () => isCompressible,
|
|
7103
7113
|
isThenable: () => isThenable,
|
|
7104
7114
|
join: () => join2,
|
|
7115
|
+
layoutCovers: () => layoutCovers,
|
|
7105
7116
|
listContentFiles: () => listContentFiles,
|
|
7106
7117
|
llmsAlternateLinkTag: () => llmsAlternateLinkTag,
|
|
7107
7118
|
loadCollections: () => loadCollections,
|
|
@@ -7226,11 +7237,14 @@ function loadEnvFiles(cwd, mode = "development") {
|
|
|
7226
7237
|
}
|
|
7227
7238
|
return env;
|
|
7228
7239
|
}
|
|
7229
|
-
function getPublicEnvVars(cwd, mode = "development") {
|
|
7230
|
-
const env =
|
|
7240
|
+
function getPublicEnvVars(cwd, mode = "development", processEnv = process.env) {
|
|
7241
|
+
const env = {
|
|
7242
|
+
...loadEnvFiles(cwd, mode),
|
|
7243
|
+
...processEnv
|
|
7244
|
+
};
|
|
7231
7245
|
const publicEnv = {};
|
|
7232
7246
|
for (const [key, value] of Object.entries(env)) {
|
|
7233
|
-
if (key.startsWith("REROUTE_")) {
|
|
7247
|
+
if (key.startsWith("REROUTE_") && value !== undefined) {
|
|
7234
7248
|
publicEnv[key] = value;
|
|
7235
7249
|
}
|
|
7236
7250
|
}
|
|
@@ -7629,7 +7643,7 @@ var init_availability = () => {};
|
|
|
7629
7643
|
|
|
7630
7644
|
// packages/cli/src/commands/lib/markdown/processor.ts
|
|
7631
7645
|
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
|
|
7632
|
-
import { basename as basename3, dirname as dirname3, extname as extname3, join as join9, relative, resolve } from "node:path";
|
|
7646
|
+
import { basename as basename3, dirname as dirname3, extname as extname3, join as join9, relative, resolve as resolve2 } from "node:path";
|
|
7633
7647
|
import matter from "gray-matter";
|
|
7634
7648
|
function convertPropertiesToJsx(properties) {
|
|
7635
7649
|
const newProperties = {};
|
|
@@ -7814,7 +7828,7 @@ function rewriteImportPaths(code, sourcePath, targetPath) {
|
|
|
7814
7828
|
const importRegex = /import\s+(?:{[^}]+}|[\w\s,]+)\s+from\s+['"](\.[^'"]+)['"]/g;
|
|
7815
7829
|
return code.replace(importRegex, (match, importPath) => {
|
|
7816
7830
|
const sourceDir = dirname3(sourcePath);
|
|
7817
|
-
const absoluteImportPath =
|
|
7831
|
+
const absoluteImportPath = resolve2(sourceDir, importPath);
|
|
7818
7832
|
const targetDir = dirname3(targetPath);
|
|
7819
7833
|
let newRelativePath = relative(targetDir, absoluteImportPath);
|
|
7820
7834
|
if (!newRelativePath.startsWith(".")) {
|
|
@@ -8196,7 +8210,7 @@ var init_suspense = __esm(() => {
|
|
|
8196
8210
|
import { createHash as createHash2 } from "node:crypto";
|
|
8197
8211
|
import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
|
|
8198
8212
|
import { mkdir as mkdir2, readdir as readdir7, unlink as unlink2, writeFile } from "node:fs/promises";
|
|
8199
|
-
import { dirname as dirname6, isAbsolute, join as join12, resolve as
|
|
8213
|
+
import { dirname as dirname6, isAbsolute, join as join12, resolve as resolve3 } from "node:path";
|
|
8200
8214
|
async function getCssPaths(cwd) {
|
|
8201
8215
|
const paths = resolveAppPaths(await loadConfig(cwd));
|
|
8202
8216
|
const input = join12(cwd, paths.cssEntry);
|
|
@@ -8214,11 +8228,11 @@ function isFileImport(specifier) {
|
|
|
8214
8228
|
return true;
|
|
8215
8229
|
}
|
|
8216
8230
|
function bundleCssEntrypoint(entryPath) {
|
|
8217
|
-
const absEntry =
|
|
8231
|
+
const absEntry = resolve3(entryPath);
|
|
8218
8232
|
const stack = new Set;
|
|
8219
8233
|
const completed = new Set;
|
|
8220
8234
|
function bundleFile(filePath) {
|
|
8221
|
-
const absPath =
|
|
8235
|
+
const absPath = resolve3(filePath);
|
|
8222
8236
|
if (completed.has(absPath)) {
|
|
8223
8237
|
return "";
|
|
8224
8238
|
}
|
|
@@ -8237,7 +8251,7 @@ function bundleCssEntrypoint(entryPath) {
|
|
|
8237
8251
|
if (condition || !isFileImport(specifier)) {
|
|
8238
8252
|
return full;
|
|
8239
8253
|
}
|
|
8240
|
-
const importedPath = isAbsolute(specifier) ? specifier :
|
|
8254
|
+
const importedPath = isAbsolute(specifier) ? specifier : resolve3(baseDir, specifier);
|
|
8241
8255
|
return `/* ${specifier} */
|
|
8242
8256
|
${bundleFile(importedPath)}
|
|
8243
8257
|
`;
|
|
@@ -8289,7 +8303,7 @@ var init_theme = __esm(() => {
|
|
|
8289
8303
|
// packages/cli/src/commands/lib/watch.ts
|
|
8290
8304
|
import { createHash as createHash3 } from "node:crypto";
|
|
8291
8305
|
import { readFile } from "node:fs/promises";
|
|
8292
|
-
import { join as join13 } from "node:path";
|
|
8306
|
+
import { join as join13, sep } from "node:path";
|
|
8293
8307
|
function isWatchNoise(name) {
|
|
8294
8308
|
return name.split(/[/\\]/).some((part) => part.startsWith(".")) || /\.bust-[^/\\]+$/.test(name);
|
|
8295
8309
|
}
|
|
@@ -8304,6 +8318,7 @@ function isClientSource(name, skipRoutes) {
|
|
|
8304
8318
|
}
|
|
8305
8319
|
function createContentFingerprint(options) {
|
|
8306
8320
|
const hashes = new Map;
|
|
8321
|
+
const gone = new Set;
|
|
8307
8322
|
const startedAt = Date.now();
|
|
8308
8323
|
const settleMs = options?.settleMs ?? 500;
|
|
8309
8324
|
return {
|
|
@@ -8311,6 +8326,7 @@ function createContentFingerprint(options) {
|
|
|
8311
8326
|
const settling = Date.now() - startedAt < settleMs;
|
|
8312
8327
|
try {
|
|
8313
8328
|
const buf = await readFile(absPath);
|
|
8329
|
+
gone.delete(absPath);
|
|
8314
8330
|
const hash2 = createHash3("sha1").update(buf).digest("hex");
|
|
8315
8331
|
const prev = hashes.get(absPath);
|
|
8316
8332
|
if (prev === hash2)
|
|
@@ -8322,6 +8338,20 @@ function createContentFingerprint(options) {
|
|
|
8322
8338
|
} catch {
|
|
8323
8339
|
if (hashes.has(absPath)) {
|
|
8324
8340
|
hashes.delete(absPath);
|
|
8341
|
+
gone.add(absPath);
|
|
8342
|
+
return !settling;
|
|
8343
|
+
}
|
|
8344
|
+
const prefix = `${absPath.replace(/[\\/]+$/, "")}${sep}`;
|
|
8345
|
+
const under = [...hashes.keys()].filter((key) => key.startsWith(prefix));
|
|
8346
|
+
if (under.length > 0) {
|
|
8347
|
+
for (const key of under) {
|
|
8348
|
+
hashes.delete(key);
|
|
8349
|
+
gone.add(key);
|
|
8350
|
+
}
|
|
8351
|
+
return !settling;
|
|
8352
|
+
}
|
|
8353
|
+
if (sourceFile.test(absPath) && !gone.has(absPath)) {
|
|
8354
|
+
gone.add(absPath);
|
|
8325
8355
|
return !settling;
|
|
8326
8356
|
}
|
|
8327
8357
|
return false;
|
|
@@ -8338,7 +8368,10 @@ async function retainChangedFiles(root, names, fingerprint) {
|
|
|
8338
8368
|
}
|
|
8339
8369
|
return changed;
|
|
8340
8370
|
}
|
|
8341
|
-
var
|
|
8371
|
+
var sourceFile;
|
|
8372
|
+
var init_watch = __esm(() => {
|
|
8373
|
+
sourceFile = /\.(tsx?|jsx?|mdx?|css|json)$/;
|
|
8374
|
+
});
|
|
8342
8375
|
|
|
8343
8376
|
// packages/cli/src/commands/gen.ts
|
|
8344
8377
|
var exports_gen = {};
|
|
@@ -8348,7 +8381,7 @@ __export(exports_gen, {
|
|
|
8348
8381
|
});
|
|
8349
8382
|
import { watch } from "node:fs";
|
|
8350
8383
|
import { copyFile as copyFile2, mkdir as mkdir3, readdir as readdir8, rm, unlink as unlink3 } from "node:fs/promises";
|
|
8351
|
-
import { dirname as dirname7, extname as extname4, join as join14, resolve as
|
|
8384
|
+
import { dirname as dirname7, extname as extname4, join as join14, resolve as resolve4 } from "node:path";
|
|
8352
8385
|
import { pathToFileURL as pathToFileURL8 } from "node:url";
|
|
8353
8386
|
async function bundleThemeCssIntoArtifacts(cwd) {
|
|
8354
8387
|
const cssPath = join14(cwd, ".reroute", "bundles", "index.css");
|
|
@@ -10112,7 +10145,7 @@ async function startGenWatch(cwd, args) {
|
|
|
10112
10145
|
};
|
|
10113
10146
|
const clientWatcher = watchClientSources(clientPath, true);
|
|
10114
10147
|
const extraWatchers = (loadedConfig.app?.watch ?? []).map((entry) => {
|
|
10115
|
-
const dir =
|
|
10148
|
+
const dir = resolve4(cwd, entry);
|
|
10116
10149
|
console.log(`[reroute/watch] \uD83D\uDCE6 Watching ${dir}...`);
|
|
10117
10150
|
return watchClientSources(dir, false);
|
|
10118
10151
|
});
|
|
@@ -10155,10 +10188,10 @@ async function gen(args) {
|
|
|
10155
10188
|
process.exit(0);
|
|
10156
10189
|
}
|
|
10157
10190
|
const session = await startGenWatch(cwd, args);
|
|
10158
|
-
await new Promise((
|
|
10191
|
+
await new Promise((resolve5) => {
|
|
10159
10192
|
process.on("SIGINT", () => {
|
|
10160
10193
|
session.close();
|
|
10161
|
-
|
|
10194
|
+
resolve5();
|
|
10162
10195
|
});
|
|
10163
10196
|
});
|
|
10164
10197
|
process.exit(0);
|
|
@@ -10279,12 +10312,44 @@ async function waitForServerReady(port = 3000, timeout = 30000) {
|
|
|
10279
10312
|
return;
|
|
10280
10313
|
}
|
|
10281
10314
|
} catch {}
|
|
10282
|
-
await new Promise((
|
|
10315
|
+
await new Promise((resolve5) => setTimeout(resolve5, checkInterval));
|
|
10283
10316
|
checkInterval = Math.min(checkInterval * 1.5, maxInterval);
|
|
10284
10317
|
}
|
|
10285
10318
|
throw new Error(`Timeout waiting for server to respond after ${timeout}ms. ` + `Make sure your server is starting correctly on port ${port}.`);
|
|
10286
10319
|
}
|
|
10287
10320
|
|
|
10321
|
+
// packages/cli/src/commands/lib/supervise.ts
|
|
10322
|
+
import { spawn } from "node:child_process";
|
|
10323
|
+
function afterDevExit(code) {
|
|
10324
|
+
return code === devRestartCode ? "restart" : "exit";
|
|
10325
|
+
}
|
|
10326
|
+
async function supervise() {
|
|
10327
|
+
const argv = process.argv.slice(1);
|
|
10328
|
+
for (;; ) {
|
|
10329
|
+
const child = spawn(process.execPath, argv, {
|
|
10330
|
+
stdio: "inherit",
|
|
10331
|
+
env: {
|
|
10332
|
+
...process.env,
|
|
10333
|
+
[supervisedEnv]: "1",
|
|
10334
|
+
REROUTE_DEV_RESTART_CODE: String(devRestartCode)
|
|
10335
|
+
}
|
|
10336
|
+
});
|
|
10337
|
+
const forward = (signal) => () => child.kill(signal);
|
|
10338
|
+
const onInt = forward("SIGINT");
|
|
10339
|
+
const onTerm = forward("SIGTERM");
|
|
10340
|
+
process.on("SIGINT", onInt);
|
|
10341
|
+
process.on("SIGTERM", onTerm);
|
|
10342
|
+
const code = await new Promise((resolve5) => child.on("exit", (exitCode) => resolve5(exitCode)));
|
|
10343
|
+
process.off("SIGINT", onInt);
|
|
10344
|
+
process.off("SIGTERM", onTerm);
|
|
10345
|
+
if (afterDevExit(code) === "exit")
|
|
10346
|
+
process.exit(code ?? 0);
|
|
10347
|
+
console.log("[reroute/dev] Restarting…");
|
|
10348
|
+
}
|
|
10349
|
+
}
|
|
10350
|
+
var devRestartCode = 75, supervisedEnv = "REROUTE_DEV_SUPERVISED";
|
|
10351
|
+
var init_supervise = () => {};
|
|
10352
|
+
|
|
10288
10353
|
// node_modules/.bun/blessed@0.1.81/node_modules/blessed/lib/alias.js
|
|
10289
10354
|
var require_alias = __commonJS(function(exports) {
|
|
10290
10355
|
var alias = exports;
|
|
@@ -20549,7 +20614,7 @@ var require_screen = __commonJS(function(exports, module) {
|
|
|
20549
20614
|
options = args;
|
|
20550
20615
|
args = [];
|
|
20551
20616
|
}
|
|
20552
|
-
var screen = this, program2 = screen.program,
|
|
20617
|
+
var screen = this, program2 = screen.program, spawn2 = __require("child_process").spawn, mouse = program2.mouseEnabled, ps;
|
|
20553
20618
|
options = options || {};
|
|
20554
20619
|
options.stdio = options.stdio || "inherit";
|
|
20555
20620
|
program2.lsaveCursor("spawn");
|
|
@@ -20583,7 +20648,7 @@ var require_screen = __commonJS(function(exports, module) {
|
|
|
20583
20648
|
screen.render();
|
|
20584
20649
|
screen.program.lrestoreCursor("spawn", true);
|
|
20585
20650
|
};
|
|
20586
|
-
ps =
|
|
20651
|
+
ps = spawn2(file, args, options);
|
|
20587
20652
|
ps.on("error", resume);
|
|
20588
20653
|
ps.on("exit", resume);
|
|
20589
20654
|
return ps;
|
|
@@ -95976,7 +96041,7 @@ Should be of format "before:after"`);
|
|
|
95976
96041
|
}
|
|
95977
96042
|
}
|
|
95978
96043
|
function objectize(node) {
|
|
95979
|
-
function
|
|
96044
|
+
function resolve5(value, key) {
|
|
95980
96045
|
if (!value._parent)
|
|
95981
96046
|
return;
|
|
95982
96047
|
if (value._parent._default && value._parent._default[key])
|
|
@@ -95999,8 +96064,8 @@ Should be of format "before:after"`);
|
|
|
95999
96064
|
if (isObject(value)) {
|
|
96000
96065
|
if (!value._before && !value._after)
|
|
96001
96066
|
return objectize(value);
|
|
96002
|
-
value._before = value._before ||
|
|
96003
|
-
value._after = value._after ||
|
|
96067
|
+
value._before = value._before || resolve5(value, "_before");
|
|
96068
|
+
value._after = value._after || resolve5(value, "_after");
|
|
96004
96069
|
return;
|
|
96005
96070
|
}
|
|
96006
96071
|
throw new Error("nodes need to be either {String}, {Object} or {Function}." + value + " is neither.");
|
|
@@ -104883,7 +104948,7 @@ var exports_dev = {};
|
|
|
104883
104948
|
__export(exports_dev, {
|
|
104884
104949
|
default: () => dev
|
|
104885
104950
|
});
|
|
104886
|
-
import { spawn } from "node:child_process";
|
|
104951
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
104887
104952
|
import { existsSync as existsSync9 } from "node:fs";
|
|
104888
104953
|
import { join as join16 } from "node:path";
|
|
104889
104954
|
import { pathToFileURL as pathToFileURL9 } from "node:url";
|
|
@@ -104897,7 +104962,7 @@ function parsePort(args) {
|
|
|
104897
104962
|
async function waitForInitialBuild(genProcess) {
|
|
104898
104963
|
console.log("[reroute/dev] Waiting for initial build...");
|
|
104899
104964
|
const outputBuffer = [];
|
|
104900
|
-
const buildCompletePromise = new Promise((
|
|
104965
|
+
const buildCompletePromise = new Promise((resolve5, reject) => {
|
|
104901
104966
|
const timeout = setTimeout(() => {
|
|
104902
104967
|
reject(new Error("Timeout waiting for initial build to complete (120s)"));
|
|
104903
104968
|
}, 120000);
|
|
@@ -104907,7 +104972,7 @@ async function waitForInitialBuild(genProcess) {
|
|
|
104907
104972
|
clearTimeout(timeout);
|
|
104908
104973
|
genProcess.stdout?.removeListener("data", checkComplete);
|
|
104909
104974
|
genProcess.stderr?.removeListener("data", checkComplete);
|
|
104910
|
-
|
|
104975
|
+
resolve5();
|
|
104911
104976
|
}
|
|
104912
104977
|
};
|
|
104913
104978
|
genProcess.stdout?.on("data", checkComplete);
|
|
@@ -104923,7 +104988,7 @@ async function startTui(port, args) {
|
|
|
104923
104988
|
const prodArgs = isProductionMode(args) ? ["--prod"] : [];
|
|
104924
104989
|
const genCommand = useShell ? `${rerouteCmd} gen --watch ${prodArgs.join(" ")}`.trim() : rerouteCmd;
|
|
104925
104990
|
const genArgs = useShell ? [] : ["gen", "--watch", ...prodArgs];
|
|
104926
|
-
const genProcess =
|
|
104991
|
+
const genProcess = spawn2(genCommand, genArgs, {
|
|
104927
104992
|
stdio: ["ignore", "pipe", "pipe"],
|
|
104928
104993
|
shell: useShell,
|
|
104929
104994
|
env: {
|
|
@@ -104938,7 +105003,7 @@ async function startTui(port, args) {
|
|
|
104938
105003
|
process.exit(1);
|
|
104939
105004
|
});
|
|
104940
105005
|
const { server: server2 } = resolveAppPaths(await loadConfig(process.cwd()));
|
|
104941
|
-
const serverProcess =
|
|
105006
|
+
const serverProcess = spawn2("bun", ["--watch", server2], {
|
|
104942
105007
|
stdio: ["ignore", "pipe", "pipe"],
|
|
104943
105008
|
env: {
|
|
104944
105009
|
...process.env,
|
|
@@ -105007,20 +105072,27 @@ function genWatchArgs(args) {
|
|
|
105007
105072
|
async function dev(args) {
|
|
105008
105073
|
const terminalUI = args.includes("--tui") || args.includes("-t");
|
|
105009
105074
|
const port = parsePort(args);
|
|
105010
|
-
|
|
105075
|
+
const supervised = process.env[supervisedEnv] === "1";
|
|
105076
|
+
if (!supervised && await isServerRunning(port)) {
|
|
105011
105077
|
console.log(`[reroute/dev] Already running at http://localhost:${port} — not starting another instance`);
|
|
105012
105078
|
return;
|
|
105013
105079
|
}
|
|
105014
105080
|
process.env.PORT = String(port);
|
|
105015
105081
|
process.env.REROUTE_DEV = "1";
|
|
105016
105082
|
try {
|
|
105017
|
-
|
|
105018
|
-
|
|
105083
|
+
if (!supervised) {
|
|
105084
|
+
console.log("[reroute/dev] Starting development server...");
|
|
105085
|
+
console.log(`[reroute/dev] Press Ctrl+C to stop
|
|
105019
105086
|
`);
|
|
105087
|
+
}
|
|
105020
105088
|
if (terminalUI) {
|
|
105021
105089
|
await startTui(port, args);
|
|
105022
105090
|
return;
|
|
105023
105091
|
}
|
|
105092
|
+
if (!supervised) {
|
|
105093
|
+
await supervise();
|
|
105094
|
+
return;
|
|
105095
|
+
}
|
|
105024
105096
|
await startDefault(port, args);
|
|
105025
105097
|
} catch (error) {
|
|
105026
105098
|
if (error.code === "SIGINT") {
|
|
@@ -105037,6 +105109,7 @@ var init_dev = __esm(() => {
|
|
|
105037
105109
|
init_gen();
|
|
105038
105110
|
init_command();
|
|
105039
105111
|
init_log();
|
|
105112
|
+
init_supervise();
|
|
105040
105113
|
});
|
|
105041
105114
|
|
|
105042
105115
|
// packages/cli/src/commands/start.ts
|
|
@@ -105044,7 +105117,7 @@ var exports_start = {};
|
|
|
105044
105117
|
__export(exports_start, {
|
|
105045
105118
|
default: () => start
|
|
105046
105119
|
});
|
|
105047
|
-
import { spawn as
|
|
105120
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
105048
105121
|
import { existsSync as existsSync10 } from "node:fs";
|
|
105049
105122
|
import { join as join17 } from "node:path";
|
|
105050
105123
|
function getRerouteCommand2() {
|
|
@@ -105098,8 +105171,8 @@ async function start(args) {
|
|
|
105098
105171
|
`);
|
|
105099
105172
|
const genCommand = useShell ? `${rerouteCmd} gen ${genArgs.join(" ")}` : rerouteCmd;
|
|
105100
105173
|
const genArgsWithCmd = useShell ? [] : ["gen", ...genArgs];
|
|
105101
|
-
await new Promise((
|
|
105102
|
-
const genProcess =
|
|
105174
|
+
await new Promise((resolve5, reject) => {
|
|
105175
|
+
const genProcess = spawn3(genCommand, genArgsWithCmd, {
|
|
105103
105176
|
stdio: ["ignore", "pipe", "pipe"],
|
|
105104
105177
|
shell: useShell
|
|
105105
105178
|
});
|
|
@@ -105109,7 +105182,7 @@ async function start(args) {
|
|
|
105109
105182
|
if (code !== null && code !== 0) {
|
|
105110
105183
|
reject(new Error(`Gen exited with code ${code}`));
|
|
105111
105184
|
} else {
|
|
105112
|
-
|
|
105185
|
+
resolve5();
|
|
105113
105186
|
}
|
|
105114
105187
|
});
|
|
105115
105188
|
genProcess.on("error", (error) => {
|
|
@@ -105121,7 +105194,7 @@ async function start(args) {
|
|
|
105121
105194
|
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/start] Starting server...")}
|
|
105122
105195
|
`);
|
|
105123
105196
|
const { server: server2 } = resolveAppPaths(await loadConfig(process.cwd()));
|
|
105124
|
-
const serverProcess =
|
|
105197
|
+
const serverProcess = spawn3("bun", [server2], {
|
|
105125
105198
|
stdio: ["ignore", "pipe", "pipe"],
|
|
105126
105199
|
env: {
|
|
105127
105200
|
...process.env,
|
|
@@ -105151,13 +105224,13 @@ async function start(args) {
|
|
|
105151
105224
|
serverProcess.kill("SIGINT");
|
|
105152
105225
|
process.exit(0);
|
|
105153
105226
|
});
|
|
105154
|
-
await new Promise((
|
|
105227
|
+
await new Promise((resolve5, reject) => {
|
|
105155
105228
|
serverProcess.on("exit", (code) => {
|
|
105156
105229
|
if (code !== null && code !== 0) {
|
|
105157
105230
|
console.error(colorizeLogPrefixAnsi(`[reroute/start] Server exited with code ${code}`));
|
|
105158
105231
|
reject(new Error(`Server exited with code ${code}`));
|
|
105159
105232
|
} else {
|
|
105160
|
-
|
|
105233
|
+
resolve5();
|
|
105161
105234
|
}
|
|
105162
105235
|
});
|
|
105163
105236
|
serverProcess.on("error", (error) => {
|
|
@@ -105219,7 +105292,7 @@ var exports_build = {};
|
|
|
105219
105292
|
__export(exports_build, {
|
|
105220
105293
|
default: () => build
|
|
105221
105294
|
});
|
|
105222
|
-
import { spawn as
|
|
105295
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
105223
105296
|
import { existsSync as existsSync12, readFileSync as readFileSync5, rmSync, unlinkSync } from "node:fs";
|
|
105224
105297
|
import { join as join19 } from "node:path";
|
|
105225
105298
|
function getRerouteCommand3() {
|
|
@@ -105266,14 +105339,15 @@ function parseBuildArgs(args) {
|
|
|
105266
105339
|
const outfileArgIndex = outfileIndex !== -1 ? outfileIndex : shortOutfileIndex;
|
|
105267
105340
|
const outfile = outfileArgIndex !== -1 && args[outfileArgIndex + 1] ? args[outfileArgIndex + 1] : `./${getOutputName()}`;
|
|
105268
105341
|
const compileBinary = args.includes("--compile");
|
|
105269
|
-
const
|
|
105342
|
+
const staticSite = args.includes("--static");
|
|
105343
|
+
const noCompression = staticSite || args.includes("--no-compression");
|
|
105270
105344
|
const externalArgs = [];
|
|
105271
105345
|
for (let i = 0;i < args.length; i++) {
|
|
105272
105346
|
if (args[i].startsWith("--external=")) {
|
|
105273
105347
|
externalArgs.push(args[i].split("=")[1]);
|
|
105274
105348
|
}
|
|
105275
105349
|
}
|
|
105276
|
-
return { outfile, compileBinary, noCompression, externalArgs };
|
|
105350
|
+
return { outfile, compileBinary, noCompression, staticSite, externalArgs };
|
|
105277
105351
|
}
|
|
105278
105352
|
function cleanDistFolder(cwd) {
|
|
105279
105353
|
const distDir = join19(cwd, "dist");
|
|
@@ -105289,7 +105363,7 @@ async function cleanRerouteFolder(cwd) {
|
|
|
105289
105363
|
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] Cleaning .reroute folder...
|
|
105290
105364
|
`));
|
|
105291
105365
|
rmSync(rerouteDir, { recursive: true, force: true });
|
|
105292
|
-
await new Promise((
|
|
105366
|
+
await new Promise((resolve5) => setTimeout(resolve5, 100));
|
|
105293
105367
|
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] ✓ .reroute folder cleaned
|
|
105294
105368
|
`));
|
|
105295
105369
|
}
|
|
@@ -105308,34 +105382,50 @@ function createOutputHandler(genBuffer) {
|
|
|
105308
105382
|
}
|
|
105309
105383
|
};
|
|
105310
105384
|
}
|
|
105311
|
-
async function
|
|
105312
|
-
|
|
105313
|
-
|
|
105314
|
-
const
|
|
105315
|
-
const
|
|
105316
|
-
|
|
105317
|
-
|
|
105318
|
-
await new Promise((resolve4, reject) => {
|
|
105319
|
-
const genProcess = spawn3(genCommand, genArgs, {
|
|
105385
|
+
async function runRerouteStep(rerouteCmd, useShell, stepArgs, env = process.env) {
|
|
105386
|
+
const command = useShell ? `${rerouteCmd} ${stepArgs.join(" ")}` : rerouteCmd;
|
|
105387
|
+
const commandArgs = useShell ? [] : stepArgs;
|
|
105388
|
+
const outputBuffer = { current: "" };
|
|
105389
|
+
const handleOutput = createOutputHandler(outputBuffer);
|
|
105390
|
+
await new Promise((resolve5, reject) => {
|
|
105391
|
+
const stepProcess = spawn4(command, commandArgs, {
|
|
105320
105392
|
stdio: ["ignore", "pipe", "pipe"],
|
|
105321
|
-
shell: useShell
|
|
105393
|
+
shell: useShell,
|
|
105394
|
+
env
|
|
105322
105395
|
});
|
|
105323
|
-
|
|
105324
|
-
|
|
105325
|
-
|
|
105396
|
+
stepProcess.stdout?.on("data", handleOutput);
|
|
105397
|
+
stepProcess.stderr?.on("data", handleOutput);
|
|
105398
|
+
stepProcess.on("exit", (code) => {
|
|
105326
105399
|
if (code !== null && code !== 0) {
|
|
105327
|
-
reject(new Error(
|
|
105400
|
+
reject(new Error(`${stepArgs[0]} exited with code ${code}`));
|
|
105328
105401
|
} else {
|
|
105329
|
-
|
|
105402
|
+
resolve5();
|
|
105330
105403
|
}
|
|
105331
105404
|
});
|
|
105332
|
-
|
|
105405
|
+
stepProcess.on("error", (error) => {
|
|
105333
105406
|
reject(error);
|
|
105334
105407
|
});
|
|
105335
105408
|
});
|
|
105409
|
+
}
|
|
105410
|
+
async function runGenCommand(rerouteCmd, useShell, noCompression) {
|
|
105411
|
+
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/build] Running gen --prod...")}
|
|
105412
|
+
`);
|
|
105413
|
+
await runRerouteStep(rerouteCmd, useShell, [
|
|
105414
|
+
"gen",
|
|
105415
|
+
"--prod",
|
|
105416
|
+
...noCompression ? ["--no-compression"] : []
|
|
105417
|
+
]);
|
|
105336
105418
|
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] Generation complete
|
|
105337
105419
|
`));
|
|
105338
105420
|
}
|
|
105421
|
+
async function runStaticRender(rerouteCmd, useShell) {
|
|
105422
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] Prerendering static site...
|
|
105423
|
+
`));
|
|
105424
|
+
await runRerouteStep(rerouteCmd, useShell, ["static-render"], {
|
|
105425
|
+
...process.env,
|
|
105426
|
+
NODE_ENV: "production"
|
|
105427
|
+
});
|
|
105428
|
+
}
|
|
105339
105429
|
async function copyAssets(cwd) {
|
|
105340
105430
|
const config2 = await loadConfig(cwd);
|
|
105341
105431
|
const { assetsDir } = resolveAppPaths(config2);
|
|
@@ -105436,6 +105526,11 @@ function logBuildComplete(buildStartTime, buildArgs) {
|
|
|
105436
105526
|
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] Build complete: ${outputPath}
|
|
105437
105527
|
`));
|
|
105438
105528
|
}
|
|
105529
|
+
function logStaticBuildComplete(buildStartTime) {
|
|
105530
|
+
const seconds = ((performance.now() - buildStartTime) / 1000).toFixed(2);
|
|
105531
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] ✓ Total build time: ${seconds}s
|
|
105532
|
+
`));
|
|
105533
|
+
}
|
|
105439
105534
|
async function build(args) {
|
|
105440
105535
|
const cwd = process.cwd();
|
|
105441
105536
|
const buildArgs = parseBuildArgs(args);
|
|
@@ -105447,6 +105542,11 @@ async function build(args) {
|
|
|
105447
105542
|
const useShell = rerouteCmd.includes(" ");
|
|
105448
105543
|
await runGenCommand(rerouteCmd, useShell, buildArgs.noCompression);
|
|
105449
105544
|
await copyAssets(cwd);
|
|
105545
|
+
if (buildArgs.staticSite) {
|
|
105546
|
+
await runStaticRender(rerouteCmd, useShell);
|
|
105547
|
+
logStaticBuildComplete(buildStartTime);
|
|
105548
|
+
process.exit(0);
|
|
105549
|
+
}
|
|
105450
105550
|
await runImagePreprocess(cwd, await loadConfig(cwd));
|
|
105451
105551
|
await buildBundle(cwd, buildArgs);
|
|
105452
105552
|
const rerouteDir = join19(cwd, ".reroute");
|
|
@@ -107495,14 +107595,14 @@ async function analyze(args) {
|
|
|
107495
107595
|
if (!existsSync13(rerouteIndexPath)) {
|
|
107496
107596
|
console.log(colorizeLogPrefixAnsi(`[reroute/analyze] .reroute artifacts not found, running build...
|
|
107497
107597
|
`));
|
|
107498
|
-
const { spawn:
|
|
107598
|
+
const { spawn: spawn5 } = await import("node:child_process");
|
|
107499
107599
|
const { getRerouteCommand: getRerouteCommand4 } = await Promise.resolve().then(() => (init_command(), exports_command));
|
|
107500
107600
|
const rerouteCmd = getRerouteCommand4();
|
|
107501
107601
|
const useShell = rerouteCmd.includes(" ");
|
|
107502
107602
|
const buildCommand = useShell ? `${rerouteCmd} build` : rerouteCmd;
|
|
107503
107603
|
const buildArgs = useShell ? [] : ["build"];
|
|
107504
|
-
await new Promise((
|
|
107505
|
-
const buildProcess =
|
|
107604
|
+
await new Promise((resolve5, reject) => {
|
|
107605
|
+
const buildProcess = spawn5(buildCommand, buildArgs, {
|
|
107506
107606
|
stdio: "inherit",
|
|
107507
107607
|
shell: useShell
|
|
107508
107608
|
});
|
|
@@ -107510,7 +107610,7 @@ async function analyze(args) {
|
|
|
107510
107610
|
if (code !== null && code !== 0) {
|
|
107511
107611
|
reject(new Error(`Build exited with code ${code}`));
|
|
107512
107612
|
} else {
|
|
107513
|
-
|
|
107613
|
+
resolve5();
|
|
107514
107614
|
}
|
|
107515
107615
|
});
|
|
107516
107616
|
buildProcess.on("error", (error) => {
|
|
@@ -107642,7 +107742,7 @@ async function analyze(args) {
|
|
|
107642
107742
|
`));
|
|
107643
107743
|
if (openBrowser) {
|
|
107644
107744
|
try {
|
|
107645
|
-
const { spawn:
|
|
107745
|
+
const { spawn: spawn5 } = await import("node:child_process");
|
|
107646
107746
|
const platform = process.platform;
|
|
107647
107747
|
let command;
|
|
107648
107748
|
let commandArgs;
|
|
@@ -107656,7 +107756,7 @@ async function analyze(args) {
|
|
|
107656
107756
|
command = "xdg-open";
|
|
107657
107757
|
commandArgs = [htmlPath];
|
|
107658
107758
|
}
|
|
107659
|
-
|
|
107759
|
+
spawn5(command, commandArgs, { detached: true, stdio: "ignore" });
|
|
107660
107760
|
console.log(colorizeLogPrefixAnsi(`[reroute/analyze] Opened report in browser
|
|
107661
107761
|
`));
|
|
107662
107762
|
} catch {
|
|
@@ -107699,7 +107799,7 @@ var exports_og = {};
|
|
|
107699
107799
|
__export(exports_og, {
|
|
107700
107800
|
default: () => og2
|
|
107701
107801
|
});
|
|
107702
|
-
import { spawn as
|
|
107802
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
107703
107803
|
import { readdir as readdir10 } from "node:fs/promises";
|
|
107704
107804
|
import { join as join21 } from "node:path";
|
|
107705
107805
|
function getPortFromConfig(baseUrl) {
|
|
@@ -107714,11 +107814,11 @@ function getPortFromConfig(baseUrl) {
|
|
|
107714
107814
|
}
|
|
107715
107815
|
async function killProcessOnPort(port) {
|
|
107716
107816
|
try {
|
|
107717
|
-
const proc =
|
|
107817
|
+
const proc = spawn5("bunx", ["kill-port", String(port)], {
|
|
107718
107818
|
stdio: "ignore"
|
|
107719
107819
|
});
|
|
107720
|
-
await new Promise((
|
|
107721
|
-
proc.on("close", () =>
|
|
107820
|
+
await new Promise((resolve5) => {
|
|
107821
|
+
proc.on("close", () => resolve5());
|
|
107722
107822
|
});
|
|
107723
107823
|
} catch {}
|
|
107724
107824
|
}
|
|
@@ -107740,7 +107840,7 @@ async function ensureServer(cwd, port) {
|
|
|
107740
107840
|
return { port, process: null, wasAlreadyRunning: true };
|
|
107741
107841
|
}
|
|
107742
107842
|
console.log(`\uD83D\uDE80 Starting dev server on port ${port}...`);
|
|
107743
|
-
const proc =
|
|
107843
|
+
const proc = spawn5("reroute", ["dev"], {
|
|
107744
107844
|
cwd,
|
|
107745
107845
|
stdio: ["ignore", "pipe", "pipe"],
|
|
107746
107846
|
detached: false
|
|
@@ -107839,7 +107939,7 @@ async function findRoutesWithOG(cwd) {
|
|
|
107839
107939
|
function openInBrowser(url) {
|
|
107840
107940
|
const platform = process.platform;
|
|
107841
107941
|
const command = platform === "darwin" ? "open" : platform === "win32" ? "start" : "xdg-open";
|
|
107842
|
-
|
|
107942
|
+
spawn5(command, [url], {
|
|
107843
107943
|
stdio: "ignore",
|
|
107844
107944
|
detached: true
|
|
107845
107945
|
}).unref();
|
|
@@ -107977,6 +108077,377 @@ var init_og2 = __esm(() => {
|
|
|
107977
108077
|
init_core();
|
|
107978
108078
|
});
|
|
107979
108079
|
|
|
108080
|
+
// packages/react/src/lib/static-data.ts
|
|
108081
|
+
function staticDataPath(pathname, key) {
|
|
108082
|
+
const route = pathname.split(/[?#]/)[0].replace(/\/+$/, "");
|
|
108083
|
+
const base = `${STATIC_DATA_DIR}${route}`;
|
|
108084
|
+
return key ? `${base}/__key/${encodeURIComponent(key)}.json` : `${base}/index.json`;
|
|
108085
|
+
}
|
|
108086
|
+
var STATIC_DATA_DIR = "/__reroute_data";
|
|
108087
|
+
|
|
108088
|
+
// packages/cli/src/commands/lib/static.ts
|
|
108089
|
+
function escapeRegExp(value) {
|
|
108090
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
108091
|
+
}
|
|
108092
|
+
function decodeSafe(value) {
|
|
108093
|
+
try {
|
|
108094
|
+
return decodeURIComponent(value);
|
|
108095
|
+
} catch {
|
|
108096
|
+
return value;
|
|
108097
|
+
}
|
|
108098
|
+
}
|
|
108099
|
+
function toOutputPath(urlPath) {
|
|
108100
|
+
const segments = urlPath.split(/[?#]/)[0].split("/").filter(Boolean).map(decodeSafe);
|
|
108101
|
+
if (segments.some((segment) => segment === ".." || segment.includes("/"))) {
|
|
108102
|
+
throw new Error(`Refusing to write outside the output directory: ${urlPath}`);
|
|
108103
|
+
}
|
|
108104
|
+
return segments.join("/");
|
|
108105
|
+
}
|
|
108106
|
+
function pageOutputPath(pathname) {
|
|
108107
|
+
const file = toOutputPath(pathname);
|
|
108108
|
+
return file ? `${file}.html` : "index.html";
|
|
108109
|
+
}
|
|
108110
|
+
function dataOutputPath(pathname, key) {
|
|
108111
|
+
return toOutputPath(staticDataPath(pathname, key));
|
|
108112
|
+
}
|
|
108113
|
+
function rewriteDataUrls(text) {
|
|
108114
|
+
const lazy = [];
|
|
108115
|
+
const rewritten = text.replace(DATA_URL_PATTERN, (_match, rawPath, rawKey) => {
|
|
108116
|
+
const pathname = decodeSafe(rawPath);
|
|
108117
|
+
const key = rawKey ? decodeSafe(rawKey) : undefined;
|
|
108118
|
+
if (key)
|
|
108119
|
+
lazy.push({ pathname, key });
|
|
108120
|
+
return staticDataPath(pathname, key);
|
|
108121
|
+
});
|
|
108122
|
+
return { text: rewritten, lazy };
|
|
108123
|
+
}
|
|
108124
|
+
function finalizeNotFoundPage(html2, probePath) {
|
|
108125
|
+
const ssrPathname = escapeRegExp(`__REROUTE_SSR_PATHNAME__=${JSON.stringify(probePath)}`);
|
|
108126
|
+
const probeTag = `<(?:link|meta)\\b[^>]*${escapeRegExp(probePath)}[^>]*>\\n?`;
|
|
108127
|
+
const page = html2.replace(new RegExp(ssrPathname, "g"), "__REROUTE_SSR_PATHNAME__=location.pathname").replace(new RegExp(probeTag, "g"), "");
|
|
108128
|
+
return page.includes('property="og:image"') ? page : page.replace(/<meta\b[^>]*property="og:image:[^"]*"[^>]*>\n?/g, "");
|
|
108129
|
+
}
|
|
108130
|
+
function injectStaticFlag(html2) {
|
|
108131
|
+
const head = /<head[^>]*>/i.exec(html2);
|
|
108132
|
+
if (!head)
|
|
108133
|
+
return `${STATIC_FLAG_SCRIPT}${html2}`;
|
|
108134
|
+
const end = head.index + head[0].length;
|
|
108135
|
+
return `${html2.slice(0, end)}${STATIC_FLAG_SCRIPT}${html2.slice(end)}`;
|
|
108136
|
+
}
|
|
108137
|
+
function extractLinks(html2, origins) {
|
|
108138
|
+
const found = new Set;
|
|
108139
|
+
const add = (raw) => {
|
|
108140
|
+
const path3 = toSitePath(raw.trim(), origins);
|
|
108141
|
+
if (path3)
|
|
108142
|
+
found.add(path3);
|
|
108143
|
+
};
|
|
108144
|
+
for (const match of html2.matchAll(LINK_ATTRIBUTE_PATTERN))
|
|
108145
|
+
add(match[1]);
|
|
108146
|
+
for (const match of html2.matchAll(SRCSET_PATTERN)) {
|
|
108147
|
+
for (const candidate of match[1].split(",")) {
|
|
108148
|
+
add(candidate.trim().split(/\s+/)[0]);
|
|
108149
|
+
}
|
|
108150
|
+
}
|
|
108151
|
+
return [...found];
|
|
108152
|
+
}
|
|
108153
|
+
function toSitePath(raw, origins) {
|
|
108154
|
+
if (!raw || raw.startsWith("#") || raw.startsWith("//"))
|
|
108155
|
+
return;
|
|
108156
|
+
if (raw.startsWith("/"))
|
|
108157
|
+
return stripHash(raw.replace(/&/g, "&"));
|
|
108158
|
+
const origin = origins.find((candidate) => raw === candidate || raw.startsWith(`${candidate}/`));
|
|
108159
|
+
if (!origin)
|
|
108160
|
+
return;
|
|
108161
|
+
return stripHash(raw.slice(origin.length) || "/");
|
|
108162
|
+
}
|
|
108163
|
+
function stripHash(path3) {
|
|
108164
|
+
return path3.split("#")[0] || "/";
|
|
108165
|
+
}
|
|
108166
|
+
function parseSitemapLocs(xml, origins) {
|
|
108167
|
+
const paths = [];
|
|
108168
|
+
for (const match of xml.matchAll(SITEMAP_LOC_PATTERN)) {
|
|
108169
|
+
const path3 = toSitePath(match[1], origins);
|
|
108170
|
+
if (path3)
|
|
108171
|
+
paths.push(path3);
|
|
108172
|
+
}
|
|
108173
|
+
return paths;
|
|
108174
|
+
}
|
|
108175
|
+
function headersFile() {
|
|
108176
|
+
return [
|
|
108177
|
+
"/bundles/*",
|
|
108178
|
+
" Cache-Control: public, max-age=31536000, immutable",
|
|
108179
|
+
""
|
|
108180
|
+
].join(`
|
|
108181
|
+
`);
|
|
108182
|
+
}
|
|
108183
|
+
function staticRedirectsFromConfig(rules = []) {
|
|
108184
|
+
const redirects = [];
|
|
108185
|
+
const skipped = [];
|
|
108186
|
+
for (const rule of rules) {
|
|
108187
|
+
if (rule.enabled === false)
|
|
108188
|
+
continue;
|
|
108189
|
+
const isRegex = rule.regex ?? rule.source instanceof RegExp;
|
|
108190
|
+
if (isRegex || typeof rule.source !== "string" || typeof rule.destination !== "string") {
|
|
108191
|
+
skipped.push(rule);
|
|
108192
|
+
continue;
|
|
108193
|
+
}
|
|
108194
|
+
redirects.push({
|
|
108195
|
+
from: rule.source,
|
|
108196
|
+
to: rule.destination,
|
|
108197
|
+
status: rule.status ?? 302
|
|
108198
|
+
});
|
|
108199
|
+
}
|
|
108200
|
+
return { redirects, skipped };
|
|
108201
|
+
}
|
|
108202
|
+
function redirectsFile(redirects) {
|
|
108203
|
+
const seen = new Set;
|
|
108204
|
+
const lines = [];
|
|
108205
|
+
for (const redirect of redirects) {
|
|
108206
|
+
if (seen.has(redirect.from))
|
|
108207
|
+
continue;
|
|
108208
|
+
seen.add(redirect.from);
|
|
108209
|
+
lines.push(`${redirect.from} ${redirect.to} ${redirect.status}`);
|
|
108210
|
+
}
|
|
108211
|
+
return lines.length > 0 ? `${lines.join(`
|
|
108212
|
+
`)}
|
|
108213
|
+
` : "";
|
|
108214
|
+
}
|
|
108215
|
+
var DATA_URL_PATTERN, LINK_ATTRIBUTE_PATTERN, SRCSET_PATTERN, SITEMAP_LOC_PATTERN, STATIC_FLAG_SCRIPT = "<script>window.__REROUTE_STATIC__=true;</script>";
|
|
108216
|
+
var init_static = __esm(() => {
|
|
108217
|
+
DATA_URL_PATTERN = /\/__reroute_data\?path=([^&"'\s<>\\]+)(?:(?:&|&|\\u0026)key=([^&"'\s<>\\]+))?/g;
|
|
108218
|
+
LINK_ATTRIBUTE_PATTERN = /\s(?:href|src|content)\s*=\s*["']([^"']+)["']/gi;
|
|
108219
|
+
SRCSET_PATTERN = /\ssrcset\s*=\s*["']([^"']+)["']/gi;
|
|
108220
|
+
SITEMAP_LOC_PATTERN = /<loc>\s*([^<\s]+)\s*<\/loc>/g;
|
|
108221
|
+
});
|
|
108222
|
+
|
|
108223
|
+
// packages/cli/src/commands/lib/prerender.ts
|
|
108224
|
+
import {
|
|
108225
|
+
cpSync as cpSync2,
|
|
108226
|
+
existsSync as existsSync14,
|
|
108227
|
+
mkdirSync as mkdirSync2,
|
|
108228
|
+
readFileSync as readFileSync6,
|
|
108229
|
+
writeFileSync
|
|
108230
|
+
} from "node:fs";
|
|
108231
|
+
import { dirname as dirname8, join as join22 } from "node:path";
|
|
108232
|
+
function writeOutput(state, relativePath, body) {
|
|
108233
|
+
const target = join22(state.outDir, relativePath);
|
|
108234
|
+
mkdirSync2(dirname8(target), { recursive: true });
|
|
108235
|
+
writeFileSync(target, body);
|
|
108236
|
+
state.files++;
|
|
108237
|
+
}
|
|
108238
|
+
function enqueue(state, path3) {
|
|
108239
|
+
if (state.queued.has(path3))
|
|
108240
|
+
return;
|
|
108241
|
+
state.queued.add(path3);
|
|
108242
|
+
if (COPIED_PREFIXES.some((prefix) => path3.startsWith(prefix))) {
|
|
108243
|
+
if (!existsSync14(join22(state.outDir, toOutputPath(path3)))) {
|
|
108244
|
+
state.warnings.push(`Referenced file is missing from the build: ${path3}`);
|
|
108245
|
+
}
|
|
108246
|
+
return;
|
|
108247
|
+
}
|
|
108248
|
+
if (path3.includes("?")) {
|
|
108249
|
+
const endpoint = path3.split("?")[0];
|
|
108250
|
+
state.serverOnly.set(endpoint, (state.serverOnly.get(endpoint) ?? 0) + 1);
|
|
108251
|
+
return;
|
|
108252
|
+
}
|
|
108253
|
+
state.queue.push(path3);
|
|
108254
|
+
}
|
|
108255
|
+
async function request(state, path3) {
|
|
108256
|
+
return state.app.handle(new Request(`${REQUEST_ORIGIN}${path3}`, { redirect: "manual" }));
|
|
108257
|
+
}
|
|
108258
|
+
function handleRedirect(state, path3, response) {
|
|
108259
|
+
const location = response.headers.get("location");
|
|
108260
|
+
if (!location)
|
|
108261
|
+
return;
|
|
108262
|
+
const target = toSitePath(location, state.origins) ?? location;
|
|
108263
|
+
state.redirects.push({ from: path3, to: target, status: response.status });
|
|
108264
|
+
if (target.startsWith("/"))
|
|
108265
|
+
enqueue(state, target);
|
|
108266
|
+
}
|
|
108267
|
+
function writePage(state, path3, html2) {
|
|
108268
|
+
const { text, lazy } = rewriteDataUrls(html2);
|
|
108269
|
+
state.lazy.push(...lazy);
|
|
108270
|
+
writeOutput(state, pageOutputPath(path3), injectStaticFlag(text));
|
|
108271
|
+
for (const link of extractLinks(html2, state.origins))
|
|
108272
|
+
enqueue(state, link);
|
|
108273
|
+
}
|
|
108274
|
+
async function visit(state, path3, optional) {
|
|
108275
|
+
const response = await request(state, path3);
|
|
108276
|
+
if (response.status >= 300 && response.status < 400) {
|
|
108277
|
+
handleRedirect(state, path3, response);
|
|
108278
|
+
return;
|
|
108279
|
+
}
|
|
108280
|
+
if (!response.ok) {
|
|
108281
|
+
if (!optional) {
|
|
108282
|
+
state.warnings.push(`${path3} returned ${response.status}, skipped`);
|
|
108283
|
+
}
|
|
108284
|
+
return;
|
|
108285
|
+
}
|
|
108286
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
108287
|
+
if (contentType.includes("text/html")) {
|
|
108288
|
+
state.pages.push(path3);
|
|
108289
|
+
writePage(state, path3, await response.text());
|
|
108290
|
+
return;
|
|
108291
|
+
}
|
|
108292
|
+
const body = new Uint8Array(await response.arrayBuffer());
|
|
108293
|
+
writeOutput(state, toOutputPath(path3), body);
|
|
108294
|
+
if (contentType.includes("xml") && path3.includes("sitemap")) {
|
|
108295
|
+
const xml = new TextDecoder().decode(body);
|
|
108296
|
+
for (const loc of parseSitemapLocs(xml, state.origins))
|
|
108297
|
+
enqueue(state, loc);
|
|
108298
|
+
}
|
|
108299
|
+
}
|
|
108300
|
+
async function drain(state, optional) {
|
|
108301
|
+
const worker = async () => {
|
|
108302
|
+
while (state.queue.length > 0) {
|
|
108303
|
+
const path3 = state.queue.shift();
|
|
108304
|
+
await visit(state, path3, optional.has(path3));
|
|
108305
|
+
}
|
|
108306
|
+
};
|
|
108307
|
+
while (state.queue.length > 0) {
|
|
108308
|
+
await Promise.all(Array.from({ length: CONCURRENCY }, worker));
|
|
108309
|
+
}
|
|
108310
|
+
}
|
|
108311
|
+
async function writeData(state, pathname, key) {
|
|
108312
|
+
const query = `path=${encodeURIComponent(pathname)}${key ? `&key=${encodeURIComponent(key)}` : ""}`;
|
|
108313
|
+
const response = await request(state, `/__reroute_data?${query}`);
|
|
108314
|
+
if (!response.ok) {
|
|
108315
|
+
state.warnings.push(`Data for ${pathname}${key ? ` (${key})` : ""} returned ${response.status}`);
|
|
108316
|
+
return;
|
|
108317
|
+
}
|
|
108318
|
+
const { text, lazy } = rewriteDataUrls(await response.text());
|
|
108319
|
+
state.lazy.push(...lazy);
|
|
108320
|
+
writeOutput(state, dataOutputPath(pathname, key), text);
|
|
108321
|
+
}
|
|
108322
|
+
async function writeAllData(state) {
|
|
108323
|
+
for (const page of state.pages)
|
|
108324
|
+
await writeData(state, page);
|
|
108325
|
+
const written = new Set;
|
|
108326
|
+
while (state.lazy.length > 0) {
|
|
108327
|
+
const ref = state.lazy.shift();
|
|
108328
|
+
const id = `${ref.pathname}
|
|
108329
|
+
${ref.key}`;
|
|
108330
|
+
if (written.has(id))
|
|
108331
|
+
continue;
|
|
108332
|
+
written.add(id);
|
|
108333
|
+
await writeData(state, ref.pathname, ref.key);
|
|
108334
|
+
}
|
|
108335
|
+
}
|
|
108336
|
+
async function writeNotFoundPage(state) {
|
|
108337
|
+
const response = await request(state, NOT_FOUND_PROBE);
|
|
108338
|
+
if (!(response.headers.get("content-type") ?? "").includes("text/html")) {
|
|
108339
|
+
return;
|
|
108340
|
+
}
|
|
108341
|
+
const { text, lazy } = rewriteDataUrls(await response.text());
|
|
108342
|
+
state.lazy.push(...lazy);
|
|
108343
|
+
writeOutput(state, "404.html", injectStaticFlag(finalizeNotFoundPage(text, NOT_FOUND_PROBE)));
|
|
108344
|
+
}
|
|
108345
|
+
function copyBuildDir(from, to) {
|
|
108346
|
+
if (!existsSync14(from))
|
|
108347
|
+
return;
|
|
108348
|
+
cpSync2(from, to, {
|
|
108349
|
+
recursive: true,
|
|
108350
|
+
filter: (source) => !/\.(gz|br|map)$/.test(source)
|
|
108351
|
+
});
|
|
108352
|
+
}
|
|
108353
|
+
function readManifestRoutes(cwd) {
|
|
108354
|
+
const manifestPath = join22(cwd, ".reroute", "manifest.json");
|
|
108355
|
+
if (!existsSync14(manifestPath))
|
|
108356
|
+
return ["/"];
|
|
108357
|
+
const manifest = JSON.parse(readFileSync6(manifestPath, "utf-8"));
|
|
108358
|
+
return [
|
|
108359
|
+
"/",
|
|
108360
|
+
...manifest.staticRoutes ?? [],
|
|
108361
|
+
...manifest.contentRoutes ?? []
|
|
108362
|
+
];
|
|
108363
|
+
}
|
|
108364
|
+
async function loadStaticApp(cwd) {
|
|
108365
|
+
const { Elysia } = await import(Bun.resolveSync("elysia", cwd));
|
|
108366
|
+
const { reroute } = await import(Bun.resolveSync("reroute-js/elysia", cwd));
|
|
108367
|
+
const app = new Elysia().use(reroute());
|
|
108368
|
+
await app.modules;
|
|
108369
|
+
return app;
|
|
108370
|
+
}
|
|
108371
|
+
async function buildStaticSite(cwd, outDir) {
|
|
108372
|
+
const config2 = await loadConfig(cwd);
|
|
108373
|
+
const rerouteDir = join22(cwd, ".reroute");
|
|
108374
|
+
mkdirSync2(outDir, { recursive: true });
|
|
108375
|
+
copyBuildDir(join22(rerouteDir, "bundles"), join22(outDir, "bundles"));
|
|
108376
|
+
copyBuildDir(join22(rerouteDir, "assets"), join22(outDir, "assets"));
|
|
108377
|
+
const baseUrl = config2.app?.baseUrl?.replace(/\/+$/, "");
|
|
108378
|
+
const state = {
|
|
108379
|
+
app: await loadStaticApp(cwd),
|
|
108380
|
+
outDir,
|
|
108381
|
+
origins: [REQUEST_ORIGIN, ...baseUrl ? [baseUrl] : []],
|
|
108382
|
+
queued: new Set,
|
|
108383
|
+
queue: [],
|
|
108384
|
+
pages: [],
|
|
108385
|
+
redirects: [],
|
|
108386
|
+
lazy: [],
|
|
108387
|
+
serverOnly: new Map,
|
|
108388
|
+
warnings: [],
|
|
108389
|
+
files: 0
|
|
108390
|
+
};
|
|
108391
|
+
for (const route of readManifestRoutes(cwd))
|
|
108392
|
+
enqueue(state, route);
|
|
108393
|
+
for (const file of WELL_KNOWN_FILES)
|
|
108394
|
+
enqueue(state, file);
|
|
108395
|
+
await drain(state, new Set(WELL_KNOWN_FILES));
|
|
108396
|
+
await writeNotFoundPage(state);
|
|
108397
|
+
await writeAllData(state);
|
|
108398
|
+
for (const [endpoint, count] of state.serverOnly) {
|
|
108399
|
+
state.warnings.push(`${count} URL(s) under ${endpoint} need a Reroute server and were skipped`);
|
|
108400
|
+
}
|
|
108401
|
+
const { redirects, skipped } = staticRedirectsFromConfig(config2.redirects);
|
|
108402
|
+
for (const rule of skipped) {
|
|
108403
|
+
state.warnings.push(`Redirect ${String(rule.source)} uses a regex or function and was not written to _redirects`);
|
|
108404
|
+
}
|
|
108405
|
+
const redirectLines = redirectsFile([...redirects, ...state.redirects]);
|
|
108406
|
+
if (redirectLines)
|
|
108407
|
+
writeOutput(state, "_redirects", redirectLines);
|
|
108408
|
+
writeOutput(state, "_headers", headersFile());
|
|
108409
|
+
return {
|
|
108410
|
+
outDir,
|
|
108411
|
+
pages: state.pages.sort(),
|
|
108412
|
+
files: state.files,
|
|
108413
|
+
warnings: state.warnings
|
|
108414
|
+
};
|
|
108415
|
+
}
|
|
108416
|
+
var WELL_KNOWN_FILES, COPIED_PREFIXES, NOT_FOUND_PROBE = "/__reroute_static_404__", REQUEST_ORIGIN = "http://reroute.static", CONCURRENCY = 8;
|
|
108417
|
+
var init_prerender = __esm(() => {
|
|
108418
|
+
init_core();
|
|
108419
|
+
init_static();
|
|
108420
|
+
WELL_KNOWN_FILES = [
|
|
108421
|
+
"/robots.txt",
|
|
108422
|
+
"/sitemap.xml",
|
|
108423
|
+
"/llms.txt",
|
|
108424
|
+
"/llms-full.txt",
|
|
108425
|
+
"/feed.xml"
|
|
108426
|
+
];
|
|
108427
|
+
COPIED_PREFIXES = ["/bundles/", "/assets/"];
|
|
108428
|
+
});
|
|
108429
|
+
|
|
108430
|
+
// packages/cli/src/commands/static-render.ts
|
|
108431
|
+
var exports_static_render = {};
|
|
108432
|
+
__export(exports_static_render, {
|
|
108433
|
+
default: () => staticRender
|
|
108434
|
+
});
|
|
108435
|
+
import { join as join23 } from "node:path";
|
|
108436
|
+
async function staticRender(_args) {
|
|
108437
|
+
const cwd = process.cwd();
|
|
108438
|
+
const result = await buildStaticSite(cwd, join23(cwd, "dist"));
|
|
108439
|
+
for (const warning of result.warnings) {
|
|
108440
|
+
process.stdout.write(`[reroute/build] ⚠ ${warning}
|
|
108441
|
+
`);
|
|
108442
|
+
}
|
|
108443
|
+
process.stdout.write(`[reroute/build] ✓ Static site: ${result.pages.length} page(s), ${result.files} file(s) in ${result.outDir}
|
|
108444
|
+
`);
|
|
108445
|
+
process.exit(0);
|
|
108446
|
+
}
|
|
108447
|
+
var init_static_render = __esm(() => {
|
|
108448
|
+
init_prerender();
|
|
108449
|
+
});
|
|
108450
|
+
|
|
107980
108451
|
// packages/cli/src/cli.ts
|
|
107981
108452
|
import path3 from "node:path";
|
|
107982
108453
|
var commands = {
|
|
@@ -107986,7 +108457,8 @@ var commands = {
|
|
|
107986
108457
|
start: () => Promise.resolve().then(() => (init_start(), exports_start)),
|
|
107987
108458
|
build: () => Promise.resolve().then(() => (init_build(), exports_build)),
|
|
107988
108459
|
analyze: () => Promise.resolve().then(() => (init_analyze(), exports_analyze)),
|
|
107989
|
-
og: () => Promise.resolve().then(() => (init_og2(), exports_og))
|
|
108460
|
+
og: () => Promise.resolve().then(() => (init_og2(), exports_og)),
|
|
108461
|
+
"static-render": () => Promise.resolve().then(() => (init_static_render(), exports_static_render))
|
|
107990
108462
|
};
|
|
107991
108463
|
async function main() {
|
|
107992
108464
|
const args = process.argv.slice(2);
|
|
@@ -108067,6 +108539,7 @@ async function printHelp2() {
|
|
|
108067
108539
|
console.log(" reroute build --prod");
|
|
108068
108540
|
console.log(" reroute build -o ./dist/myapp");
|
|
108069
108541
|
console.log(" reroute build --outfile ./dist/myapp");
|
|
108542
|
+
console.log(" reroute build --static");
|
|
108070
108543
|
console.log("");
|
|
108071
108544
|
console.log(" reroute analyze");
|
|
108072
108545
|
console.log(" reroute analyze --prod");
|
|
@@ -108081,7 +108554,7 @@ async function getVersionString2() {
|
|
|
108081
108554
|
}
|
|
108082
108555
|
async function getVersion2() {
|
|
108083
108556
|
if (true) {
|
|
108084
|
-
return "1.0.0-alpha.
|
|
108557
|
+
return "1.0.0-alpha.26";
|
|
108085
108558
|
}
|
|
108086
108559
|
const possiblePaths = [
|
|
108087
108560
|
path3.join(import.meta.dir, "../../../package.json"),
|
|
@@ -108098,10 +108571,10 @@ async function getVersion2() {
|
|
|
108098
108571
|
}
|
|
108099
108572
|
async function getCommit2() {
|
|
108100
108573
|
if (true) {
|
|
108101
|
-
return "
|
|
108574
|
+
return "f166380";
|
|
108102
108575
|
}
|
|
108103
108576
|
return "dev";
|
|
108104
108577
|
}
|
|
108105
108578
|
main();
|
|
108106
108579
|
|
|
108107
|
-
//# debugId=
|
|
108580
|
+
//# debugId=209C291AD1922D2B64756E2164756E21
|