remove uses of "npm bin"

This was removed from recent Node versions. Using 'npx' is the new way
and should resolve this issue.

I suppose we might run into someone who had a non-working npx and it
breaks, but we'll cross that bridge when we come to it; it works in my
testing and there are people broken in the current version.
This commit is contained in:
Soren I. Bjornstad 2023-10-15 21:27:22 -05:00
parent 650b21a03d
commit 553c175eb5

View File

@ -7,20 +7,10 @@ import subprocess
from textwrap import dedent
from typing import Callable, Optional, Sequence
from tzk import config
from tzk import git
from tzk.util import pushd
@functools.lru_cache(1)
def _npm_bin() -> str:
return subprocess.check_output(("npm", "bin"), text=True).strip()
def _tw_path() -> str:
return _npm_bin() + "/tiddlywiki"
@functools.lru_cache(1)
def _whoami() -> str:
"Try to guess the user's name."
@ -47,9 +37,9 @@ def exec(args: Sequence[Sequence[str]], base_wiki_folder: str = None) -> int:
# must pushd into base wiki to find the tiddlywiki node_modules
if base_wiki_folder is not None:
with pushd(base_wiki_folder):
call_args = [_tw_path()]
call_args = ["npx", "tiddlywiki"]
else:
call_args = [_tw_path()]
call_args = ["npx", "tiddlywiki"]
if base_wiki_folder is not None:
call_args.append(base_wiki_folder)
@ -114,7 +104,7 @@ def _init_tw(wiki_name: str) -> None:
old_edition_path = os.environ.get('TIDDLYWIKI_EDITION_PATH')
os.environ['TIDDLYWIKI_EDITION_PATH'] = str(Path(__file__).parent / "editions")
try:
subprocess.check_call((_tw_path(), "--init", "tzk"))
subprocess.check_call(("npx", "tiddlywiki", "--init", "tzk"))
finally:
if old_edition_path:
os.environ['TIDDLYWIKI_EDITION_PATH'] = old_edition_path