Skip to content

Commit

Permalink
fix: remove function 'requireSafe'
Browse files Browse the repository at this point in the history
  • Loading branch information
gerard2perez committed Sep 20, 2017
1 parent 0ee01b0 commit 23bddf8
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 21 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ globals:
beforeEach: true
after: true
Kmetadata: true
requireSafe: true
requireNoCache: true
i18n: true

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function initialize () {
let routers = glob('koaton_modules/**/routes.js').concat(glob('routes.js'));
for (const router of routers) {
let location = path.dirname(router);
let PackageSubdomains = requireSafe(ProyPath(location, 'config', 'server.js'), {default: { subdomains: [] }}).default.subdomains;
let PackageSubdomains = require(ProyPath(location, 'config', 'server.js'), {default: { subdomains: [] }}).default.subdomains;
for (const subdomain of PackageSubdomains) {
if (!subdomainRouters[subdomain]) {
subdomainRouters[subdomain] = new KoatonRouter(subdomain);
Expand Down
4 changes: 2 additions & 2 deletions src/support/KoatonRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class KoatonRouter {
*/
static findAction (router, binding) {
let [controller, ...actions] = binding.split('.');
let content = requireSafe(ProyPath(router.loc, 'controllers', controller), null);
let content = require(ProyPath(router.loc, 'controllers', controller));
/* istanbul ignore if */
if (content && !content.default) {
console.warn(`${controller} controller does not export any default. This will not be supported`);
Expand Down Expand Up @@ -200,7 +200,7 @@ export default class KoatonRouter {
model = url;
url = undefined;
}
let controller = requireSafe(ProyPath(this.loc, 'controllers', model), {}).default;
let controller = require(ProyPath(this.loc, 'controllers', model), {}).default;
controller = Object.assign({
Name: model,
Namespace: '',
Expand Down
2 changes: 1 addition & 1 deletion src/support/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class Configuration {
let modules = glob(ProyPath('config', '**', '*.js'));
let moduleNames = [];
for (const configFile of modules) {
let config = requireSafe(configFile, {default: {}}).default;
let config = require(configFile, {default: {}}).default;
const moduleName = basename(configFile).replace(extname(configFile), '');
moduleNames.push(moduleName);
/** @ignore */
Expand Down
17 changes: 1 addition & 16 deletions src/support/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@ global.cleanString = (text) => {
return text.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
};

/**
* Makes a require with no errors or return defaults.
* @function requireSafe
* @param {String} lib - path to require.
* @param {Object=} [defaults={}] - Object to return if require fails.
* @returns {Object} The required library.
*/
global.requireSafe = function requireSafe (lib, defaults = {}) {
try {
return require(lib);
} catch (e) {
return defaults;
}
};

/**
* Makes a require with no cache. If fails return defaults.
* @function requireNoCache
Expand All @@ -61,7 +46,7 @@ global.requireNoCache = function requireNoCache (lib, defaults) {
library = library.replace('.js', ''); // + '.js';
}
delete require.cache[library];
return requireSafe(library, defaults);
return require(library, defaults);
};

/**
Expand Down

0 comments on commit 23bddf8

Please sign in to comment.