@idlesummer/pen 0.2.1 → 0.2.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/dist/bin.mjs CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import{a as e,f as t,i as n,n as r,r as i,t as a}from"./element-tree-DoH7UgRL.mjs";import{join as o,resolve as s}from"path";import{pathToFileURL as c}from"url";import{existsSync as l}from"fs";import{Command as u}from"commander";import{duration as d,fileList as f,pipe as p}from"@idlesummer/tasker";import{mkdir as m,writeFile as h}from"fs/promises";import{build as g}from"rolldown";import _ from"rollup-plugin-node-externals";var v=Object.create,y=Object.defineProperty,b=Object.getOwnPropertyDescriptor,x=Object.getOwnPropertyNames,S=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty,w=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),T=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=x(t),a=0,o=i.length,s;a<o;a++)s=i[a],!C.call(e,s)&&s!==n&&y(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=b(t,s))||r.enumerable});return e},E=(e,t,n)=>(n=e==null?{}:v(S(e)),T(t||!e||!e.__esModule?y(n,`default`,{value:e,enumerable:!0}):n,e));const D=`@idlesummer/pen`,O=`0.2.1`,k=`@idlesummer/pen`.split(`/`)?.[1]??`@idlesummer/pen`;var A=E(w(((e,t)=>{let n=process||{},r=n.argv||[],i=n.env||{},a=!(i.NO_COLOR||r.includes(`--no-color`))&&(!!i.FORCE_COLOR||r.includes(`--color`)||n.platform===`win32`||(n.stdout||{}).isTTY&&i.TERM!==`dumb`||!!i.CI),o=(e,t,n=e)=>r=>{let i=``+r,a=i.indexOf(t,e.length);return~a?e+s(i,t,n,a)+t:e+i+t},s=(e,t,n,r)=>{let i=``,a=0;do i+=e.substring(a,r)+n,a=r+t.length,r=e.indexOf(t,a);while(~r);return i+e.substring(a)},c=(e=a)=>{let t=e?o:()=>String;return{isColorSupported:e,reset:t(`\x1B[0m`,`\x1B[0m`),bold:t(`\x1B[1m`,`\x1B[22m`,`\x1B[22m\x1B[1m`),dim:t(`\x1B[2m`,`\x1B[22m`,`\x1B[22m\x1B[2m`),italic:t(`\x1B[3m`,`\x1B[23m`),underline:t(`\x1B[4m`,`\x1B[24m`),inverse:t(`\x1B[7m`,`\x1B[27m`),hidden:t(`\x1B[8m`,`\x1B[28m`),strikethrough:t(`\x1B[9m`,`\x1B[29m`),black:t(`\x1B[30m`,`\x1B[39m`),red:t(`\x1B[31m`,`\x1B[39m`),green:t(`\x1B[32m`,`\x1B[39m`),yellow:t(`\x1B[33m`,`\x1B[39m`),blue:t(`\x1B[34m`,`\x1B[39m`),magenta:t(`\x1B[35m`,`\x1B[39m`),cyan:t(`\x1B[36m`,`\x1B[39m`),white:t(`\x1B[37m`,`\x1B[39m`),gray:t(`\x1B[90m`,`\x1B[39m`),bgBlack:t(`\x1B[40m`,`\x1B[49m`),bgRed:t(`\x1B[41m`,`\x1B[49m`),bgGreen:t(`\x1B[42m`,`\x1B[49m`),bgYellow:t(`\x1B[43m`,`\x1B[49m`),bgBlue:t(`\x1B[44m`,`\x1B[49m`),bgMagenta:t(`\x1B[45m`,`\x1B[49m`),bgCyan:t(`\x1B[46m`,`\x1B[49m`),bgWhite:t(`\x1B[47m`,`\x1B[49m`),blackBright:t(`\x1B[90m`,`\x1B[39m`),redBright:t(`\x1B[91m`,`\x1B[39m`),greenBright:t(`\x1B[92m`,`\x1B[39m`),yellowBright:t(`\x1B[93m`,`\x1B[39m`),blueBright:t(`\x1B[94m`,`\x1B[39m`),magentaBright:t(`\x1B[95m`,`\x1B[39m`),cyanBright:t(`\x1B[96m`,`\x1B[39m`),whiteBright:t(`\x1B[97m`,`\x1B[39m`),bgBlackBright:t(`\x1B[100m`,`\x1B[49m`),bgRedBright:t(`\x1B[101m`,`\x1B[49m`),bgGreenBright:t(`\x1B[102m`,`\x1B[49m`),bgYellowBright:t(`\x1B[103m`,`\x1B[49m`),bgBlueBright:t(`\x1B[104m`,`\x1B[49m`),bgMagentaBright:t(`\x1B[105m`,`\x1B[49m`),bgCyanBright:t(`\x1B[106m`,`\x1B[49m`),bgWhiteBright:t(`\x1B[107m`,`\x1B[49m`)}};t.exports=c(),t.exports.createColors=c}))(),1);const j={name:`Building file tree`,onSuccess:(e,t)=>`Built file tree (${d(t)})`,run:async t=>({fileTree:e(t.appDir)})},M={name:`Building segment tree...`,onSuccess:(e,t)=>`Built segment tree (${d(t)})`,run:async e=>({segmentTree:n(e.fileTree)})},N={name:`Building route manifest`,onSuccess:(e,t)=>`Built route table (${d(t)})`,run:async e=>({manifest:i(e.segmentTree,e.outDir)})},P={name:`Building component map`,onSuccess:(e,t)=>`Built component map (${d(t)})`,run:async e=>({componentMap:r(e.manifest)})},F={name:`Building element trees`,onSuccess:(e,t)=>`Built element trees (${d(t)})`,run:async e=>({elementTrees:a(e.manifest,e.componentMap)})},I={name:`Writing route-table.ts`,onSuccess:(e,t)=>`Saved route-table.ts (${d(t)})`,run:async e=>{let t=o(e.outDir,`generated`),n=o(t,`route-table.ts`),r=[`// Auto-generated by ${D}`,`// Do not manually edit this file`,`// NOTE: This file is kept for documentation/debugging.`,`// Runtime uses pre-built routes from routes.ts instead.`,``,`import type { RouteTable } from '${D}'`,``,`export const manifest: RouteTable = ${JSON.stringify(e.manifest,null,2)} as const`,``].join(`
3
- `);await m(t,{recursive:!0}),await h(n,r,`utf-8`)}},L={name:`Writing element-tree.ts`,onSuccess:(e,t)=>`Saved element-tree.ts (${d(t)})`,run:async e=>{let t=o(e.outDir,`generated`),n=o(t,`element-tree.ts`),r=[`// Auto-generated by ${D}`,`// Do not manually edit this file`,`// NOTE: This file is kept for documentation/debugging.`,``,`import type { ElementTreeMap } from '${D}'`,``,`export const elementTrees: ElementTreeMap = ${JSON.stringify(e.elementTrees,null,2)} as const`,``].join(`
4
- `);await m(t,{recursive:!0}),await h(n,r,`utf-8`)}},R={name:`Writing component-map.ts`,onSuccess:(e,t)=>`Saved component-map.ts (${d(t)})`,run:async e=>{let t=o(e.outDir,`generated`),n=o(t,`component-map.ts`),r=e.componentMap,i=[`// Auto-generated by ${D}`,`// Do not manually edit this file`,``,`import type { ComponentMap } from '${D}'`,``,`export const componentMap: ComponentMap = ${JSON.stringify(r,null,2)} as const`,``].join(`
5
- `);await m(t,{recursive:!0}),await h(n,i,`utf-8`)}},z={name:`Writing compiled-routes.ts`,onSuccess:(e,t)=>`Saved compiled-routes.ts (${d(t)})`,run:async e=>{let t=o(e.outDir,`generated`),n=o(t,`compiled-routes.ts`),r=e.elementTrees,i=e.componentMap,a=Object.keys(i).map((e,t)=>`import Component${t} from '${e}'`).join(`
6
- `),s=[];for(let[e,t]of Object.entries(r)){let n=` ${B(t).replace(/\n/g,`
2
+ import{a as e,f as t,i as n,n as r,r as i,t as a}from"./serialized-routes-DFDKf4sB.mjs";import{join as o,resolve as s}from"path";import{pathToFileURL as c}from"url";import{existsSync as l}from"fs";import{Command as u}from"commander";import{duration as d,fileList as f,pipe as p}from"@idlesummer/tasker";import{mkdir as m,writeFile as h}from"fs/promises";import{build as g}from"rolldown";import _ from"rollup-plugin-node-externals";var v=Object.create,y=Object.defineProperty,b=Object.getOwnPropertyDescriptor,x=Object.getOwnPropertyNames,S=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty,w=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),T=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=x(t),a=0,o=i.length,s;a<o;a++)s=i[a],!C.call(e,s)&&s!==n&&y(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=b(t,s))||r.enumerable});return e},E=(e,t,n)=>(n=e==null?{}:v(S(e)),T(t||!e||!e.__esModule?y(n,`default`,{value:e,enumerable:!0}):n,e));const D=`@idlesummer/pen`,O=`0.2.2`,k=`@idlesummer/pen`.split(`/`)?.[1]??`@idlesummer/pen`;var A=E(w(((e,t)=>{let n=process||{},r=n.argv||[],i=n.env||{},a=!(i.NO_COLOR||r.includes(`--no-color`))&&(!!i.FORCE_COLOR||r.includes(`--color`)||n.platform===`win32`||(n.stdout||{}).isTTY&&i.TERM!==`dumb`||!!i.CI),o=(e,t,n=e)=>r=>{let i=``+r,a=i.indexOf(t,e.length);return~a?e+s(i,t,n,a)+t:e+i+t},s=(e,t,n,r)=>{let i=``,a=0;do i+=e.substring(a,r)+n,a=r+t.length,r=e.indexOf(t,a);while(~r);return i+e.substring(a)},c=(e=a)=>{let t=e?o:()=>String;return{isColorSupported:e,reset:t(`\x1B[0m`,`\x1B[0m`),bold:t(`\x1B[1m`,`\x1B[22m`,`\x1B[22m\x1B[1m`),dim:t(`\x1B[2m`,`\x1B[22m`,`\x1B[22m\x1B[2m`),italic:t(`\x1B[3m`,`\x1B[23m`),underline:t(`\x1B[4m`,`\x1B[24m`),inverse:t(`\x1B[7m`,`\x1B[27m`),hidden:t(`\x1B[8m`,`\x1B[28m`),strikethrough:t(`\x1B[9m`,`\x1B[29m`),black:t(`\x1B[30m`,`\x1B[39m`),red:t(`\x1B[31m`,`\x1B[39m`),green:t(`\x1B[32m`,`\x1B[39m`),yellow:t(`\x1B[33m`,`\x1B[39m`),blue:t(`\x1B[34m`,`\x1B[39m`),magenta:t(`\x1B[35m`,`\x1B[39m`),cyan:t(`\x1B[36m`,`\x1B[39m`),white:t(`\x1B[37m`,`\x1B[39m`),gray:t(`\x1B[90m`,`\x1B[39m`),bgBlack:t(`\x1B[40m`,`\x1B[49m`),bgRed:t(`\x1B[41m`,`\x1B[49m`),bgGreen:t(`\x1B[42m`,`\x1B[49m`),bgYellow:t(`\x1B[43m`,`\x1B[49m`),bgBlue:t(`\x1B[44m`,`\x1B[49m`),bgMagenta:t(`\x1B[45m`,`\x1B[49m`),bgCyan:t(`\x1B[46m`,`\x1B[49m`),bgWhite:t(`\x1B[47m`,`\x1B[49m`),blackBright:t(`\x1B[90m`,`\x1B[39m`),redBright:t(`\x1B[91m`,`\x1B[39m`),greenBright:t(`\x1B[92m`,`\x1B[39m`),yellowBright:t(`\x1B[93m`,`\x1B[39m`),blueBright:t(`\x1B[94m`,`\x1B[39m`),magentaBright:t(`\x1B[95m`,`\x1B[39m`),cyanBright:t(`\x1B[96m`,`\x1B[39m`),whiteBright:t(`\x1B[97m`,`\x1B[39m`),bgBlackBright:t(`\x1B[100m`,`\x1B[49m`),bgRedBright:t(`\x1B[101m`,`\x1B[49m`),bgGreenBright:t(`\x1B[102m`,`\x1B[49m`),bgYellowBright:t(`\x1B[103m`,`\x1B[49m`),bgBlueBright:t(`\x1B[104m`,`\x1B[49m`),bgMagentaBright:t(`\x1B[105m`,`\x1B[49m`),bgCyanBright:t(`\x1B[106m`,`\x1B[49m`),bgWhiteBright:t(`\x1B[107m`,`\x1B[49m`)}};t.exports=c(),t.exports.createColors=c}))(),1);const j={name:`Building file tree`,onSuccess:(e,t)=>`Built file tree (${d(t)})`,run:async t=>({fileTree:e(t.appDir)})},M={name:`Building segment tree...`,onSuccess:(e,t)=>`Built segment tree (${d(t)})`,run:async e=>({segmentTree:n(e.fileTree)})},N={name:`Building route chain map`,onSuccess:(e,t)=>`Built route chain map (${d(t)})`,run:async e=>({routeChainMap:i(e.segmentTree,e.outDir)})},P={name:`Building component index map`,onSuccess:(e,t)=>`Built component map (${d(t)})`,run:async e=>({componentIdMap:r(e.routeChainMap)})},F=`route-chain-map.ts`,I={name:`Writing ${F}`,onSuccess:(e,t)=>`Saved ${F}} (${d(t)})`,run:async e=>{let t=o(e.outDir,`artifacts`),n=o(t,F),r=[`// Auto-generated by ${D}`,`// Do not manually edit this file`,`// NOTE: This file is kept for documentation/debugging.`,`// Runtime uses pre-built routes from routes.ts instead.`,``,`import type { RouteChainMap } from '${D}'`,``,`export const routes: RouteChainMap = ${JSON.stringify(e.routeChainMap,null,2)} as const`,``].join(`
3
+ `);await m(t,{recursive:!0}),await h(n,r,`utf-8`)}},L={name:`Serializing routes`,onSuccess:(e,t)=>`Serialized routes (${d(t)})`,run:async e=>({serializedRoutes:a(e.routeChainMap,e.componentIdMap)})},R=`serialized-route-tree.ts`,z={name:`Writing ${R}`,onSuccess:(e,t)=>`Saved ${R} (${d(t)})`,run:async e=>{let t=o(e.outDir,`artifacts`),n=o(t,R),r=[`// Auto-generated by ${D}`,`// Do not manually edit this file`,`// NOTE: This file is kept for documentation/debugging.`,``,`import type { SerializedRouteTreeMap } from '${D}'`,``,`export const serializedRoutes: SerializedRouteTreeMap = ${JSON.stringify(e.serializedRoutes,null,2)} as const`,``].join(`
4
+ `);await m(t,{recursive:!0}),await h(n,r,`utf-8`)}},B=`component-id-map.ts`,V={name:`Writing ${B}`,onSuccess:(e,t)=>`Saved ${B} (${d(t)})`,run:async e=>{let t=o(e.outDir,`artifacts`),n=o(t,B),r=e.componentIdMap,i=[`// Auto-generated by ${D}`,`// Do not manually edit this file`,``,`import type { ComponentIdMap } from '${D}'`,``,`export const componentIdMap: ComponentIdMap = ${JSON.stringify(r,null,2)} as const`,``].join(`
5
+ `);await m(t,{recursive:!0}),await h(n,i,`utf-8`)}},H=`compiled-routes.ts`,U={name:`Writing ${H}`,onSuccess:(e,t)=>`Saved ${H} (${d(t)})`,run:async e=>{let t=o(e.outDir,`generated`),n=o(t,H),r=e.serializedRoutes,i=e.componentIdMap,a=Object.keys(i).map((e,t)=>`import Component${t} from '${e}'`).join(`
6
+ `),s=[];for(let[e,t]of Object.entries(r)){let n=` ${W(t).replace(/\n/g,`
7
7
  `)}`;s.push(` '${e}':\n${n},`)}let c=[`// Auto-generated by ${D}`,`// Do not manually edit this file`,``,`import type { CompiledRoutes } from '${D}'`,`import { createElement } from 'react'`,``,a,``,`// Compiled route elements generated at build time`,`export const compiledRoutes: CompiledRoutes = {`,s.join(`
8
8
  `),`} as const`,``].join(`
9
- `);await m(t,{recursive:!0}),await h(n,c,`utf-8`)}};function B(e,t=0){let n=` `.repeat(t),r=Object.entries(e.props).map(([e,t])=>`${e}: ${t}`).join(`, `);if(!e.children)return`createElement(${e.component}, { ${r} })`;let i=B(e.children,t+1);return`createElement(${e.component}, { ${r} },\n${n} ${i}\n${n})`}const V={name:`Writing entry.ts`,onSuccess:(e,t)=>`Saved entry.ts (${d(t)})`,run:async e=>{let t=o(e.outDir,`generated`),n=o(t,`entry.ts`),r=[`// Auto-generated by ${D}`,`// Do not manually edit this file`,``,`import { createElement } from 'react'`,`import { render } from 'ink'`,`import { App } from '${D}'`,`import { compiledRoutes as routes } from './compiled-routes'`,``,`export async function run(initialUrl: string) {`,` const element = createElement(App, { initialUrl, routes })`,` const { waitUntilExit } = render(element)`,` await waitUntilExit()`,`}`,``].join(`
10
- `);await m(t,{recursive:!0}),await h(n,r,`utf-8`)}},H={name:`Compiling application`,onSuccess:(e,t)=>`Compiled application (${d(t)})`,onError:e=>`Compilation failed: ${e.message}`,run:async e=>{await g({input:s(o(e.outDir,`generated`,`entry.ts`)),platform:`node`,resolve:{extensions:[`.ts`,`.tsx`,`.js`,`.jsx`]},plugins:[_()],output:{dir:s(o(e.outDir,`dist`)),format:`esm`,sourcemap:!0,minify:!0}})}},U={name:`build`,desc:`Build the route manifest and compile application`,action:async()=>{try{let{appDir:e,outDir:n,emitMetadata:r}=await t();console.log(A.default.cyan(` Starting production build...
11
- `)),console.log(A.default.bold(` ✎ ${k} v${O}\n`)),console.log(A.default.dim(` entry: ${e}`)),console.log(A.default.dim(` target: node24`)),console.log(A.default.dim(` output: ${n}`)),console.log();let{duration:i}=await p([j,M,N,P,F,r&&I,r&&L,r&&R,z,V,H]).run({appDir:e,outDir:n});console.log(),console.log(f(n,`**/*`)),console.log(),console.log(`${A.default.green(`✓`)} Built in ${A.default.bold(d(i))}`),console.log()}catch(e){console.error(`${A.default.red(`✗`)} Build failed`),console.log();let t=e instanceof Error?e.message:String(e);console.error(A.default.red(t)),console.log(),process.exit(1)}}},W={name:`init`,desc:`Initialize a new Pen project`,action:async()=>{if(console.log(A.default.cyan(`\n Initializing ${k} project...\n`)),l(`pen.config.ts`)){console.error(A.default.yellow(`⚠`)+` Project already initialized`),console.error(A.default.dim(` pen.config.ts already exists`));return}await h(`pen.config.ts`,[`import { defineConfig } from '${D}'`,``,`export default defineConfig({`,` appDir: './src/app',`,` outDir: './.pen',`,`})`,``].join(`
9
+ `);await m(t,{recursive:!0}),await h(n,c,`utf-8`)}};function W(e,t=0){let n=` `.repeat(t),r=Object.entries(e.props).map(([e,t])=>`${e}: ${t}`).join(`, `);if(!e.children)return`createElement(${e.component}, { ${r} })`;let i=W(e.children,t+1);return`createElement(${e.component}, { ${r} },\n${n} ${i}\n${n})`}const G=`entry.ts`,K={name:`Writing ${G}`,onSuccess:(e,t)=>`Saved ${G} (${d(t)})`,run:async e=>{let t=o(e.outDir,`generated`),n=o(t,G),r=[`// Auto-generated by ${D}`,`// Do not manually edit this file`,``,`import { createElement } from 'react'`,`import { render } from 'ink'`,`import { App } from '${D}'`,`import { compiledRoutes as routes } from './compiled-routes'`,``,`export async function run(initialUrl: string) {`,` const element = createElement(App, { initialUrl, routes })`,` const { waitUntilExit } = render(element)`,` await waitUntilExit()`,`}`,``].join(`
10
+ `);await m(t,{recursive:!0}),await h(n,r,`utf-8`)}},q={name:`Compiling application`,onSuccess:(e,t)=>`Compiled application (${d(t)})`,onError:e=>`Compilation failed: ${e.message}`,run:async e=>{await g({input:s(o(e.outDir,`generated`,`entry.ts`)),platform:`node`,resolve:{extensions:[`.ts`,`.tsx`,`.js`,`.jsx`]},plugins:[_()],output:{dir:s(o(e.outDir,`dist`)),format:`esm`,sourcemap:!0,minify:!0}})}},J={name:`build`,desc:`Build the routing structure and compile application`,action:async()=>{try{let{appDir:e,outDir:n,emitMetadata:r}=await t();console.log(A.default.cyan(` Starting production build...
11
+ `)),console.log(A.default.bold(` ✎ ${k} v${O}\n`)),console.log(A.default.dim(` entry: ${e}`)),console.log(A.default.dim(` target: node24`)),console.log(A.default.dim(` output: ${n}`)),console.log();let{duration:i}=await p([j,M,N,P,L,r&&I,r&&z,r&&V,U,K,q]).run({appDir:e,outDir:n});console.log(),console.log(f(n,`**/*`)),console.log(),console.log(`${A.default.green(`✓`)} Built in ${A.default.bold(d(i))}`),console.log()}catch(e){console.error(`${A.default.red(`✗`)} Build failed`),console.log();let t=e instanceof Error?e.message:String(e);console.error(A.default.red(t)),console.log(),process.exit(1)}}},Y={name:`init`,desc:`Initialize a new Pen project`,action:async()=>{if(console.log(A.default.cyan(`\n Initializing ${k} project...\n`)),l(`pen.config.ts`)){console.error(A.default.yellow(`⚠`)+` Project already initialized`),console.error(A.default.dim(` pen.config.ts already exists`));return}await h(`pen.config.ts`,[`import { defineConfig } from '${D}'`,``,`export default defineConfig({`,` appDir: './src/app',`,` outDir: './.pen',`,`})`,``].join(`
12
12
  `),`utf-8`),console.log(A.default.green(`✓`)+` Created pen.config.ts`);let e=`./src/app`;await m(e,{recursive:!0});let t=[`import { Box, Text } from 'ink'`,`import type { ReactNode } from 'react'`,``,`export default function Layout({ children }: { children?: ReactNode }) {`,` return (`,` <Box flexDirection="column" padding={1}>`,` <Box marginBottom={1} borderStyle="round" borderColor="cyan" paddingX={2}>`,` <Text bold color="cyan">Welcome to Pen</Text>`,` </Box>`,` {children}`,` </Box>`,` )`,`}`,``].join(`
13
13
  `);await h(o(e,`layout.tsx`),t,`utf-8`),console.log(A.default.green(`✓`)+` Created src/app/layout.tsx`);let n=[`import { useState } from 'react'`,`import { Box, Text, useInput } from 'ink'`,``,`export default function Screen() {`,` const [count, setCount] = useState(0)`,``,` useInput((input) => {`,` if (input === ' ') setCount(c => c + 1)`,` })`,``,` return (`,` <Box flexDirection="column" gap={1}>`,` <Box>`,` <Text>Count: <Text bold color="green">{count}</Text></Text>`,` </Box>`,` <Box>`,` <Text dimColor>Press <Text bold>SPACE</Text> to increment</Text>`,` </Box>`,` </Box>`,` )`,`}`,``].join(`
14
- `);await h(o(e,`screen.tsx`),n,`utf-8`),console.log(A.default.green(`✓`)+` Created src/app/screen.tsx`),console.log(),console.log(A.default.green(`✓`)+` Project initialized!`),console.log(),console.log(A.default.bold(` Next steps:`)),console.log(),console.log(A.default.dim(` 1. Add scripts to package.json:`)),console.log(),console.log(` {`),console.log(` "scripts": {`),console.log(` "build": "${k} build",`),console.log(` "start": "${k} start"`),console.log(` }`),console.log(` }`),console.log(),console.log(A.default.dim(` 2. Run "npm run build" to build your app`)),console.log(A.default.dim(` 3. Run "npm run start" to start your app`)),console.log()}},G={name:`start`,desc:`Start the application`,action:async()=>{let{outDir:e}=await t(),n=s(e,`dist`,`entry.js`);if(!l(n))throw console.error(A.default.red(`✗`)+` Build not found`),console.error(A.default.dim(` Run "${k} build" first`)),Error(`Build not found`);let{run:r}=await import(c(n).href);await r(`/`)}};function K(e){e.name(k).description(`File-based routing for React Ink apps (experimental)`).version(O);let t=[U,W,G];for(let{name:n,desc:r,action:i}of t)e.command(n).description(r).action(i);return e}async function q(e){let t=K(new u);try{return await t.parseAsync(e),0}catch(e){let t=e instanceof Error?e.message:`Unknown error`;return console.error(t),1}}process.exit(await q(process.argv));export{};
14
+ `);await h(o(e,`screen.tsx`),n,`utf-8`),console.log(A.default.green(`✓`)+` Created src/app/screen.tsx`),console.log(),console.log(A.default.green(`✓`)+` Project initialized!`),console.log(),console.log(A.default.bold(` Next steps:`)),console.log(),console.log(A.default.dim(` 1. Add scripts to package.json:`)),console.log(),console.log(` {`),console.log(` "scripts": {`),console.log(` "build": "${k} build",`),console.log(` "start": "${k} start"`),console.log(` }`),console.log(` }`),console.log(),console.log(A.default.dim(` 2. Run "npm run build" to build your app`)),console.log(A.default.dim(` 3. Run "npm run start" to start your app`)),console.log()}},X={name:`start`,desc:`Start the application`,action:async()=>{let{outDir:e}=await t(),n=s(e,`dist`,`entry.js`);if(!l(n))throw console.error(A.default.red(`✗`)+` Build not found`),console.error(A.default.dim(` Run "${k} build" first`)),Error(`Build not found`);let{run:r}=await import(c(n).href);await r(`/`)}};function Z(e){e.name(k).description(`File-based routing for React Ink apps (experimental)`).version(O);let t=[J,Y,X];for(let{name:n,desc:r,action:i}of t)e.command(n).description(r).action(i);return e}async function Q(e){let t=Z(new u);try{return await t.parseAsync(e),0}catch(e){let t=e instanceof Error?e.message:`Unknown error`;return console.error(t),1}}process.exit(await Q(process.argv));export{};
15
15
  //# sourceMappingURL=bin.mjs.map
package/dist/bin.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.mjs","names":["rolldownBuild","build","pc","pc","pc","run","build"],"sources":["../src/pen/constants.ts","../node_modules/picocolors/picocolors.js","../src/cli/commands/build/tasks/build-file-tree.ts","../src/cli/commands/build/tasks/build-segment-tree.ts","../src/cli/commands/build/tasks/build-route-table.ts","../src/cli/commands/build/tasks/build-component-map.ts","../src/cli/commands/build/tasks/build-element-tree.ts","../src/cli/commands/build/tasks/write-route-table-file.ts","../src/cli/commands/build/tasks/write-element-tree-file.ts","../src/cli/commands/build/tasks/write-component-map-file.ts","../src/cli/commands/build/tasks/write-compiled-routes-file.ts","../src/cli/commands/build/tasks/write-entry-file.ts","../src/cli/commands/build/tasks/compile-application.ts","../src/cli/commands/build/index.ts","../src/cli/commands/init/index.ts","../src/cli/commands/start/index.ts","../src/cli/index.ts","../src/bin.ts"],"sourcesContent":["// Build-time globals injected by tsdown via `define`.\r\n// tsdown replaces these placeholders with actual values\r\n// from package.json at compile time.\r\n\r\ndeclare const __DESCRIPTION__: string\r\ndeclare const __PACKAGE_NAME__: string\r\ndeclare const __VERSION__: string\r\n\r\n// Package metadata\r\nexport const DESCRIPTION = __DESCRIPTION__\r\nexport const PACKAGE_NAME = __PACKAGE_NAME__\r\nexport const VERSION = __VERSION__\r\n\r\n// Framework metadata\r\nexport const CLI_NAME = __PACKAGE_NAME__.split('/')?.[1] ?? __PACKAGE_NAME__\r\n","let p = process || {}, argv = p.argv || [], env = p.env || {}\nlet isColorSupported =\n\t!(!!env.NO_COLOR || argv.includes(\"--no-color\")) &&\n\t(!!env.FORCE_COLOR || argv.includes(\"--color\") || p.platform === \"win32\" || ((p.stdout || {}).isTTY && env.TERM !== \"dumb\") || !!env.CI)\n\nlet formatter = (open, close, replace = open) =>\n\tinput => {\n\t\tlet string = \"\" + input, index = string.indexOf(close, open.length)\n\t\treturn ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close\n\t}\n\nlet replaceClose = (string, close, replace, index) => {\n\tlet result = \"\", cursor = 0\n\tdo {\n\t\tresult += string.substring(cursor, index) + replace\n\t\tcursor = index + close.length\n\t\tindex = string.indexOf(close, cursor)\n\t} while (~index)\n\treturn result + string.substring(cursor)\n}\n\nlet createColors = (enabled = isColorSupported) => {\n\tlet f = enabled ? formatter : () => String\n\treturn {\n\t\tisColorSupported: enabled,\n\t\treset: f(\"\\x1b[0m\", \"\\x1b[0m\"),\n\t\tbold: f(\"\\x1b[1m\", \"\\x1b[22m\", \"\\x1b[22m\\x1b[1m\"),\n\t\tdim: f(\"\\x1b[2m\", \"\\x1b[22m\", \"\\x1b[22m\\x1b[2m\"),\n\t\titalic: f(\"\\x1b[3m\", \"\\x1b[23m\"),\n\t\tunderline: f(\"\\x1b[4m\", \"\\x1b[24m\"),\n\t\tinverse: f(\"\\x1b[7m\", \"\\x1b[27m\"),\n\t\thidden: f(\"\\x1b[8m\", \"\\x1b[28m\"),\n\t\tstrikethrough: f(\"\\x1b[9m\", \"\\x1b[29m\"),\n\n\t\tblack: f(\"\\x1b[30m\", \"\\x1b[39m\"),\n\t\tred: f(\"\\x1b[31m\", \"\\x1b[39m\"),\n\t\tgreen: f(\"\\x1b[32m\", \"\\x1b[39m\"),\n\t\tyellow: f(\"\\x1b[33m\", \"\\x1b[39m\"),\n\t\tblue: f(\"\\x1b[34m\", \"\\x1b[39m\"),\n\t\tmagenta: f(\"\\x1b[35m\", \"\\x1b[39m\"),\n\t\tcyan: f(\"\\x1b[36m\", \"\\x1b[39m\"),\n\t\twhite: f(\"\\x1b[37m\", \"\\x1b[39m\"),\n\t\tgray: f(\"\\x1b[90m\", \"\\x1b[39m\"),\n\n\t\tbgBlack: f(\"\\x1b[40m\", \"\\x1b[49m\"),\n\t\tbgRed: f(\"\\x1b[41m\", \"\\x1b[49m\"),\n\t\tbgGreen: f(\"\\x1b[42m\", \"\\x1b[49m\"),\n\t\tbgYellow: f(\"\\x1b[43m\", \"\\x1b[49m\"),\n\t\tbgBlue: f(\"\\x1b[44m\", \"\\x1b[49m\"),\n\t\tbgMagenta: f(\"\\x1b[45m\", \"\\x1b[49m\"),\n\t\tbgCyan: f(\"\\x1b[46m\", \"\\x1b[49m\"),\n\t\tbgWhite: f(\"\\x1b[47m\", \"\\x1b[49m\"),\n\n\t\tblackBright: f(\"\\x1b[90m\", \"\\x1b[39m\"),\n\t\tredBright: f(\"\\x1b[91m\", \"\\x1b[39m\"),\n\t\tgreenBright: f(\"\\x1b[92m\", \"\\x1b[39m\"),\n\t\tyellowBright: f(\"\\x1b[93m\", \"\\x1b[39m\"),\n\t\tblueBright: f(\"\\x1b[94m\", \"\\x1b[39m\"),\n\t\tmagentaBright: f(\"\\x1b[95m\", \"\\x1b[39m\"),\n\t\tcyanBright: f(\"\\x1b[96m\", \"\\x1b[39m\"),\n\t\twhiteBright: f(\"\\x1b[97m\", \"\\x1b[39m\"),\n\n\t\tbgBlackBright: f(\"\\x1b[100m\", \"\\x1b[49m\"),\n\t\tbgRedBright: f(\"\\x1b[101m\", \"\\x1b[49m\"),\n\t\tbgGreenBright: f(\"\\x1b[102m\", \"\\x1b[49m\"),\n\t\tbgYellowBright: f(\"\\x1b[103m\", \"\\x1b[49m\"),\n\t\tbgBlueBright: f(\"\\x1b[104m\", \"\\x1b[49m\"),\n\t\tbgMagentaBright: f(\"\\x1b[105m\", \"\\x1b[49m\"),\n\t\tbgCyanBright: f(\"\\x1b[106m\", \"\\x1b[49m\"),\n\t\tbgWhiteBright: f(\"\\x1b[107m\", \"\\x1b[49m\"),\n\t}\n}\n\nmodule.exports = createColors()\nmodule.exports.createColors = createColors\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createFileTree } from '@/pen/compiler'\r\n\r\n// ===== Main Task =====\r\n\r\nexport const buildFileTree: Task<BuildContext> = {\r\n name: 'Building file tree',\r\n onSuccess: (_, dur) => `Built file tree (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n fileTree: createFileTree(ctx.appDir),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createSegmentTree } from '@/pen/compiler'\r\n\r\n// ===== Main Task =====\r\n\r\nexport const buildSegmentTree: Task<BuildContext> = {\r\n name: 'Building segment tree...',\r\n onSuccess: (_, dur) => `Built segment tree (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n segmentTree: createSegmentTree(ctx.fileTree!),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createRouteTable } from '@/pen/compiler'\r\n\r\n// ===== Main Task =====\r\n\r\nexport const buildRouteTable: Task<BuildContext> = {\r\n name: 'Building route manifest',\r\n onSuccess: (_, dur) => `Built route table (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n manifest: createRouteTable(ctx.segmentTree!, ctx.outDir),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createComponentMap } from '@/pen/compiler'\r\n\r\nexport const buildComponentMap: Task<BuildContext> = {\r\n name: 'Building component map',\r\n onSuccess: (_, dur) => `Built component map (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n componentMap: createComponentMap(ctx.manifest!),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createElementTrees } from '@/pen/compiler'\r\n\r\nexport const buildElementTree: Task<BuildContext> = {\r\n name: 'Building element trees',\r\n onSuccess: (_, dur) => `Built element trees (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n elementTrees: createElementTrees(ctx.manifest!, ctx.componentMap!),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\nexport const writeRouteTableFile: Task<BuildContext> = {\r\n name: 'Writing route-table.ts',\r\n onSuccess: (_, dur) => `Saved route-table.ts (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'generated')\r\n const outDir = join(genDir, 'route-table.ts')\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '// NOTE: This file is kept for documentation/debugging.',\r\n '// Runtime uses pre-built routes from routes.ts instead.',\r\n '',\r\n `import type { RouteTable } from '${PACKAGE_NAME}'`,\r\n '',\r\n `export const manifest: RouteTable = ${JSON.stringify(ctx.manifest!, null, 2)} as const`,\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\n// ===== Main Task =====\r\n\r\nexport const writeElementTreeFile: Task<BuildContext> = {\r\n name: 'Writing element-tree.ts',\r\n onSuccess: (_, dur) => `Saved element-tree.ts (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'generated')\r\n const outDir = join(genDir, 'element-tree.ts')\r\n\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '// NOTE: This file is kept for documentation/debugging.',\r\n '',\r\n `import type { ElementTreeMap } from '${PACKAGE_NAME}'`,\r\n '',\r\n `export const elementTrees: ElementTreeMap = ${JSON.stringify(ctx.elementTrees!, null, 2)} as const`,\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\nexport const writeComponentMapFile: Task<BuildContext> = {\r\n name: 'Writing component-map.ts',\r\n onSuccess: (_, dur) => `Saved component-map.ts (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'generated')\r\n const outDir = join(genDir, 'component-map.ts')\r\n\r\n const componentMap = ctx.componentMap!\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '',\r\n `import type { ComponentMap } from '${PACKAGE_NAME}'`,\r\n '',\r\n `export const componentMap: ComponentMap = ${JSON.stringify(componentMap, null, 2)} as const`,\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { ElementTree } from '@/pen/compiler'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\nexport const writeCompiledRoutesFile: Task<BuildContext> = {\r\n name: 'Writing compiled-routes.ts',\r\n onSuccess: (_, dur) => `Saved compiled-routes.ts (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'generated')\r\n const outDir = join(genDir, 'compiled-routes.ts')\r\n const elementTrees = ctx.elementTrees!\r\n const componentMap = ctx.componentMap!\r\n\r\n // Get sorted imports from component map\r\n const sortedImports = Object.keys(componentMap)\r\n\r\n // Generate component imports\r\n const importStatements = sortedImports\r\n .map((importPath, i) => `import Component${i} from '${importPath}'`)\r\n .join('\\n')\r\n\r\n // Generate pre-built route elements from element trees\r\n const routeElements: string[] = []\r\n for (const [url, tree] of Object.entries(elementTrees)) {\r\n const elementCode = ` ${serialize(tree).replace(/\\n/g, '\\n ')}`\r\n routeElements.push(` '${url}':\\n${elementCode},`)\r\n }\r\n\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '',\r\n `import type { CompiledRoutes } from '${PACKAGE_NAME}'`,\r\n 'import { createElement } from \\'react\\'',\r\n '',\r\n importStatements,\r\n '',\r\n '// Compiled route elements generated at build time',\r\n 'export const compiledRoutes: CompiledRoutes = {',\r\n routeElements.join('\\n'),\r\n '} as const',\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n\r\n/** Serializes an ElementTree to React.createElement() code string. */\r\nexport function serialize(tree: ElementTree, indent = 0): string {\r\n const spaces = ' '.repeat(indent)\r\n\r\n // Props are already pre-serialized (strings have quotes, identifiers don't)\r\n const props = Object.entries(tree.props)\r\n .map(([key, value]) => `${key}: ${value}`)\r\n .join(', ')\r\n\r\n if (!tree.children)\r\n return `createElement(${tree.component}, { ${props} })`\r\n\r\n const childCode = serialize(tree.children, indent + 1)\r\n return `createElement(${tree.component}, { ${props} },\\n${spaces} ${childCode}\\n${spaces})`\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\n// ===== Main Task =====\r\n\r\nexport const writeEntryFile: Task<BuildContext> = {\r\n name: 'Writing entry.ts',\r\n onSuccess: (_, dur) => `Saved entry.ts (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'generated')\r\n const outDir = join(genDir, 'entry.ts')\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '',\r\n 'import { createElement } from \\'react\\'',\r\n 'import { render } from \\'ink\\'',\r\n `import { App } from '${PACKAGE_NAME}'`,\r\n 'import { compiledRoutes as routes } from \\'./compiled-routes\\'',\r\n '',\r\n 'export async function run(initialUrl: string) {',\r\n ' const element = createElement(App, { initialUrl, routes })',\r\n ' const { waitUntilExit } = render(element)',\r\n ' await waitUntilExit()',\r\n '}',\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n","import { join, resolve } from 'path'\r\nimport { build as rolldownBuild } from 'rolldown'\r\nimport nodeExternals from 'rollup-plugin-node-externals'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\n\r\nexport const compileApplication: Task<BuildContext> = {\r\n name: 'Compiling application',\r\n onSuccess: (_, dur) => `Compiled application (${duration(dur)})`,\r\n onError: (err) => `Compilation failed: ${err.message}`,\r\n run: async (ctx) => {\r\n await rolldownBuild({\r\n input: resolve(join(ctx.outDir, 'generated', 'entry.ts')), // entry point\r\n platform: 'node',\r\n resolve: {\r\n extensions: ['.ts', '.tsx', '.js', '.jsx'],\r\n },\r\n plugins: [nodeExternals()],\r\n output: {\r\n dir: resolve(join(ctx.outDir, 'dist')),\r\n format: 'esm',\r\n sourcemap: true,\r\n minify: true,\r\n },\r\n })\r\n },\r\n}\r\n","import type { CLICommand } from '../../types'\r\nimport pc from 'picocolors'\r\nimport { pipe, duration, fileList } from '@idlesummer/tasker'\r\nimport { loadConfig } from '@/pen/config'\r\nimport { CLI_NAME, VERSION } from '@/pen/constants'\r\n\r\n// Import individual tasks\r\nimport { buildFileTree } from './tasks/build-file-tree'\r\nimport { buildSegmentTree } from './tasks/build-segment-tree'\r\nimport { buildRouteTable } from './tasks/build-route-table'\r\nimport { buildComponentMap } from './tasks/build-component-map'\r\nimport { buildElementTree } from './tasks/build-element-tree'\r\nimport { writeRouteTableFile } from './tasks/write-route-table-file'\r\nimport { writeElementTreeFile } from './tasks/write-element-tree-file'\r\nimport { writeComponentMapFile } from './tasks/write-component-map-file'\r\nimport { writeCompiledRoutesFile } from './tasks/write-compiled-routes-file'\r\nimport { writeEntryFile } from './tasks/write-entry-file'\r\nimport { compileApplication } from './tasks/compile-application'\r\n\r\nexport const build: CLICommand = {\r\n name: 'build',\r\n desc: 'Build the route manifest and compile application',\r\n action: async () => {\r\n try {\r\n const { appDir, outDir, emitMetadata } = await loadConfig()\r\n console.log(pc.cyan(' Starting production build...\\n'))\r\n console.log(pc.bold(` ✎ ${CLI_NAME} v${VERSION}\\n`))\r\n console.log(pc.dim( ` entry: ${appDir}`))\r\n console.log(pc.dim( ' target: node24'))\r\n console.log(pc.dim( ` output: ${outDir}`))\r\n console.log()\r\n\r\n const pipeline = pipe([\r\n buildFileTree,\r\n buildSegmentTree,\r\n buildRouteTable,\r\n buildComponentMap,\r\n buildElementTree,\r\n\r\n // Conditionally add metadata file generation tasks\r\n emitMetadata && writeRouteTableFile,\r\n emitMetadata && writeElementTreeFile,\r\n emitMetadata && writeComponentMapFile,\r\n\r\n writeCompiledRoutesFile,\r\n writeEntryFile,\r\n compileApplication,\r\n ])\r\n\r\n const { duration: dur } = await pipeline.run({ appDir, outDir })\r\n console.log()\r\n console.log(fileList(outDir, '**/*'))\r\n console.log()\r\n console.log(`${pc.green('✓')} Built in ${pc.bold(duration(dur))}`)\r\n console.log()\r\n }\r\n\r\n catch (err) {\r\n console.error(`${pc.red('✗')} Build failed`)\r\n console.log()\r\n\r\n const message = err instanceof Error ? err.message : String(err)\r\n console.error(pc.red(message))\r\n console.log()\r\n process.exit(1)\r\n }\r\n },\r\n}\r\n","import { existsSync } from 'fs'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport pc from 'picocolors'\r\n\r\nimport { CLI_NAME, PACKAGE_NAME } from '@/pen/constants'\r\nimport type { CLICommand } from '../../types'\r\n\r\nexport const init: CLICommand = {\r\n name: 'init',\r\n desc: 'Initialize a new Pen project',\r\n action: async () => {\r\n console.log(pc.cyan(`\\n Initializing ${CLI_NAME} project...\\n`))\r\n\r\n // Check if already initialized\r\n if (existsSync('pen.config.ts')) {\r\n console.error(pc.yellow('⚠') + ' Project already initialized')\r\n console.error(pc.dim(' pen.config.ts already exists'))\r\n return\r\n }\r\n\r\n // Create pen.config.ts\r\n const configContent = [\r\n `import { defineConfig } from '${PACKAGE_NAME}'`,\r\n '',\r\n 'export default defineConfig({',\r\n ' appDir: \\'./src/app\\',',\r\n ' outDir: \\'./.pen\\',',\r\n '})',\r\n '',\r\n ].join('\\n')\r\n\r\n await writeFile('pen.config.ts', configContent, 'utf-8')\r\n console.log(pc.green('✓') + ' Created pen.config.ts')\r\n\r\n // Create src/app directory\r\n const appDir = './src/app'\r\n await mkdir(appDir, { recursive: true })\r\n\r\n // Create layout.tsx\r\n const layoutContent = [\r\n 'import { Box, Text } from \\'ink\\'',\r\n 'import type { ReactNode } from \\'react\\'',\r\n '',\r\n 'export default function Layout({ children }: { children?: ReactNode }) {',\r\n ' return (',\r\n ' <Box flexDirection=\"column\" padding={1}>',\r\n ' <Box marginBottom={1} borderStyle=\"round\" borderColor=\"cyan\" paddingX={2}>',\r\n ' <Text bold color=\"cyan\">Welcome to Pen</Text>',\r\n ' </Box>',\r\n ' {children}',\r\n ' </Box>',\r\n ' )',\r\n '}',\r\n '',\r\n ].join('\\n')\r\n\r\n await writeFile(join(appDir, 'layout.tsx'), layoutContent, 'utf-8')\r\n console.log(pc.green('✓') + ' Created src/app/layout.tsx')\r\n\r\n // Create screen.tsx\r\n const screenContent = [\r\n 'import { useState } from \\'react\\'',\r\n 'import { Box, Text, useInput } from \\'ink\\'',\r\n '',\r\n 'export default function Screen() {',\r\n ' const [count, setCount] = useState(0)',\r\n '',\r\n ' useInput((input) => {',\r\n ' if (input === \\' \\') setCount(c => c + 1)',\r\n ' })',\r\n '',\r\n ' return (',\r\n ' <Box flexDirection=\"column\" gap={1}>',\r\n ' <Box>',\r\n ' <Text>Count: <Text bold color=\"green\">{count}</Text></Text>',\r\n ' </Box>',\r\n ' <Box>',\r\n ' <Text dimColor>Press <Text bold>SPACE</Text> to increment</Text>',\r\n ' </Box>',\r\n ' </Box>',\r\n ' )',\r\n '}',\r\n '',\r\n ].join('\\n')\r\n\r\n await writeFile(join(appDir, 'screen.tsx'), screenContent, 'utf-8')\r\n console.log(pc.green('✓') + ' Created src/app/screen.tsx')\r\n\r\n // Success message with instructions\r\n console.log()\r\n console.log(pc.green('✓') + ' Project initialized!')\r\n console.log()\r\n console.log(pc.bold(' Next steps:'))\r\n console.log()\r\n console.log(pc.dim(' 1. Add scripts to package.json:'))\r\n console.log()\r\n console.log(' {')\r\n console.log(' \"scripts\": {')\r\n console.log(` \"build\": \"${CLI_NAME} build\",`)\r\n console.log(` \"start\": \"${CLI_NAME} start\"`)\r\n console.log(' }')\r\n console.log(' }')\r\n console.log()\r\n console.log(pc.dim(' 2. Run \"npm run build\" to build your app'))\r\n console.log(pc.dim(' 3. Run \"npm run start\" to start your app'))\r\n console.log()\r\n },\r\n}\r\n","import { existsSync } from 'fs'\r\nimport { resolve } from 'path'\r\nimport { pathToFileURL } from 'url'\r\nimport pc from 'picocolors'\r\n\r\nimport { loadConfig } from '@/pen/config'\r\nimport { CLI_NAME } from '@/pen/constants'\r\nimport type { CLICommand } from '../../types'\r\n\r\nexport const start: CLICommand = {\r\n name: 'start',\r\n desc: 'Start the application',\r\n action: async () => {\r\n const { outDir } = await loadConfig()\r\n const initialUrl = '/'\r\n const entryPath = resolve(outDir, 'dist', 'entry.js')\r\n\r\n // Check if build exists\r\n if (!existsSync(entryPath)) {\r\n console.error(pc.red('✗') + ' Build not found')\r\n console.error(pc.dim(` Run \"${CLI_NAME} build\" first`))\r\n throw new Error('Build not found') // Let Commander handle exit\r\n }\r\n\r\n // Import and run the bundled entry\r\n const entryUrl = pathToFileURL(entryPath).href\r\n const { run } = await import(entryUrl)\r\n\r\n // Run with initial URL\r\n await run(initialUrl)\r\n },\r\n}\r\n","import { Command } from 'commander'\r\nimport { CLI_NAME, DESCRIPTION, VERSION } from '@/pen/constants'\r\nimport { build } from './commands/build'\r\nimport { init } from './commands/init'\r\nimport { start } from './commands/start'\r\n\r\nfunction configureProgram(program: Command) {\r\n program\r\n .name(CLI_NAME)\r\n .description(DESCRIPTION)\r\n .version(VERSION)\r\n\r\n const commands = [build, init, start] as const\r\n for (const { name, desc, action } of commands) {\r\n program\r\n .command(name)\r\n .description(desc)\r\n .action(action)\r\n }\r\n return program\r\n}\r\n\r\nexport async function run(argv: string[]) {\r\n const command = new Command()\r\n const program = configureProgram(command)\r\n\r\n try {\r\n await program.parseAsync(argv)\r\n return 0\r\n }\r\n catch (err) {\r\n const message = err instanceof Error ? err.message : 'Unknown error'\r\n console.error(message)\r\n return 1\r\n }\r\n}\r\n","#!/usr/bin/env node\r\n\r\nimport { run } from './cli'\r\n\r\nprocess.exit(await run(process.argv))\r\n"],"x_google_ignoreList":[1],"mappings":";k8BASA,MACa,EAAA,kBACA,EAAA,QAGA,EAAA,kBAA4B,MAAM,IAAI,GAAG,IAAA,qCCdtD,IAAI,EAAI,SAAW,EAAE,CAAE,EAAO,EAAE,MAAQ,EAAE,CAAE,EAAM,EAAE,KAAO,EAAE,CACzD,EACH,EAAI,EAAI,UAAY,EAAK,SAAS,aAAa,IAC9C,CAAC,CAAC,EAAI,aAAe,EAAK,SAAS,UAAU,EAAI,EAAE,WAAa,UAAa,EAAE,QAAU,EAAE,EAAE,OAAS,EAAI,OAAS,QAAW,CAAC,CAAC,EAAI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AGrD,GAAI,CAAC,EAAW,EAAU,CAGxB,MAFA,QAAQ,MAAMC,EAAAA,QAAG,IAAI,IAAI,CAAG,mBAAmB,CAC/C,QAAQ,MAAMA,EAAAA,QAAG,IAAI,UAAU,EAAS,eAAe,CAAC,CAC9C,MAAM,kBAAkB,CAKpC,GAAM,CAAE,IAAA,GAAQ,MAAM,OADL,EAAc,EAAU,CAAC,MAI1C,MAAMC,EAAI,IAAW,EAExB,CCzBD,SAAS,EAAiB,EAAkB,CAC1C,EACG,KAAK,EAAS,CACd,YAAY,uDAAY,CACxB,QAAQ,EAAQ,CAEnB,IAAM,EAAW,CAACC,EAAO,EAAM,EAAM,CACrC,IAAK,GAAM,CAAE,OAAM,OAAM,YAAY,EACnC,EACG,QAAQ,EAAK,CACb,YAAY,EAAK,CACjB,OAAO,EAAO,CAEnB,OAAO,EAGT,eAAsB,EAAI,EAAgB,CAExC,IAAM,EAAU,EADA,IAAI,EACqB,CAEzC,GAAI,CAEF,OADA,MAAM,EAAQ,WAAW,EAAK,CACvB,QAEF,EAAK,CACV,IAAM,EAAU,aAAe,MAAQ,EAAI,QAAU,gBAErD,OADA,QAAQ,MAAM,EAAQ,CACf,GC7BX,QAAQ,KAAK,MAAM,EAAI,QAAQ,KAAK,CAAC"}
1
+ {"version":3,"file":"bin.mjs","names":["filename","filename","filename","filename","rolldownBuild","build","pc","pc","pc","run","build"],"sources":["../src/pen/constants.ts","../node_modules/picocolors/picocolors.js","../src/cli/commands/build/tasks/build-file-tree.ts","../src/cli/commands/build/tasks/build-segment-tree.ts","../src/cli/commands/build/tasks/build-route-chain-map.ts","../src/cli/commands/build/tasks/build-component-id-map.ts","../src/cli/commands/build/tasks/write-route-chain-map-file.ts","../src/cli/commands/build/tasks/build-serialized-routes.ts","../src/cli/commands/build/tasks/write-serialized-routes-file.ts","../src/cli/commands/build/tasks/write-component-id-map-file.ts","../src/cli/commands/build/tasks/write-compiled-routes-file.ts","../src/cli/commands/build/tasks/write-entry-file.ts","../src/cli/commands/build/tasks/compile-application.ts","../src/cli/commands/build/index.ts","../src/cli/commands/init/index.ts","../src/cli/commands/start/index.ts","../src/cli/index.ts","../src/bin.ts"],"sourcesContent":["// Build-time globals injected by tsdown via `define`.\r\n// tsdown replaces these placeholders with actual values\r\n// from package.json at compile time.\r\n\r\ndeclare const __DESCRIPTION__: string\r\ndeclare const __PACKAGE_NAME__: string\r\ndeclare const __VERSION__: string\r\n\r\n// Package metadata\r\nexport const DESCRIPTION = __DESCRIPTION__\r\nexport const PACKAGE_NAME = __PACKAGE_NAME__\r\nexport const VERSION = __VERSION__\r\n\r\n// Framework metadata\r\nexport const CLI_NAME = __PACKAGE_NAME__.split('/')?.[1] ?? __PACKAGE_NAME__\r\n","let p = process || {}, argv = p.argv || [], env = p.env || {}\nlet isColorSupported =\n\t!(!!env.NO_COLOR || argv.includes(\"--no-color\")) &&\n\t(!!env.FORCE_COLOR || argv.includes(\"--color\") || p.platform === \"win32\" || ((p.stdout || {}).isTTY && env.TERM !== \"dumb\") || !!env.CI)\n\nlet formatter = (open, close, replace = open) =>\n\tinput => {\n\t\tlet string = \"\" + input, index = string.indexOf(close, open.length)\n\t\treturn ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close\n\t}\n\nlet replaceClose = (string, close, replace, index) => {\n\tlet result = \"\", cursor = 0\n\tdo {\n\t\tresult += string.substring(cursor, index) + replace\n\t\tcursor = index + close.length\n\t\tindex = string.indexOf(close, cursor)\n\t} while (~index)\n\treturn result + string.substring(cursor)\n}\n\nlet createColors = (enabled = isColorSupported) => {\n\tlet f = enabled ? formatter : () => String\n\treturn {\n\t\tisColorSupported: enabled,\n\t\treset: f(\"\\x1b[0m\", \"\\x1b[0m\"),\n\t\tbold: f(\"\\x1b[1m\", \"\\x1b[22m\", \"\\x1b[22m\\x1b[1m\"),\n\t\tdim: f(\"\\x1b[2m\", \"\\x1b[22m\", \"\\x1b[22m\\x1b[2m\"),\n\t\titalic: f(\"\\x1b[3m\", \"\\x1b[23m\"),\n\t\tunderline: f(\"\\x1b[4m\", \"\\x1b[24m\"),\n\t\tinverse: f(\"\\x1b[7m\", \"\\x1b[27m\"),\n\t\thidden: f(\"\\x1b[8m\", \"\\x1b[28m\"),\n\t\tstrikethrough: f(\"\\x1b[9m\", \"\\x1b[29m\"),\n\n\t\tblack: f(\"\\x1b[30m\", \"\\x1b[39m\"),\n\t\tred: f(\"\\x1b[31m\", \"\\x1b[39m\"),\n\t\tgreen: f(\"\\x1b[32m\", \"\\x1b[39m\"),\n\t\tyellow: f(\"\\x1b[33m\", \"\\x1b[39m\"),\n\t\tblue: f(\"\\x1b[34m\", \"\\x1b[39m\"),\n\t\tmagenta: f(\"\\x1b[35m\", \"\\x1b[39m\"),\n\t\tcyan: f(\"\\x1b[36m\", \"\\x1b[39m\"),\n\t\twhite: f(\"\\x1b[37m\", \"\\x1b[39m\"),\n\t\tgray: f(\"\\x1b[90m\", \"\\x1b[39m\"),\n\n\t\tbgBlack: f(\"\\x1b[40m\", \"\\x1b[49m\"),\n\t\tbgRed: f(\"\\x1b[41m\", \"\\x1b[49m\"),\n\t\tbgGreen: f(\"\\x1b[42m\", \"\\x1b[49m\"),\n\t\tbgYellow: f(\"\\x1b[43m\", \"\\x1b[49m\"),\n\t\tbgBlue: f(\"\\x1b[44m\", \"\\x1b[49m\"),\n\t\tbgMagenta: f(\"\\x1b[45m\", \"\\x1b[49m\"),\n\t\tbgCyan: f(\"\\x1b[46m\", \"\\x1b[49m\"),\n\t\tbgWhite: f(\"\\x1b[47m\", \"\\x1b[49m\"),\n\n\t\tblackBright: f(\"\\x1b[90m\", \"\\x1b[39m\"),\n\t\tredBright: f(\"\\x1b[91m\", \"\\x1b[39m\"),\n\t\tgreenBright: f(\"\\x1b[92m\", \"\\x1b[39m\"),\n\t\tyellowBright: f(\"\\x1b[93m\", \"\\x1b[39m\"),\n\t\tblueBright: f(\"\\x1b[94m\", \"\\x1b[39m\"),\n\t\tmagentaBright: f(\"\\x1b[95m\", \"\\x1b[39m\"),\n\t\tcyanBright: f(\"\\x1b[96m\", \"\\x1b[39m\"),\n\t\twhiteBright: f(\"\\x1b[97m\", \"\\x1b[39m\"),\n\n\t\tbgBlackBright: f(\"\\x1b[100m\", \"\\x1b[49m\"),\n\t\tbgRedBright: f(\"\\x1b[101m\", \"\\x1b[49m\"),\n\t\tbgGreenBright: f(\"\\x1b[102m\", \"\\x1b[49m\"),\n\t\tbgYellowBright: f(\"\\x1b[103m\", \"\\x1b[49m\"),\n\t\tbgBlueBright: f(\"\\x1b[104m\", \"\\x1b[49m\"),\n\t\tbgMagentaBright: f(\"\\x1b[105m\", \"\\x1b[49m\"),\n\t\tbgCyanBright: f(\"\\x1b[106m\", \"\\x1b[49m\"),\n\t\tbgWhiteBright: f(\"\\x1b[107m\", \"\\x1b[49m\"),\n\t}\n}\n\nmodule.exports = createColors()\nmodule.exports.createColors = createColors\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createFileTree } from '@/pen/compiler'\r\n\r\n// ===== Main Task =====\r\n\r\nexport const buildFileTree: Task<BuildContext> = {\r\n name: 'Building file tree',\r\n onSuccess: (_, dur) => `Built file tree (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n fileTree: createFileTree(ctx.appDir),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createSegmentTree } from '@/pen/compiler'\r\n\r\n// ===== Main Task =====\r\n\r\nexport const buildSegmentTree: Task<BuildContext> = {\r\n name: 'Building segment tree...',\r\n onSuccess: (_, dur) => `Built segment tree (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n segmentTree: createSegmentTree(ctx.fileTree!),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createRouteChainMap } from '@/pen/compiler'\r\n\r\n// ===== Main Task =====\r\n\r\nexport const buildRouteChainMap: Task<BuildContext> = {\r\n name: 'Building route chain map',\r\n onSuccess: (_, dur) => `Built route chain map (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n routeChainMap: createRouteChainMap(ctx.segmentTree!, ctx.outDir),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createComponentIdMap } from '@/pen/compiler'\r\n\r\nexport const buildComponentIdMap: Task<BuildContext> = {\r\n name: 'Building component index map',\r\n onSuccess: (_, dur) => `Built component map (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n componentIdMap: createComponentIdMap(ctx.routeChainMap!),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\nconst filename = 'route-chain-map.ts'\r\n\r\nexport const writeRouteMapFile: Task<BuildContext> = {\r\n name: `Writing ${filename}`,\r\n onSuccess: (_, dur) => `Saved ${filename}} (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'artifacts')\r\n const outDir = join(genDir, filename)\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '// NOTE: This file is kept for documentation/debugging.',\r\n '// Runtime uses pre-built routes from routes.ts instead.',\r\n '',\r\n `import type { RouteChainMap } from '${PACKAGE_NAME}'`,\r\n '',\r\n `export const routes: RouteChainMap = ${JSON.stringify(ctx.routeChainMap!, null, 2)} as const`,\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { createSerializedRoutes } from '@/pen/compiler'\r\n\r\nexport const buildSerializedRoutes: Task<BuildContext> = {\r\n name: 'Serializing routes',\r\n onSuccess: (_, dur) => `Serialized routes (${duration(dur)})`,\r\n run: async (ctx) => ({\r\n serializedRoutes: createSerializedRoutes(ctx.routeChainMap!, ctx.componentIdMap!),\r\n }),\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\nconst filename = 'serialized-route-tree.ts'\r\n\r\nexport const writeSerializedTreeFile: Task<BuildContext> = {\r\n name: `Writing ${filename}`,\r\n onSuccess: (_, dur) => `Saved ${filename} (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'artifacts')\r\n const outDir = join(genDir, filename)\r\n\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '// NOTE: This file is kept for documentation/debugging.',\r\n '',\r\n `import type { SerializedRouteTreeMap } from '${PACKAGE_NAME}'`,\r\n '',\r\n `export const serializedRoutes: SerializedRouteTreeMap = ${JSON.stringify(ctx.serializedRoutes!, null, 2)} as const`,\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\nconst filename = 'component-id-map.ts'\r\n\r\nexport const writeComponentIdMapFile: Task<BuildContext> = {\r\n name: `Writing ${filename}`,\r\n onSuccess: (_, dur) => `Saved ${filename} (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'artifacts')\r\n const outDir = join(genDir, filename)\r\n\r\n const componentIdMap = ctx.componentIdMap!\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '',\r\n `import type { ComponentIdMap } from '${PACKAGE_NAME}'`,\r\n '',\r\n `export const componentIdMap: ComponentIdMap = ${JSON.stringify(componentIdMap, null, 2)} as const`,\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { SerializedTree } from '@/pen/compiler'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\nconst filename = 'compiled-routes.ts'\r\n\r\nexport const writeCompiledRoutesFile: Task<BuildContext> = {\r\n name: `Writing ${filename}`,\r\n onSuccess: (_, dur) => `Saved ${filename} (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'generated')\r\n const outDir = join(genDir, filename)\r\n const serializedRoutes = ctx.serializedRoutes!\r\n const componentIdMap = ctx.componentIdMap!\r\n\r\n // Get sorted imports from component map\r\n const sortedImports = Object.keys(componentIdMap)\r\n\r\n // Generate component imports\r\n const importStatements = sortedImports\r\n .map((importPath, i) => `import Component${i} from '${importPath}'`)\r\n .join('\\n')\r\n\r\n // Generate pre-built route components from element trees\r\n const routeEntries: string[] = []\r\n for (const [url, tree] of Object.entries(serializedRoutes)) {\r\n const elementCode = ` ${serialize(tree).replace(/\\n/g, '\\n ')}`\r\n routeEntries.push(` '${url}':\\n${elementCode},`)\r\n }\r\n\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '',\r\n `import type { CompiledRoutes } from '${PACKAGE_NAME}'`,\r\n 'import { createElement } from \\'react\\'',\r\n '',\r\n importStatements,\r\n '',\r\n '// Compiled route elements generated at build time',\r\n 'export const compiledRoutes: CompiledRoutes = {',\r\n routeEntries.join('\\n'),\r\n '} as const',\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n\r\n/** Serializes an SerializedTree to React.createElement() code string. */\r\nexport function serialize(tree: SerializedTree, indent = 0): string {\r\n const spaces = ' '.repeat(indent)\r\n\r\n // Props are already pre-serialized (strings have quotes, identifiers don't)\r\n const props = Object.entries(tree.props)\r\n .map(([key, value]) => `${key}: ${value}`)\r\n .join(', ')\r\n\r\n if (!tree.children)\r\n return `createElement(${tree.component}, { ${props} })`\r\n\r\n const childCode = serialize(tree.children, indent + 1)\r\n return `createElement(${tree.component}, { ${props} },\\n${spaces} ${childCode}\\n${spaces})`\r\n}\r\n","import type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport { PACKAGE_NAME } from '@/pen/constants'\r\n\r\nconst filename = 'entry.ts'\r\n\r\nexport const writeEntryFile: Task<BuildContext> = {\r\n name: `Writing ${filename}`,\r\n onSuccess: (_, dur) => `Saved ${filename} (${duration(dur)})`,\r\n run: async (ctx) => {\r\n const genDir = join(ctx.outDir, 'generated')\r\n const outDir = join(genDir, filename)\r\n const code = [\r\n `// Auto-generated by ${PACKAGE_NAME}`,\r\n '// Do not manually edit this file',\r\n '',\r\n 'import { createElement } from \\'react\\'',\r\n 'import { render } from \\'ink\\'',\r\n `import { App } from '${PACKAGE_NAME}'`,\r\n 'import { compiledRoutes as routes } from \\'./compiled-routes\\'',\r\n '',\r\n 'export async function run(initialUrl: string) {',\r\n ' const element = createElement(App, { initialUrl, routes })',\r\n ' const { waitUntilExit } = render(element)',\r\n ' await waitUntilExit()',\r\n '}',\r\n '',\r\n ].join('\\n')\r\n\r\n await mkdir(genDir, { recursive: true })\r\n await writeFile(outDir, code, 'utf-8')\r\n },\r\n}\r\n","import { join, resolve } from 'path'\r\nimport { build as rolldownBuild } from 'rolldown'\r\nimport nodeExternals from 'rollup-plugin-node-externals'\r\nimport { duration } from '@idlesummer/tasker'\r\nimport type { Task } from '@idlesummer/tasker'\r\nimport type { BuildContext } from '../types'\r\n\r\nexport const compileApplication: Task<BuildContext> = {\r\n name: 'Compiling application',\r\n onSuccess: (_, dur) => `Compiled application (${duration(dur)})`,\r\n onError: (err) => `Compilation failed: ${err.message}`,\r\n run: async (ctx) => {\r\n await rolldownBuild({\r\n input: resolve(join(ctx.outDir, 'generated', 'entry.ts')), // entry point\r\n platform: 'node',\r\n resolve: {\r\n extensions: ['.ts', '.tsx', '.js', '.jsx'],\r\n },\r\n plugins: [nodeExternals()],\r\n output: {\r\n dir: resolve(join(ctx.outDir, 'dist')),\r\n format: 'esm',\r\n sourcemap: true,\r\n minify: true,\r\n },\r\n })\r\n },\r\n}\r\n","import type { CLICommand } from '../../types'\r\nimport pc from 'picocolors'\r\nimport { pipe, duration, fileList } from '@idlesummer/tasker'\r\nimport { loadConfig } from '@/pen/config'\r\nimport { CLI_NAME, VERSION } from '@/pen/constants'\r\n\r\n// Import individual tasks\r\nimport { buildFileTree } from './tasks/build-file-tree'\r\nimport { buildSegmentTree } from './tasks/build-segment-tree'\r\nimport { buildRouteChainMap } from './tasks/build-route-chain-map'\r\nimport { buildComponentIdMap } from './tasks/build-component-id-map'\r\nimport { writeRouteMapFile } from './tasks/write-route-chain-map-file'\r\nimport { buildSerializedRoutes } from './tasks/build-serialized-routes'\r\nimport { writeSerializedTreeFile } from './tasks/write-serialized-routes-file'\r\nimport { writeComponentIdMapFile } from './tasks/write-component-id-map-file'\r\nimport { writeCompiledRoutesFile } from './tasks/write-compiled-routes-file'\r\nimport { writeEntryFile } from './tasks/write-entry-file'\r\nimport { compileApplication } from './tasks/compile-application'\r\n\r\nexport const build: CLICommand = {\r\n name: 'build',\r\n desc: 'Build the routing structure and compile application',\r\n action: async () => {\r\n try {\r\n const { appDir, outDir, emitMetadata } = await loadConfig()\r\n console.log(pc.cyan(' Starting production build...\\n'))\r\n console.log(pc.bold(` ✎ ${CLI_NAME} v${VERSION}\\n`))\r\n console.log(pc.dim( ` entry: ${appDir}`))\r\n console.log(pc.dim( ' target: node24'))\r\n console.log(pc.dim( ` output: ${outDir}`))\r\n console.log()\r\n\r\n const pipeline = pipe([\r\n buildFileTree,\r\n buildSegmentTree,\r\n buildRouteChainMap,\r\n buildComponentIdMap,\r\n buildSerializedRoutes,\r\n\r\n // Conditionally add metadata file generation tasks\r\n emitMetadata && writeRouteMapFile,\r\n emitMetadata && writeSerializedTreeFile,\r\n emitMetadata && writeComponentIdMapFile,\r\n\r\n writeCompiledRoutesFile,\r\n writeEntryFile,\r\n compileApplication,\r\n ])\r\n\r\n const { duration: dur } = await pipeline.run({ appDir, outDir })\r\n console.log()\r\n console.log(fileList(outDir, '**/*'))\r\n console.log()\r\n console.log(`${pc.green('✓')} Built in ${pc.bold(duration(dur))}`)\r\n console.log()\r\n }\r\n\r\n catch (err) {\r\n console.error(`${pc.red('✗')} Build failed`)\r\n console.log()\r\n\r\n const message = err instanceof Error ? err.message : String(err)\r\n console.error(pc.red(message))\r\n console.log()\r\n process.exit(1)\r\n }\r\n },\r\n}\r\n","import { existsSync } from 'fs'\r\nimport { mkdir, writeFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport pc from 'picocolors'\r\n\r\nimport { CLI_NAME, PACKAGE_NAME } from '@/pen/constants'\r\nimport type { CLICommand } from '../../types'\r\n\r\nexport const init: CLICommand = {\r\n name: 'init',\r\n desc: 'Initialize a new Pen project',\r\n action: async () => {\r\n console.log(pc.cyan(`\\n Initializing ${CLI_NAME} project...\\n`))\r\n\r\n // Check if already initialized\r\n if (existsSync('pen.config.ts')) {\r\n console.error(pc.yellow('⚠') + ' Project already initialized')\r\n console.error(pc.dim(' pen.config.ts already exists'))\r\n return\r\n }\r\n\r\n // Create pen.config.ts\r\n const configContent = [\r\n `import { defineConfig } from '${PACKAGE_NAME}'`,\r\n '',\r\n 'export default defineConfig({',\r\n ' appDir: \\'./src/app\\',',\r\n ' outDir: \\'./.pen\\',',\r\n '})',\r\n '',\r\n ].join('\\n')\r\n\r\n await writeFile('pen.config.ts', configContent, 'utf-8')\r\n console.log(pc.green('✓') + ' Created pen.config.ts')\r\n\r\n // Create src/app directory\r\n const appDir = './src/app'\r\n await mkdir(appDir, { recursive: true })\r\n\r\n // Create layout.tsx\r\n const layoutContent = [\r\n 'import { Box, Text } from \\'ink\\'',\r\n 'import type { ReactNode } from \\'react\\'',\r\n '',\r\n 'export default function Layout({ children }: { children?: ReactNode }) {',\r\n ' return (',\r\n ' <Box flexDirection=\"column\" padding={1}>',\r\n ' <Box marginBottom={1} borderStyle=\"round\" borderColor=\"cyan\" paddingX={2}>',\r\n ' <Text bold color=\"cyan\">Welcome to Pen</Text>',\r\n ' </Box>',\r\n ' {children}',\r\n ' </Box>',\r\n ' )',\r\n '}',\r\n '',\r\n ].join('\\n')\r\n\r\n await writeFile(join(appDir, 'layout.tsx'), layoutContent, 'utf-8')\r\n console.log(pc.green('✓') + ' Created src/app/layout.tsx')\r\n\r\n // Create screen.tsx\r\n const screenContent = [\r\n 'import { useState } from \\'react\\'',\r\n 'import { Box, Text, useInput } from \\'ink\\'',\r\n '',\r\n 'export default function Screen() {',\r\n ' const [count, setCount] = useState(0)',\r\n '',\r\n ' useInput((input) => {',\r\n ' if (input === \\' \\') setCount(c => c + 1)',\r\n ' })',\r\n '',\r\n ' return (',\r\n ' <Box flexDirection=\"column\" gap={1}>',\r\n ' <Box>',\r\n ' <Text>Count: <Text bold color=\"green\">{count}</Text></Text>',\r\n ' </Box>',\r\n ' <Box>',\r\n ' <Text dimColor>Press <Text bold>SPACE</Text> to increment</Text>',\r\n ' </Box>',\r\n ' </Box>',\r\n ' )',\r\n '}',\r\n '',\r\n ].join('\\n')\r\n\r\n await writeFile(join(appDir, 'screen.tsx'), screenContent, 'utf-8')\r\n console.log(pc.green('✓') + ' Created src/app/screen.tsx')\r\n\r\n // Success message with instructions\r\n console.log()\r\n console.log(pc.green('✓') + ' Project initialized!')\r\n console.log()\r\n console.log(pc.bold(' Next steps:'))\r\n console.log()\r\n console.log(pc.dim(' 1. Add scripts to package.json:'))\r\n console.log()\r\n console.log(' {')\r\n console.log(' \"scripts\": {')\r\n console.log(` \"build\": \"${CLI_NAME} build\",`)\r\n console.log(` \"start\": \"${CLI_NAME} start\"`)\r\n console.log(' }')\r\n console.log(' }')\r\n console.log()\r\n console.log(pc.dim(' 2. Run \"npm run build\" to build your app'))\r\n console.log(pc.dim(' 3. Run \"npm run start\" to start your app'))\r\n console.log()\r\n },\r\n}\r\n","import { existsSync } from 'fs'\r\nimport { resolve } from 'path'\r\nimport { pathToFileURL } from 'url'\r\nimport pc from 'picocolors'\r\n\r\nimport { loadConfig } from '@/pen/config'\r\nimport { CLI_NAME } from '@/pen/constants'\r\nimport type { CLICommand } from '../../types'\r\n\r\nexport const start: CLICommand = {\r\n name: 'start',\r\n desc: 'Start the application',\r\n action: async () => {\r\n const { outDir } = await loadConfig()\r\n const initialUrl = '/'\r\n const entryPath = resolve(outDir, 'dist', 'entry.js')\r\n\r\n // Check if build exists\r\n if (!existsSync(entryPath)) {\r\n console.error(pc.red('✗') + ' Build not found')\r\n console.error(pc.dim(` Run \"${CLI_NAME} build\" first`))\r\n throw new Error('Build not found') // Let Commander handle exit\r\n }\r\n\r\n // Import and run the bundled entry\r\n const entryUrl = pathToFileURL(entryPath).href\r\n const { run } = await import(entryUrl)\r\n\r\n // Run with initial URL\r\n await run(initialUrl)\r\n },\r\n}\r\n","import { Command } from 'commander'\r\nimport { CLI_NAME, DESCRIPTION, VERSION } from '@/pen/constants'\r\nimport { build } from './commands/build'\r\nimport { init } from './commands/init'\r\nimport { start } from './commands/start'\r\n\r\nfunction configureProgram(program: Command) {\r\n program\r\n .name(CLI_NAME)\r\n .description(DESCRIPTION)\r\n .version(VERSION)\r\n\r\n const commands = [build, init, start] as const\r\n for (const { name, desc, action } of commands) {\r\n program\r\n .command(name)\r\n .description(desc)\r\n .action(action)\r\n }\r\n return program\r\n}\r\n\r\nexport async function run(argv: string[]) {\r\n const command = new Command()\r\n const program = configureProgram(command)\r\n\r\n try {\r\n await program.parseAsync(argv)\r\n return 0\r\n }\r\n catch (err) {\r\n const message = err instanceof Error ? err.message : 'Unknown error'\r\n console.error(message)\r\n return 1\r\n }\r\n}\r\n","#!/usr/bin/env node\r\n\r\nimport { run } from './cli'\r\n\r\nprocess.exit(await run(process.argv))\r\n"],"x_google_ignoreList":[1],"mappings":";u8BASA,MACa,EAAA,kBACA,EAAA,QAGA,EAAA,kBAA4B,MAAM,IAAI,GAAG,IAAA,qCCdtD,IAAI,EAAI,SAAW,EAAE,CAAE,EAAO,EAAE,MAAQ,EAAE,CAAE,EAAM,EAAE,KAAO,EAAE,CACzD,EACH,EAAI,EAAI,UAAY,EAAK,SAAS,aAAa,IAC9C,CAAC,CAAC,EAAI,aAAe,EAAK,SAAS,UAAU,EAAI,EAAE,WAAa,UAAa,EAAE,QAAU,EAAE,EAAE,OAAS,EAAI,OAAS,QAAW,CAAC,CAAC,EAAI,IAElI,GAAa,EAAM,EAAO,EAAU,IACvC,GAAS,CACR,IAAI,EAAS,GAAK,EAAO,EAAQ,EAAO,QAAQ,EAAO,EAAK,OAAO,CACnE,MAAO,CAAC,EAAQ,EAAO,EAAa,EAAQ,EAAO,EAAS,EAAM,CAAG,EAAQ,EAAO,EAAS,GAG3F,GAAgB,EAAQ,EAAO,EAAS,IAAU,CACrD,IAAI,EAAS,GAAI,EAAS,EAC1B,EACC,IAAU,EAAO,UAAU,EAAQ,EAAM,CAAG,EAC5C,EAAS,EAAQ,EAAM,OACvB,EAAQ,EAAO,QAAQ,EAAO,EAAO,OAC7B,CAAC,GACV,OAA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c,EAAU,CAAC,MAI1C,MAAMC,EAAI,IAAW,EAExB,CCzBD,SAAS,EAAiB,EAAkB,CAC1C,EACG,KAAK,EAAS,CACd,YAAY,uDAAY,CACxB,QAAQ,EAAQ,CAEnB,IAAM,EAAW,CAACC,EAAO,EAAM,EAAM,CACrC,IAAK,GAAM,CAAE,OAAM,OAAM,YAAY,EACnC,EACG,QAAQ,EAAK,CACb,YAAY,EAAK,CACjB,OAAO,EAAO,CAEnB,OAAO,EAGT,eAAsB,EAAI,EAAgB,CAExC,IAAM,EAAU,EADA,IAAI,EACqB,CAEzC,GAAI,CAEF,OADA,MAAM,EAAQ,WAAW,EAAK,CACvB,QAEF,EAAK,CACV,IAAM,EAAU,aAAe,MAAQ,EAAI,QAAU,gBAErD,OADA,QAAQ,MAAM,EAAQ,CACf,GC7BX,QAAQ,KAAK,MAAM,EAAI,QAAQ,KAAK,CAAC"}
package/dist/index.d.mts CHANGED
@@ -86,8 +86,8 @@ type SegmentNode = {
86
86
  */
87
87
  declare function createSegmentTree(fileTree: FileNode): SegmentNode;
88
88
  //#endregion
89
- //#region src/pen/compiler/builders/route-manifest.d.ts
90
- type RouteTable = Record<string, Route>;
89
+ //#region src/pen/compiler/builders/route-chain-map.d.ts
90
+ type RouteChainMap = Record<string, Route>;
91
91
  type Route = {
92
92
  url: string;
93
93
  chain: SegmentRoles[];
@@ -103,30 +103,30 @@ type Route = {
103
103
  * @param outDir - Output directory (to calculate relative import paths)
104
104
  * @returns Flat manifest ready for runtime composition
105
105
  */
106
- declare function createRouteTable(segmentTree: SegmentNode, outDir: string): RouteTable;
106
+ declare function createRouteChainMap(segmentTree: SegmentNode, outDir: string): RouteChainMap;
107
107
  //#endregion
108
- //#region src/pen/compiler/builders/component-map.d.ts
108
+ //#region src/pen/compiler/builders/component-id-map.d.ts
109
109
  /** Map from import path to component index (keys are in sorted order) */
110
- type ComponentMap = Record<string, number>;
110
+ type ComponentIdMap = Record<string, number>;
111
111
  /**
112
112
  * Builds a mapping of import paths to component IDs from the manifest.
113
113
  * Collects all unique import paths and assigns them indices.
114
114
  * Keys are stored in sorted order for deterministic output.
115
115
  */
116
- declare function createComponentMap(manifest: RouteTable): ComponentMap;
116
+ declare function createComponentIdMap(routes: RouteChainMap): ComponentIdMap;
117
117
  //#endregion
118
- //#region src/pen/compiler/builders/element-tree.d.ts
119
- interface ElementTree {
118
+ //#region src/pen/compiler/builders/serialized-routes.d.ts
119
+ interface SerializedTree {
120
120
  component: string;
121
121
  props: Record<string, unknown>;
122
- children?: ElementTree;
122
+ children?: SerializedTree;
123
123
  }
124
- type ElementTreeMap = Record<string, ElementTree>;
124
+ type SerializedRouteTreeMap = Record<string, SerializedTree>;
125
125
  /**
126
- * Creates element trees for all routes in the manifest.
126
+ * Creates element trees for all routeChain in the manifest.
127
127
  * Each tree represents the nested React component structure for a route.
128
128
  */
129
- declare function createElementTrees(manifest: RouteTable, componentMap: ComponentMap): ElementTreeMap;
129
+ declare function createSerializedRoutes(routeChain: RouteChainMap, componentIdMap: ComponentIdMap): SerializedRouteTreeMap;
130
130
  //#endregion
131
131
  //#region src/pen/compiler/errors.d.ts
132
132
  /**
@@ -371,5 +371,5 @@ interface MemoryUsage {
371
371
  */
372
372
  declare function useMemoryMonitor(intervalMs?: number): MemoryUsage;
373
373
  //#endregion
374
- export { App, type AppProps, type CompiledRoutes, type ComponentMap, ComponentNotFoundError, DirectoryNotFoundError, DuplicateScreenError, type ElementTree, type ElementTreeMap, EmptyChainError, ErrorBoundary, type ErrorComponentProps, ErrorScreen, type FileNode, FileRouter, FileRouterError, type FileRouterProps, MemoryUsage, NotADirectoryError, NotFoundBoundary, type NotFoundComponentProps, NotFoundError, NotFoundScreen, PenConfig, ResolvedPenConfig, RootIsFileError, type Route, type RouteTable, RouterContext, type RouterContextValue, RouterProvider, type RouterProviderProps, type SegmentNode, type SegmentRoles, createComponentMap, createElementTrees, createFileTree, createRouteTable, createSegmentTree, defineConfig, loadConfig, useHistory, useMemoryMonitor, useNavigate, useRouteData, useRouter, useUrl };
374
+ export { App, type AppProps, type CompiledRoutes, type ComponentIdMap, ComponentNotFoundError, DirectoryNotFoundError, DuplicateScreenError, EmptyChainError, ErrorBoundary, type ErrorComponentProps, ErrorScreen, type FileNode, FileRouter, FileRouterError, type FileRouterProps, MemoryUsage, NotADirectoryError, NotFoundBoundary, type NotFoundComponentProps, NotFoundError, NotFoundScreen, PenConfig, ResolvedPenConfig, RootIsFileError, type Route, type RouteChainMap, RouterContext, type RouterContextValue, RouterProvider, type RouterProviderProps, type SegmentNode, type SegmentRoles, type SerializedRouteTreeMap, type SerializedTree, createComponentIdMap, createFileTree, createRouteChainMap, createSegmentTree, createSerializedRoutes, defineConfig, loadConfig, useHistory, useMemoryMonitor, useNavigate, useRouteData, useRouter, useUrl };
375
375
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/pen/config.ts","../src/pen/compiler/types.ts","../src/pen/compiler/builders/file-tree.ts","../src/pen/compiler/builders/segment-tree.ts","../src/pen/compiler/builders/route-manifest.ts","../src/pen/compiler/builders/component-map.ts","../src/pen/compiler/builders/element-tree.ts","../src/pen/compiler/errors.ts","../src/pen/router/RouterProvider.tsx","../src/pen/router/hooks/use-history.ts","../src/pen/router/hooks/use-navigate.ts","../src/pen/router/hooks/use-route-data.ts","../src/pen/router/hooks/use-router.ts","../src/pen/router/hooks/use-url.ts","../src/pen/runtime/App.tsx","../src/pen/runtime/ui/ErrorBoundary.tsx","../src/pen/runtime/ui/NotFoundBoundary.tsx","../src/pen/runtime/ui/ErrorScreen.tsx","../src/pen/runtime/ui/NotFoundScreen.tsx","../src/pen/runtime/FileRouter.tsx","../src/pen/runtime/errors.ts","../src/pen/utils/use-memory-monitor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAOY,iBAAA;EAAA;AAyBZ;AAEA;AAeA;;;;AC1CA;;;;ACFA;AAeA;;;;ACfA,CAAA;AACA;AAEA;;;AAA2B,KH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AAA,ClBV4B;EAAA;AAAT,CAAS,EkBUL,elBVJ,CAAA,EkBUsB,YlBVtB;;;;cmBNtB,aAAA,SAAsB,KAAA;;;;ApBMnC;AAyBY,coBpBC,eAAA,SAAwB,KAAA,CpBoBb;EAER,GAAA,EAAA,MAAA;EAeM,WAAA,CAAA,GAAU,EAAA,MAAA;;;coBzBnB,sBAAA,SAA+B,KAAA;EnBjBhC,aAAA,EAAA,MAAc;;;;;UoBLT,WAAA;;;;;ErBKL;EAyBA,GAAA,EAAA,MAAA;EAEI;EAeM,QAAA,EAAA,MAAU;;;;AC1ChC;;;;ACFA;AAeA;;;;ACfA;AACA;AAEA;AAA0C,iBkBmB1B,gBAAA,ClBnB0B,UAAA,CAAA,EAAA,MAAA,CAAA,EkBmBW,WlBnBX"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/pen/config.ts","../src/pen/compiler/types.ts","../src/pen/compiler/builders/file-tree.ts","../src/pen/compiler/builders/segment-tree.ts","../src/pen/compiler/builders/route-chain-map.ts","../src/pen/compiler/builders/component-id-map.ts","../src/pen/compiler/builders/serialized-routes.ts","../src/pen/compiler/errors.ts","../src/pen/router/RouterProvider.tsx","../src/pen/router/hooks/use-history.ts","../src/pen/router/hooks/use-navigate.ts","../src/pen/router/hooks/use-route-data.ts","../src/pen/router/hooks/use-router.ts","../src/pen/router/hooks/use-url.ts","../src/pen/runtime/App.tsx","../src/pen/runtime/ui/ErrorBoundary.tsx","../src/pen/runtime/ui/NotFoundBoundary.tsx","../src/pen/runtime/ui/ErrorScreen.tsx","../src/pen/runtime/ui/NotFoundScreen.tsx","../src/pen/runtime/FileRouter.tsx","../src/pen/runtime/errors.ts","../src/pen/utils/use-memory-monitor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAOY,iBAAA;EAAA;AAyBZ;AAEA;AAeA;;;;AC1CA;;;;ACFA;AAeA;;;;ACfA,CAAA;AACA;AAEA;;;AAA2B,KHwBf,SAAA,GAAY,OGxBG,CHwBK,i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AS,EkBUL,elBVJ,CAAA,EkBUsB,YlBVtB;;;;cmBNtB,aAAA,SAAsB,KAAA;;;;ApBMnC;AAyBY,coBpBC,eAAA,SAAwB,KAAA,CpBoBb;EAER,GAAA,EAAA,MAAA;EAeM,WAAA,CAAA,GAAU,EAAA,MAAA;;;coBzBnB,sBAAA,SAA+B,KAAA;EnBjBhC,aAAA,EAAA,MAAc;;;;;UoBLT,WAAA;;;;;ErBKL;EAyBA,GAAA,EAAA,MAAA;EAEI;EAeM,QAAA,EAAA,MAAU;;;;AC1ChC;;;;ACFA;AAeA;;;;ACfA;AACA;AAEA;AAA0C,iBkBmB1B,gBAAA,ClBnB0B,UAAA,CAAA,EAAA,MAAA,CAAA,EkBmBW,WlBnBX"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,r as c,s as l,t as u,u as d}from"./element-tree-DoH7UgRL.mjs";import{Component as f,createContext as p,useCallback as m,useContext as h,useEffect as g,useState as _}from"react";import{jsx as v,jsxs as y}from"react/jsx-runtime";import{Box as b,Text as x,useInput as S}from"ink";function C(e){return e.endsWith(`/`)?e:`${e}/`}function w(e,t,n){return{stack:[...e.stack.slice(0,e.position+1),{url:C(t),data:n}],position:e.position+1}}function T(e,t){let n=[...e.stack];return n[e.position]={url:C(t)},{...e,stack:n}}function E(e){return e.position>0?{...e,position:e.position-1}:e}function D(e){return e.position<e.stack.length-1?{...e,position:e.position+1}:e}const O=p(null);function k({initialUrl:e,children:t}){let n=C(e),[r,i]=_({stack:[{url:n}],position:0}),{url:a,data:o}=r.stack[r.position]??{url:n},s=m((e,t)=>{i(n=>w(n,e,t))},[]),c=m(e=>{i(t=>T(t,e))},[]),l=m(()=>{i(e=>E(e))},[]),u=m(()=>{i(e=>D(e))},[]);return v(O.Provider,{value:{url:a,data:o,history:r.stack.map(e=>e.url),position:r.position,push:s,replace:c,back:l,forward:u},children:t})}function A(){let e=h(O);if(!e)throw Error(`useRouter must be used within a RouterProvider`);return e}function j(){let{history:e}=A();return e}function M(){let{push:e,replace:t,back:n,forward:r}=A();return{push:e,replace:t,back:n,forward:r}}function N(){let{data:e}=A();return e}function P(){let{url:e}=A();return e}var F=class extends f{state;constructor(e){super(e),this.state={error:null},this.reset=this.reset.bind(this)}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(){}reset(){this.setState({error:null})}render(){if(this.state.error){let e=this.props.fallback;return v(e,{error:this.state.error,reset:this.reset})}return this.props.children}},I=class extends Error{url;constructor(e,t=`Not Found`){super(t),this.name=`NotFoundError`,this.url=e}},L=class extends Error{constructor(e){super(`Route ${e} has an empty chain. This indicates a bug in manifest generation - routes must have at least one segment.`),this.url=e,this.name=`EmptyChainError`}},R=class extends Error{constructor(e){super(`Component not found: ${e}. This indicates the component map is out of sync with the manifest. Try running 'pen build' again.`),this.componentPath=e,this.name=`ComponentNotFoundError`}},z=class extends f{state;constructor(e){super(e),this.state={url:null}}static getDerivedStateFromError(e){return e instanceof I?{url:e.url}:null}componentDidCatch(e){if(!(e instanceof I))throw e}componentDidUpdate(e){e.url!==this.props.url&&this.state.url&&this.setState({url:null})}render(){if(this.state.url){let e=this.props.fallback;return v(e,{url:this.state.url})}return this.props.children}};function B({fallback:e,children:t}){let{url:n}=A();return v(z,{fallback:e,url:n,children:t})}function V({error:e,reset:t}){let[n,r]=_(!1);return S(e=>{e===`r`&&t(),e===`s`&&r(e=>!e),e===`q`&&process.exit(1)}),y(b,{flexDirection:`column`,padding:2,borderStyle:`double`,borderColor:`red`,children:[v(b,{marginBottom:1,children:v(x,{bold:!0,color:`red`,children:`💥 Critical Application Error`})}),v(b,{marginBottom:1,children:v(x,{color:`red`,children:`The application encountered a fatal error and cannot continue.`})}),y(b,{flexDirection:`column`,padding:1,borderStyle:`round`,borderColor:`yellow`,marginBottom:1,children:[v(x,{bold:!0,color:`yellow`,children:`Error Details:`}),v(x,{children:e.message})]}),n&&e.stack&&y(b,{flexDirection:`column`,padding:1,borderStyle:`single`,borderColor:`gray`,marginBottom:1,children:[v(x,{bold:!0,dimColor:!0,children:`Stack Trace:`}),v(x,{dimColor:!0,children:e.stack})]}),y(b,{flexDirection:`column`,marginTop:1,children:[v(x,{bold:!0,children:`Options:`}),v(x,{dimColor:!0,children:` [r] Retry [s] Toggle Stack Trace [q] Quit`})]}),v(b,{marginTop:1,children:v(x,{dimColor:!0,children:`If this error persists, please report it.`})})]})}function H({url:e}){let t=A();return S(e=>{e===`b`&&t.back(),e===`q`&&process.exit(0)}),y(b,{flexDirection:`column`,padding:2,borderStyle:`round`,borderColor:`red`,children:[y(b,{flexDirection:`column`,marginBottom:1,children:[v(x,{bold:!0,color:`red`,children:`Route Not Found`}),v(x,{dimColor:!0,children:`The router couldn't match the requested URL.`})]}),v(b,{flexDirection:`column`,paddingLeft:1,marginBottom:1,children:y(x,{children:[`Requested:`,` `,v(x,{color:`yellow`,bold:!0,children:e})]})}),y(b,{flexDirection:`column`,padding:1,borderStyle:`single`,borderColor:`gray`,marginBottom:1,children:[v(x,{bold:!0,children:`Actions`}),v(x,{dimColor:!0,children:` [b] Go back`}),v(x,{dimColor:!0,children:` [q] Quit`})]}),v(x,{dimColor:!0,children:`Tip: Check the route segment name or add a screen.tsx for this path.`})]})}function U({routes:e}){let{url:t}=A(),n=e[t];if(!n)throw new I(t);return n}function W({initialUrl:e,routes:t}){return v(F,{fallback:V,children:v(k,{initialUrl:e,children:v(B,{fallback:H,children:v(U,{routes:t})})})})}function G(e=1e3){let[t,n]=_({heapUsed:0,heapTotal:0,rss:0,external:0});return g(()=>{let t=()=>{let e=process.memoryUsage();n({heapUsed:Math.round(e.heapUsed/1024/1024),heapTotal:Math.round(e.heapTotal/1024/1024),rss:Math.round(e.rss/1024/1024),external:Math.round(e.external/1024/1024)})};t();let r=setInterval(t,e);return()=>clearInterval(r)},[e]),t}export{W as App,R as ComponentNotFoundError,s as DirectoryNotFoundError,l as DuplicateScreenError,L as EmptyChainError,F as ErrorBoundary,V as ErrorScreen,U as FileRouter,t as FileRouterError,a as NotADirectoryError,B as NotFoundBoundary,I as NotFoundError,H as NotFoundScreen,d as RootIsFileError,O as RouterContext,k as RouterProvider,o as createComponentMap,u as createElementTrees,e as createFileTree,c as createRouteTable,i as createSegmentTree,n as defineConfig,r as loadConfig,j as useHistory,G as useMemoryMonitor,M as useNavigate,N as useRouteData,A as useRouter,P as useUrl};
1
+ import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,r as c,s as l,t as u,u as d}from"./serialized-routes-DFDKf4sB.mjs";import{Component as f,createContext as p,useCallback as m,useContext as h,useEffect as g,useState as _}from"react";import{jsx as v,jsxs as y}from"react/jsx-runtime";import{Box as b,Text as x,useInput as S}from"ink";function C(e){return e.endsWith(`/`)?e:`${e}/`}function w(e,t,n){return{stack:[...e.stack.slice(0,e.position+1),{url:C(t),data:n}],position:e.position+1}}function T(e,t){let n=[...e.stack];return n[e.position]={url:C(t)},{...e,stack:n}}function E(e){return e.position>0?{...e,position:e.position-1}:e}function D(e){return e.position<e.stack.length-1?{...e,position:e.position+1}:e}const O=p(null);function k({initialUrl:e,children:t}){let n=C(e),[r,i]=_({stack:[{url:n}],position:0}),{url:a,data:o}=r.stack[r.position]??{url:n},s=m((e,t)=>{i(n=>w(n,e,t))},[]),c=m(e=>{i(t=>T(t,e))},[]),l=m(()=>{i(e=>E(e))},[]),u=m(()=>{i(e=>D(e))},[]);return v(O.Provider,{value:{url:a,data:o,history:r.stack.map(e=>e.url),position:r.position,push:s,replace:c,back:l,forward:u},children:t})}function A(){let e=h(O);if(!e)throw Error(`useRouter must be used within a RouterProvider`);return e}function j(){let{history:e}=A();return e}function M(){let{push:e,replace:t,back:n,forward:r}=A();return{push:e,replace:t,back:n,forward:r}}function N(){let{data:e}=A();return e}function P(){let{url:e}=A();return e}var F=class extends f{state;constructor(e){super(e),this.state={error:null},this.reset=this.reset.bind(this)}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(){}reset(){this.setState({error:null})}render(){if(this.state.error){let e=this.props.fallback;return v(e,{error:this.state.error,reset:this.reset})}return this.props.children}},I=class extends Error{url;constructor(e,t=`Not Found`){super(t),this.name=`NotFoundError`,this.url=e}},L=class extends Error{constructor(e){super(`Route ${e} has an empty chain. This indicates a bug in manifest generation - routes must have at least one segment.`),this.url=e,this.name=`EmptyChainError`}},R=class extends Error{constructor(e){super(`Component not found: ${e}. This indicates the component map is out of sync with the manifest. Try running 'pen build' again.`),this.componentPath=e,this.name=`ComponentNotFoundError`}},z=class extends f{state;constructor(e){super(e),this.state={url:null}}static getDerivedStateFromError(e){return e instanceof I?{url:e.url}:null}componentDidCatch(e){if(!(e instanceof I))throw e}componentDidUpdate(e){e.url!==this.props.url&&this.state.url&&this.setState({url:null})}render(){if(this.state.url){let e=this.props.fallback;return v(e,{url:this.state.url})}return this.props.children}};function B({fallback:e,children:t}){let{url:n}=A();return v(z,{fallback:e,url:n,children:t})}function V({error:e,reset:t}){let[n,r]=_(!1);return S(e=>{e===`r`&&t(),e===`s`&&r(e=>!e),e===`q`&&process.exit(1)}),y(b,{flexDirection:`column`,padding:2,borderStyle:`double`,borderColor:`red`,children:[v(b,{marginBottom:1,children:v(x,{bold:!0,color:`red`,children:`💥 Critical Application Error`})}),v(b,{marginBottom:1,children:v(x,{color:`red`,children:`The application encountered a fatal error and cannot continue.`})}),y(b,{flexDirection:`column`,padding:1,borderStyle:`round`,borderColor:`yellow`,marginBottom:1,children:[v(x,{bold:!0,color:`yellow`,children:`Error Details:`}),v(x,{children:e.message})]}),n&&e.stack&&y(b,{flexDirection:`column`,padding:1,borderStyle:`single`,borderColor:`gray`,marginBottom:1,children:[v(x,{bold:!0,dimColor:!0,children:`Stack Trace:`}),v(x,{dimColor:!0,children:e.stack})]}),y(b,{flexDirection:`column`,marginTop:1,children:[v(x,{bold:!0,children:`Options:`}),v(x,{dimColor:!0,children:` [r] Retry [s] Toggle Stack Trace [q] Quit`})]}),v(b,{marginTop:1,children:v(x,{dimColor:!0,children:`If this error persists, please report it.`})})]})}function H({url:e}){let t=A();return S(e=>{e===`b`&&t.back(),e===`q`&&process.exit(0)}),y(b,{flexDirection:`column`,padding:2,borderStyle:`round`,borderColor:`red`,children:[y(b,{flexDirection:`column`,marginBottom:1,children:[v(x,{bold:!0,color:`red`,children:`Route Not Found`}),v(x,{dimColor:!0,children:`The router couldn't match the requested URL.`})]}),v(b,{flexDirection:`column`,paddingLeft:1,marginBottom:1,children:y(x,{children:[`Requested:`,` `,v(x,{color:`yellow`,bold:!0,children:e})]})}),y(b,{flexDirection:`column`,padding:1,borderStyle:`single`,borderColor:`gray`,marginBottom:1,children:[v(x,{bold:!0,children:`Actions`}),v(x,{dimColor:!0,children:` [b] Go back`}),v(x,{dimColor:!0,children:` [q] Quit`})]}),v(x,{dimColor:!0,children:`Tip: Check the route segment name or add a screen.tsx for this path.`})]})}function U({routes:e}){let{url:t}=A(),n=e[t];if(!n)throw new I(t);return n}function W({initialUrl:e,routes:t}){return v(F,{fallback:V,children:v(k,{initialUrl:e,children:v(B,{fallback:H,children:v(U,{routes:t})})})})}function G(e=1e3){let[t,n]=_({heapUsed:0,heapTotal:0,rss:0,external:0});return g(()=>{let t=()=>{let e=process.memoryUsage();n({heapUsed:Math.round(e.heapUsed/1024/1024),heapTotal:Math.round(e.heapTotal/1024/1024),rss:Math.round(e.rss/1024/1024),external:Math.round(e.external/1024/1024)})};t();let r=setInterval(t,e);return()=>clearInterval(r)},[e]),t}export{W as App,R as ComponentNotFoundError,s as DirectoryNotFoundError,l as DuplicateScreenError,L as EmptyChainError,F as ErrorBoundary,V as ErrorScreen,U as FileRouter,t as FileRouterError,a as NotADirectoryError,B as NotFoundBoundary,I as NotFoundError,H as NotFoundScreen,d as RootIsFileError,O as RouterContext,k as RouterProvider,o as createComponentIdMap,e as createFileTree,c as createRouteChainMap,i as createSegmentTree,u as createSerializedRoutes,n as defineConfig,r as loadConfig,j as useHistory,G as useMemoryMonitor,M as useNavigate,N as useRouteData,A as useRouter,P as useUrl};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["push","actions.push","replace","actions.replace","back","actions.back","forward","actions.forward"],"sources":["../src/pen/router/actions.ts","../src/pen/router/RouterProvider.tsx","../src/pen/router/hooks/use-router.ts","../src/pen/router/hooks/use-history.ts","../src/pen/router/hooks/use-navigate.ts","../src/pen/router/hooks/use-route-data.ts","../src/pen/router/hooks/use-url.ts","../src/pen/runtime/ui/ErrorBoundary.tsx","../src/pen/runtime/errors.ts","../src/pen/runtime/ui/NotFoundBoundary.tsx","../src/pen/runtime/ui/ErrorScreen.tsx","../src/pen/runtime/ui/NotFoundScreen.tsx","../src/pen/runtime/FileRouter.tsx","../src/pen/runtime/App.tsx","../src/pen/utils/use-memory-monitor.ts"],"sourcesContent":["import type { NavigationHistory } from './types'\r\n\r\n/**\r\n * Normalizes a URL to include a trailing slash.\r\n * Routes are keyed with trailing slashes in the manifest.\r\n */\r\nexport function normalizeUrl(url: string): string {\r\n return url.endsWith('/') ? url : `${url}/`\r\n}\r\n\r\nexport function push(prev: NavigationHistory, newUrl: string, newData?: unknown): NavigationHistory {\r\n return {\r\n stack: [...prev.stack.slice(0, prev.position + 1), { url: normalizeUrl(newUrl), data: newData }],\r\n position: prev.position + 1,\r\n }\r\n}\r\n\r\nexport function replace(prev: NavigationHistory, newUrl: string): NavigationHistory {\r\n const newStack = [...prev.stack]\r\n newStack[prev.position] = { url: normalizeUrl(newUrl) }\r\n return { ...prev, stack: newStack }\r\n}\r\n\r\nexport function back(prev: NavigationHistory): NavigationHistory {\r\n return prev.position > 0\r\n ? { ...prev, position: prev.position - 1 }\r\n : prev\r\n}\r\n\r\nexport function forward(prev: NavigationHistory): NavigationHistory {\r\n return prev.position < prev.stack.length - 1\r\n ? { ...prev, position: prev.position + 1 }\r\n : prev\r\n}\r\n","import { createContext, useState, useCallback, type PropsWithChildren } from 'react'\r\nimport * as actions from './actions'\r\nimport { normalizeUrl } from './actions'\r\nimport type { NavigationHistory } from './types'\r\n\r\nexport interface RouterContextValue {\r\n url: string\r\n data: unknown | undefined\r\n history: readonly string[] // Expose as readonly\r\n position: number // Expose current position\r\n push: (url: string, data?: unknown) => void\r\n replace: (url: string) => void\r\n back: () => void\r\n forward: () => void\r\n}\r\n\r\nexport interface RouterProviderProps extends PropsWithChildren {\r\n initialUrl: string\r\n}\r\n\r\n// Step 1: Define what data exists on the channel\r\nexport const RouterContext = createContext<RouterContextValue | null>(null)\r\n\r\n// Step 2: Broadcast the data\r\nexport function RouterProvider({ initialUrl, children }: RouterProviderProps) {\r\n const normalizedInitialUrl = normalizeUrl(initialUrl)\r\n const [history, setHistory] = useState<NavigationHistory>({\r\n stack: [{ url: normalizedInitialUrl }],\r\n position: 0,\r\n })\r\n\r\n // Grab the current url and data\r\n const { url, data } = history.stack[history.position] ?? { url: normalizedInitialUrl }\r\n\r\n // Push new URL and data to history\r\n const push = useCallback((newUrl: string, newData?: unknown) => {\r\n setHistory(prev => actions.push(prev, newUrl, newData))\r\n }, [])\r\n\r\n // Replace current URL without adding to history\r\n const replace = useCallback((newUrl: string) => {\r\n setHistory(prev => actions.replace(prev, newUrl))\r\n }, [])\r\n\r\n // Navigate backwards\r\n const back = useCallback(() => {\r\n setHistory(prev => actions.back(prev))\r\n }, [])\r\n\r\n // Navigate forwards\r\n const forward = useCallback(() => {\r\n setHistory(prev => actions.forward(prev))\r\n }, [])\r\n\r\n return (\r\n <RouterContext.Provider\r\n value={{\r\n url,\r\n data,\r\n history: history.stack.map(entry => entry.url),\r\n position: history.position,\r\n push,\r\n replace,\r\n back,\r\n forward,\r\n }}\r\n >\r\n {children}\r\n </RouterContext.Provider>\r\n )\r\n}\r\n","import { useContext } from 'react'\r\nimport { RouterContext } from '../RouterProvider'\r\n\r\n// Step 3: Tune into the channel and receive the broadcast\r\nexport function useRouter() {\r\n const context = useContext(RouterContext)\r\n if (!context)\r\n throw new Error('useRouter must be used within a RouterProvider')\r\n return context\r\n}\r\n","import { useRouter } from './use-router'\r\n\r\n/**\r\n * Get the navigation history (URLs only)\r\n *\r\n * @returns readonly array of visited URLs\r\n *\r\n * @example\r\n * ```tsx\r\n * const history = useHistory()\r\n * return (\r\n * <Box>\r\n * <Text>Visited pages:</Text>\r\n * {history.map((url, i) => (\r\n * <Text key={i}>{url}</Text>\r\n * ))}\r\n * </Box>\r\n * )\r\n * ```\r\n */\r\nexport function useHistory(): readonly string[] {\r\n const { history } = useRouter()\r\n return history\r\n}\r\n","import { useRouter } from './use-router'\r\n\r\n/**\r\n * Get navigation functions without url/data\r\n */\r\nexport function useNavigate() {\r\n const { push, replace, back, forward } = useRouter()\r\n return { push, replace, back, forward }\r\n}\r\n","import { useRouter } from './use-router'\r\n\r\n/**\r\n * Access route data passed via router.push()\r\n *\r\n * @example\r\n * ```tsx\r\n * const user = useRouteData<User>()\r\n * if (!user) return <Text>No user</Text>\r\n * return <Text>{user.name}</Text>\r\n * ```\r\n */\r\nexport function useRouteData<T = unknown>() {\r\n const { data } = useRouter()\r\n return data as T | undefined\r\n}\r\n","import { useRouter } from './use-router'\r\n\r\n/**\r\n * Get the current URL\r\n */\r\nexport function useUrl(): string {\r\n const { url } = useRouter()\r\n return url\r\n}\r\n","import { Component, type ComponentType, type PropsWithChildren } from 'react'\r\n\r\n/** Props passed to error.tsx components */\r\nexport interface ErrorComponentProps {\r\n error: Error\r\n reset: () => void\r\n}\r\n\r\ninterface ErrorBoundaryProps extends PropsWithChildren {\r\n fallback: ComponentType<ErrorComponentProps>\r\n}\r\n\r\ninterface ErrorBoundaryState {\r\n error: Error | null\r\n}\r\n\r\n/**\r\n * React Error Boundary that catches errors in child components.\r\n * Renders the provided ErrorComponent when an error occurs.\r\n *\r\n * Catches:\r\n * - Errors during rendering\r\n * - Errors in lifecycle methods\r\n * - Errors in constructors\r\n *\r\n * Does NOT catch:\r\n * - Event handlers (use try-catch)\r\n * - Async code (use try-catch)\r\n * - Errors in the error boundary itself\r\n */\r\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\r\n state: ErrorBoundaryState\r\n\r\n constructor(props: ErrorBoundaryProps) {\r\n super(props)\r\n this.state = { error: null }\r\n this.reset = this.reset.bind(this) // Bind all methods that will be passed as callbacks\r\n }\r\n\r\n /** Called when a child component throws during render. */\r\n static getDerivedStateFromError(error: Error): ErrorBoundaryState {\r\n return { error }\r\n }\r\n\r\n /** Called after error is caught. */\r\n componentDidCatch() {\r\n // Error is passed to error.tsx component via props\r\n }\r\n\r\n /** Resets error state and attempts to re-render children. */\r\n reset() {\r\n this.setState({ error: null })\r\n }\r\n\r\n render() {\r\n if (this.state.error) {\r\n const ErrorComponent = this.props.fallback\r\n return <ErrorComponent error={this.state.error} reset={this.reset} />\r\n }\r\n return this.props.children\r\n }\r\n}\r\n","/** Special error thrown to trigger not-found.tsx. */\r\nexport class NotFoundError extends Error {\r\n public readonly url: string\r\n\r\n constructor(url: string, message: string = 'Not Found') {\r\n super(message)\r\n this.name = 'NotFoundError'\r\n this.url = url\r\n }\r\n}\r\n\r\n/** Error thrown when a route has an empty chain. */\r\nexport class EmptyChainError extends Error {\r\n constructor(public url: string) {\r\n super(\r\n `Route ${url} has an empty chain. ` +\r\n 'This indicates a bug in manifest generation - ' +\r\n 'routes must have at least one segment.',\r\n )\r\n this.name = 'EmptyChainError'\r\n }\r\n}\r\n\r\n/** Error thrown when a component is missing from the component map. */\r\nexport class ComponentNotFoundError extends Error {\r\n constructor(public componentPath: string) {\r\n super(\r\n `Component not found: ${componentPath}. ` +\r\n 'This indicates the component map is out of sync with the manifest. ' +\r\n 'Try running \\'pen build\\' again.',\r\n )\r\n this.name = 'ComponentNotFoundError'\r\n }\r\n}\r\n","import { Component, type ComponentType, type PropsWithChildren } from 'react'\r\nimport { useRouter } from '@/pen/router'\r\nimport { NotFoundError } from '../errors'\r\n\r\n/** Props passed to not-found.tsx components */\r\nexport interface NotFoundComponentProps {\r\n url: string\r\n}\r\n\r\ninterface NotFoundErrorBoundaryProps extends PropsWithChildren {\r\n fallback: ComponentType<NotFoundComponentProps>\r\n url: string\r\n}\r\n\r\ninterface NotFoundBoundaryState {\r\n url: string | null\r\n}\r\n\r\n/**\r\n * Catches NotFoundError thrown by notFound() function.\r\n * Renders fallback component when caught.\r\n *\r\n * Does NOT catch:\r\n * - Non-NotFoundError errors (they bubble)\r\n */\r\nclass NotFoundErrorBoundary extends Component<NotFoundErrorBoundaryProps, NotFoundBoundaryState> {\r\n state: NotFoundBoundaryState\r\n\r\n constructor(props: NotFoundErrorBoundaryProps) {\r\n super(props)\r\n this.state = { url: null }\r\n }\r\n\r\n /** Called when a child component throws during render. */\r\n static getDerivedStateFromError(error: Error) {\r\n // Only catch NotFoundError, other errors bubble\r\n return error instanceof NotFoundError ? { url: error.url } : null\r\n }\r\n\r\n /** Called after error is caught. */\r\n componentDidCatch(error: Error) {\r\n if (!(error instanceof NotFoundError)) // Only handle NotFoundError\r\n throw error // Re-throw other errors\r\n }\r\n\r\n /** Called after updates. Clears the not-found state when the URL prop changes. */\r\n componentDidUpdate(prevProps: NotFoundErrorBoundaryProps) {\r\n if (prevProps.url !== this.props.url && this.state.url) // URL changed → clear not-found state\r\n this.setState({ url: null })\r\n }\r\n\r\n render() {\r\n if (this.state.url) {\r\n const NotFoundComponent = this.props.fallback\r\n return <NotFoundComponent url={this.state.url} />\r\n }\r\n return this.props.children\r\n }\r\n}\r\n\r\nexport interface NotFoundBoundaryProps extends PropsWithChildren {\r\n fallback: ComponentType<NotFoundComponentProps>\r\n}\r\n\r\n/**\r\n * Router-aware wrapper for NotFoundErrorBoundary.\r\n * Injects the current URL so the boundary can reset on navigation.\r\n */\r\nexport function NotFoundBoundary({ fallback, children }: NotFoundBoundaryProps) {\r\n const { url } = useRouter()\r\n return (\r\n <NotFoundErrorBoundary fallback={fallback} url={url}>\r\n {children}\r\n </NotFoundErrorBoundary>\r\n )\r\n}\r\n","// src/core/router/components/GlobalErrorFallback.tsx\r\nimport { Box, Text, useInput } from 'ink'\r\nimport { useState } from 'react'\r\nimport { type ErrorComponentProps } from './ErrorBoundary'\r\n\r\n/** Global error fallback that always wraps the app. */\r\nexport function ErrorScreen({ error, reset }: ErrorComponentProps) {\r\n const [showStack, setShowStack] = useState(false)\r\n\r\n useInput((input) => {\r\n if (input === 'r') reset()\r\n if (input === 's') setShowStack(prev => !prev)\r\n if (input === 'q') process.exit(1)\r\n })\r\n\r\n return (\r\n <Box\r\n flexDirection=\"column\"\r\n padding={2}\r\n borderStyle=\"double\"\r\n borderColor=\"red\"\r\n >\r\n <Box marginBottom={1}>\r\n <Text bold color=\"red\">💥 Critical Application Error</Text>\r\n </Box>\r\n\r\n <Box marginBottom={1}>\r\n <Text color=\"red\">The application encountered a fatal error and cannot continue.</Text>\r\n </Box>\r\n\r\n <Box\r\n flexDirection=\"column\"\r\n padding={1}\r\n borderStyle=\"round\"\r\n borderColor=\"yellow\"\r\n marginBottom={1}\r\n >\r\n <Text bold color=\"yellow\">Error Details:</Text>\r\n <Text>{error.message}</Text>\r\n </Box>\r\n\r\n {showStack && error.stack && (\r\n <Box\r\n flexDirection=\"column\"\r\n padding={1}\r\n borderStyle=\"single\"\r\n borderColor=\"gray\"\r\n marginBottom={1}\r\n >\r\n <Text bold dimColor>Stack Trace:</Text>\r\n <Text dimColor>{error.stack}</Text>\r\n </Box>\r\n )}\r\n\r\n <Box flexDirection=\"column\" marginTop={1}>\r\n <Text bold>Options:</Text>\r\n <Text dimColor> [r] Retry [s] Toggle Stack Trace [q] Quit</Text>\r\n </Box>\r\n\r\n <Box marginTop={1}>\r\n <Text dimColor>\r\n If this error persists, please report it.\r\n </Text>\r\n </Box>\r\n </Box>\r\n )\r\n}\r\n","import { Box, Text, useInput } from 'ink'\r\nimport { useRouter } from '@/pen/router'\r\nimport { type NotFoundComponentProps } from './NotFoundBoundary'\r\n\r\n/**\r\n * Not found error screen displayed when a route is not found.\r\n * Shows the URL that was attempted.\r\n */\r\nexport function NotFoundScreen({ url }: NotFoundComponentProps) {\r\n const router = useRouter()\r\n\r\n useInput((input) => {\r\n if (input === 'b') router.back()\r\n if (input === 'q') process.exit(0)\r\n })\r\n\r\n return (\r\n <Box flexDirection=\"column\" padding={2} borderStyle=\"round\" borderColor=\"red\">\r\n <Box flexDirection=\"column\" marginBottom={1}>\r\n <Text bold color=\"red\">Route Not Found</Text>\r\n <Text dimColor>{'The router couldn\\'t match the requested URL.'}</Text>\r\n </Box>\r\n\r\n <Box flexDirection=\"column\" paddingLeft={1} marginBottom={1}>\r\n <Text>\r\n Requested:{' '}\r\n <Text color=\"yellow\" bold>\r\n {url}\r\n </Text>\r\n </Text>\r\n </Box>\r\n\r\n <Box\r\n flexDirection=\"column\"\r\n padding={1}\r\n borderStyle=\"single\"\r\n borderColor=\"gray\"\r\n marginBottom={1}\r\n >\r\n <Text bold>Actions</Text>\r\n <Text dimColor> [b] Go back</Text>\r\n <Text dimColor> [q] Quit</Text>\r\n </Box>\r\n\r\n <Text dimColor>\r\n Tip: Check the route segment name or add a screen.tsx for this path.\r\n </Text>\r\n </Box>\r\n )\r\n}\r\n","import { useRouter } from '@/pen/router'\r\nimport { NotFoundError } from './errors'\r\n\r\nimport type { ReactElement } from 'react'\r\nimport type { CompiledRoutes } from '../compiler/types'\r\n\r\n/**\r\n * Props for the FileRouter component.\r\n */\r\nexport interface FileRouterProps {\r\n routes: CompiledRoutes\r\n}\r\n\r\n/**\r\n * Router component that renders compiled route elements.\r\n * Simply looks up the current URL in the compiled routes map.\r\n */\r\nexport function FileRouter({ routes }: FileRouterProps): ReactElement {\r\n const { url } = useRouter()\r\n const element = routes[url]\r\n\r\n if (!element) throw new NotFoundError(url)\r\n return element\r\n}\r\n","import { RouterProvider } from '@/pen/router'\r\nimport { ErrorBoundary } from './ui/ErrorBoundary'\r\nimport { NotFoundBoundary } from './ui/NotFoundBoundary'\r\nimport { ErrorScreen } from './ui/ErrorScreen'\r\nimport { NotFoundScreen } from './ui/NotFoundScreen'\r\nimport { FileRouter } from './FileRouter'\r\nimport type { CompiledRoutes } from '../compiler/types'\r\n\r\nexport interface AppProps {\r\n initialUrl: string\r\n routes: CompiledRoutes\r\n}\r\n\r\n/**\r\n * Root application component.\r\n * Routes are compiled at build time via codegen - no runtime composition needed!\r\n */\r\nexport function App({ initialUrl, routes }: AppProps) {\r\n return (\r\n <ErrorBoundary fallback={ErrorScreen}>\r\n <RouterProvider initialUrl={initialUrl}>\r\n <NotFoundBoundary fallback={NotFoundScreen}>\r\n <FileRouter routes={routes} />\r\n </NotFoundBoundary>\r\n </RouterProvider>\r\n </ErrorBoundary>\r\n )\r\n}\r\n","import { useEffect, useState } from 'react'\r\n\r\nexport interface MemoryUsage {\r\n /** Heap memory currently used (in MB) */\r\n heapUsed: number\r\n /** Total heap memory allocated (in MB) */\r\n heapTotal: number\r\n /** Resident Set Size - total memory allocated for the process (in MB) */\r\n rss: number\r\n /** Memory used by C++ objects bound to JavaScript (in MB) */\r\n external: number\r\n}\r\n\r\n/**\r\n * Hook to monitor Node.js memory usage in real-time\r\n *\r\n * @param intervalMs - Polling interval in milliseconds (default: 1000ms)\r\n * @returns Current memory usage statistics in megabytes\r\n *\r\n * @example\r\n * ```tsx\r\n * function MemoryDisplay() {\r\n * const { heapUsed, heapTotal, rss } = useMemoryMonitor()\r\n * return <Text>RAM: {heapUsed}/{heapTotal} MB (RSS: {rss} MB)</Text>\r\n * }\r\n * ```\r\n */\r\nexport function useMemoryMonitor(intervalMs = 1000): MemoryUsage {\r\n const [memory, setMemory] = useState<MemoryUsage>({\r\n heapUsed: 0,\r\n heapTotal: 0,\r\n rss: 0,\r\n external: 0,\r\n })\r\n\r\n useEffect(() => {\r\n const updateMemory = () => {\r\n const usage = process.memoryUsage()\r\n setMemory({\r\n heapUsed: Math.round(usage.heapUsed / 1024 / 1024),\r\n heapTotal: Math.round(usage.heapTotal / 1024 / 1024),\r\n rss: Math.round(usage.rss / 1024 / 1024),\r\n external: Math.round(usage.external / 1024 / 1024),\r\n })\r\n }\r\n\r\n // Get initial reading immediately\r\n updateMemory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GAAc,CAEd,IAAM,EAAW,YAAY,EAAc,EAAW,CAEtD,UAAa,cAAc,EAAS,EACnC,CAAC,EAAW,CAAC,CAET"}
1
+ {"version":3,"file":"index.mjs","names":["push","actions.push","replace","actions.replace","back","actions.back","forward","actions.forward"],"sources":["../src/pen/router/actions.ts","../src/pen/router/RouterProvider.tsx","../src/pen/router/hooks/use-router.ts","../src/pen/router/hooks/use-history.ts","../src/pen/router/hooks/use-navigate.ts","../src/pen/router/hooks/use-route-data.ts","../src/pen/router/hooks/use-url.ts","../src/pen/runtime/ui/ErrorBoundary.tsx","../src/pen/runtime/errors.ts","../src/pen/runtime/ui/NotFoundBoundary.tsx","../src/pen/runtime/ui/ErrorScreen.tsx","../src/pen/runtime/ui/NotFoundScreen.tsx","../src/pen/runtime/FileRouter.tsx","../src/pen/runtime/App.tsx","../src/pen/utils/use-memory-monitor.ts"],"sourcesContent":["import type { NavigationHistory } from './types'\r\n\r\n/**\r\n * Normalizes a URL to include a trailing slash.\r\n * Routes are keyed with trailing slashes in the manifest.\r\n */\r\nexport function normalizeUrl(url: string): string {\r\n return url.endsWith('/') ? url : `${url}/`\r\n}\r\n\r\nexport function push(prev: NavigationHistory, newUrl: string, newData?: unknown): NavigationHistory {\r\n return {\r\n stack: [...prev.stack.slice(0, prev.position + 1), { url: normalizeUrl(newUrl), data: newData }],\r\n position: prev.position + 1,\r\n }\r\n}\r\n\r\nexport function replace(prev: NavigationHistory, newUrl: string): NavigationHistory {\r\n const newStack = [...prev.stack]\r\n newStack[prev.position] = { url: normalizeUrl(newUrl) }\r\n return { ...prev, stack: newStack }\r\n}\r\n\r\nexport function back(prev: NavigationHistory): NavigationHistory {\r\n return prev.position > 0\r\n ? { ...prev, position: prev.position - 1 }\r\n : prev\r\n}\r\n\r\nexport function forward(prev: NavigationHistory): NavigationHistory {\r\n return prev.position < prev.stack.length - 1\r\n ? { ...prev, position: prev.position + 1 }\r\n : prev\r\n}\r\n","import { createContext, useState, useCallback, type PropsWithChildren } from 'react'\r\nimport * as actions from './actions'\r\nimport { normalizeUrl } from './actions'\r\nimport type { NavigationHistory } from './types'\r\n\r\nexport interface RouterContextValue {\r\n url: string\r\n data: unknown | undefined\r\n history: readonly string[] // Expose as readonly\r\n position: number // Expose current position\r\n push: (url: string, data?: unknown) => void\r\n replace: (url: string) => void\r\n back: () => void\r\n forward: () => void\r\n}\r\n\r\nexport interface RouterProviderProps extends PropsWithChildren {\r\n initialUrl: string\r\n}\r\n\r\n// Step 1: Define what data exists on the channel\r\nexport const RouterContext = createContext<RouterContextValue | null>(null)\r\n\r\n// Step 2: Broadcast the data\r\nexport function RouterProvider({ initialUrl, children }: RouterProviderProps) {\r\n const normalizedInitialUrl = normalizeUrl(initialUrl)\r\n const [history, setHistory] = useState<NavigationHistory>({\r\n stack: [{ url: normalizedInitialUrl }],\r\n position: 0,\r\n })\r\n\r\n // Grab the current url and data\r\n const { url, data } = history.stack[history.position] ?? { url: normalizedInitialUrl }\r\n\r\n // Push new URL and data to history\r\n const push = useCallback((newUrl: string, newData?: unknown) => {\r\n setHistory(prev => actions.push(prev, newUrl, newData))\r\n }, [])\r\n\r\n // Replace current URL without adding to history\r\n const replace = useCallback((newUrl: string) => {\r\n setHistory(prev => actions.replace(prev, newUrl))\r\n }, [])\r\n\r\n // Navigate backwards\r\n const back = useCallback(() => {\r\n setHistory(prev => actions.back(prev))\r\n }, [])\r\n\r\n // Navigate forwards\r\n const forward = useCallback(() => {\r\n setHistory(prev => actions.forward(prev))\r\n }, [])\r\n\r\n return (\r\n <RouterContext.Provider\r\n value={{\r\n url,\r\n data,\r\n history: history.stack.map(entry => entry.url),\r\n position: history.position,\r\n push,\r\n replace,\r\n back,\r\n forward,\r\n }}\r\n >\r\n {children}\r\n </RouterContext.Provider>\r\n )\r\n}\r\n","import { useContext } from 'react'\r\nimport { RouterContext } from '../RouterProvider'\r\n\r\n// Step 3: Tune into the channel and receive the broadcast\r\nexport function useRouter() {\r\n const context = useContext(RouterContext)\r\n if (!context)\r\n throw new Error('useRouter must be used within a RouterProvider')\r\n return context\r\n}\r\n","import { useRouter } from './use-router'\r\n\r\n/**\r\n * Get the navigation history (URLs only)\r\n *\r\n * @returns readonly array of visited URLs\r\n *\r\n * @example\r\n * ```tsx\r\n * const history = useHistory()\r\n * return (\r\n * <Box>\r\n * <Text>Visited pages:</Text>\r\n * {history.map((url, i) => (\r\n * <Text key={i}>{url}</Text>\r\n * ))}\r\n * </Box>\r\n * )\r\n * ```\r\n */\r\nexport function useHistory(): readonly string[] {\r\n const { history } = useRouter()\r\n return history\r\n}\r\n","import { useRouter } from './use-router'\r\n\r\n/**\r\n * Get navigation functions without url/data\r\n */\r\nexport function useNavigate() {\r\n const { push, replace, back, forward } = useRouter()\r\n return { push, replace, back, forward }\r\n}\r\n","import { useRouter } from './use-router'\r\n\r\n/**\r\n * Access route data passed via router.push()\r\n *\r\n * @example\r\n * ```tsx\r\n * const user = useRouteData<User>()\r\n * if (!user) return <Text>No user</Text>\r\n * return <Text>{user.name}</Text>\r\n * ```\r\n */\r\nexport function useRouteData<T = unknown>() {\r\n const { data } = useRouter()\r\n return data as T | undefined\r\n}\r\n","import { useRouter } from './use-router'\r\n\r\n/**\r\n * Get the current URL\r\n */\r\nexport function useUrl(): string {\r\n const { url } = useRouter()\r\n return url\r\n}\r\n","import { Component, type ComponentType, type PropsWithChildren } from 'react'\r\n\r\n/** Props passed to error.tsx components */\r\nexport interface ErrorComponentProps {\r\n error: Error\r\n reset: () => void\r\n}\r\n\r\ninterface ErrorBoundaryProps extends PropsWithChildren {\r\n fallback: ComponentType<ErrorComponentProps>\r\n}\r\n\r\ninterface ErrorBoundaryState {\r\n error: Error | null\r\n}\r\n\r\n/**\r\n * React Error Boundary that catches errors in child components.\r\n * Renders the provided ErrorComponent when an error occurs.\r\n *\r\n * Catches:\r\n * - Errors during rendering\r\n * - Errors in lifecycle methods\r\n * - Errors in constructors\r\n *\r\n * Does NOT catch:\r\n * - Event handlers (use try-catch)\r\n * - Async code (use try-catch)\r\n * - Errors in the error boundary itself\r\n */\r\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\r\n state: ErrorBoundaryState\r\n\r\n constructor(props: ErrorBoundaryProps) {\r\n super(props)\r\n this.state = { error: null }\r\n this.reset = this.reset.bind(this) // Bind all methods that will be passed as callbacks\r\n }\r\n\r\n /** Called when a child component throws during render. */\r\n static getDerivedStateFromError(error: Error): ErrorBoundaryState {\r\n return { error }\r\n }\r\n\r\n /** Called after error is caught. */\r\n componentDidCatch() {\r\n // Error is passed to error.tsx component via props\r\n }\r\n\r\n /** Resets error state and attempts to re-render children. */\r\n reset() {\r\n this.setState({ error: null })\r\n }\r\n\r\n render() {\r\n if (this.state.error) {\r\n const ErrorComponent = this.props.fallback\r\n return <ErrorComponent error={this.state.error} reset={this.reset} />\r\n }\r\n return this.props.children\r\n }\r\n}\r\n","/** Special error thrown to trigger not-found.tsx. */\r\nexport class NotFoundError extends Error {\r\n public readonly url: string\r\n\r\n constructor(url: string, message: string = 'Not Found') {\r\n super(message)\r\n this.name = 'NotFoundError'\r\n this.url = url\r\n }\r\n}\r\n\r\n/** Error thrown when a route has an empty chain. */\r\nexport class EmptyChainError extends Error {\r\n constructor(public url: string) {\r\n super(\r\n `Route ${url} has an empty chain. ` +\r\n 'This indicates a bug in manifest generation - ' +\r\n 'routes must have at least one segment.',\r\n )\r\n this.name = 'EmptyChainError'\r\n }\r\n}\r\n\r\n/** Error thrown when a component is missing from the component map. */\r\nexport class ComponentNotFoundError extends Error {\r\n constructor(public componentPath: string) {\r\n super(\r\n `Component not found: ${componentPath}. ` +\r\n 'This indicates the component map is out of sync with the manifest. ' +\r\n 'Try running \\'pen build\\' again.',\r\n )\r\n this.name = 'ComponentNotFoundError'\r\n }\r\n}\r\n","import { Component, type ComponentType, type PropsWithChildren } from 'react'\r\nimport { useRouter } from '@/pen/router'\r\nimport { NotFoundError } from '../errors'\r\n\r\n/** Props passed to not-found.tsx components */\r\nexport interface NotFoundComponentProps {\r\n url: string\r\n}\r\n\r\ninterface NotFoundErrorBoundaryProps extends PropsWithChildren {\r\n fallback: ComponentType<NotFoundComponentProps>\r\n url: string\r\n}\r\n\r\ninterface NotFoundBoundaryState {\r\n url: string | null\r\n}\r\n\r\n/**\r\n * Catches NotFoundError thrown by notFound() function.\r\n * Renders fallback component when caught.\r\n *\r\n * Does NOT catch:\r\n * - Non-NotFoundError errors (they bubble)\r\n */\r\nclass NotFoundErrorBoundary extends Component<NotFoundErrorBoundaryProps, NotFoundBoundaryState> {\r\n state: NotFoundBoundaryState\r\n\r\n constructor(props: NotFoundErrorBoundaryProps) {\r\n super(props)\r\n this.state = { url: null }\r\n }\r\n\r\n /** Called when a child component throws during render. */\r\n static getDerivedStateFromError(error: Error) {\r\n // Only catch NotFoundError, other errors bubble\r\n return error instanceof NotFoundError ? { url: error.url } : null\r\n }\r\n\r\n /** Called after error is caught. */\r\n componentDidCatch(error: Error) {\r\n if (!(error instanceof NotFoundError)) // Only handle NotFoundError\r\n throw error // Re-throw other errors\r\n }\r\n\r\n /** Called after updates. Clears the not-found state when the URL prop changes. */\r\n componentDidUpdate(prevProps: NotFoundErrorBoundaryProps) {\r\n if (prevProps.url !== this.props.url && this.state.url) // URL changed → clear not-found state\r\n this.setState({ url: null })\r\n }\r\n\r\n render() {\r\n if (this.state.url) {\r\n const NotFoundComponent = this.props.fallback\r\n return <NotFoundComponent url={this.state.url} />\r\n }\r\n return this.props.children\r\n }\r\n}\r\n\r\nexport interface NotFoundBoundaryProps extends PropsWithChildren {\r\n fallback: ComponentType<NotFoundComponentProps>\r\n}\r\n\r\n/**\r\n * Router-aware wrapper for NotFoundErrorBoundary.\r\n * Injects the current URL so the boundary can reset on navigation.\r\n */\r\nexport function NotFoundBoundary({ fallback, children }: NotFoundBoundaryProps) {\r\n const { url } = useRouter()\r\n return (\r\n <NotFoundErrorBoundary fallback={fallback} url={url}>\r\n {children}\r\n </NotFoundErrorBoundary>\r\n )\r\n}\r\n","// src/core/router/components/GlobalErrorFallback.tsx\r\nimport { Box, Text, useInput } from 'ink'\r\nimport { useState } from 'react'\r\nimport { type ErrorComponentProps } from './ErrorBoundary'\r\n\r\n/** Global error fallback that always wraps the app. */\r\nexport function ErrorScreen({ error, reset }: ErrorComponentProps) {\r\n const [showStack, setShowStack] = useState(false)\r\n\r\n useInput((input) => {\r\n if (input === 'r') reset()\r\n if (input === 's') setShowStack(prev => !prev)\r\n if (input === 'q') process.exit(1)\r\n })\r\n\r\n return (\r\n <Box\r\n flexDirection=\"column\"\r\n padding={2}\r\n borderStyle=\"double\"\r\n borderColor=\"red\"\r\n >\r\n <Box marginBottom={1}>\r\n <Text bold color=\"red\">💥 Critical Application Error</Text>\r\n </Box>\r\n\r\n <Box marginBottom={1}>\r\n <Text color=\"red\">The application encountered a fatal error and cannot continue.</Text>\r\n </Box>\r\n\r\n <Box\r\n flexDirection=\"column\"\r\n padding={1}\r\n borderStyle=\"round\"\r\n borderColor=\"yellow\"\r\n marginBottom={1}\r\n >\r\n <Text bold color=\"yellow\">Error Details:</Text>\r\n <Text>{error.message}</Text>\r\n </Box>\r\n\r\n {showStack && error.stack && (\r\n <Box\r\n flexDirection=\"column\"\r\n padding={1}\r\n borderStyle=\"single\"\r\n borderColor=\"gray\"\r\n marginBottom={1}\r\n >\r\n <Text bold dimColor>Stack Trace:</Text>\r\n <Text dimColor>{error.stack}</Text>\r\n </Box>\r\n )}\r\n\r\n <Box flexDirection=\"column\" marginTop={1}>\r\n <Text bold>Options:</Text>\r\n <Text dimColor> [r] Retry [s] Toggle Stack Trace [q] Quit</Text>\r\n </Box>\r\n\r\n <Box marginTop={1}>\r\n <Text dimColor>\r\n If this error persists, please report it.\r\n </Text>\r\n </Box>\r\n </Box>\r\n )\r\n}\r\n","import { Box, Text, useInput } from 'ink'\r\nimport { useRouter } from '@/pen/router'\r\nimport { type NotFoundComponentProps } from './NotFoundBoundary'\r\n\r\n/**\r\n * Not found error screen displayed when a route is not found.\r\n * Shows the URL that was attempted.\r\n */\r\nexport function NotFoundScreen({ url }: NotFoundComponentProps) {\r\n const router = useRouter()\r\n\r\n useInput((input) => {\r\n if (input === 'b') router.back()\r\n if (input === 'q') process.exit(0)\r\n })\r\n\r\n return (\r\n <Box flexDirection=\"column\" padding={2} borderStyle=\"round\" borderColor=\"red\">\r\n <Box flexDirection=\"column\" marginBottom={1}>\r\n <Text bold color=\"red\">Route Not Found</Text>\r\n <Text dimColor>{'The router couldn\\'t match the requested URL.'}</Text>\r\n </Box>\r\n\r\n <Box flexDirection=\"column\" paddingLeft={1} marginBottom={1}>\r\n <Text>\r\n Requested:{' '}\r\n <Text color=\"yellow\" bold>\r\n {url}\r\n </Text>\r\n </Text>\r\n </Box>\r\n\r\n <Box\r\n flexDirection=\"column\"\r\n padding={1}\r\n borderStyle=\"single\"\r\n borderColor=\"gray\"\r\n marginBottom={1}\r\n >\r\n <Text bold>Actions</Text>\r\n <Text dimColor> [b] Go back</Text>\r\n <Text dimColor> [q] Quit</Text>\r\n </Box>\r\n\r\n <Text dimColor>\r\n Tip: Check the route segment name or add a screen.tsx for this path.\r\n </Text>\r\n </Box>\r\n )\r\n}\r\n","import { useRouter } from '@/pen/router'\r\nimport { NotFoundError } from './errors'\r\n\r\nimport type { ReactElement } from 'react'\r\nimport type { CompiledRoutes } from '../compiler/types'\r\n\r\n/**\r\n * Props for the FileRouter component.\r\n */\r\nexport interface FileRouterProps {\r\n routes: CompiledRoutes\r\n}\r\n\r\n/**\r\n * Router component that renders compiled route elements.\r\n * Simply looks up the current URL in the compiled routes map.\r\n */\r\nexport function FileRouter({ routes }: FileRouterProps): ReactElement {\r\n const { url } = useRouter()\r\n const element = routes[url]\r\n\r\n if (!element) throw new NotFoundError(url)\r\n return element\r\n}\r\n","import { RouterProvider } from '@/pen/router'\r\nimport { ErrorBoundary } from './ui/ErrorBoundary'\r\nimport { NotFoundBoundary } from './ui/NotFoundBoundary'\r\nimport { ErrorScreen } from './ui/ErrorScreen'\r\nimport { NotFoundScreen } from './ui/NotFoundScreen'\r\nimport { FileRouter } from './FileRouter'\r\nimport type { CompiledRoutes } from '../compiler/types'\r\n\r\nexport interface AppProps {\r\n initialUrl: string\r\n routes: CompiledRoutes\r\n}\r\n\r\n/**\r\n * Root application component.\r\n * Routes are compiled at build time via codegen - no runtime composition needed!\r\n */\r\nexport function App({ initialUrl, routes }: AppProps) {\r\n return (\r\n <ErrorBoundary fallback={ErrorScreen}>\r\n <RouterProvider initialUrl={initialUrl}>\r\n <NotFoundBoundary fallback={NotFoundScreen}>\r\n <FileRouter routes={routes} />\r\n </NotFoundBoundary>\r\n </RouterProvider>\r\n </ErrorBoundary>\r\n )\r\n}\r\n","import { useEffect, useState } from 'react'\r\n\r\nexport interface MemoryUsage {\r\n /** Heap memory currently used (in MB) */\r\n heapUsed: number\r\n /** Total heap memory allocated (in MB) */\r\n heapTotal: number\r\n /** Resident Set Size - total memory allocated for the process (in MB) */\r\n rss: number\r\n /** Memory used by C++ objects bound to JavaScript (in MB) */\r\n external: number\r\n}\r\n\r\n/**\r\n * Hook to monitor Node.js memory usage in real-time\r\n *\r\n * @param intervalMs - Polling interval in milliseconds (default: 1000ms)\r\n * @returns Current memory usage statistics in megabytes\r\n *\r\n * @example\r\n * ```tsx\r\n * function MemoryDisplay() {\r\n * const { heapUsed, heapTotal, rss } = useMemoryMonitor()\r\n * return <Text>RAM: {heapUsed}/{heapTotal} MB (RSS: {rss} MB)</Text>\r\n * }\r\n * ```\r\n */\r\nexport function useMemoryMonitor(intervalMs = 1000): MemoryUsage {\r\n const [memory, setMemory] = useState<MemoryUsage>({\r\n heapUsed: 0,\r\n heapTotal: 0,\r\n rss: 0,\r\n external: 0,\r\n })\r\n\r\n useEffect(() => {\r\n const updateMemory = () => {\r\n const usage = process.memoryUsage()\r\n setMemory({\r\n heapUsed: Math.round(usage.heapUsed / 1024 / 1024),\r\n heapTotal: Math.round(usage.heapTotal / 1024 / 1024),\r\n rss: Math.round(usage.rss / 1024 / 1024),\r\n external: Math.round(usage.external / 1024 / 1024),\r\n })\r\n }\r\n\r\n // Get initial reading immediately\r\n updateMemory()\r\n\r\n const interval = setInterval(updateMemory, intervalMs)\r\n\r\n return () => clearInterval(interval)\r\n }, [intervalMs])\r\n\r\n return memory\r\n}\r\n"],"mappings":"oVAMA,SAAgB,EAAa,EAAqB,CAChD,OAAO,EAAI,SAAS,IAAI,CAAG,EAAM,GAAG,EAAI,GAG1C,SAAgB,EAAK,EAAyB,EAAgB,EAAsC,CAClG,MAAO,CACL,MAAO,CAAC,GAAG,EAAK,MAAM,MAAM,EAAG,EAAK,SAAW,EAAE,CAAE,CAAE,IAAK,EAAa,EAAO,CAAE,KAAM,EAAS,CAAC,CAChG,SAAU,EAAK,SAAW,EAC3B,CAGH,SAAgB,EAAQ,EAAyB,EAAmC,CAClF,IAAM,EAAW,CAAC,GAAG,EAAK,MAAM,CAEhC,MADA,GAAS,EAAK,UAAY,CAAE,IAAK,EAAa,EAAO,CAAE,CAChD,CAAE,GAAG,EAAM,MAAO,EAAU,CAGrC,SAAgB,EAAK,EAA4C,CAC/D,OAAO,EAAK,SAAW,EACnB,CAAE,GAAG,EAAM,SAAU,EAAK,SAAW,EAAG,CACxC,EAGN,SAAgB,EAAQ,EAA4C,CAClE,OAAO,EAAK,SAAW,EAAK,MAAM,OAAS,EACvC,CAAE,GAAG,EAAM,SAAU,EAAK,SAAW,EAAG,CACxC,ECXN,MAAa,EAAgB,EAAyC,KAAK,CAG3E,SAAgB,EAAe,CAAE,aAAY,YAAiC,CAC5E,IAAM,EAAuB,EAAa,EAAW,CAC/C,CAAC,EAAS,GAAc,EAA4B,CACxD,MAAO,CAAC,CAAE,IAAK,EAAsB,CAAC,CACtC,SAAU,EACX,CAAC,CAGI,CAAE,MAAK,QAAS,EAAQ,MAAM,EAAQ,WAAa,CAAE,IAAK,EAAsB,CAGhFA,EAAO,GAAa,EAAgB,IAAsB,CAC9D,EAAW,GAAQC,EAAa,EAAM,EAAQ,EAAQ,CAAC,EACtD,E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C,SAAU,KAAK,MAAM,EAAM,SAAW,KAAO,KAAK,CACnD,CAAC,EAIJ,GAAc,CAEd,IAAM,EAAW,YAAY,EAAc,EAAW,CAEtD,UAAa,cAAc,EAAS,EACnC,CAAC,EAAW,CAAC,CAET"}
@@ -3,4 +3,4 @@ import{join as e,parse as t,posix as n,relative as r,resolve as i}from"path";imp
3
3
 
4
4
  Each URL can only have one screen file.
5
5
  Move one screen to a different directory or rename the route segment.`),this.url=e,this.files=t,this.name=`DuplicateScreenError`}};function v(e){let t=i(e);y(t);let n={name:`app`,relPath:`/app`,absPath:t,children:[]};return d(n,{attach:(e,t)=>t.children.push(e),expand:e=>e.children?o(e.absPath,{withFileTypes:!0}).filter(e=>e.isFile()||e.isDirectory()).map(t=>b(t,e)).sort((e,t)=>e.name.localeCompare(t.name)):[]}),n}function y(e){let t=s(e,{throwIfNoEntry:!1});if(!t)throw new m(e);if(!t.isDirectory())throw new h(e)}function b(t,r){let i=n.join(r.relPath,t.name),a=e(r.absPath,t.name);return t.isDirectory()?{name:t.name,relPath:i,absPath:a,children:[]}:{name:t.name,relPath:i,absPath:a}}const x=[`layout`,`screen`,`error`,`not-found`];function S(e){let t=C(e);return w(t),t}function C(e){if(e.children===void 0)throw new g(e.absPath);let t={segment:``,url:`/`,type:`page`,roles:{},children:[],file:e};return d(t,{attach:(e,t)=>t.children.push(e),expand:e=>(e.file.children??[]).filter(e=>e.children&&!e.name.startsWith(`_`)).map(t=>T(t,e)).sort((e,t)=>e.segment.localeCompare(t.segment))}),t}function w(e){let t={};d(e,{expand:e=>e.children??[],visit:e=>{E(e),D(e,t)}})}function T(e,t){let r=e.name.startsWith(`(`)&&e.name.endsWith(`)`);return{segment:e.name,url:r?t.url:`${n.join(t.url,e.name)}/`,type:r?`group`:`page`,roles:{},parent:t,children:[],file:e}}function E(e){for(let n of e.file.children??[]){let{name:r,ext:i}=t(n.name);i===`.tsx`&&x.includes(r)&&(e.roles[r]=n.absPath)}}function D(e,t){if(!e.roles.screen)return;let n=t[e.url];if(n)throw new _(e.url,[n,e.file.absPath]);t[e.url]=e.file.absPath}function O(n){let r=t(n);return e(r.dir,r.name)}function k(e,t){let n={},r=`${t}/generated`;return d(e,{expand:e=>e.children??[],visit:e=>{if(!e.roles.screen)return;let t=e.url;n[t]={url:t,chain:A(e,r)}}}),n}function A(e,t){let n=[];return f(e,{parent:e=>e.parent,visit:i=>{let a={},o=Object.entries(i.roles);for(let[n,s]of o)(n!==`screen`||i===e)&&(a[n]=`${r(t,O(s)).replace(/\\/g,`/`)}.js`);n.push(a)}}),n}function j(e){let t=new Set;for(let n of Object.values(e))for(let e of n.chain)for(let n of x)e[n]&&t.add(e[n]);let n=Array.from(t).sort(),r={};for(let e=0;e<n.length;e++)r[n[e]]=e;return r}function M(e,t){let n={};for(let[r,i]of Object.entries(e))n[r]=N(i,t);return n}function N(e,t){let n=Object.keys(t),r=t[e.chain[0].screen],i=JSON.stringify(n[r]),a={component:`Component${r}`,props:{key:i}};for(let r of e.chain){if(r[`not-found`]){let e=t[r[`not-found`]];a={component:`NotFoundBoundary`,props:{key:JSON.stringify(n[e]),fallback:`Component${e}`},children:a}}if(r.error){let e=t[r.error];a={component:`ErrorBoundary`,props:{key:JSON.stringify(n[e]),fallback:`Component${e}`},children:a}}if(r.layout){let e=t[r.layout],i=JSON.stringify(n[e]);a={component:`Component${e}`,props:{key:i},children:a}}}return a}export{v as a,p as c,c as d,u as f,S as i,h as l,j as n,m as o,k as r,_ as s,M as t,g as u};
6
- //# sourceMappingURL=element-tree-DoH7UgRL.mjs.map
6
+ //# sourceMappingURL=serialized-routes-DFDKf4sB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialized-routes-DFDKf4sB.mjs","names":[],"sources":["../src/pen/config.ts","../src/lib/tree.ts","../src/pen/compiler/errors.ts","../src/pen/compiler/builders/file-tree.ts","../src/pen/compiler/builders/segment-tree.ts","../src/lib/path-utils.ts","../src/pen/compiler/builders/route-chain-map.ts","../src/pen/compiler/builders/component-id-map.ts","../src/pen/compiler/builders/serialized-routes.ts"],"sourcesContent":["import { resolve } from 'path'\r\nimport { pathToFileURL } from 'url'\r\n\r\n/**\r\n * Resolved configuration with all fields guaranteed to be present.\r\n * This is what loadConfig() returns after merging user config with defaults.\r\n */\r\nexport type ResolvedPenConfig = {\r\n /**\r\n * Directory containing your app routes.\r\n * @default './src/app'\r\n */\r\n appDir: string\r\n\r\n /**\r\n * Output directory for generated files and build artifacts.\r\n * @default './.pen'\r\n */\r\n outDir: string\r\n\r\n /**\r\n * Emit metadata files (manifest, components, element-tree) to aid debugging and tooling.\r\n * These files provide introspection into your app's structure.\r\n * @default true\r\n */\r\n emitMetadata: boolean\r\n}\r\n\r\n/**\r\n * User-facing configuration (what users write in pen.config.ts).\r\n * All fields are optional and will be merged with defaults.\r\n */\r\nexport type PenConfig = Partial<ResolvedPenConfig>\r\n\r\nexport function defineConfig(config: PenConfig): PenConfig {\r\n return config\r\n}\r\n\r\nconst defaultConfig: ResolvedPenConfig = {\r\n appDir: './src/app',\r\n outDir: './.pen',\r\n emitMetadata: false,\r\n}\r\n\r\n/**\r\n * Loads pen.config.ts from the current directory.\r\n * Falls back to defaults if config file doesn't exist.\r\n * Returns a fully resolved config with all fields guaranteed to be present.\r\n */\r\nexport async function loadConfig(): Promise<ResolvedPenConfig> {\r\n try {\r\n const configPath = resolve(process.cwd(), 'pen.config.ts')\r\n const configUrl = pathToFileURL(configPath).href\r\n\r\n const module = await import(configUrl) as { default?: PenConfig }\r\n const userConfig = module.default || {}\r\n\r\n // Merge with defaults\r\n return { ...defaultConfig, ...userConfig }\r\n }\r\n catch {\r\n // Config file doesn't exist or failed to load - use defaults\r\n return defaultConfig\r\n }\r\n}\r\n","/** Callbacks for tree traversal. */\r\nexport type TraverseCallbacks<TNode> = {\r\n /** Called when visiting each node (pre-order) */\r\n visit?: (node: TNode) => void\r\n /** Returns children for a node (or creates them) */\r\n expand?: (node: TNode) => TNode[]\r\n /** Attaches a child to its parent */\r\n attach?: (child: TNode, parent: TNode) => void\r\n}\r\n\r\n/**\r\n * Depth-first tree traversal with pluggable callbacks.\r\n *\r\n * @template TNode - The type of tree nodes\r\n * @param root - The root node to start traversal from\r\n * @param callbacks - Callbacks for visit, expand, and attach operations\r\n *\r\n * @example\r\n * // Visit existing tree\r\n * traverse(tree, {\r\n * visit: (node) => console.log(node.name),\r\n * expand: (node) => node.children ?? []\r\n * })\r\n *\r\n * @example\r\n * // Build new tree\r\n * traverse(root, {\r\n * expand: (node) => createChildren(node),\r\n * attach: (child, parent) => parent.children.push(child)\r\n * })\r\n */\r\nexport function traverse<TNode>(root: TNode, callbacks: TraverseCallbacks<TNode>) {\r\n const { visit, expand, attach } = callbacks\r\n const stack = [root]\r\n\r\n while (stack.length) {\r\n const node = stack.pop()!\r\n visit?.(node)\r\n\r\n // Process children in reverse so\r\n // they're popped in correct order\r\n const children = expand?.(node) ?? []\r\n\r\n for (let i = children.length-1; i >= 0; i--) {\r\n const child = children[i]!\r\n attach?.(child, node)\r\n stack.push(child)\r\n }\r\n }\r\n}\r\n\r\n/** Callbacks for ancestor traversal. */\r\nexport type AncestorCallbacks<TNode> = {\r\n /** Called when visiting each ancestor node (from leaf to root) */\r\n visit: (node: TNode) => void\r\n /** Returns the parent node for a given node */\r\n parent: (node: TNode) => TNode | undefined\r\n}\r\n\r\n/**\r\n * Traverses the ancestor chain of a given node from leaf to root.\r\n *\r\n * @template TNode - The type of tree nodes\r\n * @param node - The node to start the ancestor traversal from\r\n * @param callbacks - Callbacks for visit and parent operations\r\n *\r\n * @example\r\n * // Visit ancestors in a tree structure\r\n * ancestors(node, {\r\n * visit: (node) => console.log(`Visiting: ${node.name}`),\r\n * parent: (node) => node.parent // Return the parent of the node\r\n * })\r\n *\r\n * @example\r\n * // Collect all ancestors' roles in a tree structure\r\n * const roles = []\r\n * ancestors(node, {\r\n * visit: (node) => roles.push(node.role),\r\n * parent: (node) => node.parent\r\n * })\r\n * console.log(roles) // Logs all ancestor roles from leaf to root\r\n */\r\nexport function ancestors<TNode>(node: TNode, callbacks: AncestorCallbacks<TNode>) {\r\n const { visit, parent } = callbacks\r\n let currentNode: TNode | undefined = node\r\n\r\n while (currentNode) {\r\n visit(currentNode)\r\n currentNode = parent(currentNode)\r\n }\r\n}\r\n","/**\r\n * Base error for all route-builder build errors\r\n */\r\nexport class FileRouterError extends Error {\r\n constructor(message: string) {\r\n super(message)\r\n this.name = 'FileRouterError'\r\n }\r\n}\r\n\r\n// ============================================================================\r\n// File Tree Errors\r\n// ============================================================================\r\n\r\nexport class DirectoryNotFoundError extends FileRouterError {\r\n constructor(public path: string) {\r\n super(`Directory not found: \"${path}\"`)\r\n this.name = 'DirectoryNotFoundError'\r\n }\r\n}\r\n\r\nexport class NotADirectoryError extends FileRouterError {\r\n constructor(public path: string) {\r\n super(`Path is not a directory: \"${path}\"`)\r\n this.name = 'NotADirectoryError'\r\n }\r\n}\r\n\r\n// ============================================================================\r\n// Route Tree Errors\r\n// ============================================================================\r\n\r\nexport class RootIsFileError extends FileRouterError {\r\n constructor(public path: string) {\r\n super(\r\n `Root path is a file, not a directory: \"${path}\"\\n\\n` +\r\n 'The app directory must be a directory, not a file.',\r\n )\r\n this.name = 'RootIsFileError'\r\n }\r\n}\r\n\r\nexport class DuplicateScreenError extends FileRouterError {\r\n constructor(\r\n public url: string,\r\n public files: string[],\r\n ) {\r\n super(\r\n `Conflicting screen routes found at \"${url}\":\\n` +\r\n files.map(f => ` - ${f}`).join('\\n') + '\\n\\n' +\r\n 'Each URL can only have one screen file.\\n' +\r\n 'Move one screen to a different directory or rename the route segment.',\r\n )\r\n this.name = 'DuplicateScreenError'\r\n }\r\n}\r\n","import { readdirSync, statSync, type Dirent } from 'fs'\r\nimport { resolve, join, posix } from 'path'\r\nimport { traverse } from '@/lib/tree'\r\nimport { DirectoryNotFoundError, NotADirectoryError } from '../errors'\r\n\r\nexport type FileNode = {\r\n name: string // dirent name\r\n relPath: string\r\n absPath: string\r\n children?: FileNode[] // present only for directories\r\n}\r\n\r\n/**\r\n * Builds a file tree from a directory path.\r\n *\r\n * @param appPath - Path to the app directory\r\n * @returns File tree structure\r\n * @throws {DirectoryNotFoundError} If the directory doesn't exist\r\n * @throws {NotADirectoryError} If the path is not a directory\r\n */\r\nexport function createFileTree(appPath: string): FileNode {\r\n const absPath = resolve(appPath)\r\n validateDirectory(absPath)\r\n\r\n // Root node\r\n const name = 'app'\r\n const relPath = '/app'\r\n const root: FileNode = { name, relPath, absPath, children: [] }\r\n\r\n traverse(root, {\r\n attach: (child, parent) => parent.children!.push(child),\r\n expand: (file) => {\r\n if (!file.children) return []\r\n\r\n return readdirSync(file.absPath, { withFileTypes: true })\r\n .filter(d => d.isFile() || d.isDirectory())\r\n .map(d => createFileNode(d, file))\r\n .sort((a, b) => a.name.localeCompare(b.name))\r\n },\r\n })\r\n return root\r\n}\r\n\r\n/** Validates that the path exists and is a directory. */\r\nfunction validateDirectory(path: string) {\r\n const stat = statSync(path, { throwIfNoEntry: false })\r\n if (!stat) throw new DirectoryNotFoundError(path)\r\n if (!stat.isDirectory()) throw new NotADirectoryError(path)\r\n}\r\n\r\nfunction createFileNode(dirent: Dirent, parent: FileNode) {\r\n const relPath = posix.join(parent.relPath, dirent.name)\r\n const absPath = join(parent.absPath, dirent.name)\r\n\r\n return dirent.isDirectory()\r\n ? { name: dirent.name, relPath, absPath, children: [] }\r\n : { name: dirent.name, relPath, absPath }\r\n}\r\n","import type { FileNode } from './file-tree'\r\nimport { parse, posix } from 'path'\r\nimport { traverse } from '@/lib/tree'\r\nimport { RootIsFileError, DuplicateScreenError } from '../errors'\r\n\r\nexport const SEGMENT_ROLES = ['layout', 'screen', 'error', 'not-found'] as const\r\nexport type SegmentRole = typeof SEGMENT_ROLES[number]\r\n\r\nexport type SegmentRoles = Partial<Record<SegmentRole, string>>\r\nexport type SegmentNode = {\r\n segment: string\r\n url: `${string}/`\r\n type: 'page' | 'group'\r\n roles: SegmentRoles\r\n parent?: SegmentNode\r\n children?: SegmentNode[]\r\n file: FileNode\r\n}\r\n\r\n/**\r\n * Creates a segment tree from a file system tree.\r\n *\r\n * @param fileTree - File system tree\r\n * @returns Segment tree with assigned roles and validated structure\r\n * @throws {RootIsFileError} If the root is a file instead of a directory\r\n * @throws {DuplicateScreenError} If multiple screens map to the same URL\r\n */\r\nexport function createSegmentTree(fileTree: FileNode): SegmentNode {\r\n const tree = buildSegmentTree(fileTree) // Builds segment tree structure from file tree\r\n bindSegmentTree(tree) // Binds roles to segments and validates tree structure\r\n return tree\r\n}\r\n\r\nfunction buildSegmentTree(fileTree: FileNode) {\r\n if (fileTree.children === undefined)\r\n throw new RootIsFileError(fileTree.absPath)\r\n\r\n const root: SegmentNode = {\r\n segment: '',\r\n url: '/',\r\n type: 'page',\r\n roles: {},\r\n children: [],\r\n file: fileTree,\r\n }\r\n\r\n traverse(root, {\r\n attach: (child, parent) => parent.children!.push(child),\r\n expand: segment =>\r\n (segment.file.children ?? [])\r\n .filter(file => file.children && !file.name.startsWith('_'))\r\n .map(file => createSegmentNode(file, segment))\r\n .sort((a, b) => a.segment.localeCompare(b.segment)),\r\n })\r\n return root\r\n}\r\n\r\nfunction bindSegmentTree(segmentTree: SegmentNode) {\r\n const screens: Record<SegmentNode['url'], string> = {}\r\n\r\n traverse(segmentTree, {\r\n expand: segment => segment.children ?? [],\r\n visit: segment => {\r\n assignRoles(segment)\r\n validateScreenUniqueness(segment, screens)\r\n },\r\n })\r\n}\r\n\r\nfunction createSegmentNode(file: FileNode, parent: SegmentNode) {\r\n const isGroup = file.name.startsWith('(') && file.name.endsWith(')')\r\n const segmentNode: SegmentNode = {\r\n segment: file.name,\r\n url: isGroup ? parent.url : `${posix.join(parent.url, file.name)}/`,\r\n type: isGroup ? 'group' : 'page',\r\n roles: {},\r\n parent,\r\n children: [],\r\n file,\r\n }\r\n return segmentNode\r\n}\r\n\r\nfunction assignRoles(segment: SegmentNode) {\r\n for (const child of segment.file.children ?? []) {\r\n const { name, ext } = parse(child.name)\r\n if (ext === '.tsx' && SEGMENT_ROLES.includes(name as SegmentRole))\r\n segment.roles[name as SegmentRole] = child.absPath\r\n }\r\n}\r\n\r\nfunction validateScreenUniqueness(segment: SegmentNode, screens: Record<SegmentNode['url'], string>) {\r\n if (!segment.roles.screen) return\r\n\r\n const existing = screens[segment.url]\r\n if (existing)\r\n throw new DuplicateScreenError(segment.url, [existing, segment.file.absPath])\r\n screens[segment.url] = segment.file.absPath\r\n}\r\n","import { parse, join } from 'path'\r\n\r\nexport function removeExtension(filePath: string) {\r\n const parsed = parse(filePath)\r\n return join(parsed.dir, parsed.name) // Use posix for forward slashes\r\n}\r\n","import type { SegmentNode, SegmentRoles } from './segment-tree'\r\nimport { ancestors, traverse } from '@/lib/tree'\r\nimport { relative } from 'path'\r\nimport { removeExtension } from '@/lib/path-utils'\r\n\r\nexport type RouteChainMap = Record<string, Route>\r\nexport type Route = {\r\n url: string\r\n chain: SegmentRoles[]\r\n}\r\n\r\n/**\r\n * Builds a route manifest from a segment tree.\r\n *\r\n * Flattens the tree into a dictionary mapping URLs to route metadata.\r\n * Only includes routes that have screens.\r\n * Paths are stored as relative import paths from the generated directory.\r\n *\r\n * @param segmentTree - Segment tree with parent pointers\r\n * @param outDir - Output directory (to calculate relative import paths)\r\n * @returns Flat manifest ready for runtime composition\r\n */\r\nexport function createRouteChainMap(segmentTree: SegmentNode, outDir: string): RouteChainMap {\r\n const routes: RouteChainMap = {}\r\n const genDir = `${outDir}/generated`\r\n\r\n traverse(segmentTree, {\r\n expand: parentSegment => parentSegment.children ?? [],\r\n visit: segment => {\r\n if (!segment.roles.screen) return\r\n const url = segment.url\r\n const chain = createSegmentChain(segment, genDir)\r\n routes[url] = { url, chain }\r\n },\r\n })\r\n return routes\r\n}\r\n\r\n/** Builds ancestor chain from leaf → root order. */\r\nfunction createSegmentChain(segment: SegmentNode, genDir: string) {\r\n const chain: SegmentRoles[] = []\r\n\r\n ancestors(segment, {\r\n parent: ancestorSegment => ancestorSegment.parent,\r\n visit: ancestorSegment => {\r\n const roles: SegmentRoles = {}\r\n const entries = Object.entries(ancestorSegment.roles) as [keyof SegmentRoles, string][]\r\n\r\n for (const [name, path] of entries) {\r\n if (name !== 'screen' || ancestorSegment === segment) { // Skip ancestor screens\r\n const importPath = removeExtension(path) // Remove extension\r\n const relPath = relative(genDir, importPath).replace(/\\\\/g, '/') // Convert to relative path\r\n roles[name] = `${relPath}.js` // Add .js for ES modules\r\n }\r\n }\r\n chain.push(roles)\r\n },\r\n })\r\n return chain\r\n}\r\n","import type { RouteChainMap } from './route-chain-map'\r\nimport { SEGMENT_ROLES } from './segment-tree'\r\n\r\n/** Map from import path to component index (keys are in sorted order) */\r\nexport type ComponentIdMap = Record<string, number>\r\n\r\n/**\r\n * Builds a mapping of import paths to component IDs from the manifest.\r\n * Collects all unique import paths and assigns them indices.\r\n * Keys are stored in sorted order for deterministic output.\r\n */\r\nexport function createComponentIdMap(routes: RouteChainMap): ComponentIdMap {\r\n const importPaths = new Set<string>()\r\n\r\n // Collect all unique import paths from manifest\r\n for (const route of Object.values(routes)) {\r\n for (const segment of route.chain) {\r\n for (const role of SEGMENT_ROLES)\r\n if (segment[role]) importPaths.add(segment[role])\r\n }\r\n }\r\n\r\n // Sort for deterministic output\r\n const imports = Array.from(importPaths).sort()\r\n const mapping: ComponentIdMap = {}\r\n for (let i = 0; i < imports.length; i++)\r\n mapping[imports[i]!] = i\r\n\r\n return mapping\r\n}\r\n","import type { Route, RouteChainMap } from './route-chain-map'\r\nimport type { ComponentIdMap } from './component-id-map'\r\n\r\nexport interface SerializedTree {\r\n component: string\r\n props: Record<string, unknown>\r\n children?: SerializedTree\r\n}\r\n\r\nexport type SerializedRouteTreeMap = Record<string, SerializedTree>\r\n\r\n/**\r\n * Creates element trees for all routeChain in the manifest.\r\n * Each tree represents the nested React component structure for a route.\r\n */\r\nexport function createSerializedRoutes(routeChain: RouteChainMap, componentIdMap: ComponentIdMap): SerializedRouteTreeMap {\r\n const serializedRoutes: SerializedRouteTreeMap = {}\r\n for (const [url, route] of Object.entries(routeChain))\r\n serializedRoutes[url] = createSerializedTree(route, componentIdMap)\r\n return serializedRoutes\r\n}\r\n\r\n/**\r\n * Builds a structured serialized element tree representing nested React components.\r\n *\r\n * This function creates a structured data tree that will be serialized into\r\n * createElement calls for the generated routeChain.ts file.\r\n */\r\nfunction createSerializedTree(route: Route, mapping: ComponentIdMap): SerializedTree {\r\n const imports = Object.keys(mapping)\r\n\r\n // Start with the screen from the first segment\r\n const screenSegment = route.chain[0]!\r\n const screenPath = screenSegment['screen']!\r\n const screenIndex = mapping[screenPath]!\r\n const screenKey = JSON.stringify(imports[screenIndex]!)\r\n\r\n let tree: SerializedTree = {\r\n component: `Component${screenIndex}`,\r\n props: { key: screenKey },\r\n }\r\n\r\n // Process segments from leaf → root (same order as runtime composition)\r\n for (const segment of route.chain) {\r\n // Not-found boundary\r\n if (segment['not-found']) {\r\n const path = segment['not-found']\r\n const index = mapping[path]!\r\n const key = JSON.stringify(imports[index]!)\r\n const fallback = `Component${index}`\r\n tree = {\r\n component: 'NotFoundBoundary',\r\n props: { key, fallback },\r\n children: tree,\r\n }\r\n }\r\n // Error boundary\r\n if (segment['error']) {\r\n const path = segment['error']\r\n const index = mapping[path]!\r\n const key = JSON.stringify(imports[index]!)\r\n const fallback = `Component${index}`\r\n tree = {\r\n component: 'ErrorBoundary',\r\n props: { key, fallback },\r\n children: tree,\r\n }\r\n }\r\n // Layout\r\n if (segment['layout']) {\r\n const path = segment['layout']\r\n const index = mapping[path]!\r\n const key = JSON.stringify(imports[index]!)\r\n tree = {\r\n component: `Component${index}`,\r\n props: { key },\r\n children: tree,\r\n }\r\n }\r\n }\r\n return tree\r\n}\r\n"],"mappings":"gKAkCA,SAAgB,EAAa,EAA8B,CACzD,OAAO,EAGT,MAAM,EAAmC,CACvC,OAAQ,YACR,OAAQ,SACR,aAAc,GACf,CAOD,eAAsB,GAAyC,CAC7D,GAAI,CAKF,IAAM,GADS,MAAM,OAFH,EAD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AO,ECbT,SAAgB,EAAuB,EAA2B,EAAwD,CACxH,IAAM,EAA2C,EAAE,CACnD,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAW,CACnD,EAAiB,GAAO,EAAqB,EAAO,EAAe,CACrE,OAAO,EAST,SAAS,EAAqB,EAAc,EAAyC,CACnF,IAAM,EAAU,OAAO,KAAK,EAAQ,CAK9B,EAAc,EAFE,EAAM,MAAM,GACD,QAE3B,EAAY,KAAK,UAAU,EAAQ,GAAc,CAEnD,EAAuB,CACzB,UAAW,YAAY,IACvB,MAAO,CAAE,IAAK,EAAW,CAC1B,CAGD,IAAK,IAAM,KAAW,EAAM,MAAO,CAEjC,GAAI,EAAQ,aAAc,CAExB,IAAM,EAAQ,EADD,EAAQ,cAIrB,EAAO,CACL,UAAW,mBACX,MAAO,CAAE,IAJC,KAAK,UAAU,EAAQ,GAAQ,CAI3B,SAHC,YAAY,IAGH,CACxB,SAAU,EACX,CAGH,GAAI,EAAQ,MAAU,CAEpB,IAAM,EAAQ,EADD,EAAQ,OAIrB,EAAO,CACL,UAAW,gBACX,MAAO,CAAE,IAJC,KAAK,UAAU,EAAQ,GAAQ,CAI3B,SAHC,YAAY,IAGH,CACxB,SAAU,EACX,CAGH,GAAI,EAAQ,OAAW,CAErB,IAAM,EAAQ,EADD,EAAQ,QAEf,EAAM,KAAK,UAAU,EAAQ,GAAQ,CAC3C,EAAO,CACL,UAAW,YAAY,IACvB,MAAO,CAAE,MAAK,CACd,SAAU,EACX,EAGL,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idlesummer/pen",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "File-based routing for React Ink apps (experimental)",
5
5
  "keywords": [
6
6
  "cli",
@@ -35,7 +35,7 @@
35
35
  "examples/*"
36
36
  ],
37
37
  "scripts": {
38
- "build": "tsc --noEmit && tsdown",
38
+ "build": "tsc && tsdown",
39
39
  "lint": "eslint",
40
40
  "prepare": "npm run build",
41
41
  "test": "vitest",
@@ -1 +0,0 @@
1
- {"version":3,"file":"element-tree-DoH7UgRL.mjs","names":[],"sources":["../src/pen/config.ts","../src/lib/tree.ts","../src/pen/compiler/errors.ts","../src/pen/compiler/builders/file-tree.ts","../src/pen/compiler/builders/segment-tree.ts","../src/lib/path-utils.ts","../src/pen/compiler/builders/route-manifest.ts","../src/pen/compiler/builders/component-map.ts","../src/pen/compiler/builders/element-tree.ts"],"sourcesContent":["import { resolve } from 'path'\r\nimport { pathToFileURL } from 'url'\r\n\r\n/**\r\n * Resolved configuration with all fields guaranteed to be present.\r\n * This is what loadConfig() returns after merging user config with defaults.\r\n */\r\nexport type ResolvedPenConfig = {\r\n /**\r\n * Directory containing your app routes.\r\n * @default './src/app'\r\n */\r\n appDir: string\r\n\r\n /**\r\n * Output directory for generated files and build artifacts.\r\n * @default './.pen'\r\n */\r\n outDir: string\r\n\r\n /**\r\n * Emit metadata files (manifest, components, element-tree) to aid debugging and tooling.\r\n * These files provide introspection into your app's structure.\r\n * @default true\r\n */\r\n emitMetadata: boolean\r\n}\r\n\r\n/**\r\n * User-facing configuration (what users write in pen.config.ts).\r\n * All fields are optional and will be merged with defaults.\r\n */\r\nexport type PenConfig = Partial<ResolvedPenConfig>\r\n\r\nexport function defineConfig(config: PenConfig): PenConfig {\r\n return config\r\n}\r\n\r\nconst defaultConfig: ResolvedPenConfig = {\r\n appDir: './src/app',\r\n outDir: './.pen',\r\n emitMetadata: false,\r\n}\r\n\r\n/**\r\n * Loads pen.config.ts from the current directory.\r\n * Falls back to defaults if config file doesn't exist.\r\n * Returns a fully resolved config with all fields guaranteed to be present.\r\n */\r\nexport async function loadConfig(): Promise<ResolvedPenConfig> {\r\n try {\r\n const configPath = resolve(process.cwd(), 'pen.config.ts')\r\n const configUrl = pathToFileURL(configPath).href\r\n\r\n const module = await import(configUrl) as { default?: PenConfig }\r\n const userConfig = module.default || {}\r\n\r\n // Merge with defaults\r\n return { ...defaultConfig, ...userConfig }\r\n }\r\n catch {\r\n // Config file doesn't exist or failed to load - use defaults\r\n return defaultConfig\r\n }\r\n}\r\n","/** Callbacks for tree traversal. */\r\nexport type TraverseCallbacks<TNode> = {\r\n /** Called when visiting each node (pre-order) */\r\n visit?: (node: TNode) => void\r\n /** Returns children for a node (or creates them) */\r\n expand?: (node: TNode) => TNode[]\r\n /** Attaches a child to its parent */\r\n attach?: (child: TNode, parent: TNode) => void\r\n}\r\n\r\n/**\r\n * Depth-first tree traversal with pluggable callbacks.\r\n *\r\n * @template TNode - The type of tree nodes\r\n * @param root - The root node to start traversal from\r\n * @param callbacks - Callbacks for visit, expand, and attach operations\r\n *\r\n * @example\r\n * // Visit existing tree\r\n * traverse(tree, {\r\n * visit: (node) => console.log(node.name),\r\n * expand: (node) => node.children ?? []\r\n * })\r\n *\r\n * @example\r\n * // Build new tree\r\n * traverse(root, {\r\n * expand: (node) => createChildren(node),\r\n * attach: (child, parent) => parent.children.push(child)\r\n * })\r\n */\r\nexport function traverse<TNode>(root: TNode, callbacks: TraverseCallbacks<TNode>) {\r\n const { visit, expand, attach } = callbacks\r\n const stack = [root]\r\n\r\n while (stack.length) {\r\n const node = stack.pop()!\r\n visit?.(node)\r\n\r\n // Process children in reverse so\r\n // they're popped in correct order\r\n const children = expand?.(node) ?? []\r\n\r\n for (let i = children.length-1; i >= 0; i--) {\r\n const child = children[i]!\r\n attach?.(child, node)\r\n stack.push(child)\r\n }\r\n }\r\n}\r\n\r\n/** Callbacks for ancestor traversal. */\r\nexport type AncestorCallbacks<TNode> = {\r\n /** Called when visiting each ancestor node (from leaf to root) */\r\n visit: (node: TNode) => void\r\n /** Returns the parent node for a given node */\r\n parent: (node: TNode) => TNode | undefined\r\n}\r\n\r\n/**\r\n * Traverses the ancestor chain of a given node from leaf to root.\r\n *\r\n * @template TNode - The type of tree nodes\r\n * @param node - The node to start the ancestor traversal from\r\n * @param callbacks - Callbacks for visit and parent operations\r\n *\r\n * @example\r\n * // Visit ancestors in a tree structure\r\n * ancestors(node, {\r\n * visit: (node) => console.log(`Visiting: ${node.name}`),\r\n * parent: (node) => node.parent // Return the parent of the node\r\n * })\r\n *\r\n * @example\r\n * // Collect all ancestors' roles in a tree structure\r\n * const roles = []\r\n * ancestors(node, {\r\n * visit: (node) => roles.push(node.role),\r\n * parent: (node) => node.parent\r\n * })\r\n * console.log(roles) // Logs all ancestor roles from leaf to root\r\n */\r\nexport function ancestors<TNode>(node: TNode, callbacks: AncestorCallbacks<TNode>) {\r\n const { visit, parent } = callbacks\r\n let currentNode: TNode | undefined = node\r\n\r\n while (currentNode) {\r\n visit(currentNode)\r\n currentNode = parent(currentNode)\r\n }\r\n}\r\n","/**\r\n * Base error for all route-builder build errors\r\n */\r\nexport class FileRouterError extends Error {\r\n constructor(message: string) {\r\n super(message)\r\n this.name = 'FileRouterError'\r\n }\r\n}\r\n\r\n// ============================================================================\r\n// File Tree Errors\r\n// ============================================================================\r\n\r\nexport class DirectoryNotFoundError extends FileRouterError {\r\n constructor(public path: string) {\r\n super(`Directory not found: \"${path}\"`)\r\n this.name = 'DirectoryNotFoundError'\r\n }\r\n}\r\n\r\nexport class NotADirectoryError extends FileRouterError {\r\n constructor(public path: string) {\r\n super(`Path is not a directory: \"${path}\"`)\r\n this.name = 'NotADirectoryError'\r\n }\r\n}\r\n\r\n// ============================================================================\r\n// Route Tree Errors\r\n// ============================================================================\r\n\r\nexport class RootIsFileError extends FileRouterError {\r\n constructor(public path: string) {\r\n super(\r\n `Root path is a file, not a directory: \"${path}\"\\n\\n` +\r\n 'The app directory must be a directory, not a file.',\r\n )\r\n this.name = 'RootIsFileError'\r\n }\r\n}\r\n\r\nexport class DuplicateScreenError extends FileRouterError {\r\n constructor(\r\n public url: string,\r\n public files: string[],\r\n ) {\r\n super(\r\n `Conflicting screen routes found at \"${url}\":\\n` +\r\n files.map(f => ` - ${f}`).join('\\n') + '\\n\\n' +\r\n 'Each URL can only have one screen file.\\n' +\r\n 'Move one screen to a different directory or rename the route segment.',\r\n )\r\n this.name = 'DuplicateScreenError'\r\n }\r\n}\r\n","import { readdirSync, statSync, type Dirent } from 'fs'\r\nimport { resolve, join, posix } from 'path'\r\nimport { traverse } from '@/lib/tree'\r\nimport { DirectoryNotFoundError, NotADirectoryError } from '../errors'\r\n\r\nexport type FileNode = {\r\n name: string // dirent name\r\n relPath: string\r\n absPath: string\r\n children?: FileNode[] // present only for directories\r\n}\r\n\r\n/**\r\n * Builds a file tree from a directory path.\r\n *\r\n * @param appPath - Path to the app directory\r\n * @returns File tree structure\r\n * @throws {DirectoryNotFoundError} If the directory doesn't exist\r\n * @throws {NotADirectoryError} If the path is not a directory\r\n */\r\nexport function createFileTree(appPath: string): FileNode {\r\n const absPath = resolve(appPath)\r\n validateDirectory(absPath)\r\n\r\n // Root node\r\n const name = 'app'\r\n const relPath = '/app'\r\n const root: FileNode = { name, relPath, absPath, children: [] }\r\n\r\n traverse(root, {\r\n attach: (child, parent) => parent.children!.push(child),\r\n expand: (file) => {\r\n if (!file.children) return []\r\n\r\n return readdirSync(file.absPath, { withFileTypes: true })\r\n .filter(d => d.isFile() || d.isDirectory())\r\n .map(d => createFileNode(d, file))\r\n .sort((a, b) => a.name.localeCompare(b.name))\r\n },\r\n })\r\n return root\r\n}\r\n\r\n/** Validates that the path exists and is a directory. */\r\nfunction validateDirectory(path: string) {\r\n const stat = statSync(path, { throwIfNoEntry: false })\r\n if (!stat) throw new DirectoryNotFoundError(path)\r\n if (!stat.isDirectory()) throw new NotADirectoryError(path)\r\n}\r\n\r\nfunction createFileNode(dirent: Dirent, parent: FileNode) {\r\n const relPath = posix.join(parent.relPath, dirent.name)\r\n const absPath = join(parent.absPath, dirent.name)\r\n\r\n return dirent.isDirectory()\r\n ? { name: dirent.name, relPath, absPath, children: [] }\r\n : { name: dirent.name, relPath, absPath }\r\n}\r\n","import type { FileNode } from './file-tree'\r\nimport { parse, posix } from 'path'\r\nimport { traverse } from '@/lib/tree'\r\nimport { RootIsFileError, DuplicateScreenError } from '../errors'\r\n\r\nexport const SEGMENT_ROLES = ['layout', 'screen', 'error', 'not-found'] as const\r\nexport type SegmentRole = typeof SEGMENT_ROLES[number]\r\n\r\nexport type SegmentRoles = Partial<Record<SegmentRole, string>>\r\nexport type SegmentNode = {\r\n segment: string\r\n url: `${string}/`\r\n type: 'page' | 'group'\r\n roles: SegmentRoles\r\n parent?: SegmentNode\r\n children?: SegmentNode[]\r\n file: FileNode\r\n}\r\n\r\n/**\r\n * Creates a segment tree from a file system tree.\r\n *\r\n * @param fileTree - File system tree\r\n * @returns Segment tree with assigned roles and validated structure\r\n * @throws {RootIsFileError} If the root is a file instead of a directory\r\n * @throws {DuplicateScreenError} If multiple screens map to the same URL\r\n */\r\nexport function createSegmentTree(fileTree: FileNode): SegmentNode {\r\n const tree = buildSegmentTree(fileTree) // Builds segment tree structure from file tree\r\n bindSegmentTree(tree) // Binds roles to segments and validates tree structure\r\n return tree\r\n}\r\n\r\nfunction buildSegmentTree(fileTree: FileNode) {\r\n if (fileTree.children === undefined)\r\n throw new RootIsFileError(fileTree.absPath)\r\n\r\n const root: SegmentNode = {\r\n segment: '',\r\n url: '/',\r\n type: 'page',\r\n roles: {},\r\n children: [],\r\n file: fileTree,\r\n }\r\n\r\n traverse(root, {\r\n attach: (child, parent) => parent.children!.push(child),\r\n expand: segment =>\r\n (segment.file.children ?? [])\r\n .filter(file => file.children && !file.name.startsWith('_'))\r\n .map(file => createSegmentNode(file, segment))\r\n .sort((a, b) => a.segment.localeCompare(b.segment)),\r\n })\r\n return root\r\n}\r\n\r\nfunction bindSegmentTree(segmentTree: SegmentNode) {\r\n const screens: Record<SegmentNode['url'], string> = {}\r\n\r\n traverse(segmentTree, {\r\n expand: segment => segment.children ?? [],\r\n visit: segment => {\r\n assignRoles(segment)\r\n validateScreenUniqueness(segment, screens)\r\n },\r\n })\r\n}\r\n\r\nfunction createSegmentNode(file: FileNode, parent: SegmentNode) {\r\n const isGroup = file.name.startsWith('(') && file.name.endsWith(')')\r\n const segmentNode: SegmentNode = {\r\n segment: file.name,\r\n url: isGroup ? parent.url : `${posix.join(parent.url, file.name)}/`,\r\n type: isGroup ? 'group' : 'page',\r\n roles: {},\r\n parent,\r\n children: [],\r\n file,\r\n }\r\n return segmentNode\r\n}\r\n\r\nfunction assignRoles(segment: SegmentNode) {\r\n for (const child of segment.file.children ?? []) {\r\n const { name, ext } = parse(child.name)\r\n if (ext === '.tsx' && SEGMENT_ROLES.includes(name as SegmentRole))\r\n segment.roles[name as SegmentRole] = child.absPath\r\n }\r\n}\r\n\r\nfunction validateScreenUniqueness(segment: SegmentNode, screens: Record<SegmentNode['url'], string>) {\r\n if (!segment.roles.screen) return\r\n\r\n const existing = screens[segment.url]\r\n if (existing)\r\n throw new DuplicateScreenError(segment.url, [existing, segment.file.absPath])\r\n screens[segment.url] = segment.file.absPath\r\n}\r\n","import { parse, join } from 'path'\r\n\r\nexport function removeExtension(filePath: string) {\r\n const parsed = parse(filePath)\r\n return join(parsed.dir, parsed.name) // Use posix for forward slashes\r\n}\r\n","import type { SegmentNode, SegmentRoles } from './segment-tree'\r\nimport { ancestors, traverse } from '@/lib/tree'\r\nimport { relative } from 'path'\r\nimport { removeExtension } from '@/lib/path-utils'\r\n\r\nexport type RouteTable = Record<string, Route>\r\nexport type Route = {\r\n url: string\r\n chain: SegmentRoles[]\r\n}\r\n\r\n/**\r\n * Builds a route manifest from a segment tree.\r\n *\r\n * Flattens the tree into a dictionary mapping URLs to route metadata.\r\n * Only includes routes that have screens.\r\n * Paths are stored as relative import paths from the generated directory.\r\n *\r\n * @param segmentTree - Segment tree with parent pointers\r\n * @param outDir - Output directory (to calculate relative import paths)\r\n * @returns Flat manifest ready for runtime composition\r\n */\r\nexport function createRouteTable(segmentTree: SegmentNode, outDir: string): RouteTable {\r\n const manifest: RouteTable = {}\r\n const genDir = `${outDir}/generated`\r\n\r\n traverse(segmentTree, {\r\n expand: parentSegment => parentSegment.children ?? [],\r\n visit: segment => {\r\n if (!segment.roles.screen) return\r\n const url = segment.url\r\n const chain = createSegmentChain(segment, genDir)\r\n manifest[url] = { url, chain }\r\n },\r\n })\r\n return manifest\r\n}\r\n\r\n/** Builds ancestor chain from leaf → root order. */\r\nfunction createSegmentChain(segment: SegmentNode, genDir: string) {\r\n const chain: SegmentRoles[] = []\r\n\r\n ancestors(segment, {\r\n parent: ancestorSegment => ancestorSegment.parent,\r\n visit: ancestorSegment => {\r\n const roles: SegmentRoles = {}\r\n const entries = Object.entries(ancestorSegment.roles) as [keyof SegmentRoles, string][]\r\n\r\n for (const [name, path] of entries) {\r\n if (name !== 'screen' || ancestorSegment === segment) { // Skip ancestor screens\r\n const importPath = removeExtension(path) // Remove extension\r\n const relPath = relative(genDir, importPath).replace(/\\\\/g, '/') // Convert to relative path\r\n roles[name] = `${relPath}.js` // Add .js for ES modules\r\n }\r\n }\r\n chain.push(roles)\r\n },\r\n })\r\n return chain\r\n}\r\n","import type { RouteTable } from './route-manifest'\r\nimport { SEGMENT_ROLES } from './segment-tree'\r\n\r\n/** Map from import path to component index (keys are in sorted order) */\r\nexport type ComponentMap = Record<string, number>\r\n\r\n/**\r\n * Builds a mapping of import paths to component IDs from the manifest.\r\n * Collects all unique import paths and assigns them indices.\r\n * Keys are stored in sorted order for deterministic output.\r\n */\r\nexport function createComponentMap(manifest: RouteTable): ComponentMap {\r\n const importPaths = new Set<string>()\r\n\r\n // Collect all unique import paths from manifest\r\n for (const route of Object.values(manifest)) {\r\n for (const segment of route.chain) {\r\n for (const role of SEGMENT_ROLES)\r\n if (segment[role]) importPaths.add(segment[role])\r\n }\r\n }\r\n\r\n // Sort for deterministic output\r\n const imports = Array.from(importPaths).sort()\r\n const mapping: ComponentMap = {}\r\n for (let i = 0; i < imports.length; i++)\r\n mapping[imports[i]!] = i\r\n\r\n return mapping\r\n}\r\n","import type { Route, RouteTable } from './route-manifest'\r\nimport type { ComponentMap } from './component-map'\r\n\r\nexport interface ElementTree {\r\n component: string\r\n props: Record<string, unknown>\r\n children?: ElementTree\r\n}\r\n\r\nexport type ElementTreeMap = Record<string, ElementTree>\r\n\r\n/**\r\n * Creates element trees for all routes in the manifest.\r\n * Each tree represents the nested React component structure for a route.\r\n */\r\nexport function createElementTrees(manifest: RouteTable, componentMap: ComponentMap): ElementTreeMap {\r\n const elementTrees: ElementTreeMap = {}\r\n for (const [url, route] of Object.entries(manifest))\r\n elementTrees[url] = createElementTree(route, componentMap)\r\n return elementTrees\r\n}\r\n\r\n/**\r\n * Builds a structured element tree representing nested React components.\r\n *\r\n * This function mirrors the runtime composition logic but creates a structured data tree\r\n * that will be serialized into createElement calls for the generated routes.ts file.\r\n *\r\n * Composition order per segment (inside to outside):\r\n * 1. Screen component (only in leaf segment)\r\n * 2. Not-found boundary (wraps screen if present)\r\n * 3. Layout (wraps content)\r\n * 4. Error boundary (wraps layout + all descendants)\r\n */\r\nfunction createElementTree(route: Route, mapping: ComponentMap): ElementTree {\r\n const imports = Object.keys(mapping)\r\n\r\n // Start with the screen from the first segment\r\n const screenSegment = route.chain[0]!\r\n const screenPath = screenSegment['screen']!\r\n const screenIndex = mapping[screenPath]!\r\n const screenKey = JSON.stringify(imports[screenIndex]!)\r\n\r\n let tree: ElementTree = {\r\n component: `Component${screenIndex}`,\r\n props: { key: screenKey },\r\n }\r\n\r\n // Process segments from leaf → root (same order as runtime composition)\r\n for (const segment of route.chain) {\r\n // Not-found boundary\r\n if (segment['not-found']) {\r\n const path = segment['not-found']\r\n const index = mapping[path]!\r\n const key = JSON.stringify(imports[index]!)\r\n const fallback = `Component${index}`\r\n tree = {\r\n component: 'NotFoundBoundary',\r\n props: { key, fallback },\r\n children: tree,\r\n }\r\n }\r\n // Error boundary\r\n if (segment['error']) {\r\n const path = segment['error']\r\n const index = mapping[path]!\r\n const key = JSON.stringify(imports[index]!)\r\n const fallback = `Component${index}`\r\n tree = {\r\n component: 'ErrorBoundary',\r\n props: { key, fallback },\r\n children: tree,\r\n }\r\n }\r\n // Layout\r\n if (segment['layout']) {\r\n const path = segment['layout']\r\n const index = mapping[path]!\r\n const key = JSON.stringify(imports[index]!)\r\n tree = {\r\n component: `Component${index}`,\r\n props: { key },\r\n children: tree,\r\n }\r\n }\r\n }\r\n return tree\r\n}\r\n"],"mappings":"gKAkCA,SAAgB,EAAa,EAA8B,CACzD,OAAO,EAGT,MAAM,EAAmC,CACvC,OAAQ,YACR,OAAQ,SACR,aAAc,GACf,CAOD,eAAsB,GAAyC,CAC7D,GAAI,CAKF,IAAM,GADS,MAAM,OAFH,EADC,EAAQ,QAAQ,KAAK,CAAE,gBAAgB,CACf,CAAC,OAGlB,SAAW,EAAE,CAGvC,MAAO,CAAE,GAAG,EAAe,GAAG,EAAY,MAEtC,CAEJ,OAAO,GC/BX,SAAgB,EAAgB,EAAa,EAAqC,CAChF,GAAM,CAAE,QAAO,SAAQ,UAAW,EAC5B,EAAQ,CAAC,EAAK,CAEpB,KAAO,EAAM,QAAQ,CACnB,IAAM,EAAO,EAAM,KAAK,CACxB,IAAQ,EAAK,CAIb,IAAM,EAAW,IAAS,EAAK,EAAI,EAAE,CAErC,IAAK,IAAI,EAAI,EAAS,OAAO,EAAG,GAAK,EAAG,IAAK,CAC3C,IAAM,EAAQ,EAAS,GACvB,IAAS,EAAO,EAAK,CACrB,EAAM,KAAK,EAAM,GAoCvB,SAAgB,EAAiB,EAAa,EAAqC,CACjF,GAAM,CAAE,QAAO,UAAW,EACtB,EAAiC,EAErC,KAAO,GACL,EAAM,EAAY,CAClB,EAAc,EAAO,EAAY,CCrFrC,IAAa,EAAb,cAAqC,KAAM,CACzC,YAAY,EAAiB,CAC3B,MAAM,EAAQ,CACd,KAAK,KAAO,oBAQH,EAAb,cAA4C,CAAgB,CAC1D,YAAY,EAAqB,CAC/B,MAAM,yBAAyB,EAAK,GAAG,CADtB,KAAA,KAAA,EAEjB,KAAK,KAAO,2BAIH,EAAb,cAAwC,CAAgB,CACtD,YAAY,EAAqB,CAC/B,MAAM,6BAA6B,EAAK,GAAG,CAD1B,KAAA,KA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