1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-11-13 21:15:15 +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 including defaults and those provided by
previous --plugin-dirs previous --plugin-dirs
--js-runtimes RUNTIME[:PATH] Additional JavaScript runtime to enable, --js-runtimes RUNTIME[:PATH] Additional JavaScript runtime to enable,
with an optional path to the runtime with an optional location for the runtime
location. This option can be used multiple (either the path to the binary or its
times to enable multiple runtimes. Supported containing directory). This option can be
runtimes are (in order of priority, from used multiple times to enable multiple
highest to lowest): deno, node, quickjs, runtimes. Supported runtimes are (in order
bun. Only "deno" is enabled by default. The of priority, from highest to lowest): deno,
highest priority runtime that is both node, quickjs, bun. Only "deno" is enabled
enabled and available will be used. In order by default. The highest priority runtime
to use a lower priority runtime when "deno" that is both enabled and available will be
is available, --no-js-runtimes needs to be used. In order to use a lower priority
passed before enabling other runtimes runtime when "deno" is available, --no-js-
runtimes needs to be passed before enabling
other runtimes
--no-js-runtimes Clear JavaScript runtimes to enable, --no-js-runtimes Clear JavaScript runtimes to enable,
including defaults and those provided by including defaults and those provided by
previous --js-runtimes previous --js-runtimes

View File

@@ -466,7 +466,8 @@ def create_parser():
callback_kwargs={'delim': None}, callback_kwargs={'delim': None},
default=['deno'], default=['deno'],
help=( 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. ' '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. ' '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 ' '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 abc
import dataclasses import dataclasses
import functools import functools
import os.path
from ._utils import _get_exe_version_output, detect_exe_version, int_or_none 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('.')) 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) @dataclasses.dataclass(frozen=True)
class JsRuntimeInfo: class JsRuntimeInfo:
name: str name: str
@@ -38,7 +47,7 @@ class DenoJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (2, 0, 0) MIN_SUPPORTED_VERSION = (2, 0, 0)
def _info(self): def _info(self):
path = self._path or 'deno' path = _determine_runtime_path(self._path, 'deno')
out = _get_exe_version_output(path, ['--version']) out = _get_exe_version_output(path, ['--version'])
if not out: if not out:
return None return None
@@ -53,7 +62,7 @@ class BunJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (1, 0, 31) MIN_SUPPORTED_VERSION = (1, 0, 31)
def _info(self): def _info(self):
path = self._path or 'bun' path = _determine_runtime_path(self._path, 'bun')
out = _get_exe_version_output(path, ['--version']) out = _get_exe_version_output(path, ['--version'])
if not out: if not out:
return None return None
@@ -68,7 +77,7 @@ class NodeJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (20, 0, 0) MIN_SUPPORTED_VERSION = (20, 0, 0)
def _info(self): def _info(self):
path = self._path or 'node' path = _determine_runtime_path(self._path, 'node')
out = _get_exe_version_output(path, ['--version']) out = _get_exe_version_output(path, ['--version'])
if not out: if not out:
return None return None
@@ -83,7 +92,7 @@ class QuickJsRuntime(JsRuntime):
MIN_SUPPORTED_VERSION = (2023, 12, 9) MIN_SUPPORTED_VERSION = (2023, 12, 9)
def _info(self): 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 # quickjs does not have --version and --help returns a status code of 1
out = _get_exe_version_output(path, ['--help'], ignore_return_code=True) out = _get_exe_version_output(path, ['--help'], ignore_return_code=True)
if not out: if not out: