@boy-offi9-inc/tidepull 0.16.0 → 0.17.1
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/README.md +1 -1
- package/dist/cli-plugin.d.ts +11 -0
- package/dist/cli-plugin.js +86 -0
- package/dist/loader.js +17 -3
- package/dist/main.js +33 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,7 +109,7 @@ export default definePlugin({
|
|
|
109
109
|
}],
|
|
110
110
|
});
|
|
111
111
|
```
|
|
112
|
-
Plugins run before built-ins; the generic fallback is always last. From disk: `import { loadPlugins } from "@boy-offi9-inc/tidepull/loader"` (the CLI does this for you, and bundles DASH). Plugins may declare `version` and `npmPackage`; the CLI then checks npm (24h cache, `TIDEPULL_NO_UPDATE_CHECK=1` to disable) and highlights available plugin upgrades next to the core one. A plugin targeting a different `apiVersion` is refused with a clear message instead of failing mysteriously. **Plugins execute with your privileges. Only load code you trust.** See `src/extractors/_template.ts`.
|
|
112
|
+
`tidepull plugin install <npm-package>` npm-installs a plugin package and drops it into the plugin dir for you (`plugin list` / `plugin remove` too) — updates are still notice-only, never auto-installed. Plugins run before built-ins; the generic fallback is always last. From disk: `import { loadPlugins } from "@boy-offi9-inc/tidepull/loader"` (the CLI does this for you, and bundles DASH). Plugins may declare `version` and `npmPackage`; the CLI then checks npm (24h cache, `TIDEPULL_NO_UPDATE_CHECK=1` to disable) and highlights available plugin upgrades next to the core one. A plugin targeting a different `apiVersion` is refused with a clear message instead of failing mysteriously. **Plugins execute with your privileges. Only load code you trust.** See `src/extractors/_template.ts`.
|
|
113
113
|
|
|
114
114
|
Ready-made site plugins live in the public [boy-offi9-inc/tidepull-plugins](https://github.com/boy-offi9-inc/tidepull-plugins) repo; its `docs/PLUGINS.md` is the contract a plugin must satisfy (naming, `apiVersion`, what an extractor may touch, how it is reviewed) before it can be loaded there.
|
|
115
115
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function pluginEntryFile(pkgDir: string): string;
|
|
2
|
+
export declare function defaultStagingDir(pluginDir: string): string;
|
|
3
|
+
export declare function pluginInstall(pkg: string, pluginDir: string, log: {
|
|
4
|
+
tag: (t: string, s: string) => void;
|
|
5
|
+
}, env?: NodeJS.ProcessEnv): Promise<void>;
|
|
6
|
+
export declare function pluginList(pluginDir: string, log: {
|
|
7
|
+
tag: (t: string, s: string) => void;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function pluginRemove(name: string, pluginDir: string, log: {
|
|
10
|
+
tag: (t: string, s: string) => void;
|
|
11
|
+
}): void;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { TidepullError, errMsg } from "./core/errors.js";
|
|
5
|
+
import { loadPlugin } from "./loader.js";
|
|
6
|
+
const NPM_TIMEOUT = 120_000;
|
|
7
|
+
export function pluginEntryFile(pkgDir) {
|
|
8
|
+
const meta = JSON.parse(readFileSync(path.join(pkgDir, "package.json"), "utf8"));
|
|
9
|
+
let rel = meta.main;
|
|
10
|
+
if (!rel && meta.exports) {
|
|
11
|
+
const e = typeof meta.exports === "string" ? meta.exports : meta.exports["."];
|
|
12
|
+
rel = typeof e === "string" ? e : e?.default;
|
|
13
|
+
}
|
|
14
|
+
rel = rel ?? "index.js";
|
|
15
|
+
const direct = path.join(pkgDir, rel);
|
|
16
|
+
if (existsSync(direct) && statSync(direct).isFile())
|
|
17
|
+
return direct;
|
|
18
|
+
const ts = direct.replace(/\.(m?js|cjs)$/, ".ts");
|
|
19
|
+
if (existsSync(ts))
|
|
20
|
+
return ts;
|
|
21
|
+
throw new TidepullError(`Package has no plugin entry file (${rel} not found in ${pkgDir})`);
|
|
22
|
+
}
|
|
23
|
+
export function defaultStagingDir(pluginDir) {
|
|
24
|
+
return path.join(pluginDir, "_packages");
|
|
25
|
+
}
|
|
26
|
+
function splitPkgSpec(pkg) {
|
|
27
|
+
const i = pkg.indexOf("@", 1);
|
|
28
|
+
return i > 0 ? [pkg.slice(0, i), pkg] : [pkg, pkg];
|
|
29
|
+
}
|
|
30
|
+
export async function pluginInstall(pkg, pluginDir, log, env = process.env) {
|
|
31
|
+
if (!/^[@a-z0-9][\w./@-]*$/i.test(pkg))
|
|
32
|
+
throw new TidepullError(`Not a valid npm package name: "${pkg}"`);
|
|
33
|
+
const [name, spec] = splitPkgSpec(pkg);
|
|
34
|
+
if (!existsSync(pluginDir))
|
|
35
|
+
mkdirSync(pluginDir, { recursive: true });
|
|
36
|
+
const staging = defaultStagingDir(pluginDir);
|
|
37
|
+
const safe = name.replace(/[^\w@./-]/g, "_");
|
|
38
|
+
const pkgDir = path.join(staging, safe, "node_modules", name);
|
|
39
|
+
log.tag("plugin", `installing ${spec} via npm…`);
|
|
40
|
+
const r = spawnSync("npm", ["i", "--prefix", path.join(staging, safe), "--no-audit", "--no-fund", "--omit=dev", spec], { timeout: NPM_TIMEOUT, encoding: "utf8", env: { ...env, NPM_CONFIG_UPDATE_NOTIFIER: "false" } });
|
|
41
|
+
if (r.status !== 0 || !existsSync(pkgDir)) {
|
|
42
|
+
throw new TidepullError(`npm install failed for ${spec} (exit ${r.status})${r.stderr ? `: ${errMsg(new Error(r.stderr.split("\n").filter((l) => l.includes("npm error")).slice(-1)[0] ?? ""))}` : ""}`);
|
|
43
|
+
}
|
|
44
|
+
const entry = pluginEntryFile(pkgDir);
|
|
45
|
+
const stagePkg = path.join(staging, safe, "package.json");
|
|
46
|
+
try {
|
|
47
|
+
const meta2 = existsSync(stagePkg) ? JSON.parse(readFileSync(stagePkg, "utf8")) : {};
|
|
48
|
+
if (meta2.type !== "module") {
|
|
49
|
+
meta2.type = "module";
|
|
50
|
+
writeFileSync(stagePkg, JSON.stringify(meta2) + "\n");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch { }
|
|
54
|
+
const work = path.join(staging, safe, name.split("/").pop().replace(/[^\w.-]/g, "_") + path.extname(entry));
|
|
55
|
+
copyFileSync(entry, work);
|
|
56
|
+
const dest = path.join(pluginDir, name.split("/").pop().replace(/[^.\w-]/g, "_") + path.extname(entry));
|
|
57
|
+
writeFileSync(dest, `// tidepull plugin shim — real code lives in ${work}\nimport plugin from ${JSON.stringify(work)};\nexport default plugin;\n`);
|
|
58
|
+
const meta = JSON.parse(readFileSync(path.join(pkgDir, "package.json"), "utf8"));
|
|
59
|
+
log.tag("plugin", `installed ${name}${meta.version ? `@${meta.version}` : ""} → ${dest}`);
|
|
60
|
+
log.tag("plugin", "loaded on the next tidepull run (plugins load once at startup)");
|
|
61
|
+
}
|
|
62
|
+
export async function pluginList(pluginDir, log) {
|
|
63
|
+
if (!existsSync(pluginDir))
|
|
64
|
+
return log.tag("plugin", `no plugin dir at ${pluginDir}`);
|
|
65
|
+
const files = readdirSync(pluginDir).filter((f) => /\.(m?js|cjs|mts|ts)$/.test(f) && !f.endsWith(".d.ts")).sort();
|
|
66
|
+
if (!files.length)
|
|
67
|
+
return log.tag("plugin", `no plugins in ${pluginDir}`);
|
|
68
|
+
for (const f of files) {
|
|
69
|
+
try {
|
|
70
|
+
const p = await loadPlugin(path.join(pluginDir, f));
|
|
71
|
+
log.tag("plugin", `${f}: ${p.name}${p.version ? ` v${p.version}` : ""}${p.npmPackage ? ` (${p.npmPackage})` : ""} — ${p.extractors?.length ?? 0} extractor(s)`);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
log.tag("plugin", `${f}: UNUSABLE — ${errMsg(e)}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function pluginRemove(name, pluginDir, log) {
|
|
79
|
+
const resolved = path.resolve(pluginDir, name);
|
|
80
|
+
if (!resolved.startsWith(path.resolve(pluginDir) + path.sep))
|
|
81
|
+
throw new TidepullError(`Refusing to remove outside the plugin dir: ${name}`);
|
|
82
|
+
if (!existsSync(resolved))
|
|
83
|
+
throw new TidepullError(`No such plugin file: ${resolved}`);
|
|
84
|
+
rmSync(resolved);
|
|
85
|
+
log.tag("plugin", `removed ${resolved} (staging copies stay in ${defaultStagingDir(pluginDir)}; delete those too if wanted)`);
|
|
86
|
+
}
|
package/dist/loader.js
CHANGED
|
@@ -55,12 +55,26 @@ function ensureModuleType(dir) {
|
|
|
55
55
|
}
|
|
56
56
|
export async function loadPlugins(paths) {
|
|
57
57
|
const out = [];
|
|
58
|
+
const seen = new Map();
|
|
59
|
+
const warn = (msg) => { try {
|
|
60
|
+
process.stderr.write(`WARNING: ${msg}\n`);
|
|
61
|
+
}
|
|
62
|
+
catch { } };
|
|
63
|
+
const keep = (p, file) => {
|
|
64
|
+
const prev = seen.get(p.name);
|
|
65
|
+
if (prev !== undefined) {
|
|
66
|
+
warn(`duplicate plugin "${p.name}": ${file} ignored — already loaded from ${prev} (remove one of the two files)`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
seen.set(p.name, file);
|
|
70
|
+
out.push(p);
|
|
71
|
+
};
|
|
58
72
|
for (const p of paths) {
|
|
59
73
|
const s = await stat(p).catch(() => undefined);
|
|
60
74
|
if (!s)
|
|
61
75
|
throw new TidepullError(`Plugin path not found: ${p}`);
|
|
62
76
|
if (s.isFile()) {
|
|
63
|
-
|
|
77
|
+
keep(await loadPlugin(p), p);
|
|
64
78
|
continue;
|
|
65
79
|
}
|
|
66
80
|
ensureModuleType(p);
|
|
@@ -70,11 +84,11 @@ export async function loadPlugins(paths) {
|
|
|
70
84
|
const full = path.join(p, name);
|
|
71
85
|
const fs = await stat(full);
|
|
72
86
|
if (fs.isFile() && FILE_RE.test(name))
|
|
73
|
-
|
|
87
|
+
keep(await loadPlugin(full), full);
|
|
74
88
|
else if (fs.isDirectory()) {
|
|
75
89
|
const idx = (await readdir(full)).find((f) => INDEX_RE.test(f));
|
|
76
90
|
if (idx)
|
|
77
|
-
|
|
91
|
+
keep(await loadPlugin(path.join(full, idx)), path.join(full, idx));
|
|
78
92
|
}
|
|
79
93
|
}
|
|
80
94
|
}
|
package/dist/main.js
CHANGED
|
@@ -18,6 +18,7 @@ import { renderBanner } from "./ui/banner.js";
|
|
|
18
18
|
import { pickTheme, THEME_NAMES } from "./ui/theme.js";
|
|
19
19
|
import { Spinner } from "./ui/spinner.js";
|
|
20
20
|
import { checkUpdates, renderNotices } from "./updatecheck.js";
|
|
21
|
+
import { pluginInstall, pluginList, pluginRemove } from "./cli-plugin.js";
|
|
21
22
|
function ffmpegProbe() {
|
|
22
23
|
try {
|
|
23
24
|
const r = spawnSync("ffmpeg", ["-version"], { timeout: 2000, encoding: "utf8" });
|
|
@@ -62,6 +63,10 @@ Info only (nothing is downloaded):
|
|
|
62
63
|
Plugins:
|
|
63
64
|
--plugin PATH Load a plugin file or directory (repeatable). Plugins run with your privileges!
|
|
64
65
|
--no-plugins Skip auto-loading ~/.config/tidepull/plugins (or $TIDEPULL_PLUGIN_DIR)
|
|
66
|
+
plugin install PKG... npm-install a plugin package and copy its entry file into the plugin dir
|
|
67
|
+
(supports <pkg>@<version>; core stays notice-only — updates are never auto-installed)
|
|
68
|
+
plugin list Show installed plugins with their declared name/version
|
|
69
|
+
plugin remove FILE... Delete plugin files from the plugin dir
|
|
65
70
|
|
|
66
71
|
Input:
|
|
67
72
|
-a, --batch-file FILE Read URLs from FILE, one per line ("-" = stdin, # starts a comment)
|
|
@@ -227,6 +232,34 @@ export async function main(argv) {
|
|
|
227
232
|
theme,
|
|
228
233
|
});
|
|
229
234
|
const urls = [...positionals];
|
|
235
|
+
if (positionals[0] === "plugin") {
|
|
236
|
+
const [, cmd, ...rest] = positionals;
|
|
237
|
+
try {
|
|
238
|
+
if (cmd === "install") {
|
|
239
|
+
if (!rest.length)
|
|
240
|
+
throw new TidepullError("usage: tidepull plugin install <npm-package> [more-packages...]");
|
|
241
|
+
for (const pkg of rest)
|
|
242
|
+
await pluginInstall(pkg, defaultPluginDir(), log);
|
|
243
|
+
}
|
|
244
|
+
else if (cmd === "list") {
|
|
245
|
+
await pluginList(defaultPluginDir(), log);
|
|
246
|
+
}
|
|
247
|
+
else if (cmd === "remove") {
|
|
248
|
+
if (!rest.length)
|
|
249
|
+
throw new TidepullError("usage: tidepull plugin remove <file-in-plugin-dir> [more...]");
|
|
250
|
+
for (const f of rest)
|
|
251
|
+
pluginRemove(f, defaultPluginDir(), log);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
throw new TidepullError("usage: tidepull plugin <install|list|remove> …");
|
|
255
|
+
}
|
|
256
|
+
return 0;
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
log.error(errMsg(e));
|
|
260
|
+
return e instanceof TidepullError ? e.exitCode : 1;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
230
263
|
let limitRate;
|
|
231
264
|
let archive;
|
|
232
265
|
let cookies;
|
package/package.json
CHANGED