commit
ab29c8e91c
|
@ -1,7 +1,6 @@
|
|||
var assert = require('assert');
|
||||
var _ = require('underscore');
|
||||
var semver = require('semver');
|
||||
var debug = require('debug')('loopback:boot:executor');
|
||||
|
||||
/**
|
||||
* Execute bootstrap instructions gathered by `boot.compile`.
|
||||
|
@ -146,7 +145,7 @@ function forEachKeyedObject(obj, fn) {
|
|||
function runScripts(app, list) {
|
||||
if (!list || !list.length) return;
|
||||
list.forEach(function(filepath) {
|
||||
var exports = tryRequire(filepath);
|
||||
var exports = require(filepath);
|
||||
if (isFunctionNotModelCtor(exports, app.loopback.Model))
|
||||
exports(app);
|
||||
});
|
||||
|
@ -157,19 +156,6 @@ function isFunctionNotModelCtor(fn, Model) {
|
|||
!(fn.prototype instanceof Model);
|
||||
}
|
||||
|
||||
function tryRequire(modulePath) {
|
||||
try {
|
||||
return require.apply(this, arguments);
|
||||
} catch(e) {
|
||||
if(e.code === 'MODULE_NOT_FOUND') {
|
||||
debug('Warning: cannot require %s - module not found.', modulePath);
|
||||
return undefined;
|
||||
}
|
||||
console.error('failed to require "%s"', modulePath);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated, will be removed soon
|
||||
function autoAttach(app) {
|
||||
try {
|
||||
|
|
|
@ -183,6 +183,17 @@ describe('executor', function() {
|
|||
expect(app.fnCalled, 'exported fn was called').to.be.true();
|
||||
});
|
||||
|
||||
it('throws on bad require() call inside model', function() {
|
||||
var file = appdir.writeFileSync('models/BadCustomer.js',
|
||||
'require("doesnt-exist"); module.exports = {};');
|
||||
|
||||
function doBoot() {
|
||||
boot.execute(app, someInstructions({ files: { models: [ file ] } }));
|
||||
}
|
||||
|
||||
expect(doBoot).to.throw(/Cannot find module \'doesnt-exist\'/);
|
||||
});
|
||||
|
||||
it('does not call Model ctor exported by models/model.json', function() {
|
||||
var file = appdir.writeFileSync('models/model.js',
|
||||
'var loopback = require("loopback");\n' +
|
||||
|
|
Loading…
Reference in New Issue