@kimesh/kit 0.2.31 → 0.2.32-nightly.20260129015928
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 +4 -1
- package/dist/index.mjs +73 -9
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -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;
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { klona } from "klona/json";
|
|
|
5
5
|
import destr from "destr";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
import consola from "consola";
|
|
8
|
-
import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
9
9
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
10
10
|
import fg from "fast-glob";
|
|
11
11
|
import { basename, dirname as dirname$1, extname, isAbsolute as isAbsolute$1, join as join$1, normalize, relative, resolve as resolve$1 } from "pathe";
|
|
@@ -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,62 @@ 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)) {
|
|
2779
|
+
try {
|
|
2780
|
+
if (statSync(resolved).isDirectory()) for (const indexFile of [
|
|
2781
|
+
"index.ts",
|
|
2782
|
+
"index.js",
|
|
2783
|
+
"index.vue",
|
|
2784
|
+
"index.mjs",
|
|
2785
|
+
"index.mts"
|
|
2786
|
+
]) {
|
|
2787
|
+
const indexPath = join$1(resolved, indexFile);
|
|
2788
|
+
if (existsSync(indexPath)) return indexPath;
|
|
2789
|
+
}
|
|
2790
|
+
} catch {}
|
|
2791
|
+
return resolved;
|
|
2792
|
+
}
|
|
2793
|
+
for (const ext of [
|
|
2794
|
+
".ts",
|
|
2795
|
+
".js",
|
|
2796
|
+
".vue",
|
|
2797
|
+
".tsx",
|
|
2798
|
+
".jsx",
|
|
2799
|
+
".mjs",
|
|
2800
|
+
".mts"
|
|
2801
|
+
]) {
|
|
2802
|
+
const withExt = resolved + ext;
|
|
2803
|
+
if (existsSync(withExt)) return withExt;
|
|
2804
|
+
}
|
|
2805
|
+
for (const indexFile of [
|
|
2806
|
+
"index.ts",
|
|
2807
|
+
"index.js",
|
|
2808
|
+
"index.vue",
|
|
2809
|
+
"index.mjs",
|
|
2810
|
+
"index.mts"
|
|
2811
|
+
]) {
|
|
2812
|
+
const indexPath = join$1(resolved, indexFile);
|
|
2813
|
+
if (existsSync(indexPath)) return indexPath;
|
|
2814
|
+
}
|
|
2815
|
+
return resolved;
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
return null;
|
|
2762
2819
|
}
|
|
2763
2820
|
return {
|
|
2764
2821
|
name: "kimesh:layer-alias",
|
|
@@ -3221,7 +3278,8 @@ function kimeshPlugin(options = {}) {
|
|
|
3221
3278
|
root: "",
|
|
3222
3279
|
generatedDir: "",
|
|
3223
3280
|
kimesh: null,
|
|
3224
|
-
hasPlugins: false
|
|
3281
|
+
hasPlugins: false,
|
|
3282
|
+
moduleRootAliases: {}
|
|
3225
3283
|
};
|
|
3226
3284
|
const layersConfig = {
|
|
3227
3285
|
enabled: options.layers?.enabled ?? config.layers?.enabled ?? "all",
|
|
@@ -3327,7 +3385,12 @@ function kimeshPlugin(options = {}) {
|
|
|
3327
3385
|
const kimeshPackageAliases = buildKimeshPackageAliases(configRoot, debug);
|
|
3328
3386
|
if (packagesLocation?.type === "workspace-packages") kimeshPackagesPath = packagesLocation.path;
|
|
3329
3387
|
const moduleAliases = {};
|
|
3330
|
-
for (const alias of state.kimesh._registries.aliases) if (typeof alias.find === "string")
|
|
3388
|
+
for (const alias of state.kimesh._registries.aliases) if (typeof alias.find === "string") {
|
|
3389
|
+
if (alias.find === "@" || alias.find === "~") continue;
|
|
3390
|
+
moduleAliases[alias.find] = alias.replacement;
|
|
3391
|
+
}
|
|
3392
|
+
state.moduleRootAliases = {};
|
|
3393
|
+
for (const alias of state.kimesh._registries.aliases) if (typeof alias.find === "string" && (alias.find === "@" || alias.find === "~")) state.moduleRootAliases[alias.find] = alias.replacement;
|
|
3331
3394
|
const appVuePath = resolve$1(resolvedDirs.srcDir, "app.vue");
|
|
3332
3395
|
const internalAliases = {
|
|
3333
3396
|
"#kimesh/routes": join$1(resolvedDirs.buildDir, "routes.gen.ts"),
|
|
@@ -3566,6 +3629,7 @@ function kimeshPlugin(options = {}) {
|
|
|
3566
3629
|
const internalPlugins = [
|
|
3567
3630
|
layerAliasPlugin({
|
|
3568
3631
|
getLayers: () => state.resolvedLayers,
|
|
3632
|
+
getModuleRootAliases: () => state.moduleRootAliases,
|
|
3569
3633
|
debug
|
|
3570
3634
|
}),
|
|
3571
3635
|
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.20260129015928",
|
|
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",
|