Namespace packages

This commit is contained in:
Simon Sawicki
2025-09-27 17:56:19 +02:00
parent 1adbcc85e3
commit 37c1277798
19 changed files with 37 additions and 40 deletions

View File

@@ -45,6 +45,5 @@ commands = [
] ]
[tool.hatch.build.targets.wheel.force-include] [tool.hatch.build.targets.wheel.force-include]
"dist/yt.solver.core.min.js" = "yt_dlp_ejs/yt.solver.core.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" "dist/yt.solver.lib.min.js" = "yt_dlp_ejs/yt/solver/lib.min.js"

View File

@@ -83,7 +83,7 @@ function prettifyOutput() {
export default defineConfig([ export default defineConfig([
{ {
input: "src/main.ts", input: "src/yt/solver/main.ts",
output: { output: {
name: "jsc", name: "jsc",
globals: { globals: {
@@ -119,7 +119,7 @@ export default defineConfig([
], ],
}, },
{ {
input: "src/main.ts", input: "src/yt/solver/main.ts",
output: { output: {
name: "jsc", name: "jsc",
globals: { globals: {
@@ -153,7 +153,7 @@ export default defineConfig([
], ],
}, },
{ {
input: "src/lib.ts", input: "src/yt/solver/lib.ts",
output: { output: {
name: "lib", name: "lib",
file: "dist/yt.solver.lib.js", file: "dist/yt.solver.lib.js",
@@ -184,7 +184,7 @@ export default defineConfig([
], ],
}, },
{ {
input: "src/lib.ts", input: "src/yt/solver/lib.ts",
output: { output: {
name: "lib", name: "lib",
file: "dist/yt.solver.lib.min.js", file: "dist/yt.solver.lib.min.js",
@@ -212,14 +212,14 @@ export default defineConfig([
], ],
}, },
{ {
input: "src/dynamic.lib.ts", input: "src/yt/solver/dynamic.lib.ts",
output: { output: {
name: "lib", name: "lib",
file: "dist/yt.solver.deno.lib.js", file: "dist/yt.solver.deno.lib.js",
format: "es", format: "es",
}, },
plugins: [ plugins: [
dynamicImportRewrite({ format: "deno" }), dynamicImportRewrite(),
license({ license({
banner: { banner: {
content: LICENSE_BANNER, content: LICENSE_BANNER,
@@ -238,7 +238,7 @@ export default defineConfig([
], ],
}, },
{ {
input: "src/dynamic.lib.ts", input: "src/yt/solver/dynamic.lib.ts",
output: { output: {
name: "lib", name: "lib",
file: "dist/yt.solver.bun.lib.js", file: "dist/yt.solver.bun.lib.js",

2
run.ts
View File

@@ -2,7 +2,7 @@ import { argv, exit } from "node:process";
import { readFileSync } from "node:fs"; import { readFileSync } from "node:fs";
import { isOneOf } from "./src/utils.ts"; import { isOneOf } from "./src/utils.ts";
import main from "./src/main.ts"; import main from "./src/yt/solver/main.ts";
const args = argv.slice(2); const args = argv.slice(2);
if (args.length < 2) { if (args.length < 2) {

View File

@@ -1,5 +1,5 @@
import { getFromPrepared, preprocessPlayer } from "./solvers.ts"; import { getFromPrepared, preprocessPlayer } from "./solvers.ts";
import { isOneOf } from "./utils.ts"; import { isOneOf } from "../../utils.ts";
export default function main(input: Input): Output { export default function main(input: Input): Output {
const preprocessedPlayer = const preprocessedPlayer =

View File

@@ -1,6 +1,6 @@
import { type ESTree } from "meriyah"; import { type ESTree } from "meriyah";
import { matchesStructure } from "./utils.ts"; import { matchesStructure } from "../../utils.ts";
import { type DeepPartial } from "./types.ts"; import { type DeepPartial } from "../../types.ts";
const identifier: DeepPartial<ESTree.VariableDeclaration> = { const identifier: DeepPartial<ESTree.VariableDeclaration> = {
type: "VariableDeclaration", type: "VariableDeclaration",

View File

@@ -1,6 +1,6 @@
import { type ESTree } from "meriyah"; import { type ESTree } from "meriyah";
import { matchesStructure } from "./utils.ts"; import { matchesStructure } from "../../utils.ts";
import { type DeepPartial } from "./types.ts"; import { type DeepPartial } from "../../types.ts";
const logicalExpression: DeepPartial<ESTree.ExpressionStatement> = { const logicalExpression: DeepPartial<ESTree.ExpressionStatement> = {
type: "ExpressionStatement", type: "ExpressionStatement",

View File

@@ -1,7 +1,7 @@
import { getFromPrepared, preprocessPlayer } from "./solvers.ts"; import { getFromPrepared, preprocessPlayer } from "./solvers.ts";
import { players, tests } from "../tests/tests.ts"; import { players, tests } from "./test/tests.ts";
import { getCachePath } from "../tests/utils.ts"; import { getCachePath } from "./test/utils.ts";
import { getIO } from "../tests/io.ts"; import { getIO } from "./test/io.ts";
const io = await getIO(); const io = await getIO();

View File

@@ -247,7 +247,7 @@ export const tests: {
input: input:
"MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJA", "MMGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKn-znQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJA",
expected: expected:
"-MGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKnMznQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJA", "-MGZJMUucirzS_SnrSPYsc85CJNnTUi6GgR5NKnMznQEICACojE8MHS6S7uYq4TGjQX_D4aPk99hNU6wbTvorvVVMgIARwsSdQfJ",
}, },
], ],
}, },

View File

@@ -1,5 +1,5 @@
import { type Variant } from "./tests.ts"; import { type Variant } from "./tests.ts";
export function getCachePath(player: string, variant: Variant) { export function getCachePath(player: string, variant: Variant) {
return `tests/players/${player}-${variant}`; return `src/yt/solver/test/players/${player}-${variant}`;
} }

View File

@@ -1,25 +1,6 @@
import importlib.resources
import yt_dlp_ejs
# XXX: this reflects package version
from yt_dlp_ejs._version import version from yt_dlp_ejs._version import version
def yt_solver_core() -> str:
"""
Read the contents of the JavaScript core solver bundle as string.
"""
return importlib.resources.read_text(yt_dlp_ejs, 'yt.solver.core.min.js')
def yt_solver_lib() -> str:
"""
Read the contents of the JavaScript library solver bundle as string.
"""
return importlib.resources.read_text(yt_dlp_ejs, 'yt.solver.lib.min.js')
__all__ = [ __all__ = [
"core",
"lib",
"version", "version",
] ]

View File

View File

@@ -0,0 +1,17 @@
import importlib
import yt_dlp_ejs.yt.solver
def core() -> str:
"""
Read the contents of the JavaScript core solver bundle as string.
"""
return importlib.resources.read_text(yt_dlp_ejs.yt.solver, "core.min.js")
def lib() -> str:
"""
Read the contents of the JavaScript library solver bundle as string.
"""
return importlib.resources.read_text(yt_dlp_ejs.yt.solver, "lib.min.js")