mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
chore(sdk): bundle CLI into SDK package and inherit the dependencies
This commit is contained in:
@@ -45,7 +45,8 @@
|
|||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@modelcontextprotocol/sdk": "^1.0.4"
|
"@modelcontextprotocol/sdk": "^1.0.4",
|
||||||
|
"tiktoken": "^1.0.21"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.14.0",
|
"@types/node": "^20.14.0",
|
||||||
|
|||||||
@@ -91,3 +91,35 @@ if (existsSync(licenseSource)) {
|
|||||||
console.warn('Could not copy LICENSE:', error.message);
|
console.warn('Could not copy LICENSE:', error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Bundling CLI into SDK package...');
|
||||||
|
const repoRoot = join(rootDir, '..', '..');
|
||||||
|
const rootDistDir = join(repoRoot, 'dist');
|
||||||
|
|
||||||
|
if (!existsSync(rootDistDir) || !existsSync(join(rootDistDir, 'cli.js'))) {
|
||||||
|
console.log('Building CLI bundle...');
|
||||||
|
try {
|
||||||
|
execSync('npm run bundle', { stdio: 'inherit', cwd: repoRoot });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to build CLI bundle:', error.message);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const cliDistDir = join(rootDir, 'dist', 'cli');
|
||||||
|
mkdirSync(cliDistDir, { recursive: true });
|
||||||
|
|
||||||
|
console.log('Copying CLI bundle...');
|
||||||
|
cpSync(join(rootDistDir, 'cli.js'), join(cliDistDir, 'cli.js'));
|
||||||
|
|
||||||
|
const vendorSource = join(rootDistDir, 'vendor');
|
||||||
|
if (existsSync(vendorSource)) {
|
||||||
|
cpSync(vendorSource, join(cliDistDir, 'vendor'), { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const localesSource = join(rootDistDir, 'locales');
|
||||||
|
if (existsSync(localesSource)) {
|
||||||
|
cpSync(localesSource, join(cliDistDir, 'locales'), { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('CLI bundle copied successfully to SDK package');
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import { execSync } from 'node:child_process';
|
import { execSync } from 'node:child_process';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executable types supported by the SDK
|
* Executable types supported by the SDK
|
||||||
@@ -40,11 +41,37 @@ export type SpawnInfo = {
|
|||||||
originalInput: string;
|
originalInput: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getBundledCliPath(): string | null {
|
||||||
|
try {
|
||||||
|
const currentFile =
|
||||||
|
typeof __filename !== 'undefined'
|
||||||
|
? __filename
|
||||||
|
: fileURLToPath(import.meta.url);
|
||||||
|
|
||||||
|
const currentDir = path.dirname(currentFile);
|
||||||
|
|
||||||
|
const bundledCliPath = path.join(currentDir, 'cli', 'cli.js');
|
||||||
|
|
||||||
|
if (fs.existsSync(bundledCliPath)) {
|
||||||
|
return bundledCliPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function findNativeCliPath(): string {
|
export function findNativeCliPath(): string {
|
||||||
|
const bundledCli = getBundledCliPath();
|
||||||
|
if (bundledCli) {
|
||||||
|
return bundledCli;
|
||||||
|
}
|
||||||
|
|
||||||
const homeDir = process.env['HOME'] || process.env['USERPROFILE'] || '';
|
const homeDir = process.env['HOME'] || process.env['USERPROFILE'] || '';
|
||||||
|
|
||||||
const candidates: Array<string | undefined> = [
|
const candidates: Array<string | undefined> = [
|
||||||
// 1. Environment variable (highest priority)
|
// 1. Environment variable
|
||||||
process.env['QWEN_CODE_CLI_PATH'],
|
process.env['QWEN_CODE_CLI_PATH'],
|
||||||
|
|
||||||
// 2. Volta bin
|
// 2. Volta bin
|
||||||
|
|||||||
Reference in New Issue
Block a user