Skip to content
Snippets Groups Projects
Commit 59433bfa authored by Jure's avatar Jure
Browse files

Merge branch 'fix_component_require' into 'master'

fix(server): require components relatively

See merge request pubsweet/pubsweet!415
parents 0f5fafc1 ce88a8ce
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,9 @@ const config = require('config')
const connector = require('./connector')
const models = require('../models')
const requireRelative = m =>
require(require.resolve(m, { paths: [process.cwd()] }))
const connectors = {
Collection: connector('Collection', models.Collection),
Fragment: connector('Fragment', models.Fragment),
......@@ -12,12 +15,11 @@ const connectors = {
// merge in component connectors, recursively
function getConnectorsRecursively(componentName) {
const component = require(componentName)
const component = requireRelative(componentName)
if (component.modelName) {
connectors[component.modelName] = connector(
component.modelName,
models[component.modelName],
component.model,
)
}
......
......@@ -5,17 +5,6 @@ const models = {
Team: './Team',
}
const config = require('config')
if (config.has('pubsweet.components')) {
config.get('pubsweet.components').forEach(name => {
const component = require(name)
if (component.model) {
module.exports[component.modelName] = component.model
}
})
}
Object.keys(models).forEach((key, _) => {
module.exports[key] = require(models[key])
})
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment