reroute-js 0.9.0 → 0.9.2
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/_/basic/package.json +1 -0
- package/_/basic/src/client/index.html +0 -1
- package/_/blog/package.json +1 -0
- package/_/store/package.json +1 -0
- package/cli/bin.d.ts +1 -1
- package/cli/bin.js +558 -674
- package/cli/bin.js.map +19 -24
- package/cli/index.d.ts +1 -1
- package/cli/index.js +47 -24
- package/cli/index.js.map +5 -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 +3 -4
- package/cli/src/commands/build.d.ts.map +1 -1
- package/cli/src/commands/dev.d.ts +2 -3
- package/cli/src/commands/dev.d.ts.map +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/init.d.ts +1 -1
- package/cli/src/commands/start.d.ts +3 -4
- package/cli/src/commands/start.d.ts.map +1 -1
- package/cli/src/libs/command.d.ts +1 -1
- package/cli/src/libs/index.d.ts +1 -1
- package/cli/src/libs/log.d.ts +1 -1
- package/cli/src/libs/log.d.ts.map +1 -1
- package/cli/src/libs/markdown-processor.d.ts +2 -1
- package/cli/src/libs/markdown-processor.d.ts.map +1 -1
- package/cli/src/libs/markdown.d.ts +1 -1
- package/cli/src/libs/production.d.ts +1 -1
- package/cli/src/libs/server.d.ts +18 -0
- package/cli/src/libs/server.d.ts.map +1 -0
- package/cli/src/libs/tailwind.d.ts +2 -2
- package/cli/src/libs/tailwind.d.ts.map +1 -1
- package/cli/src/libs/version.d.ts +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +99 -410
- package/core/index.js.map +7 -10
- package/core/src/bundler/hash.d.ts +1 -1
- package/core/src/bundler/index.d.ts +1 -2
- package/core/src/bundler/index.d.ts.map +1 -1
- package/core/src/content/discovery.d.ts +1 -3
- package/core/src/content/discovery.d.ts.map +1 -1
- package/core/src/content/index.d.ts +1 -2
- package/core/src/content/index.d.ts.map +1 -1
- package/core/src/content/metadata.d.ts +1 -1
- package/core/src/index.d.ts +1 -1
- package/core/src/ssr/data.d.ts +1 -1
- package/core/src/ssr/index.d.ts +1 -1
- package/core/src/ssr/modules.d.ts +1 -1
- package/core/src/ssr/render.d.ts +1 -1
- package/core/src/ssr/render.d.ts.map +1 -1
- package/core/src/ssr/seed.d.ts +1 -1
- package/core/src/template/html.d.ts +1 -1
- package/core/src/template/index.d.ts +1 -1
- package/core/src/types.d.ts +2 -22
- package/core/src/types.d.ts.map +1 -1
- package/core/src/utils/cache.d.ts +1 -1
- package/core/src/utils/compression.d.ts +1 -1
- package/core/src/utils/compression.d.ts.map +1 -1
- package/core/src/utils/index.d.ts +1 -1
- package/core/src/utils/mime.d.ts +1 -1
- package/core/src/utils/path.d.ts +1 -1
- package/elysia/index.d.ts +1 -1
- package/elysia/index.js +300 -773
- package/elysia/index.js.map +14 -17
- package/elysia/src/index.d.ts +1 -1
- package/elysia/src/libs/cache.d.ts +14 -0
- package/elysia/src/libs/cache.d.ts.map +1 -0
- package/elysia/src/libs/http.d.ts +1 -1
- package/elysia/src/libs/image.d.ts +1 -1
- package/elysia/src/libs/image.d.ts.map +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 +9 -2
- package/elysia/src/routes/artifacts.d.ts.map +1 -1
- package/elysia/src/routes/content.d.ts +3 -2
- package/elysia/src/routes/content.d.ts.map +1 -1
- package/elysia/src/routes/dev.d.ts +1 -1
- package/elysia/src/routes/dev.d.ts.map +1 -1
- package/elysia/src/routes/image.d.ts +1 -1
- package/elysia/src/routes/ssr.d.ts +1 -1
- package/elysia/src/routes/ssr.d.ts.map +1 -1
- package/elysia/src/routes/static.d.ts +2 -5
- package/elysia/src/routes/static.d.ts.map +1 -1
- package/elysia/src/types.d.ts +10 -3
- package/elysia/src/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/react/index.d.ts +1 -1
- package/react/index.js +17 -2
- package/react/index.js.map +5 -4
- 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/Link.d.ts +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/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/useSearchParams.d.ts +1 -1
- package/react/src/index.d.ts +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/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/react/src/utils/content.d.ts +1 -1
- package/react/src/utils/head.d.ts +1 -1
- package/react/src/utils/index.d.ts +2 -1
- package/react/src/utils/index.d.ts.map +1 -1
- package/react/src/utils/lazy-route.d.ts +41 -0
- package/react/src/utils/lazy-route.d.ts.map +1 -0
- package/cli/src/commands/boot.d.ts +0 -18
- package/cli/src/commands/boot.d.ts.map +0 -1
- package/core/src/bundler/transpile.d.ts +0 -14
- package/core/src/bundler/transpile.d.ts.map +0 -1
- package/core/src/content/registry.d.ts +0 -11
- package/core/src/content/registry.d.ts.map +0 -1
package/cli/bin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
3
|
/**
|
|
4
|
-
* reroute-js v0.9.
|
|
4
|
+
* reroute-js v0.9.2
|
|
5
5
|
*
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @copyright 2025 stewones <hi@stewan.io>
|
|
@@ -47,7 +47,7 @@ async function getVersionString() {
|
|
|
47
47
|
}
|
|
48
48
|
async function getVersion() {
|
|
49
49
|
if (true) {
|
|
50
|
-
return "0.9.
|
|
50
|
+
return "0.9.2";
|
|
51
51
|
}
|
|
52
52
|
const possiblePaths = [
|
|
53
53
|
path.join(import.meta.dir, "../../../../package.json"),
|
|
@@ -65,7 +65,7 @@ async function getVersion() {
|
|
|
65
65
|
}
|
|
66
66
|
async function getCommit() {
|
|
67
67
|
if (true) {
|
|
68
|
-
return "
|
|
68
|
+
return "07fb920";
|
|
69
69
|
}
|
|
70
70
|
return "dev";
|
|
71
71
|
}
|
|
@@ -77,7 +77,7 @@ __export(exports_init, {
|
|
|
77
77
|
default: () => init
|
|
78
78
|
});
|
|
79
79
|
import { existsSync } from "node:fs";
|
|
80
|
-
import { mkdir, readdir
|
|
80
|
+
import { mkdir, readdir } from "node:fs/promises";
|
|
81
81
|
import { join } from "node:path";
|
|
82
82
|
async function init(args) {
|
|
83
83
|
const options = parseArgs(args);
|
|
@@ -199,13 +199,13 @@ async function copyTemplateFiles(templatePath, targetPath, variables) {
|
|
|
199
199
|
await mkdir(destPath, { recursive: true });
|
|
200
200
|
await copyTemplateFiles(sourcePath, destPath, variables);
|
|
201
201
|
} else if (entry.isFile()) {
|
|
202
|
-
const content = await
|
|
202
|
+
const content = await Bun.file(sourcePath).text();
|
|
203
203
|
let processedContent = content;
|
|
204
204
|
for (const [key, value] of Object.entries(variables)) {
|
|
205
205
|
const placeholder = `{{${key}}}`;
|
|
206
206
|
processedContent = processedContent.split(placeholder).join(value);
|
|
207
207
|
}
|
|
208
|
-
await
|
|
208
|
+
await Bun.write(destPath, processedContent);
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
}
|
|
@@ -231,9 +231,9 @@ async function copySourceFiles(sourcePath, targetPath, variables) {
|
|
|
231
231
|
if (entry.isDirectory()) {
|
|
232
232
|
await copySourceFiles(sourceEntryPath, targetEntryPath, variables);
|
|
233
233
|
} else if (entry.isFile()) {
|
|
234
|
-
const content = await
|
|
234
|
+
const content = await Bun.file(sourceEntryPath).text();
|
|
235
235
|
const processedContent = variables ? applyVariableReplacements(content, entry.name, variables) : content;
|
|
236
|
-
await
|
|
236
|
+
await Bun.write(targetEntryPath, processedContent);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
}
|
|
@@ -532,14 +532,27 @@ async function compileMdx(content, cwd, options = {}) {
|
|
|
532
532
|
});
|
|
533
533
|
return String(result);
|
|
534
534
|
} catch (error) {
|
|
535
|
-
|
|
535
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
536
|
+
const errorLocation = error && typeof error === "object" && "place" in error && error.place && typeof error.place === "object" ? `at line ${error.place.line || "?"}, column ${error.place.column || "?"}` : "";
|
|
537
|
+
const fileInfo = options.filename ? ` in ${options.filename}` : "";
|
|
538
|
+
console.warn(`[reroute/mdx] Compilation failed${fileInfo}${errorLocation ? ` ${errorLocation}` : ""}: ${errorMessage}`);
|
|
539
|
+
console.warn("[reroute/mdx] Falling back to react-markdown");
|
|
536
540
|
return null;
|
|
537
541
|
}
|
|
538
542
|
}
|
|
539
543
|
async function generateMarkdownModule(processed, cwd, options = {}) {
|
|
540
544
|
const { frontmatter, content } = processed;
|
|
541
|
-
const {
|
|
542
|
-
|
|
545
|
+
const {
|
|
546
|
+
enableGfm = true,
|
|
547
|
+
theme = "github-dark",
|
|
548
|
+
isMdx = false,
|
|
549
|
+
filename
|
|
550
|
+
} = options;
|
|
551
|
+
const compiledMdx = await compileMdx(content, cwd, {
|
|
552
|
+
enableGfm,
|
|
553
|
+
theme,
|
|
554
|
+
filename
|
|
555
|
+
});
|
|
543
556
|
if (compiledMdx) {
|
|
544
557
|
return `// Generated from ${isMdx ? "MDX" : "Markdown"} file with @mdx-js/mdx
|
|
545
558
|
|
|
@@ -557,7 +570,6 @@ export const ssr = {
|
|
|
557
570
|
};
|
|
558
571
|
`;
|
|
559
572
|
}
|
|
560
|
-
console.warn("[reroute/mdx] MDX compile unavailable; falling back to react-markdown");
|
|
561
573
|
const escapedContent = content.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
562
574
|
const pluginImports = [];
|
|
563
575
|
const remarkPluginsList = [];
|
|
@@ -659,20 +671,28 @@ import { spawn } from "node:child_process";
|
|
|
659
671
|
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "node:fs";
|
|
660
672
|
import { join as join4 } from "node:path";
|
|
661
673
|
function isTailwindAvailable(cwd) {
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
674
|
+
const pathsToTry = [
|
|
675
|
+
join4(cwd, "package.json"),
|
|
676
|
+
join4(cwd, "../package.json"),
|
|
677
|
+
join4(cwd, "../../package.json"),
|
|
678
|
+
join4(cwd, "../../../package.json")
|
|
679
|
+
];
|
|
680
|
+
for (const packageJsonPath of pathsToTry) {
|
|
681
|
+
if (!existsSync4(packageJsonPath)) {
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
try {
|
|
685
|
+
const packageJson = JSON.parse(readFileSync3(packageJsonPath, "utf-8"));
|
|
686
|
+
const deps = {
|
|
687
|
+
...packageJson.dependencies,
|
|
688
|
+
...packageJson.devDependencies
|
|
689
|
+
};
|
|
690
|
+
if ("@tailwindcss/cli" in deps) {
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
} catch {}
|
|
675
694
|
}
|
|
695
|
+
return false;
|
|
676
696
|
}
|
|
677
697
|
function getTailwindPaths(cwd) {
|
|
678
698
|
const input = join4(cwd, "src/client/theme.css");
|
|
@@ -704,12 +724,16 @@ function resolveTailwindBin(cwd) {
|
|
|
704
724
|
}
|
|
705
725
|
return join4(cwd, "node_modules/.bin/tailwindcss");
|
|
706
726
|
}
|
|
707
|
-
async function buildTailwind(cwd) {
|
|
727
|
+
async function buildTailwind(cwd, minify = false) {
|
|
708
728
|
const { input, output } = getTailwindPaths(cwd);
|
|
709
729
|
return new Promise((resolve, reject) => {
|
|
710
730
|
const tailwindBin = resolveTailwindBin(cwd);
|
|
711
731
|
const args = ["-i", input, "-o", output];
|
|
712
|
-
|
|
732
|
+
if (minify) {
|
|
733
|
+
args.push("--minify");
|
|
734
|
+
}
|
|
735
|
+
const argsStr = args.join(" ");
|
|
736
|
+
console.log(`[reroute/tailwind] build start: ${argsStr}`);
|
|
713
737
|
const tailwind = spawn(tailwindBin, args, {
|
|
714
738
|
cwd,
|
|
715
739
|
stdio: "pipe"
|
|
@@ -739,10 +763,10 @@ async function buildTailwind(cwd) {
|
|
|
739
763
|
});
|
|
740
764
|
});
|
|
741
765
|
}
|
|
742
|
-
async function buildTailwindIfConfigured(cwd) {
|
|
766
|
+
async function buildTailwindIfConfigured(cwd, minify = false) {
|
|
743
767
|
try {
|
|
744
768
|
if (isTailwindAvailable(cwd) && hasTailwindInput(cwd)) {
|
|
745
|
-
await buildTailwind(cwd);
|
|
769
|
+
await buildTailwind(cwd, minify);
|
|
746
770
|
return true;
|
|
747
771
|
}
|
|
748
772
|
return false;
|
|
@@ -759,16 +783,69 @@ __export(exports_gen, {
|
|
|
759
783
|
default: () => gen
|
|
760
784
|
});
|
|
761
785
|
import { watch } from "node:fs";
|
|
762
|
-
import { mkdir as mkdir2, readdir as readdir2, rm
|
|
786
|
+
import { mkdir as mkdir2, readdir as readdir2, rm } from "node:fs/promises";
|
|
763
787
|
import { join as join5 } from "node:path";
|
|
764
788
|
import { pathToFileURL } from "node:url";
|
|
765
|
-
async function
|
|
789
|
+
async function ensureOutputDir(cwd) {
|
|
766
790
|
try {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
791
|
+
const outputPath = join5(cwd, OUTPUT_DIR);
|
|
792
|
+
let needsCleanup = false;
|
|
793
|
+
try {
|
|
794
|
+
const entries = await readdir2(outputPath);
|
|
795
|
+
needsCleanup = entries.length > 0;
|
|
796
|
+
} catch {}
|
|
797
|
+
if (needsCleanup) {
|
|
798
|
+
await rm(outputPath, { force: true, recursive: true });
|
|
799
|
+
console.log("[reroute/gen] Cleaned up generated artifacts in .reroute");
|
|
800
|
+
}
|
|
801
|
+
await mkdir2(outputPath, { recursive: true });
|
|
802
|
+
await mkdir2(join5(cwd, OUTPUT_COLLECTIONS_DIR), { recursive: true });
|
|
803
|
+
await mkdir2(join5(cwd, ".reroute/bundles"), { recursive: true });
|
|
770
804
|
} catch {}
|
|
771
805
|
}
|
|
806
|
+
async function writeStubFiles(cwd) {
|
|
807
|
+
const STUB_ROUTES = `// \uD83D\uDEA8 Auto-generated stub by Reroute - DO NOT EDIT \uD83D\uDEA8
|
|
808
|
+
// This will be replaced by actual routes
|
|
809
|
+
/* eslint-disable */
|
|
810
|
+
// @ts-nocheck
|
|
811
|
+
|
|
812
|
+
export const layouts: any[] = [];
|
|
813
|
+
export const notFoundRoutes: any[] = [];
|
|
814
|
+
|
|
815
|
+
export function matchRoute(pathname: string): any {
|
|
816
|
+
return null;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
export type RouteParams = Record<string, never>;
|
|
820
|
+
`;
|
|
821
|
+
const STUB_CONTENT = `// \uD83D\uDEA8 Auto-generated stub by Reroute - DO NOT EDIT \uD83D\uDEA8
|
|
822
|
+
// This will be replaced by actual content
|
|
823
|
+
/* eslint-disable */
|
|
824
|
+
// @ts-nocheck
|
|
825
|
+
|
|
826
|
+
export const contentRegistry: Record<string, any> = {};
|
|
827
|
+
`;
|
|
828
|
+
const STUB_INDEX = `// \uD83D\uDEA8 Auto-generated stub by Reroute - DO NOT EDIT \uD83D\uDEA8
|
|
829
|
+
// This will be replaced by actual artifacts
|
|
830
|
+
/* eslint-disable */
|
|
831
|
+
// @ts-nocheck
|
|
832
|
+
|
|
833
|
+
import { layouts, matchRoute, notFoundRoutes } from './routes';
|
|
834
|
+
|
|
835
|
+
export const artifacts = {
|
|
836
|
+
layouts,
|
|
837
|
+
matchRoute,
|
|
838
|
+
notFoundRoutes,
|
|
839
|
+
contentBaseUrl: '/.reroute/collections'
|
|
840
|
+
} as const;
|
|
841
|
+
|
|
842
|
+
export type RerouteArtifacts = typeof artifacts;
|
|
843
|
+
`;
|
|
844
|
+
await Bun.write(join5(cwd, OUTPUT_ROUTES), STUB_ROUTES);
|
|
845
|
+
await Bun.write(join5(cwd, OUTPUT_CONTENT_TS), STUB_CONTENT);
|
|
846
|
+
await Bun.write(join5(cwd, OUTPUT_INDEX), STUB_INDEX);
|
|
847
|
+
console.log("[reroute/gen] Initialized stub files");
|
|
848
|
+
}
|
|
772
849
|
async function scanDirectory(dir, base = "") {
|
|
773
850
|
const files = [];
|
|
774
851
|
const entries = await readdir2(dir, { withFileTypes: true });
|
|
@@ -880,10 +957,26 @@ function getImportPath(filePath) {
|
|
|
880
957
|
return `../src/client/routes/${pathWithoutExt}`;
|
|
881
958
|
}
|
|
882
959
|
function generateTypeScript(tree) {
|
|
883
|
-
const
|
|
884
|
-
|
|
885
|
-
...tree.
|
|
886
|
-
...tree.
|
|
960
|
+
const helperImport = "import { createLazyRoute } from 'reroute-js/react';";
|
|
961
|
+
const eagerImports = [
|
|
962
|
+
...tree.routes.map((r, i) => `import Route${i}Eager from '${getImportPath(r.filePath)}';`),
|
|
963
|
+
...tree.layouts.map((l, i) => `import Layout${i}Eager from '${getImportPath(l.filePath)}';`),
|
|
964
|
+
...tree.notFoundRoutes.map((nf, i) => `import NotFound${i}Eager from '${getImportPath(nf.filePath)}';`)
|
|
965
|
+
].join(`
|
|
966
|
+
`);
|
|
967
|
+
const lazyWrappers = [
|
|
968
|
+
...tree.routes.map((r, i) => {
|
|
969
|
+
const importPath = getImportPath(r.filePath);
|
|
970
|
+
return `const Route${i} = createLazyRoute(Route${i}Eager, () => import('${importPath}'), "${r.pattern}");`;
|
|
971
|
+
}),
|
|
972
|
+
...tree.layouts.map((l, i) => {
|
|
973
|
+
const importPath = getImportPath(l.filePath);
|
|
974
|
+
return `const Layout${i} = createLazyRoute(Layout${i}Eager, () => import('${importPath}'), "${l.pattern}");`;
|
|
975
|
+
}),
|
|
976
|
+
...tree.notFoundRoutes.map((nf, i) => {
|
|
977
|
+
const importPath = getImportPath(nf.filePath);
|
|
978
|
+
return `const NotFound${i} = createLazyRoute(NotFound${i}Eager, () => import('${importPath}'), "${nf.notFoundBasePattern || "/"}");`;
|
|
979
|
+
})
|
|
887
980
|
].join(`
|
|
888
981
|
`);
|
|
889
982
|
const routesArray = tree.routes.map((r, i) => {
|
|
@@ -923,7 +1016,11 @@ function generateTypeScript(tree) {
|
|
|
923
1016
|
/* eslint-disable */
|
|
924
1017
|
// @ts-nocheck
|
|
925
1018
|
|
|
926
|
-
${
|
|
1019
|
+
${helperImport}
|
|
1020
|
+
|
|
1021
|
+
${eagerImports}
|
|
1022
|
+
|
|
1023
|
+
${lazyWrappers}
|
|
927
1024
|
|
|
928
1025
|
export const routes: RouteInfo = [
|
|
929
1026
|
${routesArray}
|
|
@@ -1003,7 +1100,7 @@ async function sha8(text) {
|
|
|
1003
1100
|
hex += b.toString(16).padStart(2, "0");
|
|
1004
1101
|
return hex.slice(0, 8);
|
|
1005
1102
|
}
|
|
1006
|
-
async function buildContentChunks(cwd) {
|
|
1103
|
+
async function buildContentChunks(cwd, args = []) {
|
|
1007
1104
|
const routesRoot = join5(cwd, ROUTES_DIR);
|
|
1008
1105
|
console.log(`[reroute/content] scan ${routesRoot}`);
|
|
1009
1106
|
const collections = await readdir2(routesRoot, { withFileTypes: true });
|
|
@@ -1015,7 +1112,7 @@ async function buildContentChunks(cwd) {
|
|
|
1015
1112
|
const contentDir = join5(routesRoot, collection, "content");
|
|
1016
1113
|
console.log(`[reroute/content] collection ${collection} dir ${contentDir}`);
|
|
1017
1114
|
const files = await listContentFiles(contentDir);
|
|
1018
|
-
console.log(`[reroute/content] files ${files.
|
|
1115
|
+
console.log(`[reroute/content] files ${files.length}`);
|
|
1019
1116
|
if (!files.length)
|
|
1020
1117
|
continue;
|
|
1021
1118
|
for (const file of files) {
|
|
@@ -1034,8 +1131,7 @@ async function buildContentChunks(cwd) {
|
|
|
1034
1131
|
}
|
|
1035
1132
|
let code = "";
|
|
1036
1133
|
try {
|
|
1037
|
-
|
|
1038
|
-
const isProd = isProductionMode();
|
|
1134
|
+
const isProd = isProductionMode(args);
|
|
1039
1135
|
const result = await Bun.build({
|
|
1040
1136
|
entrypoints: [buildSrc],
|
|
1041
1137
|
target: "browser",
|
|
@@ -1055,19 +1151,17 @@ async function buildContentChunks(cwd) {
|
|
|
1055
1151
|
continue;
|
|
1056
1152
|
}
|
|
1057
1153
|
const hash = await sha8(code);
|
|
1058
|
-
const chunkRelDir = join5(".reroute", "
|
|
1154
|
+
const chunkRelDir = join5(".reroute", "bundles");
|
|
1059
1155
|
const chunkAbsDir = join5(cwd, chunkRelDir);
|
|
1060
|
-
const outFile = `${name}.${hash}.js`;
|
|
1156
|
+
const outFile = `${collection}-${name}.${hash}.js`;
|
|
1061
1157
|
const absOut = join5(chunkAbsDir, outFile);
|
|
1062
|
-
await mkdir2(chunkAbsDir, { recursive: true });
|
|
1063
1158
|
try {
|
|
1064
1159
|
const exists = await Bun.file(absOut).exists();
|
|
1065
1160
|
if (!exists)
|
|
1066
|
-
await
|
|
1161
|
+
await Bun.write(absOut, code);
|
|
1067
1162
|
} catch {}
|
|
1068
1163
|
let meta = {};
|
|
1069
1164
|
try {
|
|
1070
|
-
console.log(`[reroute/content] meta ${buildSrc}`);
|
|
1071
1165
|
const url = `${pathToFileURL(buildSrc).href}?t=${Date.now()}`;
|
|
1072
1166
|
const m = await import(url);
|
|
1073
1167
|
meta = m.meta || {};
|
|
@@ -1077,7 +1171,7 @@ async function buildContentChunks(cwd) {
|
|
|
1077
1171
|
name,
|
|
1078
1172
|
slug: name,
|
|
1079
1173
|
href: `/${collection}/${name}`,
|
|
1080
|
-
moduleUrl:
|
|
1174
|
+
moduleUrl: `/bundles/${outFile}`,
|
|
1081
1175
|
meta
|
|
1082
1176
|
});
|
|
1083
1177
|
}
|
|
@@ -1108,12 +1202,10 @@ async function buildContentChunks(cwd) {
|
|
|
1108
1202
|
lines.push(" return m ? (m as Record<string, any>)[name] : undefined;");
|
|
1109
1203
|
lines.push("}");
|
|
1110
1204
|
lines.push("");
|
|
1111
|
-
await
|
|
1112
|
-
|
|
1113
|
-
`), "utf-8");
|
|
1205
|
+
await Bun.write(join5(cwd, OUTPUT_CONTENT_TS), lines.join(`
|
|
1206
|
+
`));
|
|
1114
1207
|
console.log(`[reroute/content] wrote ${join5(cwd, OUTPUT_CONTENT_TS)}`);
|
|
1115
1208
|
const collectionsSet = new Set(results.map((r) => r.collection));
|
|
1116
|
-
await mkdir2(join5(cwd, OUTPUT_COLLECTIONS_DIR), { recursive: true });
|
|
1117
1209
|
for (const collection of collectionsSet) {
|
|
1118
1210
|
const items = results.filter((r) => r.collection === collection);
|
|
1119
1211
|
const js = [];
|
|
@@ -1133,8 +1225,8 @@ async function buildContentChunks(cwd) {
|
|
|
1133
1225
|
js.push(" return byName[name];");
|
|
1134
1226
|
js.push("}");
|
|
1135
1227
|
js.push("");
|
|
1136
|
-
await
|
|
1137
|
-
`)
|
|
1228
|
+
await Bun.write(join5(cwd, OUTPUT_COLLECTIONS_DIR, `${collection}.js`), js.join(`
|
|
1229
|
+
`));
|
|
1138
1230
|
console.log(`[reroute/content] wrote ${join5(cwd, OUTPUT_COLLECTIONS_DIR, `${collection}.js`)}`);
|
|
1139
1231
|
}
|
|
1140
1232
|
}
|
|
@@ -1147,9 +1239,6 @@ async function preprocessMarkdownFiles(cwd) {
|
|
|
1147
1239
|
} catch {}
|
|
1148
1240
|
const markdownConfig = getMarkdownConfig(cwd);
|
|
1149
1241
|
console.log("[reroute/markdown] Config:", markdownConfig);
|
|
1150
|
-
try {
|
|
1151
|
-
await mkdir2(markdownDir, { recursive: true });
|
|
1152
|
-
} catch {}
|
|
1153
1242
|
async function scanMarkdown(dir, base = "") {
|
|
1154
1243
|
const files = [];
|
|
1155
1244
|
try {
|
|
@@ -1161,7 +1250,6 @@ async function preprocessMarkdownFiles(cwd) {
|
|
|
1161
1250
|
const nested = await scanMarkdown(fullPath, relativePath);
|
|
1162
1251
|
files.push(...nested);
|
|
1163
1252
|
} else if (entry.isFile() && isMarkdownFile(entry.name)) {
|
|
1164
|
-
console.log(`[reroute/markdown] Found markdown file: ${relativePath}`);
|
|
1165
1253
|
files.push(relativePath);
|
|
1166
1254
|
}
|
|
1167
1255
|
}
|
|
@@ -1172,13 +1260,12 @@ async function preprocessMarkdownFiles(cwd) {
|
|
|
1172
1260
|
}
|
|
1173
1261
|
console.log(`[reroute/markdown] Scanning ${routesPath} for markdown files...`);
|
|
1174
1262
|
const markdownFiles = await scanMarkdown(routesPath);
|
|
1175
|
-
console.log(`[reroute/markdown] Scan complete. Found files:`, markdownFiles);
|
|
1263
|
+
console.log(`[reroute/markdown] Scan complete. Found files:`, markdownFiles.length);
|
|
1176
1264
|
if (markdownFiles.length === 0) {
|
|
1177
1265
|
console.log("[reroute/markdown] No markdown files found, skipping preprocessing");
|
|
1178
1266
|
return;
|
|
1179
1267
|
}
|
|
1180
1268
|
console.log(`[reroute/markdown] Found ${markdownFiles.length} markdown file(s)`);
|
|
1181
|
-
await mkdir2(markdownDir, { recursive: true });
|
|
1182
1269
|
for (const file of markdownFiles) {
|
|
1183
1270
|
const sourcePath = join5(routesPath, file);
|
|
1184
1271
|
const targetPath = join5(markdownDir, file.replace(/\.mdx?$/, ".tsx"));
|
|
@@ -1190,25 +1277,94 @@ async function preprocessMarkdownFiles(cwd) {
|
|
|
1190
1277
|
moduleCode = await generateMarkdownModule(processed, cwd, {
|
|
1191
1278
|
enableGfm: markdownConfig.hasRemarkGfm,
|
|
1192
1279
|
theme: "github-dark",
|
|
1193
|
-
isMdx
|
|
1280
|
+
isMdx,
|
|
1281
|
+
filename: file
|
|
1194
1282
|
});
|
|
1195
1283
|
} else {
|
|
1196
1284
|
moduleCode = generatePlainMarkdownModule(processed);
|
|
1197
1285
|
}
|
|
1198
|
-
|
|
1199
|
-
if (targetDir !== markdownDir) {
|
|
1200
|
-
await mkdir2(targetDir, { recursive: true });
|
|
1201
|
-
}
|
|
1202
|
-
await writeFile2(targetPath, moduleCode, "utf-8");
|
|
1203
|
-
console.log(`[reroute/markdown] Processed ${file} -> ${targetPath}`);
|
|
1286
|
+
await Bun.write(targetPath, moduleCode);
|
|
1204
1287
|
} catch (error) {
|
|
1205
1288
|
console.error(`[reroute/markdown] Failed to process ${file}:`, error);
|
|
1206
1289
|
}
|
|
1207
1290
|
}
|
|
1208
1291
|
}
|
|
1209
|
-
async function
|
|
1292
|
+
async function buildEntrypointBundle(cwd, args = []) {
|
|
1293
|
+
const clientDir = join5(cwd, "src", "client");
|
|
1294
|
+
const entrypoint = join5(clientDir, "index.tsx");
|
|
1295
|
+
const exists = await Bun.file(entrypoint).exists();
|
|
1296
|
+
if (!exists) {
|
|
1297
|
+
console.log("[reroute/gen] No index.tsx found, skipping bundle build");
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
console.log("[reroute/gen] Building entrypoint bundle with code splitting...");
|
|
1301
|
+
const isProd = isProductionMode(args);
|
|
1302
|
+
const result = await Bun.build({
|
|
1303
|
+
entrypoints: [entrypoint],
|
|
1304
|
+
target: "browser",
|
|
1305
|
+
format: "esm",
|
|
1306
|
+
splitting: true,
|
|
1307
|
+
sourcemap: isProd ? "linked" : "external",
|
|
1308
|
+
minify: isProd,
|
|
1309
|
+
naming: {
|
|
1310
|
+
entry: "[name].[hash].[ext]",
|
|
1311
|
+
chunk: "chunk.[hash].[ext]",
|
|
1312
|
+
asset: "[name].[hash].[ext]"
|
|
1313
|
+
},
|
|
1314
|
+
jsx: {
|
|
1315
|
+
runtime: "automatic",
|
|
1316
|
+
importSource: "react",
|
|
1317
|
+
development: !isProd
|
|
1318
|
+
},
|
|
1319
|
+
define: {
|
|
1320
|
+
"process.env.NODE_ENV": isProd ? '"production"' : '"development"',
|
|
1321
|
+
__DEV__: isProd ? "false" : "true",
|
|
1322
|
+
"import.meta.env.MODE": isProd ? '"production"' : '"development"'
|
|
1323
|
+
},
|
|
1324
|
+
...isProd ? { drop: ["console", "debugger"] } : {}
|
|
1325
|
+
});
|
|
1326
|
+
if (!result.success) {
|
|
1327
|
+
console.error("[reroute/gen] Entrypoint build failed:");
|
|
1328
|
+
for (const log of result.logs)
|
|
1329
|
+
console.error(log);
|
|
1330
|
+
throw new Error("Failed to build entrypoint");
|
|
1331
|
+
}
|
|
1332
|
+
const bundlesDir = join5(cwd, ".reroute", "bundles");
|
|
1333
|
+
try {
|
|
1334
|
+
const existingFiles = await readdir2(bundlesDir);
|
|
1335
|
+
for (const file of existingFiles) {
|
|
1336
|
+
if (/^(index|chunk)\.[a-z0-9]+\.(js|js\.map)$/i.test(file)) {
|
|
1337
|
+
await rm(join5(bundlesDir, file), { force: true });
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
} catch {}
|
|
1341
|
+
const outputs = [];
|
|
1342
|
+
let entryFile = "";
|
|
1343
|
+
for (const output of result.outputs) {
|
|
1344
|
+
const content = await output.text();
|
|
1345
|
+
const fileName = output.path.split("/").pop() || output.path.split("\\").pop() || "unknown";
|
|
1346
|
+
const destPath = join5(bundlesDir, fileName);
|
|
1347
|
+
await Bun.write(destPath, content);
|
|
1348
|
+
const isEntry = fileName.startsWith("index.") && fileName.endsWith(".js") && !fileName.endsWith(".map");
|
|
1349
|
+
if (isEntry)
|
|
1350
|
+
entryFile = fileName;
|
|
1351
|
+
outputs.push({
|
|
1352
|
+
fileName,
|
|
1353
|
+
size: content.length,
|
|
1354
|
+
isEntry
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
const totalSize = outputs.reduce((sum, o) => sum + o.size, 0);
|
|
1358
|
+
const gzipped = Bun.gzipSync(new TextEncoder().encode(outputs.find((o) => o.isEntry)?.fileName ? await Bun.file(join5(bundlesDir, entryFile)).text() : "")).length;
|
|
1359
|
+
console.log(`[reroute/gen] Built ${outputs.length} files (${(totalSize / 1024).toFixed(2)}KB, ${(gzipped / 1024).toFixed(2)}KB gzipped)`);
|
|
1360
|
+
console.log(`[reroute/gen] Entry: ${entryFile}`);
|
|
1361
|
+
console.log(`[reroute/gen] Chunks: ${outputs.filter((o) => !o.isEntry && o.fileName.endsWith(".js")).length}`);
|
|
1362
|
+
}
|
|
1363
|
+
async function generate(cwd, args = []) {
|
|
1364
|
+
const startTime = performance.now();
|
|
1210
1365
|
console.log("[reroute/gen] Starting generation...");
|
|
1211
|
-
await
|
|
1366
|
+
await ensureOutputDir(cwd);
|
|
1367
|
+
await writeStubFiles(cwd);
|
|
1212
1368
|
await preprocessMarkdownFiles(cwd);
|
|
1213
1369
|
const routesPath = join5(cwd, ROUTES_DIR);
|
|
1214
1370
|
try {
|
|
@@ -1217,15 +1373,14 @@ async function generate(cwd) {
|
|
|
1217
1373
|
const all = Array.from(new Set([...files, ...nfFiles]));
|
|
1218
1374
|
const tree = generateRouteTree(all.map((f) => f.replace(/\\/g, "/")));
|
|
1219
1375
|
const ts = generateTypeScript(tree);
|
|
1220
|
-
await
|
|
1221
|
-
await writeFile2(join5(cwd, OUTPUT_ROUTES), ts, "utf-8");
|
|
1376
|
+
await Bun.write(join5(cwd, OUTPUT_ROUTES), ts);
|
|
1222
1377
|
console.log(`[reroute/gen] Generated routes: ${join5(cwd, OUTPUT_ROUTES)}`);
|
|
1223
1378
|
} catch (error) {
|
|
1224
1379
|
console.error("[reroute/gen] Failed to generate routes:", error);
|
|
1225
1380
|
throw error;
|
|
1226
1381
|
}
|
|
1227
1382
|
try {
|
|
1228
|
-
await buildContentChunks(cwd);
|
|
1383
|
+
await buildContentChunks(cwd, args);
|
|
1229
1384
|
console.log(`[reroute/gen] Generated content: ${join5(cwd, OUTPUT_CONTENT_TS)} + collections/*.js`);
|
|
1230
1385
|
} catch (error) {
|
|
1231
1386
|
console.error("[reroute/gen] Failed to generate content:", error);
|
|
@@ -1246,25 +1401,34 @@ async function generate(cwd) {
|
|
|
1246
1401
|
indexLines.push("} as const;");
|
|
1247
1402
|
indexLines.push("");
|
|
1248
1403
|
indexLines.push("export type RerouteArtifacts = typeof artifacts;");
|
|
1249
|
-
await
|
|
1250
|
-
`)
|
|
1404
|
+
await Bun.write(join5(cwd, OUTPUT_INDEX), indexLines.join(`
|
|
1405
|
+
`));
|
|
1251
1406
|
console.log(`[reroute/gen] Generated index: ${join5(cwd, OUTPUT_INDEX)}`);
|
|
1252
|
-
|
|
1407
|
+
try {
|
|
1408
|
+
await buildEntrypointBundle(cwd, args);
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
console.error("[reroute/gen] Failed to build entrypoint:", error);
|
|
1411
|
+
throw error;
|
|
1412
|
+
}
|
|
1413
|
+
const endTime = performance.now();
|
|
1414
|
+
const duration = ((endTime - startTime) / 1000).toFixed(2);
|
|
1415
|
+
console.log(`[reroute/gen] Generation complete in ${duration}s`);
|
|
1253
1416
|
}
|
|
1254
1417
|
async function gen(args) {
|
|
1255
1418
|
const cwd = process.cwd();
|
|
1256
1419
|
const watchMode = args.includes("--watch") || args.includes("-w");
|
|
1420
|
+
const isProd = isProductionMode(args);
|
|
1257
1421
|
if (!watchMode) {
|
|
1258
|
-
await generate(cwd);
|
|
1259
|
-
await buildTailwindIfConfigured(cwd);
|
|
1422
|
+
await generate(cwd, args);
|
|
1423
|
+
await buildTailwindIfConfigured(cwd, isProd);
|
|
1260
1424
|
checkMarkdownIfConfigured(cwd);
|
|
1261
1425
|
return;
|
|
1262
1426
|
}
|
|
1263
1427
|
console.log("[reroute/gen] Watch mode enabled");
|
|
1264
1428
|
console.log("[reroute/gen] Initial generation...");
|
|
1265
|
-
await generate(cwd);
|
|
1429
|
+
await generate(cwd, args);
|
|
1266
1430
|
try {
|
|
1267
|
-
await buildTailwindIfConfigured(cwd);
|
|
1431
|
+
await buildTailwindIfConfigured(cwd, isProd);
|
|
1268
1432
|
checkMarkdownIfConfigured(cwd);
|
|
1269
1433
|
} catch {}
|
|
1270
1434
|
const notifyReload = async (reason) => {
|
|
@@ -1284,6 +1448,7 @@ async function gen(args) {
|
|
|
1284
1448
|
} catch {}
|
|
1285
1449
|
}
|
|
1286
1450
|
};
|
|
1451
|
+
await notifyReload("initial generation");
|
|
1287
1452
|
const routesPath = join5(cwd, ROUTES_DIR);
|
|
1288
1453
|
console.log(`[reroute/gen] Watching ${routesPath} for changes...`);
|
|
1289
1454
|
let debounce = null;
|
|
@@ -1295,16 +1460,16 @@ async function gen(args) {
|
|
|
1295
1460
|
debounce = setTimeout(async () => {
|
|
1296
1461
|
console.log("[reroute/gen] Change detected, regenerating...");
|
|
1297
1462
|
try {
|
|
1298
|
-
await generate(cwd);
|
|
1299
|
-
await buildTailwindIfConfigured(cwd);
|
|
1463
|
+
await generate(cwd, args);
|
|
1464
|
+
await buildTailwindIfConfigured(cwd, isProd);
|
|
1300
1465
|
await notifyReload("routes change");
|
|
1301
1466
|
} catch (e) {
|
|
1302
1467
|
console.error("[reroute/gen] Error during regeneration:", e);
|
|
1303
1468
|
}
|
|
1304
|
-
},
|
|
1469
|
+
}, 50);
|
|
1305
1470
|
});
|
|
1306
1471
|
const clientPath = join5(cwd, "src", "client");
|
|
1307
|
-
console.log(`[reroute/gen] Watching ${clientPath} for
|
|
1472
|
+
console.log(`[reroute/gen] Watching ${clientPath} for changes...`);
|
|
1308
1473
|
let twDebounce = null;
|
|
1309
1474
|
const twWatcher = watch(clientPath, { recursive: true }, (_ev, filename) => {
|
|
1310
1475
|
if (!filename)
|
|
@@ -1320,10 +1485,14 @@ async function gen(args) {
|
|
|
1320
1485
|
clearTimeout(twDebounce);
|
|
1321
1486
|
twDebounce = setTimeout(async () => {
|
|
1322
1487
|
try {
|
|
1323
|
-
|
|
1488
|
+
if (name === "index.tsx" || name.includes("components/") || name.includes("hooks/") || name.includes("providers/")) {
|
|
1489
|
+
console.log("[reroute/gen] Client code changed, rebuilding bundle...");
|
|
1490
|
+
await buildEntrypointBundle(cwd, args);
|
|
1491
|
+
}
|
|
1492
|
+
await buildTailwindIfConfigured(cwd, isProd);
|
|
1324
1493
|
await notifyReload("client change");
|
|
1325
1494
|
} catch {}
|
|
1326
|
-
},
|
|
1495
|
+
}, 100);
|
|
1327
1496
|
});
|
|
1328
1497
|
process.on("SIGINT", () => {
|
|
1329
1498
|
console.log(`
|
|
@@ -1344,69 +1513,6 @@ var init_gen = __esm(() => {
|
|
|
1344
1513
|
init_tailwind();
|
|
1345
1514
|
});
|
|
1346
1515
|
|
|
1347
|
-
// packages/cli/src/commands/boot.ts
|
|
1348
|
-
var exports_boot = {};
|
|
1349
|
-
__export(exports_boot, {
|
|
1350
|
-
default: () => boot
|
|
1351
|
-
});
|
|
1352
|
-
import { mkdir as mkdir3, writeFile as writeFile3 } from "node:fs/promises";
|
|
1353
|
-
import { join as join6 } from "node:path";
|
|
1354
|
-
async function boot(_) {
|
|
1355
|
-
const cwd = process.cwd();
|
|
1356
|
-
try {
|
|
1357
|
-
console.log("[reroute/boot] Initializing .reroute directory...");
|
|
1358
|
-
await mkdir3(join6(cwd, OUTPUT_DIR2), { recursive: true });
|
|
1359
|
-
await mkdir3(join6(cwd, OUTPUT_COLLECTIONS_DIR2), { recursive: true });
|
|
1360
|
-
await writeFile3(join6(cwd, OUTPUT_ROUTES2), STUB_ROUTES, "utf-8");
|
|
1361
|
-
console.log(`[reroute/boot] Created stub: ${OUTPUT_ROUTES2}`);
|
|
1362
|
-
await writeFile3(join6(cwd, OUTPUT_CONTENT_TS2), STUB_CONTENT, "utf-8");
|
|
1363
|
-
console.log(`[reroute/boot] Created stub: ${OUTPUT_CONTENT_TS2}`);
|
|
1364
|
-
await writeFile3(join6(cwd, OUTPUT_INDEX2), STUB_INDEX, "utf-8");
|
|
1365
|
-
console.log(`[reroute/boot] Created stub: ${OUTPUT_INDEX2}`);
|
|
1366
|
-
console.log("[reroute/boot] Initialization complete");
|
|
1367
|
-
console.log('[reroute/boot] Run "reroute gen" to generate actual routes and content.');
|
|
1368
|
-
} catch (error) {
|
|
1369
|
-
console.error("[reroute/boot] Failed to initialize:", error);
|
|
1370
|
-
throw error;
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
var OUTPUT_DIR2 = ".reroute", OUTPUT_ROUTES2 = ".reroute/routes.ts", OUTPUT_CONTENT_TS2 = ".reroute/content.ts", OUTPUT_COLLECTIONS_DIR2 = ".reroute/collections", OUTPUT_INDEX2 = ".reroute/index.ts", STUB_ROUTES = `// \uD83D\uDEA8 Auto-generated stub by Reroute - DO NOT EDIT \uD83D\uDEA8
|
|
1374
|
-
// Run 'reroute gen' to generate actual routes
|
|
1375
|
-
/* eslint-disable */
|
|
1376
|
-
// @ts-nocheck
|
|
1377
|
-
|
|
1378
|
-
export const layouts: any[] = [];
|
|
1379
|
-
export const notFoundRoutes: any[] = [];
|
|
1380
|
-
|
|
1381
|
-
export function matchRoute(pathname: string): any {
|
|
1382
|
-
return null;
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
export type RouteParams = Record<string, never>;
|
|
1386
|
-
`, STUB_CONTENT = `// \uD83D\uDEA8 Auto-generated stub by Reroute - DO NOT EDIT \uD83D\uDEA8
|
|
1387
|
-
// Run 'reroute gen' to generate actual content
|
|
1388
|
-
/* eslint-disable */
|
|
1389
|
-
// @ts-nocheck
|
|
1390
|
-
|
|
1391
|
-
export const contentRegistry: Record<string, any> = {};
|
|
1392
|
-
`, STUB_INDEX = `// \uD83D\uDEA8 Auto-generated stub by Reroute - DO NOT EDIT \uD83D\uDEA8
|
|
1393
|
-
// Run 'reroute gen' to generate actual artifacts
|
|
1394
|
-
/* eslint-disable */
|
|
1395
|
-
// @ts-nocheck
|
|
1396
|
-
|
|
1397
|
-
import { layouts, matchRoute, notFoundRoutes } from './routes';
|
|
1398
|
-
|
|
1399
|
-
export const artifacts = {
|
|
1400
|
-
layouts,
|
|
1401
|
-
matchRoute,
|
|
1402
|
-
notFoundRoutes,
|
|
1403
|
-
contentBaseUrl: '/.reroute/collections'
|
|
1404
|
-
} as const;
|
|
1405
|
-
|
|
1406
|
-
export type RerouteArtifacts = typeof artifacts;
|
|
1407
|
-
`;
|
|
1408
|
-
var init_boot = () => {};
|
|
1409
|
-
|
|
1410
1516
|
// packages/cli/src/libs/log.ts
|
|
1411
1517
|
function colorizeLogPrefix(text) {
|
|
1412
1518
|
let colored = text;
|
|
@@ -1447,7 +1553,6 @@ var init_log = __esm(() => {
|
|
|
1447
1553
|
"[reroute/markdown]": "{yellow-fg}",
|
|
1448
1554
|
"[reroute/tailwind]": "{red-fg}",
|
|
1449
1555
|
"[reroute/mdx]": "{bright-red-fg}",
|
|
1450
|
-
"[reroute/boot]": "{bright-yellow-fg}",
|
|
1451
1556
|
"[reroute/dev]": "{green-fg}",
|
|
1452
1557
|
"[reroute/start]": "{bright-cyan-fg}",
|
|
1453
1558
|
"[reroute/build]": "{bright-magenta-fg}",
|
|
@@ -1457,6 +1562,24 @@ var init_log = __esm(() => {
|
|
|
1457
1562
|
};
|
|
1458
1563
|
});
|
|
1459
1564
|
|
|
1565
|
+
// packages/cli/src/libs/server.ts
|
|
1566
|
+
async function waitForServerReady(port = 3000, timeout = 1e4) {
|
|
1567
|
+
const startTime = Date.now();
|
|
1568
|
+
const checkInterval = 200;
|
|
1569
|
+
while (Date.now() - startTime < timeout) {
|
|
1570
|
+
try {
|
|
1571
|
+
const response = await fetch(`http://localhost:${port}/`, {
|
|
1572
|
+
method: "GET"
|
|
1573
|
+
});
|
|
1574
|
+
if (response.status < 500) {
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
} catch {}
|
|
1578
|
+
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
1579
|
+
}
|
|
1580
|
+
throw new Error(`Timeout waiting for server to respond after ${timeout}ms`);
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1460
1583
|
// packages/cli/src/commands/dev.ts
|
|
1461
1584
|
var exports_dev = {};
|
|
1462
1585
|
__export(exports_dev, {
|
|
@@ -1464,19 +1587,65 @@ __export(exports_dev, {
|
|
|
1464
1587
|
});
|
|
1465
1588
|
import { spawn as spawn2 } from "node:child_process";
|
|
1466
1589
|
import { existsSync as existsSync5 } from "node:fs";
|
|
1467
|
-
import { join as
|
|
1590
|
+
import { join as join6 } from "node:path";
|
|
1591
|
+
async function waitForRequiredFiles(cwd, timeout = 30000) {
|
|
1592
|
+
const requiredFiles = [
|
|
1593
|
+
join6(cwd, ".reroute/routes.ts"),
|
|
1594
|
+
join6(cwd, ".reroute/content.ts"),
|
|
1595
|
+
join6(cwd, ".reroute/index.ts")
|
|
1596
|
+
];
|
|
1597
|
+
const bundlesDir = join6(cwd, ".reroute/bundles");
|
|
1598
|
+
const startTime = Date.now();
|
|
1599
|
+
const checkInterval = 100;
|
|
1600
|
+
while (Date.now() - startTime < timeout) {
|
|
1601
|
+
const allFilesExist = requiredFiles.every((file) => existsSync5(file));
|
|
1602
|
+
if (!allFilesExist) {
|
|
1603
|
+
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
1604
|
+
continue;
|
|
1605
|
+
}
|
|
1606
|
+
if (existsSync5(bundlesDir)) {
|
|
1607
|
+
const { readdirSync, statSync } = __require("node:fs");
|
|
1608
|
+
try {
|
|
1609
|
+
const files = readdirSync(bundlesDir);
|
|
1610
|
+
const indexBundleFile = files.find((f) => {
|
|
1611
|
+
if (!f.startsWith("index.") || !f.endsWith(".js") || f.endsWith(".map")) {
|
|
1612
|
+
return false;
|
|
1613
|
+
}
|
|
1614
|
+
try {
|
|
1615
|
+
const filePath = join6(bundlesDir, f);
|
|
1616
|
+
const stats = statSync(filePath);
|
|
1617
|
+
return stats.size > 100;
|
|
1618
|
+
} catch {
|
|
1619
|
+
return false;
|
|
1620
|
+
}
|
|
1621
|
+
});
|
|
1622
|
+
if (indexBundleFile) {
|
|
1623
|
+
const filePath = join6(bundlesDir, indexBundleFile);
|
|
1624
|
+
const size1 = statSync(filePath).size;
|
|
1625
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
1626
|
+
const size2 = statSync(filePath).size;
|
|
1627
|
+
if (size1 === size2 && size2 > 100) {
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
} catch {}
|
|
1632
|
+
}
|
|
1633
|
+
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
1634
|
+
}
|
|
1635
|
+
throw new Error(`Timeout waiting for required files to be created after ${timeout}ms`);
|
|
1636
|
+
}
|
|
1468
1637
|
function getRerouteCommand() {
|
|
1469
|
-
const binPath =
|
|
1638
|
+
const binPath = join6(import.meta.dir, "..", "..", "bin.ts");
|
|
1470
1639
|
const isBunDev = existsSync5(binPath);
|
|
1471
1640
|
if (isBunDev) {
|
|
1472
1641
|
return `bun ${binPath}`;
|
|
1473
1642
|
}
|
|
1474
1643
|
const cwd = process.cwd();
|
|
1475
1644
|
const nodeModulesPaths = [
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1645
|
+
join6(cwd, "node_modules", ".bin", "reroute"),
|
|
1646
|
+
join6(cwd, "..", "node_modules", ".bin", "reroute"),
|
|
1647
|
+
join6(cwd, "..", "..", "node_modules", ".bin", "reroute"),
|
|
1648
|
+
join6(cwd, "..", "..", "..", "node_modules", ".bin", "reroute")
|
|
1480
1649
|
];
|
|
1481
1650
|
for (const binPath2 of nodeModulesPaths) {
|
|
1482
1651
|
if (existsSync5(binPath2)) {
|
|
@@ -1488,10 +1657,6 @@ function getRerouteCommand() {
|
|
|
1488
1657
|
async function dev(args) {
|
|
1489
1658
|
const singleColumn = args.includes("--single") || args.includes("-s");
|
|
1490
1659
|
try {
|
|
1491
|
-
console.log("[reroute/dev] Running boot...");
|
|
1492
|
-
await boot([]);
|
|
1493
|
-
console.log(`[reroute/dev] Boot complete
|
|
1494
|
-
`);
|
|
1495
1660
|
console.log("[reroute/dev] Starting development servers...");
|
|
1496
1661
|
console.log(`[reroute/dev] Press Ctrl+C to stop
|
|
1497
1662
|
`);
|
|
@@ -1503,9 +1668,27 @@ async function dev(args) {
|
|
|
1503
1668
|
stdio: ["ignore", "pipe", "pipe"],
|
|
1504
1669
|
shell: useShell
|
|
1505
1670
|
});
|
|
1671
|
+
console.log("[reroute/dev] Generating bundle...");
|
|
1672
|
+
try {
|
|
1673
|
+
await waitForRequiredFiles(process.cwd());
|
|
1674
|
+
} catch (error) {
|
|
1675
|
+
console.error("[reroute/dev] Failed to initialize:", error);
|
|
1676
|
+
genProcess.kill();
|
|
1677
|
+
process.exit(1);
|
|
1678
|
+
}
|
|
1506
1679
|
const serverProcess = spawn2("bun", ["--watch", "src/index.ts"], {
|
|
1507
1680
|
stdio: ["ignore", "pipe", "pipe"]
|
|
1508
1681
|
});
|
|
1682
|
+
console.log("[reroute/dev] Bundle complete, waiting for server...");
|
|
1683
|
+
const port = Number(process.env.PORT || "3000");
|
|
1684
|
+
try {
|
|
1685
|
+
await waitForServerReady(port);
|
|
1686
|
+
} catch (error) {
|
|
1687
|
+
console.error("[reroute/dev] Server failed to start:", error);
|
|
1688
|
+
genProcess.kill();
|
|
1689
|
+
serverProcess.kill();
|
|
1690
|
+
process.exit(1);
|
|
1691
|
+
}
|
|
1509
1692
|
if (singleColumn) {
|
|
1510
1693
|
const genBuffer = { current: "" };
|
|
1511
1694
|
const serverBuffer = { current: "" };
|
|
@@ -1751,7 +1934,6 @@ async function dev(args) {
|
|
|
1751
1934
|
}
|
|
1752
1935
|
var init_dev = __esm(() => {
|
|
1753
1936
|
init_log();
|
|
1754
|
-
init_boot();
|
|
1755
1937
|
});
|
|
1756
1938
|
|
|
1757
1939
|
// packages/cli/src/commands/start.ts
|
|
@@ -1761,19 +1943,19 @@ __export(exports_start, {
|
|
|
1761
1943
|
});
|
|
1762
1944
|
import { spawn as spawn3 } from "node:child_process";
|
|
1763
1945
|
import { existsSync as existsSync6 } from "node:fs";
|
|
1764
|
-
import { join as
|
|
1946
|
+
import { join as join7 } from "node:path";
|
|
1765
1947
|
function getRerouteCommand2() {
|
|
1766
|
-
const binPath =
|
|
1948
|
+
const binPath = join7(import.meta.dir, "..", "..", "bin.ts");
|
|
1767
1949
|
const isBunDev = existsSync6(binPath);
|
|
1768
1950
|
if (isBunDev) {
|
|
1769
1951
|
return `bun ${binPath}`;
|
|
1770
1952
|
}
|
|
1771
1953
|
const cwd = process.cwd();
|
|
1772
1954
|
const nodeModulesPaths = [
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1955
|
+
join7(cwd, "node_modules", ".bin", "reroute"),
|
|
1956
|
+
join7(cwd, "..", "node_modules", ".bin", "reroute"),
|
|
1957
|
+
join7(cwd, "..", "..", "node_modules", ".bin", "reroute"),
|
|
1958
|
+
join7(cwd, "..", "..", "..", "node_modules", ".bin", "reroute")
|
|
1777
1959
|
];
|
|
1778
1960
|
for (const binPath2 of nodeModulesPaths) {
|
|
1779
1961
|
if (existsSync6(binPath2)) {
|
|
@@ -1786,21 +1968,7 @@ async function start(_args) {
|
|
|
1786
1968
|
try {
|
|
1787
1969
|
const rerouteCmd = getRerouteCommand2();
|
|
1788
1970
|
const useShell = rerouteCmd.includes(" ");
|
|
1789
|
-
const bootBuffer = { current: "" };
|
|
1790
1971
|
const genBuffer = { current: "" };
|
|
1791
|
-
const handleBootOutput = (data) => {
|
|
1792
|
-
const text = bootBuffer.current + data.toString();
|
|
1793
|
-
const lines = text.split(`
|
|
1794
|
-
`);
|
|
1795
|
-
bootBuffer.current = lines.pop() || "";
|
|
1796
|
-
for (const line of lines) {
|
|
1797
|
-
if (!line.trim()) {
|
|
1798
|
-
continue;
|
|
1799
|
-
}
|
|
1800
|
-
const ansiColored = colorizeLogPrefixAnsi(line);
|
|
1801
|
-
console.log(ansiColored);
|
|
1802
|
-
}
|
|
1803
|
-
};
|
|
1804
1972
|
const handleGenOutput = (data) => {
|
|
1805
1973
|
const text = genBuffer.current + data.toString();
|
|
1806
1974
|
const lines = text.split(`
|
|
@@ -1814,34 +1982,10 @@ async function start(_args) {
|
|
|
1814
1982
|
console.log(ansiColored);
|
|
1815
1983
|
}
|
|
1816
1984
|
};
|
|
1817
|
-
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/start] Running boot...")}
|
|
1818
|
-
`);
|
|
1819
|
-
const bootCommand = useShell ? `${rerouteCmd} boot` : rerouteCmd;
|
|
1820
|
-
const bootArgs = useShell ? [] : ["boot"];
|
|
1821
|
-
await new Promise((resolve, reject) => {
|
|
1822
|
-
const bootProcess = spawn3(bootCommand, bootArgs, {
|
|
1823
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
1824
|
-
shell: useShell
|
|
1825
|
-
});
|
|
1826
|
-
bootProcess.stdout?.on("data", handleBootOutput);
|
|
1827
|
-
bootProcess.stderr?.on("data", handleBootOutput);
|
|
1828
|
-
bootProcess.on("exit", (code) => {
|
|
1829
|
-
if (code !== null && code !== 0) {
|
|
1830
|
-
reject(new Error(`Boot exited with code ${code}`));
|
|
1831
|
-
} else {
|
|
1832
|
-
resolve();
|
|
1833
|
-
}
|
|
1834
|
-
});
|
|
1835
|
-
bootProcess.on("error", (error) => {
|
|
1836
|
-
reject(error);
|
|
1837
|
-
});
|
|
1838
|
-
});
|
|
1839
|
-
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/start] Boot complete
|
|
1840
|
-
`));
|
|
1841
1985
|
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/start] Running gen...")}
|
|
1842
1986
|
`);
|
|
1843
|
-
const genCommand = useShell ? `${rerouteCmd} gen` : rerouteCmd;
|
|
1844
|
-
const genArgs = useShell ? [] : ["gen"];
|
|
1987
|
+
const genCommand = useShell ? `${rerouteCmd} gen --prod` : rerouteCmd;
|
|
1988
|
+
const genArgs = useShell ? [] : ["gen", "--prod"];
|
|
1845
1989
|
await new Promise((resolve, reject) => {
|
|
1846
1990
|
const genProcess = spawn3(genCommand, genArgs, {
|
|
1847
1991
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -1864,8 +2008,6 @@ async function start(_args) {
|
|
|
1864
2008
|
`));
|
|
1865
2009
|
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/start] Starting server...")}
|
|
1866
2010
|
`);
|
|
1867
|
-
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/start] Press Ctrl+C to stop
|
|
1868
|
-
`));
|
|
1869
2011
|
const serverProcess = spawn3("bun", ["src/index.ts"], {
|
|
1870
2012
|
stdio: ["ignore", "pipe", "pipe"]
|
|
1871
2013
|
});
|
|
@@ -1873,6 +2015,19 @@ async function start(_args) {
|
|
|
1873
2015
|
const handleServerOutput = createServerOutputHandler(serverBuffer);
|
|
1874
2016
|
serverProcess.stdout?.on("data", handleServerOutput);
|
|
1875
2017
|
serverProcess.stderr?.on("data", handleServerOutput);
|
|
2018
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/start] Waiting for server to be ready...
|
|
2019
|
+
`));
|
|
2020
|
+
const port = Number(process.env.PORT || "3000");
|
|
2021
|
+
try {
|
|
2022
|
+
await waitForServerReady(port, 1e4);
|
|
2023
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/start] Server is ready!
|
|
2024
|
+
`));
|
|
2025
|
+
} catch {
|
|
2026
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/start] \uD83D\uDEA8Warning: Server may not be fully ready yet
|
|
2027
|
+
`));
|
|
2028
|
+
}
|
|
2029
|
+
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/start] Press Ctrl+C to stop
|
|
2030
|
+
`));
|
|
1876
2031
|
process.on("SIGINT", () => {
|
|
1877
2032
|
process.stdout.write(`${colorizeLogPrefixAnsi(`
|
|
1878
2033
|
[reroute/start] Shutting down...`)}
|
|
@@ -1916,19 +2071,19 @@ __export(exports_build, {
|
|
|
1916
2071
|
});
|
|
1917
2072
|
import { spawn as spawn4 } from "node:child_process";
|
|
1918
2073
|
import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
|
|
1919
|
-
import { join as
|
|
2074
|
+
import { join as join8 } from "node:path";
|
|
1920
2075
|
function getRerouteCommand3() {
|
|
1921
|
-
const binPath =
|
|
2076
|
+
const binPath = join8(import.meta.dir, "..", "..", "bin.ts");
|
|
1922
2077
|
const isBunDev = existsSync7(binPath);
|
|
1923
2078
|
if (isBunDev) {
|
|
1924
2079
|
return `bun ${binPath}`;
|
|
1925
2080
|
}
|
|
1926
2081
|
const cwd = process.cwd();
|
|
1927
2082
|
const nodeModulesPaths = [
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
2083
|
+
join8(cwd, "node_modules", ".bin", "reroute"),
|
|
2084
|
+
join8(cwd, "..", "node_modules", ".bin", "reroute"),
|
|
2085
|
+
join8(cwd, "..", "..", "node_modules", ".bin", "reroute"),
|
|
2086
|
+
join8(cwd, "..", "..", "..", "node_modules", ".bin", "reroute")
|
|
1932
2087
|
];
|
|
1933
2088
|
for (const binPath2 of nodeModulesPaths) {
|
|
1934
2089
|
if (existsSync7(binPath2)) {
|
|
@@ -1939,7 +2094,7 @@ function getRerouteCommand3() {
|
|
|
1939
2094
|
}
|
|
1940
2095
|
function getOutputName() {
|
|
1941
2096
|
const cwd = process.cwd();
|
|
1942
|
-
const packageJsonPath =
|
|
2097
|
+
const packageJsonPath = join8(cwd, "package.json");
|
|
1943
2098
|
if (existsSync7(packageJsonPath)) {
|
|
1944
2099
|
try {
|
|
1945
2100
|
const packageJson = JSON.parse(readFileSync4(packageJsonPath, "utf-8"));
|
|
@@ -1966,21 +2121,7 @@ async function build(args) {
|
|
|
1966
2121
|
if (outfileArgIndex !== -1 && args[outfileArgIndex + 1]) {
|
|
1967
2122
|
outputPath = args[outfileArgIndex + 1];
|
|
1968
2123
|
}
|
|
1969
|
-
const bootBuffer = { current: "" };
|
|
1970
2124
|
const genBuffer = { current: "" };
|
|
1971
|
-
const handleBootOutput = (data) => {
|
|
1972
|
-
const text = bootBuffer.current + data.toString();
|
|
1973
|
-
const lines = text.split(`
|
|
1974
|
-
`);
|
|
1975
|
-
bootBuffer.current = lines.pop() || "";
|
|
1976
|
-
for (const line of lines) {
|
|
1977
|
-
if (!line.trim()) {
|
|
1978
|
-
continue;
|
|
1979
|
-
}
|
|
1980
|
-
const ansiColored = colorizeLogPrefixAnsi(line);
|
|
1981
|
-
console.log(ansiColored);
|
|
1982
|
-
}
|
|
1983
|
-
};
|
|
1984
2125
|
const handleGenOutput = (data) => {
|
|
1985
2126
|
const text = genBuffer.current + data.toString();
|
|
1986
2127
|
const lines = text.split(`
|
|
@@ -1994,34 +2135,10 @@ async function build(args) {
|
|
|
1994
2135
|
console.log(ansiColored);
|
|
1995
2136
|
}
|
|
1996
2137
|
};
|
|
1997
|
-
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/build] Running
|
|
2138
|
+
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/build] Running gen --prod...")}
|
|
1998
2139
|
`);
|
|
1999
|
-
const
|
|
2000
|
-
const
|
|
2001
|
-
await new Promise((resolve, reject) => {
|
|
2002
|
-
const bootProcess = spawn4(bootCommand, bootArgs, {
|
|
2003
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
2004
|
-
shell: useShell
|
|
2005
|
-
});
|
|
2006
|
-
bootProcess.stdout?.on("data", handleBootOutput);
|
|
2007
|
-
bootProcess.stderr?.on("data", handleBootOutput);
|
|
2008
|
-
bootProcess.on("exit", (code) => {
|
|
2009
|
-
if (code !== null && code !== 0) {
|
|
2010
|
-
reject(new Error(`Boot exited with code ${code}`));
|
|
2011
|
-
} else {
|
|
2012
|
-
resolve();
|
|
2013
|
-
}
|
|
2014
|
-
});
|
|
2015
|
-
bootProcess.on("error", (error) => {
|
|
2016
|
-
reject(error);
|
|
2017
|
-
});
|
|
2018
|
-
});
|
|
2019
|
-
process.stdout.write(colorizeLogPrefixAnsi(`[reroute/build] Boot complete
|
|
2020
|
-
`));
|
|
2021
|
-
process.stdout.write(`${colorizeLogPrefixAnsi("[reroute/build] Running gen...")}
|
|
2022
|
-
`);
|
|
2023
|
-
const genCommand = useShell ? `${rerouteCmd} gen` : rerouteCmd;
|
|
2024
|
-
const genArgs = useShell ? [] : ["gen"];
|
|
2140
|
+
const genCommand = useShell ? `${rerouteCmd} gen --prod` : rerouteCmd;
|
|
2141
|
+
const genArgs = useShell ? [] : ["gen", "--prod"];
|
|
2025
2142
|
await new Promise((resolve, reject) => {
|
|
2026
2143
|
const genProcess = spawn4(genCommand, genArgs, {
|
|
2027
2144
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -2095,59 +2212,11 @@ async function generateContentHash(content) {
|
|
|
2095
2212
|
return hex.slice(0, 8);
|
|
2096
2213
|
}
|
|
2097
2214
|
|
|
2098
|
-
// packages/
|
|
2099
|
-
var
|
|
2100
|
-
__export(exports_command, {
|
|
2101
|
-
getRerouteCommand: () => getRerouteCommand4
|
|
2102
|
-
});
|
|
2103
|
-
import { existsSync as existsSync8 } from "node:fs";
|
|
2104
|
-
import { join as join10 } from "node:path";
|
|
2105
|
-
function getRerouteCommand4() {
|
|
2106
|
-
const binPath = join10(import.meta.dir, "..", "..", "bin.ts");
|
|
2107
|
-
const isBunDev = existsSync8(binPath);
|
|
2108
|
-
if (isBunDev) {
|
|
2109
|
-
return `bun ${binPath}`;
|
|
2110
|
-
}
|
|
2111
|
-
const cwd = process.cwd();
|
|
2112
|
-
const nodeModulesPaths = [
|
|
2113
|
-
join10(cwd, "node_modules", ".bin", "reroute"),
|
|
2114
|
-
join10(cwd, "..", "node_modules", ".bin", "reroute"),
|
|
2115
|
-
join10(cwd, "..", "..", "node_modules", ".bin", "reroute"),
|
|
2116
|
-
join10(cwd, "..", "..", "..", "node_modules", ".bin", "reroute")
|
|
2117
|
-
];
|
|
2118
|
-
for (const binPath2 of nodeModulesPaths) {
|
|
2119
|
-
if (existsSync8(binPath2)) {
|
|
2120
|
-
return binPath2;
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
return "reroute";
|
|
2124
|
-
}
|
|
2125
|
-
var init_command = () => {};
|
|
2126
|
-
|
|
2127
|
-
// packages/cli/src/libs/index.ts
|
|
2128
|
-
var init_libs = __esm(() => {
|
|
2129
|
-
init_command();
|
|
2130
|
-
init_log();
|
|
2131
|
-
init_markdown();
|
|
2132
|
-
init_markdown_processor();
|
|
2133
|
-
init_tailwind();
|
|
2134
|
-
});
|
|
2135
|
-
|
|
2136
|
-
// packages/cli/index.ts
|
|
2137
|
-
var init_cli = __esm(() => {
|
|
2138
|
-
init_libs();
|
|
2139
|
-
});
|
|
2215
|
+
// packages/core/src/bundler/index.ts
|
|
2216
|
+
var init_bundler = () => {};
|
|
2140
2217
|
|
|
2141
2218
|
// packages/core/src/utils/path.ts
|
|
2142
|
-
|
|
2143
|
-
__export(exports_path, {
|
|
2144
|
-
stripStart: () => stripStart,
|
|
2145
|
-
stripEnd: () => stripEnd,
|
|
2146
|
-
join: () => join11,
|
|
2147
|
-
extname: () => extname2,
|
|
2148
|
-
basename: () => basename2
|
|
2149
|
-
});
|
|
2150
|
-
function join11(...parts) {
|
|
2219
|
+
function join9(...parts) {
|
|
2151
2220
|
return parts.join("/").replace(/\/+/g, "/");
|
|
2152
2221
|
}
|
|
2153
2222
|
function extname2(p) {
|
|
@@ -2165,178 +2234,60 @@ function stripEnd(p, ch) {
|
|
|
2165
2234
|
return p.endsWith(ch) ? p.slice(0, -ch.length) : p;
|
|
2166
2235
|
}
|
|
2167
2236
|
|
|
2168
|
-
// packages/core/src/
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
} catch {
|
|
2173
|
-
return false;
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
async function transpileFile(filePath, originalPath, options, bundleCache) {
|
|
2177
|
-
const src = await Bun.file(filePath).text();
|
|
2178
|
-
const cacheKey = `${filePath}-${await generateContentHash(src)}`;
|
|
2179
|
-
if (bundleCache.has(cacheKey)) {
|
|
2180
|
-
return bundleCache.get(cacheKey);
|
|
2181
|
-
}
|
|
2182
|
-
console.log(`[reroute] Building ${originalPath}${options.minify ? " (minified)" : ""}...`);
|
|
2237
|
+
// packages/core/src/content/discovery.ts
|
|
2238
|
+
import { readdir as readdir3, stat } from "node:fs/promises";
|
|
2239
|
+
async function listContentFiles2(dir, baseRel) {
|
|
2240
|
+
const out = [];
|
|
2183
2241
|
try {
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2242
|
+
const entries = await readdir3(dir, { withFileTypes: true });
|
|
2243
|
+
for (const entry of entries) {
|
|
2244
|
+
const full = join9(dir, entry.name);
|
|
2245
|
+
const rel = join9(baseRel, entry.name);
|
|
2246
|
+
if (entry.isDirectory()) {
|
|
2247
|
+
const nested = await listContentFiles2(full, rel);
|
|
2248
|
+
out.push(...nested);
|
|
2249
|
+
} else if (entry.isFile()) {
|
|
2250
|
+
if (/\.(tsx|ts)$/.test(entry.name) && !entry.name.startsWith("_")) {
|
|
2251
|
+
out.push(rel);
|
|
2252
|
+
}
|
|
2188
2253
|
}
|
|
2189
2254
|
}
|
|
2190
|
-
} catch
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
target: "browser",
|
|
2197
|
-
format: "esm",
|
|
2198
|
-
minify: options.minify,
|
|
2199
|
-
splitting: true,
|
|
2200
|
-
sourcemap: sm,
|
|
2201
|
-
jsx: {
|
|
2202
|
-
runtime: "automatic",
|
|
2203
|
-
importSource: "react",
|
|
2204
|
-
development: !options.minify
|
|
2205
|
-
},
|
|
2206
|
-
define: {
|
|
2207
|
-
"process.env.NODE_ENV": options.minify ? '"production"' : '"development"',
|
|
2208
|
-
__DEV__: options.minify ? "false" : "true",
|
|
2209
|
-
"import.meta.env.MODE": options.minify ? '"production"' : '"development"'
|
|
2210
|
-
},
|
|
2211
|
-
...options.minify ? { drop: ["console", "debugger"] } : {}
|
|
2212
|
-
});
|
|
2213
|
-
}
|
|
2214
|
-
let result;
|
|
2255
|
+
} catch {}
|
|
2256
|
+
return out;
|
|
2257
|
+
}
|
|
2258
|
+
async function discoverCollections(clientDir) {
|
|
2259
|
+
const root = join9(clientDir, "routes");
|
|
2260
|
+
const collections = new Set;
|
|
2215
2261
|
try {
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
console.error(log2);
|
|
2225
|
-
throw new Error(`Failed to transpile ${filePath}`);
|
|
2226
|
-
}
|
|
2227
|
-
const outputs = await Promise.all(result.outputs.map(async (o) => ({
|
|
2228
|
-
path: o.path,
|
|
2229
|
-
text: await o.text()
|
|
2230
|
-
})));
|
|
2231
|
-
const entryBase = basename2(originalPath, extname2(originalPath));
|
|
2232
|
-
let entry = outputs.find((o) => o.path.endsWith(`${entryBase}.js`));
|
|
2233
|
-
if (!entry) {
|
|
2234
|
-
entry = outputs.filter((o) => o.path.endsWith(".js")).sort((a, b) => b.text.length - a.text.length)[0];
|
|
2235
|
-
}
|
|
2236
|
-
if (!entry) {
|
|
2237
|
-
throw new Error(`[reroute] No JS output generated for ${originalPath}`);
|
|
2238
|
-
}
|
|
2239
|
-
const code = entry.text;
|
|
2240
|
-
let sourceMap;
|
|
2241
|
-
if (options.sourcemap && result.outputs.length > 1) {
|
|
2242
|
-
const mapOutput = result.outputs.find((o) => o.path.endsWith(".map"));
|
|
2243
|
-
if (mapOutput) {
|
|
2244
|
-
sourceMap = await mapOutput.text();
|
|
2245
|
-
}
|
|
2246
|
-
}
|
|
2247
|
-
const contentHash = await generateContentHash(code);
|
|
2248
|
-
const chunks = outputs.filter((o) => o !== entry && o.path.endsWith(".js")).map((o) => ({
|
|
2249
|
-
fileName: basename2(o.path),
|
|
2250
|
-
code: o.text,
|
|
2251
|
-
hash: "",
|
|
2252
|
-
isEntry: false,
|
|
2253
|
-
imports: []
|
|
2254
|
-
}));
|
|
2255
|
-
for (const c of chunks) {
|
|
2256
|
-
c.hash = await generateContentHash(c.code);
|
|
2257
|
-
try {
|
|
2258
|
-
const bn = c.fileName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2259
|
-
const re = new RegExp(`["'\`]((?:\\./)?${bn})["'\`]`, "g");
|
|
2260
|
-
const matches = [...code.matchAll(re)];
|
|
2261
|
-
if (matches.length) {
|
|
2262
|
-
c.isEntry = false;
|
|
2262
|
+
const entries = await readdir3(root, { withFileTypes: true });
|
|
2263
|
+
for (const entry of entries) {
|
|
2264
|
+
if (entry.isDirectory()) {
|
|
2265
|
+
const contentDir = join9(root, entry.name, "content");
|
|
2266
|
+
try {
|
|
2267
|
+
await stat(contentDir);
|
|
2268
|
+
collections.add(entry.name);
|
|
2269
|
+
} catch {}
|
|
2263
2270
|
}
|
|
2264
|
-
} catch {}
|
|
2265
|
-
}
|
|
2266
|
-
const staticDepNames = [];
|
|
2267
|
-
try {
|
|
2268
|
-
for (const c of chunks) {
|
|
2269
|
-
const bn = c.fileName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2270
|
-
const re = new RegExp(`["'\`]((?:\\./)?${bn})["'\`]`, "g");
|
|
2271
|
-
if (re.test(code))
|
|
2272
|
-
staticDepNames.push(c.fileName);
|
|
2273
2271
|
}
|
|
2274
2272
|
} catch {}
|
|
2275
|
-
|
|
2276
|
-
hash: contentHash,
|
|
2277
|
-
code,
|
|
2278
|
-
sourceMap,
|
|
2279
|
-
chunks
|
|
2280
|
-
};
|
|
2281
|
-
bundleCache.set(cacheKey, bundleInfo);
|
|
2282
|
-
const sizeKB = (code.length / 1024).toFixed(2);
|
|
2283
|
-
const gzippedSize = Bun.gzipSync(new TextEncoder().encode(code)).length;
|
|
2284
|
-
const gzippedKB = (gzippedSize / 1024).toFixed(2);
|
|
2285
|
-
console.log(`[reroute] Built ${originalPath} -> ${sizeKB} KB (${gzippedKB} KB gzipped)`);
|
|
2286
|
-
return bundleInfo;
|
|
2287
|
-
}
|
|
2288
|
-
async function getBundleUrlsFor(modules, clientDir, prefix, options, bundleCache) {
|
|
2289
|
-
const mods = Array.isArray(modules) ? modules : [modules];
|
|
2290
|
-
const urls = [];
|
|
2291
|
-
const { join: join12 } = await Promise.resolve().then(() => exports_path);
|
|
2292
|
-
for (const mod of mods) {
|
|
2293
|
-
const rel = mod.replace(/^\.\//, "");
|
|
2294
|
-
const fullPath = join12(clientDir, rel);
|
|
2295
|
-
try {
|
|
2296
|
-
const bundleInfo = await transpileFile(fullPath, rel, options, bundleCache);
|
|
2297
|
-
const base = basename2(rel, extname2(rel));
|
|
2298
|
-
const entryUrl = `${prefix}/${base}.${bundleInfo.hash}.js`;
|
|
2299
|
-
urls.push(entryUrl);
|
|
2300
|
-
try {
|
|
2301
|
-
const depNames = Array.isArray(bundleInfo.chunks) ? bundleInfo.chunks.map((c) => c.fileName).filter((name) => new RegExp(`["'\`]((?:\\./)?${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["'\`]`, "g").test(bundleInfo.code)) : [];
|
|
2302
|
-
const depUrls = depNames.map((n) => `${prefix}/${n}`.replace(/\/+/g, "/"));
|
|
2303
|
-
entryUrlToStaticDeps.set(entryUrl, depUrls);
|
|
2304
|
-
} catch {}
|
|
2305
|
-
} catch (error) {
|
|
2306
|
-
console.error(`[reroute] Error getting bundle URL for ${rel}:`, error);
|
|
2307
|
-
urls.push(`${prefix}/${rel}`);
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
return urls;
|
|
2311
|
-
}
|
|
2312
|
-
function getStaticDepsForUrl(entryUrl) {
|
|
2313
|
-
return entryUrlToStaticDeps.get(entryUrl) || [];
|
|
2273
|
+
return Array.from(collections);
|
|
2314
2274
|
}
|
|
2315
|
-
var
|
|
2316
|
-
var init_transpile = __esm(() => {
|
|
2317
|
-
init_cli();
|
|
2318
|
-
entryUrlToStaticDeps = new Map;
|
|
2319
|
-
});
|
|
2320
|
-
|
|
2321
|
-
// packages/core/src/bundler/index.ts
|
|
2322
|
-
var init_bundler = __esm(() => {
|
|
2323
|
-
init_transpile();
|
|
2324
|
-
});
|
|
2275
|
+
var init_discovery = () => {};
|
|
2325
2276
|
|
|
2326
2277
|
// packages/core/src/content/metadata.ts
|
|
2327
|
-
import { stat } from "node:fs/promises";
|
|
2278
|
+
import { stat as stat2 } from "node:fs/promises";
|
|
2328
2279
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
2329
|
-
async function getContentMeta(absPath,
|
|
2280
|
+
async function getContentMeta(absPath, isWatchMode) {
|
|
2330
2281
|
try {
|
|
2331
2282
|
const url = pathToFileURL2(absPath).href;
|
|
2332
|
-
const mod = await import(`${url}${
|
|
2283
|
+
const mod = await import(`${url}${isWatchMode ? `?t=${Date.now()}` : ""}`);
|
|
2333
2284
|
const meta = mod.meta || mod.frontmatter || {};
|
|
2334
2285
|
if (meta && typeof meta === "object")
|
|
2335
2286
|
return meta;
|
|
2336
2287
|
return {};
|
|
2337
2288
|
} catch {
|
|
2338
2289
|
try {
|
|
2339
|
-
const s = await
|
|
2290
|
+
const s = await stat2(absPath);
|
|
2340
2291
|
return { date: new Date(s.mtimeMs).toISOString() };
|
|
2341
2292
|
} catch {
|
|
2342
2293
|
return {};
|
|
@@ -2362,94 +2313,16 @@ function escapeHtml(input) {
|
|
|
2362
2313
|
}
|
|
2363
2314
|
var init_metadata = () => {};
|
|
2364
2315
|
|
|
2365
|
-
// packages/core/src/content/discovery.ts
|
|
2366
|
-
import { readdir as readdir3, stat as stat2 } from "node:fs/promises";
|
|
2367
|
-
async function listContentFiles2(dir, baseRel) {
|
|
2368
|
-
const out = [];
|
|
2369
|
-
try {
|
|
2370
|
-
const entries = await readdir3(dir, { withFileTypes: true });
|
|
2371
|
-
for (const entry of entries) {
|
|
2372
|
-
const full = join11(dir, entry.name);
|
|
2373
|
-
const rel = join11(baseRel, entry.name);
|
|
2374
|
-
if (entry.isDirectory()) {
|
|
2375
|
-
const nested = await listContentFiles2(full, rel);
|
|
2376
|
-
out.push(...nested);
|
|
2377
|
-
} else if (entry.isFile()) {
|
|
2378
|
-
if (/\.(tsx|ts)$/.test(entry.name) && !entry.name.startsWith("_")) {
|
|
2379
|
-
out.push(rel);
|
|
2380
|
-
}
|
|
2381
|
-
}
|
|
2382
|
-
}
|
|
2383
|
-
} catch {}
|
|
2384
|
-
return out;
|
|
2385
|
-
}
|
|
2386
|
-
async function buildContentDTOs(collectionPath, clientDir, prefix, isWatchMode2) {
|
|
2387
|
-
const normalized = stripStart(stripEnd(collectionPath, "/"), "/");
|
|
2388
|
-
const contentRelDir = join11("routes", normalized, "content");
|
|
2389
|
-
const contentAbsDir = join11(clientDir, contentRelDir);
|
|
2390
|
-
const files = await listContentFiles2(contentAbsDir, "");
|
|
2391
|
-
const items = [];
|
|
2392
|
-
for (const rel of files) {
|
|
2393
|
-
const fullRelPath = join11(contentRelDir, rel);
|
|
2394
|
-
const absPath = join11(clientDir, fullRelPath);
|
|
2395
|
-
const noExt = rel.replace(/\.(tsx|ts)$/, "");
|
|
2396
|
-
const name = basename2(noExt);
|
|
2397
|
-
const moduleUrl = `${prefix}/${fullRelPath}`.replace(/\/+/g, "/");
|
|
2398
|
-
const meta = await getContentMeta(absPath, isWatchMode2);
|
|
2399
|
-
const href = `/${normalized}/${name}`.replace(/\\+/g, "/");
|
|
2400
|
-
items.push({
|
|
2401
|
-
slug: noExt,
|
|
2402
|
-
name,
|
|
2403
|
-
path: fullRelPath,
|
|
2404
|
-
module: moduleUrl,
|
|
2405
|
-
meta,
|
|
2406
|
-
href
|
|
2407
|
-
});
|
|
2408
|
-
}
|
|
2409
|
-
return items;
|
|
2410
|
-
}
|
|
2411
|
-
async function discoverCollections(clientDir) {
|
|
2412
|
-
const root = join11(clientDir, "routes");
|
|
2413
|
-
const collections = new Set;
|
|
2414
|
-
try {
|
|
2415
|
-
const entries = await readdir3(root, { withFileTypes: true });
|
|
2416
|
-
for (const entry of entries) {
|
|
2417
|
-
if (entry.isDirectory()) {
|
|
2418
|
-
const contentDir = join11(root, entry.name, "content");
|
|
2419
|
-
try {
|
|
2420
|
-
await stat2(contentDir);
|
|
2421
|
-
collections.add(entry.name);
|
|
2422
|
-
} catch {}
|
|
2423
|
-
}
|
|
2424
|
-
}
|
|
2425
|
-
} catch {}
|
|
2426
|
-
return Array.from(collections);
|
|
2427
|
-
}
|
|
2428
|
-
var init_discovery = __esm(() => {
|
|
2429
|
-
init_metadata();
|
|
2430
|
-
});
|
|
2431
|
-
|
|
2432
|
-
// packages/core/src/content/registry.ts
|
|
2433
|
-
async function generateContentRegistry(cwd) {
|
|
2434
|
-
try {
|
|
2435
|
-
const p = join11(cwd, ".reroute", "content.ts");
|
|
2436
|
-
const exists = await Bun.file(p).exists();
|
|
2437
|
-
console.log(exists ? "[reroute] Content registry up-to-date" : "[reroute] Warning: .reroute/content.ts not found");
|
|
2438
|
-
} catch {}
|
|
2439
|
-
}
|
|
2440
|
-
var init_registry = () => {};
|
|
2441
|
-
|
|
2442
2316
|
// packages/core/src/content/index.ts
|
|
2443
2317
|
var init_content = __esm(() => {
|
|
2444
2318
|
init_discovery();
|
|
2445
2319
|
init_metadata();
|
|
2446
|
-
init_registry();
|
|
2447
2320
|
});
|
|
2448
2321
|
|
|
2449
2322
|
// packages/core/src/ssr/modules.ts
|
|
2450
2323
|
import { readdir as readdir4, stat as stat3 } from "node:fs/promises";
|
|
2451
2324
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
2452
|
-
async function importContentModuleForPath(pathname, clientDir, cwd,
|
|
2325
|
+
async function importContentModuleForPath(pathname, clientDir, cwd, isWatchMode) {
|
|
2453
2326
|
try {
|
|
2454
2327
|
const parts = pathname.split("/").filter(Boolean);
|
|
2455
2328
|
if (parts.length < 2)
|
|
@@ -2457,20 +2330,20 @@ async function importContentModuleForPath(pathname, clientDir, cwd, isWatchMode2
|
|
|
2457
2330
|
const collection = parts[0];
|
|
2458
2331
|
const name = parts[1];
|
|
2459
2332
|
try {
|
|
2460
|
-
const registryPath =
|
|
2461
|
-
const reg = await import(pathToFileURL3(registryPath).href + (
|
|
2333
|
+
const registryPath = join9(cwd, ".reroute", "content.ts");
|
|
2334
|
+
const reg = await import(pathToFileURL3(registryPath).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
2462
2335
|
const get = reg?.getContentEntry;
|
|
2463
2336
|
const entry = typeof get === "function" ? get(collection, name) : undefined;
|
|
2464
2337
|
const moduleUrl = entry?.module;
|
|
2465
2338
|
if (moduleUrl?.endsWith(".js")) {
|
|
2466
|
-
const abs =
|
|
2467
|
-
const href = pathToFileURL3(abs).href + (
|
|
2339
|
+
const abs = join9(cwd, moduleUrl.replace(/^\//, ""));
|
|
2340
|
+
const href = pathToFileURL3(abs).href + (isWatchMode ? `?t=${Date.now()}` : "");
|
|
2468
2341
|
const mod = await import(href);
|
|
2469
2342
|
return mod;
|
|
2470
2343
|
}
|
|
2471
2344
|
} catch {}
|
|
2472
2345
|
try {
|
|
2473
|
-
const chunkDir =
|
|
2346
|
+
const chunkDir = join9(cwd, ".reroute", "chunks", collection);
|
|
2474
2347
|
const files = await readdir4(chunkDir);
|
|
2475
2348
|
const matches = files.filter((n) => n.startsWith(`${name}.`) && n.endsWith(".js"));
|
|
2476
2349
|
if (matches.length) {
|
|
@@ -2478,22 +2351,22 @@ async function importContentModuleForPath(pathname, clientDir, cwd, isWatchMode2
|
|
|
2478
2351
|
let latestM = 0;
|
|
2479
2352
|
for (const f of matches) {
|
|
2480
2353
|
try {
|
|
2481
|
-
const s = await stat3(
|
|
2354
|
+
const s = await stat3(join9(chunkDir, f));
|
|
2482
2355
|
if (s.mtimeMs >= latestM) {
|
|
2483
2356
|
latestM = s.mtimeMs;
|
|
2484
2357
|
latest = f;
|
|
2485
2358
|
}
|
|
2486
2359
|
} catch {}
|
|
2487
2360
|
}
|
|
2488
|
-
const absChunk =
|
|
2489
|
-
const href = pathToFileURL3(absChunk).href + (
|
|
2361
|
+
const absChunk = join9(chunkDir, latest);
|
|
2362
|
+
const href = pathToFileURL3(absChunk).href + (isWatchMode ? `?t=${Date.now()}` : "");
|
|
2490
2363
|
const mod = await import(href);
|
|
2491
2364
|
return mod;
|
|
2492
2365
|
}
|
|
2493
2366
|
} catch {}
|
|
2494
2367
|
try {
|
|
2495
|
-
const srcTsx =
|
|
2496
|
-
const srcTs =
|
|
2368
|
+
const srcTsx = join9(clientDir, "routes", collection, "content", `${name}.tsx`);
|
|
2369
|
+
const srcTs = join9(clientDir, "routes", collection, "content", `${name}.ts`);
|
|
2497
2370
|
let absSrc = null;
|
|
2498
2371
|
if (await Bun.file(srcTsx).exists())
|
|
2499
2372
|
absSrc = srcTsx;
|
|
@@ -2501,7 +2374,7 @@ async function importContentModuleForPath(pathname, clientDir, cwd, isWatchMode2
|
|
|
2501
2374
|
absSrc = srcTs;
|
|
2502
2375
|
if (absSrc) {
|
|
2503
2376
|
const href = pathToFileURL3(absSrc).href;
|
|
2504
|
-
const mod = await (
|
|
2377
|
+
const mod = await (isWatchMode ? import(`${href}?t=${Date.now()}`) : import(href));
|
|
2505
2378
|
return mod;
|
|
2506
2379
|
}
|
|
2507
2380
|
} catch {}
|
|
@@ -2511,7 +2384,7 @@ async function importContentModuleForPath(pathname, clientDir, cwd, isWatchMode2
|
|
|
2511
2384
|
var init_modules = () => {};
|
|
2512
2385
|
|
|
2513
2386
|
// packages/core/src/ssr/seed.ts
|
|
2514
|
-
async function seedSSRModuleForPath(pathname, clientDir, cwd,
|
|
2387
|
+
async function seedSSRModuleForPath(pathname, clientDir, cwd, isWatchMode) {
|
|
2515
2388
|
try {
|
|
2516
2389
|
const parts = pathname.split("/").filter(Boolean);
|
|
2517
2390
|
if (parts.length < 2)
|
|
@@ -2519,7 +2392,7 @@ async function seedSSRModuleForPath(pathname, clientDir, cwd, isWatchMode2) {
|
|
|
2519
2392
|
const collection = parts[0];
|
|
2520
2393
|
const name = parts[1];
|
|
2521
2394
|
const key = `${collection}:${name}`;
|
|
2522
|
-
const mod = await importContentModuleForPath(pathname, clientDir, cwd,
|
|
2395
|
+
const mod = await importContentModuleForPath(pathname, clientDir, cwd, isWatchMode);
|
|
2523
2396
|
if (!mod)
|
|
2524
2397
|
return;
|
|
2525
2398
|
const C = mod.default || mod;
|
|
@@ -2543,9 +2416,9 @@ var init_seed = __esm(() => {
|
|
|
2543
2416
|
// packages/core/src/ssr/data.ts
|
|
2544
2417
|
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
2545
2418
|
async function computeSSRDataForPath(params) {
|
|
2546
|
-
const { pathname, clientDir, cwd, isWatchMode
|
|
2419
|
+
const { pathname, clientDir, cwd, isWatchMode } = params;
|
|
2547
2420
|
try {
|
|
2548
|
-
await seedSSRModuleForPath(pathname, clientDir, cwd,
|
|
2421
|
+
await seedSSRModuleForPath(pathname, clientDir, cwd, isWatchMode);
|
|
2549
2422
|
} catch {}
|
|
2550
2423
|
try {
|
|
2551
2424
|
const parts = pathname.split("/").filter(Boolean);
|
|
@@ -2560,15 +2433,15 @@ async function computeSSRDataForPath(params) {
|
|
|
2560
2433
|
}
|
|
2561
2434
|
} catch {}
|
|
2562
2435
|
try {
|
|
2563
|
-
const routesPath =
|
|
2564
|
-
const m = await import(pathToFileURL4(routesPath).href + (
|
|
2436
|
+
const routesPath = join9(cwd, ".reroute", "routes.ts");
|
|
2437
|
+
const m = await import(pathToFileURL4(routesPath).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
2565
2438
|
const match = typeof m.matchRoute === "function" ? m.matchRoute(pathname) : null;
|
|
2566
2439
|
const r = match?.route;
|
|
2567
2440
|
const paramsValue = match?.params || {};
|
|
2568
2441
|
if (r && typeof r.path === "string") {
|
|
2569
2442
|
try {
|
|
2570
|
-
const abs =
|
|
2571
|
-
const mod = await import(pathToFileURL4(abs).href + (
|
|
2443
|
+
const abs = join9(clientDir, "routes", String(r.path));
|
|
2444
|
+
const mod = await import(pathToFileURL4(abs).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
2572
2445
|
const ssr = mod?.ssr;
|
|
2573
2446
|
const dataFn = ssr?.data;
|
|
2574
2447
|
if (typeof dataFn === "function") {
|
|
@@ -2583,7 +2456,7 @@ var init_data = __esm(() => {
|
|
|
2583
2456
|
init_seed();
|
|
2584
2457
|
});
|
|
2585
2458
|
|
|
2586
|
-
// node_modules/dedent/dist/dedent.mjs
|
|
2459
|
+
// node_modules/.bun/dedent@1.7.0/node_modules/dedent/dist/dedent.mjs
|
|
2587
2460
|
function ownKeys(object, enumerableOnly) {
|
|
2588
2461
|
var keys = Object.keys(object);
|
|
2589
2462
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -2704,7 +2577,7 @@ var init_dedent = __esm(() => {
|
|
|
2704
2577
|
|
|
2705
2578
|
// packages/core/src/template/html.ts
|
|
2706
2579
|
async function loadIndexHtml(clientDir) {
|
|
2707
|
-
const templatePath =
|
|
2580
|
+
const templatePath = join9(clientDir, "index.html");
|
|
2708
2581
|
try {
|
|
2709
2582
|
const content = await Bun.file(templatePath).text();
|
|
2710
2583
|
return content;
|
|
@@ -2792,7 +2665,7 @@ async function renderSSRDocument(options) {
|
|
|
2792
2665
|
rootComponent,
|
|
2793
2666
|
clientDir,
|
|
2794
2667
|
cwd,
|
|
2795
|
-
isWatchMode
|
|
2668
|
+
isWatchMode,
|
|
2796
2669
|
bundleUrl,
|
|
2797
2670
|
head = "",
|
|
2798
2671
|
lang = "en",
|
|
@@ -2808,15 +2681,6 @@ async function renderSSRDocument(options) {
|
|
|
2808
2681
|
<link rel="modulepreload" href="${bundleUrl}" />`;
|
|
2809
2682
|
}
|
|
2810
2683
|
} catch {}
|
|
2811
|
-
try {
|
|
2812
|
-
const staticDeps = getStaticDepsForUrl(bundleUrl);
|
|
2813
|
-
if (Array.isArray(staticDeps) && staticDeps.length) {
|
|
2814
|
-
for (const dep of staticDeps) {
|
|
2815
|
-
extraHead += `
|
|
2816
|
-
<link rel="modulepreload" href="${dep}" />`;
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
} catch {}
|
|
2820
2684
|
let statusOverride;
|
|
2821
2685
|
try {
|
|
2822
2686
|
globalThis.__REROUTE_SSR_ACCESSED__ = {};
|
|
@@ -2829,7 +2693,7 @@ async function renderSSRDocument(options) {
|
|
|
2829
2693
|
let modulePath = "";
|
|
2830
2694
|
let isContentCollection = false;
|
|
2831
2695
|
try {
|
|
2832
|
-
const maybeDir =
|
|
2696
|
+
const maybeDir = join9(clientDir, "routes", collection, "content");
|
|
2833
2697
|
const s = await stat4(maybeDir);
|
|
2834
2698
|
isContentCollection = typeof s?.isDirectory === "function" ? s.isDirectory() : true;
|
|
2835
2699
|
} catch {
|
|
@@ -2839,8 +2703,8 @@ async function renderSSRDocument(options) {
|
|
|
2839
2703
|
throw new Error("skip-content-preload");
|
|
2840
2704
|
}
|
|
2841
2705
|
try {
|
|
2842
|
-
const registryPath =
|
|
2843
|
-
const reg = await import(pathToFileURL5(registryPath).href + (
|
|
2706
|
+
const registryPath = join9(cwd, ".reroute", "content.ts");
|
|
2707
|
+
const reg = await import(pathToFileURL5(registryPath).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
2844
2708
|
const get = reg?.getContentEntry;
|
|
2845
2709
|
const entry = typeof get === "function" ? get(collection, name) : undefined;
|
|
2846
2710
|
const moduleUrl = entry?.module;
|
|
@@ -2850,7 +2714,7 @@ async function renderSSRDocument(options) {
|
|
|
2850
2714
|
} catch {}
|
|
2851
2715
|
if (!modulePath) {
|
|
2852
2716
|
try {
|
|
2853
|
-
const chunkDir =
|
|
2717
|
+
const chunkDir = join9(cwd, ".reroute", "chunks", collection);
|
|
2854
2718
|
const files = await readdir5(chunkDir);
|
|
2855
2719
|
const candidates = files.filter((n) => n.startsWith(`${name}.`) && n.endsWith(".js"));
|
|
2856
2720
|
if (candidates.length) {
|
|
@@ -2858,25 +2722,25 @@ async function renderSSRDocument(options) {
|
|
|
2858
2722
|
let latestM = 0;
|
|
2859
2723
|
for (const candidateName of candidates) {
|
|
2860
2724
|
try {
|
|
2861
|
-
const s = await stat4(
|
|
2725
|
+
const s = await stat4(join9(chunkDir, candidateName));
|
|
2862
2726
|
if (s.mtimeMs >= latestM) {
|
|
2863
2727
|
latestM = s.mtimeMs;
|
|
2864
2728
|
latest = candidateName;
|
|
2865
2729
|
}
|
|
2866
2730
|
} catch {}
|
|
2867
2731
|
}
|
|
2868
|
-
modulePath = `/${
|
|
2732
|
+
modulePath = `/${join9(".reroute", "chunks", collection, latest).replace(/\\+/g, "/")}`;
|
|
2869
2733
|
}
|
|
2870
2734
|
} catch {}
|
|
2871
2735
|
}
|
|
2872
2736
|
if (!modulePath) {
|
|
2873
|
-
const tsx =
|
|
2874
|
-
const ts =
|
|
2737
|
+
const tsx = join9(clientDir, "routes", collection, "content", `${name}.tsx`);
|
|
2738
|
+
const ts = join9(clientDir, "routes", collection, "content", `${name}.ts`);
|
|
2875
2739
|
let srcUrl = "";
|
|
2876
2740
|
if (await Bun.file(tsx).exists()) {
|
|
2877
|
-
srcUrl = `/${
|
|
2741
|
+
srcUrl = `/${join9("routes", collection, "content", `${name}.tsx`).replace(/\\+/g, "/")}`;
|
|
2878
2742
|
} else if (await Bun.file(ts).exists()) {
|
|
2879
|
-
srcUrl = `/${
|
|
2743
|
+
srcUrl = `/${join9("routes", collection, "content", `${name}.ts`).replace(/\\+/g, "/")}`;
|
|
2880
2744
|
}
|
|
2881
2745
|
if (srcUrl) {
|
|
2882
2746
|
modulePath = srcUrl;
|
|
@@ -2894,7 +2758,7 @@ async function renderSSRDocument(options) {
|
|
|
2894
2758
|
}
|
|
2895
2759
|
}
|
|
2896
2760
|
} catch {}
|
|
2897
|
-
await seedSSRModuleForPath(pathname, clientDir, cwd,
|
|
2761
|
+
await seedSSRModuleForPath(pathname, clientDir, cwd, isWatchMode);
|
|
2898
2762
|
const __SSR_DATA__ = {};
|
|
2899
2763
|
try {
|
|
2900
2764
|
try {
|
|
@@ -2914,15 +2778,15 @@ async function renderSSRDocument(options) {
|
|
|
2914
2778
|
}
|
|
2915
2779
|
} catch {}
|
|
2916
2780
|
try {
|
|
2917
|
-
const routesPath =
|
|
2918
|
-
const m = await import(pathToFileURL5(routesPath).href + (
|
|
2781
|
+
const routesPath = join9(cwd, ".reroute", "routes.ts");
|
|
2782
|
+
const m = await import(pathToFileURL5(routesPath).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
2919
2783
|
const match = typeof m.matchRoute === "function" ? m.matchRoute(pathname) : null;
|
|
2920
2784
|
const r = match?.route;
|
|
2921
2785
|
const params = match?.params || {};
|
|
2922
2786
|
if (r && typeof r.path === "string") {
|
|
2923
2787
|
try {
|
|
2924
|
-
const abs =
|
|
2925
|
-
const mod = await import(pathToFileURL5(abs).href + (
|
|
2788
|
+
const abs = join9(clientDir, "routes", String(r.path));
|
|
2789
|
+
const mod = await import(pathToFileURL5(abs).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
2926
2790
|
const ssr = mod?.ssr;
|
|
2927
2791
|
const dataFn = ssr?.data;
|
|
2928
2792
|
if (typeof dataFn === "function") {
|
|
@@ -2938,8 +2802,8 @@ async function renderSSRDocument(options) {
|
|
|
2938
2802
|
} catch {}
|
|
2939
2803
|
let __byCollectionForSSR = {};
|
|
2940
2804
|
try {
|
|
2941
|
-
const p =
|
|
2942
|
-
const mod = await import(pathToFileURL5(p).href + (
|
|
2805
|
+
const p = join9(cwd, ".reroute", "content.ts");
|
|
2806
|
+
const mod = await import(pathToFileURL5(p).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
2943
2807
|
__byCollectionForSSR = mod?.byCollection || {};
|
|
2944
2808
|
try {
|
|
2945
2809
|
globalThis.__REROUTE_COLLECTIONS__ = __byCollectionForSSR;
|
|
@@ -2953,10 +2817,10 @@ async function renderSSRDocument(options) {
|
|
|
2953
2817
|
let inlineStyleTag = "";
|
|
2954
2818
|
try {
|
|
2955
2819
|
const candidates = [
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2820
|
+
join9(clientDir, "..", ".reroute", "theme.css"),
|
|
2821
|
+
join9(clientDir, "..", "..", ".reroute", "theme.css"),
|
|
2822
|
+
join9(clientDir, "..", "..", "..", ".reroute", "theme.css"),
|
|
2823
|
+
join9(clientDir, "..", "..", "..", "..", ".reroute", "theme.css")
|
|
2960
2824
|
];
|
|
2961
2825
|
let cssPath = "";
|
|
2962
2826
|
for (const p of candidates) {
|
|
@@ -3039,7 +2903,7 @@ async function renderSSRDocument(options) {
|
|
|
3039
2903
|
</script>`;
|
|
3040
2904
|
} catch {}
|
|
3041
2905
|
hydrationScript += scripts.map((src) => `<script type="module" src="${src}"></script>`).join("");
|
|
3042
|
-
if (
|
|
2906
|
+
if (isWatchMode) {
|
|
3043
2907
|
hydrationScript += `<script type="module" src="/__reroute_watch.js"></script>`;
|
|
3044
2908
|
}
|
|
3045
2909
|
let perPageHead = "";
|
|
@@ -3064,8 +2928,8 @@ ${ssrHead}`;
|
|
|
3064
2928
|
}
|
|
3065
2929
|
} catch {}
|
|
3066
2930
|
try {
|
|
3067
|
-
const routesPath =
|
|
3068
|
-
const m = await import(pathToFileURL5(routesPath).href + (
|
|
2931
|
+
const routesPath = join9(cwd, ".reroute", "routes.ts");
|
|
2932
|
+
const m = await import(pathToFileURL5(routesPath).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
3069
2933
|
const match = typeof m.matchRoute === "function" ? m.matchRoute(pathname) : null;
|
|
3070
2934
|
const r = match?.route;
|
|
3071
2935
|
if (!r) {
|
|
@@ -3073,8 +2937,8 @@ ${ssrHead}`;
|
|
|
3073
2937
|
}
|
|
3074
2938
|
if (r && typeof r.path === "string") {
|
|
3075
2939
|
try {
|
|
3076
|
-
const abs =
|
|
3077
|
-
const mod = await import(pathToFileURL5(abs).href + (
|
|
2940
|
+
const abs = join9(clientDir, "routes", String(r.path));
|
|
2941
|
+
const mod = await import(pathToFileURL5(abs).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
3078
2942
|
const meta = mod?.meta;
|
|
3079
2943
|
const ssr = mod?.ssr;
|
|
3080
2944
|
if (meta)
|
|
@@ -3108,8 +2972,8 @@ ${ssrHead}`;
|
|
|
3108
2972
|
}
|
|
3109
2973
|
if (chosen && typeof chosen.path === "string") {
|
|
3110
2974
|
try {
|
|
3111
|
-
const abs =
|
|
3112
|
-
const mod = await import(pathToFileURL5(abs).href + (
|
|
2975
|
+
const abs = join9(clientDir, "routes", String(chosen.path));
|
|
2976
|
+
const mod = await import(pathToFileURL5(abs).href + (isWatchMode ? `?t=${Date.now()}` : ""));
|
|
3113
2977
|
const meta = mod?.meta;
|
|
3114
2978
|
const ssr = mod?.ssr;
|
|
3115
2979
|
if (meta)
|
|
@@ -3144,7 +3008,6 @@ ${ssrHead}`;
|
|
|
3144
3008
|
}
|
|
3145
3009
|
var init_render = __esm(() => {
|
|
3146
3010
|
init_dedent();
|
|
3147
|
-
init_bundler();
|
|
3148
3011
|
init_metadata();
|
|
3149
3012
|
init_template();
|
|
3150
3013
|
init_seed();
|
|
@@ -3276,7 +3139,6 @@ var init_src = __esm(() => {
|
|
|
3276
3139
|
// packages/core/index.ts
|
|
3277
3140
|
var exports_core = {};
|
|
3278
3141
|
__export(exports_core, {
|
|
3279
|
-
transpileFile: () => transpileFile,
|
|
3280
3142
|
toBytes: () => toBytes,
|
|
3281
3143
|
stripStart: () => stripStart,
|
|
3282
3144
|
stripEnd: () => stripEnd,
|
|
@@ -3284,20 +3146,16 @@ __export(exports_core, {
|
|
|
3284
3146
|
renderSSRDocument: () => renderSSRDocument,
|
|
3285
3147
|
loadIndexHtml: () => loadIndexHtml,
|
|
3286
3148
|
listContentFiles: () => listContentFiles2,
|
|
3287
|
-
join: () =>
|
|
3149
|
+
join: () => join9,
|
|
3288
3150
|
isCompressible: () => isCompressible,
|
|
3289
3151
|
gzipIfAccepted: () => gzipIfAccepted,
|
|
3290
|
-
getStaticDepsForUrl: () => getStaticDepsForUrl,
|
|
3291
3152
|
getMimeType: () => getMimeType,
|
|
3292
3153
|
getContentMeta: () => getContentMeta,
|
|
3293
|
-
getBundleUrlsFor: () => getBundleUrlsFor,
|
|
3294
|
-
generateContentRegistry: () => generateContentRegistry,
|
|
3295
3154
|
generateContentHash: () => generateContentHash,
|
|
3296
3155
|
extname: () => extname2,
|
|
3297
3156
|
discoverCollections: () => discoverCollections,
|
|
3298
3157
|
computeSSRDataForPath: () => computeSSRDataForPath,
|
|
3299
3158
|
buildHeadFromMeta: () => buildHeadFromMeta,
|
|
3300
|
-
buildContentDTOs: () => buildContentDTOs,
|
|
3301
3159
|
basename: () => basename2,
|
|
3302
3160
|
applyIndexTemplate: () => applyIndexTemplate,
|
|
3303
3161
|
acceptsGzip: () => acceptsGzip,
|
|
@@ -3308,32 +3166,61 @@ var init_core = __esm(() => {
|
|
|
3308
3166
|
init_src();
|
|
3309
3167
|
});
|
|
3310
3168
|
|
|
3169
|
+
// packages/cli/src/libs/command.ts
|
|
3170
|
+
var exports_command = {};
|
|
3171
|
+
__export(exports_command, {
|
|
3172
|
+
getRerouteCommand: () => getRerouteCommand4
|
|
3173
|
+
});
|
|
3174
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
3175
|
+
import { join as join10 } from "node:path";
|
|
3176
|
+
function getRerouteCommand4() {
|
|
3177
|
+
const binPath = join10(import.meta.dir, "..", "..", "bin.ts");
|
|
3178
|
+
const isBunDev = existsSync8(binPath);
|
|
3179
|
+
if (isBunDev) {
|
|
3180
|
+
return `bun ${binPath}`;
|
|
3181
|
+
}
|
|
3182
|
+
const cwd = process.cwd();
|
|
3183
|
+
const nodeModulesPaths = [
|
|
3184
|
+
join10(cwd, "node_modules", ".bin", "reroute"),
|
|
3185
|
+
join10(cwd, "..", "node_modules", ".bin", "reroute"),
|
|
3186
|
+
join10(cwd, "..", "..", "node_modules", ".bin", "reroute"),
|
|
3187
|
+
join10(cwd, "..", "..", "..", "node_modules", ".bin", "reroute")
|
|
3188
|
+
];
|
|
3189
|
+
for (const binPath2 of nodeModulesPaths) {
|
|
3190
|
+
if (existsSync8(binPath2)) {
|
|
3191
|
+
return binPath2;
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
return "reroute";
|
|
3195
|
+
}
|
|
3196
|
+
var init_command = () => {};
|
|
3197
|
+
|
|
3311
3198
|
// packages/cli/src/commands/analyze.ts
|
|
3312
3199
|
var exports_analyze = {};
|
|
3313
3200
|
__export(exports_analyze, {
|
|
3314
3201
|
default: () => analyze
|
|
3315
3202
|
});
|
|
3316
3203
|
import { existsSync as existsSync9, statSync } from "node:fs";
|
|
3317
|
-
import { readdir as readdir6, readFile
|
|
3318
|
-
import { basename as basename3, join as
|
|
3204
|
+
import { readdir as readdir6, readFile, stat as stat5, writeFile } from "node:fs/promises";
|
|
3205
|
+
import { basename as basename3, join as join11, relative } from "node:path";
|
|
3319
3206
|
import Table from "cli-table3";
|
|
3320
3207
|
async function findBundles(cwd) {
|
|
3321
3208
|
const bundles = [];
|
|
3322
|
-
const chunksDir =
|
|
3209
|
+
const chunksDir = join11(cwd, ".reroute", "chunks");
|
|
3323
3210
|
if (existsSync9(chunksDir)) {
|
|
3324
3211
|
const collections = await readdir6(chunksDir, { withFileTypes: true });
|
|
3325
3212
|
for (const collection of collections) {
|
|
3326
3213
|
if (!collection.isDirectory())
|
|
3327
3214
|
continue;
|
|
3328
|
-
const collectionDir =
|
|
3215
|
+
const collectionDir = join11(chunksDir, collection.name);
|
|
3329
3216
|
const files = await readdir6(collectionDir);
|
|
3330
3217
|
for (const file of files) {
|
|
3331
3218
|
if (!file.endsWith(".js"))
|
|
3332
3219
|
continue;
|
|
3333
|
-
const filePath =
|
|
3220
|
+
const filePath = join11(collectionDir, file);
|
|
3334
3221
|
const stats = await stat5(filePath);
|
|
3335
|
-
const content2 = await
|
|
3336
|
-
const gzippedSize = Bun.gzipSync(content2).length;
|
|
3222
|
+
const content2 = await Bun.file(filePath).arrayBuffer();
|
|
3223
|
+
const gzippedSize = Bun.gzipSync(new Uint8Array(content2)).length;
|
|
3337
3224
|
bundles.push({
|
|
3338
3225
|
path: filePath,
|
|
3339
3226
|
name: file,
|
|
@@ -3345,15 +3232,15 @@ async function findBundles(cwd) {
|
|
|
3345
3232
|
}
|
|
3346
3233
|
}
|
|
3347
3234
|
}
|
|
3348
|
-
const distDir =
|
|
3235
|
+
const distDir = join11(cwd, "dist");
|
|
3349
3236
|
if (existsSync9(distDir)) {
|
|
3350
3237
|
const files = await readdir6(distDir);
|
|
3351
3238
|
for (const file of files) {
|
|
3352
|
-
const filePath =
|
|
3239
|
+
const filePath = join11(distDir, file);
|
|
3353
3240
|
const stats = statSync(filePath);
|
|
3354
3241
|
if (stats.isFile() && !file.endsWith(".map") && !file.endsWith(".d.ts")) {
|
|
3355
|
-
const content2 = await
|
|
3356
|
-
const gzippedSize = Bun.gzipSync(content2).length;
|
|
3242
|
+
const content2 = await Bun.file(filePath).arrayBuffer();
|
|
3243
|
+
const gzippedSize = Bun.gzipSync(new Uint8Array(content2)).length;
|
|
3357
3244
|
bundles.push({
|
|
3358
3245
|
path: filePath,
|
|
3359
3246
|
name: file,
|
|
@@ -3369,9 +3256,9 @@ async function findBundles(cwd) {
|
|
|
3369
3256
|
}
|
|
3370
3257
|
async function findBrowserEntry(cwd) {
|
|
3371
3258
|
try {
|
|
3372
|
-
const clientDir =
|
|
3373
|
-
const tsxEntry =
|
|
3374
|
-
const tsEntry =
|
|
3259
|
+
const clientDir = join11(cwd, "src", "client");
|
|
3260
|
+
const tsxEntry = join11(clientDir, "index.tsx");
|
|
3261
|
+
const tsEntry = join11(clientDir, "index.ts");
|
|
3375
3262
|
let sourceEntry = null;
|
|
3376
3263
|
if (existsSync9(tsxEntry)) {
|
|
3377
3264
|
sourceEntry = tsxEntry;
|
|
@@ -3395,7 +3282,7 @@ async function findBrowserEntry(cwd) {
|
|
|
3395
3282
|
});
|
|
3396
3283
|
if (!result.success) {
|
|
3397
3284
|
if (result.logs && result.logs.length > 0) {
|
|
3398
|
-
console.warn("[reroute/analyze] Browser build errors:", result.logs.map((
|
|
3285
|
+
console.warn("[reroute/analyze] Browser build errors:", result.logs.map((log) => log.message).join(`
|
|
3399
3286
|
`));
|
|
3400
3287
|
}
|
|
3401
3288
|
return null;
|
|
@@ -3404,17 +3291,17 @@ async function findBrowserEntry(cwd) {
|
|
|
3404
3291
|
console.warn("[reroute/analyze] Browser build produced no outputs");
|
|
3405
3292
|
return null;
|
|
3406
3293
|
}
|
|
3407
|
-
const tempDir =
|
|
3294
|
+
const tempDir = join11(cwd, ".reroute", "browser");
|
|
3408
3295
|
await import("node:fs/promises").then((fs) => fs.mkdir(tempDir, { recursive: true }));
|
|
3409
3296
|
const output = result.outputs[0];
|
|
3410
3297
|
const code = await output.text();
|
|
3411
3298
|
const actualHash = await generateContentHash2(code);
|
|
3412
|
-
const bundlePath =
|
|
3413
|
-
await
|
|
3299
|
+
const bundlePath = join11(tempDir, `index.${actualHash}.js`);
|
|
3300
|
+
await writeFile(bundlePath, code, "utf-8");
|
|
3414
3301
|
const mapOutput = result.outputs.find((o) => o.path.endsWith(".map"));
|
|
3415
3302
|
if (mapOutput) {
|
|
3416
3303
|
const mapContent = await mapOutput.text();
|
|
3417
|
-
await
|
|
3304
|
+
await writeFile(`${bundlePath}.map`, mapContent, "utf-8");
|
|
3418
3305
|
}
|
|
3419
3306
|
return bundlePath;
|
|
3420
3307
|
} catch (error) {
|
|
@@ -3461,7 +3348,7 @@ function calculateStats(bundles) {
|
|
|
3461
3348
|
}
|
|
3462
3349
|
async function getInstalledPackageSizes(cwd) {
|
|
3463
3350
|
const packageSizes = new Map;
|
|
3464
|
-
const nodeModulesDir =
|
|
3351
|
+
const nodeModulesDir = join11(cwd, "node_modules");
|
|
3465
3352
|
if (!existsSync9(nodeModulesDir))
|
|
3466
3353
|
return packageSizes;
|
|
3467
3354
|
try {
|
|
@@ -3520,7 +3407,7 @@ async function buildDependencyTree(entryPath, cwd) {
|
|
|
3520
3407
|
if (!pkgNode) {
|
|
3521
3408
|
pkgNode = {
|
|
3522
3409
|
name: pkgName || "unknown",
|
|
3523
|
-
path:
|
|
3410
|
+
path: join11(cwd, "node_modules", pkgName || ""),
|
|
3524
3411
|
size: 0,
|
|
3525
3412
|
children: []
|
|
3526
3413
|
};
|
|
@@ -3541,7 +3428,7 @@ async function buildDependencyTree(entryPath, cwd) {
|
|
|
3541
3428
|
if (!child) {
|
|
3542
3429
|
child = {
|
|
3543
3430
|
name: part,
|
|
3544
|
-
path:
|
|
3431
|
+
path: join11(cwd, ...parts.slice(0, i + 1)),
|
|
3545
3432
|
size: 0,
|
|
3546
3433
|
children: []
|
|
3547
3434
|
};
|
|
@@ -3561,11 +3448,11 @@ async function buildDependencyTree(entryPath, cwd) {
|
|
|
3561
3448
|
}
|
|
3562
3449
|
return node.size;
|
|
3563
3450
|
};
|
|
3564
|
-
const content2 = await
|
|
3451
|
+
const content2 = await readFile(entryPath, "utf-8");
|
|
3565
3452
|
const modulePattern = /\/\/\s*(.+?\.(?:ts|tsx|js|jsx|mjs|cjs))\s*$/gm;
|
|
3566
3453
|
const nodeModulesNode = {
|
|
3567
3454
|
name: "node_modules",
|
|
3568
|
-
path:
|
|
3455
|
+
path: join11(cwd, "node_modules"),
|
|
3569
3456
|
size: 0,
|
|
3570
3457
|
children: []
|
|
3571
3458
|
};
|
|
@@ -3631,7 +3518,7 @@ async function buildTreeFromSourceMap(bundlePath, cwd) {
|
|
|
3631
3518
|
if (sourcePath.startsWith("/") || sourcePath.match(/^[A-Za-z]:\\/))
|
|
3632
3519
|
return sourcePath;
|
|
3633
3520
|
const bundleDir = bundlePath.substring(0, bundlePath.lastIndexOf("/"));
|
|
3634
|
-
return
|
|
3521
|
+
return join11(bundleDir, sourceRoot || "", sourcePath);
|
|
3635
3522
|
}, computeSizes = function(node) {
|
|
3636
3523
|
if (node.children && node.children.length > 0) {
|
|
3637
3524
|
node.size = node.children.reduce((s, c) => s + computeSizes(c), 0);
|
|
@@ -3642,8 +3529,8 @@ async function buildTreeFromSourceMap(bundlePath, cwd) {
|
|
|
3642
3529
|
if (!existsSync9(mapPath))
|
|
3643
3530
|
return null;
|
|
3644
3531
|
const [bundle, mapJson] = await Promise.all([
|
|
3645
|
-
|
|
3646
|
-
|
|
3532
|
+
readFile(bundlePath, "utf-8"),
|
|
3533
|
+
readFile(mapPath, "utf-8")
|
|
3647
3534
|
]);
|
|
3648
3535
|
const map = JSON.parse(mapJson);
|
|
3649
3536
|
const sourceRoot = map.sourceRoot || "";
|
|
@@ -3703,7 +3590,7 @@ async function buildTreeFromSourceMap(bundlePath, cwd) {
|
|
|
3703
3590
|
};
|
|
3704
3591
|
const nodeModulesNode = {
|
|
3705
3592
|
name: "node_modules",
|
|
3706
|
-
path:
|
|
3593
|
+
path: join11(cwd, "node_modules"),
|
|
3707
3594
|
size: 0,
|
|
3708
3595
|
children: []
|
|
3709
3596
|
};
|
|
@@ -3743,7 +3630,7 @@ async function buildTreeFromSourceMap(bundlePath, cwd) {
|
|
|
3743
3630
|
if (!pkgNode) {
|
|
3744
3631
|
pkgNode = {
|
|
3745
3632
|
name: pkgName || "unknown",
|
|
3746
|
-
path:
|
|
3633
|
+
path: join11(cwd, "node_modules", pkgName || ""),
|
|
3747
3634
|
size: 0,
|
|
3748
3635
|
children: []
|
|
3749
3636
|
};
|
|
@@ -3764,7 +3651,7 @@ async function buildTreeFromSourceMap(bundlePath, cwd) {
|
|
|
3764
3651
|
if (!child) {
|
|
3765
3652
|
child = {
|
|
3766
3653
|
name: part,
|
|
3767
|
-
path:
|
|
3654
|
+
path: join11(cwd, ...parts.slice(0, i2 + 1)),
|
|
3768
3655
|
size: 0,
|
|
3769
3656
|
children: []
|
|
3770
3657
|
};
|
|
@@ -3794,15 +3681,15 @@ async function generateHTMLReport(stats, depTree, mainInfo, browserDepTree, brow
|
|
|
3794
3681
|
let actualServerBinarySize = null;
|
|
3795
3682
|
let actualServerBinaryGzipped = null;
|
|
3796
3683
|
try {
|
|
3797
|
-
const distDir =
|
|
3684
|
+
const distDir = join11(process.cwd(), "dist");
|
|
3798
3685
|
if (existsSync9(distDir)) {
|
|
3799
3686
|
const files = await readdir6(distDir);
|
|
3800
3687
|
for (const file of files) {
|
|
3801
|
-
const filePath =
|
|
3688
|
+
const filePath = join11(distDir, file);
|
|
3802
3689
|
const stats2 = statSync(filePath);
|
|
3803
3690
|
if (stats2.isFile() && !file.includes(".")) {
|
|
3804
3691
|
actualServerBinarySize = stats2.size;
|
|
3805
|
-
const content2 = await
|
|
3692
|
+
const content2 = await readFile(filePath);
|
|
3806
3693
|
actualServerBinaryGzipped = Bun.gzipSync(content2).length;
|
|
3807
3694
|
break;
|
|
3808
3695
|
}
|
|
@@ -5280,15 +5167,15 @@ async function printConsoleReport(stats, depTree, mainInfo, browserDepTree, brow
|
|
|
5280
5167
|
let actualServerBinarySize = null;
|
|
5281
5168
|
let actualServerBinaryGzipped = null;
|
|
5282
5169
|
try {
|
|
5283
|
-
const distDir =
|
|
5170
|
+
const distDir = join11(process.cwd(), "dist");
|
|
5284
5171
|
if (existsSync9(distDir)) {
|
|
5285
5172
|
const files = await readdir6(distDir);
|
|
5286
5173
|
for (const file of files) {
|
|
5287
|
-
const filePath =
|
|
5174
|
+
const filePath = join11(distDir, file);
|
|
5288
5175
|
const stats2 = statSync(filePath);
|
|
5289
5176
|
if (stats2.isFile() && !file.includes(".")) {
|
|
5290
5177
|
actualServerBinarySize = stats2.size;
|
|
5291
|
-
const content2 = await
|
|
5178
|
+
const content2 = await readFile(filePath);
|
|
5292
5179
|
actualServerBinaryGzipped = Bun.gzipSync(content2).length;
|
|
5293
5180
|
break;
|
|
5294
5181
|
}
|
|
@@ -5318,7 +5205,7 @@ async function analyze(args) {
|
|
|
5318
5205
|
const isProd = isProductionMode(args);
|
|
5319
5206
|
const searchIndex = args.indexOf("--search");
|
|
5320
5207
|
const initialSearch = searchIndex !== -1 && args[searchIndex + 1] ? args[searchIndex + 1] : "";
|
|
5321
|
-
const rerouteIndexPath =
|
|
5208
|
+
const rerouteIndexPath = join11(cwd, ".reroute", "index.ts");
|
|
5322
5209
|
if (!existsSync9(rerouteIndexPath)) {
|
|
5323
5210
|
console.log(colorizeLogPrefixAnsi(`[reroute/analyze] .reroute artifacts not found, running build...
|
|
5324
5211
|
`));
|
|
@@ -5366,7 +5253,7 @@ async function analyze(args) {
|
|
|
5366
5253
|
}
|
|
5367
5254
|
try {
|
|
5368
5255
|
const browserStat = await stat5(browserEntry);
|
|
5369
|
-
const browserContent = await
|
|
5256
|
+
const browserContent = await readFile(browserEntry);
|
|
5370
5257
|
const browserGzipped = Bun.gzipSync(browserContent).length;
|
|
5371
5258
|
browserInfo = {
|
|
5372
5259
|
name: basename3(browserEntry),
|
|
@@ -5381,13 +5268,13 @@ async function analyze(args) {
|
|
|
5381
5268
|
let entry = null;
|
|
5382
5269
|
let depTree = null;
|
|
5383
5270
|
let mainInfo = null;
|
|
5384
|
-
const srcEntry =
|
|
5271
|
+
const srcEntry = join11(cwd, "src", "index.ts");
|
|
5385
5272
|
if (existsSync9(srcEntry)) {
|
|
5386
5273
|
console.log(colorizeLogPrefixAnsi(`[reroute/analyze] Building server binary for analysis...
|
|
5387
5274
|
`));
|
|
5388
|
-
const { mkdir:
|
|
5389
|
-
const serverAnalysisDir =
|
|
5390
|
-
await
|
|
5275
|
+
const { mkdir: mkdir3 } = await import("node:fs/promises");
|
|
5276
|
+
const serverAnalysisDir = join11(cwd, ".reroute", "server");
|
|
5277
|
+
await mkdir3(serverAnalysisDir, { recursive: true });
|
|
5391
5278
|
const result = await Bun.build({
|
|
5392
5279
|
entrypoints: [srcEntry],
|
|
5393
5280
|
target: "bun",
|
|
@@ -5399,12 +5286,12 @@ async function analyze(args) {
|
|
|
5399
5286
|
if (result.success && result.outputs.length > 0) {
|
|
5400
5287
|
const output = result.outputs[0];
|
|
5401
5288
|
const code = await output.text();
|
|
5402
|
-
const analysisEntry =
|
|
5403
|
-
await
|
|
5289
|
+
const analysisEntry = join11(serverAnalysisDir, "index.js");
|
|
5290
|
+
await writeFile(analysisEntry, code, "utf-8");
|
|
5404
5291
|
const mapOutput = result.outputs.find((o) => o.path.endsWith(".map"));
|
|
5405
5292
|
if (mapOutput) {
|
|
5406
5293
|
const mapContent = await mapOutput.text();
|
|
5407
|
-
await
|
|
5294
|
+
await writeFile(`${analysisEntry}.map`, mapContent, "utf-8");
|
|
5408
5295
|
}
|
|
5409
5296
|
entry = analysisEntry;
|
|
5410
5297
|
}
|
|
@@ -5417,10 +5304,10 @@ async function analyze(args) {
|
|
|
5417
5304
|
`));
|
|
5418
5305
|
const installedSizes = await getInstalledPackageSizes(cwd);
|
|
5419
5306
|
if (depTree) {
|
|
5420
|
-
const packageJsonPath =
|
|
5307
|
+
const packageJsonPath = join11(cwd, "package.json");
|
|
5421
5308
|
if (existsSync9(packageJsonPath)) {
|
|
5422
5309
|
try {
|
|
5423
|
-
const packageJson = JSON.parse(await
|
|
5310
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf-8"));
|
|
5424
5311
|
const runtimeDeps = packageJson.dependencies || {};
|
|
5425
5312
|
const nodeModulesNode = depTree.root.children?.find((c) => c.name === "node_modules");
|
|
5426
5313
|
if (nodeModulesNode) {
|
|
@@ -5429,7 +5316,7 @@ async function analyze(args) {
|
|
|
5429
5316
|
if (!trackedPkgs.has(pkgName) && installedSizes.has(pkgName)) {
|
|
5430
5317
|
nodeModulesNode.children?.push({
|
|
5431
5318
|
name: pkgName,
|
|
5432
|
-
path:
|
|
5319
|
+
path: join11(cwd, "node_modules", pkgName),
|
|
5433
5320
|
size: installedSizes.get(pkgName) || 0
|
|
5434
5321
|
});
|
|
5435
5322
|
}
|
|
@@ -5448,7 +5335,7 @@ async function analyze(args) {
|
|
|
5448
5335
|
}
|
|
5449
5336
|
try {
|
|
5450
5337
|
const entryStat = await stat5(entry);
|
|
5451
|
-
const entryContent = await
|
|
5338
|
+
const entryContent = await readFile(entry);
|
|
5452
5339
|
const entryGzipped = Bun.gzipSync(entryContent).length;
|
|
5453
5340
|
mainInfo = {
|
|
5454
5341
|
name: basename3(entry),
|
|
@@ -5460,30 +5347,30 @@ async function analyze(args) {
|
|
|
5460
5347
|
const fullOutput = args.includes("--full");
|
|
5461
5348
|
await printConsoleReport(stats, depTree, mainInfo, browserDepTree, browserInfo, fullOutput);
|
|
5462
5349
|
if (outputHtml || openBrowser) {
|
|
5463
|
-
const htmlPath =
|
|
5350
|
+
const htmlPath = join11(cwd, ".reroute", "analysis.html");
|
|
5464
5351
|
const html2 = await generateHTMLReport(stats, depTree, mainInfo, browserDepTree, browserInfo, initialSearch);
|
|
5465
|
-
const { mkdir:
|
|
5466
|
-
await
|
|
5467
|
-
await
|
|
5352
|
+
const { mkdir: mkdir3 } = await import("node:fs/promises");
|
|
5353
|
+
await mkdir3(join11(cwd, ".reroute"), { recursive: true });
|
|
5354
|
+
await writeFile(htmlPath, html2, "utf-8");
|
|
5468
5355
|
console.log(colorizeLogPrefixAnsi(`[reroute/analyze] HTML report generated: ${relative(cwd, htmlPath)}
|
|
5469
5356
|
`));
|
|
5470
5357
|
if (openBrowser) {
|
|
5471
5358
|
try {
|
|
5472
5359
|
const { spawn: spawn5 } = await import("node:child_process");
|
|
5473
5360
|
const platform = process.platform;
|
|
5474
|
-
let
|
|
5361
|
+
let command;
|
|
5475
5362
|
let commandArgs;
|
|
5476
5363
|
if (platform === "darwin") {
|
|
5477
|
-
|
|
5364
|
+
command = "open";
|
|
5478
5365
|
commandArgs = [htmlPath];
|
|
5479
5366
|
} else if (platform === "win32") {
|
|
5480
|
-
|
|
5367
|
+
command = "cmd";
|
|
5481
5368
|
commandArgs = ["/c", "start", "", htmlPath];
|
|
5482
5369
|
} else {
|
|
5483
|
-
|
|
5370
|
+
command = "xdg-open";
|
|
5484
5371
|
commandArgs = [htmlPath];
|
|
5485
5372
|
}
|
|
5486
|
-
spawn5(
|
|
5373
|
+
spawn5(command, commandArgs, { detached: true, stdio: "ignore" });
|
|
5487
5374
|
console.log(colorizeLogPrefixAnsi(`[reroute/analyze] Opened report in browser
|
|
5488
5375
|
`));
|
|
5489
5376
|
} catch {
|
|
@@ -5525,7 +5412,6 @@ import path3 from "node:path";
|
|
|
5525
5412
|
var commands = {
|
|
5526
5413
|
init: () => Promise.resolve().then(() => (init_init(), exports_init)),
|
|
5527
5414
|
gen: () => Promise.resolve().then(() => (init_gen(), exports_gen)),
|
|
5528
|
-
boot: () => Promise.resolve().then(() => (init_boot(), exports_boot)),
|
|
5529
5415
|
dev: () => Promise.resolve().then(() => (init_dev(), exports_dev)),
|
|
5530
5416
|
start: () => Promise.resolve().then(() => (init_start(), exports_start)),
|
|
5531
5417
|
build: () => Promise.resolve().then(() => (init_build(), exports_build)),
|
|
@@ -5542,9 +5428,9 @@ async function main() {
|
|
|
5542
5428
|
await printHelp2();
|
|
5543
5429
|
process.exit(0);
|
|
5544
5430
|
}
|
|
5545
|
-
const
|
|
5546
|
-
if (!commands[
|
|
5547
|
-
console.error(`Unknown command: ${
|
|
5431
|
+
const command = args[0];
|
|
5432
|
+
if (!commands[command]) {
|
|
5433
|
+
console.error(`Unknown command: ${command}`);
|
|
5548
5434
|
console.error("");
|
|
5549
5435
|
await printHelp2();
|
|
5550
5436
|
process.exit(1);
|
|
@@ -5557,7 +5443,7 @@ async function main() {
|
|
|
5557
5443
|
Bun.env.NODE_ENV = "production";
|
|
5558
5444
|
}
|
|
5559
5445
|
}
|
|
5560
|
-
const module = await commands[
|
|
5446
|
+
const module = await commands[command]();
|
|
5561
5447
|
await module.default(commandArgs);
|
|
5562
5448
|
} catch (error) {
|
|
5563
5449
|
console.error("Error executing command:", error);
|
|
@@ -5577,7 +5463,6 @@ async function printHelp2() {
|
|
|
5577
5463
|
console.log("Commands:");
|
|
5578
5464
|
console.log("");
|
|
5579
5465
|
console.log(" init Scaffold a new Reroute project");
|
|
5580
|
-
console.log(" boot Initialize .reroute directory with stub files");
|
|
5581
5466
|
console.log(" gen Generate content registry and static assets");
|
|
5582
5467
|
console.log(" dev Start development environment");
|
|
5583
5468
|
console.log(" start Run production-like server locally");
|
|
@@ -5595,7 +5480,6 @@ async function printHelp2() {
|
|
|
5595
5480
|
console.log("Examples:");
|
|
5596
5481
|
console.log("");
|
|
5597
5482
|
console.log(" reroute init my-app");
|
|
5598
|
-
console.log(" reroute boot");
|
|
5599
5483
|
console.log("");
|
|
5600
5484
|
console.log(" reroute gen");
|
|
5601
5485
|
console.log(" reroute gen -w");
|
|
@@ -5625,7 +5509,7 @@ async function getVersionString2() {
|
|
|
5625
5509
|
}
|
|
5626
5510
|
async function getVersion2() {
|
|
5627
5511
|
if (true) {
|
|
5628
|
-
return "0.9.
|
|
5512
|
+
return "0.9.2";
|
|
5629
5513
|
}
|
|
5630
5514
|
const possiblePaths = [
|
|
5631
5515
|
path3.join(import.meta.dir, "../../../package.json"),
|
|
@@ -5642,10 +5526,10 @@ async function getVersion2() {
|
|
|
5642
5526
|
}
|
|
5643
5527
|
async function getCommit2() {
|
|
5644
5528
|
if (true) {
|
|
5645
|
-
return "
|
|
5529
|
+
return "07fb920";
|
|
5646
5530
|
}
|
|
5647
5531
|
return "dev";
|
|
5648
5532
|
}
|
|
5649
5533
|
main();
|
|
5650
5534
|
|
|
5651
|
-
//# debugId=
|
|
5535
|
+
//# debugId=EEA72E4BE30148EF64756E2164756E21
|