Comparing version 0.2.1 to 0.2.2
@@ -51,12 +51,34 @@ 'use strict'; | ||
Migrator.prototype._createAdapter = function(adapter, params) { | ||
Migrator.prototype._tryLoadAdapter = function(path) { | ||
try { | ||
return new (require(adapter))(params); | ||
return require(path); | ||
} catch (err) { | ||
err.message = | ||
'Error while loading adapter `' + adapter + '`:\n' + err.message; | ||
throw err; | ||
return err; | ||
} | ||
}; | ||
Migrator.prototype._createAdapter = function(adapterPath, params) { | ||
// try load adapter from migrator-related path first then from cwd-related | ||
var paths = [adapterPath, path.join(process.cwd(), adapterPath)], | ||
Adapter, | ||
errors = []; | ||
for (var i = 0; i < paths.length; i++) { | ||
Adapter = this._tryLoadAdapter(paths[i]); | ||
if (Adapter instanceof Error) { | ||
errors.push(Adapter); | ||
} else { | ||
break; | ||
} | ||
} | ||
// if adapter is not loaded put all error messages into throwing error | ||
if (Adapter instanceof Error) { | ||
var error = new Error('Error loading adapter from all paths:\n'); | ||
errors.forEach(function(err) { | ||
error.message += '\n' + (err.stack || err.message) + '\n'; | ||
}); | ||
throw error; | ||
} | ||
return new Adapter(params); | ||
}; | ||
Migrator.prototype.init = function(callback) { | ||
@@ -63,0 +85,0 @@ if (this.isDirExists()) throw Error( |
{ | ||
"name": "east", | ||
"description": "node.js database migration tool", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"author": "Oleg Korobenko <oleg.korobenko@gmail.com>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
28749
473