From 1d79787e2e792fb0b5088958fe2cca703e4ea508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Fri, 5 Feb 2016 20:03:37 +0300 Subject: [PATCH] fs: add a temporary fix for re-evaluation support This is needed to give users a grace period before actually breaking modules that re-evaluate fs sources from context where internal modules are not allowed, e.g. older version of graceful-fs module. To be reverted in Node.js 7.0 Fixes: #5097, see also #1898, #2026, and #4525. PR-URL: https://github.com/nodejs/node/pull/5102 Reviewed-By: Rod Vagg Reviewed-By: Jeremiah Senkpiel Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- lib/fs.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index 1ffb1a7ab699d1..1fd40b9f4fcada 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -35,7 +35,42 @@ const isWindows = process.platform === 'win32'; const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG); const errnoException = util._errnoException; -const printDeprecation = require('internal/util').printDeprecationMessage; + +var printDeprecation; +try { + printDeprecation = require('internal/util').printDeprecationMessage; +} catch (e) { + if (e.code !== 'MODULE_NOT_FOUND') throw e; + + // TODO(ChALkeR): remove this in master after 6.x + // This code was based upon internal/util and is required to give users + // a grace period before actually breaking modules that re-evaluate fs + // sources from context where internal modules are not allowed, e.g. + // older versions of graceful-fs module. + + const prefix = `(${process.release.name}:${process.pid}) `; + + printDeprecation = function(msg, warned) { + if (process.noDeprecation) + return true; + + if (warned) + return warned; + + if (process.throwDeprecation) + throw new Error(`${prefix}${msg}`); + else if (process.traceDeprecation) + console.trace(msg); + else + console.error(`${prefix}${msg}`); + + return true; + }; + printDeprecation('fs: re-evaluating native module sources is not ' + + 'supported. If you are using the graceful-fs module, ' + + 'please update it to a more recent version.', + false); +} function throwOptionsError(options) { throw new TypeError('Expected options to be either an object or a string, ' +