mirror of
https://github.com/yt-dlp/ejs.git
synced 2026-06-28 09:06:34 +00:00
Add formatting/linting CI (#18)
This commit is contained in:
88
.github/workflows/ci.yml
vendored
88
.github/workflows/ci.yml
vendored
@@ -1,27 +1,13 @@
|
|||||||
name: CI
|
name: CI
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths-ignore:
|
||||||
- ".github/workflows/ci.yml"
|
- 'README.md'
|
||||||
- ".github/workflows/release.yml"
|
- 'LICENSE'
|
||||||
- "hatch_build.py"
|
|
||||||
- "package.json"
|
|
||||||
- "pyproject.toml"
|
|
||||||
- "rollup.config.js"
|
|
||||||
- "run.ts"
|
|
||||||
- "src/**"
|
|
||||||
- "yt_dlp_ejs/**"
|
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths-ignore:
|
||||||
- ".github/workflows/ci.yml"
|
- 'README.md'
|
||||||
- ".github/workflows/release.yml"
|
- 'LICENSE'
|
||||||
- "hatch_build.py"
|
|
||||||
- "package.json"
|
|
||||||
- "pyproject.toml"
|
|
||||||
- "rollup.config.js"
|
|
||||||
- "run.ts"
|
|
||||||
- "src/**"
|
|
||||||
- "yt_dlp_ejs/**"
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
@@ -31,6 +17,56 @@ concurrency:
|
|||||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
ruff-format:
|
||||||
|
name: Ruff format check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: astral-sh/ruff-action@v3
|
||||||
|
with:
|
||||||
|
args: "check --output-format github"
|
||||||
|
|
||||||
|
ruff-lint:
|
||||||
|
name: Ruff linting check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: astral-sh/ruff-action@v3
|
||||||
|
with:
|
||||||
|
args: "format --check --diff"
|
||||||
|
|
||||||
|
prettier:
|
||||||
|
name: Prettier check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install Deno v2.x (latest)
|
||||||
|
uses: denoland/setup-deno@v2
|
||||||
|
with:
|
||||||
|
deno-version: v2.x
|
||||||
|
- name: Install Deno requirements
|
||||||
|
run: |
|
||||||
|
deno install
|
||||||
|
- name: Run Prettier check
|
||||||
|
run: |
|
||||||
|
deno task fmt:check
|
||||||
|
|
||||||
|
eslint:
|
||||||
|
name: ESLint check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: Install Deno v2.x (latest)
|
||||||
|
uses: denoland/setup-deno@v2
|
||||||
|
with:
|
||||||
|
deno-version: v2.x
|
||||||
|
- name: Install Deno requirements
|
||||||
|
run: |
|
||||||
|
deno install
|
||||||
|
- name: Run ESLint check
|
||||||
|
run: |
|
||||||
|
deno task lint
|
||||||
|
|
||||||
python_tests:
|
python_tests:
|
||||||
name: Python tests
|
name: Python tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -304,7 +340,17 @@ jobs:
|
|||||||
node --test
|
node --test
|
||||||
|
|
||||||
all_passed:
|
all_passed:
|
||||||
needs: [deno_build, deno_tests, bun_build, bun_tests, node_build, node_tests]
|
needs:
|
||||||
|
- ruff-format
|
||||||
|
- ruff-lint
|
||||||
|
- prettier
|
||||||
|
- eslint
|
||||||
|
- deno_build
|
||||||
|
- deno_tests
|
||||||
|
- bun_build
|
||||||
|
- bun_tests
|
||||||
|
- node_build
|
||||||
|
- node_tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: All checks passed
|
- name: All checks passed
|
||||||
|
|||||||
14
eslint.config.js
Normal file
14
eslint.config.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import js from "@eslint/js";
|
||||||
|
import globals from "globals";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
import { defineConfig } from "eslint/config";
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
{
|
||||||
|
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
|
||||||
|
plugins: { js },
|
||||||
|
extends: ["js/recommended"],
|
||||||
|
languageOptions: { globals: globals.node },
|
||||||
|
},
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
]);
|
||||||
@@ -28,12 +28,15 @@ class CustomBuildHook(BuildHookInterface):
|
|||||||
else:
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"One of 'deno', 'bun', or 'npm' could not be found. "
|
"One of 'deno', 'bun', or 'npm' could not be found. "
|
||||||
"Please install one of them to proceed with the build.")
|
"Please install one of them to proceed with the build."
|
||||||
|
)
|
||||||
|
|
||||||
build_data["force_include"].update({
|
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",
|
"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):
|
def clean(self, versions):
|
||||||
shutil.rmtree("node_modules", ignore_errors=True)
|
shutil.rmtree("node_modules", ignore_errors=True)
|
||||||
|
|||||||
12
package.json
12
package.json
@@ -3,21 +3,27 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"bundle": "rollup -c",
|
"bundle": "rollup -c",
|
||||||
"fmt": "prettier --write \"src/**.ts\" \"package.json\" \"rollup.config.js\" \"run.ts\""
|
"fmt": "prettier --write \"src/**.ts\" \"package.json\" \"rollup.config.js\" \"run.ts\" \"eslint.config.js\"",
|
||||||
|
"fmt:check": "prettier --check \"src/**.ts\" \"package.json\" \"rollup.config.js\" \"run.ts\" \"eslint.config.js\"",
|
||||||
|
"lint": "eslint src"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"astring": "1.9.0",
|
"astring": "1.9.0",
|
||||||
"meriyah": "6.1.4"
|
"meriyah": "6.1.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@eslint/js": "9.38.0",
|
||||||
"@rollup/plugin-node-resolve": "16.0.3",
|
"@rollup/plugin-node-resolve": "16.0.3",
|
||||||
"@rollup/plugin-sucrase": "5.0.2",
|
"@rollup/plugin-sucrase": "5.0.2",
|
||||||
"@rollup/plugin-terser": "0.4.4",
|
"@rollup/plugin-terser": "0.4.4",
|
||||||
"rollup-plugin-license": "3.6.0",
|
|
||||||
"@types/bun": "1.3.0",
|
"@types/bun": "1.3.0",
|
||||||
"@types/deno": "2.5.0",
|
"@types/deno": "2.5.0",
|
||||||
"@types/node": "24.8.1",
|
"@types/node": "24.8.1",
|
||||||
|
"eslint": "9.38.0",
|
||||||
|
"globals": "16.4.0",
|
||||||
|
"prettier": "3.6.2",
|
||||||
"rollup": "4.52.5",
|
"rollup": "4.52.5",
|
||||||
"prettier": "3.6.2"
|
"rollup-plugin-license": "3.6.0",
|
||||||
|
"typescript-eslint": "8.46.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ classifiers = [
|
|||||||
]
|
]
|
||||||
dependencies = []
|
dependencies = []
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"ruff>=0.14.1",
|
||||||
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Documentation = "https://github.com/yt-dlp/ejs#readme"
|
Documentation = "https://github.com/yt-dlp/ejs#readme"
|
||||||
Issues = "https://github.com/yt-dlp/ejs/issues"
|
Issues = "https://github.com/yt-dlp/ejs/issues"
|
||||||
@@ -51,3 +56,33 @@ 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]
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = [
|
||||||
|
"C4",
|
||||||
|
"E",
|
||||||
|
"F",
|
||||||
|
"I",
|
||||||
|
"PLC",
|
||||||
|
"PLE",
|
||||||
|
"PLW",
|
||||||
|
"PYI",
|
||||||
|
"RET",
|
||||||
|
"RUF",
|
||||||
|
"SIM",
|
||||||
|
"TD",
|
||||||
|
"TID",
|
||||||
|
"W",
|
||||||
|
]
|
||||||
|
ignore = [
|
||||||
|
"TD003",
|
||||||
|
"E402",
|
||||||
|
"E501",
|
||||||
|
"PLR09",
|
||||||
|
]
|
||||||
|
|
||||||
|
[tool.ruff.lint.isort]
|
||||||
|
force-single-line = true
|
||||||
|
|
||||||
|
[tool.ruff.lint.flake8-tidy-imports]
|
||||||
|
ban-relative-imports = "all"
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ function printHash() {
|
|||||||
for (const [fileName, assetInfo] of Object.entries(bundle)) {
|
for (const [fileName, assetInfo] of Object.entries(bundle)) {
|
||||||
if (assetInfo.code) {
|
if (assetInfo.code) {
|
||||||
try {
|
try {
|
||||||
const digest = createHash("sha3-512").update(assetInfo.code).digest("hex");
|
const digest = createHash("sha3-512")
|
||||||
|
.update(assetInfo.code)
|
||||||
|
.digest("hex");
|
||||||
console.log(`SHA3-512 for ${assetInfo.fileName}: ${digest}`);
|
console.log(`SHA3-512 for ${assetInfo.fileName}: ${digest}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Error hashing ${fileName}:`, err.message);
|
console.error(`Error hashing ${fileName}:`, err.message);
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ export function matchesStructure<T extends ESTree.Node>(
|
|||||||
if ("anykey" in structure && Array.isArray(structure.anykey)) {
|
if ("anykey" in structure && Array.isArray(structure.anykey)) {
|
||||||
// Handle `{ anykey: [a, b] }`
|
// Handle `{ anykey: [a, b] }`
|
||||||
const haystack = Array.isArray(obj) ? obj : Object.values(obj);
|
const haystack = Array.isArray(obj) ? obj : Object.values(obj);
|
||||||
return structure.anykey.every(value => haystack.some((el) => matchesStructure(el, value)));
|
return structure.anykey.every((value) =>
|
||||||
|
haystack.some((el) => matchesStructure(el, value)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
for (const [key, value] of Object.entries(structure)) {
|
for (const [key, value] of Object.entries(structure)) {
|
||||||
if (!matchesStructure(obj[key as keyof typeof obj], value)) {
|
if (!matchesStructure(obj[key as keyof typeof obj], value)) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export async function getIO(): Promise<IO> {
|
|||||||
|
|
||||||
async function _getIO(): Promise<IO> {
|
async function _getIO(): Promise<IO> {
|
||||||
// Old Deno requires casting to any as globalThis lacks an index signature
|
// Old Deno requires casting to any as globalThis lacks an index signature
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
if ((globalThis as any).process?.release?.name === "node") {
|
if ((globalThis as any).process?.release?.name === "node") {
|
||||||
// Assume node compatibility
|
// Assume node compatibility
|
||||||
const { access, readFile } = await import("node:fs/promises");
|
const { access, readFile } = await import("node:fs/promises");
|
||||||
|
|||||||
@@ -4,15 +4,21 @@ from pathlib import Path
|
|||||||
import yt_dlp_ejs.yt.solver
|
import yt_dlp_ejs.yt.solver
|
||||||
|
|
||||||
BASE_PATH = Path(__file__).parent.parent
|
BASE_PATH = Path(__file__).parent.parent
|
||||||
CORE_PATH = BASE_PATH / 'yt_dlp_ejs/yt/solver/core.min.js'
|
CORE_PATH = BASE_PATH / "yt_dlp_ejs/yt/solver/core.min.js"
|
||||||
LIB_PATH = BASE_PATH / 'yt_dlp_ejs/yt/solver/lib.min.js'
|
LIB_PATH = BASE_PATH / "yt_dlp_ejs/yt/solver/lib.min.js"
|
||||||
|
|
||||||
|
|
||||||
class TestModules(unittest.TestCase):
|
class TestModules(unittest.TestCase):
|
||||||
def test_yt_solver(self):
|
def test_yt_solver(self):
|
||||||
self.assertEqual(yt_dlp_ejs.yt.solver.core(), CORE_PATH.read_text(encoding='utf-8'))
|
self.assertEqual(
|
||||||
self.assertEqual(yt_dlp_ejs.yt.solver.lib(), LIB_PATH.read_text(encoding='utf-8'))
|
yt_dlp_ejs.yt.solver.core(),
|
||||||
|
CORE_PATH.read_text(encoding="utf-8"),
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
yt_dlp_ejs.yt.solver.lib(),
|
||||||
|
LIB_PATH.read_text(encoding="utf-8"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
from yt_dlp_ejs._version import version
|
from yt_dlp_ejs._version import version
|
||||||
from yt_dlp_ejs import yt
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = ["version"]
|
||||||
"version",
|
|
||||||
"yt"
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
from . import solver
|
|
||||||
|
|
||||||
__all__ = ["solver"]
|
|
||||||
@@ -2,6 +2,7 @@ import importlib.resources
|
|||||||
|
|
||||||
import yt_dlp_ejs.yt.solver
|
import yt_dlp_ejs.yt.solver
|
||||||
|
|
||||||
|
|
||||||
def core() -> str:
|
def core() -> str:
|
||||||
"""
|
"""
|
||||||
Read the contents of the JavaScript core solver bundle as string.
|
Read the contents of the JavaScript core solver bundle as string.
|
||||||
|
|||||||
Reference in New Issue
Block a user