mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(tryRequire) add module name
This commit is contained in:
parent
38fd38f582
commit
bf825d6bf9
1 changed files with 9 additions and 5 deletions
|
|
@ -2,24 +2,28 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function tryRequire(name, options) {
|
||||
var module,
|
||||
var result,
|
||||
o = options || {},
|
||||
|
||||
error = tryCatch(function() {
|
||||
module = require(name);
|
||||
result = require(name);
|
||||
});
|
||||
|
||||
if (error) {
|
||||
if (o.log)
|
||||
console.error(error.message);
|
||||
console.error([
|
||||
module.parent.filename + ':',
|
||||
error.code,
|
||||
'\'' + name + '\'',
|
||||
].join(' '));
|
||||
else if (o.callback)
|
||||
module = exec.bind(null, error);
|
||||
result = exec.bind(null, error);
|
||||
|
||||
if (o.exit)
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return module;
|
||||
return result;
|
||||
};
|
||||
|
||||
function exec(error, callback) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue