Skip to content

Commit

Permalink
fs: add a temporary fix for re-evaluation support
Browse files Browse the repository at this point in the history
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: nodejs#5097, see also nodejs#1898, nodejs#2026, and nodejs#4525.
PR-URL: nodejs#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>
  • Loading branch information
ChALkeR authored and stefanmb committed Feb 23, 2016
1 parent 239bf75 commit cb0e317
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' +
Expand Down

0 comments on commit cb0e317

Please sign in to comment.