mirror of https://github.com/nodejs/node.git
module: don't require fs several times
As we are going to need fs in any case, just require it at the beginning of the file. Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
parent
df205360f5
commit
46ccb201cb
|
@ -24,6 +24,7 @@ var util = NativeModule.require('util');
|
|||
var runInThisContext = require('vm').runInThisContext;
|
||||
var runInNewContext = require('vm').runInNewContext;
|
||||
var assert = require('assert').ok;
|
||||
var fs = NativeModule.require('fs');
|
||||
|
||||
|
||||
// If obj.hasOwnProperty has been overridden, then calling
|
||||
|
@ -81,7 +82,6 @@ var debug = Module._debug;
|
|||
// -> a/index.<ext>
|
||||
|
||||
function statPath(path) {
|
||||
var fs = NativeModule.require('fs');
|
||||
try {
|
||||
return fs.statSync(path);
|
||||
} catch (ex) {}
|
||||
|
@ -96,7 +96,6 @@ function readPackage(requestPath) {
|
|||
return packageMainCache[requestPath];
|
||||
}
|
||||
|
||||
var fs = NativeModule.require('fs');
|
||||
try {
|
||||
var jsonPath = path.resolve(requestPath, 'package.json');
|
||||
var json = fs.readFileSync(jsonPath, 'utf8');
|
||||
|
@ -131,7 +130,6 @@ Module._realpathCache = {};
|
|||
|
||||
// check if the file exists and is not a directory
|
||||
function tryFile(requestPath) {
|
||||
var fs = NativeModule.require('fs');
|
||||
var stats = statPath(requestPath);
|
||||
if (stats && !stats.isDirectory()) {
|
||||
return fs.realpathSync(requestPath, Module._realpathCache);
|
||||
|
@ -476,14 +474,14 @@ function stripBOM(content) {
|
|||
|
||||
// Native extension for .js
|
||||
Module._extensions['.js'] = function(module, filename) {
|
||||
var content = NativeModule.require('fs').readFileSync(filename, 'utf8');
|
||||
var content = fs.readFileSync(filename, 'utf8');
|
||||
module._compile(stripBOM(content), filename);
|
||||
};
|
||||
|
||||
|
||||
// Native extension for .json
|
||||
Module._extensions['.json'] = function(module, filename) {
|
||||
var content = NativeModule.require('fs').readFileSync(filename, 'utf8');
|
||||
var content = fs.readFileSync(filename, 'utf8');
|
||||
try {
|
||||
module.exports = JSON.parse(stripBOM(content));
|
||||
} catch (err) {
|
||||
|
|
Loading…
Reference in New Issue