Execute `js` using given `node` executable.
(node: str, js: str)
| 127 | |
| 128 | @staticmethod |
| 129 | async def exec(node: str, js: str) -> str: |
| 130 | """Execute `js` using given `node` executable.""" |
| 131 | p = await asyncio.subprocess.create_subprocess_exec( |
| 132 | node, |
| 133 | stdin=asyncio.subprocess.PIPE, |
| 134 | stdout=asyncio.subprocess.PIPE, |
| 135 | stderr=asyncio.subprocess.PIPE, |
| 136 | executable=which(node), |
| 137 | ) |
| 138 | stdout, stderr = await p.communicate(js.encode()) |
| 139 | removesuffix = lambda s: s[:-1] if str.endswith(s, "\n") else s |
| 140 | if stderr: |
| 141 | raise JsRuntimeError(p.returncode or 1, node, removesuffix(stderr.decode())) |
| 142 | return removesuffix(stdout.decode()) |
| 143 | |
| 144 | def bind(self, expr: Optional[JsExpr] = None): |
| 145 | """Return an partial of `.exec`, with `node` set to :obj:`.node`, |
nothing calls this directly
no test coverage detected