From f2609c943aed96b75c51c00e0ae0584124994b21 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 27 Jan 2018 22:18:40 +0100 Subject: [PATCH] =?UTF-8?q?Avoid=20relying=20on=20Node=E2=80=99s=20interna?= =?UTF-8?q?ls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- lib/tmp.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tmp.js b/lib/tmp.js index 4ce81dd..ba6728a 100644 --- a/lib/tmp.js +++ b/lib/tmp.js @@ -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. @@ -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; }