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 runInThisContext = require('vm').runInThisContext;
|
||||||
var runInNewContext = require('vm').runInNewContext;
|
var runInNewContext = require('vm').runInNewContext;
|
||||||
var assert = require('assert').ok;
|
var assert = require('assert').ok;
|
||||||
|
var fs = NativeModule.require('fs');
|
||||||
|
|
||||||
|
|
||||||
// If obj.hasOwnProperty has been overridden, then calling
|
// If obj.hasOwnProperty has been overridden, then calling
|
||||||
|
@ -81,7 +82,6 @@ var debug = Module._debug;
|
||||||
// -> a/index.<ext>
|
// -> a/index.<ext>
|
||||||
|
|
||||||
function statPath(path) {
|
function statPath(path) {
|
||||||
var fs = NativeModule.require('fs');
|
|
||||||
try {
|
try {
|
||||||
return fs.statSync(path);
|
return fs.statSync(path);
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
|
@ -96,7 +96,6 @@ function readPackage(requestPath) {
|
||||||
return packageMainCache[requestPath];
|
return packageMainCache[requestPath];
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs = NativeModule.require('fs');
|
|
||||||
try {
|
try {
|
||||||
var jsonPath = path.resolve(requestPath, 'package.json');
|
var jsonPath = path.resolve(requestPath, 'package.json');
|
||||||
var json = fs.readFileSync(jsonPath, 'utf8');
|
var json = fs.readFileSync(jsonPath, 'utf8');
|
||||||
|
@ -131,7 +130,6 @@ Module._realpathCache = {};
|
||||||
|
|
||||||
// check if the file exists and is not a directory
|
// check if the file exists and is not a directory
|
||||||
function tryFile(requestPath) {
|
function tryFile(requestPath) {
|
||||||
var fs = NativeModule.require('fs');
|
|
||||||
var stats = statPath(requestPath);
|
var stats = statPath(requestPath);
|
||||||
if (stats && !stats.isDirectory()) {
|
if (stats && !stats.isDirectory()) {
|
||||||
return fs.realpathSync(requestPath, Module._realpathCache);
|
return fs.realpathSync(requestPath, Module._realpathCache);
|
||||||
|
@ -476,14 +474,14 @@ function stripBOM(content) {
|
||||||
|
|
||||||
// Native extension for .js
|
// Native extension for .js
|
||||||
Module._extensions['.js'] = function(module, filename) {
|
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);
|
module._compile(stripBOM(content), filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Native extension for .json
|
// Native extension for .json
|
||||||
Module._extensions['.json'] = function(module, filename) {
|
Module._extensions['.json'] = function(module, filename) {
|
||||||
var content = NativeModule.require('fs').readFileSync(filename, 'utf8');
|
var content = fs.readFileSync(filename, 'utf8');
|
||||||
try {
|
try {
|
||||||
module.exports = JSON.parse(stripBOM(content));
|
module.exports = JSON.parse(stripBOM(content));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Reference in New Issue