mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

Remove a hack that was introduced in commit bb6d468d
from November 2010.
This is groundwork for a follow-up commit that makes it possible to use
internal modules in lib/repl.js.
PR-URL: https://github.com/nodejs/node/pull/4026
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
40 lines
952 B
JavaScript
40 lines
952 B
JavaScript
'use strict';
|
|
|
|
module.exports = { makeRequireFunction, stripBOM };
|
|
|
|
// Invoke with makeRequireFunction.call(module) where |module| is the
|
|
// Module object to use as the context for the require() function.
|
|
function makeRequireFunction() {
|
|
const Module = this.constructor;
|
|
const self = this;
|
|
|
|
function require(path) {
|
|
return self.require(path);
|
|
}
|
|
|
|
require.resolve = function(request) {
|
|
return Module._resolveFilename(request, self);
|
|
};
|
|
|
|
require.main = process.mainModule;
|
|
|
|
// Enable support to add extra extension types.
|
|
require.extensions = Module._extensions;
|
|
|
|
require.cache = Module._cache;
|
|
|
|
return require;
|
|
}
|
|
|
|
/**
|
|
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
|
* because the buffer-to-string conversion in `fs.readFileSync()`
|
|
* translates it to FEFF, the UTF-16 BOM.
|
|
*/
|
|
function stripBOM(content) {
|
|
if (content.charCodeAt(0) === 0xFEFF) {
|
|
content = content.slice(1);
|
|
}
|
|
return content;
|
|
}
|