@benjavicente/virtual-file-routes 1.161.7

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) 2021-present Tanner Linsley
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/bin/intent.js ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ // Auto-generated by @tanstack/intent setup
3
+ // Exposes the intent end-user CLI for consumers of this library.
4
+ // Commit this file, then add to your package.json:
5
+ // "bin": { "intent": "./bin/intent.js" }
6
+ try {
7
+ await import('@tanstack/intent/intent-library')
8
+ } catch (e) {
9
+ const isModuleNotFound =
10
+ e?.code === 'ERR_MODULE_NOT_FOUND' || e?.code === 'MODULE_NOT_FOUND'
11
+ const missingIntentLibrary =
12
+ typeof e?.message === 'string' && e.message.includes('@tanstack/intent')
13
+
14
+ if (isModuleNotFound && missingIntentLibrary) {
15
+ console.error('@tanstack/intent is not installed.')
16
+ console.error('')
17
+ console.error('Install it as a dev dependency:')
18
+ console.error(' npm add -D @tanstack/intent')
19
+ console.error('')
20
+ console.error('Or run directly:')
21
+ console.error(' npx @tanstack/intent@latest list')
22
+ process.exit(1)
23
+ }
24
+ throw e
25
+ }
@@ -0,0 +1,60 @@
1
+ //#region src/api.ts
2
+ function rootRoute(file, children) {
3
+ return {
4
+ type: "root",
5
+ file,
6
+ children
7
+ };
8
+ }
9
+ function index(file) {
10
+ return {
11
+ type: "index",
12
+ file
13
+ };
14
+ }
15
+ function layout(idOrFile, fileOrChildren, children) {
16
+ if (Array.isArray(fileOrChildren)) return {
17
+ type: "layout",
18
+ file: idOrFile,
19
+ children: fileOrChildren
20
+ };
21
+ else return {
22
+ type: "layout",
23
+ id: idOrFile,
24
+ file: fileOrChildren,
25
+ children
26
+ };
27
+ }
28
+ function route(path, fileOrChildren, children) {
29
+ if (typeof fileOrChildren === "string") return {
30
+ type: "route",
31
+ file: fileOrChildren,
32
+ path,
33
+ children
34
+ };
35
+ return {
36
+ type: "route",
37
+ path,
38
+ children: fileOrChildren
39
+ };
40
+ }
41
+ function physical(pathPrefixOrDirectory, directory) {
42
+ if (directory === void 0) return {
43
+ type: "physical",
44
+ directory: pathPrefixOrDirectory,
45
+ pathPrefix: ""
46
+ };
47
+ return {
48
+ type: "physical",
49
+ directory,
50
+ pathPrefix: pathPrefixOrDirectory
51
+ };
52
+ }
53
+ //#endregion
54
+ exports.index = index;
55
+ exports.layout = layout;
56
+ exports.physical = physical;
57
+ exports.rootRoute = rootRoute;
58
+ exports.route = route;
59
+
60
+ //# sourceMappingURL=api.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.cjs","names":[],"sources":["../../src/api.ts"],"sourcesContent":["import type {\n IndexRoute,\n LayoutRoute,\n PhysicalSubtree,\n Route,\n VirtualRootRoute,\n VirtualRouteNode,\n} from './types'\n\nexport function rootRoute(\n file: string,\n children?: Array<VirtualRouteNode>,\n): VirtualRootRoute {\n return {\n type: 'root',\n file,\n children,\n }\n}\n\nexport function index(file: string): IndexRoute {\n return {\n type: 'index',\n file,\n }\n}\n\nexport function layout(\n file: string,\n children: Array<VirtualRouteNode>,\n): LayoutRoute\nexport function layout(\n id: string,\n file: string,\n children: Array<VirtualRouteNode>,\n): LayoutRoute\n\nexport function layout(\n idOrFile: string,\n fileOrChildren: string | Array<VirtualRouteNode>,\n children?: Array<VirtualRouteNode>,\n): LayoutRoute {\n if (Array.isArray(fileOrChildren)) {\n return {\n type: 'layout',\n file: idOrFile,\n children: fileOrChildren,\n }\n } else {\n return {\n type: 'layout',\n id: idOrFile,\n file: fileOrChildren,\n children,\n }\n }\n}\n\nexport function route(path: string, children: Array<VirtualRouteNode>): Route\nexport function route(path: string, file: string): Route\nexport function route(\n path: string,\n file: string,\n children: Array<VirtualRouteNode>,\n): Route\nexport function route(\n path: string,\n fileOrChildren: string | Array<VirtualRouteNode>,\n children?: Array<VirtualRouteNode>,\n): Route {\n if (typeof fileOrChildren === 'string') {\n return {\n type: 'route',\n file: fileOrChildren,\n path,\n children,\n }\n }\n return {\n type: 'route',\n path,\n children: fileOrChildren,\n }\n}\n\n/**\n * Mount a physical directory of route files at a given path prefix.\n *\n * @param pathPrefix - The path prefix to mount the directory at. Use empty string '' to merge routes at the current level.\n * @param directory - The directory containing the route files, relative to the routes directory.\n */\nexport function physical(pathPrefix: string, directory: string): PhysicalSubtree\n/**\n * Mount a physical directory of route files at the current level (empty path prefix).\n * This is equivalent to `physical('', directory)`.\n *\n * @param directory - The directory containing the route files, relative to the routes directory.\n */\nexport function physical(directory: string): PhysicalSubtree\nexport function physical(\n pathPrefixOrDirectory: string,\n directory?: string,\n): PhysicalSubtree {\n if (directory === undefined) {\n // Single argument: directory only, use empty path prefix\n return {\n type: 'physical',\n directory: pathPrefixOrDirectory,\n pathPrefix: '',\n }\n }\n // Two arguments: pathPrefix and directory\n return {\n type: 'physical',\n directory,\n pathPrefix: pathPrefixOrDirectory,\n }\n}\n"],"mappings":";AASA,SAAgB,UACd,MACA,UACkB;AAClB,QAAO;EACL,MAAM;EACN;EACA;EACD;;AAGH,SAAgB,MAAM,MAA0B;AAC9C,QAAO;EACL,MAAM;EACN;EACD;;AAaH,SAAgB,OACd,UACA,gBACA,UACa;AACb,KAAI,MAAM,QAAQ,eAAe,CAC/B,QAAO;EACL,MAAM;EACN,MAAM;EACN,UAAU;EACX;KAED,QAAO;EACL,MAAM;EACN,IAAI;EACJ,MAAM;EACN;EACD;;AAWL,SAAgB,MACd,MACA,gBACA,UACO;AACP,KAAI,OAAO,mBAAmB,SAC5B,QAAO;EACL,MAAM;EACN,MAAM;EACN;EACA;EACD;AAEH,QAAO;EACL,MAAM;EACN;EACA,UAAU;EACX;;AAiBH,SAAgB,SACd,uBACA,WACiB;AACjB,KAAI,cAAc,KAAA,EAEhB,QAAO;EACL,MAAM;EACN,WAAW;EACX,YAAY;EACb;AAGH,QAAO;EACL,MAAM;EACN;EACA,YAAY;EACb"}
@@ -0,0 +1,22 @@
1
+ import { IndexRoute, LayoutRoute, PhysicalSubtree, Route, VirtualRootRoute, VirtualRouteNode } from './types.cjs';
2
+ export declare function rootRoute(file: string, children?: Array<VirtualRouteNode>): VirtualRootRoute;
3
+ export declare function index(file: string): IndexRoute;
4
+ export declare function layout(file: string, children: Array<VirtualRouteNode>): LayoutRoute;
5
+ export declare function layout(id: string, file: string, children: Array<VirtualRouteNode>): LayoutRoute;
6
+ export declare function route(path: string, children: Array<VirtualRouteNode>): Route;
7
+ export declare function route(path: string, file: string): Route;
8
+ export declare function route(path: string, file: string, children: Array<VirtualRouteNode>): Route;
9
+ /**
10
+ * Mount a physical directory of route files at a given path prefix.
11
+ *
12
+ * @param pathPrefix - The path prefix to mount the directory at. Use empty string '' to merge routes at the current level.
13
+ * @param directory - The directory containing the route files, relative to the routes directory.
14
+ */
15
+ export declare function physical(pathPrefix: string, directory: string): PhysicalSubtree;
16
+ /**
17
+ * Mount a physical directory of route files at the current level (empty path prefix).
18
+ * This is equivalent to `physical('', directory)`.
19
+ *
20
+ * @param directory - The directory containing the route files, relative to the routes directory.
21
+ */
22
+ export declare function physical(directory: string): PhysicalSubtree;
@@ -0,0 +1,8 @@
1
+ //#region src/defineConfig.ts
2
+ function defineVirtualSubtreeConfig(config) {
3
+ return config;
4
+ }
5
+ //#endregion
6
+ exports.defineVirtualSubtreeConfig = defineVirtualSubtreeConfig;
7
+
8
+ //# sourceMappingURL=defineConfig.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineConfig.cjs","names":[],"sources":["../../src/defineConfig.ts"],"sourcesContent":["import type { VirtualRouteNode } from './types'\n\n// this is adapted from vite/src/node/config.ts\n\nexport type ConfigFnObject<TConfig> = () => TConfig\nexport type ConfigFnPromise<TConfig> = () => Promise<TConfig>\nexport type ConfigFn<TConfig> = () => TConfig | Promise<TConfig>\n\nexport type ConfigExport<TConfig> =\n | TConfig\n | Promise<TConfig>\n | ConfigFnObject<TConfig>\n | ConfigFnPromise<TConfig>\n | ConfigFn<TConfig>\n\nexport type VirtualRouteSubtreeConfig = Array<VirtualRouteNode>\n\n/**\n * Type helper to make it easier to use __virtual.ts\n * accepts a direct {@link VirtualRouteSubtreeConfig} object, or a function that returns it.\n */\nexport function defineVirtualSubtreeConfig(\n config: VirtualRouteSubtreeConfig,\n): VirtualRouteSubtreeConfig\nexport function defineVirtualSubtreeConfig(\n config: Promise<VirtualRouteSubtreeConfig>,\n): Promise<VirtualRouteSubtreeConfig>\nexport function defineVirtualSubtreeConfig(\n config: ConfigFnObject<VirtualRouteSubtreeConfig>,\n): ConfigFnObject<VirtualRouteSubtreeConfig>\nexport function defineVirtualSubtreeConfig(\n config: ConfigExport<VirtualRouteSubtreeConfig>,\n): ConfigExport<VirtualRouteSubtreeConfig>\nexport function defineVirtualSubtreeConfig(\n config: ConfigExport<VirtualRouteSubtreeConfig>,\n): ConfigExport<VirtualRouteSubtreeConfig> {\n return config\n}\n"],"mappings":";AAiCA,SAAgB,2BACd,QACyC;AACzC,QAAO"}
@@ -0,0 +1,14 @@
1
+ import { VirtualRouteNode } from './types.cjs';
2
+ export type ConfigFnObject<TConfig> = () => TConfig;
3
+ export type ConfigFnPromise<TConfig> = () => Promise<TConfig>;
4
+ export type ConfigFn<TConfig> = () => TConfig | Promise<TConfig>;
5
+ export type ConfigExport<TConfig> = TConfig | Promise<TConfig> | ConfigFnObject<TConfig> | ConfigFnPromise<TConfig> | ConfigFn<TConfig>;
6
+ export type VirtualRouteSubtreeConfig = Array<VirtualRouteNode>;
7
+ /**
8
+ * Type helper to make it easier to use __virtual.ts
9
+ * accepts a direct {@link VirtualRouteSubtreeConfig} object, or a function that returns it.
10
+ */
11
+ export declare function defineVirtualSubtreeConfig(config: VirtualRouteSubtreeConfig): VirtualRouteSubtreeConfig;
12
+ export declare function defineVirtualSubtreeConfig(config: Promise<VirtualRouteSubtreeConfig>): Promise<VirtualRouteSubtreeConfig>;
13
+ export declare function defineVirtualSubtreeConfig(config: ConfigFnObject<VirtualRouteSubtreeConfig>): ConfigFnObject<VirtualRouteSubtreeConfig>;
14
+ export declare function defineVirtualSubtreeConfig(config: ConfigExport<VirtualRouteSubtreeConfig>): ConfigExport<VirtualRouteSubtreeConfig>;
@@ -0,0 +1,9 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_api = require("./api.cjs");
3
+ const require_defineConfig = require("./defineConfig.cjs");
4
+ exports.defineVirtualSubtreeConfig = require_defineConfig.defineVirtualSubtreeConfig;
5
+ exports.index = require_api.index;
6
+ exports.layout = require_api.layout;
7
+ exports.physical = require_api.physical;
8
+ exports.rootRoute = require_api.rootRoute;
9
+ exports.route = require_api.route;
@@ -0,0 +1,4 @@
1
+ export { rootRoute, index, route, layout, physical } from './api.cjs';
2
+ export type { LayoutRoute, Route, IndexRoute, PhysicalSubtree, VirtualRootRoute, VirtualRouteNode, } from './types.cjs';
3
+ export { defineVirtualSubtreeConfig } from './defineConfig.cjs';
4
+ export type { ConfigExport, ConfigFn, ConfigFnObject, ConfigFnPromise, VirtualRouteSubtreeConfig, } from './defineConfig.cjs';
@@ -0,0 +1,27 @@
1
+ export type IndexRoute = {
2
+ type: 'index';
3
+ file: string;
4
+ };
5
+ export type LayoutRoute = {
6
+ type: 'layout';
7
+ id?: string;
8
+ file: string;
9
+ children?: Array<VirtualRouteNode>;
10
+ };
11
+ export type PhysicalSubtree = {
12
+ type: 'physical';
13
+ directory: string;
14
+ pathPrefix: string;
15
+ };
16
+ export type Route = {
17
+ type: 'route';
18
+ file?: string;
19
+ path: string;
20
+ children?: Array<VirtualRouteNode>;
21
+ };
22
+ export type VirtualRouteNode = IndexRoute | LayoutRoute | Route | PhysicalSubtree;
23
+ export type VirtualRootRoute = {
24
+ type: 'root';
25
+ file: string;
26
+ children?: Array<VirtualRouteNode>;
27
+ };
@@ -0,0 +1,22 @@
1
+ import { IndexRoute, LayoutRoute, PhysicalSubtree, Route, VirtualRootRoute, VirtualRouteNode } from './types.js';
2
+ export declare function rootRoute(file: string, children?: Array<VirtualRouteNode>): VirtualRootRoute;
3
+ export declare function index(file: string): IndexRoute;
4
+ export declare function layout(file: string, children: Array<VirtualRouteNode>): LayoutRoute;
5
+ export declare function layout(id: string, file: string, children: Array<VirtualRouteNode>): LayoutRoute;
6
+ export declare function route(path: string, children: Array<VirtualRouteNode>): Route;
7
+ export declare function route(path: string, file: string): Route;
8
+ export declare function route(path: string, file: string, children: Array<VirtualRouteNode>): Route;
9
+ /**
10
+ * Mount a physical directory of route files at a given path prefix.
11
+ *
12
+ * @param pathPrefix - The path prefix to mount the directory at. Use empty string '' to merge routes at the current level.
13
+ * @param directory - The directory containing the route files, relative to the routes directory.
14
+ */
15
+ export declare function physical(pathPrefix: string, directory: string): PhysicalSubtree;
16
+ /**
17
+ * Mount a physical directory of route files at the current level (empty path prefix).
18
+ * This is equivalent to `physical('', directory)`.
19
+ *
20
+ * @param directory - The directory containing the route files, relative to the routes directory.
21
+ */
22
+ export declare function physical(directory: string): PhysicalSubtree;
@@ -0,0 +1,56 @@
1
+ //#region src/api.ts
2
+ function rootRoute(file, children) {
3
+ return {
4
+ type: "root",
5
+ file,
6
+ children
7
+ };
8
+ }
9
+ function index(file) {
10
+ return {
11
+ type: "index",
12
+ file
13
+ };
14
+ }
15
+ function layout(idOrFile, fileOrChildren, children) {
16
+ if (Array.isArray(fileOrChildren)) return {
17
+ type: "layout",
18
+ file: idOrFile,
19
+ children: fileOrChildren
20
+ };
21
+ else return {
22
+ type: "layout",
23
+ id: idOrFile,
24
+ file: fileOrChildren,
25
+ children
26
+ };
27
+ }
28
+ function route(path, fileOrChildren, children) {
29
+ if (typeof fileOrChildren === "string") return {
30
+ type: "route",
31
+ file: fileOrChildren,
32
+ path,
33
+ children
34
+ };
35
+ return {
36
+ type: "route",
37
+ path,
38
+ children: fileOrChildren
39
+ };
40
+ }
41
+ function physical(pathPrefixOrDirectory, directory) {
42
+ if (directory === void 0) return {
43
+ type: "physical",
44
+ directory: pathPrefixOrDirectory,
45
+ pathPrefix: ""
46
+ };
47
+ return {
48
+ type: "physical",
49
+ directory,
50
+ pathPrefix: pathPrefixOrDirectory
51
+ };
52
+ }
53
+ //#endregion
54
+ export { index, layout, physical, rootRoute, route };
55
+
56
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","names":[],"sources":["../../src/api.ts"],"sourcesContent":["import type {\n IndexRoute,\n LayoutRoute,\n PhysicalSubtree,\n Route,\n VirtualRootRoute,\n VirtualRouteNode,\n} from './types'\n\nexport function rootRoute(\n file: string,\n children?: Array<VirtualRouteNode>,\n): VirtualRootRoute {\n return {\n type: 'root',\n file,\n children,\n }\n}\n\nexport function index(file: string): IndexRoute {\n return {\n type: 'index',\n file,\n }\n}\n\nexport function layout(\n file: string,\n children: Array<VirtualRouteNode>,\n): LayoutRoute\nexport function layout(\n id: string,\n file: string,\n children: Array<VirtualRouteNode>,\n): LayoutRoute\n\nexport function layout(\n idOrFile: string,\n fileOrChildren: string | Array<VirtualRouteNode>,\n children?: Array<VirtualRouteNode>,\n): LayoutRoute {\n if (Array.isArray(fileOrChildren)) {\n return {\n type: 'layout',\n file: idOrFile,\n children: fileOrChildren,\n }\n } else {\n return {\n type: 'layout',\n id: idOrFile,\n file: fileOrChildren,\n children,\n }\n }\n}\n\nexport function route(path: string, children: Array<VirtualRouteNode>): Route\nexport function route(path: string, file: string): Route\nexport function route(\n path: string,\n file: string,\n children: Array<VirtualRouteNode>,\n): Route\nexport function route(\n path: string,\n fileOrChildren: string | Array<VirtualRouteNode>,\n children?: Array<VirtualRouteNode>,\n): Route {\n if (typeof fileOrChildren === 'string') {\n return {\n type: 'route',\n file: fileOrChildren,\n path,\n children,\n }\n }\n return {\n type: 'route',\n path,\n children: fileOrChildren,\n }\n}\n\n/**\n * Mount a physical directory of route files at a given path prefix.\n *\n * @param pathPrefix - The path prefix to mount the directory at. Use empty string '' to merge routes at the current level.\n * @param directory - The directory containing the route files, relative to the routes directory.\n */\nexport function physical(pathPrefix: string, directory: string): PhysicalSubtree\n/**\n * Mount a physical directory of route files at the current level (empty path prefix).\n * This is equivalent to `physical('', directory)`.\n *\n * @param directory - The directory containing the route files, relative to the routes directory.\n */\nexport function physical(directory: string): PhysicalSubtree\nexport function physical(\n pathPrefixOrDirectory: string,\n directory?: string,\n): PhysicalSubtree {\n if (directory === undefined) {\n // Single argument: directory only, use empty path prefix\n return {\n type: 'physical',\n directory: pathPrefixOrDirectory,\n pathPrefix: '',\n }\n }\n // Two arguments: pathPrefix and directory\n return {\n type: 'physical',\n directory,\n pathPrefix: pathPrefixOrDirectory,\n }\n}\n"],"mappings":";AASA,SAAgB,UACd,MACA,UACkB;AAClB,QAAO;EACL,MAAM;EACN;EACA;EACD;;AAGH,SAAgB,MAAM,MAA0B;AAC9C,QAAO;EACL,MAAM;EACN;EACD;;AAaH,SAAgB,OACd,UACA,gBACA,UACa;AACb,KAAI,MAAM,QAAQ,eAAe,CAC/B,QAAO;EACL,MAAM;EACN,MAAM;EACN,UAAU;EACX;KAED,QAAO;EACL,MAAM;EACN,IAAI;EACJ,MAAM;EACN;EACD;;AAWL,SAAgB,MACd,MACA,gBACA,UACO;AACP,KAAI,OAAO,mBAAmB,SAC5B,QAAO;EACL,MAAM;EACN,MAAM;EACN;EACA;EACD;AAEH,QAAO;EACL,MAAM;EACN;EACA,UAAU;EACX;;AAiBH,SAAgB,SACd,uBACA,WACiB;AACjB,KAAI,cAAc,KAAA,EAEhB,QAAO;EACL,MAAM;EACN,WAAW;EACX,YAAY;EACb;AAGH,QAAO;EACL,MAAM;EACN;EACA,YAAY;EACb"}
@@ -0,0 +1,14 @@
1
+ import { VirtualRouteNode } from './types.js';
2
+ export type ConfigFnObject<TConfig> = () => TConfig;
3
+ export type ConfigFnPromise<TConfig> = () => Promise<TConfig>;
4
+ export type ConfigFn<TConfig> = () => TConfig | Promise<TConfig>;
5
+ export type ConfigExport<TConfig> = TConfig | Promise<TConfig> | ConfigFnObject<TConfig> | ConfigFnPromise<TConfig> | ConfigFn<TConfig>;
6
+ export type VirtualRouteSubtreeConfig = Array<VirtualRouteNode>;
7
+ /**
8
+ * Type helper to make it easier to use __virtual.ts
9
+ * accepts a direct {@link VirtualRouteSubtreeConfig} object, or a function that returns it.
10
+ */
11
+ export declare function defineVirtualSubtreeConfig(config: VirtualRouteSubtreeConfig): VirtualRouteSubtreeConfig;
12
+ export declare function defineVirtualSubtreeConfig(config: Promise<VirtualRouteSubtreeConfig>): Promise<VirtualRouteSubtreeConfig>;
13
+ export declare function defineVirtualSubtreeConfig(config: ConfigFnObject<VirtualRouteSubtreeConfig>): ConfigFnObject<VirtualRouteSubtreeConfig>;
14
+ export declare function defineVirtualSubtreeConfig(config: ConfigExport<VirtualRouteSubtreeConfig>): ConfigExport<VirtualRouteSubtreeConfig>;
@@ -0,0 +1,8 @@
1
+ //#region src/defineConfig.ts
2
+ function defineVirtualSubtreeConfig(config) {
3
+ return config;
4
+ }
5
+ //#endregion
6
+ export { defineVirtualSubtreeConfig };
7
+
8
+ //# sourceMappingURL=defineConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineConfig.js","names":[],"sources":["../../src/defineConfig.ts"],"sourcesContent":["import type { VirtualRouteNode } from './types'\n\n// this is adapted from vite/src/node/config.ts\n\nexport type ConfigFnObject<TConfig> = () => TConfig\nexport type ConfigFnPromise<TConfig> = () => Promise<TConfig>\nexport type ConfigFn<TConfig> = () => TConfig | Promise<TConfig>\n\nexport type ConfigExport<TConfig> =\n | TConfig\n | Promise<TConfig>\n | ConfigFnObject<TConfig>\n | ConfigFnPromise<TConfig>\n | ConfigFn<TConfig>\n\nexport type VirtualRouteSubtreeConfig = Array<VirtualRouteNode>\n\n/**\n * Type helper to make it easier to use __virtual.ts\n * accepts a direct {@link VirtualRouteSubtreeConfig} object, or a function that returns it.\n */\nexport function defineVirtualSubtreeConfig(\n config: VirtualRouteSubtreeConfig,\n): VirtualRouteSubtreeConfig\nexport function defineVirtualSubtreeConfig(\n config: Promise<VirtualRouteSubtreeConfig>,\n): Promise<VirtualRouteSubtreeConfig>\nexport function defineVirtualSubtreeConfig(\n config: ConfigFnObject<VirtualRouteSubtreeConfig>,\n): ConfigFnObject<VirtualRouteSubtreeConfig>\nexport function defineVirtualSubtreeConfig(\n config: ConfigExport<VirtualRouteSubtreeConfig>,\n): ConfigExport<VirtualRouteSubtreeConfig>\nexport function defineVirtualSubtreeConfig(\n config: ConfigExport<VirtualRouteSubtreeConfig>,\n): ConfigExport<VirtualRouteSubtreeConfig> {\n return config\n}\n"],"mappings":";AAiCA,SAAgB,2BACd,QACyC;AACzC,QAAO"}
@@ -0,0 +1,4 @@
1
+ export { rootRoute, index, route, layout, physical } from './api.js';
2
+ export type { LayoutRoute, Route, IndexRoute, PhysicalSubtree, VirtualRootRoute, VirtualRouteNode, } from './types.js';
3
+ export { defineVirtualSubtreeConfig } from './defineConfig.js';
4
+ export type { ConfigExport, ConfigFn, ConfigFnObject, ConfigFnPromise, VirtualRouteSubtreeConfig, } from './defineConfig.js';
@@ -0,0 +1,3 @@
1
+ import { index, layout, physical, rootRoute, route } from "./api.js";
2
+ import { defineVirtualSubtreeConfig } from "./defineConfig.js";
3
+ export { defineVirtualSubtreeConfig, index, layout, physical, rootRoute, route };
@@ -0,0 +1,27 @@
1
+ export type IndexRoute = {
2
+ type: 'index';
3
+ file: string;
4
+ };
5
+ export type LayoutRoute = {
6
+ type: 'layout';
7
+ id?: string;
8
+ file: string;
9
+ children?: Array<VirtualRouteNode>;
10
+ };
11
+ export type PhysicalSubtree = {
12
+ type: 'physical';
13
+ directory: string;
14
+ pathPrefix: string;
15
+ };
16
+ export type Route = {
17
+ type: 'route';
18
+ file?: string;
19
+ path: string;
20
+ children?: Array<VirtualRouteNode>;
21
+ };
22
+ export type VirtualRouteNode = IndexRoute | LayoutRoute | Route | PhysicalSubtree;
23
+ export type VirtualRootRoute = {
24
+ type: 'root';
25
+ file: string;
26
+ children?: Array<VirtualRouteNode>;
27
+ };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@benjavicente/virtual-file-routes",
3
+ "version": "1.161.7",
4
+ "description": "Modern and scalable routing for React applications",
5
+ "author": "Tanner Linsley",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/TanStack/router.git",
10
+ "directory": "packages/virtual-file-routes"
11
+ },
12
+ "homepage": "https://tanstack.com/router",
13
+ "funding": {
14
+ "type": "github",
15
+ "url": "https://github.com/sponsors/tannerlinsley"
16
+ },
17
+ "keywords": [
18
+ "react",
19
+ "location",
20
+ "router",
21
+ "routing",
22
+ "async",
23
+ "async router",
24
+ "typescript"
25
+ ],
26
+ "type": "module",
27
+ "types": "dist/esm/index.d.ts",
28
+ "main": "dist/cjs/index.cjs",
29
+ "module": "dist/esm/index.js",
30
+ "exports": {
31
+ ".": {
32
+ "import": {
33
+ "types": "./dist/esm/index.d.ts",
34
+ "default": "./dist/esm/index.js"
35
+ },
36
+ "require": {
37
+ "types": "./dist/cjs/index.d.cts",
38
+ "default": "./dist/cjs/index.cjs"
39
+ }
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "sideEffects": false,
44
+ "files": [
45
+ "dist",
46
+ "src",
47
+ "skills",
48
+ "bin",
49
+ "!skills/_artifacts"
50
+ ],
51
+ "engines": {
52
+ "node": ">=20.19"
53
+ },
54
+ "devDependencies": {
55
+ "@tanstack/intent": "^0.0.14",
56
+ "vite": "*"
57
+ },
58
+ "bin": {
59
+ "intent": "./bin/intent.js"
60
+ },
61
+ "scripts": {
62
+ "clean": "rimraf ./dist && rimraf ./coverage",
63
+ "test:eslint": "eslint ./src",
64
+ "test:build": "publint --strict && attw --ignore-rules no-resolution --pack .",
65
+ "build": "vite build"
66
+ }
67
+ }
@@ -0,0 +1,218 @@
1
+ ---
2
+ name: virtual-file-routes
3
+ description: >-
4
+ Programmatic route tree building as an alternative to filesystem
5
+ conventions: rootRoute, index, route, layout, physical,
6
+ defineVirtualSubtreeConfig. Use with TanStack Router plugin's
7
+ virtualRouteConfig option.
8
+ type: core
9
+ library: tanstack-router
10
+ library_version: '1.161.4'
11
+ sources:
12
+ - TanStack/router:packages/virtual-file-routes/src
13
+ - TanStack/router:docs/router/routing/virtual-file-routes.md
14
+ ---
15
+
16
+ # Virtual File Routes (`@benjavicente/virtual-file-routes`)
17
+
18
+ Build route trees programmatically instead of relying on filesystem conventions. Useful when you want explicit control over route structure, need to mix virtual and physical routes, or want to define route subtrees within file-based routing directories.
19
+
20
+ > **CRITICAL**: Types are FULLY INFERRED. Never cast, never annotate inferred values.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ npm install @benjavicente/virtual-file-routes
26
+ ```
27
+
28
+ ## API Reference
29
+
30
+ ### `rootRoute(file, children?)`
31
+
32
+ Creates the root of a virtual route tree.
33
+
34
+ ```ts
35
+ import { rootRoute, index, route } from '@benjavicente/virtual-file-routes'
36
+
37
+ const routes = rootRoute('root.tsx', [
38
+ index('index.tsx'),
39
+ route('/about', 'about.tsx'),
40
+ ])
41
+ ```
42
+
43
+ ### `index(file)`
44
+
45
+ Creates an index route — the default rendered when the parent path matches exactly.
46
+
47
+ ```ts
48
+ import { index } from '@benjavicente/virtual-file-routes'
49
+
50
+ index('home.tsx')
51
+ ```
52
+
53
+ ### `route(path, ...)`
54
+
55
+ Creates a route node. Three call signatures:
56
+
57
+ ```ts
58
+ import { route, index } from '@benjavicente/virtual-file-routes'
59
+
60
+ // Leaf route: path + file
61
+ route('/about', 'about.tsx')
62
+
63
+ // Branch route: path + file + children
64
+ route('/dashboard', 'dashboard.tsx', [
65
+ index('dashboard-index.tsx'),
66
+ route('/settings', 'settings.tsx'),
67
+ ])
68
+
69
+ // Path prefix only (no file): groups children under a URL segment
70
+ route('/api', [route('/users', 'users.tsx'), route('/posts', 'posts.tsx')])
71
+ ```
72
+
73
+ ### `layout(file, children)` or `layout(id, file, children)`
74
+
75
+ Creates a pathless layout route — wraps children without adding a URL segment.
76
+
77
+ ```ts
78
+ import { layout, route, index } from '@benjavicente/virtual-file-routes'
79
+
80
+ // ID derived from filename
81
+ layout('authLayout.tsx', [
82
+ route('/dashboard', 'dashboard.tsx'),
83
+ route('/settings', 'settings.tsx'),
84
+ ])
85
+
86
+ // Explicit ID
87
+ layout('admin-layout', 'adminLayout.tsx', [route('/admin', 'admin.tsx')])
88
+ ```
89
+
90
+ ### `physical(pathPrefix, directory)` or `physical(directory)`
91
+
92
+ Mounts a directory of file-based routes at a URL prefix. Uses TanStack Router's standard file-based routing conventions within that directory.
93
+
94
+ ```ts
95
+ import { physical } from '@benjavicente/virtual-file-routes'
96
+
97
+ // Mount posts/ directory under /posts
98
+ physical('/posts', 'posts')
99
+
100
+ // Merge features/ directory at the current level
101
+ physical('features')
102
+ ```
103
+
104
+ ### `defineVirtualSubtreeConfig(config)`
105
+
106
+ Type helper for `__virtual.ts` files inside file-based routing directories. Identity function that provides type inference.
107
+
108
+ ```ts
109
+ // src/routes/admin/__virtual.ts
110
+ import {
111
+ defineVirtualSubtreeConfig,
112
+ index,
113
+ route,
114
+ } from '@benjavicente/virtual-file-routes'
115
+
116
+ export default defineVirtualSubtreeConfig([
117
+ index('home.tsx'),
118
+ route('$id', 'details.tsx'),
119
+ ])
120
+ ```
121
+
122
+ ## Integration with Router Plugin
123
+
124
+ Pass the virtual route config to the TanStack Router plugin:
125
+
126
+ ```ts
127
+ // vite.config.ts
128
+ import { defineConfig } from 'vite'
129
+ import { tanstackRouter } from '@benjavicente/router-plugin/vite'
130
+ import { routes } from './routes'
131
+
132
+ export default defineConfig({
133
+ plugins: [
134
+ tanstackRouter({
135
+ target: 'react', // or 'solid', 'vue'
136
+ virtualRouteConfig: routes,
137
+ }),
138
+ // Add your framework's Vite plugin here
139
+ ],
140
+ })
141
+ ```
142
+
143
+ Or reference a file path:
144
+
145
+ ```ts
146
+ tanstackRouter({
147
+ target: 'react',
148
+ virtualRouteConfig: './routes.ts',
149
+ })
150
+ ```
151
+
152
+ ## Full Example
153
+
154
+ ```ts
155
+ // routes.ts
156
+ import {
157
+ rootRoute,
158
+ route,
159
+ index,
160
+ layout,
161
+ physical,
162
+ } from '@benjavicente/virtual-file-routes'
163
+
164
+ export const routes = rootRoute('root.tsx', [
165
+ index('index.tsx'),
166
+
167
+ layout('authLayout.tsx', [
168
+ route('/dashboard', 'app/dashboard.tsx', [
169
+ index('app/dashboard-index.tsx'),
170
+ route('/invoices', 'app/dashboard-invoices.tsx', [
171
+ index('app/invoices-index.tsx'),
172
+ route('$id', 'app/invoice-detail.tsx'),
173
+ ]),
174
+ ]),
175
+ ]),
176
+
177
+ // Mount file-based routing from posts/ directory
178
+ physical('/posts', 'posts'),
179
+ ])
180
+ ```
181
+
182
+ ## Common Mistakes
183
+
184
+ ### 1. HIGH: Forgetting that file paths are relative to routesDirectory
185
+
186
+ File paths in `rootRoute`, `index`, `route`, and `layout` are relative to the `routesDirectory` configured in the router plugin (default: `./src/routes`). Do not use absolute paths or paths relative to the project root.
187
+
188
+ ```ts
189
+ // WRONG — absolute path
190
+ route('/about', '/src/routes/about.tsx')
191
+
192
+ // CORRECT — relative to routesDirectory
193
+ route('/about', 'about.tsx')
194
+ ```
195
+
196
+ ### 2. MEDIUM: Using physical() without matching directory structure
197
+
198
+ The directory passed to `physical()` must exist inside `routesDirectory` and follow TanStack Router's file-based routing conventions.
199
+
200
+ ```ts
201
+ // WRONG — directory doesn't exist or wrong location
202
+ physical('/blog', 'src/blog')
203
+
204
+ // CORRECT — relative to routesDirectory
205
+ physical('/blog', 'blog')
206
+ // Expects: src/routes/blog/ (with route files inside)
207
+ ```
208
+
209
+ ### 3. MEDIUM: Confusing layout() with route()
210
+
211
+ `layout()` creates a pathless wrapper — it does NOT add a URL segment. Use `route()` for URL segments.
212
+
213
+ ```ts
214
+ // This does NOT create a /dashboard URL
215
+ layout('dashboardLayout.tsx', [route('/dashboard', 'dashboard.tsx')])
216
+
217
+ // The URL is /dashboard, and dashboardLayout.tsx wraps it
218
+ ```
package/src/api.ts ADDED
@@ -0,0 +1,118 @@
1
+ import type {
2
+ IndexRoute,
3
+ LayoutRoute,
4
+ PhysicalSubtree,
5
+ Route,
6
+ VirtualRootRoute,
7
+ VirtualRouteNode,
8
+ } from './types'
9
+
10
+ export function rootRoute(
11
+ file: string,
12
+ children?: Array<VirtualRouteNode>,
13
+ ): VirtualRootRoute {
14
+ return {
15
+ type: 'root',
16
+ file,
17
+ children,
18
+ }
19
+ }
20
+
21
+ export function index(file: string): IndexRoute {
22
+ return {
23
+ type: 'index',
24
+ file,
25
+ }
26
+ }
27
+
28
+ export function layout(
29
+ file: string,
30
+ children: Array<VirtualRouteNode>,
31
+ ): LayoutRoute
32
+ export function layout(
33
+ id: string,
34
+ file: string,
35
+ children: Array<VirtualRouteNode>,
36
+ ): LayoutRoute
37
+
38
+ export function layout(
39
+ idOrFile: string,
40
+ fileOrChildren: string | Array<VirtualRouteNode>,
41
+ children?: Array<VirtualRouteNode>,
42
+ ): LayoutRoute {
43
+ if (Array.isArray(fileOrChildren)) {
44
+ return {
45
+ type: 'layout',
46
+ file: idOrFile,
47
+ children: fileOrChildren,
48
+ }
49
+ } else {
50
+ return {
51
+ type: 'layout',
52
+ id: idOrFile,
53
+ file: fileOrChildren,
54
+ children,
55
+ }
56
+ }
57
+ }
58
+
59
+ export function route(path: string, children: Array<VirtualRouteNode>): Route
60
+ export function route(path: string, file: string): Route
61
+ export function route(
62
+ path: string,
63
+ file: string,
64
+ children: Array<VirtualRouteNode>,
65
+ ): Route
66
+ export function route(
67
+ path: string,
68
+ fileOrChildren: string | Array<VirtualRouteNode>,
69
+ children?: Array<VirtualRouteNode>,
70
+ ): Route {
71
+ if (typeof fileOrChildren === 'string') {
72
+ return {
73
+ type: 'route',
74
+ file: fileOrChildren,
75
+ path,
76
+ children,
77
+ }
78
+ }
79
+ return {
80
+ type: 'route',
81
+ path,
82
+ children: fileOrChildren,
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Mount a physical directory of route files at a given path prefix.
88
+ *
89
+ * @param pathPrefix - The path prefix to mount the directory at. Use empty string '' to merge routes at the current level.
90
+ * @param directory - The directory containing the route files, relative to the routes directory.
91
+ */
92
+ export function physical(pathPrefix: string, directory: string): PhysicalSubtree
93
+ /**
94
+ * Mount a physical directory of route files at the current level (empty path prefix).
95
+ * This is equivalent to `physical('', directory)`.
96
+ *
97
+ * @param directory - The directory containing the route files, relative to the routes directory.
98
+ */
99
+ export function physical(directory: string): PhysicalSubtree
100
+ export function physical(
101
+ pathPrefixOrDirectory: string,
102
+ directory?: string,
103
+ ): PhysicalSubtree {
104
+ if (directory === undefined) {
105
+ // Single argument: directory only, use empty path prefix
106
+ return {
107
+ type: 'physical',
108
+ directory: pathPrefixOrDirectory,
109
+ pathPrefix: '',
110
+ }
111
+ }
112
+ // Two arguments: pathPrefix and directory
113
+ return {
114
+ type: 'physical',
115
+ directory,
116
+ pathPrefix: pathPrefixOrDirectory,
117
+ }
118
+ }
@@ -0,0 +1,38 @@
1
+ import type { VirtualRouteNode } from './types'
2
+
3
+ // this is adapted from vite/src/node/config.ts
4
+
5
+ export type ConfigFnObject<TConfig> = () => TConfig
6
+ export type ConfigFnPromise<TConfig> = () => Promise<TConfig>
7
+ export type ConfigFn<TConfig> = () => TConfig | Promise<TConfig>
8
+
9
+ export type ConfigExport<TConfig> =
10
+ | TConfig
11
+ | Promise<TConfig>
12
+ | ConfigFnObject<TConfig>
13
+ | ConfigFnPromise<TConfig>
14
+ | ConfigFn<TConfig>
15
+
16
+ export type VirtualRouteSubtreeConfig = Array<VirtualRouteNode>
17
+
18
+ /**
19
+ * Type helper to make it easier to use __virtual.ts
20
+ * accepts a direct {@link VirtualRouteSubtreeConfig} object, or a function that returns it.
21
+ */
22
+ export function defineVirtualSubtreeConfig(
23
+ config: VirtualRouteSubtreeConfig,
24
+ ): VirtualRouteSubtreeConfig
25
+ export function defineVirtualSubtreeConfig(
26
+ config: Promise<VirtualRouteSubtreeConfig>,
27
+ ): Promise<VirtualRouteSubtreeConfig>
28
+ export function defineVirtualSubtreeConfig(
29
+ config: ConfigFnObject<VirtualRouteSubtreeConfig>,
30
+ ): ConfigFnObject<VirtualRouteSubtreeConfig>
31
+ export function defineVirtualSubtreeConfig(
32
+ config: ConfigExport<VirtualRouteSubtreeConfig>,
33
+ ): ConfigExport<VirtualRouteSubtreeConfig>
34
+ export function defineVirtualSubtreeConfig(
35
+ config: ConfigExport<VirtualRouteSubtreeConfig>,
36
+ ): ConfigExport<VirtualRouteSubtreeConfig> {
37
+ return config
38
+ }
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ export { rootRoute, index, route, layout, physical } from './api'
2
+ export type {
3
+ LayoutRoute,
4
+ Route,
5
+ IndexRoute,
6
+ PhysicalSubtree,
7
+ VirtualRootRoute,
8
+ VirtualRouteNode,
9
+ } from './types'
10
+
11
+ export { defineVirtualSubtreeConfig } from './defineConfig'
12
+ export type {
13
+ ConfigExport,
14
+ ConfigFn,
15
+ ConfigFnObject,
16
+ ConfigFnPromise,
17
+ VirtualRouteSubtreeConfig,
18
+ } from './defineConfig'
package/src/types.ts ADDED
@@ -0,0 +1,35 @@
1
+ export type IndexRoute = {
2
+ type: 'index'
3
+ file: string
4
+ }
5
+
6
+ export type LayoutRoute = {
7
+ type: 'layout'
8
+ id?: string
9
+ file: string
10
+ children?: Array<VirtualRouteNode>
11
+ }
12
+
13
+ export type PhysicalSubtree = {
14
+ type: 'physical'
15
+ directory: string
16
+ pathPrefix: string
17
+ }
18
+
19
+ export type Route = {
20
+ type: 'route'
21
+ file?: string
22
+ path: string
23
+ children?: Array<VirtualRouteNode>
24
+ }
25
+ export type VirtualRouteNode =
26
+ | IndexRoute
27
+ | LayoutRoute
28
+ | Route
29
+ | PhysicalSubtree
30
+
31
+ export type VirtualRootRoute = {
32
+ type: 'root'
33
+ file: string
34
+ children?: Array<VirtualRouteNode>
35
+ }