next-route-graph 1.0.2 → 1.2.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/CHANGELOG.md +95 -0
- package/CONTRIBUTING.md +74 -0
- package/README.md +169 -134
- package/SECURITY.md +19 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +126 -44
- package/dist/core/analyzer.d.ts +16 -0
- package/dist/core/analyzer.d.ts.map +1 -0
- package/dist/core/analyzer.js +113 -29
- package/dist/core/detector.d.ts +19 -0
- package/dist/core/detector.d.ts.map +1 -0
- package/dist/core/detector.js +31 -3
- package/dist/core/inspect.d.ts +6 -0
- package/dist/core/inspect.d.ts.map +1 -0
- package/dist/core/inspect.js +21 -0
- package/dist/core/linter.d.ts +11 -0
- package/dist/core/linter.d.ts.map +1 -0
- package/dist/core/linter.js +194 -0
- package/dist/core/parser.d.ts +95 -0
- package/dist/core/parser.d.ts.map +1 -0
- package/dist/core/parser.js +242 -15
- package/dist/core/scanner.d.ts +12 -0
- package/dist/core/scanner.d.ts.map +1 -0
- package/dist/core/scanner.js +32 -6
- package/dist/errors/index.d.ts +35 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +65 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/preview.d.ts +4 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +25 -0
- package/dist/render/dot.d.ts +13 -0
- package/dist/render/dot.d.ts.map +1 -0
- package/dist/render/dot.js +66 -0
- package/dist/render/flat.d.ts +13 -0
- package/dist/render/flat.d.ts.map +1 -0
- package/dist/render/flat.js +14 -2
- package/dist/render/graph.d.ts +13 -0
- package/dist/render/graph.d.ts.map +1 -0
- package/dist/render/graph.js +53 -0
- package/dist/render/html.d.ts +8 -0
- package/dist/render/html.d.ts.map +1 -0
- package/dist/render/html.js +718 -0
- package/dist/render/index.d.ts +20 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +37 -0
- package/dist/render/json.d.ts +13 -0
- package/dist/render/json.d.ts.map +1 -0
- package/dist/render/json.js +12 -14
- package/dist/render/markdown.d.ts +13 -0
- package/dist/render/markdown.d.ts.map +1 -0
- package/dist/render/markdown.js +59 -0
- package/dist/render/mermaid.d.ts +13 -0
- package/dist/render/mermaid.d.ts.map +1 -0
- package/dist/render/mermaid.js +64 -0
- package/dist/render/renderer.interface.d.ts +8 -0
- package/dist/render/renderer.interface.d.ts.map +1 -0
- package/dist/render/renderer.interface.js +1 -0
- package/dist/render/svg.d.ts +8 -0
- package/dist/render/svg.d.ts.map +1 -0
- package/dist/render/svg.js +76 -0
- package/dist/render/tree.d.ts +13 -0
- package/dist/render/tree.d.ts.map +1 -0
- package/dist/render/tree.js +57 -7
- package/dist/types/index.d.ts +132 -0
- package/dist/types/index.d.ts.map +1 -0
- package/docs/ARCHITECTURE.md +71 -0
- package/docs/NEW_FEATURES.md +16 -0
- package/docs/adr/0001-offline-reports-and-shared-route-graph.md +29 -0
- package/docs/route-report.png +0 -0
- package/package.json +71 -52
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## [1.2.0] - 2026-11-10
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Offline SVG route maps with intermediate URL segments and source information; available through `--svg`, `--format svg`, and the SDK.
|
|
14
|
+
- A focused HTML explorer with route selection, layout chains, search, endpoint filters, health diagnostics, and downloadable exports.
|
|
15
|
+
- `--output <file>` for every format, including creation of parent directories.
|
|
16
|
+
- `inspectProject()` and immutable `filterRoutes()` SDK helpers, plus a shared `buildRouteGraph()` model for visual exporters.
|
|
17
|
+
- Offline browser regression tests and Windows/Linux CI checks.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- Interception markers now resolve target URL segments while ignoring route groups and parallel slots.
|
|
21
|
+
- Valid parallel and intercepted views no longer trigger duplicate URL diagnostics. API-only projects do not require UI layouts.
|
|
22
|
+
- Dynamic parameter conflicts are detected even when descendant endpoints differ; static paths remain case-sensitive.
|
|
23
|
+
- File read failures abort with `ERR_FILE_READ` instead of silently producing incomplete metadata.
|
|
24
|
+
- Named HTTP exports use the exported alias and ignore type-only entries.
|
|
25
|
+
- HTML uses escaped markup and text nodes for source data, a restrictive content policy, and spreadsheet-safe CSV cells.
|
|
26
|
+
- Preview binds to `127.0.0.1`, validates ports, handles occupied ports, and serves only the report.
|
|
27
|
+
- Format conflicts and unknown formats fail explicitly. Reports remain available when strict validation fails; status messages use stderr.
|
|
28
|
+
- Mermaid and DOT now share the URL hierarchy, including segments without endpoints; DOT line breaks render correctly.
|
|
29
|
+
- Tests rebuild production artifacts first, preventing stale CLI and SDK tests.
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
- Indexed layout lookup replaces repeated scans of every discovered file per endpoint.
|
|
33
|
+
- Search updates every endpoint summary count while keeping convention totals and diagnostics project-wide.
|
|
34
|
+
- CLI version is read from package metadata; npm packages include the linked guides, changelog, and report screenshot.
|
|
35
|
+
|
|
36
|
+
## [1.1.0] - 2026-11-07
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
- **Route Linter & Collision Detection Engine**: Built-in validation rules detecting dynamic segment collisions (`/users/[id]` vs `/users/[slug]`), duplicate URL path conflicts across route groups (`no-duplicate-paths`), conflicting `page.tsx` and `route.ts` handlers, missing root layouts, and unhandled parallel route slots (`@slot`).
|
|
40
|
+
- **Strategy Pattern Renderers**:
|
|
41
|
+
- `MermaidRenderer` (`--mermaid` or `--format mermaid`): Generates Mermaid flowchart diagrams with entity-encoded node shapes.
|
|
42
|
+
- `DotRenderer` (`--dot` or `--format dot`): Generates Graphviz DOT graphs with properly escaped string literals.
|
|
43
|
+
- `MarkdownRenderer` (`--markdown` or `--format markdown`): Generates GitHub-flavored Markdown tables.
|
|
44
|
+
- `HtmlRenderer` (`--html`, `--serve`, or `--format html`): Generates a standalone, zero-dependency interactive visual HTML report with route hierarchy cards, searchable data table, CSV export, integrated tabbed format explorer (Mermaid, DOT, Markdown, ANSI Terminal, JSON, Flat), and built-in local preview server.
|
|
45
|
+
- **Deep HTTP Method & Metadata Inspection**: Automatically detects exported HTTP handlers (`GET`, `POST`, `PUT`, `DELETE`, etc.) in `route.ts`, React Server Actions (`"use server"`), and route segment configurations (`runtime`, `dynamic`).
|
|
46
|
+
- **Programmatic TypeScript SDK**: Exported root module `dist/index.js` with TypeScript type declarations (`dist/index.d.ts`) and `"exports"` map, enabling library usage via `import { analyzeRoutes } from 'next-route-graph'`.
|
|
47
|
+
- **Domain Error Hierarchy**: Structured error classes (`ProjectNotFoundError`, `AmbiguousRouterError`, `NoAppRouterError`, `RouteLintError`) with machine-readable codes and actionable hints.
|
|
48
|
+
- **New CLI Commands & Flags**:
|
|
49
|
+
- `next-route-graph check`: Run route linting checks with exit codes.
|
|
50
|
+
- `--strict`: Fails with non-zero exit code if route issues or collisions are detected.
|
|
51
|
+
- `--format <tree|flat|json|mermaid|dot|markdown|html>`: Flexible format selector.
|
|
52
|
+
- `--html [file]`: Export self-contained interactive HTML report (defaults to `route-graph.html`).
|
|
53
|
+
- `--serve [port]`: Spin up zero-dependency local HTTP preview server (defaults to port 3000) and open in default browser.
|
|
54
|
+
- **Comprehensive Automated Test Suite**: Expanded test coverage from 9 to 50 unit and integration tests, including end-to-end Next.js project fixtures, CLI subprocess tests, scanner edge cases, linter edge cases, external SDK consumer verification, and HTML report validation.
|
|
55
|
+
- **Documentation & Governance Suite**: Added `docs/ARCHITECTURE.md`, `docs/adr/0001-hybrid-parsing-and-strategy-renderers.md`, `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`, and `SECURITY.md`.
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
- **Private Folders**: Ignored Next.js private folders (`_folder`, e.g. `_components`, `_lib`) and hidden directories during route discovery so internal components are not treated as public routes.
|
|
59
|
+
- **Multiple Root Layouts**: Added support for Multiple Root Layouts partitioned within top-level route groups (e.g. `app/(marketing)/layout.tsx` and `app/(shop)/layout.tsx`), eliminating false-positive `require-root-layout` errors.
|
|
60
|
+
- **Intercepting Routes**: Fixed regex in `parseRoutePath` and `extractRouteMetadata` to match multi-level intercepting tokens `(..)(..)` before single-level `(..)`.
|
|
61
|
+
- **Directive Truncation**: Replaced 500-character slice heuristic with a prologue parser (`getPrologueDirectives`), fixing missed `"use client"` / `"use server"` directives in files with long license headers.
|
|
62
|
+
- **Comment-Stripped Extraction**: Stripped comments before extracting HTTP methods, Server Actions, and route configs to prevent commented-out code (e.g. `// export function GET()`) from being reported.
|
|
63
|
+
- **Renderer Escaping**:
|
|
64
|
+
- Escaped backslashes before double quotes in Graphviz DOT output.
|
|
65
|
+
- Entity-encoded square brackets (`#91;`, `#93;`) in Mermaid labels to prevent broken node shape syntax.
|
|
66
|
+
- Escaped pipe characters (`\|`) in Markdown table cells.
|
|
67
|
+
|
|
68
|
+
### Performance
|
|
69
|
+
- **Reduced Disk I/O**: Reduced filesystem reads by 66% in `analyzer.ts` by reading each file once into memory and caching parsed metadata.
|
|
70
|
+
- **Deterministic Route Ordering**: Implemented composite multi-level sorting (`path`, then `file`) guaranteeing consistent output across operating systems.
|
|
71
|
+
|
|
72
|
+
### Changed
|
|
73
|
+
- Refactored `analyzer.ts` into a decoupled pipeline supporting layout hierarchy tracking and slot resolution.
|
|
74
|
+
- Enriched `AnalysisResult` and `SummaryStats` with API route, parallel route, and interceptor counts.
|
|
75
|
+
- Enabled direct path execution in `detectAppRouter` when targeting `app/` or `src/app/` directly.
|
|
76
|
+
- Decoded Next.js `%5F` prefix syntax to underscores in URL routes (e.g. `%5Fprivate` ➔ `/_private`).
|
|
77
|
+
- Aligned route tree columns dynamically based on the longest route path in the project.
|
|
78
|
+
- Fixed nested markdown code blocks in `README.md`.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## [1.0.2] - 2026-09-13
|
|
83
|
+
|
|
84
|
+
### Changed
|
|
85
|
+
- Improved rendering performance and CLI tree layout formatting.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## [1.0.0] - 2026-09-05
|
|
90
|
+
|
|
91
|
+
### Added
|
|
92
|
+
- Initial release of `next-route-graph`.
|
|
93
|
+
- Support for static, dynamic, catch-all, and optional catch-all route detection.
|
|
94
|
+
- App Router directory auto-discovery (`app` and `src/app`).
|
|
95
|
+
- Basic tree, flat, and JSON output formats.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributing to next-route-graph
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing! We welcome bug reports, documentation improvements, new renderers, and feature contributions.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Development Setup
|
|
8
|
+
|
|
9
|
+
1. **Prerequisites**:
|
|
10
|
+
* Node.js >= 18.0.0
|
|
11
|
+
* npm >= 9.0.0
|
|
12
|
+
* Node.js >= 20 for the optional browser tests
|
|
13
|
+
|
|
14
|
+
2. **Clone and Install**:
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/Nima-sltn/next-route-graph.git
|
|
17
|
+
cd next-route-graph
|
|
18
|
+
npm install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
3. **Running the Development CLI**:
|
|
22
|
+
```bash
|
|
23
|
+
npm run dev -- [path-to-nextjs-app]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Quality Checks & Testing
|
|
29
|
+
|
|
30
|
+
Before submitting a Pull Request, ensure all tests, type checks, and builds pass:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Run unit tests
|
|
34
|
+
npm test
|
|
35
|
+
|
|
36
|
+
# Run TypeScript type check
|
|
37
|
+
npm run typecheck
|
|
38
|
+
|
|
39
|
+
# Build the project
|
|
40
|
+
npm run build
|
|
41
|
+
|
|
42
|
+
# Exercise the offline HTML report in Chromium
|
|
43
|
+
npx playwright install chromium
|
|
44
|
+
npm run test:browser
|
|
45
|
+
|
|
46
|
+
# Run the complete pre-publish verification suite
|
|
47
|
+
npm run prepublishOnly
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Project Structure
|
|
53
|
+
|
|
54
|
+
* `src/cli.ts` - Command line interface definition and options.
|
|
55
|
+
* `src/index.ts` - Programmatic public SDK entry point.
|
|
56
|
+
* `src/core/detector.ts` - App Router root directory detection.
|
|
57
|
+
* `src/core/scanner.ts` - File discovery and directory traversal.
|
|
58
|
+
* `src/core/parser.ts` - Directive detection, HTTP method parsing, and URL resolution.
|
|
59
|
+
* `src/core/linter.ts` - Route collision and framework best practice validation.
|
|
60
|
+
* `src/core/analyzer.ts` - Core analysis orchestrator and indexed layout lookup.
|
|
61
|
+
* `src/core/inspect.ts` - Shared CLI/SDK scan entry point and immutable filtering.
|
|
62
|
+
* `src/render/` - Text, SVG, and offline HTML renderers with a shared URL graph.
|
|
63
|
+
* `src/preview.ts` - Loopback-only static report serving.
|
|
64
|
+
* `src/errors/` - Domain error classes and actionable hints.
|
|
65
|
+
* `tests/` - Node.js built-in unit/integration tests and Playwright browser checks.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Pull Request Guidelines
|
|
70
|
+
|
|
71
|
+
1. Create a descriptive branch name (e.g. `feature/openapi-export` or `fix/parallel-routes`).
|
|
72
|
+
2. Add unit tests for any new functionality in `tests/`.
|
|
73
|
+
3. Follow existing code conventions and maintain explicit TypeScript types.
|
|
74
|
+
4. Update `README.md` and `CHANGELOG.md` when introducing user-facing changes.
|
package/README.md
CHANGED
|
@@ -1,134 +1,169 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
npx next-route-graph
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
npx next-route-graph ./my-
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
next-route-graph --
|
|
79
|
-
next-route-graph --
|
|
80
|
-
next-route-graph --
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
1
|
+
# next-route-graph
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/next-route-graph)
|
|
4
|
+
[](https://github.com/Nima-sltn/next-route-graph/actions/workflows/ci.yml)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
Inspect, lint, and visualize a Next.js App Router project without starting Next.js or executing its code. Use the terminal for quick inspection, an offline HTML report for exploration, and SVG for a diagram you can share anywhere.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npx next-route-graph ./my-app
|
|
11
|
+
npx next-route-graph ./my-app --html reports/routes.html
|
|
12
|
+
npx next-route-graph ./my-app --svg --output reports/routes.svg
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Version **1.2.0** adds rendered SVG exports, an offline HTML explorer, and shared CLI/SDK scanning. See the [changelog](CHANGELOG.md) for details.
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
## What it tells you
|
|
20
|
+
|
|
21
|
+
- Public URL paths, dynamic segments, route groups, parallel slots, and intercepted targets.
|
|
22
|
+
- Page and API handler source files, declared HTTP methods, client directives, Server Actions, and literal segment configuration.
|
|
23
|
+
- Layout chains from the outermost layout to each endpoint.
|
|
24
|
+
- Route collisions, missing page layouts, page/handler conflicts, slot fallback warnings, and misplaced global error files.
|
|
25
|
+
|
|
26
|
+
Private folders and build/dependency directories are excluded. Routes are sorted for consistent output. All exports work without a Next.js server.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
Requires Node.js 18 or newer. Run with `npx`, or install in your project:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
npm install -D next-route-graph
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Explore visually
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
# Standalone report; opens directly from disk and works offline
|
|
40
|
+
npx next-route-graph ./my-app --html reports/routes.html
|
|
41
|
+
|
|
42
|
+
# Local static snapshot; visit the printed URL (default port 3000)
|
|
43
|
+
npx next-route-graph ./my-app --serve
|
|
44
|
+
|
|
45
|
+
# Choose a port, or 0 to choose an available port
|
|
46
|
+
npx next-route-graph ./my-app --serve 4300
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The report has four sections:
|
|
50
|
+
|
|
51
|
+
| Section | Purpose |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| Route map | Rendered SVG hierarchy, including segments without endpoints. Select a node with a mouse or keyboard to inspect every source and its layout chain. |
|
|
54
|
+
| Routes | Search paths, source files, methods, or layouts; filter pages, handlers, rendering declarations, dynamic routes, slots, or interceptions. Download matching rows as CSV. |
|
|
55
|
+
| Health | Project-wide diagnostics with rule names, locations, and actionable hints. |
|
|
56
|
+
| Exports | Download SVG, Mermaid, DOT, Markdown, JSON, flat paths, or a plain terminal tree. One selector keeps the interface compact. |
|
|
57
|
+
|
|
58
|
+
Multiple sources at one URL remain inspectable. Map filtering dims unrelated branches and retains ancestors for context. Report downloads contain all endpoints included in the report; CSV uses the current browser filter.
|
|
59
|
+
|
|
60
|
+
SVG is a real vector image. Mermaid and Graphviz DOT are source formats for their respective renderers; they do not need to render in your terminal. The HTML map renders directly without a CDN or a graph library. The preview server binds only to `127.0.0.1` and serves the in-memory report. Rerun the command to refresh its snapshot.
|
|
61
|
+
|
|
62
|
+
## Export and automate
|
|
63
|
+
|
|
64
|
+
Choose one format flag, or use `--format`. `--output` works for every format and creates missing parent directories. File-write notices go to stderr; stdout remains suitable for pipes.
|
|
65
|
+
|
|
66
|
+
| Format | Flag | Use |
|
|
67
|
+
| --- | --- | --- |
|
|
68
|
+
| Terminal tree | Default / `--format tree` | Quick overview and lint summary |
|
|
69
|
+
| Flat paths | `--flat` | Shell pipelines |
|
|
70
|
+
| JSON | `--json` | SDK consumers, build tools, or AI context |
|
|
71
|
+
| SVG | `--svg` | Rendered image for reports and design tools |
|
|
72
|
+
| HTML | `--html [file]` / `--format html` | Offline interactive report |
|
|
73
|
+
| Mermaid | `--mermaid` | Fenced diagram for Markdown documentation |
|
|
74
|
+
| Graphviz DOT | `--dot` | Graphviz processing |
|
|
75
|
+
| Markdown | `--markdown` | Documentation table |
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
npx next-route-graph ./my-app --json --output reports/routes.json
|
|
79
|
+
npx next-route-graph ./my-app --mermaid --output reports/routes.md
|
|
80
|
+
npx next-route-graph ./my-app --dot --output reports/routes.dot
|
|
81
|
+
dot -Tsvg reports/routes.dot -o reports/graphviz.svg
|
|
82
|
+
|
|
83
|
+
# Stream HTML instead of writing a report file
|
|
84
|
+
npx next-route-graph ./my-app --format html > routes.html
|
|
85
|
+
|
|
86
|
+
# Case-insensitive filtering by path, file, or HTTP method
|
|
87
|
+
npx next-route-graph ./my-app --search POST --json
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`--search` changes endpoint counts in the report; layout/loading/error-file totals and diagnostics still describe the whole project. A filtered export cannot hide a CI failure. Use `--output -` to explicitly write to stdout. `--html` defaults to `route-graph.html`.
|
|
91
|
+
|
|
92
|
+
## Validate in CI
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
npx next-route-graph check ./my-app
|
|
96
|
+
npx next-route-graph check ./my-app --strict --json
|
|
97
|
+
|
|
98
|
+
# Save a reviewable artifact even if validation fails
|
|
99
|
+
npx next-route-graph ./my-app --strict --format html --output reports/routes.html
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
| Command | Exit 1 when |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| Default scan | Scanning or output fails |
|
|
105
|
+
| `check` / `--check` | Scanning fails or lint errors exist |
|
|
106
|
+
| `--strict` | Scanning fails or lint errors or warnings exist |
|
|
107
|
+
|
|
108
|
+
JSON scan errors are written as `{ "error": "…", "code": "…" }` to stderr. Successful report data is written to stdout or the requested file. Invalid options also fail. A strict file export is written before lint determines the exit code.
|
|
109
|
+
|
|
110
|
+
Example GitHub Actions step after installing your project's dependencies:
|
|
111
|
+
|
|
112
|
+
```yaml
|
|
113
|
+
- name: Check routing and generate a report
|
|
114
|
+
run: npx next-route-graph . --strict --format html --output reports/routes.html
|
|
115
|
+
- name: Save report
|
|
116
|
+
if: always()
|
|
117
|
+
uses: actions/upload-artifact@v4
|
|
118
|
+
with:
|
|
119
|
+
name: route-report
|
|
120
|
+
path: reports/routes.html
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## TypeScript SDK
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { inspectProject, filterRoutes, getRenderer } from "next-route-graph";
|
|
127
|
+
import { writeFile } from "node:fs/promises";
|
|
128
|
+
|
|
129
|
+
const result = await inspectProject("./my-app");
|
|
130
|
+
await writeFile("routes.html", getRenderer("html").render(result));
|
|
131
|
+
await writeFile("routes.svg", getRenderer("svg").render(result));
|
|
132
|
+
|
|
133
|
+
const api = filterRoutes(result, "api/"); // returns a new result
|
|
134
|
+
console.log(api.summary.apiRoutes);
|
|
135
|
+
if (result.lint?.hasErrors) process.exitCode = 1;
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The lower-level `detectAppRouter()`, `scanAppDir()`, `analyzeRoutes()`, and `lintRoutes()` APIs remain available. `buildRouteGraph(result.routes)` exposes URL nodes with stable IDs within an export, parent IDs, depth, and all endpoint sources attached to each node. `getRenderer()` rejects unknown formats. See [architecture](docs/ARCHITECTURE.md) for module boundaries.
|
|
139
|
+
|
|
140
|
+
## Scope and limitations
|
|
141
|
+
|
|
142
|
+
This is static **App Router** source inspection, not a replacement for `next build`. Pages Router, metadata-generated endpoints, custom `pageExtensions`, rewrites, redirects, middleware/proxy behavior, and imports are not evaluated. Source extraction uses comment-aware text parsing, not an AST or TypeScript evaluation; computed exports, complex string contents, and re-export chains can be incomplete. Detected HTTP methods are declared methods, not Next.js-generated methods.
|
|
143
|
+
|
|
144
|
+
“Server” means the file has no top-level `use client` directive. It does not prove static generation, caching, SSR behavior, or imported component boundaries. Runtime and dynamic configuration show local literal declarations, not inherited effective values. The URL graph describes structure; its edges do not imply imports, navigation links, or layout inheritance. Layout inheritance appears separately in the details panel.
|
|
145
|
+
|
|
146
|
+
Diagnostics intentionally cover a small set of routing conventions. Parallel fallback warnings flag potentially unmatched navigation; the tool does not simulate navigation. Share exported reports with the same care as source filenames and internal endpoint names: they contain those names and detected metadata, but never source file contents.
|
|
147
|
+
|
|
148
|
+
Framework references: [intercepting routes](https://nextjs.org/docs/app/api-reference/file-conventions/intercepting-routes), [parallel routes](https://nextjs.org/docs/app/api-reference/file-conventions/parallel-routes), and [layouts](https://nextjs.org/docs/app/api-reference/file-conventions/layout).
|
|
149
|
+
|
|
150
|
+
## Development
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
npm ci
|
|
154
|
+
npm run typecheck
|
|
155
|
+
npm test # builds first; unit, CLI, SDK, and HTTP integration tests
|
|
156
|
+
npx playwright install chromium
|
|
157
|
+
npm run test:browser # builds first; real offline browser workflow
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Browser development tests require Node.js 20 or newer. To use installed Chrome in PowerShell: `$env:PLAYWRIGHT_CHROMIUM_CHANNEL='chrome'`. Set `NRG_REPORT_ARTIFACT_DIR=reports` to save the example HTML and desktop/mobile screenshots during browser tests.
|
|
161
|
+
|
|
162
|
+
- [Contributing](CONTRIBUTING.md)
|
|
163
|
+
- [Architecture and trade-offs](docs/ARCHITECTURE.md)
|
|
164
|
+
- [Architecture decision](docs/adr/0001-offline-reports-and-shared-route-graph.md)
|
|
165
|
+
- [Improvement evidence](docs/NEW_FEATURES.md)
|
|
166
|
+
- [Changelog](CHANGELOG.md)
|
|
167
|
+
- [Security](SECURITY.md)
|
|
168
|
+
|
|
169
|
+
[MIT](LICENSE) © 2026 Nima Soltanian
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
| Version | Supported |
|
|
6
|
+
| ------- | ------------------ |
|
|
7
|
+
| 1.2.x | :white_check_mark: |
|
|
8
|
+
| 1.1.x | :white_check_mark: |
|
|
9
|
+
| 1.0.x | :x: |
|
|
10
|
+
|
|
11
|
+
## Reporting a Vulnerability
|
|
12
|
+
|
|
13
|
+
If you discover a security vulnerability in `next-route-graph`, please report it responsibly:
|
|
14
|
+
|
|
15
|
+
1. **Do not open a public GitHub issue.**
|
|
16
|
+
2. Send an email to the repository maintainer or open a private security advisory through GitHub.
|
|
17
|
+
3. Include detailed steps to reproduce the issue along with a minimal reproduction project if possible.
|
|
18
|
+
|
|
19
|
+
You will receive an acknowledgment within 48 hours, followed by updates on the timeline for a patch.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|