function evaluateModule(baseDir, packageId, name, source) {
  const Module = require('module');
  let implementation;
  try {
    // Use the Node.js module API to evaluate in the correct directory context
    const modulePath = path.resolve(baseDir, `./components/${name}.js`);
    const moduleImpl = new Module(modulePath, module);
    // @ts-ignore
    moduleImpl.paths = Module._nodeModulePaths(path.dirname(modulePath));
    moduleImpl.filename = modulePath;
    // @ts-ignore
    moduleImpl._compile(source, modulePath);
    implementation = moduleImpl.exports;
  } catch (e) {
    return Promise.reject(e);
  }
  if ((typeof implementation !== 'function') && (typeof implementation.getComponent !== 'function')) {
    return Promise.reject(new Error(`Provided source for ${packageId}/${name} failed to create a runnable component`));
  }
  return Promise.resolve(implementation);
}
@param {string} baseDir
@param {string} packageId
@param {string} name
@param {string} source
@returns {Promise<Object|Function>}