@kimesh/auto-import 0.2.8 → 0.2.9

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.
@@ -375,9 +375,29 @@ const kimeshPreset = {
375
375
  "useParams",
376
376
  "useReactiveParams",
377
377
  "useSearch",
378
+ "useRuntimeConfig",
378
379
  "KmOutlet",
379
380
  "KmLink",
380
- "KmDeferred"
381
+ "KmDeferred",
382
+ "defineKimeshMiddleware",
383
+ "navigateTo",
384
+ "abortNavigation",
385
+ {
386
+ name: "RouteMiddleware",
387
+ type: true
388
+ },
389
+ {
390
+ name: "MiddlewareContext",
391
+ type: true
392
+ },
393
+ {
394
+ name: "MiddlewareResult",
395
+ type: true
396
+ },
397
+ {
398
+ name: "NavigationRedirect",
399
+ type: true
400
+ }
381
401
  ]
382
402
  };
383
403
  /**
@@ -0,0 +1,4 @@
1
+ import "./oxc-scanner-tiRVQcUS.mjs";
2
+ import { t as RegistryBuilder } from "./builder-DR3SkMBz.mjs";
3
+
4
+ export { RegistryBuilder };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as OxcExportScanner } from "./oxc-scanner-tiRVQcUS.mjs";
2
- import { a as piniaPreset, c as vuePreset, d as collectExistingDirectories, i as normalizePreset, l as vueRouterPreset, n as builtinPresets, o as resolvePresets, r as kimeshPreset, s as tanstackQueryPreset, t as RegistryBuilder, u as ConflictResolver } from "./builder-Do3z5o7Q.mjs";
2
+ import { a as piniaPreset, c as vuePreset, d as collectExistingDirectories, i as normalizePreset, l as vueRouterPreset, n as builtinPresets, o as resolvePresets, r as kimeshPreset, s as tanstackQueryPreset, t as RegistryBuilder, u as ConflictResolver } from "./builder-DR3SkMBz.mjs";
3
3
  import { parseSync } from "oxc-parser";
4
4
  import { parse } from "@vue/compiler-sfc";
5
5
  import * as fs from "node:fs";
@@ -462,7 +462,6 @@ function generateAutoImportsDts(registry) {
462
462
  const header = [
463
463
  "/* eslint-disable */",
464
464
  "/* prettier-ignore */",
465
- "// @ts-nocheck",
466
465
  "// noinspection JSUnusedGlobalSymbols",
467
466
  "",
468
467
  "// Auto-generated by @kimesh/auto-import",
@@ -490,8 +489,11 @@ function generateAutoImportsDts(registry) {
490
489
  "}"
491
490
  ].join("\n");
492
491
  }
492
+ const SPECIAL_FUNCTION_DECLARATIONS = { defineKimeshMiddleware: ` function defineKimeshMiddleware(middleware: import('@kimesh/router-runtime').RouteMiddleware): import('@kimesh/router-runtime').RouteMiddleware
493
+ function defineKimeshMiddleware(definition: import('@kimesh/router-runtime').MiddlewareDefinition): import('@kimesh/router-runtime').RouteMiddleware` };
493
494
  function formatGlobalDeclaration(entry) {
494
495
  const comment = entry.layer !== "app" ? ` // from ${entry.layer}` : "";
496
+ if (SPECIAL_FUNCTION_DECLARATIONS[entry.name]) return SPECIAL_FUNCTION_DECLARATIONS[entry.name];
495
497
  if (entry.isType) return ` type ${entry.name} = import('${entry.from}').${entry.name}${comment}`;
496
498
  if (entry.isDefault) return ` const ${entry.name}: typeof import('${entry.from}').default${comment}`;
497
499
  return ` const ${entry.name}: typeof import('${entry.from}').${entry.name}${comment}`;
@@ -592,6 +594,7 @@ const DEFAULT_INCLUDE = [
592
594
  /\.vue\?vue/
593
595
  ];
594
596
  const DEFAULT_EXCLUDE = [/node_modules/, /\.d\.ts$/];
597
+ const MIDDLEWARE_INCLUDE = /[\\/]middleware[\\/].*\.[jt]sx?$/;
595
598
  function debounce(fn, ms) {
596
599
  let timeoutId = null;
597
600
  return ((...args) => {
@@ -651,6 +654,15 @@ function createScriptPlugin(options) {
651
654
  const elapsed = performance.now() - startTime;
652
655
  logger$1.debug(`Script auto-import registry built in ${elapsed.toFixed(1)}ms`);
653
656
  logger$1.debug(` ${registry.stats.composablesCount} composables, ${registry.stats.utilitiesCount} utilities, ${registry.stats.presetsCount} preset imports`);
657
+ if (debug && registry) {
658
+ const reg = registry;
659
+ const helperStatus = [
660
+ "defineKimeshMiddleware",
661
+ "navigateTo",
662
+ "abortNavigation"
663
+ ].map((name) => `${name}=${reg.imports.has(name)}`).join(", ");
664
+ logger$1.debug(`Middleware helper auto-imports: ${helperStatus}`);
665
+ }
654
666
  if (registry.conflicts.length > 0) logger$1.warn(` ${registry.conflicts.length} auto-import conflicts detected`);
655
667
  await generateDtsForLayers(registry);
656
668
  onRegistryUpdate?.(registry);
@@ -718,10 +730,16 @@ function createScriptPlugin(options) {
718
730
  },
719
731
  transform(code, id) {
720
732
  if (!registry) return null;
721
- if (!shouldTransform(id, include, exclude)) return null;
733
+ const isMiddlewarePath = MIDDLEWARE_INCLUDE.test(id);
734
+ if (!shouldTransform(id, include, exclude) && !isMiddlewarePath) return null;
722
735
  const startTime = performance.now();
723
736
  const isVue = id.endsWith(".vue") || id.includes(".vue?");
737
+ const isMiddlewareFile = id.includes(`${path.sep}middleware${path.sep}`);
724
738
  const refs = isVue ? detector.detectInVue(code, id) : detector.detectInScript(code, id);
739
+ if (debug && isMiddlewareFile) {
740
+ const names = refs.map((ref) => ref.name).join(", ");
741
+ logger$1.debug(`[middleware] refs in ${id}: ${names}`);
742
+ }
725
743
  if (refs.length === 0) return null;
726
744
  const existingImports = injector.extractExistingImports(code, isVue);
727
745
  const imports = [];
@@ -739,6 +757,10 @@ function createScriptPlugin(options) {
739
757
  imports.push(entry);
740
758
  matched.add(ref.name);
741
759
  }
760
+ if (debug && isMiddlewareFile) {
761
+ const injected = imports.map((entry) => entry.name).join(", ");
762
+ logger$1.debug(`[middleware] imports in ${id}: ${injected}`);
763
+ }
742
764
  if (imports.length === 0) return null;
743
765
  const result = injector.inject(code, imports, isVue);
744
766
  if (!result) return null;
@@ -945,7 +967,7 @@ var plugin_default = autoImportPlugin;
945
967
  * Build import registry from sources (convenience function)
946
968
  */
947
969
  async function buildImportRegistry(sources) {
948
- const { RegistryBuilder } = await import("./builder-Ci3XAFwH.mjs");
970
+ const { RegistryBuilder } = await import("./builder-t33LltiO.mjs");
949
971
  return new RegistryBuilder().build(sources);
950
972
  }
951
973
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimesh/auto-import",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "OXC-powered auto-import system for Kimesh framework with layer support",
5
5
  "type": "module",
6
6
  "repository": {
@@ -1,4 +0,0 @@
1
- import "./oxc-scanner-tiRVQcUS.mjs";
2
- import { t as RegistryBuilder } from "./builder-Do3z5o7Q.mjs";
3
-
4
- export { RegistryBuilder };