(currentDir, context)
| 590 | }; |
| 591 | |
| 592 | const createRequire = (currentDir, context) => |
| 593 | function require(modulePath) { |
| 594 | const resolvedPath = path.resolve( |
| 595 | currentDir, |
| 596 | modulePath.endsWith(".js") ? modulePath : `${modulePath}.js` |
| 597 | ); |
| 598 | |
| 599 | const code = outputFileSystem.readFileSync(resolvedPath, "utf8"); |
| 600 | |
| 601 | const module = { exports: {} }; |
| 602 | const exports = module.exports; |
| 603 | |
| 604 | const wrapper = vm.runInNewContext( |
| 605 | `(function(exports, require, module, __filename, __dirname) { ${code} \n})`, |
| 606 | context |
| 607 | ); |
| 608 | |
| 609 | wrapper( |
| 610 | exports, |
| 611 | createRequire(path.dirname(resolvedPath)), |
| 612 | module, |
| 613 | resolvedPath, |
| 614 | path.dirname(resolvedPath) |
| 615 | ); |
| 616 | |
| 617 | return module.exports; |
| 618 | }; |
| 619 | |
| 620 | const create262Host = (context) => ({ |
| 621 | evalScript(code, options = {}) { |
no test coverage detected