mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
require npm module only as needed - shaves off a full second of loading time yay
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var start = process.hrtime();
|
||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
@@ -18,10 +19,12 @@ var fs = require('fs'),
|
|||||||
|
|
||||||
controllers = require('./controllers'),
|
controllers = require('./controllers'),
|
||||||
app, middleware;
|
app, middleware;
|
||||||
|
process.profile('requiring modules', start);
|
||||||
|
|
||||||
(function(Plugins) {
|
(function(Plugins) {
|
||||||
|
var start = process.hrtime();
|
||||||
require('./plugins/install')(Plugins);
|
require('./plugins/install')(Plugins);
|
||||||
|
process.profile('requiring modules 2', start);
|
||||||
require('./plugins/load')(Plugins);
|
require('./plugins/load')(Plugins);
|
||||||
require('./plugins/hooks')(Plugins);
|
require('./plugins/hooks')(Plugins);
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
var winston = require('winston'),
|
var winston = require('winston'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
npm = require('npm'),
|
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
@@ -88,10 +87,10 @@ module.exports = function(Plugins) {
|
|||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
npm.load({}, next);
|
require('npm').load({}, next);
|
||||||
},
|
},
|
||||||
function(res, next) {
|
function(res, next) {
|
||||||
npm.commands[type](installed ? id : [id + '@' + (version || 'latest')], next);
|
require('npm').commands[type](installed ? id : [id + '@' + (version || 'latest')], next);
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -111,10 +110,10 @@ module.exports = function(Plugins) {
|
|||||||
function upgrade(id, version, callback) {
|
function upgrade(id, version, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
npm.load({}, next);
|
require('npm').load({}, next);
|
||||||
},
|
},
|
||||||
function(res, next) {
|
function(res, next) {
|
||||||
npm.commands.install([id + '@' + (version || 'latest')], next);
|
require('npm').commands.install([id + '@' + (version || 'latest')], next);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user