Sha256: 0eff3981c2f85bfab685c8f104bc910f782fa3547fc96a62aa32ef3f64ca6df4

Contents?: true

Size: 1.45 KB

Versions: 138

Compression:

Stored size: 1.45 KB

Contents

'use strict';

const isWin = process.platform === 'win32';

function notFoundError(original, syscall) {
    return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
        code: 'ENOENT',
        errno: 'ENOENT',
        syscall: `${syscall} ${original.command}`,
        path: original.command,
        spawnargs: original.args,
    });
}

function hookChildProcess(cp, parsed) {
    if (!isWin) {
        return;
    }

    const originalEmit = cp.emit;

    cp.emit = function (name, arg1) {
        // If emitting "exit" event and exit code is 1, we need to check if
        // the command exists and emit an "error" instead
        // See https://github.com/IndigoUnited/node-cross-spawn/issues/16
        if (name === 'exit') {
            const err = verifyENOENT(arg1, parsed, 'spawn');

            if (err) {
                return originalEmit.call(cp, 'error', err);
            }
        }

        return originalEmit.apply(cp, arguments); // eslint-disable-line prefer-rest-params
    };
}

function verifyENOENT(status, parsed) {
    if (isWin && status === 1 && !parsed.file) {
        return notFoundError(parsed.original, 'spawn');
    }

    return null;
}

function verifyENOENTSync(status, parsed) {
    if (isWin && status === 1 && !parsed.file) {
        return notFoundError(parsed.original, 'spawnSync');
    }

    return null;
}

module.exports = {
    hookChildProcess,
    verifyENOENT,
    verifyENOENTSync,
    notFoundError,
};

Version data entries

138 entries across 136 versions & 16 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.50 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.49 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.48 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.47 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.46 node_modules/cross-spawn/lib/enoent.js
pcp-server-ruby-sdk-0.0.6 node_modules/cross-spawn/lib/enoent.js
pcp-server-ruby-sdk-0.1.0 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.45 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.44 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.43 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.42 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.41 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.40 node_modules/cross-spawn/lib/enoent.js
wice_grid-7.1.0 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.39 node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.38 node_modules/cross-spawn/lib/enoent.js
optimacms-0.1.61 spec/dummy/node_modules/webpack-cli/node_modules/cross-spawn/lib/enoent.js
optimacms-0.1.61 spec/dummy/node_modules/execa/node_modules/cross-spawn/lib/enoent.js
immosquare-cleaner-0.1.32 node_modules/cross-spawn/lib/enoent.js