@route-intelligence/react-router 2.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/dist/index.d.ts +9 -0
- package/dist/index.js +102 -0
- package/package.json +38 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FrameworkPlugin } from '@route-intelligence/shared';
|
|
2
|
+
|
|
3
|
+
interface ReactRouterPluginOptions {
|
|
4
|
+
routesDir?: string;
|
|
5
|
+
routerFile?: string;
|
|
6
|
+
}
|
|
7
|
+
declare function ReactRouterPlugin(options?: ReactRouterPluginOptions): FrameworkPlugin;
|
|
8
|
+
|
|
9
|
+
export { ReactRouterPlugin, type ReactRouterPluginOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import fg from "fast-glob";
|
|
5
|
+
function ReactRouterPlugin(options = {}) {
|
|
6
|
+
const opts = { routesDir: "src/routes", routerFile: "src/router.tsx", ...options };
|
|
7
|
+
return {
|
|
8
|
+
id: "react-router",
|
|
9
|
+
name: "React Router",
|
|
10
|
+
version: "0.1.0",
|
|
11
|
+
capabilities: {
|
|
12
|
+
supportsAppRouter: false,
|
|
13
|
+
supportsPagesRouter: false,
|
|
14
|
+
supportsMiddleware: false,
|
|
15
|
+
supportsApiRoutes: false,
|
|
16
|
+
supportsI18n: false,
|
|
17
|
+
supportsIncrementalAnalysis: true
|
|
18
|
+
},
|
|
19
|
+
async detect(ctx) {
|
|
20
|
+
const pkgPath = join(ctx.root, "package.json");
|
|
21
|
+
if (!existsSync(pkgPath)) return false;
|
|
22
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
23
|
+
return Boolean(
|
|
24
|
+
pkg.dependencies?.["react-router"] || pkg.dependencies?.["react-router-dom"] || existsSync(join(ctx.root, opts.routerFile))
|
|
25
|
+
);
|
|
26
|
+
},
|
|
27
|
+
async configure(ctx) {
|
|
28
|
+
return { routesDir: opts.routesDir, routerFile: opts.routerFile };
|
|
29
|
+
},
|
|
30
|
+
async *discoverRoutes(ctx) {
|
|
31
|
+
const files = await fg(["**/*.{tsx,jsx}"], {
|
|
32
|
+
cwd: join(ctx.root, opts.routesDir),
|
|
33
|
+
absolute: true,
|
|
34
|
+
ignore: ["**/*.test.*", "**/*.spec.*"]
|
|
35
|
+
});
|
|
36
|
+
for (const filePath of files) {
|
|
37
|
+
const rel = filePath.replace(join(ctx.root, opts.routesDir), "").replace(/\\/g, "/");
|
|
38
|
+
const urlPath = rel.replace(/\.(tsx|jsx)$/, "").replace(/\/index$/, "").replace(/^\//, "") || "/";
|
|
39
|
+
yield {
|
|
40
|
+
id: `react-router:${urlPath}`,
|
|
41
|
+
type: "route",
|
|
42
|
+
filePath,
|
|
43
|
+
urlPath: urlPath.startsWith("/") ? urlPath : `/${urlPath}`,
|
|
44
|
+
segment: urlPath.split("/").pop() ?? "",
|
|
45
|
+
isDynamic: urlPath.includes(":"),
|
|
46
|
+
isCatchAll: urlPath.includes("*"),
|
|
47
|
+
isOptionalCatchAll: false,
|
|
48
|
+
isParallelSlot: false,
|
|
49
|
+
isIntercepted: false,
|
|
50
|
+
isRouteGroup: false,
|
|
51
|
+
tags: ["react-router"]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
async analyzeFile(file, ctx) {
|
|
56
|
+
const edges = [];
|
|
57
|
+
const sourceId = [...ctx.routes.values()].find((r) => r.filePath === file.path)?.id ?? "";
|
|
58
|
+
for (const link of file.jsxLinks) {
|
|
59
|
+
if (link.componentName === "Link" || link.componentName === "NavLink") {
|
|
60
|
+
edges.push({
|
|
61
|
+
sourceId,
|
|
62
|
+
targetPath: link.destination.kind === "static" ? link.destination.path : void 0,
|
|
63
|
+
type: "navigation",
|
|
64
|
+
source: "Link",
|
|
65
|
+
isExternal: link.destination.kind === "external",
|
|
66
|
+
conditions: link.conditions,
|
|
67
|
+
loc: link.loc
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const call of file.navigationCalls) {
|
|
72
|
+
if (call.callee.includes("navigate") || call.callee.startsWith("router.")) {
|
|
73
|
+
edges.push({
|
|
74
|
+
sourceId,
|
|
75
|
+
targetPath: call.destination.kind === "static" ? call.destination.path : void 0,
|
|
76
|
+
type: "navigation",
|
|
77
|
+
source: call.callee.startsWith("router.") ? call.callee : "Navigate",
|
|
78
|
+
method: call.method,
|
|
79
|
+
isExternal: call.destination.kind === "external",
|
|
80
|
+
conditions: call.conditions,
|
|
81
|
+
loc: call.loc
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
filePath: file.path,
|
|
87
|
+
edges,
|
|
88
|
+
conditions: [],
|
|
89
|
+
tags: ["react-router"],
|
|
90
|
+
diagnostics: []
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
async enrichGraph(_graph, _ctx) {
|
|
94
|
+
},
|
|
95
|
+
async runDiagnostics(_graph) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
ReactRouterPlugin
|
|
102
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@route-intelligence/react-router",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "React Router plugin for Route Intelligence",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"development": "./src/index.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"test": "vitest run --passWithNoTests"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@route-intelligence/shared": "*",
|
|
25
|
+
"fast-glob": "^3.3.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@route-intelligence/tsconfig": "*",
|
|
29
|
+
"@types/node": "^22.15.32",
|
|
30
|
+
"tsup": "^8.4.0",
|
|
31
|
+
"typescript": "^5.8.3",
|
|
32
|
+
"vitest": "^3.2.4"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|