@van1s1mys/ai-router-plugin-vite 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +60 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
aiRouter: () => aiRouter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_shared = require("@ai-router/shared");
|
|
27
|
+
function aiRouter(options = {}) {
|
|
28
|
+
let root = process.cwd();
|
|
29
|
+
return {
|
|
30
|
+
name: "ai-router",
|
|
31
|
+
configResolved(config) {
|
|
32
|
+
root = config.root;
|
|
33
|
+
},
|
|
34
|
+
resolveId(id) {
|
|
35
|
+
if (id === import_shared.VIRTUAL_MODULE_ID) {
|
|
36
|
+
return import_shared.RESOLVED_VIRTUAL_MODULE_ID;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
load(id) {
|
|
40
|
+
if (id === import_shared.RESOLVED_VIRTUAL_MODULE_ID) {
|
|
41
|
+
const routes = (0, import_shared.scanRoutes)(root, options);
|
|
42
|
+
return (0, import_shared.generateRoutesModule)(routes);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
handleHotUpdate({ file, server }) {
|
|
46
|
+
if (options.dirs?.some((dir) => file.includes(dir))) {
|
|
47
|
+
const module2 = server.moduleGraph.getModuleById(import_shared.RESOLVED_VIRTUAL_MODULE_ID);
|
|
48
|
+
if (module2) {
|
|
49
|
+
server.moduleGraph.invalidateModule(module2);
|
|
50
|
+
server.ws.send({ type: "full-reload" });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
aiRouter
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Vite plugin for ai-router.\n *\n * Scans page directories at build time and exposes a `virtual:ai-router`\n * module that exports the generated route config array.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { aiRouter } from 'ai-router-plugin-vite';\n *\n * export default defineConfig({\n * plugins: [\n * aiRouter({ dirs: ['src/pages'] }),\n * ],\n * });\n * ```\n *\n * ```ts\n * // app.ts\n * import { routes } from 'virtual:ai-router';\n * import { SmartRouter } from 'ai-router';\n *\n * const router = new SmartRouter({ routes });\n * ```\n *\n * @module\n */\n\nimport type { Plugin } from 'vite';\nimport {\n scanRoutes,\n generateRoutesModule,\n VIRTUAL_MODULE_ID,\n RESOLVED_VIRTUAL_MODULE_ID,\n type PluginOptions,\n} from '@ai-router/shared';\n\nexport type { PluginOptions } from '@ai-router/shared';\n\n/**\n * Creates a Vite plugin that generates route config from the file system.\n *\n * The plugin provides a virtual module `virtual:ai-router` that exports\n * a `routes` array compatible with {@link SmartRouter}.\n *\n * Supports HMR — routes are re-scanned when files in `dirs` change.\n *\n * @param options - Directories to scan, file extensions, exclusions, and manual routes.\n * @returns Vite plugin instance.\n *\n * @example\n * ```ts\n * // Auto-scan + manual overrides\n * aiRouter({\n * dirs: ['src/pages'],\n * routes: [\n * { path: '/pricing', title: 'Pricing', description: 'cost, plans, billing' },\n * ],\n * });\n * ```\n */\nexport function aiRouter(options: PluginOptions = {}): Plugin {\n let root = process.cwd();\n\n return {\n name: 'ai-router',\n\n configResolved(config) {\n root = config.root;\n },\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n const routes = scanRoutes(root, options);\n return generateRoutesModule(routes);\n }\n },\n\n handleHotUpdate({ file, server }) {\n if (options.dirs?.some((dir) => file.includes(dir))) {\n const module = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);\n if (module) {\n server.moduleGraph.invalidateModule(module);\n server.ws.send({ type: 'full-reload' });\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BA,oBAMO;AA0BA,SAAS,SAAS,UAAyB,CAAC,GAAW;AAC5D,MAAI,OAAO,QAAQ,IAAI;AAEvB,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,eAAe,QAAQ;AACrB,aAAO,OAAO;AAAA,IAChB;AAAA,IAEA,UAAU,IAAI;AACZ,UAAI,OAAO,iCAAmB;AAC5B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAI;AACP,UAAI,OAAO,0CAA4B;AACrC,cAAM,aAAS,0BAAW,MAAM,OAAO;AACvC,mBAAO,oCAAqB,MAAM;AAAA,MACpC;AAAA,IACF;AAAA,IAEA,gBAAgB,EAAE,MAAM,OAAO,GAAG;AAChC,UAAI,QAAQ,MAAM,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,CAAC,GAAG;AACnD,cAAMA,UAAS,OAAO,YAAY,cAAc,wCAA0B;AAC1E,YAAIA,SAAQ;AACV,iBAAO,YAAY,iBAAiBA,OAAM;AAC1C,iBAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["module"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { PluginOptions } from '@ai-router/shared';
|
|
3
|
+
export { PluginOptions } from '@ai-router/shared';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Vite plugin for ai-router.
|
|
7
|
+
*
|
|
8
|
+
* Scans page directories at build time and exposes a `virtual:ai-router`
|
|
9
|
+
* module that exports the generated route config array.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // vite.config.ts
|
|
14
|
+
* import { aiRouter } from 'ai-router-plugin-vite';
|
|
15
|
+
*
|
|
16
|
+
* export default defineConfig({
|
|
17
|
+
* plugins: [
|
|
18
|
+
* aiRouter({ dirs: ['src/pages'] }),
|
|
19
|
+
* ],
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* // app.ts
|
|
25
|
+
* import { routes } from 'virtual:ai-router';
|
|
26
|
+
* import { SmartRouter } from 'ai-router';
|
|
27
|
+
*
|
|
28
|
+
* const router = new SmartRouter({ routes });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @module
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates a Vite plugin that generates route config from the file system.
|
|
36
|
+
*
|
|
37
|
+
* The plugin provides a virtual module `virtual:ai-router` that exports
|
|
38
|
+
* a `routes` array compatible with {@link SmartRouter}.
|
|
39
|
+
*
|
|
40
|
+
* Supports HMR — routes are re-scanned when files in `dirs` change.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Directories to scan, file extensions, exclusions, and manual routes.
|
|
43
|
+
* @returns Vite plugin instance.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Auto-scan + manual overrides
|
|
48
|
+
* aiRouter({
|
|
49
|
+
* dirs: ['src/pages'],
|
|
50
|
+
* routes: [
|
|
51
|
+
* { path: '/pricing', title: 'Pricing', description: 'cost, plans, billing' },
|
|
52
|
+
* ],
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function aiRouter(options?: PluginOptions): Plugin;
|
|
57
|
+
|
|
58
|
+
export { aiRouter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { PluginOptions } from '@ai-router/shared';
|
|
3
|
+
export { PluginOptions } from '@ai-router/shared';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Vite plugin for ai-router.
|
|
7
|
+
*
|
|
8
|
+
* Scans page directories at build time and exposes a `virtual:ai-router`
|
|
9
|
+
* module that exports the generated route config array.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // vite.config.ts
|
|
14
|
+
* import { aiRouter } from 'ai-router-plugin-vite';
|
|
15
|
+
*
|
|
16
|
+
* export default defineConfig({
|
|
17
|
+
* plugins: [
|
|
18
|
+
* aiRouter({ dirs: ['src/pages'] }),
|
|
19
|
+
* ],
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* // app.ts
|
|
25
|
+
* import { routes } from 'virtual:ai-router';
|
|
26
|
+
* import { SmartRouter } from 'ai-router';
|
|
27
|
+
*
|
|
28
|
+
* const router = new SmartRouter({ routes });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @module
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates a Vite plugin that generates route config from the file system.
|
|
36
|
+
*
|
|
37
|
+
* The plugin provides a virtual module `virtual:ai-router` that exports
|
|
38
|
+
* a `routes` array compatible with {@link SmartRouter}.
|
|
39
|
+
*
|
|
40
|
+
* Supports HMR — routes are re-scanned when files in `dirs` change.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Directories to scan, file extensions, exclusions, and manual routes.
|
|
43
|
+
* @returns Vite plugin instance.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Auto-scan + manual overrides
|
|
48
|
+
* aiRouter({
|
|
49
|
+
* dirs: ['src/pages'],
|
|
50
|
+
* routes: [
|
|
51
|
+
* { path: '/pricing', title: 'Pricing', description: 'cost, plans, billing' },
|
|
52
|
+
* ],
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare function aiRouter(options?: PluginOptions): Plugin;
|
|
57
|
+
|
|
58
|
+
export { aiRouter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
scanRoutes,
|
|
4
|
+
generateRoutesModule,
|
|
5
|
+
VIRTUAL_MODULE_ID,
|
|
6
|
+
RESOLVED_VIRTUAL_MODULE_ID
|
|
7
|
+
} from "@ai-router/shared";
|
|
8
|
+
function aiRouter(options = {}) {
|
|
9
|
+
let root = process.cwd();
|
|
10
|
+
return {
|
|
11
|
+
name: "ai-router",
|
|
12
|
+
configResolved(config) {
|
|
13
|
+
root = config.root;
|
|
14
|
+
},
|
|
15
|
+
resolveId(id) {
|
|
16
|
+
if (id === VIRTUAL_MODULE_ID) {
|
|
17
|
+
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
load(id) {
|
|
21
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
22
|
+
const routes = scanRoutes(root, options);
|
|
23
|
+
return generateRoutesModule(routes);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
handleHotUpdate({ file, server }) {
|
|
27
|
+
if (options.dirs?.some((dir) => file.includes(dir))) {
|
|
28
|
+
const module = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
29
|
+
if (module) {
|
|
30
|
+
server.moduleGraph.invalidateModule(module);
|
|
31
|
+
server.ws.send({ type: "full-reload" });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
aiRouter
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Vite plugin for ai-router.\n *\n * Scans page directories at build time and exposes a `virtual:ai-router`\n * module that exports the generated route config array.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { aiRouter } from 'ai-router-plugin-vite';\n *\n * export default defineConfig({\n * plugins: [\n * aiRouter({ dirs: ['src/pages'] }),\n * ],\n * });\n * ```\n *\n * ```ts\n * // app.ts\n * import { routes } from 'virtual:ai-router';\n * import { SmartRouter } from 'ai-router';\n *\n * const router = new SmartRouter({ routes });\n * ```\n *\n * @module\n */\n\nimport type { Plugin } from 'vite';\nimport {\n scanRoutes,\n generateRoutesModule,\n VIRTUAL_MODULE_ID,\n RESOLVED_VIRTUAL_MODULE_ID,\n type PluginOptions,\n} from '@ai-router/shared';\n\nexport type { PluginOptions } from '@ai-router/shared';\n\n/**\n * Creates a Vite plugin that generates route config from the file system.\n *\n * The plugin provides a virtual module `virtual:ai-router` that exports\n * a `routes` array compatible with {@link SmartRouter}.\n *\n * Supports HMR — routes are re-scanned when files in `dirs` change.\n *\n * @param options - Directories to scan, file extensions, exclusions, and manual routes.\n * @returns Vite plugin instance.\n *\n * @example\n * ```ts\n * // Auto-scan + manual overrides\n * aiRouter({\n * dirs: ['src/pages'],\n * routes: [\n * { path: '/pricing', title: 'Pricing', description: 'cost, plans, billing' },\n * ],\n * });\n * ```\n */\nexport function aiRouter(options: PluginOptions = {}): Plugin {\n let root = process.cwd();\n\n return {\n name: 'ai-router',\n\n configResolved(config) {\n root = config.root;\n },\n\n resolveId(id) {\n if (id === VIRTUAL_MODULE_ID) {\n return RESOLVED_VIRTUAL_MODULE_ID;\n }\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_MODULE_ID) {\n const routes = scanRoutes(root, options);\n return generateRoutesModule(routes);\n }\n },\n\n handleHotUpdate({ file, server }) {\n if (options.dirs?.some((dir) => file.includes(dir))) {\n const module = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);\n if (module) {\n server.moduleGraph.invalidateModule(module);\n server.ws.send({ type: 'full-reload' });\n }\n }\n },\n };\n}\n"],"mappings":";AA8BA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA0BA,SAAS,SAAS,UAAyB,CAAC,GAAW;AAC5D,MAAI,OAAO,QAAQ,IAAI;AAEvB,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,eAAe,QAAQ;AACrB,aAAO,OAAO;AAAA,IAChB;AAAA,IAEA,UAAU,IAAI;AACZ,UAAI,OAAO,mBAAmB;AAC5B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,KAAK,IAAI;AACP,UAAI,OAAO,4BAA4B;AACrC,cAAM,SAAS,WAAW,MAAM,OAAO;AACvC,eAAO,qBAAqB,MAAM;AAAA,MACpC;AAAA,IACF;AAAA,IAEA,gBAAgB,EAAE,MAAM,OAAO,GAAG;AAChC,UAAI,QAAQ,MAAM,KAAK,CAAC,QAAQ,KAAK,SAAS,GAAG,CAAC,GAAG;AACnD,cAAM,SAAS,OAAO,YAAY,cAAc,0BAA0B;AAC1E,YAAI,QAAQ;AACV,iBAAO,YAAY,iBAAiB,MAAM;AAC1C,iBAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@van1s1mys/ai-router-plugin-vite",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vite plugin for ai-router — auto-scan pages and generate route config",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"dev": "tsup --watch"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"vite",
|
|
30
|
+
"vite-plugin",
|
|
31
|
+
"ai-router"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@ai-router/shared": "workspace:*"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"vite": ">=5.0.0"
|
|
39
|
+
}
|
|
40
|
+
}
|