From cf89836a4dc627cdaf8284ea1d13aaea31722b7e Mon Sep 17 00:00:00 2001 From: detachhead Date: Wed, 8 May 2024 13:53:13 +1000 Subject: [PATCH] remove hacky workarounds for calling node now that there's an api for it --- basedpyright/run_node.py | 6 ++++-- pdm_build.py | 25 +++++++++++-------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/basedpyright/run_node.py b/basedpyright/run_node.py index e968cb378..417e04b66 100644 --- a/basedpyright/run_node.py +++ b/basedpyright/run_node.py @@ -3,8 +3,10 @@ import sys from pathlib import Path -from nodejs_wheel import executable # pyright:ignore[reportMissingTypeStubs] +from nodejs_wheel.executable import ( # pyright:ignore[reportMissingTypeStubs] + node, # pyright:ignore[reportUnknownVariableType] +) def run(script_name: str): - sys.exit(executable.call_node(Path(__file__).parent / f"{script_name}.js", *sys.argv[1:])) # pyright:ignore[reportUnknownMemberType] + sys.exit(node([Path(__file__).parent / f"{script_name}.js", *sys.argv[1:]])) diff --git a/pdm_build.py b/pdm_build.py index 37b2fe6f0..ed0778192 100644 --- a/pdm_build.py +++ b/pdm_build.py @@ -1,30 +1,27 @@ from __future__ import annotations -import sys from json import loads from pathlib import Path from shutil import copyfile, copytree -from subprocess import run # noqa: S404 from typing import TypedDict, cast -from nodejs_wheel.executable import ROOT_DIR # pyright:ignore[reportMissingTypeStubs] - -node_exe = Path(ROOT_DIR, ("node.exe" if sys.platform == "win32" else "bin/node")) - -npm_script = Path(ROOT_DIR, "lib", "node_modules", "npm", "bin", "npm-cli.js") - - -# Remove when https://github.com/njzjz/nodejs-wheel/pull/24 is merged -def npm(cmd: list[str]): - _ = run([node_exe, npm_script, *cmd], check=True) # noqa: S603 +from nodejs_wheel.executable import ( # pyright:ignore[reportMissingTypeStubs] + npm, # pyright:ignore[reportUnknownVariableType] +) class PackageJson(TypedDict): bin: dict[str, str] -npm(["ci"]) -npm(["run", "build:cli:dev"]) +def run_npm(*args: str): + exit_code = npm(args) + if exit_code != 0: + raise Exception(f"the following npm command exited with {exit_code=}: {args}") + + +run_npm("ci") +run_npm("run", "build:cli:dev") npm_package_dir = Path("packages/pyright") pypi_package_dir = Path("basedpyright")