Remove compatibility layer for `util.getSystemErrorName()` (#221)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by Sindre Sorhus · parent 575d464 · Browse files · 3 files·+2 added−67 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+2 added−67 removed
- tests:+0 added−26 removed
- other:+2 added−41 removed
Provenance
- Commit
4cd3d35- Tree
7eaa235- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
575d464
3 files changed+2 added−67 removed
deleted:lib/errname.js-39 removed
123456789101112131415161718192021222324252627282930313233343536373839'use strict';// Older verions of Node.js might not have `util.getSystemErrorName()`.// In that case, fall back to a deprecated internal.const util = require('util');
let uv;
if (typeof util.getSystemErrorName === 'function') { module.exports = util.getSystemErrorName;} else { try { uv = process.binding('uv'); // eslint-disable-line node/no-deprecated-api
if (typeof uv.errname !== 'function') { throw new TypeError('uv.errname is not a function'); } } catch (error) { console.error('execa/lib/errname: unable to establish process.binding(\'uv\')', error); uv = undefined; }
module.exports = code => errname(uv, code);}
// Used for testing the fallback behaviormodule.exports.__test__ = errname;
function errname(uv, code) { if (uv !== undefined) { return uv.errname(code); }
if (!(code < 0)) { throw new Error('err >= 0'); }
return `Unknown system error ${code}`;}
deleted:test/errname.js-26 removed
1234567891011121314151617181920212223242526import test from 'ava';import errname from '../lib/errname';
const isWindows = process.platform === 'win32';
// Simulates failure to capture `process.binding('uv');`const fallback = code => errname.__test__(undefined, code);
function makeTests(name, m, expected) { test(`${name}: >=0 exit codes`, t => { // Throws >= 0 t.throws(() => m(0), /err >= 0|It must be a negative integer|must be of type negative number/); t.throws(() => m(1), /err >= 0|It must be a negative integer|must be of type negative number/); t.throws(() => m('2'), /err >= 0|must be of type number|must be of type negative number/); t.throws(() => m('foo'), /err >= 0|must be of type number|must be of type negative number/); });
test(`${name}: negative exit codes`, t => { t.is(m(-2), expected); });}
const unknown = 'Unknown system error -2';
makeTests('native', errname, isWindows ? unknown : 'ENOENT');makeTests('fallback', fallback, unknown);modified:index.js+2 added-2 removed
1 'use strict';2 const path = require('path');3 const os = require('os');4+const util = require('util');5 const childProcess = require('child_process');6 const crossSpawn = require('cross-spawn');7 const stripFinalNewline = require('strip-final-newline');8 const npmRunPath = require('npm-run-path');1 unmodified line10 const _getStream = require('get-stream');11 const mergeStream = require('merge-stream');12 const pFinally = require('p-finally');13 const onExit = require('signal-exit');13-const errname = require('./lib/errname');14 const stdio = require('./lib/stdio');15 16 const TEN_MEGABYTES = 1000 * 1000 * 10;17 201 unmodified lines219 return [error.code, os.constants.errno[error.code]];220 }221 222 if (Number.isInteger(code)) {223- return [errname(-Math.abs(code)), Math.abs(code)];223+ return [util.getSystemErrorName(-Math.abs(code)), Math.abs(code)];224 }225 226 return [];227 }272 unmodified lines