I am trying to use ripgrep in node.js application running on my mac machine. ( VS Code Extension).
I tried ripgrep-js npm libray but it was not giving any response and application was just going to hang state.
I tried to debug and found that ripgrep-js is just running the rg command and grabbing its results and giving it back in a formatted way. I tried the running the simple command like
rg test .
I got the results.
But same thing which when I am running via node.js child_process its not giving any response. Here is the code which I am running.
// index.js
const cp = require('child_process');
let p = cp.spawn('rg', ['test'], { cwd: './'});
p.stdout.on('data', data => {
console.log('stdout: ' + data.toString());
});
p.stderr.on('data', data => {
console.log('stderr: ' + data.toString());
});
p.on('close', code => {
console.log('closed: ' + code);
});
Not sure what could be the cause of it. I came around this question child_process.spawn doesn't emit any events which kind of matches with my use case where the ripgrep was not working. But it is not very clear what exactly was done to resolve the issue. Reaching out to community for the help.
In order to reproduce this, please create the index.js with above code and run with node as node index.js