krillplayer-plugin 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// package/cli.ts
|
|
2
2
|
import { execFile as execFile2 } from "node:child_process";
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
4
4
|
import { cp, mkdir as mkdir3, mkdtemp as mkdtemp2, readdir as readdir5, readFile as readFile6, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
|
|
5
5
|
import { createRequire as createRequire2 } from "node:module";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
|
-
import { basename as basename2, dirname as dirname2, join as
|
|
8
|
-
import { fileURLToPath as
|
|
7
|
+
import { basename as basename2, dirname as dirname2, join as join6, relative as relative3, resolve as resolve3 } from "node:path";
|
|
8
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
9
9
|
import { parseArgs, promisify as promisify2 } from "node:util";
|
|
10
10
|
|
|
11
11
|
// contract/schema.ts
|
|
@@ -877,8 +877,8 @@ function slotMember(slot, name2) {
|
|
|
877
877
|
// packer/pack.ts
|
|
878
878
|
import { build as build2 } from "esbuild";
|
|
879
879
|
import { mkdir as mkdir2, readdir as readdir4, readFile as readFile5, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
880
|
-
import { join as
|
|
881
|
-
import { fileURLToPath as
|
|
880
|
+
import { join as join5 } from "node:path";
|
|
881
|
+
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
882
882
|
|
|
883
883
|
// contract/not-yet-used.ts
|
|
884
884
|
var NOT_YET_USED = [
|
|
@@ -1087,7 +1087,12 @@ function translate({ locale, language, dictionaries: dictionaries2 }, text, valu
|
|
|
1087
1087
|
|
|
1088
1088
|
// trial-runner/trial.ts
|
|
1089
1089
|
import { readdir as readdir3, readFile as readFile4, writeFile } from "node:fs/promises";
|
|
1090
|
-
import { basename, join as
|
|
1090
|
+
import { basename, join as join4, resolve } from "node:path";
|
|
1091
|
+
|
|
1092
|
+
// host/network.ts
|
|
1093
|
+
import { readFileSync } from "node:fs";
|
|
1094
|
+
import { join } from "node:path";
|
|
1095
|
+
import { domainToASCII, fileURLToPath } from "node:url";
|
|
1091
1096
|
|
|
1092
1097
|
// host/files.ts
|
|
1093
1098
|
var FileServiceError = class extends Error {
|
|
@@ -1166,6 +1171,52 @@ function createFiles(host) {
|
|
|
1166
1171
|
}
|
|
1167
1172
|
|
|
1168
1173
|
// host/network.ts
|
|
1174
|
+
function sameSite(host, other) {
|
|
1175
|
+
if (host === other) return true;
|
|
1176
|
+
const domain = registrableDomain(host);
|
|
1177
|
+
return domain !== null && domain === registrableDomain(other);
|
|
1178
|
+
}
|
|
1179
|
+
function vouchedByUserHost(host, use, userHosts, downgrade) {
|
|
1180
|
+
if (use !== "playback" && use !== "playback-follow" && use !== "playback-probe" || downgrade) return false;
|
|
1181
|
+
return [...userHosts].some((user) => sameSite(host, user));
|
|
1182
|
+
}
|
|
1183
|
+
function registrableDomain(host) {
|
|
1184
|
+
const labels = host.split(".");
|
|
1185
|
+
if (labels.length < 2 || labels.includes("") || host.includes(":") || /^[0-9]+$/.test(labels[labels.length - 1])) return null;
|
|
1186
|
+
const rules = publicSuffixRules();
|
|
1187
|
+
const suffix = (start) => labels.slice(start).join(".");
|
|
1188
|
+
let suffixLength = 1;
|
|
1189
|
+
const exception = labels.findIndex((_, start) => rules.exceptions.has(suffix(start)));
|
|
1190
|
+
if (exception >= 0) {
|
|
1191
|
+
suffixLength = labels.length - exception - 1;
|
|
1192
|
+
} else {
|
|
1193
|
+
const start = labels.findIndex((_, index) => rules.exact.has(suffix(index)) || index + 1 < labels.length && rules.wildcards.has(suffix(index + 1)));
|
|
1194
|
+
if (start >= 0) suffixLength = labels.length - start;
|
|
1195
|
+
}
|
|
1196
|
+
return labels.length > suffixLength ? labels.slice(labels.length - suffixLength - 1).join(".") : null;
|
|
1197
|
+
}
|
|
1198
|
+
var suffixRules;
|
|
1199
|
+
var suffixListKernel;
|
|
1200
|
+
function usePublicSuffixListFrom(kernelDirectory2) {
|
|
1201
|
+
suffixListKernel = kernelDirectory2;
|
|
1202
|
+
suffixRules = void 0;
|
|
1203
|
+
}
|
|
1204
|
+
function publicSuffixRules() {
|
|
1205
|
+
if (suffixRules !== void 0) return suffixRules;
|
|
1206
|
+
const kernel = process.env.KRILLPLAYER_KERNEL_DIR ?? suffixListKernel ?? fileURLToPath(new URL("../../Packages/Kernel", import.meta.url));
|
|
1207
|
+
const text = readFileSync(join(kernel, "Sources/Kernel/Network/PublicSuffixList.dat"), "utf8");
|
|
1208
|
+
const rules = { exact: /* @__PURE__ */ new Set(), wildcards: /* @__PURE__ */ new Set(), exceptions: /* @__PURE__ */ new Set() };
|
|
1209
|
+
const domain = (text2) => text2.includes("*") ? "" : bareHost(domainToASCII(text2));
|
|
1210
|
+
for (const line of text.split(/\r?\n/)) {
|
|
1211
|
+
const rule = line.trim().split(/\s/)[0];
|
|
1212
|
+
if (rule === "" || rule.startsWith("//")) continue;
|
|
1213
|
+
const [set, name2] = rule.startsWith("!") ? [rules.exceptions, rule.slice(1)] : rule.startsWith("*.") ? [rules.wildcards, rule.slice(2)] : [rules.exact, rule];
|
|
1214
|
+
const ascii = domain(name2);
|
|
1215
|
+
if (ascii !== "") set.add(ascii);
|
|
1216
|
+
}
|
|
1217
|
+
suffixRules = rules;
|
|
1218
|
+
return rules;
|
|
1219
|
+
}
|
|
1169
1220
|
var MAX_REDIRECTS = 20;
|
|
1170
1221
|
var REMEMBERED_HOSTS = 8;
|
|
1171
1222
|
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
@@ -1419,7 +1470,7 @@ var Chain = class {
|
|
|
1419
1470
|
this.leftOrigin = true;
|
|
1420
1471
|
headers2 = hostClass === "derived" ? only(headers2, SAFELIST) : this.withoutCredentials(headers2);
|
|
1421
1472
|
}
|
|
1422
|
-
return this.settle({ address, hostClass, method, headers: headers2, body });
|
|
1473
|
+
return this.settle({ address, hostClass, method, headers: headers2, body, downgrade });
|
|
1423
1474
|
}
|
|
1424
1475
|
// 主机解析出的地址。解析不出(空)算连不上,不是这里的事。
|
|
1425
1476
|
resolved(addresses) {
|
|
@@ -1502,7 +1553,7 @@ var Chain = class {
|
|
|
1502
1553
|
return "only network stream addresses are allowed";
|
|
1503
1554
|
}
|
|
1504
1555
|
}
|
|
1505
|
-
settle({ address, hostClass, method, headers: headers2, body, frames }) {
|
|
1556
|
+
settle({ address, hostClass, method, headers: headers2, body, frames, downgrade = false }) {
|
|
1506
1557
|
if (hostClass === "derived") {
|
|
1507
1558
|
if (method !== "GET" && method !== "HEAD" || body) {
|
|
1508
1559
|
throw this.refuse(
|
|
@@ -1512,7 +1563,7 @@ var Chain = class {
|
|
|
1512
1563
|
);
|
|
1513
1564
|
}
|
|
1514
1565
|
const carried = [address.href, ...Object.keys(headers2), ...Object.values(headers2), ...frames ?? []];
|
|
1515
|
-
if (this.tokens.some((secret) => carried.some((text) => carries(text, secret)))) {
|
|
1566
|
+
if (this.tokens.some((secret) => carried.some((text) => carries(text, secret))) && !vouchedByUserHost(address.host, this.use, this.user, downgrade)) {
|
|
1516
1567
|
throw this.refuse("derived-no-secrets", address, `credentials may not be sent to ${address.host}, a host that is neither declared nor given by the user`);
|
|
1517
1568
|
}
|
|
1518
1569
|
}
|
|
@@ -1831,11 +1882,85 @@ function readAttributes(text) {
|
|
|
1831
1882
|
}
|
|
1832
1883
|
return { attributes, rest: void 0 };
|
|
1833
1884
|
}
|
|
1834
|
-
var
|
|
1885
|
+
var PAIRS = /* @__PURE__ */ Symbol("pairs");
|
|
1886
|
+
var HEADER_FORMS = [
|
|
1887
|
+
{ directive: "#extinf", key: "http-header", carrier: PAIRS },
|
|
1888
|
+
{ directive: "#extinf", key: "http-user-agent", carrier: "User-Agent" },
|
|
1889
|
+
{ directive: "#extinf", key: "http-referrer", carrier: "Referer" },
|
|
1890
|
+
{ directive: "#extinf", key: "http-referer", carrier: "Referer" },
|
|
1891
|
+
{ directive: "#extvlcopt", key: "http-user-agent", carrier: "User-Agent" },
|
|
1892
|
+
{ directive: "#extvlcopt", key: "http-referrer", carrier: "Referer" },
|
|
1893
|
+
{ directive: "#extvlcopt", key: "http-referer", carrier: "Referer" },
|
|
1894
|
+
{ directive: "#kodiprop", key: "inputstream.adaptive.common_headers", carrier: PAIRS },
|
|
1895
|
+
{ directive: "#kodiprop", key: "inputstream.adaptive.manifest_headers", carrier: PAIRS },
|
|
1896
|
+
{ directive: "#kodiprop", key: "inputstream.adaptive.stream_headers", carrier: PAIRS }
|
|
1897
|
+
];
|
|
1898
|
+
var HEADER_NAMES = /* @__PURE__ */ new Map([["user-agent", "User-Agent"], ["referer", "Referer"], ["referrer", "Referer"]]);
|
|
1899
|
+
var NON_HEADER_OPTIONS = /* @__PURE__ */ new Set([
|
|
1900
|
+
"seekable",
|
|
1901
|
+
"reconnect_at_eof",
|
|
1902
|
+
"reconnect_streamed",
|
|
1903
|
+
"reconnect_delay_max",
|
|
1904
|
+
"icy",
|
|
1905
|
+
"icy_metadata_headers",
|
|
1906
|
+
"icy_metadata_packet"
|
|
1907
|
+
]);
|
|
1908
|
+
var RESERVED_HEADERS = /* @__PURE__ */ new Set(["host", "content-length", "connection", "proxy-authenticate", "proxy-authorization", "www-authenticate"]);
|
|
1909
|
+
var HEADER_TOKEN = /^[!#$%&'*+\-.^_\x60|~0-9A-Za-z]+$/;
|
|
1910
|
+
var HEADER_CONTROL = /[\x00-\x08\x0A-\x1F\x7F]/;
|
|
1911
|
+
var M3UHeaders = class {
|
|
1912
|
+
fields = /* @__PURE__ */ new Map();
|
|
1913
|
+
record() {
|
|
1914
|
+
return this.fields.size === 0 ? void 0 : Object.fromEntries(this.fields.values());
|
|
1915
|
+
}
|
|
1916
|
+
set(name2, raw) {
|
|
1917
|
+
const value = trimSpace(raw);
|
|
1918
|
+
if (!HEADER_TOKEN.test(name2) || value === "" || HEADER_CONTROL.test(value)) return;
|
|
1919
|
+
const lower2 = asciiLower(name2);
|
|
1920
|
+
if (RESERVED_HEADERS.has(lower2)) return;
|
|
1921
|
+
this.fields.set(lower2, [name2, value]);
|
|
1922
|
+
}
|
|
1923
|
+
apply(carrier, value) {
|
|
1924
|
+
if (carrier === PAIRS) this.setPairs(value);
|
|
1925
|
+
else this.set(carrier, value);
|
|
1926
|
+
}
|
|
1927
|
+
// `名=值&名=值`:名字前的 `!` 是 Kodi 的自定义头记号;值能按 URL 解码就解码,解不了按原样。
|
|
1928
|
+
setPairs(text) {
|
|
1929
|
+
for (const pair of headerPairs(text)) {
|
|
1930
|
+
if (pair === void 0) continue;
|
|
1931
|
+
const [name2, raw] = pair;
|
|
1932
|
+
const lower2 = asciiLower(name2);
|
|
1933
|
+
if (NON_HEADER_OPTIONS.has(lower2)) continue;
|
|
1934
|
+
this.set(HEADER_NAMES.get(lower2) ?? name2, decodedOr(raw));
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
};
|
|
1938
|
+
function headerPairs(text) {
|
|
1939
|
+
return text.split("&").filter((pair) => pair !== "").map((pair) => {
|
|
1940
|
+
const equals = pair.indexOf("=");
|
|
1941
|
+
if (equals === -1) return void 0;
|
|
1942
|
+
const name2 = trimSpace(pair.slice(0, equals));
|
|
1943
|
+
return [name2.startsWith("!") ? name2.slice(1) : name2, pair.slice(equals + 1)];
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
function headerSuffix(line) {
|
|
1947
|
+
const bar = line.indexOf("|");
|
|
1948
|
+
if (bar <= 0) return void 0;
|
|
1949
|
+
const suffix = line.slice(bar + 1);
|
|
1950
|
+
const isHeaders = headerPairs(suffix).every((pair) => pair !== void 0 && HEADER_TOKEN.test(pair[0]));
|
|
1951
|
+
return isHeaders ? { url: trimSpace(line.slice(0, bar)), suffix } : void 0;
|
|
1952
|
+
}
|
|
1953
|
+
function decodedOr(raw) {
|
|
1954
|
+
try {
|
|
1955
|
+
return decodeURIComponent(raw);
|
|
1956
|
+
} catch {
|
|
1957
|
+
return raw;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1835
1960
|
function parseM3U(data) {
|
|
1836
1961
|
const playlist = { guideURLs: [], attributes: {}, entries: [] };
|
|
1837
1962
|
let info;
|
|
1838
|
-
let
|
|
1963
|
+
let directiveHeaders = [];
|
|
1839
1964
|
let group;
|
|
1840
1965
|
for (const raw of splitLines(textOf(data))) {
|
|
1841
1966
|
const line = trimSpace(raw);
|
|
@@ -1843,19 +1968,28 @@ function parseM3U(data) {
|
|
|
1843
1968
|
if (line[0] !== "#") {
|
|
1844
1969
|
const attributes = info?.attributes ?? /* @__PURE__ */ new Map();
|
|
1845
1970
|
const tvgName = nonEmpty(attributes.get("tvg-name"));
|
|
1971
|
+
const headers2 = new M3UHeaders();
|
|
1972
|
+
for (const form of HEADER_FORMS) {
|
|
1973
|
+
const value2 = form.directive === "#extinf" ? attributes.get(form.key) : void 0;
|
|
1974
|
+
if (value2 !== void 0) headers2.apply(form.carrier, value2);
|
|
1975
|
+
}
|
|
1976
|
+
for (const [carrier, value2] of directiveHeaders) headers2.apply(carrier, value2);
|
|
1977
|
+
const split = headerSuffix(line);
|
|
1978
|
+
const url = split?.url ?? line;
|
|
1979
|
+
if (split !== void 0) headers2.setPairs(split.suffix);
|
|
1846
1980
|
playlist.entries.push(compact({
|
|
1847
|
-
url
|
|
1848
|
-
title: nonEmpty(info?.title) ?? tvgName ??
|
|
1981
|
+
url,
|
|
1982
|
+
title: nonEmpty(info?.title) ?? tvgName ?? url,
|
|
1849
1983
|
duration: info?.duration ?? -1,
|
|
1850
1984
|
tvgId: nonEmpty(attributes.get("tvg-id")),
|
|
1851
1985
|
tvgName,
|
|
1852
1986
|
logo: nonEmpty(attributes.get("tvg-logo")),
|
|
1853
1987
|
group: nonEmpty(attributes.get("group-title")) ?? group,
|
|
1854
|
-
headers: headers2.
|
|
1988
|
+
headers: headers2.record(),
|
|
1855
1989
|
attributes: Object.fromEntries(attributes)
|
|
1856
1990
|
}));
|
|
1857
1991
|
info = void 0;
|
|
1858
|
-
|
|
1992
|
+
directiveHeaders = [];
|
|
1859
1993
|
group = void 0;
|
|
1860
1994
|
continue;
|
|
1861
1995
|
}
|
|
@@ -1876,13 +2010,13 @@ function parseM3U(data) {
|
|
|
1876
2010
|
const { attributes, rest } = readAttributes(duration === null ? value : value.slice(duration[0].length));
|
|
1877
2011
|
const seconds = duration === null ? -1 : Number(duration[1]);
|
|
1878
2012
|
info = { duration: Number.isFinite(seconds) ? seconds : -1, attributes, title: trimSpace(rest ?? "") };
|
|
1879
|
-
} else if (directive === "#extvlcopt") {
|
|
1880
|
-
const equals = value.indexOf("=");
|
|
1881
|
-
const name3 = VLC_HEADERS.get(asciiLower(trimSpace(equals === -1 ? value : value.slice(0, equals))));
|
|
1882
|
-
const headerValue = equals === -1 ? "" : trimSpace(value.slice(equals + 1));
|
|
1883
|
-
if (name3 !== void 0 && headerValue !== "") headers2.set(name3, headerValue);
|
|
1884
2013
|
} else if (directive === "#extgrp") {
|
|
1885
2014
|
group = nonEmpty(value);
|
|
2015
|
+
} else {
|
|
2016
|
+
const equals = value.indexOf("=");
|
|
2017
|
+
const key = asciiLower(trimSpace(equals === -1 ? value : value.slice(0, equals)));
|
|
2018
|
+
const form = HEADER_FORMS.find((row) => row.directive === directive && row.key === key);
|
|
2019
|
+
if (equals !== -1 && form !== void 0) directiveHeaders.push([form.carrier, value.slice(equals + 1)]);
|
|
1886
2020
|
}
|
|
1887
2021
|
}
|
|
1888
2022
|
return playlist;
|
|
@@ -2134,6 +2268,121 @@ function createMetadata(service) {
|
|
|
2134
2268
|
};
|
|
2135
2269
|
}
|
|
2136
2270
|
|
|
2271
|
+
// host/interop-crypto.ts
|
|
2272
|
+
var rotl = (x, n) => x << n | x >>> 32 - n;
|
|
2273
|
+
function padded(data, littleEndian) {
|
|
2274
|
+
const length = (data.length + 8 >> 6) + 1 << 6;
|
|
2275
|
+
const block = new Uint8Array(length);
|
|
2276
|
+
block.set(data);
|
|
2277
|
+
block[data.length] = 128;
|
|
2278
|
+
const view = new DataView(block.buffer);
|
|
2279
|
+
const bits = data.length * 8;
|
|
2280
|
+
const high = Math.floor(bits / 4294967296);
|
|
2281
|
+
const low = bits >>> 0;
|
|
2282
|
+
if (littleEndian) {
|
|
2283
|
+
view.setUint32(length - 8, low, true);
|
|
2284
|
+
view.setUint32(length - 4, high, true);
|
|
2285
|
+
} else {
|
|
2286
|
+
view.setUint32(length - 8, high);
|
|
2287
|
+
view.setUint32(length - 4, low);
|
|
2288
|
+
}
|
|
2289
|
+
return view;
|
|
2290
|
+
}
|
|
2291
|
+
var MD5_K = Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0);
|
|
2292
|
+
var MD5_S = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21];
|
|
2293
|
+
function md5(data) {
|
|
2294
|
+
const view = padded(data, true);
|
|
2295
|
+
let a0 = 1732584193, b0 = 4023233417, c0 = 2562383102, d0 = 271733878;
|
|
2296
|
+
const m = new Array(16);
|
|
2297
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) {
|
|
2298
|
+
for (let i = 0; i < 16; i++) m[i] = view.getUint32(offset + i * 4, true);
|
|
2299
|
+
let a = a0, b = b0, c = c0, d = d0;
|
|
2300
|
+
for (let i = 0; i < 64; i++) {
|
|
2301
|
+
const round = i >> 4;
|
|
2302
|
+
let f, g;
|
|
2303
|
+
if (round === 0) {
|
|
2304
|
+
f = b & c | ~b & d;
|
|
2305
|
+
g = i;
|
|
2306
|
+
} else if (round === 1) {
|
|
2307
|
+
f = d & b | ~d & c;
|
|
2308
|
+
g = 5 * i + 1 & 15;
|
|
2309
|
+
} else if (round === 2) {
|
|
2310
|
+
f = b ^ c ^ d;
|
|
2311
|
+
g = 3 * i + 5 & 15;
|
|
2312
|
+
} else {
|
|
2313
|
+
f = c ^ (b | ~d);
|
|
2314
|
+
g = 7 * i & 15;
|
|
2315
|
+
}
|
|
2316
|
+
const next = d;
|
|
2317
|
+
d = c;
|
|
2318
|
+
c = b;
|
|
2319
|
+
b = b + rotl(a + f + MD5_K[i] + m[g] | 0, MD5_S[round << 2 | i & 3]) | 0;
|
|
2320
|
+
a = next;
|
|
2321
|
+
}
|
|
2322
|
+
a0 = a0 + a | 0;
|
|
2323
|
+
b0 = b0 + b | 0;
|
|
2324
|
+
c0 = c0 + c | 0;
|
|
2325
|
+
d0 = d0 + d | 0;
|
|
2326
|
+
}
|
|
2327
|
+
const out = new DataView(new ArrayBuffer(16));
|
|
2328
|
+
[a0, b0, c0, d0].forEach((word, i) => out.setUint32(i * 4, word >>> 0, true));
|
|
2329
|
+
return new Uint8Array(out.buffer);
|
|
2330
|
+
}
|
|
2331
|
+
var SM3_IV = [1937774191, 1226093241, 388252375, 3666478592, 2842636476, 372324522, 3817729613, 2969243214];
|
|
2332
|
+
var p0 = (x) => x ^ rotl(x, 9) ^ rotl(x, 17);
|
|
2333
|
+
var p1 = (x) => x ^ rotl(x, 15) ^ rotl(x, 23);
|
|
2334
|
+
function sm3(data) {
|
|
2335
|
+
const view = padded(data, false);
|
|
2336
|
+
const v = [...SM3_IV];
|
|
2337
|
+
const w = new Array(68);
|
|
2338
|
+
const w1 = new Array(64);
|
|
2339
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) {
|
|
2340
|
+
for (let j = 0; j < 16; j++) w[j] = view.getUint32(offset + j * 4) | 0;
|
|
2341
|
+
for (let j = 16; j < 68; j++) w[j] = p1(w[j - 16] ^ w[j - 9] ^ rotl(w[j - 3], 15)) ^ rotl(w[j - 13], 7) ^ w[j - 6];
|
|
2342
|
+
for (let j = 0; j < 64; j++) w1[j] = w[j] ^ w[j + 4];
|
|
2343
|
+
let [a, b, c, d, e, f, g, h] = v;
|
|
2344
|
+
for (let j = 0; j < 64; j++) {
|
|
2345
|
+
const t = j < 16 ? 2043430169 : 2055708042;
|
|
2346
|
+
const ss1 = rotl(rotl(a, 12) + e + rotl(t, j % 32) | 0, 7);
|
|
2347
|
+
const ss2 = ss1 ^ rotl(a, 12);
|
|
2348
|
+
const ff = j < 16 ? a ^ b ^ c : a & b | a & c | b & c;
|
|
2349
|
+
const gg = j < 16 ? e ^ f ^ g : e & f | ~e & g;
|
|
2350
|
+
const tt1 = ff + d + ss2 + w1[j] | 0;
|
|
2351
|
+
const tt2 = gg + h + ss1 + w[j] | 0;
|
|
2352
|
+
d = c;
|
|
2353
|
+
c = rotl(b, 9);
|
|
2354
|
+
b = a;
|
|
2355
|
+
a = tt1;
|
|
2356
|
+
h = g;
|
|
2357
|
+
g = rotl(f, 19);
|
|
2358
|
+
f = e;
|
|
2359
|
+
e = p0(tt2);
|
|
2360
|
+
}
|
|
2361
|
+
[a, b, c, d, e, f, g, h].forEach((word, i) => {
|
|
2362
|
+
v[i] ^= word;
|
|
2363
|
+
});
|
|
2364
|
+
}
|
|
2365
|
+
const out = new DataView(new ArrayBuffer(32));
|
|
2366
|
+
v.forEach((word, i) => out.setUint32(i * 4, word >>> 0));
|
|
2367
|
+
return new Uint8Array(out.buffer);
|
|
2368
|
+
}
|
|
2369
|
+
function rc4(key, data) {
|
|
2370
|
+
const s = new Uint8Array(256);
|
|
2371
|
+
for (let i = 0; i < 256; i++) s[i] = i;
|
|
2372
|
+
for (let i = 0, j = 0; i < 256; i++) {
|
|
2373
|
+
j = j + s[i] + key[i % key.length] & 255;
|
|
2374
|
+
[s[i], s[j]] = [s[j], s[i]];
|
|
2375
|
+
}
|
|
2376
|
+
const out = new Uint8Array(data.length);
|
|
2377
|
+
for (let n = 0, i = 0, j = 0; n < data.length; n++) {
|
|
2378
|
+
i = i + 1 & 255;
|
|
2379
|
+
j = j + s[i] & 255;
|
|
2380
|
+
[s[i], s[j]] = [s[j], s[i]];
|
|
2381
|
+
out[n] = data[n] ^ s[s[i] + s[j] & 255];
|
|
2382
|
+
}
|
|
2383
|
+
return out;
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2137
2386
|
// host/json-depth.ts
|
|
2138
2387
|
function pluginJSONText(bytes2) {
|
|
2139
2388
|
if (bytes2[0] === 239 && bytes2[1] === 187 && bytes2[2] === 191) return void 0;
|
|
@@ -2922,15 +3171,30 @@ function createSubtle() {
|
|
|
2922
3171
|
};
|
|
2923
3172
|
}
|
|
2924
3173
|
var DIGESTS = /* @__PURE__ */ new Map([["sha-1", "SHA-1"], ["sha-256", "SHA-256"], ["sha-384", "SHA-384"], ["sha-512", "SHA-512"]]);
|
|
3174
|
+
var INTEROP_DIGESTS = /* @__PURE__ */ new Map([["md5", md5], ["sm3", sm3]]);
|
|
3175
|
+
function plainBytes(value) {
|
|
3176
|
+
if (typeof value === "string") return new TextEncoder().encode(value);
|
|
3177
|
+
if (ArrayBuffer.isView(value) && Object.prototype.toString.call(value) === "[object Uint8Array]") return new Uint8Array(value);
|
|
3178
|
+
throw new TypeError("expected a Uint8Array or a string");
|
|
3179
|
+
}
|
|
2925
3180
|
async function plainDigest(algorithm, data) {
|
|
2926
|
-
const
|
|
2927
|
-
|
|
2928
|
-
|
|
3181
|
+
const lowered = String(algorithm).toLowerCase();
|
|
3182
|
+
const interop = INTEROP_DIGESTS.get(lowered);
|
|
3183
|
+
const name2 = DIGESTS.get(lowered);
|
|
3184
|
+
if (interop === void 0 && name2 === void 0) throw new TypeError(`unsupported digest ${algorithm}`);
|
|
3185
|
+
const bytes2 = plainBytes(data);
|
|
3186
|
+
return interop !== void 0 ? interop(bytes2) : new Uint8Array(await subtle().digest(name2, bytes2));
|
|
3187
|
+
}
|
|
3188
|
+
async function plainRC4(key, data) {
|
|
3189
|
+
const keyBytes = plainBytes(key);
|
|
3190
|
+
if (keyBytes.length < 1 || keyBytes.length > 256) throw new TypeError("krillplayer.crypto.rc4 needs a key of 1 to 256 bytes");
|
|
3191
|
+
return rc4(keyBytes, plainBytes(data));
|
|
2929
3192
|
}
|
|
2930
3193
|
function createCrypto() {
|
|
2931
3194
|
return {
|
|
2932
3195
|
randomBytes: (length) => globalThis.crypto.getRandomValues(new Uint8Array(length)),
|
|
2933
3196
|
digest: plainDigest,
|
|
3197
|
+
rc4: plainRC4,
|
|
2934
3198
|
subtle: createSubtle()
|
|
2935
3199
|
};
|
|
2936
3200
|
}
|
|
@@ -3703,7 +3967,7 @@ function readZip(zip) {
|
|
|
3703
3967
|
|
|
3704
3968
|
// trial-runner/cases.ts
|
|
3705
3969
|
import { readdir, readFile as readFile2 } from "node:fs/promises";
|
|
3706
|
-
import { join, relative } from "node:path";
|
|
3970
|
+
import { join as join2, relative } from "node:path";
|
|
3707
3971
|
|
|
3708
3972
|
// trial-runner/credentials.ts
|
|
3709
3973
|
import { readFile } from "node:fs/promises";
|
|
@@ -4146,7 +4410,7 @@ function recordingFetch(fetch) {
|
|
|
4146
4410
|
}
|
|
4147
4411
|
async function jsonFiles(directory) {
|
|
4148
4412
|
const entries = await readdir(directory, { recursive: true, withFileTypes: true });
|
|
4149
|
-
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json") && !entry.parentPath.includes("node_modules")).map((entry) =>
|
|
4413
|
+
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json") && !entry.parentPath.includes("node_modules")).map((entry) => join2(entry.parentPath, entry.name)).sort();
|
|
4150
4414
|
}
|
|
4151
4415
|
var BYTE_ORDER_MARK_IN_CASE = "case file holds U+FEFF, which the Swift kernel's JSON reader drops; keep such text as $bytes";
|
|
4152
4416
|
var holdsByteOrderMark = (raw) => raw.includes("\uFEFF") || /\\u[fF][eE][fF][fF]/.test(raw);
|
|
@@ -4235,8 +4499,8 @@ import { constants } from "node:fs";
|
|
|
4235
4499
|
import { access, mkdir, mkdtemp, readdir as readdir2, readFile as readFile3, rename, rm, stat } from "node:fs/promises";
|
|
4236
4500
|
import { createRequire } from "node:module";
|
|
4237
4501
|
import { homedir } from "node:os";
|
|
4238
|
-
import { dirname, join as
|
|
4239
|
-
import { fileURLToPath } from "node:url";
|
|
4502
|
+
import { dirname, join as join3, relative as relative2 } from "node:path";
|
|
4503
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
4240
4504
|
import { promisify } from "node:util";
|
|
4241
4505
|
|
|
4242
4506
|
// host/globals.ts
|
|
@@ -4348,7 +4612,7 @@ function decode(json, blob) {
|
|
|
4348
4612
|
}
|
|
4349
4613
|
|
|
4350
4614
|
// trial-runner/engine.ts
|
|
4351
|
-
var here = dirname(
|
|
4615
|
+
var here = dirname(fileURLToPath2(import.meta.url));
|
|
4352
4616
|
var run3 = promisify(execFile);
|
|
4353
4617
|
var KERNEL_LIMITS = {
|
|
4354
4618
|
memoryBytes: RUNTIME_LIMITS.memoryBytes,
|
|
@@ -4358,17 +4622,18 @@ var KERNEL_LIMITS = {
|
|
|
4358
4622
|
var packagedKernel;
|
|
4359
4623
|
function useKernelDirectory(directory) {
|
|
4360
4624
|
packagedKernel = directory;
|
|
4625
|
+
usePublicSuffixListFrom(directory);
|
|
4361
4626
|
}
|
|
4362
4627
|
function kernelDirectory() {
|
|
4363
|
-
return process.env.KRILLPLAYER_KERNEL_DIR ?? packagedKernel ??
|
|
4628
|
+
return process.env.KRILLPLAYER_KERNEL_DIR ?? packagedKernel ?? join3(here, "../../Packages/Kernel");
|
|
4364
4629
|
}
|
|
4365
4630
|
var FLAGS = ["-O2", "-D_GNU_SOURCE", "-DQUICKJS_NG_BUILD", "-DNDEBUG", "-w"];
|
|
4366
4631
|
async function files(directory) {
|
|
4367
4632
|
const entries = await readdir2(directory, { withFileTypes: true, recursive: true });
|
|
4368
|
-
return entries.filter((entry) => entry.isFile()).map((entry) =>
|
|
4633
|
+
return entries.filter((entry) => entry.isFile()).map((entry) => join3(entry.parentPath, entry.name)).sort();
|
|
4369
4634
|
}
|
|
4370
|
-
var DRIVER =
|
|
4371
|
-
async function engineSourceHash(quickjs =
|
|
4635
|
+
var DRIVER = join3(here, "engine/engine.c");
|
|
4636
|
+
async function engineSourceHash(quickjs = join3(kernelDirectory(), "Sources/CQuickJS")) {
|
|
4372
4637
|
const hash = createHash("sha256").update(JSON.stringify(FLAGS)).update("engine.c").update(await readFile3(DRIVER));
|
|
4373
4638
|
for (const file of await files(quickjs)) hash.update(relative2(quickjs, file)).update(await readFile3(file));
|
|
4374
4639
|
return hash.digest("hex");
|
|
@@ -4378,7 +4643,7 @@ async function prebuilt(source) {
|
|
|
4378
4643
|
try {
|
|
4379
4644
|
const manifest = createRequire(import.meta.url).resolve(`${ENGINE_PACKAGE()}/engine.json`);
|
|
4380
4645
|
if (JSON.parse(await readFile3(manifest, "utf8"))?.source !== source) return void 0;
|
|
4381
|
-
const binary2 =
|
|
4646
|
+
const binary2 = join3(dirname(manifest), "engine");
|
|
4382
4647
|
return await executable(binary2) ? binary2 : void 0;
|
|
4383
4648
|
} catch {
|
|
4384
4649
|
return void 0;
|
|
@@ -4394,7 +4659,7 @@ async function executable(file) {
|
|
|
4394
4659
|
}
|
|
4395
4660
|
var environment = (name2) => process.env[name2] || void 0;
|
|
4396
4661
|
async function build() {
|
|
4397
|
-
const quickjs =
|
|
4662
|
+
const quickjs = join3(kernelDirectory(), "Sources/CQuickJS");
|
|
4398
4663
|
const compiler = environment("CC") ?? "cc";
|
|
4399
4664
|
const source = await engineSourceHash(quickjs).catch((error) => {
|
|
4400
4665
|
throw new EngineFailure(`could not read the QuickJS-ng engine sources in ${quickjs}: ${error.message}`);
|
|
@@ -4408,15 +4673,15 @@ async function build() {
|
|
|
4408
4673
|
}
|
|
4409
4674
|
}
|
|
4410
4675
|
async function compileEngine(output, { compiler = environment("CC") ?? "cc", arch } = {}) {
|
|
4411
|
-
const quickjs =
|
|
4676
|
+
const quickjs = join3(kernelDirectory(), "Sources/CQuickJS");
|
|
4412
4677
|
await run3(compiler, [
|
|
4413
4678
|
...FLAGS,
|
|
4414
4679
|
...arch === void 0 ? [] : ["-arch", arch],
|
|
4415
|
-
`-I${
|
|
4680
|
+
`-I${join3(quickjs, "include")}`,
|
|
4416
4681
|
`-I${quickjs}`,
|
|
4417
4682
|
DRIVER,
|
|
4418
|
-
|
|
4419
|
-
|
|
4683
|
+
join3(quickjs, "kernel_qjs.c"),
|
|
4684
|
+
join3(quickjs, "quickjs_vendor.c"),
|
|
4420
4685
|
"-lm",
|
|
4421
4686
|
"-lpthread",
|
|
4422
4687
|
"-o",
|
|
@@ -4426,14 +4691,14 @@ async function compileEngine(output, { compiler = environment("CC") ?? "cc", arc
|
|
|
4426
4691
|
async function compile(quickjs, compiler, source) {
|
|
4427
4692
|
const version = (await run3(compiler, ["--version"])).stdout;
|
|
4428
4693
|
const key = createHash("sha256").update(source).update(version).digest("hex");
|
|
4429
|
-
const cache = environment("KRILLPLAYER_ENGINE_CACHE") ??
|
|
4430
|
-
const target =
|
|
4431
|
-
const binary2 =
|
|
4694
|
+
const cache = environment("KRILLPLAYER_ENGINE_CACHE") ?? join3(environment("XDG_CACHE_HOME") ?? join3(homedir(), ".cache"), "krillplayer-plugin/engine");
|
|
4695
|
+
const target = join3(cache, key.slice(0, 32));
|
|
4696
|
+
const binary2 = join3(target, "engine");
|
|
4432
4697
|
if (await executable(binary2)) return binary2;
|
|
4433
4698
|
await mkdir(cache, { recursive: true });
|
|
4434
|
-
const staging = await mkdtemp(
|
|
4699
|
+
const staging = await mkdtemp(join3(cache, "build-"));
|
|
4435
4700
|
try {
|
|
4436
|
-
await compileEngine(
|
|
4701
|
+
await compileEngine(join3(staging, "engine"), { compiler });
|
|
4437
4702
|
await rename(staging, target).catch(async (error) => {
|
|
4438
4703
|
if (error.code !== "ENOTEMPTY" && error.code !== "EEXIST") throw error;
|
|
4439
4704
|
await rm(staging, { recursive: true, force: true });
|
|
@@ -4451,7 +4716,7 @@ function engineBinary() {
|
|
|
4451
4716
|
}
|
|
4452
4717
|
var prelude;
|
|
4453
4718
|
function preludeSource() {
|
|
4454
|
-
const path =
|
|
4719
|
+
const path = join3(kernelDirectory(), "Sources/Kernel/PluginPrelude.js");
|
|
4455
4720
|
prelude ??= readFile3(path, "utf8").then(
|
|
4456
4721
|
(template) => template.replaceAll("__GLOBALS__", `[${[...PLUGIN_GLOBALS].sort().map((name2) => JSON.stringify(name2)).join(", ")}]`),
|
|
4457
4722
|
(error) => {
|
|
@@ -4584,6 +4849,7 @@ var CALLS = {
|
|
|
4584
4849
|
"formats.xml": (k, [data]) => k.formats.xml(data),
|
|
4585
4850
|
"decompress": (k, [format2, data]) => k.decompress(format2, data),
|
|
4586
4851
|
"crypto.digest": (k, [algorithm, data]) => k.crypto.digest(algorithm, data),
|
|
4852
|
+
"crypto.rc4": (k, [key, data]) => k.crypto.rc4(key, data),
|
|
4587
4853
|
"crypto.randomBytes": (k, [length]) => k.crypto.randomBytes(length),
|
|
4588
4854
|
"crypto.subtle.generateKey": (k, [algorithm, extractable, usages]) => k.crypto.subtle.generateKey(algorithm, extractable, usages),
|
|
4589
4855
|
"crypto.subtle.importKey": (k, [format2, keyData, algorithm, extractable, usages]) => k.crypto.subtle.importKey(format2, keyData, algorithm, extractable, usages),
|
|
@@ -5087,9 +5353,9 @@ function checkManifest(manifest) {
|
|
|
5087
5353
|
// trial-runner/trial.ts
|
|
5088
5354
|
async function readFiles(path) {
|
|
5089
5355
|
const entries = path.endsWith(".zip") ? [...readZip(await readFile4(path))] : await (async () => {
|
|
5090
|
-
const locales = (await readdir3(
|
|
5356
|
+
const locales = (await readdir3(join4(path, LOCALES)).catch(() => [])).filter((name2) => name2.endsWith(".json")).map((name2) => `${LOCALES}/${name2}`);
|
|
5091
5357
|
const names = [...(await readdir3(path)).filter((name2) => /\.m?js$/.test(name2) || name2 === "manifest.json"), ...locales];
|
|
5092
|
-
return Promise.all(names.map(async (name2) => [name2, await readFile4(
|
|
5358
|
+
return Promise.all(names.map(async (name2) => [name2, await readFile4(join4(path, name2))]));
|
|
5093
5359
|
})();
|
|
5094
5360
|
return new Map(entries.map(([name2, data]) => {
|
|
5095
5361
|
if (!name2.endsWith(".json")) return [name2, Buffer.from(data).toString("utf8")];
|
|
@@ -5114,10 +5380,10 @@ async function readPlugin(path) {
|
|
|
5114
5380
|
const manifest = JSON.parse(files2.get("manifest.json") ?? "{}");
|
|
5115
5381
|
const source = files2.get(scripts[0]);
|
|
5116
5382
|
const checked = checkPlugin(source);
|
|
5117
|
-
const capabilities = Array.isArray(manifest.capabilities) || checked.violations.length > 0 ? manifest.capabilities : await loadPlugin(source, { identifier:
|
|
5383
|
+
const capabilities = Array.isArray(manifest.capabilities) || checked.violations.length > 0 ? manifest.capabilities : await loadPlugin(source, { identifier: join4(path, scripts[0]), allowCodeGeneration: !checked.exports.includes("status") }).then((namespace) => capabilitiesOf(namespace).capabilities, () => void 0);
|
|
5118
5384
|
return {
|
|
5119
5385
|
id: manifest.id ?? basename(resolve(path)),
|
|
5120
|
-
file:
|
|
5386
|
+
file: join4(path, scripts[0]),
|
|
5121
5387
|
name: scripts[0],
|
|
5122
5388
|
source,
|
|
5123
5389
|
network: { hosts: manifest.hosts ?? [], userProvidedURLs: manifest.userProvidedURLs ?? false },
|
|
@@ -5465,14 +5731,14 @@ if (false) {
|
|
|
5465
5731
|
}
|
|
5466
5732
|
|
|
5467
5733
|
// packer/pack.ts
|
|
5468
|
-
var TEMPLATES =
|
|
5469
|
-
var SAMPLES =
|
|
5470
|
-
var SAMPLE_PACKAGES =
|
|
5734
|
+
var TEMPLATES = fileURLToPath3(new URL("../templates/", import.meta.url));
|
|
5735
|
+
var SAMPLES = fileURLToPath3(new URL("../samples/src/", import.meta.url));
|
|
5736
|
+
var SAMPLE_PACKAGES = fileURLToPath3(new URL("../samples/dist/", import.meta.url));
|
|
5471
5737
|
var ICON = "icon.png";
|
|
5472
5738
|
var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
5473
5739
|
var LOCALES2 = "locales";
|
|
5474
5740
|
async function dictionaries(directory) {
|
|
5475
|
-
const files2 = (await readdir4(
|
|
5741
|
+
const files2 = (await readdir4(join5(directory, LOCALES2)).catch(() => [])).sort();
|
|
5476
5742
|
const problems = [];
|
|
5477
5743
|
const tags = /* @__PURE__ */ new Map();
|
|
5478
5744
|
const result = [];
|
|
@@ -5488,7 +5754,7 @@ async function dictionaries(directory) {
|
|
|
5488
5754
|
continue;
|
|
5489
5755
|
}
|
|
5490
5756
|
tags.set(tag, file);
|
|
5491
|
-
const data = await readFile5(
|
|
5757
|
+
const data = await readFile5(join5(directory, LOCALES2, file));
|
|
5492
5758
|
bytes2 += data.length;
|
|
5493
5759
|
let table;
|
|
5494
5760
|
try {
|
|
@@ -5536,12 +5802,12 @@ async function pack(directory, warn = () => {
|
|
|
5536
5802
|
const source = result.outputFiles[0].text;
|
|
5537
5803
|
const { exports, violations } = checkPlugin(source);
|
|
5538
5804
|
if (violations.length > 0) throw new Error(`${directory}: ${violations.join("; ")}`);
|
|
5539
|
-
const namespace = await loadPlugin(source, { identifier:
|
|
5805
|
+
const namespace = await loadPlugin(source, { identifier: join5(directory, "plugin.js"), allowCodeGeneration: !exports.includes("status") });
|
|
5540
5806
|
const { capabilities, problems } = capabilitiesOf(namespace);
|
|
5541
5807
|
if (capabilities.length === 0 && problems.length === 0) problems.push("exports no capability; a plugin exports at least one slot or resolve");
|
|
5542
5808
|
if (problems.length > 0) throw new Error(`${directory}: ${problems.join("; ")}`);
|
|
5543
5809
|
for (const name2 of notYetUsedExports(namespace)) warn(`WARN ${directory}: exports ${name2}, which this version of the App does not call yet (App \u5C1A\u672A\u4F7F\u7528)`);
|
|
5544
|
-
const { default: metadata } = await import(pathToFileURL(
|
|
5810
|
+
const { default: metadata } = await import(pathToFileURL(join5(directory, "manifest.ts")).href);
|
|
5545
5811
|
if (metadata.interfaceLevel > CONTRACT.interfaceLevel || metadata.contractRevision !== CONTRACT.revision) {
|
|
5546
5812
|
throw new Error(`${directory}/manifest.ts targets interface level ${metadata.interfaceLevel} revision ${metadata.contractRevision}; the contract is level ${CONTRACT.interfaceLevel} revision ${CONTRACT.revision}`);
|
|
5547
5813
|
}
|
|
@@ -5556,7 +5822,7 @@ async function pack(directory, warn = () => {
|
|
|
5556
5822
|
throw new Error(`${directory}/manifest.ts: language ${metadata.language} is not a language tag (for example zh-Hans, en, ja)`);
|
|
5557
5823
|
}
|
|
5558
5824
|
const manifest = { ...metadata, ...language === void 0 ? {} : { language }, capabilities };
|
|
5559
|
-
const icon = await readFile5(
|
|
5825
|
+
const icon = await readFile5(join5(directory, ICON)).catch(() => void 0);
|
|
5560
5826
|
if (icon !== void 0 && !icon.subarray(0, 8).equals(PNG_SIGNATURE)) throw new Error(`${directory}/${ICON} is not a PNG`);
|
|
5561
5827
|
return writeZip([
|
|
5562
5828
|
{ name: "manifest.json", data: Buffer.from(`${JSON.stringify(manifest, null, 2)}
|
|
@@ -5578,20 +5844,20 @@ if (false) {
|
|
|
5578
5844
|
}
|
|
5579
5845
|
|
|
5580
5846
|
// package/cli.ts
|
|
5581
|
-
var here2 = dirname2(
|
|
5847
|
+
var here2 = dirname2(fileURLToPath4(import.meta.url));
|
|
5582
5848
|
var ROOT = basename2(here2) === "dist" ? dirname2(here2) : here2;
|
|
5583
5849
|
var PACKAGED = basename2(here2) === "dist";
|
|
5584
|
-
if (PACKAGED) useKernelDirectory(
|
|
5585
|
-
var TEMPLATES2 = PACKAGED ?
|
|
5586
|
-
var SKILL =
|
|
5850
|
+
if (PACKAGED) useKernelDirectory(join6(ROOT, "kernel"));
|
|
5851
|
+
var TEMPLATES2 = PACKAGED ? join6(ROOT, "templates") : join6(ROOT, "../templates");
|
|
5852
|
+
var SKILL = join6(ROOT, "skill/krillplayer-plugin");
|
|
5587
5853
|
var PACKAGE_NAME = "krillplayer-plugin";
|
|
5588
5854
|
function plugin(directory) {
|
|
5589
5855
|
const root = resolve3(directory ?? ".");
|
|
5590
|
-
return { root, cases:
|
|
5856
|
+
return { root, cases: join6(root, "cases"), zip: join6(root, "dist", `${basename2(root)}.zip`) };
|
|
5591
5857
|
}
|
|
5592
5858
|
function requirePlugin(directory) {
|
|
5593
5859
|
for (const file of ["plugin.ts", "manifest.ts"]) {
|
|
5594
|
-
if (!existsSync(
|
|
5860
|
+
if (!existsSync(join6(directory, file))) throw new UsageError(`${directory} has no ${file}; run this in a plugin directory, or npx ${PACKAGE_NAME} new <dir>`);
|
|
5595
5861
|
}
|
|
5596
5862
|
}
|
|
5597
5863
|
async function bundle(directory, out, log) {
|
|
@@ -5630,38 +5896,38 @@ var COMPILER_OPTIONS = {
|
|
|
5630
5896
|
};
|
|
5631
5897
|
var SCAFFOLD_TSCONFIG = { compilerOptions: COMPILER_OPTIONS, include: ["plugin.ts", "manifest.ts", "src/**/*.ts"] };
|
|
5632
5898
|
async function fallbackConfig(directory) {
|
|
5633
|
-
const config =
|
|
5634
|
-
await writeFile3(config, JSON.stringify({ compilerOptions: COMPILER_OPTIONS, files: ["plugin.ts", "manifest.ts"].map((file) =>
|
|
5899
|
+
const config = join6(await mkdtemp2(join6(tmpdir(), "krillplayer-plugin-tsconfig-")), "tsconfig.json");
|
|
5900
|
+
await writeFile3(config, JSON.stringify({ compilerOptions: COMPILER_OPTIONS, files: ["plugin.ts", "manifest.ts"].map((file) => join6(directory, file)) }));
|
|
5635
5901
|
return config;
|
|
5636
5902
|
}
|
|
5637
5903
|
async function newCommand(directory, { id, name: name2, template = "apple-hls" }, log) {
|
|
5638
5904
|
const target = resolve3(directory);
|
|
5639
5905
|
if (existsSync(target) && (await readdir5(target)).length > 0) throw new UsageError(`${target} already exists and is not empty`);
|
|
5640
|
-
const source =
|
|
5906
|
+
const source = join6(TEMPLATES2, template);
|
|
5641
5907
|
if (!existsSync(source)) throw new UsageError(`no template ${template}; templates: ${(await readdir5(TEMPLATES2)).join(", ")}`);
|
|
5642
5908
|
const slug = basename2(target).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "plugin";
|
|
5643
5909
|
const pluginId = id ?? `com.example.${slug}`;
|
|
5644
5910
|
await cp(source, target, { recursive: true });
|
|
5645
5911
|
for (const file of ["plugin.ts", "manifest.ts"]) {
|
|
5646
|
-
await writeFile3(
|
|
5912
|
+
await writeFile3(join6(target, file), rewriteImports(await readFile6(join6(target, file), "utf8")));
|
|
5647
5913
|
}
|
|
5648
|
-
const manifest = (await readFile6(
|
|
5649
|
-
await writeFile3(
|
|
5650
|
-
const { version } = JSON.parse(await readFile6(
|
|
5651
|
-
await writeFile3(
|
|
5914
|
+
const manifest = (await readFile6(join6(target, "manifest.ts"), "utf8")).replace(/id: "[^"]*"/, () => `id: ${JSON.stringify(pluginId)}`).replace(/sourceId: "[^"]*"/, () => `sourceId: ${JSON.stringify(slug)}`).replace(/name: "[^"]*"/, () => `name: ${JSON.stringify(name2 ?? basename2(target))}`).replace(/author: "[^"]*"/, () => `author: "<your name>"`).replace(/version: "[^"]*"/, () => `version: "0.1.0"`);
|
|
5915
|
+
await writeFile3(join6(target, "manifest.ts"), manifest);
|
|
5916
|
+
const { version } = JSON.parse(await readFile6(join6(ROOT, "package.json"), "utf8"));
|
|
5917
|
+
await writeFile3(join6(target, "package.json"), `${JSON.stringify(SCAFFOLD_PACKAGE(slug, version), null, 2)}
|
|
5652
5918
|
`);
|
|
5653
|
-
await writeFile3(
|
|
5919
|
+
await writeFile3(join6(target, "tsconfig.json"), `${JSON.stringify(SCAFFOLD_TSCONFIG, null, 2)}
|
|
5654
5920
|
`);
|
|
5655
|
-
await writeFile3(
|
|
5921
|
+
await writeFile3(join6(target, ".gitignore"), "node_modules/\ndist/\n");
|
|
5656
5922
|
log(`created ${target} from the ${template} template (contract revision ${CONTRACT.revision})`);
|
|
5657
5923
|
log(`next: cd ${relative3(process.cwd(), target) || "."} && npm install && npx ${PACKAGE_NAME} check`);
|
|
5658
5924
|
}
|
|
5659
5925
|
function tsc(directory) {
|
|
5660
|
-
for (const from of [
|
|
5926
|
+
for (const from of [join6(directory, "package.json"), join6(ROOT, "package.json")]) {
|
|
5661
5927
|
try {
|
|
5662
5928
|
const manifest = createRequire2(from).resolve("typescript/package.json");
|
|
5663
|
-
const bin = JSON.parse(
|
|
5664
|
-
return
|
|
5929
|
+
const bin = JSON.parse(readFileSync2(manifest, "utf8")).bin?.tsc ?? "bin/tsc";
|
|
5930
|
+
return join6(dirname2(manifest), bin);
|
|
5665
5931
|
} catch {
|
|
5666
5932
|
}
|
|
5667
5933
|
}
|
|
@@ -5673,7 +5939,7 @@ async function typecheck(directory, log) {
|
|
|
5673
5939
|
log(`FAIL typecheck: typescript is not installed; run npm install --save-dev typescript in ${directory}`);
|
|
5674
5940
|
return false;
|
|
5675
5941
|
}
|
|
5676
|
-
const own = existsSync(
|
|
5942
|
+
const own = existsSync(join6(directory, "tsconfig.json"));
|
|
5677
5943
|
const config = own ? directory : await fallbackConfig(directory);
|
|
5678
5944
|
try {
|
|
5679
5945
|
await promisify2(execFile2)(process.execPath, [compiler, "--noEmit", "-p", config], { cwd: directory, maxBuffer: 16 << 20 });
|