@yancyyu/openhermit 1.5.9 → 1.5.10

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.
@@ -0,0 +1,51 @@
1
+ import { existsSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+
5
+ const repoRoot = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..');
6
+
7
+ const ALIASES = [
8
+ ['@features/', 'src/features/'],
9
+ ['@main/', 'src/main/'],
10
+ ['@renderer/', 'src/renderer/'],
11
+ ['@shared/', 'src/shared/'],
12
+ ];
13
+
14
+ const EXACT_ALIASES = new Map([
15
+ ['@shared/types', 'src/shared/types/index.ts'],
16
+ ['@main/types', 'src/main/types/index.ts'],
17
+ ]);
18
+
19
+ function resolveAlias(specifier) {
20
+ const exactTarget = EXACT_ALIASES.get(specifier);
21
+ if (exactTarget) {
22
+ const absolutePath = path.join(repoRoot, exactTarget);
23
+ if (existsSync(absolutePath)) return pathToFileURL(absolutePath).href;
24
+ }
25
+
26
+ for (const [prefix, target] of ALIASES) {
27
+ if (!specifier.startsWith(prefix)) continue;
28
+ const relativePath = specifier.slice(prefix.length);
29
+ const basePath = path.join(repoRoot, target, relativePath);
30
+ const candidates = [
31
+ basePath,
32
+ `${basePath}.ts`,
33
+ `${basePath}.tsx`,
34
+ `${basePath}.js`,
35
+ path.join(basePath, 'index.ts'),
36
+ path.join(basePath, 'index.tsx'),
37
+ path.join(basePath, 'index.js'),
38
+ ];
39
+ const match = candidates.find((candidate) => existsSync(candidate));
40
+ if (match) return pathToFileURL(match).href;
41
+ }
42
+ return null;
43
+ }
44
+
45
+ export async function resolve(specifier, context, nextResolve) {
46
+ const aliasUrl = resolveAlias(specifier);
47
+ if (aliasUrl) {
48
+ return { url: aliasUrl, shortCircuit: true };
49
+ }
50
+ return nextResolve(specifier, context);
51
+ }
package/bin/hermit.mjs CHANGED
@@ -20,7 +20,7 @@ import { mkdirSync, writeFileSync, readFileSync, existsSync } from 'node:fs';
20
20
  import { createRequire } from 'node:module';
21
21
  import os from 'node:os';
22
22
  import path from 'node:path';
23
- import { fileURLToPath } from 'node:url';
23
+ import { fileURLToPath, pathToFileURL } from 'node:url';
24
24
 
25
25
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
26
26
  const repoRoot = path.resolve(__dirname, '..');
@@ -252,8 +252,13 @@ function resolveCcConnectRunner() {
252
252
  return path.join(path.dirname(pkgPath), 'run.js');
253
253
  }
254
254
 
255
- function resolveTsxCli() {
256
- return require.resolve('tsx/cli');
255
+ function resolveTsxLoader() {
256
+ return require.resolve('tsx');
257
+ }
258
+
259
+ function resolveAliasLoaderRegister() {
260
+ const aliasLoaderUrl = pathToFileURL(path.join(__dirname, 'alias-loader.mjs')).href;
261
+ return `data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register(${JSON.stringify(aliasLoaderUrl)}, pathToFileURL("./"));`;
257
262
  }
258
263
 
259
264
  let ccConnectProcess = null;
@@ -325,7 +330,10 @@ if (!existsSync(distRenderererDir) || !existsSync(path.join(distRenderererDir, '
325
330
  // Start the server
326
331
  console.log('[openHermit] Launching server...\n');
327
332
 
328
- const serverProcess = spawn(process.execPath, [resolveTsxCli(), 'src/main/server.ts'], {
333
+ const serverProcess = spawn(
334
+ process.execPath,
335
+ ['--import', resolveAliasLoaderRegister(), '--import', resolveTsxLoader(), 'src/main/server.ts'],
336
+ {
329
337
  cwd: repoRoot,
330
338
  env: {
331
339
  ...process.env,
@@ -339,7 +347,8 @@ const serverProcess = spawn(process.execPath, [resolveTsxCli(), 'src/main/server
339
347
  CC_CONNECT_CONFIG: ccConnectConfigPath,
340
348
  },
341
349
  stdio: 'inherit',
342
- });
350
+ }
351
+ );
343
352
 
344
353
  serverProcess.on('exit', (code) => {
345
354
  if (code !== 0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yancyyu/openhermit",
3
3
  "type": "module",
4
- "version": "1.5.9",
4
+ "version": "1.5.10",
5
5
  "description": "openHermit: team-oriented agent management workbench atop cc-connect.",
6
6
  "license": "AGPL-3.0",
7
7
  "author": {