Skip to content

Commit f2609c9

Browse files
committed
Avoid relying on Node’s internals
`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.
1 parent 89d3114 commit f2609c9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/tmp.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
* Module dependencies.
1111
*/
1212
const fs = require('fs');
13+
const os = require('os');
1314
const path = require('path');
1415
const crypto = require('crypto');
1516
const osTmpDir = require('os-tmpdir');
16-
const _c = process.binding('constants');
17+
const _c = fs.constants && os.constants ?
18+
{ fs: fs.constants, os: os.constants } :
19+
process.binding('constants');
1720

1821
/*
1922
* The working inner variables.
@@ -289,7 +292,7 @@ function fileSync(options) {
289292
var fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
290293
/* istanbul ignore else */
291294
if (opts.discardDescriptor) {
292-
fs.closeSync(fd);
295+
fs.closeSync(fd);
293296
fd = undefined;
294297
}
295298

0 commit comments

Comments
 (0)