Browse Source

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>
archived-io.js-v0.10
Robert Kowalski 11 years ago
committed by Fedor Indutny
parent
commit
46ccb201cb
  1. 8
      lib/module.js

8
lib/module.js

@ -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…
Cancel
Save