mirror of
https://github.com/yt-dlp/ejs.git
synced 2026-06-13 08:42:29 +00:00
Apply formatter
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
"name": "ejs",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"bundle": "rollup -c"
|
||||
"bundle": "rollup -c",
|
||||
"fmt": "prettier --write \"src/**.ts\" \"tests/**.ts\" \"package.json\" \"rollup.config.js\" \"run.ts\""
|
||||
},
|
||||
"dependencies": {
|
||||
"astring": "1.9.0",
|
||||
|
||||
@@ -4,11 +4,11 @@ import sucrase from "@rollup/plugin-sucrase";
|
||||
import terser from "@rollup/plugin-terser";
|
||||
import { createHash } from "node:crypto";
|
||||
import { Buffer } from "node:buffer";
|
||||
import license from 'rollup-plugin-license';
|
||||
import license from "rollup-plugin-license";
|
||||
import { readFileSync } from "node:fs";
|
||||
import prettier from "prettier";
|
||||
|
||||
const pkg = JSON.parse(readFileSync('./package.json'));
|
||||
const pkg = JSON.parse(readFileSync("./package.json"));
|
||||
|
||||
const LICENSE_BANNER =
|
||||
"SPDX-License-Identifier: Unlicense\n" +
|
||||
@@ -23,9 +23,9 @@ const LICENSE_BANNER =
|
||||
"<% if (dependency.homepage && dependency.homepage.url) { %>\nHomepage: <%= dependency.homepage.url %><% } %>" +
|
||||
"<% if (dependency.author) { %>\nAuthor: <%= dependency.author.text() %><% } %>" +
|
||||
"<% if (dependency.licenseText) { %>\n\n<%= dependency.licenseText %><% } %>" +
|
||||
"\n---<% } }) %>\n<% } %>"
|
||||
"\n---<% } }) %>\n<% } %>";
|
||||
|
||||
const ALLOWED_COMMENTS_RE = /SPDX-License-Identifier:/
|
||||
const ALLOWED_COMMENTS_RE = /SPDX-License-Identifier:/;
|
||||
|
||||
function printHash() {
|
||||
return {
|
||||
@@ -34,7 +34,7 @@ function printHash() {
|
||||
for (const [fileName, assetInfo] of Object.entries(bundle)) {
|
||||
if (assetInfo.code) {
|
||||
try {
|
||||
const data = Buffer.from(assetInfo.code)
|
||||
const data = Buffer.from(assetInfo.code);
|
||||
const hash = createHash("sha3-512").update(data).digest("hex");
|
||||
console.log(`SHA3-512 for ${assetInfo.fileName}: ${hash}`);
|
||||
} catch (err) {
|
||||
@@ -52,29 +52,34 @@ function dynamicImportRewrite({format = "deno"} = {}) {
|
||||
resolveId(source) {
|
||||
if (pkg.dependencies[source]) {
|
||||
if (format === "deno") {
|
||||
return {id: `npm:${source}@${pkg.dependencies[source]}`, external: true};
|
||||
return {
|
||||
id: `npm:${source}@${pkg.dependencies[source]}`,
|
||||
external: true,
|
||||
};
|
||||
} else if (format === "bun") {
|
||||
return {id: `${source}@${pkg.dependencies[source]}`, external: true};
|
||||
return {
|
||||
id: `${source}@${pkg.dependencies[source]}`,
|
||||
external: true,
|
||||
};
|
||||
}
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
renderDynamicImport() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function prettifyOutput() {
|
||||
return {
|
||||
name: 'prettify-output',
|
||||
name: "prettify-output",
|
||||
renderChunk(code) {
|
||||
return prettier.format(code, {parser: 'babel', singleQuote: true});
|
||||
return prettier.format(code, { parser: "babel", singleQuote: true });
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default defineConfig([
|
||||
{
|
||||
@@ -98,13 +103,13 @@ export default defineConfig([
|
||||
}),
|
||||
license({
|
||||
banner: {
|
||||
content: LICENSE_BANNER
|
||||
content: LICENSE_BANNER,
|
||||
},
|
||||
}),
|
||||
// Use terser to remove comments but do not minify
|
||||
terser({
|
||||
format: {
|
||||
comments: ALLOWED_COMMENTS_RE
|
||||
comments: ALLOWED_COMMENTS_RE,
|
||||
},
|
||||
compress: false,
|
||||
mangle: false,
|
||||
@@ -136,12 +141,12 @@ export default defineConfig([
|
||||
}),
|
||||
terser({
|
||||
format: {
|
||||
comments: ALLOWED_COMMENTS_RE
|
||||
}
|
||||
comments: ALLOWED_COMMENTS_RE,
|
||||
},
|
||||
}),
|
||||
license({
|
||||
banner: {
|
||||
content: LICENSE_BANNER
|
||||
content: LICENSE_BANNER,
|
||||
},
|
||||
}),
|
||||
printHash(),
|
||||
@@ -163,13 +168,13 @@ export default defineConfig([
|
||||
}),
|
||||
license({
|
||||
banner: {
|
||||
content: LICENSE_BANNER
|
||||
content: LICENSE_BANNER,
|
||||
},
|
||||
}),
|
||||
// Use terser to remove comments but do not minify
|
||||
terser({
|
||||
format: {
|
||||
comments: ALLOWED_COMMENTS_RE
|
||||
comments: ALLOWED_COMMENTS_RE,
|
||||
},
|
||||
compress: false,
|
||||
mangle: false,
|
||||
@@ -195,12 +200,12 @@ export default defineConfig([
|
||||
}),
|
||||
terser({
|
||||
format: {
|
||||
comments: ALLOWED_COMMENTS_RE
|
||||
}
|
||||
comments: ALLOWED_COMMENTS_RE,
|
||||
},
|
||||
}),
|
||||
license({
|
||||
banner: {
|
||||
content: LICENSE_BANNER
|
||||
content: LICENSE_BANNER,
|
||||
},
|
||||
}),
|
||||
printHash(),
|
||||
@@ -217,13 +222,13 @@ export default defineConfig([
|
||||
dynamicImportRewrite({ format: "deno" }),
|
||||
license({
|
||||
banner: {
|
||||
content: LICENSE_BANNER
|
||||
content: LICENSE_BANNER,
|
||||
},
|
||||
}),
|
||||
// Use terser to remove comments but do not minify
|
||||
terser({
|
||||
format: {
|
||||
comments: ALLOWED_COMMENTS_RE
|
||||
comments: ALLOWED_COMMENTS_RE,
|
||||
},
|
||||
compress: false,
|
||||
mangle: false,
|
||||
@@ -243,13 +248,13 @@ export default defineConfig([
|
||||
dynamicImportRewrite({ format: "bun" }),
|
||||
license({
|
||||
banner: {
|
||||
content: LICENSE_BANNER
|
||||
content: LICENSE_BANNER,
|
||||
},
|
||||
}),
|
||||
// Use terser to remove comments but do not minify
|
||||
terser({
|
||||
format: {
|
||||
comments: ALLOWED_COMMENTS_RE
|
||||
comments: ALLOWED_COMMENTS_RE,
|
||||
},
|
||||
compress: false,
|
||||
mangle: false,
|
||||
|
||||
8
run.ts
8
run.ts
@@ -27,7 +27,9 @@ for (const request of args.slice(1)) {
|
||||
}
|
||||
requests[type].push(challenge);
|
||||
}
|
||||
console.log(JSON.stringify(main({
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
main({
|
||||
type: "player",
|
||||
player,
|
||||
output_preprocessed: false,
|
||||
@@ -35,4 +37,6 @@ console.log(JSON.stringify(main({
|
||||
{ type: "n", challenges: requests.n },
|
||||
{ type: "sig", challenges: requests.sig },
|
||||
],
|
||||
})));
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Used for generating deno/bun auto-imports
|
||||
export const lib = {
|
||||
meriyah: (await import('meriyah')),
|
||||
astring: (await import('astring'))
|
||||
meriyah: await import("meriyah"),
|
||||
astring: await import("astring"),
|
||||
};
|
||||
12
src/main.ts
12
src/main.ts
@@ -2,13 +2,13 @@ import { getFromPrepared, preprocessPlayer } from "./solvers.ts";
|
||||
import { isOneOf } from "./utils.ts";
|
||||
|
||||
export default function main(input: Input): Output {
|
||||
const preprocessedPlayer = input.type === "player"
|
||||
const preprocessedPlayer =
|
||||
input.type === "player"
|
||||
? preprocessPlayer(input.player)
|
||||
: input.preprocessed_player;
|
||||
const solvers = getFromPrepared(preprocessedPlayer);
|
||||
|
||||
const responses = input.requests.map(
|
||||
(input): Response => {
|
||||
const responses = input.requests.map((input): Response => {
|
||||
if (!isOneOf(input.type, "n", "sig")) {
|
||||
return {
|
||||
type: "error",
|
||||
@@ -32,13 +32,13 @@ export default function main(input: Input): Output {
|
||||
} catch (error) {
|
||||
return {
|
||||
type: "error",
|
||||
error: error instanceof Error
|
||||
error:
|
||||
error instanceof Error
|
||||
? `${error.message}\n${error.stack}`
|
||||
: `${error}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
const output: Output = {
|
||||
type: "result",
|
||||
|
||||
3
src/n.ts
3
src/n.ts
@@ -97,7 +97,8 @@ export function extract(
|
||||
}
|
||||
const declaration = node.declarations[0];
|
||||
if (
|
||||
declaration.type !== "VariableDeclarator" || !declaration.init ||
|
||||
declaration.type !== "VariableDeclarator" ||
|
||||
!declaration.init ||
|
||||
declaration.init.type !== "ArrayExpression" ||
|
||||
declaration.init.elements.length !== 1
|
||||
) {
|
||||
|
||||
23
src/sig.ts
23
src/sig.ts
@@ -63,7 +63,8 @@ const logicalExpression: DeepPartial<ESTree.ExpressionStatement> = {
|
||||
};
|
||||
|
||||
const identifier = {
|
||||
or: [{
|
||||
or: [
|
||||
{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "AssignmentExpression",
|
||||
@@ -76,10 +77,12 @@ const identifier = {
|
||||
params: [{}, {}, {}],
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
type: "FunctionDeclaration",
|
||||
params: [{}, {}, {}],
|
||||
}],
|
||||
},
|
||||
],
|
||||
} as const;
|
||||
|
||||
export function extract(
|
||||
@@ -90,9 +93,10 @@ export function extract(
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const block = (node.type === "ExpressionStatement" &&
|
||||
const block =
|
||||
node.type === "ExpressionStatement" &&
|
||||
node.expression.type === "AssignmentExpression" &&
|
||||
node.expression.right.type === "FunctionExpression")
|
||||
node.expression.right.type === "FunctionExpression"
|
||||
? node.expression.right.body
|
||||
: node.type === "FunctionDeclaration"
|
||||
? node.body
|
||||
@@ -103,10 +107,8 @@ export function extract(
|
||||
}
|
||||
if (
|
||||
relevantExpression?.type !== "ExpressionStatement" ||
|
||||
relevantExpression.expression.type !==
|
||||
"LogicalExpression" ||
|
||||
relevantExpression.expression.right.type !==
|
||||
"SequenceExpression" ||
|
||||
relevantExpression.expression.type !== "LogicalExpression" ||
|
||||
relevantExpression.expression.right.type !== "SequenceExpression" ||
|
||||
relevantExpression.expression.right.expressions[0].type !==
|
||||
"AssignmentExpression"
|
||||
) {
|
||||
@@ -131,7 +133,8 @@ export function extract(
|
||||
type: "Identifier",
|
||||
name: call.callee.name,
|
||||
},
|
||||
arguments: call.arguments.length === 1
|
||||
arguments:
|
||||
call.arguments.length === 1
|
||||
? [
|
||||
{
|
||||
type: "Identifier",
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
export type DeepPartial<T> = T extends object ? Or<
|
||||
{
|
||||
export type DeepPartial<T> = T extends object
|
||||
? Or<{
|
||||
[P in keyof T]?: DeepPartial<T[P]>;
|
||||
}
|
||||
>
|
||||
}>
|
||||
: Or<T>;
|
||||
|
||||
type Or<T> = T | { or: T[] };
|
||||
|
||||
@@ -253,8 +253,7 @@ export const tests: {
|
||||
},
|
||||
];
|
||||
|
||||
export const players = new Map(
|
||||
[
|
||||
export const players = new Map([
|
||||
["main", "player_ias.vflset/en_US/base.js"],
|
||||
["tcc", "player_ias_tcc.vflset/en_US/base.js"],
|
||||
["tce", "player_ias_tce.vflset/en_US/base.js"],
|
||||
@@ -264,7 +263,6 @@ export const players = new Map(
|
||||
["tv_es6", "tv-player-es6.vflset/tv-player-es6.js"],
|
||||
["phone", "player-plasma-ias-phone-en_US.vflset/base.js"],
|
||||
["tablet", "player-plasma-ias-tablet-en_US.vflset/base.js"],
|
||||
] as const,
|
||||
);
|
||||
] as const);
|
||||
|
||||
export type Variant = typeof players extends Map<infer T, unknown> ? T : never;
|
||||
|
||||
Reference in New Issue
Block a user