Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Dadigua",
"email": "0laopo0@gmail.com"
},
"version": "2.0.0-alpha.56",
"version": "2.0.0-alpha.57",
"private": true,
"scripts": {
"dev": "node scripts/build.mjs dev",
Expand Down
115 changes: 113 additions & 2 deletions packages/core/build.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import { execSync } from 'child_process';
import { existsSync, mkdirSync, rmSync, copyFileSync } from 'fs';
import { join, dirname } from 'path';
import { existsSync, mkdirSync, rmSync, copyFileSync, readFileSync, writeFileSync, readdirSync } from 'fs';
import { join, dirname, relative, resolve } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -51,4 +51,115 @@ if (existsSync(sharedI18nPath)) {
console.log(`已复制: ${sharedI18nPath} -> ${distI18nPath}`);
} else {
console.warn(`警告: 找不到i18n.json文件: ${sharedI18nPath}`);
}

// 替换tsconfig.paths中的别名引用为实际路径
console.log('替换路径别名...');
replacePathAliases();

/**
* 替换tsconfig中定义的paths别名引用
*/
function replacePathAliases() {
const sharedPackageName = '@dadigua/hyperchat-shared';

// 检查shared包的输出文件类型
const sharedIndexPath = join(distDir, 'shared', 'src', 'index.mjs');
const sharedIndexJsPath = join(distDir, 'shared', 'src', 'index.js');
const sharedIndexDtsPath = join(distDir, 'shared', 'src', 'index.d.ts');

let sharedPackagePath;
let sharedDtsPath;
if (existsSync(sharedIndexPath)) {
sharedPackagePath = 'index.mjs';
sharedDtsPath = 'index.d.ts';
} else if (existsSync(sharedIndexJsPath)) {
sharedPackagePath = 'index.js';
sharedDtsPath = 'index.d.ts';
} else {
console.warn('警告: 找不到shared包的index文件');
return;
}

// 查找所有.mjs和.d.ts文件
const mjsFiles = findFiles(distDir, '.mjs');
const dtsFiles = findFiles(distDir, '.d.ts');
const dmtsFiles = findFiles(distDir, '.d.mts');

const allFiles = [...mjsFiles, ...dtsFiles, ...dmtsFiles];

console.log(`找到 ${allFiles.length} 个文件需要处理 (.mjs: ${mjsFiles.length}, .d.ts: ${dtsFiles.length}, .d.mts: ${dmtsFiles.length})`);

allFiles.forEach(filePath => {
try {
let content = readFileSync(filePath, 'utf8');

// 检查是否包含需要替换的别名
if (content.includes(sharedPackageName)) {
// 计算相对路径
const fileDir = dirname(filePath);
const isTypeDeclaration = filePath.endsWith('.d.ts') || filePath.endsWith('.d.mts');

let targetPath;
if (isTypeDeclaration) {
targetPath = join(distDir, 'shared', 'src', sharedDtsPath);
} else {
targetPath = join(distDir, 'shared', 'src', sharedPackagePath);
}

const relativePath = relative(fileDir, targetPath);

// 确保路径格式正确(使用./开头)
const normalizedRelativePath = relativePath.startsWith('.') ? relativePath : './' + relativePath;

// 替换所有引用(支持import type和import语句)
const originalContent = content;

// 替换import type引用
content = content.replace(
new RegExp(`from\s+['"]${sharedPackageName}['"]`, 'g'),
`from '${normalizedRelativePath}'`
);

// 替换import引用(确保不重复替换)
content = content.replace(
new RegExp(`['"]${sharedPackageName}['"]`, 'g'),
`'${normalizedRelativePath}'`
);

if (content !== originalContent) {
writeFileSync(filePath, content, 'utf8');
console.log(`已更新: ${filePath} -> ${normalizedRelativePath}`);
}
}
} catch (error) {
console.warn(`处理文件 ${filePath} 时出错: ${error.message}`);
}
});
}

/**
* 查找指定目录下的所有指定扩展名的文件
*/
function findFiles(dir, extension) {
const files = [];

function traverse(currentDir) {
if (!existsSync(currentDir)) return;

const items = readdirSync(currentDir, { withFileTypes: true });

items.forEach(item => {
const fullPath = join(currentDir, item.name);

if (item.isDirectory()) {
traverse(fullPath);
} else if (item.name.endsWith(extension)) {
files.push(fullPath);
}
});
}

traverse(dir);
return files;
}
58 changes: 0 additions & 58 deletions packages/core/collectedMessages.json

This file was deleted.

58 changes: 0 additions & 58 deletions packages/core/messages.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dadigua/hyperchat",
"version": "2.0.0-alpha.56",
"version": "2.0.0-alpha.57",
"description": "HyperChat Core - Node.js backend and CLI tool with AI chat, MCP support",
"author": "Dadigua <0laopo0@gmail.com>",
"license": "MIT",
Expand Down
5 changes: 1 addition & 4 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"./types"
],
"paths": {
"@dadigua/hyperchat-shared/*": [
"../shared/src/*"
],
"@dadigua/hyperchat-shared": [
"../shared/src/index.ts"
]
Expand All @@ -24,7 +21,7 @@
"include": [
"src",
"types",
"**/*.json",
"package.json",
"../shared/src",
"../shared/src/**/*.json",
],
Expand Down
2 changes: 1 addition & 1 deletion packages/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
]
}
},
"version": "2.0.0-alpha.56",
"version": "2.0.0-alpha.57",
"description": "HyperChat Electron main process and related functionality",
"main": "dist/electron/src/main.mjs",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dadigua/hyperchat-shared",
"version": "2.0.0-alpha.56",
"version": "2.0.0-alpha.57",
"description": "HyperChat Shared - Common types, utilities and schemas",
"type": "module",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dadigua/hyperchat-web",
"version": "2.0.0-alpha.56",
"version": "2.0.0-alpha.57",
"private": true,
"dependencies": {
"@ant-design/cssinjs": "^1.24.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
"./types"
],
"paths": {
"@dadigua/hyperchat-shared/*": [
"../shared/src/*"
],
"@dadigua/hyperchat-shared": [
"../shared/src/index.ts"
],
Expand Down