From 553c175eb54e53936f53e5ffff8a3fcd0fb9f114 Mon Sep 17 00:00:00 2001 From: "Soren I. Bjornstad" Date: Sun, 15 Oct 2023 21:27:22 -0500 Subject: [PATCH] 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. --- tzk/tw.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/tzk/tw.py b/tzk/tw.py index 6fe7388..d9de5b6 100644 --- a/tzk/tw.py +++ b/tzk/tw.py @@ -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