From 46ccb201cb41b2979ce4127c67935cbf0932e15c Mon Sep 17 00:00:00 2001 From: Robert Kowalski Date: Thu, 3 Jul 2014 22:39:29 +0200 Subject: [PATCH] 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 --- lib/module.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/module.js b/lib/module.js index d310f93c17e..c0902327d30 100644 --- a/lib/module.js +++ b/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. 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) {