@kimesh/kit 0.2.10 → 0.2.11-nightly.20260127015259

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -118,65 +118,65 @@ interface KimeshRouteMiddleware {
118
118
  type HookResult = void | Promise<void>;
119
119
  interface KimeshHooks {
120
120
  /** Called after config is loaded, before layers */
121
- "config:loaded": (config: KimeshConfig) => HookResult;
121
+ 'config:loaded': (config: KimeshConfig) => HookResult;
122
122
  /** Called after layers are resolved */
123
- "layers:resolved": (layers: ResolvedLayer$1[]) => HookResult;
123
+ 'layers:resolved': (layers: ResolvedLayer$1[]) => HookResult;
124
124
  /** Called to extend layer configuration */
125
- "layers:extend": (layers: ResolvedLayer$1[]) => HookResult;
125
+ 'layers:extend': (layers: ResolvedLayer$1[]) => HookResult;
126
126
  /** Called when Kimesh is fully initialized and ready */
127
127
  ready: (kimesh: Kimesh) => HookResult;
128
128
  /** Called before modules are processed */
129
- "modules:before": (kimesh: Kimesh) => HookResult;
129
+ 'modules:before': (kimesh: Kimesh) => HookResult;
130
130
  /** Called after all modules are processed */
131
- "modules:done": (kimesh: Kimesh) => HookResult;
131
+ 'modules:done': (kimesh: Kimesh) => HookResult;
132
132
  /** Called before build starts */
133
- "build:before": (kimesh: Kimesh) => HookResult;
133
+ 'build:before': (kimesh: Kimesh) => HookResult;
134
134
  /** Called after build completes */
135
- "build:done": (kimesh: Kimesh) => HookResult;
135
+ 'build:done': (kimesh: Kimesh) => HookResult;
136
136
  /** Called on build error */
137
- "build:error": (error: Error, kimesh: Kimesh) => HookResult;
137
+ 'build:error': (error: Error, kimesh: Kimesh) => HookResult;
138
138
  /** Called to extend Vite config before it's resolved */
139
- "vite:extend": (ctx: {
139
+ 'vite:extend': (ctx: {
140
140
  kimesh: Kimesh;
141
141
  config: vite0.UserConfig;
142
142
  }) => HookResult;
143
143
  /** Called after Vite config is resolved */
144
- "vite:configResolved": (config: ResolvedConfig, kimesh: Kimesh) => HookResult;
144
+ 'vite:configResolved': (config: ResolvedConfig, kimesh: Kimesh) => HookResult;
145
145
  /** Called when Vite dev server is created */
146
- "vite:serverCreated": (server: ViteDevServer, kimesh: Kimesh) => HookResult;
146
+ 'vite:serverCreated': (server: ViteDevServer, kimesh: Kimesh) => HookResult;
147
147
  /** Called to add import sources/presets */
148
- "imports:sources": (sources: Array<{
148
+ 'imports:sources': (sources: Array<{
149
149
  from: string;
150
150
  imports: string[];
151
151
  }>, kimesh: Kimesh) => HookResult;
152
152
  /** Called to extend imports */
153
- "imports:extend": (imports: KimeshImport[], kimesh: Kimesh) => HookResult;
153
+ 'imports:extend': (imports: KimeshImport[], kimesh: Kimesh) => HookResult;
154
154
  /** Called to add import directories */
155
- "imports:dirs": (dirs: KimeshImportsDir[], kimesh: Kimesh) => HookResult;
155
+ 'imports:dirs': (dirs: KimeshImportsDir[], kimesh: Kimesh) => HookResult;
156
156
  /** Called to add component directories */
157
- "components:dirs": (dirs: KimeshComponentsDir[], kimesh: Kimesh) => HookResult;
157
+ 'components:dirs': (dirs: KimeshComponentsDir[], kimesh: Kimesh) => HookResult;
158
158
  /** Called to extend components */
159
- "components:extend": (components: KimeshComponent[], kimesh: Kimesh) => HookResult;
159
+ 'components:extend': (components: KimeshComponent[], kimesh: Kimesh) => HookResult;
160
160
  /** Called to add component resolvers */
161
- "components:resolvers": (resolvers: ComponentResolver[], kimesh: Kimesh) => HookResult;
161
+ 'components:resolvers': (resolvers: ComponentResolver[], kimesh: Kimesh) => HookResult;
162
162
  /** Called after routes are generated */
163
- "routes:extend": (routes: KimeshRoute[], kimesh: Kimesh) => HookResult;
163
+ 'routes:extend': (routes: KimeshRoute[], kimesh: Kimesh) => HookResult;
164
164
  /** Called to add route middleware */
165
- "routes:middleware": (middleware: KimeshRouteMiddleware[], kimesh: Kimesh) => HookResult;
165
+ 'routes:middleware': (middleware: KimeshRouteMiddleware[], kimesh: Kimesh) => HookResult;
166
166
  /** Called when templates need generation */
167
- "templates:extend": (templates: KimeshTemplate[], kimesh: Kimesh) => HookResult;
167
+ 'templates:extend': (templates: KimeshTemplate[], kimesh: Kimesh) => HookResult;
168
168
  /** Called after templates are written */
169
- "templates:done": (templates: KimeshTemplate[], kimesh: Kimesh) => HookResult;
169
+ 'templates:done': (templates: KimeshTemplate[], kimesh: Kimesh) => HookResult;
170
170
  /** Called to extend type templates */
171
- "types:extend": (typeTemplates: KimeshTypeTemplate[], kimesh: Kimesh) => HookResult;
171
+ 'types:extend': (typeTemplates: KimeshTypeTemplate[], kimesh: Kimesh) => HookResult;
172
172
  /** Called after types are generated */
173
- "types:done": (files: string[], kimesh: Kimesh) => HookResult;
173
+ 'types:done': (files: string[], kimesh: Kimesh) => HookResult;
174
174
  /** Called on file change in watch mode */
175
- "watch:change": (file: string, event: "add" | "change" | "unlink", kimesh: Kimesh) => HookResult;
175
+ 'watch:change': (file: string, event: 'add' | 'change' | 'unlink', kimesh: Kimesh) => HookResult;
176
176
  /** Called before HMR update */
177
- "hmr:before": (file: string, kimesh: Kimesh) => HookResult;
177
+ 'hmr:before': (file: string, kimesh: Kimesh) => HookResult;
178
178
  /** Called after HMR update */
179
- "hmr:after": (file: string, kimesh: Kimesh) => HookResult;
179
+ 'hmr:after': (file: string, kimesh: Kimesh) => HookResult;
180
180
  /** Called when Kimesh is closing */
181
181
  close: (kimesh: Kimesh) => HookResult;
182
182
  }
@@ -187,7 +187,7 @@ interface KimeshHooks {
187
187
  */
188
188
  interface KimeshRuntimePluginMeta {
189
189
  name?: string;
190
- enforce?: "pre" | "default" | "post";
190
+ enforce?: 'pre' | 'default' | 'post';
191
191
  order?: number;
192
192
  dependsOn?: string[];
193
193
  parallel?: boolean;
@@ -196,22 +196,22 @@ interface KimeshRuntimePluginMeta {
196
196
  * Runtime hooks available in Kimesh app lifecycle
197
197
  */
198
198
  interface KimeshRuntimeHooks {
199
- "app:created": (app: App) => void | Promise<void>;
200
- "app:beforeMount": (app: App) => void | Promise<void>;
201
- "app:mounted": (app: App) => void | Promise<void>;
202
- "app:error": (err: unknown) => void | Promise<void>;
203
- "page:start": () => void | Promise<void>;
204
- "page:finish": () => void | Promise<void>;
205
- "navigate:before": (context: {
199
+ 'app:created': (app: App) => void | Promise<void>;
200
+ 'app:beforeMount': (app: App) => void | Promise<void>;
201
+ 'app:mounted': (app: App) => void | Promise<void>;
202
+ 'app:error': (err: unknown) => void | Promise<void>;
203
+ 'page:start': () => void | Promise<void>;
204
+ 'page:finish': () => void | Promise<void>;
205
+ 'navigate:before': (context: {
206
206
  to: unknown;
207
207
  from: unknown;
208
208
  }) => void | false | Promise<void | false>;
209
- "navigate:after": (context: {
209
+ 'navigate:after': (context: {
210
210
  to: unknown;
211
211
  from: unknown;
212
212
  failure?: unknown;
213
213
  }) => void | Promise<void>;
214
- "navigate:error": (context: {
214
+ 'navigate:error': (context: {
215
215
  error: Error;
216
216
  to: unknown;
217
217
  from: unknown;
@@ -309,7 +309,7 @@ interface KimeshVitePluginEntry {
309
309
  /** The Vite plugin */
310
310
  plugin: Plugin;
311
311
  /** Plugin enforce order */
312
- enforce?: "pre" | "post";
312
+ enforce?: 'pre' | 'post';
313
313
  /** Numeric order (lower = earlier) */
314
314
  order?: number;
315
315
  /** Metadata for debugging */
@@ -488,7 +488,7 @@ interface LayersConfig {
488
488
  /** Directories to scan for layers (default: ['layers']) */
489
489
  dirs?: string[];
490
490
  /** Layers to enable - 'all' | 'none' | string[] */
491
- enabled?: "all" | "none" | string[];
491
+ enabled?: 'all' | 'none' | string[];
492
492
  /** Layers to exclude */
493
493
  excluded?: string[];
494
494
  }
@@ -527,7 +527,7 @@ interface ComponentsConfig {
527
527
  /**
528
528
  * Vite configuration options for Kimesh.
529
529
  */
530
- interface KimeshViteConfig extends Omit<UserConfig, "root" | "configFile"> {
530
+ interface KimeshViteConfig extends Omit<UserConfig, 'root' | 'configFile'> {
531
531
  /**
532
532
  * Additional Vite plugins.
533
533
  * These are merged AFTER Kimesh's internal plugins.
@@ -739,7 +739,7 @@ interface BuildConfig {
739
739
  *
740
740
  * @default false
741
741
  */
742
- sourcemap?: boolean | "hidden" | "inline";
742
+ sourcemap?: boolean | 'hidden' | 'inline';
743
743
  /**
744
744
  * Build target for esbuild/terser.
745
745
  * Specifies the JS language version to target.
@@ -756,7 +756,7 @@ interface BuildConfig {
756
756
  *
757
757
  * @default 'esbuild'
758
758
  */
759
- minify?: boolean | "esbuild" | "terser";
759
+ minify?: boolean | 'esbuild' | 'terser';
760
760
  }
761
761
  /**
762
762
  * HTTPS configuration options for dev server.
@@ -925,7 +925,7 @@ interface TypeScriptConfig {
925
925
  *
926
926
  * @default false
927
927
  */
928
- typeCheck?: boolean | "build";
928
+ typeCheck?: boolean | 'build';
929
929
  /**
930
930
  * Additional tsconfig compiler options to merge with generated config.
931
931
  * These options will extend the auto-generated `.kimesh/tsconfig.json`.
@@ -1343,7 +1343,7 @@ interface KimeshConfig extends KimeshModuleOptions {
1343
1343
  /** Router configuration */
1344
1344
  router?: {
1345
1345
  /** Routes directory relative to srcDir (default: 'routes') */routesDir?: string; /** Import mode for route components */
1346
- importMode?: "async" | "sync";
1346
+ importMode?: 'async' | 'sync';
1347
1347
  };
1348
1348
  /** Extend from other layers (paths or package names) */
1349
1349
  extends?: Array<string | {
@@ -1503,7 +1503,7 @@ declare function defineKimeshPlugin(definition: KimeshPluginDefinition): KimeshP
1503
1503
  //#region src/kit/vite.d.ts
1504
1504
  interface AddVitePluginOptions {
1505
1505
  /** Plugin enforce order */
1506
- enforce?: "pre" | "post";
1506
+ enforce?: 'pre' | 'post';
1507
1507
  /** Numeric order (lower = earlier) */
1508
1508
  order?: number;
1509
1509
  /** Add to beginning of plugins array */
@@ -1801,6 +1801,10 @@ interface InternalAliasConfig {
1801
1801
  *
1802
1802
  * Each entry maps an internal alias (#kimesh/...) to the actual internal
1803
1803
  * package subpath export (@kimesh/...) that should be resolved and re-exported.
1804
+ *
1805
+ * Note: #kimesh/middleware/plugin is NOT included here because it's generated
1806
+ * dynamically by the kit plugin (middleware-plugin.mjs) using createMiddlewarePlugin
1807
+ * with the scanned middleware registry. This avoids virtual module import issues.
1804
1808
  */
1805
1809
  declare const INTERNAL_ALIASES: InternalAliasConfig[];
1806
1810
  /**
@@ -2224,11 +2228,11 @@ interface HMRContext {
2224
2228
  /** File that changed */
2225
2229
  file: string;
2226
2230
  /** Type of change */
2227
- type: "add" | "change" | "unlink";
2231
+ type: 'add' | 'change' | 'unlink';
2228
2232
  /** Layer this file belongs to (if any) */
2229
2233
  layer?: ResolvedLayer$1;
2230
2234
  /** Category of the file */
2231
- category: "route" | "component" | "composable" | "config" | "other";
2235
+ category: 'route' | 'component' | 'composable' | 'config' | 'other';
2232
2236
  }
2233
2237
  /**
2234
2238
  * Create HMR watcher for Kimesh layers
@@ -2275,7 +2279,7 @@ declare function formatWarning(message: string, context?: ErrorContext): string;
2275
2279
  /**
2276
2280
  * Format a conflict warning
2277
2281
  */
2278
- declare function formatConflictWarning(type: "route" | "import" | "component", name: string, sources: Array<{
2282
+ declare function formatConflictWarning(type: 'route' | 'import' | 'component', name: string, sources: Array<{
2279
2283
  layer: string;
2280
2284
  path: string;
2281
2285
  }>, winner: string): string;
@@ -2296,7 +2300,7 @@ interface KimeshPluginOptions {
2296
2300
  config?: KimeshConfig;
2297
2301
  /** Layer configuration (from CLI) */
2298
2302
  layers?: {
2299
- /** Enabled layers */enabled?: "all" | "none" | string[]; /** Excluded layers */
2303
+ /** Enabled layers */enabled?: 'all' | 'none' | string[]; /** Excluded layers */
2300
2304
  excluded?: string[];
2301
2305
  };
2302
2306
  /** Enable debug logging */
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { createHooks } from "hookable";
3
3
  import { snakeCase } from "scule";
4
4
  import { klona } from "klona/json";
5
5
  import destr from "destr";
6
- import { pathToFileURL } from "node:url";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import consola from "consola";
8
8
  import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
9
9
  import { dirname, isAbsolute, join, resolve } from "node:path";
@@ -1032,7 +1032,14 @@ function generatePluginsTemplate(options) {
1032
1032
  imports.push("// Module-registered plugins");
1033
1033
  for (const plugin of pluginsWithSrc) {
1034
1034
  const varName = toVariableName(plugin.name || "module", index);
1035
- const importPath = plugin.src.startsWith("@") || plugin.src.startsWith(".") || plugin.src.startsWith("#") || plugin.src.startsWith("kimesh/") ? plugin.src : relative(buildDir, plugin.src).replace(/\.ts$/, "");
1035
+ const isPackageOrAliasPath = plugin.src.startsWith("@") || plugin.src.startsWith(".") || plugin.src.startsWith("#") || plugin.src.startsWith("kimesh/");
1036
+ let importPath;
1037
+ if (isPackageOrAliasPath) importPath = plugin.src;
1038
+ else {
1039
+ let relativePath = relative(buildDir, plugin.src).replace(/\.ts$/, "");
1040
+ if (!relativePath.startsWith(".") && !relativePath.startsWith("/")) relativePath = "./" + relativePath;
1041
+ importPath = relativePath;
1042
+ }
1036
1043
  imports.push(`import ${varName} from '${importPath}'`);
1037
1044
  pluginVars.push(varName);
1038
1045
  index++;
@@ -1102,24 +1109,20 @@ function addPluginsTemplate(kimesh, discoveredPlugins) {
1102
1109
  *
1103
1110
  * Each entry maps an internal alias (#kimesh/...) to the actual internal
1104
1111
  * package subpath export (@kimesh/...) that should be resolved and re-exported.
1112
+ *
1113
+ * Note: #kimesh/middleware/plugin is NOT included here because it's generated
1114
+ * dynamically by the kit plugin (middleware-plugin.mjs) using createMiddlewarePlugin
1115
+ * with the scanned middleware registry. This avoids virtual module import issues.
1105
1116
  */
1106
- const INTERNAL_ALIASES = [
1107
- {
1108
- alias: "#kimesh/head/plugin",
1109
- packageSpecifier: "@kimesh/head/plugin",
1110
- filename: "head-plugin.mjs"
1111
- },
1112
- {
1113
- alias: "#kimesh/router-runtime/default-app",
1114
- packageSpecifier: "@kimesh/router-runtime/default-app",
1115
- filename: "router-runtime-default-app.mjs"
1116
- },
1117
- {
1118
- alias: "#kimesh/middleware/plugin",
1119
- packageSpecifier: "@kimesh/router-runtime/middleware/plugin",
1120
- filename: "middleware-plugin.mjs"
1121
- }
1122
- ];
1117
+ const INTERNAL_ALIASES = [{
1118
+ alias: "#kimesh/head/plugin",
1119
+ packageSpecifier: "@kimesh/head/plugin",
1120
+ filename: "head-plugin.mjs"
1121
+ }, {
1122
+ alias: "#kimesh/router-runtime/default-app",
1123
+ packageSpecifier: "@kimesh/router-runtime/default-app",
1124
+ filename: "router-runtime-default-app.mjs"
1125
+ }];
1123
1126
  /**
1124
1127
  * Resolve a package specifier to an absolute file path.
1125
1128
  * This uses exsolve/createRequire to find the package from @kimesh/kit's location.
@@ -1243,6 +1246,7 @@ function defineKmConfig(config) {
1243
1246
  *
1244
1247
  * Utilities for resolving and processing path aliases.
1245
1248
  */
1249
+ const __kitDir = dirname(dirname(fileURLToPath(import.meta.url)));
1246
1250
  /**
1247
1251
  * Resolve an alias path template to an actual path
1248
1252
  *
@@ -1327,6 +1331,38 @@ function isDebugEnabled(debug, option) {
1327
1331
  if (debug === true) return true;
1328
1332
  return !!debug[option];
1329
1333
  }
1334
+ /**
1335
+ * Resolve the actual directory path of an npm package.
1336
+ * Handles different package manager setups (npm hoists, pnpm isolates, workspace links).
1337
+ *
1338
+ * @param packageName - The npm package name (e.g., "@kimesh/router-runtime")
1339
+ * @param _fromDir - Deprecated, no longer used. Resolution is done from @kimesh/kit's location.
1340
+ * @returns The absolute path to the package directory, or null if not found
1341
+ *
1342
+ * @example
1343
+ * ```ts
1344
+ * const pkgDir = resolvePackageDir("@kimesh/router-runtime", "/path/to/project");
1345
+ * // Returns: "/path/to/project/node_modules/.pnpm/@kimesh+router-runtime@0.2.11/node_modules/@kimesh/router-runtime"
1346
+ * // or: "/path/to/monorepo/packages/router-runtime" (for workspace links)
1347
+ * ```
1348
+ */
1349
+ function resolvePackageDir(packageName, _fromDir) {
1350
+ try {
1351
+ const resolvedPath = resolveModulePath(packageName, { from: __kitDir });
1352
+ const pkgNameParts = packageName.split("/");
1353
+ const pkgPattern = pkgNameParts.length === 2 ? `node_modules/${pkgNameParts[0]}/${pkgNameParts[1]}` : `node_modules/${packageName}`;
1354
+ const patternIndex = resolvedPath.indexOf(pkgPattern);
1355
+ if (patternIndex !== -1) return resolvedPath.slice(0, patternIndex + pkgPattern.length);
1356
+ let currentDir = dirname(resolvedPath);
1357
+ for (let i = 0; i < 5; i++) {
1358
+ if ((currentDir.split("/").pop() || "") === pkgNameParts[pkgNameParts.length - 1]) return currentDir;
1359
+ currentDir = dirname(currentDir);
1360
+ }
1361
+ return dirname(dirname(resolvedPath));
1362
+ } catch {
1363
+ return null;
1364
+ }
1365
+ }
1330
1366
 
1331
1367
  //#endregion
1332
1368
  //#region src/kit/ignore-utils.ts
@@ -1659,7 +1695,7 @@ function debugTable(title, data) {
1659
1695
  * @returns TSConfig JSON object
1660
1696
  */
1661
1697
  function generateTsConfig(options) {
1662
- const { rootDir, srcDir, buildDir, aliases, layerAliases = {}, moduleAliases = {}, internalAliases = {}, include = ["../src/**/*", "./**/*"] } = options;
1698
+ const { rootDir, buildDir, aliases, layerAliases = {}, moduleAliases = {}, internalAliases = {}, include = ["../src/**/*", "./**/*"] } = options;
1663
1699
  const allAliases = {
1664
1700
  ...aliases,
1665
1701
  ...layerAliases,
@@ -1680,8 +1716,16 @@ function generateTsConfig(options) {
1680
1716
  "@kimesh/head",
1681
1717
  "@kimesh/query"
1682
1718
  ]) {
1683
- paths[pkg] = [`../node_modules/${pkg}`];
1684
- paths[`${pkg}/*`] = [`../node_modules/${pkg}/*`];
1719
+ const pkgDir = resolvePackageDir(pkg, rootDir);
1720
+ if (pkgDir) {
1721
+ const relativePkgPath = relative(buildDir, pkgDir);
1722
+ const normalizedPath = relativePkgPath.startsWith("..") ? relativePkgPath : "./" + relativePkgPath;
1723
+ paths[pkg] = [normalizedPath];
1724
+ paths[`${pkg}/*`] = [`${normalizedPath}/*`];
1725
+ } else {
1726
+ paths[pkg] = [`../node_modules/${pkg}`];
1727
+ paths[`${pkg}/*`] = [`../node_modules/${pkg}/*`];
1728
+ }
1685
1729
  }
1686
1730
  return {
1687
1731
  compilerOptions: {
@@ -2641,7 +2685,7 @@ function extractModuleNames$1(modules) {
2641
2685
  * Generate modules.ts that imports all configured modules
2642
2686
  * AND references their augment.d.ts files for type declarations
2643
2687
  */
2644
- function generateModulesTypeDeclaration(modules, buildDir) {
2688
+ function generateModulesTypeDeclaration(modules, buildDir, rootDir) {
2645
2689
  const moduleNames = extractModuleNames$1(modules);
2646
2690
  if (moduleNames.length === 0) return;
2647
2691
  const imports = moduleNames.map((name) => `import "${name}";`).join("\n");
@@ -2652,7 +2696,14 @@ function generateModulesTypeDeclaration(modules, buildDir) {
2652
2696
  * DO NOT EDIT - This file is regenerated when modules change.
2653
2697
  */
2654
2698
 
2655
- ${moduleNames.map((name) => `/// <reference path="../node_modules/${name}/augment.d.ts" />`).join("\n")}
2699
+ ${moduleNames.map((name) => {
2700
+ const pkgDir = resolvePackageDir(name, rootDir);
2701
+ if (pkgDir) {
2702
+ const relativePath = relative(buildDir, pkgDir);
2703
+ return `/// <reference path="${relativePath.startsWith("..") ? relativePath : "./" + relativePath}/augment.d.ts" />`;
2704
+ }
2705
+ return `/// <reference path="../node_modules/${name}/augment.d.ts" />`;
2706
+ }).join("\n")}
2656
2707
 
2657
2708
  ${imports}
2658
2709
  `;
@@ -2794,9 +2845,22 @@ function kimeshPlugin(options = {}) {
2794
2845
  writeFileSync(registryPath, registryCode, "utf-8");
2795
2846
  const typesCode = generateMiddlewareTypes(middlewareResult);
2796
2847
  writeFileSync(join$1(resolvedDirs.buildDir, "middleware.d.ts"), typesCode, "utf-8");
2848
+ writeFileSync(join$1(resolvedDirs.buildDir, "middleware-plugin.mjs"), `/**
2849
+ * Kimesh Middleware Plugin - Auto-generated
2850
+ * DO NOT EDIT - This file is regenerated when middleware files change
2851
+ */
2852
+
2853
+ import { createMiddlewarePlugin } from '@kimesh/router-runtime'
2854
+ import { globalMiddleware, namedMiddleware } from './middleware.gen'
2855
+
2856
+ export default createMiddlewarePlugin({
2857
+ globalMiddleware,
2858
+ namedMiddleware,
2859
+ })
2860
+ `, "utf-8");
2797
2861
  if (debug) consola.info(`[Kimesh] Middleware: ${middlewareResult.globalMiddleware.length} global, ${middlewareResult.namedMiddleware.length} named`);
2798
- const middlewarePluginSrc = "#kimesh/middleware/plugin";
2799
- if (!state.kimesh._registries.runtimePlugins.some((p) => p.src === middlewarePluginSrc)) {
2862
+ const middlewarePluginSrc = join$1(resolvedDirs.buildDir, "middleware-plugin.mjs");
2863
+ if (!state.kimesh._registries.runtimePlugins.some((p) => p.name === "middleware")) {
2800
2864
  state.kimesh._registries.runtimePlugins.push({
2801
2865
  src: middlewarePluginSrc,
2802
2866
  name: "middleware"
@@ -2807,7 +2871,7 @@ function kimeshPlugin(options = {}) {
2807
2871
  } catch (error) {
2808
2872
  if (debug) consola.warn(`[Kimesh] Middleware scanning failed:`, error);
2809
2873
  }
2810
- generateModulesTypeDeclaration(config.modules, state.generatedDir);
2874
+ generateModulesTypeDeclaration(config.modules, state.generatedDir, configRoot);
2811
2875
  await writeTemplates(state.kimesh);
2812
2876
  const userAliases = buildAliases(config, resolvedDirs.srcDir, configRoot);
2813
2877
  const kimeshPackageAliases = buildKimeshPackageAliases(configRoot, debug);
@@ -2896,7 +2960,14 @@ function kimeshPlugin(options = {}) {
2896
2960
  sourcemap: resolvedBuildConfig.sourcemap,
2897
2961
  minify: resolvedBuildConfig.minify,
2898
2962
  rollupOptions: command === "build" ? { input: join$1(resolvedDirs.buildDir, "index.html") } : void 0
2899
- }
2963
+ },
2964
+ optimizeDeps: { exclude: [
2965
+ "#kimesh/routes",
2966
+ "#kimesh/app",
2967
+ "#kimesh/context",
2968
+ "#kimesh/plugins",
2969
+ "#kimesh/middleware"
2970
+ ] }
2900
2971
  }, userViteOptions);
2901
2972
  },
2902
2973
  configResolved(resolvedConfig) {
@@ -3293,7 +3364,14 @@ export default []
3293
3364
  * DO NOT EDIT - This file is regenerated when modules change.
3294
3365
  */
3295
3366
 
3296
- ${moduleNames.map((name) => `/// <reference path="../node_modules/${name}/augment.d.ts" />`).join("\n")}
3367
+ ${moduleNames.map((name) => {
3368
+ const pkgDir = resolvePackageDir(name, root);
3369
+ if (pkgDir) {
3370
+ const relativePath = relative(buildDir, pkgDir);
3371
+ return `/// <reference path="${relativePath.startsWith("..") ? relativePath : "./" + relativePath}/augment.d.ts" />`;
3372
+ }
3373
+ return `/// <reference path="../node_modules/${name}/augment.d.ts" />`;
3374
+ }).join("\n")}
3297
3375
 
3298
3376
  ${imports}
3299
3377
  `, "utf-8");
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@kimesh/kit",
3
- "version": "0.2.10",
3
+ "version": "0.2.11-nightly.20260127015259",
4
4
  "description": "Build-time engine for Kimesh framework",
5
- "type": "module",
6
5
  "repository": {
7
6
  "type": "git",
8
7
  "url": "https://github.com/kimeshjs/kimesh.git"
9
8
  },
9
+ "files": [
10
+ "dist",
11
+ "types.d.ts"
12
+ ],
13
+ "type": "module",
14
+ "main": "./dist/index.mjs",
15
+ "types": "./types.d.ts",
10
16
  "exports": {
11
17
  ".": {
12
18
  "types": "./types.d.ts",
13
19
  "import": "./dist/index.mjs"
14
20
  }
15
21
  },
16
- "main": "./dist/index.mjs",
17
- "types": "./types.d.ts",
18
- "files": [
19
- "dist",
20
- "types.d.ts"
21
- ],
22
22
  "scripts": {
23
23
  "build": "tsdown",
24
24
  "dev": "tsdown --watch",
@@ -26,14 +26,10 @@
26
26
  "test": "vitest run",
27
27
  "test:watch": "vitest"
28
28
  },
29
- "peerDependencies": {
30
- "vite": "^8.0.0-beta.8",
31
- "vue": "^3.5.0"
32
- },
33
29
  "dependencies": {
34
- "@kimesh/auto-import": "0.2.10",
35
- "@kimesh/layers": "0.2.10",
36
- "@kimesh/router-generator": "0.2.10",
30
+ "@kimesh/auto-import": "workspace:*",
31
+ "@kimesh/layers": "workspace:*",
32
+ "@kimesh/router-generator": "workspace:*",
37
33
  "@vitejs/plugin-vue": "^6.0.3",
38
34
  "c12": "^3.3.3",
39
35
  "consola": "^3.4.2",
@@ -55,5 +51,9 @@
55
51
  "unplugin-vue-components": "^31.0.0",
56
52
  "vite": "^8.0.0-beta.8",
57
53
  "vue": "^3.5.26"
54
+ },
55
+ "peerDependencies": {
56
+ "vite": "^8.0.0-beta.8",
57
+ "vue": "^3.5.0"
58
58
  }
59
59
  }
package/types.d.ts CHANGED
@@ -5,14 +5,14 @@
5
5
  * Similar to Nuxt's types.d.ts, this allows using defineKmConfig without imports.
6
6
  */
7
7
 
8
- import type { KimeshConfig } from "./dist/index.mjs";
8
+ import type { KimeshConfig } from './dist/index.mjs'
9
9
 
10
- export * from "./dist/index.mjs";
10
+ export * from './dist/index.mjs'
11
11
 
12
12
  /**
13
13
  * Function type for defineKmConfig
14
14
  */
15
- type DefineKmConfig = (config: KimeshConfig) => KimeshConfig;
15
+ type DefineKmConfig = (config: KimeshConfig) => KimeshConfig
16
16
 
17
17
  declare global {
18
18
  /**
@@ -29,5 +29,5 @@ declare global {
29
29
  * })
30
30
  * ```
31
31
  */
32
- const defineKmConfig: DefineKmConfig;
32
+ const defineKmConfig: DefineKmConfig
33
33
  }