@renr/parcel-plugin-rsc-router 0.0.0-stage → 1.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,148 @@
1
- # Temporary Holding Version
1
+ # @renr/parcel-plugin-rsc-router
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A native Parcel v3 plugin (reporter + transformer) that scans RSC page files, generates typed filesystem route definitions on build, and statically prerenders HTML and RSC payloads.
4
+
5
+ Pair with [`@renr/parcel-rsc-router`](https://github.com/renrizzolo/parcel-rsc-react/tree/main/packages/parcel-rsc-router) for type-safe client-side navigation in Parcel static RSC applications.
6
+
7
+ ## Installation
8
+
9
+ For the simplest setup, install [`@renr/parcel-config-rsc-router`](../parcel-config-rsc-router) (which depends on `@renr/parcel-plugin-rsc-router`):
10
+
11
+ ```bash
12
+ pnpm add -D @renr/parcel-config-rsc-router
13
+ # or
14
+ npm install -D @renr/parcel-config-rsc-router
15
+ # or
16
+ yarn add -D @renr/parcel-config-rsc-router
17
+ ```
18
+
19
+ Or install `@renr/parcel-plugin-rsc-router` directly if configuring `.parcelrc` manually:
20
+
21
+ ```bash
22
+ pnpm add -D @renr/parcel-plugin-rsc-router
23
+ # or
24
+ npm install -D @renr/parcel-plugin-rsc-router
25
+ # or
26
+ yarn add -D @renr/parcel-plugin-rsc-router
27
+ ```
28
+
29
+ ## Setup
30
+
31
+ ### 1. Configure `.parcelrc`
32
+
33
+ **Recommended** (using `@renr/parcel-config-rsc-router`):
34
+
35
+ ```json
36
+ {
37
+ "extends": "@renr/parcel-config-rsc-router"
38
+ }
39
+ ```
40
+
41
+ **Manual `.parcelrc` setup** (register `@renr/parcel-plugin-rsc-router` in both `transformers` for `routes.ts` and `reporters`):
42
+
43
+ ```json
44
+ {
45
+ "extends": "@parcel/config-default",
46
+ "transformers": {
47
+ "routes.ts": ["@renr/parcel-plugin-rsc-router", "..."]
48
+ },
49
+ "reporters": ["...", "@renr/parcel-plugin-rsc-router"]
50
+ }
51
+ ```
52
+
53
+ Why both? Parcel `.parcelrc` lists plugins by the pipeline stage they participate in. Inside one native package, `@renr/parcel-plugin-rsc-router` handles three distinct phases:
54
+
55
+ 1. **`build_start` (Reporter)**: scans `src/pages/**/*` and writes the clean, typed `routes.ts` to disk before bundling.
56
+ 2. **`transform` on `routes.ts` (Transformer)**: runs **only** in the `ReactServer` environment to append an in-memory `prerenderStaticSite` + parallel `Promise.all` dynamic `import(...)` bootstrap footer, leaving `routes.ts` clean on disk and untouched for `ReactClient` imports.
57
+ 3. **`build_success` (Reporter)**: runs the built `ReactServer` `routes.js` bundle with `PARCEL_RSC_PRERENDER=1` to write static `.html` and `.rsc` files to your target `distDir`.
58
+
59
+ ### 2. Configure `package.json`
60
+
61
+ Point Parcel's `source` at your generated `routes.ts` entrypoint with a `react-server` target, and configure `@renr/parcel-plugin-rsc-router`:
62
+
63
+ ```json
64
+ {
65
+ "source": "routes.ts",
66
+ "@renr/parcel-plugin-rsc-router": {
67
+ "source": "src/pages/**/*.{tsx,mdx}"
68
+ },
69
+ "targets": {
70
+ "default": {
71
+ "context": "react-server",
72
+ "distDir": "dist"
73
+ }
74
+ }
75
+ }
76
+ ```
77
+
78
+ > Note: Parcel 3 resolves `package.json#source` (`"routes.ts"`) before plugin hooks run, so `routes.ts` should already exist on disk before `parcel build` (committed to the repo, or generated once on a clean checkout with `npx parcel-rsc-routes`).
79
+
80
+ #### Output Configuration
81
+
82
+ - **Built site & prerendered `.html`/`.rsc` output directory**: set Parcel's `targets.default.distDir` in `package.json` (defaults to `dist`).
83
+ - **Generated `routes.ts` output path**: set `"output"` under `@renr/parcel-plugin-rsc-router` (defaults to `routes.ts`). Passing a directory such as `"src"` automatically appends `routes.ts` (`src/routes.ts`).
84
+
85
+ Whenever you change `"output"`, **you must also update `package.json#source`** (Parcel's entrypoint) and any app imports (such as `flatRoutes` or `routeTree`) to point at the generated file:
86
+
87
+ ```json
88
+ {
89
+ "source": "src/routes.ts",
90
+ "@renr/parcel-plugin-rsc-router": {
91
+ "source": "src/pages/**/*.{tsx,mdx}",
92
+ "output": "src/routes.ts"
93
+ },
94
+ "targets": {
95
+ "default": {
96
+ "context": "react-server",
97
+ "distDir": "dist"
98
+ }
99
+ }
100
+ }
101
+ ```
102
+
103
+ Because Parcel matches `"routes.ts"` in `.parcelrc` against file basenames, keeping the filename `routes.ts` (for example `"output": "src/routes.ts"` or `"output": "src"`) works automatically with `@renr/parcel-config-rsc-router`.
104
+
105
+ If you use a filename other than `routes.ts` (such as `"output": "routes/index.ts"`), also update `package.json#source` and add a matching glob in `.parcelrc#transformers`:
106
+
107
+ `.parcelrc`:
108
+
109
+ ```json
110
+ {
111
+ "extends": "@renr/parcel-config-rsc-router",
112
+ "transformers": {
113
+ "routes/index.ts": ["@renr/parcel-plugin-rsc-router", "..."]
114
+ }
115
+ }
116
+ ```
117
+
118
+ `package.json`:
119
+
120
+ ```json
121
+ {
122
+ "source": "routes/index.ts",
123
+ "@renr/parcel-plugin-rsc-router": {
124
+ "source": "src/pages/**/*.{tsx,mdx}",
125
+ "output": "routes/index.ts"
126
+ },
127
+ "targets": {
128
+ "default": {
129
+ "context": "react-server",
130
+ "distDir": "dist"
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ ## What It Generates
137
+
138
+ On each build and during watch mode, the native plugin scans your page files and produces:
139
+
140
+ 1. **`flatRoutes`**: A flat array of all route definitions conforming to `RouteData[]`.
141
+ 2. **`routeTree`**: A nested tree structure with parent-child relationships and `children` arrays (`RouteNode`).
142
+ 3. **`routesByPage`**: A typed lookup dictionary mapping HTML file paths to their route objects.
143
+ 4. **TypeScript Module Augmentation**: Augments `App.Routes` in `@renr/parcel-rsc-router` so all paths passed to `<Link to="...">` and `useRouter().navigate(...)` are strictly type-checked.
144
+ 5. **Static Prerendered Output**: Writes `.html` and `.rsc` files for every route into your target `distDir` after bundling succeeds (using `oxfmt` in the standalone `parcel-rsc-routes` CLI / `generateRoutes` API, and native Rust formatting in Parcel builds).
145
+
146
+ ## License
147
+
148
+ MIT
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ import { generateRoutes } from "./generate-routes.mjs";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import { parseArgs } from "util";
6
+ //#region src/cli.ts
7
+ const origin = "@renr/parcel-plugin-rsc-router";
8
+ function isRoutesEntry(source) {
9
+ return source === "routes.ts" || source.endsWith("/routes.ts") || source.endsWith("\\routes.ts");
10
+ }
11
+ function loadParcelRcConfig(rootDir) {
12
+ const parcelRcPath = path.join(rootDir, ".parcelrc");
13
+ if (!fs.existsSync(parcelRcPath)) return;
14
+ try {
15
+ const raw = JSON.parse(fs.readFileSync(parcelRcPath, "utf-8"));
16
+ if (Array.isArray(raw.reporters)) {
17
+ for (const entry of raw.reporters) if (typeof entry === "object" && entry !== null && entry.plugin === origin && entry.config) return entry.config;
18
+ }
19
+ } catch (_unused) {}
20
+ }
21
+ function loadPackageConfig(rootDir) {
22
+ const pkgPath = path.join(rootDir, "package.json");
23
+ if (!fs.existsSync(pkgPath)) return;
24
+ try {
25
+ return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
26
+ } catch (_unused2) {
27
+ return;
28
+ }
29
+ }
30
+ async function main() {
31
+ var _ref, _ref2, _ref3, _pkgConfig$origin, _ref4, _ref5, _pkgConfig$origin2;
32
+ const { values } = parseArgs({
33
+ options: {
34
+ source: {
35
+ type: "string",
36
+ short: "s"
37
+ },
38
+ output: {
39
+ type: "string",
40
+ short: "o"
41
+ },
42
+ root: {
43
+ type: "string",
44
+ short: "r"
45
+ }
46
+ },
47
+ strict: false
48
+ });
49
+ const rootDir = typeof values.root === "string" ? path.resolve(process.cwd(), values.root) : process.cwd();
50
+ const rcConfig = loadParcelRcConfig(rootDir);
51
+ const pkgConfig = loadPackageConfig(rootDir);
52
+ const fallbackPkgSource = typeof (pkgConfig === null || pkgConfig === void 0 ? void 0 : pkgConfig.source) === "string" && !isRoutesEntry(pkgConfig.source) ? pkgConfig.source : void 0;
53
+ const source = (_ref = (_ref2 = (_ref3 = typeof values.source === "string" ? values.source : void 0) !== null && _ref3 !== void 0 ? _ref3 : rcConfig === null || rcConfig === void 0 ? void 0 : rcConfig.source) !== null && _ref2 !== void 0 ? _ref2 : pkgConfig === null || pkgConfig === void 0 || (_pkgConfig$origin = pkgConfig[origin]) === null || _pkgConfig$origin === void 0 ? void 0 : _pkgConfig$origin.source) !== null && _ref !== void 0 ? _ref : fallbackPkgSource;
54
+ const output = (_ref4 = (_ref5 = typeof values.output === "string" ? values.output : void 0) !== null && _ref5 !== void 0 ? _ref5 : rcConfig === null || rcConfig === void 0 ? void 0 : rcConfig.output) !== null && _ref4 !== void 0 ? _ref4 : pkgConfig === null || pkgConfig === void 0 || (_pkgConfig$origin2 = pkgConfig[origin]) === null || _pkgConfig$origin2 === void 0 ? void 0 : _pkgConfig$origin2.output;
55
+ if (!source) throw new Error(`No route source found in .parcelrc or package.json under "${origin}".`);
56
+ await generateRoutes({
57
+ pagesPattern: source,
58
+ rootDir,
59
+ outputPath: output,
60
+ log: console.info
61
+ });
62
+ }
63
+ main().catch((error) => {
64
+ console.error(error instanceof Error ? error.message : String(error));
65
+ process.exit(1);
66
+ });
67
+ //#endregion
68
+ export {};
69
+
70
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"fs\";\nimport path from \"path\";\nimport { parseArgs } from \"util\";\nimport {\n generateRoutes,\n type ReporterPluginConfig,\n} from \"./generate-routes.js\";\n\nconst origin = \"@renr/parcel-plugin-rsc-router\";\n\ninterface PackageConfig {\n source?: string | string[];\n [origin]?: ReporterPluginConfig;\n}\n\nfunction isRoutesEntry(source: string): boolean {\n return (\n source === \"routes.ts\" ||\n source.endsWith(\"/routes.ts\") ||\n source.endsWith(\"\\\\routes.ts\")\n );\n}\n\nfunction loadParcelRcConfig(rootDir: string): ReporterPluginConfig | undefined {\n const parcelRcPath = path.join(rootDir, \".parcelrc\");\n if (!fs.existsSync(parcelRcPath)) {\n return undefined;\n }\n try {\n const raw = JSON.parse(fs.readFileSync(parcelRcPath, \"utf-8\")) as {\n reporters?: Array<\n string | { plugin?: string; config?: ReporterPluginConfig }\n >;\n };\n if (Array.isArray(raw.reporters)) {\n for (const entry of raw.reporters) {\n if (\n typeof entry === \"object\" &&\n entry !== null &&\n entry.plugin === origin &&\n entry.config\n ) {\n return entry.config;\n }\n }\n }\n } catch {\n // ignore parse errors\n }\n return undefined;\n}\n\nfunction loadPackageConfig(rootDir: string): PackageConfig | undefined {\n const pkgPath = path.join(rootDir, \"package.json\");\n if (!fs.existsSync(pkgPath)) {\n return undefined;\n }\n try {\n return JSON.parse(fs.readFileSync(pkgPath, \"utf-8\")) as PackageConfig;\n } catch {\n return undefined;\n }\n}\n\nasync function main() {\n const { values } = parseArgs({\n options: {\n source: { type: \"string\", short: \"s\" },\n output: { type: \"string\", short: \"o\" },\n root: { type: \"string\", short: \"r\" },\n },\n strict: false,\n });\n\n const rootDir =\n typeof values.root === \"string\"\n ? path.resolve(process.cwd(), values.root)\n : process.cwd();\n\n const rcConfig = loadParcelRcConfig(rootDir);\n const pkgConfig = loadPackageConfig(rootDir);\n\n const fallbackPkgSource =\n typeof pkgConfig?.source === \"string\" && !isRoutesEntry(pkgConfig.source)\n ? pkgConfig.source\n : undefined;\n\n const source =\n (typeof values.source === \"string\" ? values.source : undefined) ??\n rcConfig?.source ??\n pkgConfig?.[origin]?.source ??\n fallbackPkgSource;\n\n const output =\n (typeof values.output === \"string\" ? values.output : undefined) ??\n rcConfig?.output ??\n pkgConfig?.[origin]?.output;\n\n if (!source) {\n throw new Error(\n `No route source found in .parcelrc or package.json under \"${origin}\".`\n );\n }\n\n await generateRoutes({\n pagesPattern: source,\n rootDir,\n outputPath: output,\n log: console.info,\n });\n}\n\nmain().catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n});\n"],"mappings":";;;;;;AASA,MAAM,SAAS;AAOf,SAAS,cAAc,QAAyB;CAC9C,OACE,WAAW,eACX,OAAO,SAAS,YAAY,KAC5B,OAAO,SAAS,aAAa;AAEjC;AAEA,SAAS,mBAAmB,SAAmD;CAC7E,MAAM,eAAe,KAAK,KAAK,SAAS,WAAW;CACnD,IAAI,CAAC,GAAG,WAAW,YAAY,GAC7B;CAEF,IAAI;EACF,MAAM,MAAM,KAAK,MAAM,GAAG,aAAa,cAAc,OAAO,CAAC;EAK7D,IAAI,MAAM,QAAQ,IAAI,SAAS,GACxB;QAAA,MAAM,SAAS,IAAI,WACtB,IACE,OAAO,UAAU,YACjB,UAAU,QACV,MAAM,WAAW,UACjB,MAAM,QAEN,OAAO,MAAM;EAAA;CAIrB,SAAA,SAAQ,CAER;AAEF;AAEA,SAAS,kBAAkB,SAA4C;CACrE,MAAM,UAAU,KAAK,KAAK,SAAS,cAAc;CACjD,IAAI,CAAC,GAAG,WAAW,OAAO,GACxB;CAEF,IAAI;EACF,OAAO,KAAK,MAAM,GAAG,aAAa,SAAS,OAAO,CAAC;CACrD,SAAA,UAAQ;EACN;CACF;AACF;AAEA,eAAe,OAAO;;CACpB,MAAM,EAAE,WAAW,UAAU;EAC3B,SAAS;GACP,QAAQ;IAAE,MAAM;IAAU,OAAO;GAAI;GACrC,QAAQ;IAAE,MAAM;IAAU,OAAO;GAAI;GACrC,MAAM;IAAE,MAAM;IAAU,OAAO;GAAI;EACrC;EACA,QAAQ;CACV,CAAC;CAED,MAAM,UACJ,OAAO,OAAO,SAAS,WACnB,KAAK,QAAQ,QAAQ,IAAI,GAAG,OAAO,IAAI,IACvC,QAAQ,IAAI;CAElB,MAAM,WAAW,mBAAmB,OAAO;CAC3C,MAAM,YAAY,kBAAkB,OAAO;CAE3C,MAAM,oBACJ,QAAA,cAAA,QAAA,cAAA,KAAA,IAAA,KAAA,IAAO,UAAW,YAAW,YAAY,CAAC,cAAc,UAAU,MAAM,IACpE,UAAU,SACV,KAAA;CAEN,MAAM,UAAA,QAAA,SAAA,QACH,OAAO,OAAO,WAAW,WAAW,OAAO,SAAS,KAAA,OAAA,QAAA,UAAA,KAAA,IAAA,QAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IACrD,SAAU,YAAA,QAAA,UAAA,KAAA,IAAA,QAAA,cAAA,QAAA,cAAA,KAAA,MAAA,oBACV,UAAY,aAAA,QAAA,sBAAA,KAAA,IAAA,KAAA,IAAA,kBAAS,YAAA,QAAA,SAAA,KAAA,IAAA,OACrB;CAEF,MAAM,UAAA,SAAA,QACH,OAAO,OAAO,WAAW,WAAW,OAAO,SAAS,KAAA,OAAA,QAAA,UAAA,KAAA,IAAA,QAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IACrD,SAAU,YAAA,QAAA,UAAA,KAAA,IAAA,QAAA,cAAA,QAAA,cAAA,KAAA,MAAA,qBACV,UAAY,aAAA,QAAA,uBAAA,KAAA,IAAA,KAAA,IAAA,mBAAS;CAEvB,IAAI,CAAC,QACH,MAAM,IAAI,MACR,6DAA6D,OAAO,GACtE;CAGF,MAAM,eAAe;EACnB,cAAc;EACd;EACA,YAAY;EACZ,KAAK,QAAQ;CACf,CAAC;AACH;AAEA,KAAK,CAAC,CAAC,OAAO,UAAmB;CAC/B,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,KAAK,CAAC;AAChB,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { FormatConfig } from "oxfmt";
2
+ import { RouteData, RouteNode } from "@renr/parcel-rsc-router";
3
+ //#region src/generate-routes.d.ts
4
+ export type GeneratedRouteNode = RouteNode<string, string, string>;
5
+ export type GeneratedRouteData = RouteData<string, string, string>;
6
+ export declare const pageFilesCache: Map<string, number>;
7
+ export declare const lastGeneratedContentCache: Map<string, {
8
+ unformatted: string;
9
+ formatted: string;
10
+ }>;
11
+ export declare const formattingConfigCache: Map<string, FormatConfig | null>;
12
+ export declare function clearRouteCaches(): void;
13
+ export declare function buildRouteTree(filePaths: string[], _log?: (message: string) => void): GeneratedRouteNode;
14
+ /** flatten a RouteNode tree into a list of RouteData pages */
15
+ export declare function flattenRouteTree(node: GeneratedRouteNode): GeneratedRouteData[];
16
+ /** generate a lookup of routes by their html path (parcel RSC's Page['url']) */
17
+ export declare function getRoutesByPagePath(pages: GeneratedRouteData[]): RouteData<string, string, string>;
18
+ export interface ReporterPluginConfig {
19
+ source?: string;
20
+ output?: string;
21
+ }
22
+ export interface GenerateRoutesOptions {
23
+ pagesPattern: string;
24
+ rootDir: string;
25
+ outputPath?: string;
26
+ log?: (message: string) => void;
27
+ }
28
+ /** generates a routes file in the `outputPath` (defaulting to routes.ts in `rootDir`) from pages found in `pagesPattern` */
29
+ export declare function generateRoutes({ pagesPattern, rootDir, outputPath, log }: GenerateRoutesOptions): Promise<void>;
30
+ export declare function resolveFormattingConfig(filePath: string): Promise<FormatConfig | undefined>;
31
+ export declare const resolveOxfmtConfig: typeof resolveFormattingConfig;
32
+ export declare function resolveOutputPath(rootDir: string, outputPath?: string): string;
33
+ export declare function removeExtension(file: string): string;
34
+ //#endregion
35
+ //# sourceMappingURL=generate-routes.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-routes.d.mts","names":[],"sources":["../../src/generate-routes.ts"],"mappings":";;;YAOY,qBAAqB;YACrB,qBAAqB;qBAapB,gBAAc;qBACd,2BAAyB;EAErB;EAAmB;;qBAEvB,uBAAqB,YAAA;wBAElB;wBAMA,eACd,qBACA,QAAQ,2BACP;;wBAuGa,iBACd,MAAM,qBACL;;wBAoBa,oBAAoB,OAAO,uBAAoB;iBAU9C;EACf;EACA;;iBAGe;EACf;EACA;EACA;EACA,OAAO;;;wBAIa,iBACpB,cACA,SACA,YACA,OACC,wBAAqB;wBAoMF,wBACpB,mBACC,QAAQ;qBA+CE,2BAAkB;wBAEf,kBACd,iBACA;wBA4Gc,gBAAgB"}
@@ -0,0 +1,338 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { pathToFileURL } from "url";
4
+ import { format } from "oxfmt";
5
+ import { glob } from "tinyglobby";
6
+ //#region src/generate-routes.ts
7
+ const routerPackageName = "@renr/parcel-rsc-router";
8
+ const packageName = "@renr/parcel-plugin-rsc-router";
9
+ const legacyPackageName = "@renr/parcel-reporter-rsc-router";
10
+ const allowedPageFileExtensions = [
11
+ ".tsx",
12
+ ".mdx",
13
+ ".ts",
14
+ ".jsx",
15
+ ".js",
16
+ ".md"
17
+ ];
18
+ const disallowedCharsRegex = /[\s\\?#:*<>|!$%]/;
19
+ const pageFilesCache = /* @__PURE__ */ new Map();
20
+ const lastGeneratedContentCache = /* @__PURE__ */ new Map();
21
+ const formattingConfigCache = /* @__PURE__ */ new Map();
22
+ function clearRouteCaches() {
23
+ pageFilesCache.clear();
24
+ lastGeneratedContentCache.clear();
25
+ formattingConfigCache.clear();
26
+ }
27
+ function buildRouteTree(filePaths, _log) {
28
+ const rootNode = {
29
+ path: "/",
30
+ slug: "index",
31
+ html: "/index.html",
32
+ rsc: "/index.rsc",
33
+ children: []
34
+ };
35
+ let foundRoot = false;
36
+ const nodes = filePaths.filter((filePath) => {
37
+ const match = disallowedCharsRegex.exec(filePath);
38
+ if (match) throw new Error(`File path "${filePath}" contains unsupported character: "${match[0]}".`);
39
+ if (removeExtension(filePath) === "index") {
40
+ foundRoot = true;
41
+ return false;
42
+ }
43
+ return true;
44
+ }).map((filePath) => createRouteNode(filePath));
45
+ if (!foundRoot) throw new Error(`No root file found. Please ensure there is an index file in the pages directory root.`);
46
+ nodes.sort((a, b) => a.path.split("/").length - b.path.split("/").length);
47
+ for (const node of nodes) {
48
+ let bestParent = rootNode;
49
+ let bestParentPathLength = 0;
50
+ function findParent(potentialParent) {
51
+ let isPotentialParent = false;
52
+ if (potentialParent.path === "/") isPotentialParent = node.path !== "/";
53
+ else isPotentialParent = node.path.startsWith(potentialParent.path + "/");
54
+ if (isPotentialParent && node.path !== potentialParent.path) {
55
+ if (potentialParent.path.length > bestParentPathLength) {
56
+ bestParentPathLength = potentialParent.path.length;
57
+ bestParent = potentialParent;
58
+ }
59
+ }
60
+ for (const child of potentialParent.children) findParent(child);
61
+ }
62
+ findParent(rootNode);
63
+ bestParent.children.push(node);
64
+ bestParent.children.sort((a, b) => a.path.localeCompare(b.path));
65
+ }
66
+ return rootNode;
67
+ }
68
+ /**
69
+ * create a RouteNode from a file path
70
+ */
71
+ function createRouteNode(filePath) {
72
+ const path = normalizeIndex(removeExtension(filePath));
73
+ return {
74
+ path: `/${path}`,
75
+ slug: path.split("/").pop() || "index",
76
+ html: convertFilePathToType(filePath, "html"),
77
+ rsc: convertFilePathToType(filePath, "rsc"),
78
+ children: []
79
+ };
80
+ }
81
+ function normalizeIndex(filePath) {
82
+ return filePath.endsWith("/index") ? filePath.substring(0, filePath.length - 6) : filePath;
83
+ }
84
+ /** flatten a RouteNode tree into a list of RouteData pages */
85
+ function flattenRouteTree(node) {
86
+ const pages = [];
87
+ if (node.rsc && node.html) pages.push({
88
+ path: node.path,
89
+ slug: node.slug,
90
+ rsc: node.rsc,
91
+ html: node.html
92
+ });
93
+ for (const child of node.children) pages.push(...flattenRouteTree(child));
94
+ return pages;
95
+ }
96
+ /** generate a lookup of routes by their html path (parcel RSC's Page['url']) */
97
+ function getRoutesByPagePath(pages) {
98
+ return pages.reduce((acc, page) => {
99
+ acc[page.html] = page;
100
+ return acc;
101
+ }, {});
102
+ }
103
+ /** generates a routes file in the `outputPath` (defaulting to routes.ts in `rootDir`) from pages found in `pagesPattern` */
104
+ async function generateRoutes({ pagesPattern, rootDir, outputPath = "routes.ts", log = console.log }) {
105
+ const resolvedPagesDir = path.resolve(rootDir, getBasePathFromGlob(pagesPattern));
106
+ if (!fs.existsSync(resolvedPagesDir)) throw new Error(`Pages directory "${resolvedPagesDir}" does not exist.`);
107
+ const files = (await getFilesAndNormalizePaths(pagesPattern, rootDir)).sort((a, b) => a.localeCompare(b));
108
+ let hasChanges = false;
109
+ if (files.length !== pageFilesCache.size) hasChanges = true;
110
+ else for (const file of files) {
111
+ var _pageFilesCache$get;
112
+ const fullPath = path.resolve(rootDir, getBasePathFromGlob(pagesPattern), file);
113
+ const mtime = (await fs.promises.stat(fullPath)).mtimeMs;
114
+ if (((_pageFilesCache$get = pageFilesCache.get(fullPath)) !== null && _pageFilesCache$get !== void 0 ? _pageFilesCache$get : pageFilesCache.get(file)) !== mtime) {
115
+ hasChanges = true;
116
+ break;
117
+ }
118
+ }
119
+ const routesTypePath = resolveOutputPath(rootDir, outputPath);
120
+ if (!hasChanges && fs.existsSync(routesTypePath)) return;
121
+ const routeTree = buildRouteTree(files);
122
+ const pages = flattenRouteTree(routeTree);
123
+ const routesByPage = getRoutesByPagePath(pages);
124
+ const routesType = buildRoutesType(pages);
125
+ const autoGeneratedString = `// This file is auto-generated by ${packageName}.`;
126
+ const legacyAutoGeneratedString = `// This file is auto-generated by ${legacyPackageName}.`;
127
+ const routesTypeContent = `/* eslint-disable */
128
+
129
+ ${autoGeneratedString}
130
+ // Do not edit it manually.
131
+ // You should also exclude it from your linting/formatting rules.
132
+
133
+ import type {
134
+ App,
135
+ Page,
136
+ PageProps,
137
+ RouteData,
138
+ RouteHtml,
139
+ RouteNode,
140
+ RoutePath,
141
+ } from '${routerPackageName}';
142
+
143
+ export type { Page, PageProps, RouteHtml, RoutePath };
144
+
145
+ ${routesType}
146
+
147
+ export const flatRoutes = ${JSON.stringify(pages, null, 2)} as const satisfies RouteData[];
148
+
149
+ export const routeTree = ${JSON.stringify(routeTree, null, 2)} as const satisfies RouteNode;
150
+
151
+ // lookup routes by PageProps url
152
+ export const routesByPage = ${JSON.stringify(routesByPage, null, 2)} satisfies {
153
+ [Key in keyof App.Routes as App.Routes[Key]["html"]]: App.Routes[Key];
154
+ };
155
+ `;
156
+ const outputDir = path.dirname(routesTypePath);
157
+ if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
158
+ let oldContent = null;
159
+ if (fs.existsSync(routesTypePath)) {
160
+ oldContent = fs.readFileSync(routesTypePath, "utf-8");
161
+ if (!oldContent.includes(autoGeneratedString) && !oldContent.includes(legacyAutoGeneratedString)) throw new Error(`Cannot overwrite existing routes file at "${routesTypePath}" because it was not generated by ${packageName}. \n Please remove the file and try again.`);
162
+ }
163
+ const cached = lastGeneratedContentCache.get(routesTypePath);
164
+ if (cached && cached.unformatted === routesTypeContent && oldContent !== null && cached.formatted === oldContent) {
165
+ await updatePageFilesCache(files, rootDir, pagesPattern);
166
+ log === null || log === void 0 || log(`✅ ${path.basename(routesTypePath)} is up to date.`);
167
+ return;
168
+ }
169
+ const formattingConfig = await resolveFormattingConfig(routesTypePath);
170
+ const { code: formatted } = await format(routesTypePath, routesTypeContent, formattingConfig);
171
+ if (oldContent === formatted) {
172
+ lastGeneratedContentCache.set(routesTypePath, {
173
+ unformatted: routesTypeContent,
174
+ formatted
175
+ });
176
+ await updatePageFilesCache(files, rootDir, pagesPattern);
177
+ log === null || log === void 0 || log(`✅ ${path.basename(routesTypePath)} is up to date.`);
178
+ return;
179
+ }
180
+ fs.writeFileSync(routesTypePath, formatted, "utf-8");
181
+ lastGeneratedContentCache.set(routesTypePath, {
182
+ unformatted: routesTypeContent,
183
+ formatted
184
+ });
185
+ await updatePageFilesCache(files, rootDir, pagesPattern);
186
+ log === null || log === void 0 || log(`✅ Routes generated at ${normalizePathToPosix(routesTypePath)} (${pages.length} pages)`);
187
+ }
188
+ async function updatePageFilesCache(files, rootDir, pagesPattern) {
189
+ pageFilesCache.clear();
190
+ const basePath = getBasePathFromGlob(pagesPattern);
191
+ for (const file of files) {
192
+ const fullPath = path.resolve(rootDir, basePath, file);
193
+ try {
194
+ const stat = await fs.promises.stat(fullPath);
195
+ pageFilesCache.set(fullPath, stat.mtimeMs);
196
+ } catch (_unused) {}
197
+ }
198
+ }
199
+ async function loadConfigFile(filePath) {
200
+ const ext = path.extname(filePath);
201
+ if ([
202
+ ".ts",
203
+ ".mts",
204
+ ".js",
205
+ ".mjs",
206
+ ".cjs"
207
+ ].includes(ext)) try {
208
+ var _mod$default;
209
+ const mod = await import(pathToFileURL(filePath).href);
210
+ let config = (_mod$default = mod.default) !== null && _mod$default !== void 0 ? _mod$default : mod;
211
+ if (typeof config === "function") config = await config();
212
+ if (typeof config === "object" && config !== null) return config;
213
+ } catch (_unused2) {
214
+ return null;
215
+ }
216
+ try {
217
+ const content = await fs.promises.readFile(filePath, "utf-8");
218
+ return JSON.parse(content);
219
+ } catch (_unused3) {
220
+ return null;
221
+ }
222
+ }
223
+ const CONFIG_FILES = [
224
+ "oxfmt.config.ts",
225
+ "oxfmt.config.js",
226
+ "oxfmt.config.mjs",
227
+ ".oxfmtrc.json",
228
+ ".oxfmtrc",
229
+ "prettier.config.js",
230
+ "prettier.config.ts",
231
+ "prettier.config.mjs",
232
+ ".prettierrc.json",
233
+ ".prettierrc"
234
+ ];
235
+ async function resolveFormattingConfig(filePath) {
236
+ const dirPath = path.dirname(path.resolve(filePath));
237
+ if (formattingConfigCache.has(dirPath)) {
238
+ var _formattingConfigCach;
239
+ return (_formattingConfigCach = formattingConfigCache.get(dirPath)) !== null && _formattingConfigCach !== void 0 ? _formattingConfigCach : void 0;
240
+ }
241
+ let dir = dirPath;
242
+ while (true) {
243
+ for (const name of CONFIG_FILES) {
244
+ const candidate = path.join(dir, name);
245
+ if (fs.existsSync(candidate)) {
246
+ const loaded = await loadConfigFile(candidate);
247
+ if (loaded) {
248
+ formattingConfigCache.set(dirPath, loaded);
249
+ return loaded;
250
+ }
251
+ }
252
+ }
253
+ const pkgPath = path.join(dir, "package.json");
254
+ if (fs.existsSync(pkgPath)) try {
255
+ const content = await fs.promises.readFile(pkgPath, "utf-8");
256
+ const pkg = JSON.parse(content);
257
+ const config = (pkg === null || pkg === void 0 ? void 0 : pkg.oxfmt) || (pkg === null || pkg === void 0 ? void 0 : pkg.prettier);
258
+ if (config && typeof config === "object") {
259
+ formattingConfigCache.set(dirPath, config);
260
+ return config;
261
+ }
262
+ } catch (_unused4) {}
263
+ const parent = path.dirname(dir);
264
+ if (parent === dir) break;
265
+ dir = parent;
266
+ }
267
+ formattingConfigCache.set(dirPath, null);
268
+ }
269
+ const resolveOxfmtConfig = resolveFormattingConfig;
270
+ function resolveOutputPath(rootDir, outputPath = "routes.ts") {
271
+ const resolved = path.resolve(rootDir, outputPath);
272
+ if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) return path.join(resolved, "routes.ts");
273
+ if (path.extname(resolved) === "") return path.join(resolved, "routes.ts");
274
+ return resolved;
275
+ }
276
+ /** normalize file paths to use posix style */
277
+ async function getFilesAndNormalizePaths(pagesPattern, rootDir) {
278
+ const basePath = getBasePathFromGlob(pagesPattern);
279
+ const files = (await glob(pagesPattern, { cwd: rootDir })).filter((file) => {
280
+ if (typeof file !== "string") throw new Error("expected file to be a string");
281
+ const filePath = path.join(rootDir, file);
282
+ return fs.statSync(filePath).isFile() && isAllowedFile(filePath);
283
+ }).map((file) => {
284
+ return normalizePathToPosix(file.substring(basePath.length));
285
+ });
286
+ if (files.length === 0) throw new Error(`No page files found matching pattern "${pagesPattern}" in directory "${rootDir}"`);
287
+ return files;
288
+ }
289
+ function normalizePathToPosix(filePath) {
290
+ return filePath.replace(/\\/g, "/");
291
+ }
292
+ /**
293
+ * Given a glob, returns the part of the path before the first glob pattern
294
+ *
295
+ * eg: `src/pages/**\/*.tsx -> src/pages/`
296
+ **/
297
+ function getBasePathFromGlob(globPattern) {
298
+ const magicChars = [
299
+ "*",
300
+ "?",
301
+ "{",
302
+ "["
303
+ ];
304
+ let basePath = globPattern;
305
+ for (const char of magicChars) {
306
+ const index = basePath.indexOf(char);
307
+ if (index !== -1) basePath = basePath.substring(0, index);
308
+ }
309
+ return basePath;
310
+ }
311
+ function buildRoutesType(pages) {
312
+ const routes = pages.map((page) => {
313
+ const { path, slug, rsc, html } = page;
314
+ return `'${path}': { slug: '${slug}', path:'${path}', rsc: '${rsc}', html: '${html}' };`;
315
+ });
316
+ return `
317
+ declare module "${routerPackageName}" {
318
+ namespace App {
319
+ interface Routes {
320
+ ${routes.join("\n")}
321
+ }
322
+ }
323
+ }`;
324
+ }
325
+ const extensionRegex = new RegExp(`(${allowedPageFileExtensions.join("|")})$`);
326
+ function convertFilePathToType(fileName, fileTypeTo) {
327
+ return `/${fileName.replace(extensionRegex, "")}.${fileTypeTo}`;
328
+ }
329
+ function isAllowedFile(file) {
330
+ return allowedPageFileExtensions.some((ext) => file.endsWith(ext));
331
+ }
332
+ function removeExtension(file) {
333
+ return file.replace(extensionRegex, "");
334
+ }
335
+ //#endregion
336
+ export { buildRouteTree, clearRouteCaches, flattenRouteTree, formattingConfigCache, generateRoutes, getRoutesByPagePath, lastGeneratedContentCache, pageFilesCache, removeExtension, resolveFormattingConfig, resolveOutputPath, resolveOxfmtConfig };
337
+
338
+ //# sourceMappingURL=generate-routes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-routes.mjs","names":[],"sources":["../../src/generate-routes.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport { format, type FormatConfig } from \"oxfmt\";\nimport type { RouteNode, RouteData } from \"@renr/parcel-rsc-router\";\nimport { glob } from \"tinyglobby\";\n\nexport type GeneratedRouteNode = RouteNode<string, string, string>;\nexport type GeneratedRouteData = RouteData<string, string, string>;\n\nconst routerPackageName = \"@renr/parcel-rsc-router\";\nconst packageName = \"@renr/parcel-plugin-rsc-router\";\nconst legacyPackageName = \"@renr/parcel-reporter-rsc-router\";\nconst allowedPageFileExtensions = [\".tsx\", \".mdx\", \".ts\", \".jsx\", \".js\", \".md\"];\n\n// we can't allow whitespace because parcel will bundle the file with the space rather than encoding it,\n// so we can't properly match it to the url (and/or there's a bug with how parcel's server resolves files with spaces?).\n// special chars \\ ? # : * < > | ! $ % don't make sense to be in file names/urls either.\nconst disallowedCharsRegex = /[\\s\\\\?#:*<>|!$%]/;\n\n// cache for watch mode across buildStart events\nexport const pageFilesCache = new Map<string, number>();\nexport const lastGeneratedContentCache = new Map<\n string,\n { unformatted: string; formatted: string }\n>();\nexport const formattingConfigCache = new Map<string, FormatConfig | null>();\n\nexport function clearRouteCaches() {\n pageFilesCache.clear();\n lastGeneratedContentCache.clear();\n formattingConfigCache.clear();\n}\n\nexport function buildRouteTree(\n filePaths: string[],\n _log?: (message: string) => void\n): GeneratedRouteNode {\n const rootNode: GeneratedRouteNode = {\n path: \"/\",\n slug: \"index\",\n html: \"/index.html\",\n rsc: \"/index.rsc\",\n children: [],\n };\n\n let foundRoot = false;\n\n const nodes = filePaths\n .filter((filePath) => {\n const match = disallowedCharsRegex.exec(filePath);\n if (match) {\n throw new Error(\n `File path \"${filePath}\" contains unsupported character: \"${match[0]}\".`\n );\n }\n\n if (removeExtension(filePath) === \"index\") {\n foundRoot = true;\n // skip the the root - `rootNode` is already created as our initial node\n return false;\n }\n\n return true;\n })\n .map((filePath) => createRouteNode(filePath));\n\n if (!foundRoot) {\n throw new Error(\n `No root file found. Please ensure there is an index file in the pages directory root.`\n );\n }\n\n // sort nodes by path depth, to make it easier to find parents\n nodes.sort((a, b) => a.path.split(\"/\").length - b.path.split(\"/\").length);\n\n for (const node of nodes) {\n let bestParent = rootNode;\n // track the length of the best parent's path\n let bestParentPathLength = 0;\n\n // recursively find the parent this node should be inserted under\n function findParent(potentialParent: GeneratedRouteNode) {\n let isPotentialParent = false;\n if (potentialParent.path === \"/\") {\n // if potential parent is root, any node that is not root itself is a potential child\n isPotentialParent = node.path !== \"/\";\n } else {\n // for non-root potential parents, the node's path must start with parent's path segment\n isPotentialParent = node.path.startsWith(potentialParent.path + \"/\");\n }\n\n if (isPotentialParent && node.path !== potentialParent.path) {\n // if the potential parent's path is longer than the current best, it's a better match\n if (potentialParent.path.length > bestParentPathLength) {\n bestParentPathLength = potentialParent.path.length;\n bestParent = potentialParent;\n }\n }\n\n // recursively search in children of the potential parent\n for (const child of potentialParent.children) {\n findParent(child);\n }\n }\n\n // start searching from the root node\n findParent(rootNode);\n // insert the node under the best parent found\n bestParent.children.push(node);\n // keep children sorted by path\n bestParent.children.sort((a, b) => a.path.localeCompare(b.path));\n }\n\n return rootNode;\n}\n/**\n * create a RouteNode from a file path\n */\nfunction createRouteNode(filePath: string): GeneratedRouteNode {\n const path = normalizeIndex(removeExtension(filePath));\n\n return {\n path: `/${path}`,\n slug: path.split(\"/\").pop() || \"index\",\n html: convertFilePathToType(filePath, \"html\"),\n rsc: convertFilePathToType(filePath, \"rsc\"),\n children: [],\n };\n}\n\nfunction normalizeIndex(filePath: string): string {\n // remove the trailing /index for paths that are index files\n // e.g /blog/index becomes /blog\n return filePath.endsWith(\"/index\")\n ? filePath.substring(0, filePath.length - \"/index\".length)\n : filePath;\n}\n\n/** flatten a RouteNode tree into a list of RouteData pages */\nexport function flattenRouteTree(\n node: GeneratedRouteNode\n): GeneratedRouteData[] {\n const pages: GeneratedRouteData[] = [];\n\n if (node.rsc && node.html) {\n pages.push({\n path: node.path,\n slug: node.slug,\n rsc: node.rsc,\n html: node.html,\n });\n }\n\n for (const child of node.children) {\n pages.push(...flattenRouteTree(child));\n }\n\n return pages;\n}\n\n/** generate a lookup of routes by their html path (parcel RSC's Page['url']) */\nexport function getRoutesByPagePath(pages: GeneratedRouteData[]) {\n return pages.reduce(\n (acc, page) => {\n acc[page.html] = page;\n return acc;\n },\n {} as Record<string, GeneratedRouteData>\n );\n}\n\nexport interface ReporterPluginConfig {\n source?: string;\n output?: string;\n}\n\nexport interface GenerateRoutesOptions {\n pagesPattern: string;\n rootDir: string;\n outputPath?: string;\n log?: (message: string) => void;\n}\n\n/** generates a routes file in the `outputPath` (defaulting to routes.ts in `rootDir`) from pages found in `pagesPattern` */\nexport async function generateRoutes({\n pagesPattern,\n rootDir,\n outputPath = \"routes.ts\",\n log = console.log,\n}: GenerateRoutesOptions) {\n const resolvedPagesDir = path.resolve(\n rootDir,\n getBasePathFromGlob(pagesPattern)\n );\n\n if (!fs.existsSync(resolvedPagesDir)) {\n throw new Error(`Pages directory \"${resolvedPagesDir}\" does not exist.`);\n }\n\n const files = (await getFilesAndNormalizePaths(pagesPattern, rootDir)).sort(\n (a, b) => a.localeCompare(b)\n );\n\n let hasChanges = false;\n if (files.length !== pageFilesCache.size) {\n hasChanges = true;\n } else {\n for (const file of files) {\n const fullPath = path.resolve(\n rootDir,\n getBasePathFromGlob(pagesPattern),\n file\n );\n const mtime = (await fs.promises.stat(fullPath)).mtimeMs;\n const cachedMtime =\n pageFilesCache.get(fullPath) ?? pageFilesCache.get(file);\n if (cachedMtime !== mtime) {\n hasChanges = true;\n break;\n }\n }\n }\n\n const routesTypePath = resolveOutputPath(rootDir, outputPath);\n if (!hasChanges && fs.existsSync(routesTypePath)) {\n // Fast path: nothing changed, skip tree generation, logging, and formatting\n return;\n }\n\n const routeTree = buildRouteTree(files);\n const pages = flattenRouteTree(routeTree);\n\n const routesByPage = getRoutesByPagePath(pages);\n\n const routesType = buildRoutesType(pages);\n\n const autoGeneratedString = `// This file is auto-generated by ${packageName}.`;\n const legacyAutoGeneratedString = `// This file is auto-generated by ${legacyPackageName}.`;\n const routesTypeContent = `/* eslint-disable */\n \n ${autoGeneratedString}\n // Do not edit it manually.\n // You should also exclude it from your linting/formatting rules.\n\n import type {\n App,\n Page,\n PageProps,\n RouteData,\n RouteHtml,\n RouteNode,\n RoutePath,\n } from '${routerPackageName}';\n\n export type { Page, PageProps, RouteHtml, RoutePath };\n\n ${routesType}\n\n export const flatRoutes = ${JSON.stringify(pages, null, 2)} as const satisfies RouteData[];\n\n export const routeTree = ${JSON.stringify(routeTree, null, 2)} as const satisfies RouteNode;\n\n // lookup routes by PageProps url\n export const routesByPage = ${JSON.stringify(routesByPage, null, 2)} satisfies {\n [Key in keyof App.Routes as App.Routes[Key][\"html\"]]: App.Routes[Key];\n };\n`;\n\n const outputDir = path.dirname(routesTypePath);\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n let oldContent: string | null = null;\n if (fs.existsSync(routesTypePath)) {\n oldContent = fs.readFileSync(routesTypePath, \"utf-8\");\n\n if (\n !oldContent.includes(autoGeneratedString) &&\n !oldContent.includes(legacyAutoGeneratedString)\n ) {\n throw new Error(\n `Cannot overwrite existing routes file at \"${routesTypePath}\" because it was not generated by ${packageName}. \\n Please remove the file and try again.`\n );\n }\n }\n\n const cached = lastGeneratedContentCache.get(routesTypePath);\n if (\n cached &&\n cached.unformatted === routesTypeContent &&\n oldContent !== null &&\n cached.formatted === oldContent\n ) {\n await updatePageFilesCache(files, rootDir, pagesPattern);\n log?.(`✅ ${path.basename(routesTypePath)} is up to date.`);\n return;\n }\n\n const formattingConfig = await resolveFormattingConfig(routesTypePath);\n const { code: formatted } = await format(\n routesTypePath,\n routesTypeContent,\n formattingConfig\n );\n\n if (oldContent === formatted) {\n lastGeneratedContentCache.set(routesTypePath, {\n unformatted: routesTypeContent,\n formatted,\n });\n await updatePageFilesCache(files, rootDir, pagesPattern);\n log?.(`✅ ${path.basename(routesTypePath)} is up to date.`);\n return;\n }\n\n fs.writeFileSync(routesTypePath, formatted, \"utf-8\");\n lastGeneratedContentCache.set(routesTypePath, {\n unformatted: routesTypeContent,\n formatted,\n });\n await updatePageFilesCache(files, rootDir, pagesPattern);\n\n log?.(\n `✅ Routes generated at ${normalizePathToPosix(routesTypePath)} (${pages.length} pages)`\n );\n}\n\nasync function updatePageFilesCache(\n files: string[],\n rootDir: string,\n pagesPattern: string\n) {\n pageFilesCache.clear();\n const basePath = getBasePathFromGlob(pagesPattern);\n for (const file of files) {\n const fullPath = path.resolve(rootDir, basePath, file);\n try {\n const stat = await fs.promises.stat(fullPath);\n pageFilesCache.set(fullPath, stat.mtimeMs);\n } catch {\n // file may not exist\n }\n }\n}\n\nasync function loadConfigFile(filePath: string): Promise<FormatConfig | null> {\n const ext = path.extname(filePath);\n if ([\".ts\", \".mts\", \".js\", \".mjs\", \".cjs\"].includes(ext)) {\n try {\n const fileUrl = pathToFileURL(filePath).href;\n const mod = await import(fileUrl);\n let config = mod.default ?? mod;\n if (typeof config === \"function\") {\n config = await config();\n }\n if (typeof config === \"object\" && config !== null) {\n return config as FormatConfig;\n }\n } catch {\n return null;\n }\n }\n\n try {\n const content = await fs.promises.readFile(filePath, \"utf-8\");\n return JSON.parse(content) as FormatConfig;\n } catch {\n return null;\n }\n}\n\nconst CONFIG_FILES = [\n \"oxfmt.config.ts\",\n \"oxfmt.config.js\",\n \"oxfmt.config.mjs\",\n \".oxfmtrc.json\",\n \".oxfmtrc\",\n \"prettier.config.js\",\n \"prettier.config.ts\",\n \"prettier.config.mjs\",\n \".prettierrc.json\",\n \".prettierrc\",\n];\n\nexport async function resolveFormattingConfig(\n filePath: string\n): Promise<FormatConfig | undefined> {\n const dirPath = path.dirname(path.resolve(filePath));\n if (formattingConfigCache.has(dirPath)) {\n return formattingConfigCache.get(dirPath) ?? undefined;\n }\n\n let dir = dirPath;\n while (true) {\n for (const name of CONFIG_FILES) {\n const candidate = path.join(dir, name);\n if (fs.existsSync(candidate)) {\n const loaded = await loadConfigFile(candidate);\n if (loaded) {\n formattingConfigCache.set(dirPath, loaded);\n return loaded;\n }\n }\n }\n\n const pkgPath = path.join(dir, \"package.json\");\n if (fs.existsSync(pkgPath)) {\n try {\n const content = await fs.promises.readFile(pkgPath, \"utf-8\");\n const pkg = JSON.parse(content);\n const config = (pkg?.oxfmt || pkg?.prettier) as\n | FormatConfig\n | undefined;\n if (config && typeof config === \"object\") {\n formattingConfigCache.set(dirPath, config);\n return config;\n }\n } catch {\n // ignore\n }\n }\n\n const parent = path.dirname(dir);\n if (parent === dir) {\n break;\n }\n dir = parent;\n }\n\n formattingConfigCache.set(dirPath, null);\n return undefined;\n}\n\nexport const resolveOxfmtConfig = resolveFormattingConfig;\n\nexport function resolveOutputPath(\n rootDir: string,\n outputPath: string = \"routes.ts\"\n): string {\n const resolved = path.resolve(rootDir, outputPath);\n if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {\n return path.join(resolved, \"routes.ts\");\n }\n if (path.extname(resolved) === \"\") {\n return path.join(resolved, \"routes.ts\");\n }\n return resolved;\n}\n\n/** normalize file paths to use posix style */\nasync function getFilesAndNormalizePaths(\n pagesPattern: string,\n rootDir: string\n) {\n const basePath = getBasePathFromGlob(pagesPattern);\n\n const files = (\n await glob(pagesPattern, {\n cwd: rootDir,\n })\n )\n .filter((file) => {\n if (typeof file !== \"string\") {\n throw new Error(\"expected file to be a string\");\n }\n\n const filePath = path.join(rootDir, file);\n\n return fs.statSync(filePath).isFile() && isAllowedFile(filePath);\n })\n .map((file) => {\n return normalizePathToPosix(\n file\n // remove the base path (src/pages/blog/index.tsx -> blog/index.tsx)\n .substring(basePath.length)\n );\n });\n\n if (files.length === 0) {\n throw new Error(\n `No page files found matching pattern \"${pagesPattern}\" in directory \"${rootDir}\"`\n );\n }\n\n return files;\n}\n\nfunction normalizePathToPosix(filePath: string): string {\n // normalize Windows paths to use forward slashes\n return filePath.replace(/\\\\/g, \"/\");\n}\n\n/**\n * Given a glob, returns the part of the path before the first glob pattern\n *\n * eg: `src/pages/**\\/*.tsx -> src/pages/`\n **/\nfunction getBasePathFromGlob(globPattern: string): string {\n // find the first occurrence of a glob character\n const magicChars = [\"*\", \"?\", \"{\", \"[\"];\n let basePath = globPattern;\n\n for (const char of magicChars) {\n const index = basePath.indexOf(char);\n if (index !== -1) {\n basePath = basePath.substring(0, index);\n }\n }\n\n return basePath;\n}\n\nfunction buildRoutesType(pages: GeneratedRouteData[]) {\n const routes = pages.map((page) => {\n const { path, slug, rsc, html } = page;\n return `'${path}': { slug: '${slug}', path:'${path}', rsc: '${rsc}', html: '${html}' };`;\n });\n\n // this generates a module augmentation for the router package\n // so that the routes are typed in the consumer's app\n return `\n declare module \"${routerPackageName}\" {\n namespace App {\n interface Routes {\n ${routes.join(\"\\n\")}\n }\n }\n }`;\n}\n\nconst extensionRegex = new RegExp(`(${allowedPageFileExtensions.join(\"|\")})$`);\n\nfunction convertFilePathToType<T extends \"rsc\" | \"html\">(\n fileName: string,\n fileTypeTo: T\n): `/${string}.${T}` {\n // make sure the rsc path is always prefixed with a slash\n // so we don't fetch from a sub-path\n return `/${fileName.replace(extensionRegex, \"\")}.${fileTypeTo}`;\n}\n\nfunction isAllowedFile(file: string): boolean {\n return allowedPageFileExtensions.some((ext) => file.endsWith(ext));\n}\n\nexport function removeExtension(file: string): string {\n return file.replace(extensionRegex, \"\");\n}\n"],"mappings":";;;;;;AAUA,MAAM,oBAAoB;AAC1B,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAC1B,MAAM,4BAA4B;CAAC;CAAQ;CAAQ;CAAO;CAAQ;CAAO;AAAK;AAK9E,MAAM,uBAAuB;AAG7B,MAAa,iCAAiB,IAAI,IAAoB;AACtD,MAAa,4CAA4B,IAAI,IAG3C;AACF,MAAa,wCAAwB,IAAI,IAAiC;AAE1E,SAAgB,mBAAmB;CACjC,eAAe,MAAM;CACrB,0BAA0B,MAAM;CAChC,sBAAsB,MAAM;AAC9B;AAEA,SAAgB,eACd,WACA,MACoB;CACpB,MAAM,WAA+B;EACnC,MAAM;EACN,MAAM;EACN,MAAM;EACN,KAAK;EACL,UAAU,CAAC;CACb;CAEA,IAAI,YAAY;CAEhB,MAAM,QAAQ,UACX,QAAQ,aAAa;EACpB,MAAM,QAAQ,qBAAqB,KAAK,QAAQ;EAChD,IAAI,OACF,MAAM,IAAI,MACR,cAAc,SAAS,qCAAqC,MAAM,GAAG,GACvE;EAGF,IAAI,gBAAgB,QAAQ,MAAM,SAAS;GACzC,YAAY;GAEZ,OAAO;EACT;EAEA,OAAO;CACT,CAAC,CAAC,CACD,KAAK,aAAa,gBAAgB,QAAQ,CAAC;CAE9C,IAAI,CAAC,WACH,MAAM,IAAI,MACR,uFACF;CAIF,MAAM,MAAM,GAAG,MAAM,EAAE,KAAK,MAAM,GAAG,CA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teData, GeneratedRouteNode, ReporterPluginConfig, buildRouteTree, clearRouteCaches, flattenRouteTree, formattingConfigCache, generateRoutes, getRoutesByPagePath, lastGeneratedContentCache, pageFilesCache, removeExtension, resolveFormattingConfig, resolveOutputPath, resolveOxfmtConfig } from "./generate-routes.mjs";
2
+ export { GenerateRoutesOptions, GeneratedRouteData, GeneratedRouteNode, ReporterPluginConfig, buildRouteTree, clearRouteCaches, flattenRouteTree, formattingConfigCache, generateRoutes, getRoutesByPagePath, lastGeneratedContentCache, pageFilesCache, removeExtension, resolveFormattingConfig, resolveOutputPath, resolveOxfmtConfig };
@@ -0,0 +1,2 @@
1
+ import { buildRouteTree, clearRouteCaches, flattenRouteTree, formattingConfigCache, generateRoutes, getRoutesByPagePath, lastGeneratedContentCache, pageFilesCache, removeExtension, resolveFormattingConfig, resolveOutputPath, resolveOxfmtConfig } from "./generate-routes.mjs";
2
+ export { buildRouteTree, clearRouteCaches, flattenRouteTree, formattingConfigCache, generateRoutes, getRoutesByPagePath, lastGeneratedContentCache, pageFilesCache, removeExtension, resolveFormattingConfig, resolveOutputPath, resolveOxfmtConfig };
package/package.json CHANGED
@@ -1,6 +1,83 @@
1
1
  {
2
2
  "name": "@renr/parcel-plugin-rsc-router",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0-beta.21",
4
+ "author": "Ren Rizzolo",
5
+ "license": "MIT",
6
+ "description": "Parcel v3 native plugin that generates typed filesystem routes and statically prerenders RSC apps",
7
+ "keywords": [
8
+ "parcel",
9
+ "rsc"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/renrizzolo/parcel-rsc-react.git"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/esm/index.mjs",
17
+ "module": "./dist/esm/index.mjs",
18
+ "types": "./dist/esm/index.d.mts",
19
+ "bin": {
20
+ "parcel-rsc-routes": "./dist/esm/cli.mjs"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "target/release/libparcel_plugin_rsc_router.so",
25
+ "target/release/libparcel_plugin_rsc_router.dylib",
26
+ "target/release/parcel_plugin_rsc_router.dll"
27
+ ],
28
+ "sideEffects": false,
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/esm/index.d.mts",
32
+ "import": "./dist/esm/index.mjs",
33
+ "default": "./dist/esm/index.mjs"
34
+ }
35
+ },
36
+ "engines": {
37
+ "parcel": "^3.0.0-alpha.3"
38
+ },
39
+ "parcel": {
40
+ "abi": 1,
41
+ "artifacts": {
42
+ "aarch64-apple-darwin": "@renr/parcel-plugin-rsc-router-darwin-arm64",
43
+ "x86_64-apple-darwin": "@renr/parcel-plugin-rsc-router-darwin-x64",
44
+ "x86_64-pc-windows-msvc": "@renr/parcel-plugin-rsc-router-win32-x64-msvc",
45
+ "aarch64-pc-windows-msvc": "@renr/parcel-plugin-rsc-router-win32-arm64-msvc",
46
+ "x86_64-unknown-linux-gnu": "@renr/parcel-plugin-rsc-router-linux-x64-gnu",
47
+ "aarch64-unknown-linux-gnu": "@renr/parcel-plugin-rsc-router-linux-arm64-gnu",
48
+ "x86_64-unknown-linux-musl": "@renr/parcel-plugin-rsc-router-linux-x64-musl",
49
+ "aarch64-unknown-linux-musl": "@renr/parcel-plugin-rsc-router-linux-arm64-musl"
50
+ }
51
+ },
52
+ "scripts": {
53
+ "build": "node ../../scripts/build-rust.mjs && tsdown",
54
+ "build:rust": "node ../../scripts/build-rust.mjs",
55
+ "test:rust": "node ../../scripts/build-rust.mjs --test",
56
+ "prepack": "node ../../scripts/prepack-plugin.mjs",
57
+ "type-check": "tsc --noEmit"
58
+ },
59
+ "dependencies": {
60
+ "oxfmt": "^0.75.0",
61
+ "tinyglobby": "^0.2.17"
62
+ },
63
+ "peerDependencies": {
64
+ "@renr/parcel-rsc-router": "1.0.0-beta.14"
65
+ },
66
+ "devDependencies": {
67
+ "@types/node": "^25.6.2",
68
+ "dedent": "^1.7.2"
69
+ },
70
+ "publishConfig": {
71
+ "access": "public"
72
+ },
73
+ "optionalDependencies": {
74
+ "@renr/parcel-plugin-rsc-router-darwin-arm64": "1.0.0-beta.21",
75
+ "@renr/parcel-plugin-rsc-router-darwin-x64": "1.0.0-beta.21",
76
+ "@renr/parcel-plugin-rsc-router-win32-x64-msvc": "1.0.0-beta.21",
77
+ "@renr/parcel-plugin-rsc-router-win32-arm64-msvc": "1.0.0-beta.21",
78
+ "@renr/parcel-plugin-rsc-router-linux-x64-gnu": "1.0.0-beta.21",
79
+ "@renr/parcel-plugin-rsc-router-linux-arm64-gnu": "1.0.0-beta.21",
80
+ "@renr/parcel-plugin-rsc-router-linux-x64-musl": "1.0.0-beta.21",
81
+ "@renr/parcel-plugin-rsc-router-linux-arm64-musl": "1.0.0-beta.21"
82
+ }
83
+ }