@kimesh/kit 0.2.5 → 0.2.6-nightly.20260123101918

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.
Files changed (2) hide show
  1. package/dist/index.mjs +66 -4
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -8,7 +8,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";
10
10
  import fg from "fast-glob";
11
- import { basename, extname, isAbsolute as isAbsolute$1, join as join$1, relative, resolve as resolve$1 } from "pathe";
11
+ import { basename, dirname as dirname$1, extname, isAbsolute as isAbsolute$1, join as join$1, relative, resolve as resolve$1 } from "pathe";
12
12
  import ignore from "ignore";
13
13
  import pc from "picocolors";
14
14
  import { defu } from "defu";
@@ -2163,6 +2163,44 @@ function findWorkspaceRoot(startDir) {
2163
2163
  return startDir;
2164
2164
  }
2165
2165
  /**
2166
+ * Try to resolve a package path from multiple locations
2167
+ * This handles various package manager layouts (npm, pnpm, bun, yarn)
2168
+ */
2169
+ function tryResolvePackage(packageName, fromDir) {
2170
+ const require = createRequire(join$1(fromDir, "package.json"));
2171
+ try {
2172
+ return dirname$1(require.resolve(`${packageName}/package.json`));
2173
+ } catch {
2174
+ const locations = [join$1(fromDir, "node_modules", packageName), join$1(findWorkspaceRoot(fromDir), "node_modules", packageName)];
2175
+ for (const loc of locations) if (existsSync(join$1(loc, "package.json"))) return loc;
2176
+ return null;
2177
+ }
2178
+ }
2179
+ /**
2180
+ * Build aliases for @kimesh/* packages
2181
+ * This ensures Vite can resolve these packages regardless of package manager
2182
+ */
2183
+ function buildKimeshPackageAliases(rootDir, debug$1) {
2184
+ const packages = [
2185
+ "@kimesh/router-runtime",
2186
+ "@kimesh/head",
2187
+ "@kimesh/query",
2188
+ "@kimesh/kit",
2189
+ "@kimesh/layers",
2190
+ "@kimesh/auto-import",
2191
+ "@kimesh/router-generator"
2192
+ ];
2193
+ const aliases = {};
2194
+ for (const pkg of packages) {
2195
+ const resolved = tryResolvePackage(pkg, rootDir);
2196
+ if (resolved) {
2197
+ aliases[pkg] = resolved;
2198
+ if (debug$1) consola.debug(`[Kimesh] Resolved ${pkg} -> ${resolved}`);
2199
+ } else if (debug$1) consola.warn(`[Kimesh] Could not resolve ${pkg}`);
2200
+ }
2201
+ return aliases;
2202
+ }
2203
+ /**
2166
2204
  * Process all configured modules using the new v2 system
2167
2205
  */
2168
2206
  async function processModules(kimesh, debug$1) {
@@ -2300,6 +2338,7 @@ function kimeshPlugin(options = {}) {
2300
2338
  generateModulesTypeDeclaration(config.modules, state.generatedDir);
2301
2339
  await writeTemplates(state.kimesh);
2302
2340
  const userAliases = buildAliases(config, resolvedDirs.srcDir, configRoot);
2341
+ const kimeshPackageAliases = buildKimeshPackageAliases(configRoot, debug$1);
2303
2342
  const moduleAliases = {};
2304
2343
  for (const alias of state.kimesh._registries.aliases) if (typeof alias.find === "string") moduleAliases[alias.find] = alias.replacement;
2305
2344
  const appVuePath = resolve$1(resolvedDirs.srcDir, "app.vue");
@@ -2352,6 +2391,7 @@ function kimeshPlugin(options = {}) {
2352
2391
  __KIMESH_LAYERS_CONFIG__: JSON.stringify(layerConfigMap)
2353
2392
  },
2354
2393
  resolve: { alias: {
2394
+ ...kimeshPackageAliases,
2355
2395
  "#kimesh/routes": join$1(resolvedDirs.buildDir, "routes.gen.ts"),
2356
2396
  "#kimesh/app": existsSync(appVuePath) ? appVuePath : "@kimesh/router-runtime/default-app",
2357
2397
  "#kimesh/context": join$1(resolvedDirs.srcDir, "app.context.ts"),
@@ -2552,12 +2592,34 @@ function kimeshPlugin(options = {}) {
2552
2592
  //#endregion
2553
2593
  //#region src/config.ts
2554
2594
  /**
2595
+ * Wrap a function with defineKmConfig injected into globalThis.
2596
+ * This allows kimesh.config.ts to use defineKmConfig without explicit import (like Nuxt).
2597
+ *
2598
+ * @internal
2599
+ */
2600
+ async function withDefineKmConfig(fn) {
2601
+ const key = "defineKmConfig";
2602
+ const globalSelf = globalThis;
2603
+ if (!globalSelf[key]) {
2604
+ globalSelf[key] = defineKmConfig;
2605
+ globalSelf[key].count = 0;
2606
+ }
2607
+ globalSelf[key].count++;
2608
+ try {
2609
+ return await fn();
2610
+ } finally {
2611
+ globalSelf[key].count--;
2612
+ if (!globalSelf[key].count) delete globalSelf[key];
2613
+ }
2614
+ }
2615
+ /**
2555
2616
  * Load kimesh.config.ts using c12
2556
2617
  */
2557
2618
  async function loadConfig(options = {}) {
2558
- const { config, configFile } = await loadConfig$1({
2619
+ const root = options.root || process.cwd();
2620
+ const { config, configFile } = await withDefineKmConfig(() => loadConfig$1({
2559
2621
  name: "kimesh",
2560
- cwd: options.root || process.cwd(),
2622
+ cwd: root,
2561
2623
  configFile: options.configFile,
2562
2624
  defaultConfig: {
2563
2625
  name: "kimesh-app",
@@ -2566,7 +2628,7 @@ async function loadConfig(options = {}) {
2566
2628
  host: "localhost"
2567
2629
  }
2568
2630
  }
2569
- });
2631
+ }));
2570
2632
  if (configFile) consola.debug(`[Kimesh] Config loaded from: ${configFile}`);
2571
2633
  return config || {};
2572
2634
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimesh/kit",
3
- "version": "0.2.5",
3
+ "version": "0.2.6-nightly.20260123101918",
4
4
  "description": "Build-time engine for Kimesh framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -30,9 +30,9 @@
30
30
  "vue": "^3.5.0"
31
31
  },
32
32
  "dependencies": {
33
- "@kimesh/auto-import": "0.2.5",
34
- "@kimesh/layers": "0.2.5",
35
- "@kimesh/router-generator": "0.2.5",
33
+ "@kimesh/auto-import": "workspace:*",
34
+ "@kimesh/layers": "workspace:*",
35
+ "@kimesh/router-generator": "workspace:*",
36
36
  "@vitejs/plugin-vue": "^6.0.3",
37
37
  "c12": "^3.3.3",
38
38
  "consola": "^3.4.2",