refactor: remove CommonJS ripgrep launcher and spawn binary directly

Replace the ripgrep_launcher.cjs intermediary with direct binary execution.
This simplifies the ripgrep module by spawning the binary directly instead
of going through a Node.js subprocess wrapper. Add platform-specific binary
path resolution to handle both Unix and Windows environments.
This commit is contained in:
weishu
2025-12-23 18:09:12 +08:00
parent eafd4d12a9
commit 92996667d5
5 changed files with 13 additions and 49 deletions
-33
View File
@@ -1,33 +0,0 @@
#!/usr/bin/env node
/**
* Ripgrep runner - executed as a subprocess to run the native module
* This file is intentionally written in CommonJS to avoid ESM complexities
*/
const path = require('path');
// Load the native module from unpacked directory
const modulePath = path.join(__dirname, '..', 'tools', 'unpacked', 'ripgrep.node');
const ripgrepNative = require(modulePath);
// Get arguments from command line (skip node and script name)
const args = process.argv.slice(2);
// Parse the JSON-encoded arguments
let parsedArgs;
try {
parsedArgs = JSON.parse(args[0]);
} catch (error) {
console.error('Failed to parse arguments:', error.message);
process.exit(1);
}
// Run ripgrep
try {
const exitCode = ripgrepNative.ripgrepMain(parsedArgs);
process.exit(exitCode);
} catch (error) {
console.error('Ripgrep error:', error.message);
process.exit(1);
}
+2 -3
View File
@@ -57,8 +57,7 @@ function areToolsUnpacked(toolsDir) {
const expectedFiles = [
path.join(unpackedPath, difftBinary),
path.join(unpackedPath, rgBinary),
path.join(unpackedPath, 'ripgrep.node')
path.join(unpackedPath, rgBinary)
];
return expectedFiles.every(file => fs.existsSync(file));
@@ -160,4 +159,4 @@ if (require.main === module) {
console.error('Error:', error);
process.exit(1);
});
}
}