mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-01 21:20:44 +00:00
fix(vscode-ide-companion): prune ripgrep binaries and remove generic node-pty
- Re-enable macOS x64 CI builds using macos-15-intel runner - Remove generic node-pty dependency in favor of platform-specific @lydell/node-pty-* packages - Add ripgrep binary pruning for platform-specific builds to reduce VSIX size - Add Windows workaround to remove npm junction self-references during packaging
This commit is contained in:
parent
3d6fe23c3b
commit
e5b800a79d
6 changed files with 139 additions and 32 deletions
|
|
@ -21,6 +21,7 @@ import path from 'node:path';
|
|||
import { fileURLToPath } from 'node:url';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import os from 'node:os';
|
||||
import fs from 'node:fs';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
|
@ -49,6 +50,132 @@ function run(cmd, args, opts = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
function parseVsceTarget(target) {
|
||||
if (!target) return null;
|
||||
const parts = target.split('-');
|
||||
if (parts.length !== 2) return null;
|
||||
const [platform, arch] = parts;
|
||||
return { platform, arch };
|
||||
}
|
||||
|
||||
function getExpectedRipgrepDirName() {
|
||||
const target = parseVsceTarget(process.env.VSCODE_TARGET);
|
||||
const platform = target?.platform ?? process.platform;
|
||||
const arch = target?.arch ?? process.arch;
|
||||
|
||||
const normalizedPlatform =
|
||||
platform === 'darwin' || platform === 'linux' || platform === 'win32'
|
||||
? platform
|
||||
: null;
|
||||
const normalizedArch = arch === 'x64' || arch === 'arm64' ? arch : null;
|
||||
|
||||
if (!normalizedPlatform || !normalizedArch) return null;
|
||||
return `${normalizedArch}-${normalizedPlatform}`;
|
||||
}
|
||||
|
||||
function pruneBundledRipgrep() {
|
||||
const isUniversalBuild = process.env.UNIVERSAL_BUILD === 'true';
|
||||
if (isUniversalBuild) {
|
||||
console.log('[prepackage] Universal build: keeping all ripgrep binaries');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!process.env.VSCODE_TARGET) {
|
||||
console.log(
|
||||
'[prepackage] VSCODE_TARGET not set: keeping all ripgrep binaries',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const expectedDirName = getExpectedRipgrepDirName();
|
||||
if (!expectedDirName) {
|
||||
console.warn(
|
||||
'[prepackage] Could not resolve expected ripgrep target; keeping all binaries',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const ripgrepDir = path.join(bundledCliDir, 'vendor', 'ripgrep');
|
||||
if (!fs.existsSync(ripgrepDir)) {
|
||||
console.log('[prepackage] No bundled ripgrep directory found; skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
const entries = fs.readdirSync(ripgrepDir, { withFileTypes: true });
|
||||
const removed = [];
|
||||
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
const name = entry.name;
|
||||
if (!/^(x64|arm64)-(darwin|linux|win32)$/.test(name)) continue;
|
||||
if (name === expectedDirName) continue;
|
||||
|
||||
const fullPath = path.join(ripgrepDir, name);
|
||||
fs.rmSync(fullPath, { recursive: true, force: true });
|
||||
removed.push(name);
|
||||
}
|
||||
|
||||
if (removed.length === 0) {
|
||||
console.log(
|
||||
`[prepackage] Ripgrep already pruned for ${expectedDirName} (no changes)`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`[prepackage] Pruned ripgrep binaries; kept ${expectedDirName}, removed: ${removed.join(', ')}`,
|
||||
);
|
||||
}
|
||||
|
||||
function removeSelfReferenceFromNodeModules() {
|
||||
if (process.platform !== 'win32') return;
|
||||
|
||||
const packageJsonPath = path.join(bundledCliDir, 'package.json');
|
||||
if (!fs.existsSync(packageJsonPath)) return;
|
||||
|
||||
let packageName;
|
||||
try {
|
||||
const parsed = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||
packageName = parsed?.name;
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof packageName !== 'string' || packageName.length === 0) return;
|
||||
|
||||
// Some npm installations on Windows can create a junction in node_modules
|
||||
// pointing back to the package itself. vsce/yazl can't zip that reliably.
|
||||
let selfPath;
|
||||
if (packageName.startsWith('@')) {
|
||||
const [scope, name] = packageName.split('/');
|
||||
if (!scope || !name) return;
|
||||
selfPath = path.join(bundledCliDir, 'node_modules', scope, name);
|
||||
} else {
|
||||
selfPath = path.join(bundledCliDir, 'node_modules', packageName);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(selfPath)) return;
|
||||
|
||||
fs.rmSync(selfPath, { recursive: true, force: true });
|
||||
console.log(
|
||||
`[prepackage] Windows: removed self-reference from node_modules: ${packageName}`,
|
||||
);
|
||||
|
||||
// Cleanup empty scope directory (cosmetic).
|
||||
try {
|
||||
const parentDir = path.dirname(selfPath);
|
||||
if (
|
||||
fs.existsSync(parentDir) &&
|
||||
fs.statSync(parentDir).isDirectory() &&
|
||||
fs.readdirSync(parentDir).length === 0
|
||||
) {
|
||||
fs.rmdirSync(parentDir);
|
||||
}
|
||||
} catch {
|
||||
// Best-effort cleanup only.
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const npm = npmBin();
|
||||
|
||||
|
|
@ -113,6 +240,9 @@ function main() {
|
|||
npm_config_link_workspace_packages: 'false',
|
||||
},
|
||||
});
|
||||
|
||||
removeSelfReferenceFromNodeModules();
|
||||
pruneBundledRipgrep();
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue