function requireFromString(src, filename = 'tmp.js') {
  const srcWithPath = `const path = require('path');\n${src}`;
  // @ts-expect-error
  const m = new module.constructor();
  // @ts-expect-error
  m.paths = module.paths;
  m._compile(srcWithPath, filename);
  return m.exports;
}
Allows to execute an actual node module code block.
Supports imports (via require) within those code blocks.

@example
  const virtualMod = requireFromString('module.export = { a: "a value", fn: () => {} }');
  console.log(virtualMod.a); // a value
  // execute function
  virtualMod.fn();

@param {string} src
@param {string} filename
@returns {object}