1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-11-13 13:05:13 +00:00

Allow --js-runtimes to accept path to binary or directory (#14964)

Fix 6224a38988

Authored by: bashonly
This commit is contained in:
bashonly
2025-11-09 09:14:22 -06:00
committed by GitHub
parent c63b4e2a2b
commit 4b4223b436
3 changed files with 28 additions and 16 deletions

View File

@@ -369,17 +369,19 @@ Tip: Use `CTRL`+`F` (or `Command`+`F`) to search by keywords
including defaults and those provided by
previous --plugin-dirs
--js-runtimes RUNTIME[:PATH] Additional JavaScript runtime to enable,
with an optional path to the runtime
location. This option can be used multiple
times to enable multiple runtimes. Supported
runtimes are (in order of priority, from
highest to lowest): deno, node, quickjs,
bun. Only "deno" is enabled by default. The
highest priority runtime that is both
enabled and available will be used. In order
to use a lower priority runtime when "deno"
is available, --no-js-runtimes needs to be
passed before enabling other runtimes
with an optional location for the runtime
(either the path to the binary or its
containing directory). This option can be
used multiple times to enable multiple
runtimes. Supported runtimes are (in order
of priority, from highest to lowest): deno,
node, quickjs, bun. Only "deno" is enabled
by default. The highest priority runtime
that is both enabled and available will be
used. In order to use a lower priority
runtime when "deno" is available, --no-js-
runtimes needs to be passed before enabling
other runtimes
--no-js-runtimes Clear JavaScript runtimes to enable,
including defaults and those provided by
previous --js-runtimes

View File

@@ -466,7 +466,8 @@ def create_parser():
callback_kwargs={'delim': None},
default=['deno'],
help=(
'Additional JavaScript runtime to enable, with an optional path to the runtime location. '
'Additional JavaScript runtime to enable, with an optional location for the runtime '
'(either the path to the binary or its containing directory). '
'This option can be used multiple times to enable multiple runtimes. '
'Supported runtimes are (in order of priority, from highest to lowest): deno, node, quickjs, bun. '
'Only "deno" is enabled by default. The highest priority runtime that is both enabled and '

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
import abc
import dataclasses
import functools
import os.path
from ._utils import _get_exe_version_output, detect_exe_version, int_or_none
@@ -12,6 +13,14 @@ def runtime_version_tuple(v):
return tuple(int_or_none(x, default=0) for x in v.split('.'))
def _determine_runtime_path(path, basename):
if not path:
return basename
if os.path.isdir(path):
return os.path.join(path, basename)
return path
@dataclasses.dataclass(frozen=True)
class JsRuntimeInfo:
name: str
@@ -38,7 +47,7 @@ class DenoJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (2, 0, 0)
def _info(self):
path = self._path or 'deno'
path = _determine_runtime_path(self._path, 'deno')
out = _get_exe_version_output(path, ['--version'])
if not out:
return None
@@ -53,7 +62,7 @@ class BunJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (1, 0, 31)
def _info(self):
path = self._path or 'bun'
path = _determine_runtime_path(self._path, 'bun')
out = _get_exe_version_output(path, ['--version'])
if not out:
return None
@@ -68,7 +77,7 @@ class NodeJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (20, 0, 0)
def _info(self):
path = self._path or 'node'
path = _determine_runtime_path(self._path, 'node')
out = _get_exe_version_output(path, ['--version'])
if not out:
return None
@@ -83,7 +92,7 @@ class QuickJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (2023, 12, 9)
def _info(self):
path = self._path or 'qjs'
path = _determine_runtime_path(self._path, 'qjs')
# quickjs does not have --version and --help returns a status code of 1
out = _get_exe_version_output(path, ['--help'], ignore_return_code=True)
if not out: