@tanstack/virtual-file-routes 1.161.5 → 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/bin/intent.js +25 -0
- package/dist/cjs/api.cjs +45 -51
- package/dist/cjs/api.cjs.map +1 -1
- package/dist/cjs/defineConfig.cjs +5 -4
- package/dist/cjs/defineConfig.cjs.map +1 -1
- package/dist/cjs/index.cjs +8 -10
- package/dist/esm/api.js +46 -56
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/defineConfig.js +6 -5
- package/dist/esm/defineConfig.js.map +1 -1
- package/dist/esm/index.js +1 -9
- package/package.json +9 -2
- package/skills/virtual-file-routes/SKILL.md +218 -0
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
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
|
+
}
|
package/dist/cjs/api.cjs
CHANGED
|
@@ -1,66 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
|
+
//#region src/api.ts
|
|
3
2
|
function rootRoute(file, children) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
return {
|
|
4
|
+
type: "root",
|
|
5
|
+
file,
|
|
6
|
+
children
|
|
7
|
+
};
|
|
9
8
|
}
|
|
10
9
|
function index(file) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
return {
|
|
11
|
+
type: "index",
|
|
12
|
+
file
|
|
13
|
+
};
|
|
15
14
|
}
|
|
16
15
|
function layout(idOrFile, fileOrChildren, children) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
children
|
|
29
|
-
};
|
|
30
|
-
}
|
|
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
|
+
};
|
|
31
27
|
}
|
|
32
28
|
function route(path, fileOrChildren, children) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
children: fileOrChildren
|
|
45
|
-
};
|
|
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
|
+
};
|
|
46
40
|
}
|
|
47
41
|
function physical(pathPrefixOrDirectory, directory) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
pathPrefix: pathPrefixOrDirectory
|
|
59
|
-
};
|
|
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
|
+
};
|
|
60
52
|
}
|
|
53
|
+
//#endregion
|
|
61
54
|
exports.index = index;
|
|
62
55
|
exports.layout = layout;
|
|
63
56
|
exports.physical = physical;
|
|
64
57
|
exports.rootRoute = rootRoute;
|
|
65
58
|
exports.route = route;
|
|
66
|
-
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=api.cjs.map
|
package/dist/cjs/api.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.cjs","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"],"
|
|
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"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
|
+
//#region src/defineConfig.ts
|
|
3
2
|
function defineVirtualSubtreeConfig(config) {
|
|
4
|
-
|
|
3
|
+
return config;
|
|
5
4
|
}
|
|
5
|
+
//#endregion
|
|
6
6
|
exports.defineVirtualSubtreeConfig = defineVirtualSubtreeConfig;
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=defineConfig.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineConfig.cjs","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"],"
|
|
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"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
//# sourceMappingURL=index.cjs.map
|
|
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;
|
package/dist/esm/api.js
CHANGED
|
@@ -1,66 +1,56 @@
|
|
|
1
|
+
//#region src/api.ts
|
|
1
2
|
function rootRoute(file, children) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
return {
|
|
4
|
+
type: "root",
|
|
5
|
+
file,
|
|
6
|
+
children
|
|
7
|
+
};
|
|
7
8
|
}
|
|
8
9
|
function index(file) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
return {
|
|
11
|
+
type: "index",
|
|
12
|
+
file
|
|
13
|
+
};
|
|
13
14
|
}
|
|
14
15
|
function layout(idOrFile, fileOrChildren, children) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
children
|
|
27
|
-
};
|
|
28
|
-
}
|
|
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
|
+
};
|
|
29
27
|
}
|
|
30
28
|
function route(path, fileOrChildren, children) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
children: fileOrChildren
|
|
43
|
-
};
|
|
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
|
+
};
|
|
44
40
|
}
|
|
45
41
|
function physical(pathPrefixOrDirectory, directory) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
pathPrefix: pathPrefixOrDirectory
|
|
57
|
-
};
|
|
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
|
+
};
|
|
58
52
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
rootRoute,
|
|
64
|
-
route
|
|
65
|
-
};
|
|
66
|
-
//# sourceMappingURL=api.js.map
|
|
53
|
+
//#endregion
|
|
54
|
+
export { index, layout, physical, rootRoute, route };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=api.js.map
|
package/dist/esm/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","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"],"
|
|
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"}
|
package/dist/esm/defineConfig.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
//#region src/defineConfig.ts
|
|
1
2
|
function defineVirtualSubtreeConfig(config) {
|
|
2
|
-
|
|
3
|
+
return config;
|
|
3
4
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=defineConfig.js.map
|
|
5
|
+
//#endregion
|
|
6
|
+
export { defineVirtualSubtreeConfig };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=defineConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineConfig.js","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"],"
|
|
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"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
import { index, layout, physical, rootRoute, route } from "./api.js";
|
|
2
2
|
import { defineVirtualSubtreeConfig } from "./defineConfig.js";
|
|
3
|
-
export {
|
|
4
|
-
defineVirtualSubtreeConfig,
|
|
5
|
-
index,
|
|
6
|
-
layout,
|
|
7
|
-
physical,
|
|
8
|
-
rootRoute,
|
|
9
|
-
route
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
|
3
|
+
export { defineVirtualSubtreeConfig, index, layout, physical, rootRoute, route };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/virtual-file-routes",
|
|
3
|
-
"version": "1.161.
|
|
3
|
+
"version": "1.161.7",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,14 +43,21 @@
|
|
|
43
43
|
"sideEffects": false,
|
|
44
44
|
"files": [
|
|
45
45
|
"dist",
|
|
46
|
-
"src"
|
|
46
|
+
"src",
|
|
47
|
+
"skills",
|
|
48
|
+
"bin",
|
|
49
|
+
"!skills/_artifacts"
|
|
47
50
|
],
|
|
48
51
|
"engines": {
|
|
49
52
|
"node": ">=20.19"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
55
|
+
"@tanstack/intent": "^0.0.14",
|
|
52
56
|
"vite": "*"
|
|
53
57
|
},
|
|
58
|
+
"bin": {
|
|
59
|
+
"intent": "./bin/intent.js"
|
|
60
|
+
},
|
|
54
61
|
"scripts": {
|
|
55
62
|
"clean": "rimraf ./dist && rimraf ./coverage",
|
|
56
63
|
"test:eslint": "eslint ./src",
|
|
@@ -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 (`@tanstack/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 @tanstack/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 '@tanstack/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 '@tanstack/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 '@tanstack/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 '@tanstack/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 '@tanstack/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 '@tanstack/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 '@tanstack/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 '@tanstack/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/dist/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|