mirror of
https://github.com/yt-dlp/ejs.git
synced 2026-06-13 08:42:29 +00:00
30
.github/workflows/ci.yml
vendored
30
.github/workflows/ci.yml
vendored
@@ -46,12 +46,12 @@ jobs:
|
|||||||
uses: denoland/setup-deno@v2
|
uses: denoland/setup-deno@v2
|
||||||
with:
|
with:
|
||||||
deno-version: v2.x
|
deno-version: v2.x
|
||||||
- name: Install Deno requirements
|
- name: Install requirements
|
||||||
run: |
|
run: |
|
||||||
deno install
|
python pnpm.py install --frozen-lockfile
|
||||||
- name: Run Prettier check
|
- name: Run Prettier check
|
||||||
run: |
|
run: |
|
||||||
deno task fmt:check
|
python pnpm.py fmt:check
|
||||||
|
|
||||||
eslint:
|
eslint:
|
||||||
name: ESLint check
|
name: ESLint check
|
||||||
@@ -62,12 +62,12 @@ jobs:
|
|||||||
uses: denoland/setup-deno@v2
|
uses: denoland/setup-deno@v2
|
||||||
with:
|
with:
|
||||||
deno-version: v2.x
|
deno-version: v2.x
|
||||||
- name: Install Deno requirements
|
- name: Install requirements
|
||||||
run: |
|
run: |
|
||||||
deno install
|
python pnpm.py install --frozen-lockfile
|
||||||
- name: Run ESLint check
|
- name: Run ESLint check
|
||||||
run: |
|
run: |
|
||||||
deno task lint
|
python pnpm.py lint
|
||||||
|
|
||||||
python_tests:
|
python_tests:
|
||||||
name: Python tests
|
name: Python tests
|
||||||
@@ -117,12 +117,12 @@ jobs:
|
|||||||
uses: denoland/setup-deno@v2
|
uses: denoland/setup-deno@v2
|
||||||
with:
|
with:
|
||||||
deno-version: v2.x
|
deno-version: v2.x
|
||||||
- name: Install Deno requirements
|
- name: Install requirements
|
||||||
run: |
|
run: |
|
||||||
deno install
|
python pnpm.py install --frozen-lockfile
|
||||||
- name: Build control bundle
|
- name: Build control bundle
|
||||||
run: |
|
run: |
|
||||||
deno task bundle
|
python pnpm.py run bundle
|
||||||
- name: Generate bundle hashes
|
- name: Generate bundle hashes
|
||||||
run: |
|
run: |
|
||||||
pushd dist
|
pushd dist
|
||||||
@@ -189,7 +189,7 @@ jobs:
|
|||||||
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
||||||
- name: Install Deno requirements
|
- name: Install Deno requirements
|
||||||
run: |
|
run: |
|
||||||
deno install
|
python pnpm.py install --frozen-lockfile
|
||||||
- name: Bundle with Deno
|
- name: Bundle with Deno
|
||||||
run: |
|
run: |
|
||||||
deno task bundle
|
deno task bundle
|
||||||
@@ -215,7 +215,7 @@ jobs:
|
|||||||
deno-version: "2.0.0" # minimum supported version
|
deno-version: "2.0.0" # minimum supported version
|
||||||
- name: Install Deno requirements
|
- name: Install Deno requirements
|
||||||
run: |
|
run: |
|
||||||
deno install
|
python pnpm.py install --frozen-lockfile
|
||||||
- name: Download player JS artifact
|
- name: Download player JS artifact
|
||||||
uses: actions/download-artifact@v5
|
uses: actions/download-artifact@v5
|
||||||
with:
|
with:
|
||||||
@@ -256,7 +256,7 @@ jobs:
|
|||||||
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
||||||
- name: Install Bun requirements
|
- name: Install Bun requirements
|
||||||
run: |
|
run: |
|
||||||
bun install
|
python pnpm.py install --frozen-lockfile
|
||||||
- name: Bundle with Bun
|
- name: Bundle with Bun
|
||||||
run: |
|
run: |
|
||||||
bun --bun run bundle
|
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+
|
bun-version: "1.2.11" # XXX: We support 1.0.31, but test suite requires 1.2.11+
|
||||||
- name: Install Bun requirements
|
- name: Install Bun requirements
|
||||||
run: |
|
run: |
|
||||||
bun install
|
python pnpm.py install --frozen-lockfile
|
||||||
- name: Download player JS artifact
|
- name: Download player JS artifact
|
||||||
uses: actions/download-artifact@v5
|
uses: actions/download-artifact@v5
|
||||||
with:
|
with:
|
||||||
@@ -321,7 +321,7 @@ jobs:
|
|||||||
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
grep -q 'yt_dlp_ejs/yt/solver/lib\.min\.js' .wheel_contents
|
||||||
- name: Install Node requirements
|
- name: Install Node requirements
|
||||||
run: |
|
run: |
|
||||||
npm install
|
python pnpm.py install --frozen-lockfile
|
||||||
- name: Bundle with Node
|
- name: Bundle with Node
|
||||||
run: |
|
run: |
|
||||||
npm run bundle
|
npm run bundle
|
||||||
@@ -347,7 +347,7 @@ jobs:
|
|||||||
node-version: "22.18" # XXX: We support 20.0, but test suite requires 22.18+
|
node-version: "22.18" # XXX: We support 20.0, but test suite requires 22.18+
|
||||||
- name: Install Node requirements
|
- name: Install Node requirements
|
||||||
run: |
|
run: |
|
||||||
npm install
|
python pnpm.py install --frozen-lockfile
|
||||||
- name: Download player JS artifact
|
- name: Download player JS artifact
|
||||||
uses: actions/download-artifact@v5
|
uses: actions/download-artifact@v5
|
||||||
with:
|
with:
|
||||||
|
|||||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -37,7 +37,7 @@ jobs:
|
|||||||
compression-level: 0
|
compression-level: 0
|
||||||
- name: Build JavaScript artifacts
|
- name: Build JavaScript artifacts
|
||||||
run: |
|
run: |
|
||||||
deno install --frozen
|
python pnpm.py install --frozen-lockfile
|
||||||
deno task bundle
|
deno task bundle
|
||||||
- name: Upload JavaScript artifacts
|
- name: Upload JavaScript artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@
|
|||||||
/yt_dlp_ejs/_version.py
|
/yt_dlp_ejs/_version.py
|
||||||
/node_modules
|
/node_modules
|
||||||
/bun.lock
|
/bun.lock
|
||||||
|
/deno.lock
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
/.idea
|
/.idea
|
||||||
/.venv
|
/.venv
|
||||||
|
|||||||
33
README.md
33
README.md
@@ -12,9 +12,13 @@ pip install -U yt-dlp-ejs
|
|||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
While this project does pin its dependencies,
|
The project uses [`pnpm`](<https://github.com/pnpm/pnpm>) as a package manager with
|
||||||
it only provides a lockfile for building with `deno`.
|
dependencies pinned through `pnpm-lock.yaml`.
|
||||||
You may install dependencies using any compatible package manager.
|
|
||||||
|
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
|
If you notice differences between different runtimes' builds
|
||||||
please open an issue [here](<https://github.com/yt-dlp/ejs/issues/new>).
|
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:
|
Alternatively, to only build the JavaScript files you can run the `bundle` script manually:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Deno:
|
python pnpm.py install --frozen-lockfile
|
||||||
deno install --frozen
|
python pnpm.py run bundle
|
||||||
deno task bundle
|
|
||||||
|
|
||||||
# Bun:
|
|
||||||
bun install
|
|
||||||
bun --bun run bundle
|
|
||||||
|
|
||||||
# Node:
|
|
||||||
npm install
|
|
||||||
npm run bundle
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This will automatically select an available runtime and invoke `pnpm` to build it.
|
||||||
|
|
||||||
### Tests
|
### Tests
|
||||||
|
|
||||||
First, make sure the project's dependencies are installed and download the player JS files:
|
First, make sure the project's dependencies are installed and download the player JS files:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Deno:
|
# Deno:
|
||||||
deno install --frozen
|
python pnpm.py install --frozen-lockfile
|
||||||
deno run src/yt/solver/test/download.ts
|
deno run src/yt/solver/test/download.ts
|
||||||
|
|
||||||
# Bun:
|
# Bun:
|
||||||
bun install
|
python pnpm.py install --frozen-lockfile
|
||||||
bun --bun run src/yt/solver/test/download.ts
|
bun --bun run src/yt/solver/test/download.ts
|
||||||
|
|
||||||
# Node 22.6+:
|
# Node 22.6+:
|
||||||
npm install
|
python pnpm.py install --frozen-lockfile
|
||||||
node --experimental-strip-types src/yt/solver/test/download.ts
|
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/>).
|
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>),
|
[`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.
|
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": "4.52.5",
|
||||||
"rollup-plugin-license": "3.6.0",
|
"rollup-plugin-license": "3.6.0",
|
||||||
"typescript-eslint": "8.46.2"
|
"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"
|
version-file = "yt_dlp_ejs/_version.py"
|
||||||
|
|
||||||
[tool.hatch.build.targets.wheel.hooks.custom]
|
[tool.hatch.build.targets.wheel.hooks.custom]
|
||||||
|
path = "pnpm.py"
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
select = [
|
select = [
|
||||||
|
|||||||
Reference in New Issue
Block a user