react-fs-router 1.0.13 → 2.0.1
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/README.md +721 -175
- package/dist/adapters/custom.d.ts +9 -0
- package/dist/adapters/custom.d.ts.map +1 -0
- package/dist/adapters/custom.js +11 -0
- package/dist/adapters/custom.js.map +1 -0
- package/dist/adapters/index.d.ts +8 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +14 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/react-router.d.ts +18 -0
- package/dist/adapters/react-router.d.ts.map +1 -0
- package/dist/adapters/react-router.js +58 -0
- package/dist/adapters/react-router.js.map +1 -0
- package/dist/adapters/tanstack.d.ts +16 -0
- package/dist/adapters/tanstack.d.ts.map +1 -0
- package/dist/adapters/tanstack.js +75 -0
- package/dist/adapters/tanstack.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +59 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +81 -0
- package/dist/config.js.map +1 -0
- package/dist/generator.d.ts +48 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +272 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/render.d.ts +53 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +100 -0
- package/dist/render.js.map +1 -0
- package/dist/scanner.d.ts +27 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +38 -0
- package/dist/scanner.js.map +1 -0
- package/dist/tree.d.ts +11 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +83 -0
- package/dist/tree.js.map +1 -0
- package/dist/types.d.ts +98 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vite.d.ts +14 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +33 -0
- package/dist/vite.js.map +1 -0
- package/dist/webpack.d.ts +32 -0
- package/dist/webpack.d.ts.map +1 -0
- package/dist/webpack.js +26 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +103 -35
- package/.idea/git_toolbox_prj.xml +0 -15
- package/.idea/modules.xml +0 -8
- package/.idea/react-filesystem-router.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/genPath.js +0 -212
- package/index.js +0 -19
- package/lib/components/Routes.js +0 -0
- package/tsconfig.json +0 -7
package/dist/tree.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { isIgnoredName, isIndexName, isSupportedFile, parseFileName, toRouteSegment, } from "./scanner.js";
|
|
4
|
+
/** Join a base route path with a segment, normalizing the leading slash. */
|
|
5
|
+
export function joinPath(base, segment) {
|
|
6
|
+
if (!base || base === "/")
|
|
7
|
+
return "/" + segment;
|
|
8
|
+
return base + "/" + segment;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Recursively scan a pages directory and build the route tree.
|
|
12
|
+
* Directories define hierarchy, index files define the directory's page,
|
|
13
|
+
* layout (and other mapped functions) are attached as add-ons, and other
|
|
14
|
+
* files become leaf routes.
|
|
15
|
+
*/
|
|
16
|
+
export function scanDirectory(pages, config) {
|
|
17
|
+
return walk(pages, "", config);
|
|
18
|
+
}
|
|
19
|
+
function walk(dir, basePath, config) {
|
|
20
|
+
const node = {
|
|
21
|
+
type: "directory",
|
|
22
|
+
path: basePath === "" ? "/" : basePath,
|
|
23
|
+
component: null,
|
|
24
|
+
layout: null,
|
|
25
|
+
functions: {},
|
|
26
|
+
loaders: {},
|
|
27
|
+
children: [],
|
|
28
|
+
};
|
|
29
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
30
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
if (isIgnoredName(entry.name, config))
|
|
33
|
+
continue;
|
|
34
|
+
if (entry.isDirectory()) {
|
|
35
|
+
const segment = toRouteSegment(entry.name, config.pathFormatter);
|
|
36
|
+
node.children.push(...walk(join(dir, entry.name), joinPath(basePath, segment), config));
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (!isSupportedFile(entry.name, config.extensions))
|
|
40
|
+
continue;
|
|
41
|
+
const full = join(dir, entry.name);
|
|
42
|
+
// Never scan the generated routes module itself (avoids self-imports).
|
|
43
|
+
if (full === config.outFile)
|
|
44
|
+
continue;
|
|
45
|
+
const { name } = parseFileName(entry.name);
|
|
46
|
+
const functionName = config.fileToFunction(name);
|
|
47
|
+
const loaderName = config.fileToLoader(name);
|
|
48
|
+
if (functionName === "layout") {
|
|
49
|
+
node.layout = full;
|
|
50
|
+
}
|
|
51
|
+
else if (functionName) {
|
|
52
|
+
node.functions[functionName] = full;
|
|
53
|
+
}
|
|
54
|
+
else if (loaderName) {
|
|
55
|
+
node.loaders[loaderName] = full;
|
|
56
|
+
}
|
|
57
|
+
else if (isIndexName(name)) {
|
|
58
|
+
node.component = full;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
node.children.push({
|
|
62
|
+
type: "file",
|
|
63
|
+
path: joinPath(basePath, toRouteSegment(name, config.pathFormatter)),
|
|
64
|
+
component: full,
|
|
65
|
+
layout: null,
|
|
66
|
+
functions: {},
|
|
67
|
+
loaders: {},
|
|
68
|
+
children: [],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (basePath === "") {
|
|
73
|
+
const rootHasContent = node.component !== null ||
|
|
74
|
+
node.layout !== null ||
|
|
75
|
+
Object.keys(node.functions).length > 0 ||
|
|
76
|
+
Object.keys(node.loaders).length > 0;
|
|
77
|
+
// A content-bearing root becomes a single wrapper route; otherwise we
|
|
78
|
+
// return the top-level routes directly.
|
|
79
|
+
return rootHasContent ? [node] : node.children;
|
|
80
|
+
}
|
|
81
|
+
return [node];
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=tree.js.map
|
package/dist/tree.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../src/tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,aAAa,EACb,WAAW,EACX,eAAe,EACf,aAAa,EACb,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,4EAA4E;AAC5E,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,OAAe;IACpD,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,GAAG,GAAG,OAAO,CAAC;IAChD,OAAO,IAAI,GAAG,GAAG,GAAG,OAAO,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,MAAsB;IACjE,OAAO,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,IAAI,CAAC,GAAW,EAAE,QAAgB,EAAE,MAAsB;IACjE,MAAM,IAAI,GAAc;QACtB,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ;QACtC,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,EAAE;KACb,CAAC;IAEF,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,OAAO,CAAC,IA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ACtC,CAAC;aAAM,IAAI,UAAU,EAAE,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;QAClC,CAAC;aAAM,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACjB,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;gBACpE,SAAS,EAAE,IAAI;gBACf,MAAM,EAAE,IAAI;gBACZ,SAAS,EAAE,EAAE;gBACb,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,EAAE;aACb,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpB,MAAM,cAAc,GAClB,IAAI,CAAC,SAAS,KAAK,IAAI;YACvB,IAAI,CAAC,MAAM,KAAK,IAAI;YACpB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC;YACtC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QACvC,sEAAsE;QACtE,wCAAwC;QACxC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;IACjD,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export interface RouteNode {
|
|
2
|
+
/** Whether this node came from a single file ("file") or a directory ("directory"). */
|
|
3
|
+
type: "file" | "directory";
|
|
4
|
+
/** Full route path, e.g. "/about" or "/users/:id". */
|
|
5
|
+
path: string;
|
|
6
|
+
/** Absolute path to the route/index component file, or null. */
|
|
7
|
+
component: string | null;
|
|
8
|
+
/** Absolute path to the layout function file, or null. */
|
|
9
|
+
layout: string | null;
|
|
10
|
+
/** User-defined function files mapped by function name, e.g. { loading: "/abs/path.tsx" }. */
|
|
11
|
+
functions: Record<string, string>;
|
|
12
|
+
/** Data function files (loader, action, ...) mapped by name, e.g. { loader: "/abs/path.ts" }. */
|
|
13
|
+
loaders: Record<string, string>;
|
|
14
|
+
children: RouteNode[];
|
|
15
|
+
}
|
|
16
|
+
/** Serializable (no component references) route descriptor. */
|
|
17
|
+
export interface RouteMeta {
|
|
18
|
+
type: "file" | "directory";
|
|
19
|
+
path: string;
|
|
20
|
+
component: string | null;
|
|
21
|
+
layout: string | null;
|
|
22
|
+
functions: Record<string, string>;
|
|
23
|
+
loaders: Record<string, string>;
|
|
24
|
+
children: RouteMeta[];
|
|
25
|
+
}
|
|
26
|
+
export type FileToFunction = (fileName: string) => string | null;
|
|
27
|
+
/** Formats dynamic path segments for a specific router. */
|
|
28
|
+
export interface PathFormatter {
|
|
29
|
+
/** Format a dynamic segment, e.g. `[id]` -> `:id` (react-router) or `$id` (tanstack). */
|
|
30
|
+
dynamic: (name: string) => string;
|
|
31
|
+
/** Format a catch-all segment, e.g. `[...rest]` -> `*rest`. */
|
|
32
|
+
catchAll: (name: string) => string;
|
|
33
|
+
}
|
|
34
|
+
export interface UserConfig {
|
|
35
|
+
/** Directory to scan for routes. Default: "src/pages". */
|
|
36
|
+
pages?: string;
|
|
37
|
+
/** Directory to write generated files to. Default: the pages directory. */
|
|
38
|
+
outDir?: string;
|
|
39
|
+
/** Name of the generated routes file. Default: "routes.tsx". */
|
|
40
|
+
outFileName?: string;
|
|
41
|
+
/** Routing adapter to target. Default: "react-router". */
|
|
42
|
+
adapter?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Maps a file base name (without extension) to a function name, e.g.
|
|
45
|
+
* { layout: "layout", loading: "loading", error: "error" }.
|
|
46
|
+
* A file whose name maps to a function is treated as an add-on instead of a route.
|
|
47
|
+
*/
|
|
48
|
+
functions?: Record<string, string> | FileToFunction;
|
|
49
|
+
/**
|
|
50
|
+
* Maps a file base name to a data function (loader, action, ...). These files
|
|
51
|
+
* export a function attached to the route rather than a wrapper component.
|
|
52
|
+
* Default: { loader: "loader", action: "action" }.
|
|
53
|
+
*/
|
|
54
|
+
loaders?: Record<string, string> | FileToFunction;
|
|
55
|
+
/** File extensions to treat as route/function files. */
|
|
56
|
+
extensions?: string[];
|
|
57
|
+
/** Prefix that marks a file/directory as ignored. Default: "_". Set to "" to disable. */
|
|
58
|
+
ignorePrefix?: string;
|
|
59
|
+
/** Whether dot-prefixed files/directories are ignored. Default: true. */
|
|
60
|
+
ignoreDotFiles?: boolean;
|
|
61
|
+
/** Extra file/directory names to ignore. */
|
|
62
|
+
ignore?: string[];
|
|
63
|
+
/** Optional import alias prefix, e.g. "@/pages" (replaces relative imports). */
|
|
64
|
+
importPrefix?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Whether a parent's layout cascades to descendants that do not define their
|
|
67
|
+
* own layout. When a descendant defines its own layout, it always overrides
|
|
68
|
+
* (replaces) the parent's layout. Default: true.
|
|
69
|
+
*/
|
|
70
|
+
inheritLayout?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Generate the legacy declarative React Router component (for use inside
|
|
73
|
+
* `<BrowserRouter>`) instead of the default data-router route objects.
|
|
74
|
+
* Default: false.
|
|
75
|
+
*/
|
|
76
|
+
legacyBrowserRouter?: boolean;
|
|
77
|
+
/** Customize dynamic segment formatting (defaults come from the selected adapter). */
|
|
78
|
+
formatDynamicSegment?: (name: string) => string;
|
|
79
|
+
/** Customize catch-all segment formatting (defaults come from the selected adapter). */
|
|
80
|
+
formatCatchAllSegment?: (name: string) => string;
|
|
81
|
+
}
|
|
82
|
+
export interface ResolvedConfig {
|
|
83
|
+
pages: string;
|
|
84
|
+
outDir: string;
|
|
85
|
+
outFile: string;
|
|
86
|
+
adapter: string;
|
|
87
|
+
fileToFunction: FileToFunction;
|
|
88
|
+
fileToLoader: FileToFunction;
|
|
89
|
+
extensions: string[];
|
|
90
|
+
ignore: string[];
|
|
91
|
+
ignorePrefix: string;
|
|
92
|
+
ignoreDotFiles: boolean;
|
|
93
|
+
inheritLayout: boolean;
|
|
94
|
+
legacyBrowserRouter: boolean;
|
|
95
|
+
pathFormatter: PathFormatter;
|
|
96
|
+
importPrefix: string | null;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,uFAAuF;IACvF,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,0DAA0D;IAC1D,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,8FAA8F;IAC9F,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,iGAAiG;IACjG,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,EAAE,SAAS,EAAE,CAAC;CACvB;AAED,+DAA+D;AAC/D,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,EAAE,SAAS,EAAE,CAAC;CACvB;AA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AClD;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,cAAc,CAAC;IAC/B,YAAY,EAAE,cAAc,CAAC;IAC7B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;IACvB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import type { UserConfig } from "./types.js";
|
|
3
|
+
export interface VitePluginOptions {
|
|
4
|
+
/** Path to a config file (unused when `userConfig` is provided). */
|
|
5
|
+
config?: string;
|
|
6
|
+
/** Inline config, merged over defaults. */
|
|
7
|
+
userConfig?: UserConfig;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Vite plugin: generates the routes module on startup and on every change to
|
|
11
|
+
* the pages directory. Import the generated file in your app as usual.
|
|
12
|
+
*/
|
|
13
|
+
export declare function reactFsRouter(options?: VitePluginOptions): Plugin;
|
|
14
|
+
//# sourceMappingURL=vite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAGlD,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7D,MAAM,WAAW,iBAAiB;IAChC,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAuBrE"}
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { watch } from "chokidar";
|
|
2
|
+
import { resolveConfig } from "./config.js";
|
|
3
|
+
import { writeRoutes } from "./generator.js";
|
|
4
|
+
/**
|
|
5
|
+
* Vite plugin: generates the routes module on startup and on every change to
|
|
6
|
+
* the pages directory. Import the generated file in your app as usual.
|
|
7
|
+
*/
|
|
8
|
+
export function reactFsRouter(options = {}) {
|
|
9
|
+
let resolved;
|
|
10
|
+
return {
|
|
11
|
+
name: "react-fs-router",
|
|
12
|
+
configResolved() {
|
|
13
|
+
resolved = resolveConfig(options.userConfig ?? {}, process.cwd());
|
|
14
|
+
writeRoutes(resolved);
|
|
15
|
+
},
|
|
16
|
+
buildStart() {
|
|
17
|
+
if (resolved)
|
|
18
|
+
writeRoutes(resolved);
|
|
19
|
+
},
|
|
20
|
+
configureServer(server) {
|
|
21
|
+
if (!resolved)
|
|
22
|
+
return;
|
|
23
|
+
const current = resolved;
|
|
24
|
+
const regenerate = () => {
|
|
25
|
+
writeRoutes(current);
|
|
26
|
+
server.ws.send({ type: "full-reload" });
|
|
27
|
+
};
|
|
28
|
+
const watcher = watch(current.pages, { ignored: /(^|[\/\\])\../ });
|
|
29
|
+
watcher.on("add", regenerate).on("change", regenerate).on("unlink", regenerate);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAU7C;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,UAA6B,EAAE;IAC3D,IAAI,QAAoC,CAAC;IAEzC,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,cAAc;YACZ,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;YAClE,WAAW,CAAC,QAAQ,CAAC,CAAC;QACxB,CAAC;QACD,UAAU;YACR,IAAI,QAAQ;gBAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;QACD,eAAe,CAAC,MAAqB;YACnC,IAAI,CAAC,QAAQ;gBAAE,OAAO;YACtB,MAAM,OAAO,GAAG,QAAQ,CAAC;YACzB,MAAM,UAAU,GAAG,GAAS,EAAE;gBAC5B,WAAW,CAAC,OAAO,CAAC,CAAC;gBACrB,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;YAC1C,CAAC,CAAC;YACF,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;YACnE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAClF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { UserConfig } from "./types.js";
|
|
2
|
+
export interface WebpackPluginOptions {
|
|
3
|
+
/** Path to a config file (unused when `userConfig` is provided). */
|
|
4
|
+
config?: string;
|
|
5
|
+
/** Inline config, merged over defaults. */
|
|
6
|
+
userConfig?: UserConfig;
|
|
7
|
+
}
|
|
8
|
+
interface MinimalCompiler {
|
|
9
|
+
hooks: {
|
|
10
|
+
beforeRun: {
|
|
11
|
+
tap: (name: string, fn: () => void) => void;
|
|
12
|
+
};
|
|
13
|
+
watchRun: {
|
|
14
|
+
tap: (name: string, fn: () => void) => void;
|
|
15
|
+
};
|
|
16
|
+
watchClose: {
|
|
17
|
+
tap: (name: string, fn: () => void) => void;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Webpack plugin: regenerates the routes module before each build/watch run
|
|
23
|
+
* and whenever a page file changes.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ReactFsRouterWebpackPlugin {
|
|
26
|
+
private options;
|
|
27
|
+
private watcher?;
|
|
28
|
+
constructor(options?: WebpackPluginOptions);
|
|
29
|
+
apply(compiler: MinimalCompiler): void;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=webpack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACnC,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,UAAU,eAAe;IACvB,KAAK,EAAE;QACL,SAAS,EAAE;YAAE,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;SAAE,CAAC;QAC3D,QAAQ,EAAE;YAAE,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;SAAE,CAAC;QAC1D,UAAU,EAAE;YAAE,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;SAAE,CAAC;KAC7D,CAAC;CACH;AAED;;;GAGG;AACH,qBAAa,0BAA0B;IAGzB,OAAO,CAAC,OAAO;IAF3B,OAAO,CAAC,OAAO,CAAC,CAA2B;gBAEvB,OAAO,GAAE,oBAAyB;IAEtD,KAAK,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;CAavC"}
|
package/dist/webpack.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { watch } from "chokidar";
|
|
2
|
+
import { resolveConfig } from "./config.js";
|
|
3
|
+
import { writeRoutes } from "./generator.js";
|
|
4
|
+
/**
|
|
5
|
+
* Webpack plugin: regenerates the routes module before each build/watch run
|
|
6
|
+
* and whenever a page file changes.
|
|
7
|
+
*/
|
|
8
|
+
export class ReactFsRouterWebpackPlugin {
|
|
9
|
+
options;
|
|
10
|
+
watcher;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
apply(compiler) {
|
|
15
|
+
const config = resolveConfig(this.options.userConfig ?? {}, process.cwd());
|
|
16
|
+
const generate = () => {
|
|
17
|
+
writeRoutes(config);
|
|
18
|
+
};
|
|
19
|
+
compiler.hooks.beforeRun.tap("ReactFsRouterWebpackPlugin", generate);
|
|
20
|
+
compiler.hooks.watchRun.tap("ReactFsRouterWebpackPlugin", generate);
|
|
21
|
+
compiler.hooks.watchClose.tap("ReactFsRouterWebpackPlugin", () => this.watcher?.close());
|
|
22
|
+
this.watcher = watch(config.pages, { ignored: /(^|[\/\\])\../ });
|
|
23
|
+
this.watcher.on("add", generate).on("change", generate).on("unlink", generate);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=webpack.js.map
|
|
@@ -0,0 +1 @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
|
@@ -1,35 +1,103 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-fs-router",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
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
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "react-fs-router",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Config-driven, adapter-pluggable file-system routing for React.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./render": {
|
|
14
|
+
"types": "./dist/render.d.ts",
|
|
15
|
+
"import": "./dist/render.js"
|
|
16
|
+
},
|
|
17
|
+
"./vite": {
|
|
18
|
+
"types": "./dist/vite.d.ts",
|
|
19
|
+
"import": "./dist/vite.js"
|
|
20
|
+
},
|
|
21
|
+
"./webpack": {
|
|
22
|
+
"types": "./dist/webpack.d.ts",
|
|
23
|
+
"import": "./dist/webpack.js"
|
|
24
|
+
},
|
|
25
|
+
"./adapters/react-router": {
|
|
26
|
+
"types": "./dist/adapters/react-router.d.ts",
|
|
27
|
+
"import": "./dist/adapters/react-router.js"
|
|
28
|
+
},
|
|
29
|
+
"./adapters/custom": {
|
|
30
|
+
"types": "./dist/adapters/custom.d.ts",
|
|
31
|
+
"import": "./dist/adapters/custom.js"
|
|
32
|
+
},
|
|
33
|
+
"./adapters/tanstack": {
|
|
34
|
+
"types": "./dist/adapters/tanstack.d.ts",
|
|
35
|
+
"import": "./dist/adapters/tanstack.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"react-fs-router": "./dist/cli.js",
|
|
40
|
+
"rfr": "./dist/cli.js"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc -p tsconfig.json",
|
|
47
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
48
|
+
"pretest": "npm run build",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest"
|
|
51
|
+
},
|
|
52
|
+
"keywords": [
|
|
53
|
+
"react",
|
|
54
|
+
"file-system",
|
|
55
|
+
"routing",
|
|
56
|
+
"react-router",
|
|
57
|
+
"tanstack-router",
|
|
58
|
+
"vite",
|
|
59
|
+
"webpack"
|
|
60
|
+
],
|
|
61
|
+
"author": "Mehran Zahiroddini",
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "https://github.com/Mehran9675/react-filesystem-routing"
|
|
66
|
+
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"chokidar": "^3.6.0",
|
|
69
|
+
"commander": "^12.1.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"react": ">=17",
|
|
73
|
+
"react-router": ">=7",
|
|
74
|
+
"@tanstack/react-router": ">=1"
|
|
75
|
+
},
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"react": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"react-router": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"@tanstack/react-router": {
|
|
84
|
+
"optional": true
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"devDependencies": {
|
|
88
|
+
"@tanstack/react-router": "^1.170.33",
|
|
89
|
+
"@testing-library/react": "^16.1.0",
|
|
90
|
+
"@types/node": "^22.10.2",
|
|
91
|
+
"@types/react": "^18.3.12",
|
|
92
|
+
"@types/react-dom": "^18.3.1",
|
|
93
|
+
"esbuild-loader": "^4.2.2",
|
|
94
|
+
"jsdom": "^25.0.1",
|
|
95
|
+
"react": "^18.3.1",
|
|
96
|
+
"react-dom": "^18.3.1",
|
|
97
|
+
"react-router": "^7.0.0",
|
|
98
|
+
"typescript": "^5.7.2",
|
|
99
|
+
"vite": "^5.4.11",
|
|
100
|
+
"vitest": "^2.1.8",
|
|
101
|
+
"webpack": "^5.95.0"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="GitToolBoxProjectSettings">
|
|
4
|
-
<option name="commitMessageIssueKeyValidationOverride">
|
|
5
|
-
<BoolValueOverride>
|
|
6
|
-
<option name="enabled" value="true" />
|
|
7
|
-
</BoolValueOverride>
|
|
8
|
-
</option>
|
|
9
|
-
<option name="commitMessageValidationEnabledOverride">
|
|
10
|
-
<BoolValueOverride>
|
|
11
|
-
<option name="enabled" value="true" />
|
|
12
|
-
</BoolValueOverride>
|
|
13
|
-
</option>
|
|
14
|
-
</component>
|
|
15
|
-
</project>
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/react-filesystem-router.iml" filepath="$PROJECT_DIR$/.idea/react-filesystem-router.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$">
|
|
5
|
-
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
-
</content>
|
|
9
|
-
<orderEntry type="inheritedJdk" />
|
|
10
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
-
</component>
|
|
12
|
-
</module>
|