Skip to content

Commit 1d79787

Browse files
ChALkeRjasnell
authored andcommitted
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: #5102 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 00638ac commit 1d79787

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

lib/fs.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,42 @@ const isWindows = process.platform === 'win32';
3535

3636
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
3737
const errnoException = util._errnoException;
38-
const printDeprecation = require('internal/util').printDeprecationMessage;
38+
39+
var printDeprecation;
40+
try {
41+
printDeprecation = require('internal/util').printDeprecationMessage;
42+
} catch (e) {
43+
if (e.code !== 'MODULE_NOT_FOUND') throw e;
44+
45+
// TODO(ChALkeR): remove this in master after 6.x
46+
// This code was based upon internal/util and is required to give users
47+
// a grace period before actually breaking modules that re-evaluate fs
48+
// sources from context where internal modules are not allowed, e.g.
49+
// older versions of graceful-fs module.
50+
51+
const prefix = `(${process.release.name}:${process.pid}) `;
52+
53+
printDeprecation = function(msg, warned) {
54+
if (process.noDeprecation)
55+
return true;
56+
57+
if (warned)
58+
return warned;
59+
60+
if (process.throwDeprecation)
61+
throw new Error(`${prefix}${msg}`);
62+
else if (process.traceDeprecation)
63+
console.trace(msg);
64+
else
65+
console.error(`${prefix}${msg}`);
66+
67+
return true;
68+
};
69+
printDeprecation('fs: re-evaluating native module sources is not ' +
70+
'supported. If you are using the graceful-fs module, ' +
71+
'please update it to a more recent version.',
72+
false);
73+
}
3974

4075
function throwOptionsError(options) {
4176
throw new TypeError('Expected options to be either an object or a string, ' +

0 commit comments

Comments
 (0)