feat:构建工具改为esbuild

This commit is contained in:
li1553770945 2025-06-15 23:53:30 +08:00
parent 3cae8572e8
commit 2a8ff295b2
11 changed files with 3131 additions and 1546 deletions

16
esbuild.config.js Normal file
View File

@ -0,0 +1,16 @@
// esbuild.config.js
const { build } = require('esbuild');
build({
entryPoints: ['src/extension.ts'],
bundle: true,
platform: 'node',
format: 'cjs',
outfile: 'dist/extension.cjs.js',
sourcemap: true,
external: ['vscode'], // 只排除 vscode其他依赖全部打包进来
target: ['node18'], // 你可以根据实际 node 版本调整
loader: {
'.json': 'json'
}
}).catch(() => process.exit(1));

4497
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -19,8 +19,7 @@
"Other" "Other"
], ],
"activationEvents": [], "activationEvents": [],
"type": "module", "main": "./dist/extension.cjs.js",
"main": "./dist/extension.js",
"icon": "icons/openmcp.png", "icon": "icons/openmcp.png",
"contributes": { "contributes": {
"configuration": { "configuration": {
@ -223,9 +222,9 @@
"scripts": { "scripts": {
"setup": "npm i && npm run prepare:ocr", "setup": "npm i && npm run prepare:ocr",
"serve": "turbo serve", "serve": "turbo serve",
"build": "turbo build && tsc -p ./", "build": "turbo build && tsc -p ./ && node esbuild.config.js",
"build:plugin": "npm run build && tsc && vsce package", "build:plugin": "npm run build && tsc && vsce package",
"vscode:prepublish": "rollup --config rollup.config.js", "vscode:prepublish": "node esbuild.config.js",
"compile": "tsc -p ./", "compile": "tsc -p ./",
"watch": "tsc -watch -p ./", "watch": "tsc -watch -p ./",
"pretest": "npm run build", "pretest": "npm run build",
@ -237,11 +236,17 @@
"dependencies": { "dependencies": {
"@modelcontextprotocol/sdk": "^1.12.1", "@modelcontextprotocol/sdk": "^1.12.1",
"@seald-io/nedb": "^4.1.1", "@seald-io/nedb": "^4.1.1",
"@types/node-fetch": "^2.6.4",
"abort-controller": "^3.0.0",
"agentkeepalive": "^4.2.1",
"axios": "^1.9.0", "axios": "^1.9.0",
"bson": "^6.8.0", "bson": "^6.8.0",
"form-data-encoder": "^1.7.2",
"formdata-node": "^4.3.2",
"https-proxy-agent": "^7.0.6", "https-proxy-agent": "^7.0.6",
"openai": "^5.0.1", "openai": "^5.0.1",
"pako": "^2.1.0", "pako": "^2.1.0",
"pkce-challenge": "^5.0.0",
"tesseract.js": "^6.0.1", "tesseract.js": "^6.0.1",
"tslib": "^2.8.1", "tslib": "^2.8.1",
"uuid": "^11.1.0", "uuid": "^11.1.0",
@ -261,6 +266,7 @@
"@vscode/test-cli": "^0.0.11", "@vscode/test-cli": "^0.0.11",
"@vscode/test-electron": "^2.5.2", "@vscode/test-electron": "^2.5.2",
"copy-webpack-plugin": "^13.0.0", "copy-webpack-plugin": "^13.0.0",
"esbuild": "^0.25.5",
"fork-ts-checker-webpack-plugin": "^9.1.0", "fork-ts-checker-webpack-plugin": "^9.1.0",
"null-loader": "^4.0.1", "null-loader": "^4.0.1",
"rollup": "^4.43.0", "rollup": "^4.43.0",

View File

@ -1,23 +0,0 @@
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json';
export default {
input: 'src/extension.ts',
output: {
file: 'dist/extension.js',
format: 'es',
sourcemap: true
},
plugins: [
json(),
resolve({ browser: true }), // 支持 node_modules 解析
commonjs(), // 转换 CommonJS 模块
typescript() // 处理 TypeScript
],
external: ['vscode'], // 排除 VSCode 内置模块
onwarn(warning, warn) {
if (warning.code !== 'SOURCEMAP_ERROR') warn(warning);
}
};

View File

@ -24,15 +24,7 @@ const serverPath = join(devHome, 'servers');
const envPath = join(__dirname, '..', '.env'); const envPath = join(__dirname, '..', '.env');
const logger = pino({ const logger = pino({
transport: {
target: 'pino-pretty',
options: {
colorize: true,
levelFirst: true,
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss',
ignore: 'pid,hostname',
}
}
}); });
export type MessageHandler = (message: VSCodeMessage) => void; export type MessageHandler = (message: VSCodeMessage) => void;

View File

@ -7,15 +7,7 @@ import { pino } from 'pino';
// 保留现有 logger 配置 // 保留现有 logger 配置
const logger = pino({ const logger = pino({
transport: {
target: 'pino-pretty',
options: {
colorize: true,
levelFirst: true,
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss',
ignore: 'pid,hostname',
}
}
}); });
function getFilePath(options: { function getFilePath(options: {

View File

@ -20,15 +20,7 @@ export interface VSCodeMessage {
} }
const logger = pino.default({ const logger = pino.default({
transport: {
target: 'pino-pretty',
options: {
colorize: true,
levelFirst: true,
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss',
ignore: 'pid,hostname',
}
}
}); });
export type MessageHandler = (message: VSCodeMessage) => void; export type MessageHandler = (message: VSCodeMessage) => void;

32
src/test/e2e/runTest.ts Normal file
View File

@ -0,0 +1,32 @@
import * as path from 'path';
import { runTests } from '@vscode/test-electron';
import { fileURLToPath } from 'url';
// 将 import.meta.url 转换为文件路径
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../../');
console.log('Extension Path:', extensionDevelopmentPath); // 添加日志验证路径
// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index.js');
// Download VS Code, unzip it and run the integration test
await runTests({
extensionDevelopmentPath: extensionDevelopmentPath,
extensionTestsPath: extensionTestsPath,
});
} catch (err) {
console.error('Failed to run tests');
console.error(err);
process.exit(1);
}
}
main();

View File

@ -0,0 +1,15 @@
import * as assert from 'assert';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';
suite('Extension Test Suite', () => {
// vscode.window.showInformationMessage('Start all tests.');
console.log("Running sample test")
test('Sample test', () => {
assert.strictEqual([1, 2, 3].indexOf(5), -1);
assert.strictEqual([1, 2, 3].indexOf(0), -1);
});
});

View File

@ -0,0 +1,43 @@
import * as path from 'path';
import Mocha from 'mocha';
import {glob} from 'glob';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd'
});
const testsRoot = path.resolve(__dirname, '..');
return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }).then((files: string[]) => {
// Add files to the test suite
console.log('Test files found:', files); // Log the found test files
files.forEach((f: string) => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
console.log("Running test:", files)
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
}).catch(err => {
e(err);
});
});
}

View File

@ -1,8 +1,8 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES6", "target": "ES2020",
"module": "NodeNext", "module": "ESNext",
"moduleResolution": "NodeNext", "moduleResolution": "node",
"outDir": "./dist", "outDir": "./dist",
"rootDir": "./src", "rootDir": "./src",
"strict": true, "strict": true,
@ -12,6 +12,7 @@
"importHelpers": false, "importHelpers": false,
"noEmitHelpers": false, "noEmitHelpers": false,
"experimentalDecorators": true, "experimentalDecorators": true,
"sourceMap": true,
// 访 openmcp-sdk // 访 openmcp-sdk
"paths": { "paths": {
"@openmcp-sdk/*": [ "@openmcp-sdk/*": [