Skip to content

Commit

Permalink
Avoid relying on Node’s internals
Browse files Browse the repository at this point in the history
`process.binding()` is an internal API of Node, and
its use should be avoided.

Modern versions of Node have `constants` properties
on the individual public modules, so using these
and falling back to the `process.binding()` path
ensures that this module is unaffected by
changes to Node’s internals.
  • Loading branch information
addaleax committed Jan 27, 2018
1 parent 89d3114 commit f2609c9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/tmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
* Module dependencies.
*/
const fs = require('fs');
const os = require('os');
const path = require('path');
const crypto = require('crypto');
const osTmpDir = require('os-tmpdir');
const _c = process.binding('constants');
const _c = fs.constants && os.constants ?
{ fs: fs.constants, os: os.constants } :
process.binding('constants');

/*
* The working inner variables.
Expand Down Expand Up @@ -289,7 +292,7 @@ function fileSync(options) {
var fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
/* istanbul ignore else */
if (opts.discardDescriptor) {
fs.closeSync(fd);
fs.closeSync(fd);
fd = undefined;
}

Expand Down

0 comments on commit f2609c9

Please sign in to comment.