@kimesh/kit 0.2.31 → 0.2.32-nightly.20260129013552
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 +9 -6
- package/dist/index.mjs +48 -8
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hookable } from "hookable";
|
|
2
2
|
import { Ignore } from "ignore";
|
|
3
|
-
import * as
|
|
3
|
+
import * as vite3 from "vite";
|
|
4
4
|
import { Plugin, Plugin as VitePlugin, PluginOption, PluginOption as VitePluginOption, ResolvedConfig, UserConfig, ViteDevServer } from "vite";
|
|
5
5
|
import { KimeshLayerConfig, LayerAutoImportConfig, LayerComponentConfig, LayerComposableConfig, LayerRouteConfig, ResolvedLayer, ResolvedLayer as ResolvedLayer$1, generateLayerAliases, mergeLayerConfigs, prepareLayers, resolveLayers } from "@kimesh/layers";
|
|
6
6
|
import { AutoImportConfig, ImportPreset, LayerAutoImportSource as ImportSource, buildImportRegistry, generateDts, kimeshAutoImport, scanExports } from "@kimesh/auto-import";
|
|
@@ -158,7 +158,7 @@ interface KimeshHooks {
|
|
|
158
158
|
/** Called to extend Vite config before it's resolved */
|
|
159
159
|
'vite:extend': (ctx: {
|
|
160
160
|
kimesh: Kimesh;
|
|
161
|
-
config:
|
|
161
|
+
config: vite3.UserConfig;
|
|
162
162
|
}) => HookResult;
|
|
163
163
|
/** Called after Vite config is resolved */
|
|
164
164
|
'vite:configResolved': (config: ResolvedConfig, kimesh: Kimesh) => HookResult;
|
|
@@ -523,7 +523,7 @@ interface KimeshPluginDefinition {
|
|
|
523
523
|
* Setup function that returns Vite plugin(s)
|
|
524
524
|
* @param kimesh - Kimesh context
|
|
525
525
|
*/
|
|
526
|
-
setup: (kimesh: Kimesh) =>
|
|
526
|
+
setup: (kimesh: Kimesh) => vite3.PluginOption | vite3.PluginOption[];
|
|
527
527
|
}
|
|
528
528
|
interface KimeshPlugin {
|
|
529
529
|
/** Plugin definition */
|
|
@@ -531,7 +531,7 @@ interface KimeshPlugin {
|
|
|
531
531
|
/** Plugin name */
|
|
532
532
|
name: string;
|
|
533
533
|
/** Get Vite plugins */
|
|
534
|
-
getPlugins: (kimesh: Kimesh) =>
|
|
534
|
+
getPlugins: (kimesh: Kimesh) => vite3.PluginOption[];
|
|
535
535
|
}
|
|
536
536
|
//#endregion
|
|
537
537
|
//#region src/types/config.d.ts
|
|
@@ -1635,10 +1635,13 @@ declare function addBuildPlugin(plugin: Plugin | Plugin[], options?: AddVitePlug
|
|
|
1635
1635
|
/**
|
|
1636
1636
|
* Add an alias
|
|
1637
1637
|
*
|
|
1638
|
+
* Note: '@' and '~' aliases are context-aware and handled by layerAliasPlugin
|
|
1639
|
+
* for files within layers. For module/package internal use, they work as expected.
|
|
1640
|
+
*
|
|
1638
1641
|
* @example
|
|
1639
1642
|
* ```ts
|
|
1640
1643
|
* addAlias("#my-module", "/path/to/module");
|
|
1641
|
-
* addAlias("
|
|
1644
|
+
* addAlias("@", "./src"); // For module internal use
|
|
1642
1645
|
* ```
|
|
1643
1646
|
*/
|
|
1644
1647
|
declare function addAlias(find: string | RegExp, replacement: string): void;
|
|
@@ -2415,7 +2418,7 @@ interface KimeshPluginOptions {
|
|
|
2415
2418
|
/**
|
|
2416
2419
|
* Additional Vite plugins added programmatically.
|
|
2417
2420
|
*/
|
|
2418
|
-
additionalPlugins?:
|
|
2421
|
+
additionalPlugins?: vite3.PluginOption[];
|
|
2419
2422
|
}
|
|
2420
2423
|
//#endregion
|
|
2421
2424
|
export { type AddRuntimePluginOptions, type AutoImportConfig, type AutoImportOptions, type ComponentsConfig, DEFAULT_ALIASES, DEFAULT_IGNORE_PATTERNS, type DebugConfig, type DiscoveredPlugin, type EnvOptions, type ErrorContext, type FormattedError, type GeneratePluginsTemplateOptions, type HMRContext, type HMRWatcherOptions, type HookResult, INTERNAL_ALIASES, type IgnoreOptions, type ImportPreset, type ImportSource, type InternalAliasConfig, type Kimesh, type KimeshAlias, type KimeshAppContext, type KimeshComponent, type KimeshComponentsDir, type KimeshConfig, type KimeshHooks, type KimeshImport, type KimeshImportPreset, type KimeshImportsDir, type KimeshLayerConfig, type KimeshModule, type KimeshModuleDefaults, type KimeshModuleDefinition, type KimeshModuleInput, type KimeshModuleMeta, type KimeshModuleOptions, type KimeshOptions, type KimeshPlugin, type KimeshPluginDefinition, KimeshPluginOptions, type KimeshRegistries, type KimeshResolver, type KimeshRoute, type KimeshRouteMiddleware, type KimeshRuntimeHooks, type KimeshRuntimePlugin, type KimeshRuntimePluginDefinition, type KimeshRuntimePluginEntry, type KimeshRuntimePluginMeta, type KimeshRuntimePluginResult, type KimeshTemplate, type KimeshTypeTemplate, type KimeshViteConfig, type KimeshVitePluginEntry, type LayerAutoImportConfig, type LayerComponentConfig, type LayerComposableConfig, type LayerRouteConfig, type LayersConfig, type LoadConfigOptions, type PrepareOptions, type PrepareResult, type ResolvedLayer, type ResolvedTemplate, type RouteRule, type RuntimeConfig, type RuntimeConfigPublic, type ScanPluginsOptions, type VitePlugin, type VitePluginOption, addAlias, addBuildPlugin, addComponent, addComponentResolver, addComponentsDir, addImports, addImportsDir, addImportsPreset, addInternalAliasTemplates, addPluginsTemplate, addRuntimePlugin, addTemplate, addTypeTemplate, addVitePlugin, applyEnv, buildAliases, buildImportRegistry, buildInternalAliasMap, createDebugLogger, createDefaultRuntimeConfig, createHMRWatcher, createIgnoreFilter, createIgnoreMatcher, createKimesh, createResolver, createTimer, debug, debugTable, defineKimeshModule, defineKimeshPlugin, defineKmConfig, envToKey, executeModule, executeModules, filterIgnored, findMatchingRules, formatConflictWarning, formatError, formatTiming, formatWarning, generateDts, generateInternalAliasTemplate, generateLayerAliases, generatePluginsTemplate, generateRouteRulesManifest, getIgnorePatterns, getRedirectInfo, getRouteRule, getRuntimePlugins, hasPlugins, hasRuntimePlugin, isDebug, isDebugEnabled, keyToEnv, kimeshAutoImport, kimeshPlugin, loadConfig, matchRoutePattern, mergeLayerConfigs, mergeRouteRules, normalizeDebugConfig, normalizeModuleInput, prepare, prepareLayers, removeRuntimePlugin, resolveAlias, resolveAliasPath, resolveLayers, resolvePathFromBuild, resolvePathFromRoot, scanExports, scanPluginsDir, setDebugConfig, shouldIgnore, toTsConfigPaths, toViteAliases, tryUseKimesh, updateTemplates, useKimesh, writeTemplates };
|
package/dist/index.mjs
CHANGED
|
@@ -599,10 +599,13 @@ function addBuildPlugin(plugin, options) {
|
|
|
599
599
|
/**
|
|
600
600
|
* Add an alias
|
|
601
601
|
*
|
|
602
|
+
* Note: '@' and '~' aliases are context-aware and handled by layerAliasPlugin
|
|
603
|
+
* for files within layers. For module/package internal use, they work as expected.
|
|
604
|
+
*
|
|
602
605
|
* @example
|
|
603
606
|
* ```ts
|
|
604
607
|
* addAlias("#my-module", "/path/to/module");
|
|
605
|
-
* addAlias("
|
|
608
|
+
* addAlias("@", "./src"); // For module internal use
|
|
606
609
|
* ```
|
|
607
610
|
*/
|
|
608
611
|
function addAlias(find, replacement) {
|
|
@@ -2661,9 +2664,17 @@ function stripVirtualPrefixes(filePath) {
|
|
|
2661
2664
|
* @param layers - Array of resolved layers
|
|
2662
2665
|
* @returns The layer the file belongs to, or null if not in any layer
|
|
2663
2666
|
*/
|
|
2667
|
+
/**
|
|
2668
|
+
* Strip query string from file path
|
|
2669
|
+
* e.g., "file.vue?vue&type=script" -> "file.vue"
|
|
2670
|
+
*/
|
|
2671
|
+
function stripQueryString(filePath) {
|
|
2672
|
+
const queryIndex = filePath.indexOf("?");
|
|
2673
|
+
return queryIndex >= 0 ? filePath.slice(0, queryIndex) : filePath;
|
|
2674
|
+
}
|
|
2664
2675
|
function findLayerForFile(filePath, layers) {
|
|
2665
2676
|
if (!filePath || layers.length === 0) return null;
|
|
2666
|
-
const strippedPath = stripVirtualPrefixes(filePath);
|
|
2677
|
+
const strippedPath = stripQueryString(stripVirtualPrefixes(filePath));
|
|
2667
2678
|
const normalizedFilePath = normalize(strippedPath);
|
|
2668
2679
|
const realFilePath = normalize(getRealPath(strippedPath));
|
|
2669
2680
|
const sortedLayers = [...layers].sort((a, b) => b.path.length - a.path.length);
|
|
@@ -2749,16 +2760,38 @@ const ALIAS_IMPORT_RE = /from\s+['"]([~@]\/[^'"]+)['"]/g;
|
|
|
2749
2760
|
* to handle all cases.
|
|
2750
2761
|
*/
|
|
2751
2762
|
function layerAliasPlugin(options) {
|
|
2752
|
-
const { getLayers, debug = false } = options;
|
|
2763
|
+
const { getLayers, getModuleRootAliases, debug = false } = options;
|
|
2753
2764
|
/**
|
|
2754
2765
|
* Resolve an alias import given the importer path
|
|
2755
2766
|
*/
|
|
2756
2767
|
function resolveAliasImport(id, importer) {
|
|
2757
2768
|
const layers = getLayers();
|
|
2758
2769
|
if (layers.length === 0) return null;
|
|
2759
|
-
const
|
|
2760
|
-
if (
|
|
2761
|
-
|
|
2770
|
+
const importerLayer = findLayerForFile(importer, layers);
|
|
2771
|
+
if (importerLayer) return resolveLayerAlias(id, importerLayer);
|
|
2772
|
+
if (getModuleRootAliases) {
|
|
2773
|
+
const moduleAliases = getModuleRootAliases();
|
|
2774
|
+
const aliasKey = id.startsWith("@/") ? "@" : id.startsWith("~/") ? "~" : null;
|
|
2775
|
+
if (aliasKey && moduleAliases[aliasKey]) {
|
|
2776
|
+
const relativePath = id.slice(2);
|
|
2777
|
+
const resolved = join$1(moduleAliases[aliasKey], relativePath);
|
|
2778
|
+
if (existsSync(resolved)) return resolved;
|
|
2779
|
+
for (const ext of [
|
|
2780
|
+
".ts",
|
|
2781
|
+
".js",
|
|
2782
|
+
".vue",
|
|
2783
|
+
".tsx",
|
|
2784
|
+
".jsx",
|
|
2785
|
+
".mjs",
|
|
2786
|
+
".mts"
|
|
2787
|
+
]) {
|
|
2788
|
+
const withExt = resolved + ext;
|
|
2789
|
+
if (existsSync(withExt)) return withExt;
|
|
2790
|
+
}
|
|
2791
|
+
return resolved;
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
return null;
|
|
2762
2795
|
}
|
|
2763
2796
|
return {
|
|
2764
2797
|
name: "kimesh:layer-alias",
|
|
@@ -3221,7 +3254,8 @@ function kimeshPlugin(options = {}) {
|
|
|
3221
3254
|
root: "",
|
|
3222
3255
|
generatedDir: "",
|
|
3223
3256
|
kimesh: null,
|
|
3224
|
-
hasPlugins: false
|
|
3257
|
+
hasPlugins: false,
|
|
3258
|
+
moduleRootAliases: {}
|
|
3225
3259
|
};
|
|
3226
3260
|
const layersConfig = {
|
|
3227
3261
|
enabled: options.layers?.enabled ?? config.layers?.enabled ?? "all",
|
|
@@ -3327,7 +3361,12 @@ function kimeshPlugin(options = {}) {
|
|
|
3327
3361
|
const kimeshPackageAliases = buildKimeshPackageAliases(configRoot, debug);
|
|
3328
3362
|
if (packagesLocation?.type === "workspace-packages") kimeshPackagesPath = packagesLocation.path;
|
|
3329
3363
|
const moduleAliases = {};
|
|
3330
|
-
for (const alias of state.kimesh._registries.aliases) if (typeof alias.find === "string")
|
|
3364
|
+
for (const alias of state.kimesh._registries.aliases) if (typeof alias.find === "string") {
|
|
3365
|
+
if (alias.find === "@" || alias.find === "~") continue;
|
|
3366
|
+
moduleAliases[alias.find] = alias.replacement;
|
|
3367
|
+
}
|
|
3368
|
+
state.moduleRootAliases = {};
|
|
3369
|
+
for (const alias of state.kimesh._registries.aliases) if (typeof alias.find === "string" && (alias.find === "@" || alias.find === "~")) state.moduleRootAliases[alias.find] = alias.replacement;
|
|
3331
3370
|
const appVuePath = resolve$1(resolvedDirs.srcDir, "app.vue");
|
|
3332
3371
|
const internalAliases = {
|
|
3333
3372
|
"#kimesh/routes": join$1(resolvedDirs.buildDir, "routes.gen.ts"),
|
|
@@ -3566,6 +3605,7 @@ function kimeshPlugin(options = {}) {
|
|
|
3566
3605
|
const internalPlugins = [
|
|
3567
3606
|
layerAliasPlugin({
|
|
3568
3607
|
getLayers: () => state.resolvedLayers,
|
|
3608
|
+
getModuleRootAliases: () => state.moduleRootAliases,
|
|
3569
3609
|
debug
|
|
3570
3610
|
}),
|
|
3571
3611
|
mainPlugin,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kimesh/kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.32-nightly.20260129013552",
|
|
4
4
|
"description": "Build-time engine for Kimesh framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"test:watch": "vitest"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@kimesh/auto-import": "
|
|
31
|
-
"@kimesh/layers": "
|
|
32
|
-
"@kimesh/router-generator": "
|
|
30
|
+
"@kimesh/auto-import": "workspace:*",
|
|
31
|
+
"@kimesh/layers": "workspace:*",
|
|
32
|
+
"@kimesh/router-generator": "workspace:*",
|
|
33
33
|
"@vitejs/plugin-vue": "^6.0.3",
|
|
34
34
|
"c12": "^3.3.3",
|
|
35
35
|
"consola": "^3.4.2",
|