@kimesh/kit 0.2.31 → 0.2.32

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
@@ -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("@/components", "./src/components");
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
@@ -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("@/components", "./src/components");
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 targetLayer = findLayerForFile(importer, layers) || layers.find((l) => l.isApp) || layers[0];
2760
- if (!targetLayer) return null;
2761
- return resolveLayerAlias(id, targetLayer);
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") moduleAliases[alias.find] = alias.replacement;
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.31",
3
+ "version": "0.2.32",
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": "0.2.31",
31
- "@kimesh/layers": "0.2.31",
32
- "@kimesh/router-generator": "0.2.31",
30
+ "@kimesh/auto-import": "0.2.32",
31
+ "@kimesh/layers": "0.2.32",
32
+ "@kimesh/router-generator": "0.2.32",
33
33
  "@vitejs/plugin-vue": "^6.0.3",
34
34
  "c12": "^3.3.3",
35
35
  "consola": "^3.4.2",