github.com/w3security/vervet/v5@v5.3.1-0.20230618081846-5bd9b5d799dc/packaging/npm/passthrough.js (about) 1 #!/usr/bin/env node 2 var path = require('path'); 3 4 // os and arch restrictions are handled by the package.json 5 var os = process.platform; 6 var arch = process.arch; 7 8 // Select the right binary for this platform, then exec it with the original 9 // arguments. This is a true exec(3), which will take over the pid, env, and 10 // file descriptors. 11 var vervetPath = path.join(__dirname, '../bin/vervet-' + os + '-' + arch); 12 if (os === 'win32') { 13 vervetPath = path.join(__dirname, '../bin/vervet.exe'); 14 } 15 16 try { 17 var kexec = require('kexec'); 18 kexec(vervetPath, process.argv.slice(2)); 19 } catch (err) { 20 if (err.code !== 'MODULE_NOT_FOUND') { 21 console.error('Could not leverage kexec due to error: ' + err.message); 22 } 23 24 var spawn = require('child_process').spawn; 25 var proc = spawn(vervetPath, process.argv.slice(2), { stdio: 'inherit' }); 26 proc.on('exit', function (code, signal) { 27 process.on('exit', function () { 28 if (signal) { 29 process.kill(process.pid, signal); 30 } else { 31 process.exit(code); 32 } 33 }); 34 }); 35 }