show-routes 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 slxca
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,244 @@
1
- # Temporary Holding Version
1
+ # show-routes
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Next.js routing gets messy.** `show-routes` is a zero-dependency analyzer that turns your App Router into an interactive map, revealing hidden rendering behaviors and layout cascades.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/show-routes?color=black)](https://www.npmjs.com/package/show-routes)
6
+ [![license](https://img.shields.io/npm/l/show-routes?color=black)](./LICENSE)
7
+ [![node](https://img.shields.io/node/v/show-routes?color=black)](https://www.npmjs.com/package/show-routes)
8
+
9
+ One analyzer. Two ways to see your app:
10
+
11
+ - **CLI** — a fast architectural tree in your terminal.
12
+ - **Web UI** — a drop-in route handler with a searchable, expandable map.
13
+
14
+ ## Features
15
+
16
+ - ⚡ **Dual-mode by design** — CLI tree + local web UI, same tiny core.
17
+ - 🧠 **AST-aware** — native TypeScript compiler API; detects `"use client"`, `runtime`, `dynamic`, `revalidate`.
18
+ - 🗺️ **App Router native** — route groups, dynamic / catch-all / optional-catch-all segments, parallel slots, intercepting routes, `src/app`.
19
+ - 🥪 **Boundary aware** — active layout / loading / error cascade per route.
20
+ - 🎨 **Rendering hints** — static / dynamic / ISR, edge / node, client markers.
21
+ - 📦 **Nearly zero runtime dependencies** — only `picocolors` for terminal colors.
22
+ - 🛠️ **Scriptable** — `--json` output and a typed programmatic API.
23
+
24
+ ## Quick start
25
+
26
+ ### CLI
27
+
28
+ ```bash
29
+ npx show-routes
30
+ # or
31
+ pnpm dlx show-routes
32
+ ```
33
+
34
+ Example output:
35
+
36
+ ```text
37
+ / (Root)
38
+ ├─ 🥪 RootLayout
39
+ ├─ 🚨 RootError
40
+ └─ 📄 /
41
+ ├─ Engine: 🧊 Static
42
+ └─ Bounds: Server Component
43
+
44
+ ├── (marketing)
45
+ │ ├── /about
46
+ │ │ └─ 📄 /about
47
+ │ │ ├─ Engine: 🧊 Static
48
+ │ │ └─ Bounds: Server Component
49
+ │ └── /blog/[slug]
50
+ │ └─ 📄 /blog/[slug]
51
+ │ ├─ Engine: ⏱️ ISR (revalidate: 3600s)
52
+ │ └─ Bounds: Server Component
53
+ │
54
+ └── /dashboard
55
+ ├─ 🥪 DashboardLayout
56
+ ├─ ⏳ DashboardLoading
57
+ └── /dashboard/settings
58
+ └─ 📄 /dashboard/settings
59
+ ├─ Engine: 🟢 Dynamic (Node.js)
60
+ └─ Bounds: 🟦 Client Component
61
+ ```
62
+
63
+ ### Icon legend
64
+
65
+ The same icon language is used in both the CLI and the web UI:
66
+
67
+ | Icon | Meaning |
68
+ | --- | --- |
69
+ | ⚡️ | Edge runtime |
70
+ | 🟢 | Node.js runtime (dynamic rendering) |
71
+ | 🧊 | Static generation (SSG) |
72
+ | ⏱️ | Incremental Static Regeneration (ISR) |
73
+ | 🟦 | Client component boundary (`"use client"`) |
74
+ | 🥪 | Layout boundary (`layout.tsx`) |
75
+ | ⏳ | Loading boundary (`loading.tsx`) |
76
+ | 🚨 | Error boundary (`error.tsx`) |
77
+ | 📄 | Page (`page.tsx`) |
78
+ | 🔗 | API route (`route.ts`) |
79
+
80
+ ### Web UI
81
+
82
+ Add the analyzer as a route in your Next.js app:
83
+
84
+ ```bash
85
+ pnpm add show-routes
86
+ ```
87
+
88
+ ```ts
89
+ // app/map/route.ts
90
+ import { createRouteMap } from 'show-routes/server';
91
+
92
+ export const dynamic = 'force-dynamic';
93
+ export const GET = createRouteMap({ basePath: '/map' });
94
+ ```
95
+
96
+ Then visit `http://localhost:3000/map`.
97
+
98
+ By default the handler is disabled in production. To override explicitly:
99
+
100
+ ```ts
101
+ export const GET = createRouteMap({
102
+ basePath: '/map',
103
+ enabled: true, // or false
104
+ });
105
+ ```
106
+
107
+ ## CLI options
108
+
109
+ | Option | Description |
110
+ | --- | --- |
111
+ | `[path]` | Project directory to scan (default: current directory) |
112
+ | `-d, --dir <path>` | Same as positional path |
113
+ | `--json` | Print the route map as JSON |
114
+ | `--no-color` | Disable colored output |
115
+ | `-h, --help` | Show help |
116
+ | `-v, --version` | Show version |
117
+
118
+ ## Programmatic API
119
+
120
+ ```ts
121
+ import { scanApp } from 'show-routes/core';
122
+
123
+ const map = await scanApp();
124
+
125
+ console.log(map.stats);
126
+ console.log(map.root.children);
127
+ ```
128
+
129
+ Or import from the root entry:
130
+
131
+ ```ts
132
+ import { scanApp, createRouteMap } from 'show-routes';
133
+ ```
134
+
135
+ ## JSON shape
136
+
137
+ ```json
138
+ {
139
+ "appDir": "/Users/slxca/project/src/app",
140
+ "cwd": "/Users/slxca/project",
141
+ "generatedAt": "2026-10-31T12:00:00.000Z",
142
+ "stats": { "pages": 3, "routes": 1, "layouts": 2, "loading": 0, "errors": 0, "client": 1, "edge": 1 },
143
+ "warnings": [],
144
+ "root": {
145
+ "segment": "",
146
+ "url": "/",
147
+ "isDynamic": false,
148
+ "isGroup": false,
149
+ "isSlot": false,
150
+ "boundaries": { "layouts": [] },
151
+ "children": [
152
+ {
153
+ "segment": "blog",
154
+ "url": "/blog",
155
+ "isDynamic": false,
156
+ "boundaries": { "layouts": [...] },
157
+ "page": { "kind": "page", "relativePath": "src/app/blog/page.tsx", "client": false },
158
+ "children": [...]
159
+ }
160
+ ]
161
+ }
162
+ }
163
+ ```
164
+
165
+ ## What gets detected
166
+
167
+ | Convention | How it is shown |
168
+ | --- | --- |
169
+ | `page.tsx` | 📄 URL with engine & bounds metadata |
170
+ | `route.ts` | 🔗 Route handler endpoint |
171
+ | `layout.tsx` | 🥪 Active wrapping layout (cascaded) |
172
+ | `loading.tsx` | ⏳ Active loading boundary |
173
+ | `error.tsx` | 🚨 Active error boundary |
174
+ | `(marketing)` | Route group, no URL change |
175
+ | `[id]`, `[...slug]`, `[[...slug]]` | Dynamic URL segment, marked yellow |
176
+ | `@modal` | Parallel slot, no URL change |
177
+ | `(.)photo` / `(..)photo` | Interception markers stripped |
178
+ | `_folder` / `.folder` | Ignored |
179
+ | `src/app` | Auto-detected |
180
+
181
+ ## How it works
182
+
183
+ 1. Locate `app/` or `src/app/`.
184
+ 2. Recursively walk the directory tree and map Next.js conventions to URL paths.
185
+ 3. Parse every route file with the native TypeScript compiler API (`ts.createSourceFile`), no eval, no Babel.
186
+ 4. Inherit layouts / loading / error boundaries down the tree.
187
+ 5. Render a terminal tree or inject the JSON into a local HTML page.
188
+
189
+ ## Built with
190
+
191
+ - TypeScript native compiler API
192
+ - [tsup](https://tsup.egoist.dev/)
193
+ - [Biome](https://biomejs.dev/)
194
+ - [picocolors](https://github.com/alexeyraspopov/picocolors)
195
+ - [Tailwind CSS](https://tailwindcss.com/) (Play CDN, local UI only)
196
+ - Next.js + TypeScript as peer dependencies
197
+
198
+ ## Local development before publishing
199
+
200
+ Use the `file:` protocol to test the package locally. Next.js (Turbopack) cannot resolve symlinked packages created with `pnpm link`, so `file:` is the reliable approach:
201
+
202
+ ```bash
203
+ cd /path/to/show-routes
204
+ pnpm install
205
+ pnpm build
206
+
207
+ cd /path/to/your-next-app
208
+ pnpm add show-routes@file:/path/to/show-routes
209
+ ```
210
+
211
+ Then use it in your app:
212
+
213
+ ```ts
214
+ // app/map/route.ts
215
+ import { createRouteMap } from 'show-routes/server';
216
+
217
+ export const dynamic = 'force-dynamic';
218
+ export const GET = createRouteMap({ basePath: '/map' });
219
+ ```
220
+
221
+ > Route handler files must use `.ts` or `.js`, not `.tsx`. After installing, restart your Next.js dev server.
222
+
223
+ ## Limitations
224
+
225
+ - Rendering mode is inferred from the `dynamic` config, `revalidate`, and dynamic URL segments. The tool does **not** execute your code, so runtime dynamic APIs (`cookies()`, `headers()`, `searchParams`) are not reflected.
226
+ - Recommended for local development. The handler is disabled by default in production.
227
+ - Intercepting routes are approximated as normal URL segments.
228
+ - `.mdx` pages are not parsed.
229
+
230
+ ## Contributing
231
+
232
+ See [CONTRIBUTING.md](./CONTRIBUTING.md). Please read the [Code of Conduct](./CODE_OF_CONDUCT.md) first.
233
+
234
+ ## Security
235
+
236
+ If you discover a security issue, please report it privately via [GitHub Security Advisories](https://github.com/slxca/show-routes/security/advisories/new). See [SECURITY.md](./SECURITY.md) for details.
237
+
238
+ ## Sponsor
239
+
240
+ If this tool saves you time, consider [sponsoring on GitHub](https://github.com/sponsors/slxca). See [SPONSORS.md](./SPONSORS.md) for more.
241
+
242
+ ## License
243
+
244
+ MIT © [slxca](https://github.com/slxca)