mirror of
https://github.com/yt-dlp/ejs.git
synced 2026-06-13 00:32:11 +00:00
30
.github/workflows/ci.yml
vendored
30
.github/workflows/ci.yml
vendored
@@ -46,12 +46,12 @@ jobs:
|
||||
uses: denoland/setup-deno@v2
|
||||
with:
|
||||
deno-version: v2.x
|
||||
- name: Install Deno requirements
|
||||
- name: Install requirements
|
||||
run: |
|
||||
deno install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
- name: Run Prettier check
|
||||
run: |
|
||||
deno task fmt:check
|
||||
python pnpm.py fmt:check
|
||||
|
||||
eslint:
|
||||
name: ESLint check
|
||||
@@ -62,12 +62,12 @@ jobs:
|
||||
uses: denoland/setup-deno@v2
|
||||
with:
|
||||
deno-version: v2.x
|
||||
- name: Install Deno requirements
|
||||
- name: Install requirements
|
||||
run: |
|
||||
deno install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
- name: Run ESLint check
|
||||
run: |
|
||||
deno task lint
|
||||
python pnpm.py lint
|
||||
|
||||
python_tests:
|
||||
name: Python tests
|
||||
@@ -117,12 +117,12 @@ jobs:
|
||||
uses: denoland/setup-deno@v2
|
||||
with:
|
||||
deno-version: v2.x
|
||||
- name: Install Deno requirements
|
||||
- name: Install requirements
|
||||
run: |
|
||||
deno install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
- name: Build control bundle
|
||||
run: |
|
||||
deno task bundle
|
||||
python pnpm.py run bundle
|
||||
- name: Generate bundle hashes
|
||||
run: |
|
||||
pushd dist
|
||||
@@ -189,7 +189,7 @@ jobs:
|
||||
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
||||
- name: Install Deno requirements
|
||||
run: |
|
||||
deno install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
- name: Bundle with Deno
|
||||
run: |
|
||||
deno task bundle
|
||||
@@ -215,7 +215,7 @@ jobs:
|
||||
deno-version: "2.0.0" # minimum supported version
|
||||
- name: Install Deno requirements
|
||||
run: |
|
||||
deno install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
- name: Download player JS artifact
|
||||
uses: actions/download-artifact@v5
|
||||
with:
|
||||
@@ -256,7 +256,7 @@ jobs:
|
||||
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
||||
- name: Install Bun requirements
|
||||
run: |
|
||||
bun install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
- name: Bundle with Bun
|
||||
run: |
|
||||
bun --bun run bundle
|
||||
@@ -282,7 +282,7 @@ jobs:
|
||||
bun-version: "1.2.11" # XXX: We support 1.0.31, but test suite requires 1.2.11+
|
||||
- name: Install Bun requirements
|
||||
run: |
|
||||
bun install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
- name: Download player JS artifact
|
||||
uses: actions/download-artifact@v5
|
||||
with:
|
||||
@@ -321,7 +321,7 @@ jobs:
|
||||
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
||||
- name: Install Node requirements
|
||||
run: |
|
||||
npm install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
- name: Bundle with Node
|
||||
run: |
|
||||
npm run bundle
|
||||
@@ -347,7 +347,7 @@ jobs:
|
||||
node-version: "22.18" # XXX: We support 20.0, but test suite requires 22.18+
|
||||
- name: Install Node requirements
|
||||
run: |
|
||||
npm install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
- name: Download player JS artifact
|
||||
uses: actions/download-artifact@v5
|
||||
with:
|
||||
|
||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -37,7 +37,7 @@ jobs:
|
||||
compression-level: 0
|
||||
- name: Build JavaScript artifacts
|
||||
run: |
|
||||
deno install --frozen
|
||||
python pnpm.py install --frozen-lockfile
|
||||
deno task bundle
|
||||
- name: Upload JavaScript artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@
|
||||
/yt_dlp_ejs/_version.py
|
||||
/node_modules
|
||||
/bun.lock
|
||||
/deno.lock
|
||||
/package-lock.json
|
||||
/.idea
|
||||
/.venv
|
||||
|
||||
33
README.md
33
README.md
@@ -12,9 +12,13 @@ pip install -U yt-dlp-ejs
|
||||
|
||||
## Development
|
||||
|
||||
While this project does pin its dependencies,
|
||||
it only provides a lockfile for building with `deno`.
|
||||
You may install dependencies using any compatible package manager.
|
||||
The project uses [`pnpm`](<https://github.com/pnpm/pnpm>) as a package manager with
|
||||
dependencies pinned through `pnpm-lock.yaml`.
|
||||
|
||||
If you only have Python and a JS runtime you may instead invoke `./pnpm.py`,
|
||||
which will transparently invoke one of the supported JS runtimes to call `pnpm`.
|
||||
|
||||
This pure JavaScript approach should be runtime agnostic.
|
||||
If you notice differences between different runtimes' builds
|
||||
please open an issue [here](<https://github.com/yt-dlp/ejs/issues/new>).
|
||||
|
||||
@@ -26,34 +30,27 @@ The build hook will automatically invoke `deno`, `bun` or `node` as required.
|
||||
Alternatively, to only build the JavaScript files you can run the `bundle` script manually:
|
||||
|
||||
```bash
|
||||
# Deno:
|
||||
deno install --frozen
|
||||
deno task bundle
|
||||
|
||||
# Bun:
|
||||
bun install
|
||||
bun --bun run bundle
|
||||
|
||||
# Node:
|
||||
npm install
|
||||
npm run bundle
|
||||
python pnpm.py install --frozen-lockfile
|
||||
python pnpm.py run bundle
|
||||
```
|
||||
|
||||
This will automatically select an available runtime and invoke `pnpm` to build it.
|
||||
|
||||
### Tests
|
||||
|
||||
First, make sure the project's dependencies are installed and download the player JS files:
|
||||
|
||||
```bash
|
||||
# Deno:
|
||||
deno install --frozen
|
||||
python pnpm.py install --frozen-lockfile
|
||||
deno run src/yt/solver/test/download.ts
|
||||
|
||||
# Bun:
|
||||
bun install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
bun --bun run src/yt/solver/test/download.ts
|
||||
|
||||
# Node 22.6+:
|
||||
npm install
|
||||
python pnpm.py install --frozen-lockfile
|
||||
node --experimental-strip-types src/yt/solver/test/download.ts
|
||||
```
|
||||
|
||||
@@ -74,6 +71,6 @@ node --test
|
||||
|
||||
This code is licensed under [Unlicense](<https://unlicense.org/>).
|
||||
|
||||
An exception to this are the prebuilt wheels, which contain both
|
||||
An exception to this is the prebuilt wheels, which contain both
|
||||
[`meriyah`](<https://github.com/meriyah/meriyah>) and [`astring`](<https://github.com/davidbonnet/astring>),
|
||||
licensed under [`ISC`](<https://github.com/meriyah/meriyah?tab=ISC-1-ov-file>) and [`MIT`](<https://github.com/davidbonnet/astring?tab=MIT-1-ov-file>), respectively.
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||||
|
||||
|
||||
class CustomBuildHook(BuildHookInterface):
|
||||
def initialize(self, version, build_data):
|
||||
if shutil.which("deno"):
|
||||
print("Building with deno...", flush=True)
|
||||
os.environ["DENO_NO_UPDATE_CHECK"] = "1"
|
||||
subprocess.run(["deno", "install", "--frozen"], check=True)
|
||||
subprocess.run(["deno", "task", "bundle"], check=True)
|
||||
|
||||
elif shutil.which("bun"):
|
||||
print("Building with bun...", flush=True)
|
||||
subprocess.run(["bun", "install"], check=True)
|
||||
subprocess.run(["bun", "--bun", "run", "bundle"], check=True)
|
||||
|
||||
elif shutil.which("npm"):
|
||||
print("Building with npm...", flush=True)
|
||||
# npm is a batch file (`npm.cmd`) on windows, which requires `shell=True`
|
||||
requires_shell = os.name == "nt"
|
||||
subprocess.run(["npm", "install"], check=True, shell=requires_shell)
|
||||
subprocess.run(["npm", "run", "bundle"], check=True, shell=requires_shell)
|
||||
|
||||
else:
|
||||
raise RuntimeError(
|
||||
"One of 'deno', 'bun', or 'npm' could not be found. "
|
||||
"Please install one of them to proceed with the build."
|
||||
)
|
||||
|
||||
build_data["force_include"].update(
|
||||
{
|
||||
"dist/yt.solver.core.min.js": "yt_dlp_ejs/yt/solver/core.min.js",
|
||||
"dist/yt.solver.lib.min.js": "yt_dlp_ejs/yt/solver/lib.min.js",
|
||||
}
|
||||
)
|
||||
|
||||
def clean(self, versions):
|
||||
shutil.rmtree("node_modules", ignore_errors=True)
|
||||
@@ -25,5 +25,6 @@
|
||||
"rollup": "4.52.5",
|
||||
"rollup-plugin-license": "3.6.0",
|
||||
"typescript-eslint": "8.46.2"
|
||||
}
|
||||
},
|
||||
"packageManager": "pnpm@10.24.0"
|
||||
}
|
||||
|
||||
1782
pnpm-lock.yaml
generated
Normal file
1782
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
86
pnpm.py
Executable file
86
pnpm.py
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||||
except ImportError:
|
||||
BuildHookInterface = object
|
||||
|
||||
|
||||
class CustomBuildHook(BuildHookInterface):
|
||||
def initialize(self, version, build_data):
|
||||
name, pnpm = build_pnpm()
|
||||
if pnpm is None:
|
||||
raise RuntimeError(
|
||||
"One of 'deno', 'bun', or 'npm' could not be found. "
|
||||
"Please install one of them to proceed with the build."
|
||||
)
|
||||
print(f"Building with {name}...")
|
||||
|
||||
pnpm(["install", "--frozen-lockfile"])
|
||||
pnpm(["run", "bundle"])
|
||||
|
||||
build_data["force_include"].update(
|
||||
{
|
||||
"dist/yt.solver.core.min.js": "yt_dlp_ejs/yt/solver/core.min.js",
|
||||
"dist/yt.solver.lib.min.js": "yt_dlp_ejs/yt/solver/lib.min.js",
|
||||
}
|
||||
)
|
||||
|
||||
def clean(self, versions):
|
||||
shutil.rmtree("node_modules", ignore_errors=True)
|
||||
|
||||
|
||||
def build_pnpm():
|
||||
package_json = pathlib.Path(__file__).with_name("package.json")
|
||||
with package_json.open("rb") as file:
|
||||
data = json.load(file)
|
||||
|
||||
package_manager = data["packageManager"]
|
||||
env = os.environ.copy()
|
||||
|
||||
if deno := shutil.which("deno"):
|
||||
name = "deno"
|
||||
env["DENO_NO_UPDATE_CHECK"] = "1"
|
||||
cmd = [
|
||||
deno,
|
||||
"run",
|
||||
"--allow-all",
|
||||
"--node-modules-dir=none",
|
||||
f"npm:{package_manager}",
|
||||
]
|
||||
|
||||
elif bun := shutil.which("bun"):
|
||||
name = "bun"
|
||||
cmd = [bun, "x", package_manager]
|
||||
|
||||
elif npm := shutil.which("npm"):
|
||||
name = "npm (node)"
|
||||
cmd = [npm, "exec", "--", package_manager]
|
||||
|
||||
else:
|
||||
return None, None
|
||||
|
||||
def pnpm(args: list[str]):
|
||||
return subprocess.check_call([*cmd, *args], env=env)
|
||||
|
||||
return name, pnpm
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
name, pnpm = build_pnpm()
|
||||
if pnpm is None:
|
||||
print("ERROR: No suitable JavaScript runtime found", file=sys.stderr)
|
||||
sys.exit(128)
|
||||
print(f"Calling {name}...", file=sys.stderr)
|
||||
|
||||
try:
|
||||
pnpm(sys.argv[1:])
|
||||
except subprocess.CalledProcessError as error:
|
||||
sys.exit(error.returncode)
|
||||
@@ -57,6 +57,7 @@ packages = ["yt_dlp_ejs"]
|
||||
version-file = "yt_dlp_ejs/_version.py"
|
||||
|
||||
[tool.hatch.build.targets.wheel.hooks.custom]
|
||||
path = "pnpm.py"
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = [
|
||||
|
||||
Reference in New Issue
Block a user