src/hooks/HooksRunner.js
function extractSheBangInterpreter(fullpath) {
    var fileChunk;
    var octetsRead;
    var fileData;
    var hookFd = fs.openSync(fullpath, 'r');
    try {
        // this is a modern cluster size. no need to read less
        fileData = new Buffer(4096);
        octetsRead = fs.readSync(hookFd, fileData, 0, 4096, 0);
        fileChunk = fileData.toString();
    } finally {
        fs.closeSync(hookFd);
    }

    var hookCmd, shMatch;
    // Filter out /usr/bin/env so that "/usr/bin/env node" works like "node".
    var shebangMatch = fileChunk.match(/^#!(?:\/usr\/bin\/env )?([^\r\n]+)/m);
    if (octetsRead == 4096 && !fileChunk.match(/[\r\n]/))
        events.emit('warn', 'shebang is too long for "' + fullpath + '"');
    if (shebangMatch)
        hookCmd = shebangMatch[1];
    // Likewise, make /usr/bin/bash work like "bash".
    if (hookCmd)
        shMatch = hookCmd.match(/bin\/((?:ba)?sh)$/);
    if (shMatch)
        hookCmd = shMatch[1];
    return hookCmd;
}
function extractSheBangInterpreter(fullpath) {
    var fileChunk;
    var octetsRead;
    var fileData;
    var hookFd = fs.openSync(fullpath, 'r');
    try {
        // this is a modern cluster size. no need to read less
        fileData = new Buffer(4096);
        octetsRead = fs.readSync(hookFd, fileData, 0, 4096, 0);
        fileChunk = fileData.toString();
    } finally {
        fs.closeSync(hookFd);
    }

    var hookCmd, shMatch;
    // Filter out /usr/bin/env so that "/usr/bin/env node" works like "node".
    var shebangMatch = fileChunk.match(/^#!(?:\/usr\/bin\/env )?([^\r\n]+)/m);
    if (octetsRead == 4096 && !fileChunk.match(/[\r\n]/))
        events.emit('warn', 'shebang is too long for "' + fullpath + '"');
    if (shebangMatch)
        hookCmd = shebangMatch[1];
    // Likewise, make /usr/bin/bash work like "bash".
    if (hookCmd)
        shMatch = hookCmd.match(/bin\/((?:ba)?sh)$/);
    if (shMatch)
        hookCmd = shMatch[1];
    return hookCmd;
}
function extractSheBangInterpreter ( fullpath ) { var fileChunk ; var octetsRead ; var fileData ; var hookFd = fs . openSync ( fullpath , 'r' ) ; try { // this is a modern cluster size. no need to read less fileData = new Buffer ( 4096 ) ; octetsRead = fs . readSync ( hookFd , fileData , 0 , 4096 , 0 ) ; fileChunk = fileData . toString ( ) ; } finally { fs . closeSync ( hookFd ) ; } var hookCmd , shMatch ; // Filter out /usr/bin/env so that "/usr/bin/env node" works like "node". var shebangMatch = fileChunk . match ( / ^#!(?:\/usr\/bin\/env )?([^\r\n]+) / m ) ; if ( octetsRead == 4096 && ! fileChunk . match ( / [\r\n] / ) ) events . emit ( 'warn' , 'shebang is too long for "' + fullpath + '"' ) ; if ( shebangMatch ) hookCmd = shebangMatch [ 1 ] ; // Likewise, make /usr/bin/bash work like "bash". if ( hookCmd ) shMatch = hookCmd . match ( / bin\/((?:ba)?sh)$ / ) ; if ( shMatch ) hookCmd = shMatch [ 1 ] ; return hookCmd ; }
Extracts shebang interpreter from script' source.
Extracts shebang interpreter from script source .