Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (bin, shebang, code) => {
if (!shebangRegex.test(shebang)) {
shebang = '#!/usr/bin/env ' + shebang;
}
// On windows shebangs aren't supported. Use a fake extension to prevent
// the bin from being executed instead of the shim.
const fileName = bin + (process.platform === 'win32' ? '.x-mock-bin' : '');
let oldPath = shell.env.PATH;
return tempWrite(shebang + '\n' + code, fileName)
.then(filepath => {
// Path separator according to platform
const sep = process.platform === 'win32' ? ';' : ':';
shell.chmod('+x', filepath);
shell.env.PATH = filepath.replace(new RegExp(fileName + '$'), '') + sep + oldPath;