@renr/parcel-rsc-router 1.0.0-beta.13 → 1.0.0-beta.14

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.
@@ -12,7 +12,9 @@ export interface PrerenderOptions {
12
12
  bootstrapComponent?: ComponentType;
13
13
  outDir?: string;
14
14
  staticDir?: string;
15
+ /** Maximum number of routes to prerender concurrently. Defaults to 6. */
16
+ concurrency?: number;
15
17
  }
16
- export declare function prerenderStaticSite({ routes, pages, bootstrapComponent, outDir, staticDir }: PrerenderOptions): Promise<void>;
18
+ export declare function prerenderStaticSite({ routes, pages, bootstrapComponent, outDir, staticDir, concurrency }: PrerenderOptions): Promise<void>;
17
19
  //#endregion
18
20
  //# sourceMappingURL=prerender.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prerender.d.mts","names":[],"sources":["../../src/prerender.tsx"],"mappings":";;;iBAMiB;EACf,SAAS,cAAc;EACvB,kBAAkB;GACjB;;iBAGc;EACf,QAAQ;EACR,OAAO,eAAe;EACtB,qBAAqB;EACrB;EACA;;wBA6EoB,sBACpB,QACA,OACA,oBACA,QAGA,aACC,mBAAmB"}
1
+ {"version":3,"file":"prerender.d.mts","names":[],"sources":["../../src/prerender.tsx"],"mappings":";;;iBAMiB;EACf,SAAS,cAAc;EACvB,kBAAkB;GACjB;;iBAGc;EACf,QAAQ;EACR,OAAO,eAAe;EACtB,qBAAqB;EACrB;EACA;;EAEA;;wBA6EoB,sBACpB,QACA,OACA,oBACA,QAGA,WACA,eACC,mBAAmB"}
@@ -34,7 +34,7 @@ function resolveBootstrapComponent(PageComponent, props) {
34
34
  return;
35
35
  }
36
36
  }
37
- async function prerenderStaticSite({ routes, pages, bootstrapComponent, outDir = process.env.PARCEL_RSC_OUT_DIR ? path.resolve(process.env.PARCEL_RSC_OUT_DIR) : path.resolve(process.cwd(), "dist"), staticDir = path.resolve(process.cwd(), "static") }) {
37
+ async function prerenderStaticSite({ routes, pages, bootstrapComponent, outDir = process.env.PARCEL_RSC_OUT_DIR ? path.resolve(process.env.PARCEL_RSC_OUT_DIR) : path.resolve(process.cwd(), "dist"), staticDir = path.resolve(process.cwd(), "static"), concurrency = 6 }) {
38
38
  var _Object$values$find;
39
39
  await fs.mkdir(outDir, { recursive: true });
40
40
  try {
@@ -71,18 +71,29 @@ async function prerenderStaticSite({ routes, pages, bootstrapComponent, outDir =
71
71
  break;
72
72
  }
73
73
  }
74
- for (const route of routes) {
74
+ const activeRoutes = routes.filter((route) => {
75
+ var _pages$route$html;
76
+ return Boolean((_pages$route$html = pages[route.html]) === null || _pages$route$html === void 0 ? void 0 : _pages$route$html.default);
77
+ });
78
+ const dirsToCreate = /* @__PURE__ */ new Set();
79
+ for (const route of activeRoutes) {
80
+ dirsToCreate.add(path.dirname(path.join(outDir, route.html.slice(1))));
81
+ dirsToCreate.add(path.dirname(path.join(outDir, route.rsc.slice(1))));
82
+ }
83
+ await Promise.all(Array.from(dirsToCreate, (dir) => fs.mkdir(dir, { recursive: true })));
84
+ const renderRoute = async (route) => {
75
85
  const mod = pages[route.html];
76
- if (!(mod === null || mod === void 0 ? void 0 : mod.default)) continue;
86
+ if (!(mod === null || mod === void 0 ? void 0 : mod.default)) return;
77
87
  const { default: PageComponent, tableOfContents, ...exports } = mod;
88
+ const currentPage = {
89
+ url: route.html,
90
+ name: route.slug,
91
+ exports,
92
+ tableOfContents
93
+ };
78
94
  const pageProps = {
79
95
  pages: allPages,
80
- currentPage: {
81
- url: route.html,
82
- name: route.slug,
83
- exports,
84
- tableOfContents
85
- }
96
+ currentPage
86
97
  };
87
98
  const element = /* @__PURE__ */ jsx(PageComponent, { ...pageProps });
88
99
  let componentWithBootstrap;
@@ -95,16 +106,26 @@ async function prerenderStaticSite({ routes, pages, bootstrapComponent, outDir =
95
106
  var _resolveBootstrapComp;
96
107
  componentWithBootstrap = (_resolveBootstrapComp = resolveBootstrapComponent(PageComponent, pageProps)) !== null && _resolveBootstrapComp !== void 0 ? _resolveBootstrapComp : fallbackBootstrap;
97
108
  }
98
- const htmlStream = await renderHTML(element, { component: componentWithBootstrap });
99
- const html = await new Response(htmlStream).text();
100
- const rscStream = renderRSC(element);
101
- const rsc = await new Response(rscStream).text();
102
109
  const htmlFilePath = path.join(outDir, route.html.slice(1));
103
110
  const rscFilePath = path.join(outDir, route.rsc.slice(1));
104
- await fs.mkdir(path.dirname(htmlFilePath), { recursive: true });
105
- await fs.writeFile(htmlFilePath, html, "utf-8");
106
- await fs.writeFile(rscFilePath, rsc, "utf-8");
107
- }
111
+ const [html, rsc] = await Promise.all([renderHTML(element, { component: componentWithBootstrap }).then((htmlStream) => new Response(htmlStream).text()), new Response(renderRSC(element)).text()]);
112
+ await Promise.all([fs.writeFile(htmlFilePath, html, "utf-8"), fs.writeFile(rscFilePath, rsc, "utf-8")]);
113
+ };
114
+ const workerCount = Math.max(1, Math.min(concurrency, activeRoutes.length));
115
+ let nextIndex = 0;
116
+ let aborted = false;
117
+ const workers = Array.from({ length: workerCount }, async () => {
118
+ while (!aborted && nextIndex < activeRoutes.length) {
119
+ const route = activeRoutes[nextIndex++];
120
+ if (route) try {
121
+ await renderRoute(route);
122
+ } catch (err) {
123
+ aborted = true;
124
+ throw err;
125
+ }
126
+ }
127
+ });
128
+ await Promise.all(workers);
108
129
  }
109
130
  //#endregion
110
131
  export { prerenderStaticSite };
@@ -1 +1 @@
1
- {"version":3,"file":"prerender.mjs","names":[],"sources":["../../src/prerender.tsx"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { ComponentType } from \"react\";\nimport { renderHTML, renderRSC } from \"@parcel/rsc/server\";\nimport type { Page, PageProps, RouteData, TocNode } from \"./types.js\";\n\nexport interface PrerenderPageModule {\n default: ComponentType<PageProps>;\n tableOfContents?: TocNode[];\n [key: string]: unknown;\n}\n\nexport interface PrerenderOptions {\n routes: RouteData[];\n pages: Record<string, PrerenderPageModule>;\n bootstrapComponent?: ComponentType;\n outDir?: string;\n staticDir?: string;\n}\n\nfunction hasBootstrapScript(\n value: unknown\n): value is ComponentType & { bootstrapScript: string } {\n return (\n typeof value === \"function\" &&\n typeof (value as { bootstrapScript?: unknown }).bootstrapScript ===\n \"string\" &&\n Boolean((value as { bootstrapScript?: string }).bootstrapScript)\n );\n}\n\nfunction findBootstrapInElement(\n node: unknown,\n depth = 0\n): ComponentType | undefined {\n if (depth > 5 || !node || typeof node !== \"object\") {\n return undefined;\n }\n\n if (Array.isArray(node)) {\n for (const child of node) {\n const found = findBootstrapInElement(child, depth + 1);\n if (found) {\n return found;\n }\n }\n return undefined;\n }\n\n const maybeElement = node as {\n type?: unknown;\n props?: { children?: unknown };\n };\n if (hasBootstrapScript(maybeElement.type)) {\n return maybeElement.type;\n }\n\n if (maybeElement.props && \"children\" in maybeElement.props) {\n return findBootstrapInElement(maybeElement.props.children, depth + 1);\n }\n\n return undefined;\n}\n\nfunction resolveBootstrapComponent(\n PageComponent: ComponentType<PageProps>,\n props: PageProps\n): ComponentType | undefined {\n if (hasBootstrapScript(PageComponent)) {\n return PageComponent as unknown as ComponentType;\n }\n\n // Avoid invoking async server components outside React's render lifecycle.\n if (PageComponent.constructor?.name === \"AsyncFunction\") {\n return undefined;\n }\n\n try {\n const rendered = (PageComponent as (p: PageProps) => unknown)(props);\n if (\n rendered &&\n typeof rendered === \"object\" &&\n \"then\" in rendered &&\n typeof (rendered as { then?: unknown }).then === \"function\"\n ) {\n (rendered as Promise<unknown>).catch(() => {});\n return undefined;\n }\n return findBootstrapInElement(rendered);\n } catch {\n return undefined;\n }\n}\n\nexport async function prerenderStaticSite({\n routes,\n pages,\n bootstrapComponent,\n outDir = process.env.PARCEL_RSC_OUT_DIR\n ? path.resolve(process.env.PARCEL_RSC_OUT_DIR)\n : path.resolve(process.cwd(), \"dist\"),\n staticDir = path.resolve(process.cwd(), \"static\"),\n}: PrerenderOptions): Promise<void> {\n await fs.mkdir(outDir, { recursive: true });\n\n try {\n await fs.cp(staticDir, outDir, { recursive: true });\n } catch {\n // ignore if staticDir doesn't exist\n }\n\n const allPages: Page[] = routes.map((route) => {\n const mod = pages[route.html];\n const { default: _default, tableOfContents, ...exports } = mod ?? {};\n return {\n url: route.html,\n name: route.slug,\n exports,\n tableOfContents,\n };\n });\n\n const probedBootstrapByRoute = new Map<string, ComponentType | undefined>();\n\n let fallbackBootstrap: ComponentType | undefined =\n bootstrapComponent ??\n (Object.values(pages).find((mod) => hasBootstrapScript(mod?.default))\n ?.default as ComponentType | undefined);\n\n // If no page module carries bootstrapScript directly (e.g. an MDX-only site where\n // `'use server-entry'` lives on the layout component wrapped by each `.mdx` file),\n // probe page wrappers until one yields a layout's bootstrapScript and cache the result\n // so that route is not invoked twice.\n if (!fallbackBootstrap) {\n for (const route of routes) {\n const mod = pages[route.html];\n if (!mod?.default) continue;\n const { default: PageComponent, tableOfContents, ...exports } = mod;\n const resolved = resolveBootstrapComponent(PageComponent, {\n pages: allPages,\n currentPage: {\n url: route.html,\n name: route.slug,\n exports,\n tableOfContents,\n },\n });\n probedBootstrapByRoute.set(route.html, resolved);\n if (resolved) {\n fallbackBootstrap = resolved;\n break;\n }\n }\n }\n\n for (const route of routes) {\n const mod = pages[route.html];\n if (!mod?.default) continue;\n\n const { default: PageComponent, tableOfContents, ...exports } = mod;\n const currentPage: PageProps[\"currentPage\"] = {\n url: route.html,\n name: route.slug,\n exports,\n tableOfContents,\n };\n\n const pageProps: PageProps = {\n pages: allPages,\n currentPage,\n };\n\n const element = <PageComponent {...pageProps} />;\n\n let componentWithBootstrap: ComponentType | undefined;\n if (hasBootstrapScript(PageComponent)) {\n componentWithBootstrap = PageComponent as unknown as ComponentType;\n } else if (bootstrapComponent) {\n componentWithBootstrap = bootstrapComponent;\n } else if (probedBootstrapByRoute.has(route.html)) {\n componentWithBootstrap =\n probedBootstrapByRoute.get(route.html) ?? fallbackBootstrap;\n } else {\n componentWithBootstrap =\n resolveBootstrapComponent(PageComponent, pageProps) ??\n fallbackBootstrap;\n }\n\n const htmlStream = await renderHTML(element, {\n component: componentWithBootstrap,\n });\n const html = await new Response(htmlStream).text();\n\n const rscStream = renderRSC(element);\n const rsc = await new Response(rscStream).text();\n\n const htmlFilePath = path.join(outDir, route.html.slice(1));\n const rscFilePath = path.join(outDir, route.rsc.slice(1));\n\n await fs.mkdir(path.dirname(htmlFilePath), { recursive: true });\n await fs.writeFile(htmlFilePath, html, \"utf-8\");\n await fs.writeFile(rscFilePath, rsc, \"utf-8\");\n }\n}\n"],"mappings":";;;;;AAoBA,SAAS,mBACP,OACsD;CACtD,OACE,OAAO,UAAU,cACjB,OAAQ,MAAwC,oBAC9C,YACF,QAAS,MAAuC,eAAe;AAEnE;AAEA,SAAS,uBACP,MACA,QAAQ,GACmB;CAC3B,IAAI,QAAQ,KAAK,CAAC,QAAQ,OAAO,SAAS,UACxC;CAGF,IAAI,MAAM,QAAQ,IAAI,GAAG;EACvB,KAAK,MAAM,SAAS,MAAM;GACxB,MAAM,QAAQ,uBAAuB,OAAO,QAAQ,CAAC;GACrD,IAAI,OACF,OAAO;EAEX;EACA;CACF;CAEA,MAAM,eAAe;CAIrB,IAAI,mBAAmB,aAAa,IAAI,GACtC,OAAO,aAAa;CAGtB,IAAI,aAAa,SAAS,cAAc,aAAa,OACnD,OAAO,uBAAuB,aAAa,MAAM,UAAU,QAAQ,CAAC;AAIxE;AAEA,SAAS,0BACP,eACA,OAC2B;;CAC3B,IAAI,mBAAmB,aAAa,GAClC,OAAO;CAIT,MAAA,wBAAI,cAAc,iBAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAa,UAAS,iBACtC;CAGF,IAAI;EACF,MAAM,WAAY,cAA4C,KAAK;EACnE,IACE,YACA,OAAO,aAAa,YACpB,UAAU,YACV,OAAQ,SAAgC,SAAS,YACjD;GACA,SAA+B,YAAY,CAAC,CAAC;GAC7C;EACF;EACA,OAAO,uBAAuB,QAAQ;CACxC,SAAA,SAAQ;EACN;CACF;AACF;AAEA,eAAsB,oBAAoB,EACxC,QACA,OAC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import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { ComponentType } from \"react\";\nimport { renderHTML, renderRSC } from \"@parcel/rsc/server\";\nimport type { Page, PageProps, RouteData, TocNode } from \"./types.js\";\n\nexport interface PrerenderPageModule {\n default: ComponentType<PageProps>;\n tableOfContents?: TocNode[];\n [key: string]: unknown;\n}\n\nexport interface PrerenderOptions {\n routes: RouteData[];\n pages: Record<string, PrerenderPageModule>;\n bootstrapComponent?: ComponentType;\n outDir?: string;\n staticDir?: string;\n /** Maximum number of routes to prerender concurrently. Defaults to 6. */\n concurrency?: number;\n}\n\nfunction hasBootstrapScript(\n value: unknown\n): value is ComponentType & { bootstrapScript: string } {\n return (\n typeof value === \"function\" &&\n typeof (value as { bootstrapScript?: unknown }).bootstrapScript ===\n \"string\" &&\n Boolean((value as { bootstrapScript?: string }).bootstrapScript)\n );\n}\n\nfunction findBootstrapInElement(\n node: unknown,\n depth = 0\n): ComponentType | undefined {\n if (depth > 5 || !node || typeof node !== \"object\") {\n return undefined;\n }\n\n if (Array.isArray(node)) {\n for (const child of node) {\n const found = findBootstrapInElement(child, depth + 1);\n if (found) {\n return found;\n }\n }\n return undefined;\n }\n\n const maybeElement = node as {\n type?: unknown;\n props?: { children?: unknown };\n };\n if (hasBootstrapScript(maybeElement.type)) {\n return maybeElement.type;\n }\n\n if (maybeElement.props && \"children\" in maybeElement.props) {\n return findBootstrapInElement(maybeElement.props.children, depth + 1);\n }\n\n return undefined;\n}\n\nfunction resolveBootstrapComponent(\n PageComponent: ComponentType<PageProps>,\n props: PageProps\n): ComponentType | undefined {\n if (hasBootstrapScript(PageComponent)) {\n return PageComponent as unknown as ComponentType;\n }\n\n // Avoid invoking async server components outside React's render lifecycle.\n if (PageComponent.constructor?.name === \"AsyncFunction\") {\n return undefined;\n }\n\n try {\n const rendered = (PageComponent as (p: PageProps) => unknown)(props);\n if (\n rendered &&\n typeof rendered === \"object\" &&\n \"then\" in rendered &&\n typeof (rendered as { then?: unknown }).then === \"function\"\n ) {\n (rendered as Promise<unknown>).catch(() => {});\n return undefined;\n }\n return findBootstrapInElement(rendered);\n } catch {\n return undefined;\n }\n}\n\nexport async function prerenderStaticSite({\n routes,\n pages,\n bootstrapComponent,\n outDir = process.env.PARCEL_RSC_OUT_DIR\n ? path.resolve(process.env.PARCEL_RSC_OUT_DIR)\n : path.resolve(process.cwd(), \"dist\"),\n staticDir = path.resolve(process.cwd(), \"static\"),\n concurrency = 6,\n}: PrerenderOptions): Promise<void> {\n await fs.mkdir(outDir, { recursive: true });\n\n try {\n await fs.cp(staticDir, outDir, { recursive: true });\n } catch {\n // ignore if staticDir doesn't exist\n }\n\n const allPages: Page[] = routes.map((route) => {\n const mod = pages[route.html];\n const { default: _default, tableOfContents, ...exports } = mod ?? {};\n return {\n url: route.html,\n name: route.slug,\n exports,\n tableOfContents,\n };\n });\n\n const probedBootstrapByRoute = new Map<string, ComponentType | undefined>();\n\n let fallbackBootstrap: ComponentType | undefined =\n bootstrapComponent ??\n (Object.values(pages).find((mod) => hasBootstrapScript(mod?.default))\n ?.default as ComponentType | undefined);\n\n // If no page module carries bootstrapScript directly (e.g. an MDX-only site where\n // `'use server-entry'` lives on the layout component wrapped by each `.mdx` file),\n // probe page wrappers until one yields a layout's bootstrapScript and cache the result\n // so that route is not invoked twice.\n if (!fallbackBootstrap) {\n for (const route of routes) {\n const mod = pages[route.html];\n if (!mod?.default) continue;\n const { default: PageComponent, tableOfContents, ...exports } = mod;\n const resolved = resolveBootstrapComponent(PageComponent, {\n pages: allPages,\n currentPage: {\n url: route.html,\n name: route.slug,\n exports,\n tableOfContents,\n },\n });\n probedBootstrapByRoute.set(route.html, resolved);\n if (resolved) {\n fallbackBootstrap = resolved;\n break;\n }\n }\n }\n\n const activeRoutes = routes.filter((route) =>\n Boolean(pages[route.html]?.default)\n );\n\n // Pre-create all unique output subdirectories once up front.\n const dirsToCreate = new Set<string>();\n for (const route of activeRoutes) {\n dirsToCreate.add(path.dirname(path.join(outDir, route.html.slice(1))));\n dirsToCreate.add(path.dirname(path.join(outDir, route.rsc.slice(1))));\n }\n await Promise.all(\n Array.from(dirsToCreate, (dir) => fs.mkdir(dir, { recursive: true }))\n );\n\n const renderRoute = async (route: RouteData): Promise<void> => {\n const mod = pages[route.html];\n if (!mod?.default) return;\n\n const { default: PageComponent, tableOfContents, ...exports } = mod;\n const currentPage: PageProps[\"currentPage\"] = {\n url: route.html,\n name: route.slug,\n exports,\n tableOfContents,\n };\n\n const pageProps: PageProps = {\n pages: allPages,\n currentPage,\n };\n\n const element = <PageComponent {...pageProps} />;\n\n let componentWithBootstrap: ComponentType | undefined;\n if (hasBootstrapScript(PageComponent)) {\n componentWithBootstrap = PageComponent as unknown as ComponentType;\n } else if (bootstrapComponent) {\n componentWithBootstrap = bootstrapComponent;\n } else if (probedBootstrapByRoute.has(route.html)) {\n componentWithBootstrap =\n probedBootstrapByRoute.get(route.html) ?? fallbackBootstrap;\n } else {\n componentWithBootstrap =\n resolveBootstrapComponent(PageComponent, pageProps) ??\n fallbackBootstrap;\n }\n\n const htmlFilePath = path.join(outDir, route.html.slice(1));\n const rscFilePath = path.join(outDir, route.rsc.slice(1));\n\n const [html, rsc] = await Promise.all([\n renderHTML(element, { component: componentWithBootstrap }).then(\n (htmlStream) => new Response(htmlStream).text()\n ),\n new Response(renderRSC(element)).text(),\n ]);\n\n await Promise.all([\n fs.writeFile(htmlFilePath, html, \"utf-8\"),\n fs.writeFile(rscFilePath, rsc, \"utf-8\"),\n ]);\n };\n\n const workerCount = Math.max(1, Math.min(concurrency, activeRoutes.length));\n let nextIndex = 0;\n let aborted = false;\n\n const workers = Array.from({ length: workerCount }, async () => {\n while (!aborted && nextIndex < activeRoutes.length) {\n const route = activeRoutes[nextIndex++];\n if (route) {\n try {\n await renderRoute(route);\n } catch (err) {\n aborted = true;\n throw err;\n }\n }\n }\n });\n\n await Promise.all(workers);\n}\n"],"mappings":";;;;;AAsBA,SAAS,mBACP,OACsD;CACtD,OACE,OAAO,UAAU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c,MAAM,OAAO,GACxC,GAAG,UAAU,aAAa,KAAK,OAAO,CACxC,CAAC;CACH;CAEA,MAAM,cAAc,KAAK,IAAI,GAAG,KAAK,IAAI,aAAa,aAAa,MAAM,CAAC;CAC1E,IAAI,YAAY;CAChB,IAAI,UAAU;CAEd,MAAM,UAAU,MAAM,KAAK,EAAE,QAAQ,YAAY,GAAG,YAAY;EAC9D,OAAO,CAAC,WAAW,YAAY,aAAa,QAAQ;GAClD,MAAM,QAAQ,aAAa;GAC3B,IAAI,OACF,IAAI;IACF,MAAM,YAAY,KAAK;GACzB,SAAS,KAAK;IACZ,UAAU;IACV,MAAM;GACR;EAEJ;CACF,CAAC;CAED,MAAM,QAAQ,IAAI,OAAO;AAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renr/parcel-rsc-router",
3
- "version": "1.0.0-beta.13",
3
+ "version": "1.0.0-beta.14",
4
4
  "author": "Ren Rizzolo",
5
5
  "license": "MIT",
6
6
  "description": "Parcel rsc router",