Initialize globalThis for pmjs use in the extra-module context (eg -r, -e, -p). This context needs a require function which resolves modules relative to the current working directory at pmjs launch. The global require is to the JS function using a trick instead of a JS-wrapped-Python-wrapped
()
| 306 | |
| 307 | |
| 308 | def initGlobalThis(): |
| 309 | """ |
| 310 | Initialize globalThis for pmjs use in the extra-module context (eg -r, -e, -p). This context |
| 311 | needs a require function which resolves modules relative to the current working directory at pmjs |
| 312 | launch. The global require is to the JS function using a trick instead of a JS-wrapped-Python-wrapped function |
| 313 | """ |
| 314 | global requirePath |
| 315 | |
| 316 | require = pm.createRequire(os.path.abspath(os.getcwd() + '/__pmjs_virtual__'), requirePath) |
| 317 | globalThis.require = require |
| 318 | globalInitModule = require( |
| 319 | os.path.realpath( |
| 320 | os.path.dirname(__file__) + |
| 321 | "/../lib/pmjs/global-init")) # module load has side-effects |
| 322 | globalThis.arguments = sys.argv |
| 323 | return globalInitModule |
| 324 | |
| 325 | |
| 326 | def main(): |