diffwiki-core 0.14.0 → 0.15.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/bm25.cjs +6 -0
- package/dist/bm25.js +1 -1
- package/dist/chunk-6MW6KSS4.js +278 -0
- package/dist/{chunk-FTUF6IXS.js → chunk-TK2373AM.js} +6 -0
- package/dist/{chunk-7V2DIQNL.js → chunk-TXM4OGBA.js} +12 -3
- package/dist/{events-AVD3G5AX.js → events-K3MKWACA.js} +1 -1
- package/dist/frontmatter-ghMCpLNf.d.cts +585 -0
- package/dist/frontmatter-ghMCpLNf.d.ts +585 -0
- package/dist/index.cjs +303 -195
- package/dist/index.d.cts +69 -359
- package/dist/index.d.ts +69 -359
- package/dist/index.js +200 -189
- package/dist/plugin.cjs +134 -2
- package/dist/plugin.d.cts +54 -177
- package/dist/plugin.d.ts +54 -177
- package/dist/plugin.js +9 -3
- package/package.json +1 -1
- package/dist/chunk-EEETAETA.js +0 -145
package/dist/plugin.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
commandExists,
|
|
3
3
|
definePlugin,
|
|
4
|
+
ensureTool,
|
|
5
|
+
parseArticle,
|
|
4
6
|
resolveDependency,
|
|
5
7
|
runProcess,
|
|
6
|
-
runProcessJson
|
|
7
|
-
|
|
8
|
+
runProcessJson,
|
|
9
|
+
stripFrontmatter
|
|
10
|
+
} from "./chunk-6MW6KSS4.js";
|
|
8
11
|
export {
|
|
9
12
|
commandExists,
|
|
10
13
|
definePlugin,
|
|
14
|
+
ensureTool,
|
|
15
|
+
parseArticle,
|
|
11
16
|
resolveDependency,
|
|
12
17
|
runProcess,
|
|
13
|
-
runProcessJson
|
|
18
|
+
runProcessJson,
|
|
19
|
+
stripFrontmatter
|
|
14
20
|
};
|
package/package.json
CHANGED
package/dist/chunk-EEETAETA.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
// src/plugins/sdk.ts
|
|
2
|
-
import { execFile } from "child_process";
|
|
3
|
-
import { promisify } from "util";
|
|
4
|
-
import { existsSync, readFileSync } from "fs";
|
|
5
|
-
import { dirname, join } from "path";
|
|
6
|
-
import { fileURLToPath } from "url";
|
|
7
|
-
var execFileAsync = promisify(execFile);
|
|
8
|
-
async function runProcess(file, args, opts) {
|
|
9
|
-
const { stdout, stderr } = await execFileAsync(file, args, {
|
|
10
|
-
env: opts?.env,
|
|
11
|
-
timeout: opts?.timeout,
|
|
12
|
-
// Large: qmd emits multi-MB JSON search payloads that overflow the default 1 MB.
|
|
13
|
-
maxBuffer: 50 * 1024 * 1024
|
|
14
|
-
});
|
|
15
|
-
return { stdout, stderr };
|
|
16
|
-
}
|
|
17
|
-
async function runProcessJson(file, args, opts) {
|
|
18
|
-
const { stdout } = await runProcess(file, args, opts);
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(stdout);
|
|
21
|
-
} catch {
|
|
22
|
-
throw new Error(`${file} ${args.join(" ")} did not return valid JSON: ${stdout.slice(0, 200)}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async function commandExists(name) {
|
|
26
|
-
try {
|
|
27
|
-
await execFileAsync(name, ["--version"]);
|
|
28
|
-
return true;
|
|
29
|
-
} catch {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function resolveNpmBin(pkg, command, fromUrl) {
|
|
34
|
-
try {
|
|
35
|
-
let dir = dirname(fileURLToPath(fromUrl));
|
|
36
|
-
for (; ; ) {
|
|
37
|
-
const pkgJson = join(dir, "node_modules", pkg, "package.json");
|
|
38
|
-
if (existsSync(pkgJson)) {
|
|
39
|
-
const raw = JSON.parse(readFileSync(pkgJson, "utf8"));
|
|
40
|
-
const rel = typeof raw.bin === "string" ? raw.bin : raw.bin?.[command];
|
|
41
|
-
if (!rel) return null;
|
|
42
|
-
const binPath = join(dirname(pkgJson), rel);
|
|
43
|
-
return existsSync(binPath) ? binPath : null;
|
|
44
|
-
}
|
|
45
|
-
const parent = dirname(dir);
|
|
46
|
-
if (parent === dir) return null;
|
|
47
|
-
dir = parent;
|
|
48
|
-
}
|
|
49
|
-
} catch {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async function resolveDependency(dep, fromUrl) {
|
|
54
|
-
if (dep.npm) {
|
|
55
|
-
const local = resolveNpmBin(dep.npm, dep.command, fromUrl);
|
|
56
|
-
if (local) return { dependency: dep, command: [local], source: "npm" };
|
|
57
|
-
}
|
|
58
|
-
if (await commandExists(dep.command)) {
|
|
59
|
-
return { dependency: dep, command: [dep.command], source: "path" };
|
|
60
|
-
}
|
|
61
|
-
return { dependency: dep, command: null, source: "missing" };
|
|
62
|
-
}
|
|
63
|
-
function definePlugin(def) {
|
|
64
|
-
const { name, kind, version, capabilities, dependencies, handlers } = def;
|
|
65
|
-
const describeResult = {
|
|
66
|
-
name,
|
|
67
|
-
kind,
|
|
68
|
-
version,
|
|
69
|
-
capabilities: {
|
|
70
|
-
searchTypes: capabilities.searchTypes,
|
|
71
|
-
collectionFilter: capabilities.collectionFilter,
|
|
72
|
-
events: capabilities.events
|
|
73
|
-
},
|
|
74
|
-
dependencies: (dependencies ?? []).map((d) => ({ command: d.command, npm: d.npm, hint: d.hint }))
|
|
75
|
-
};
|
|
76
|
-
async function dispatch(op, params, log) {
|
|
77
|
-
switch (op) {
|
|
78
|
-
case "describe":
|
|
79
|
-
return describeResult;
|
|
80
|
-
case "search":
|
|
81
|
-
return handlers.search(params, log);
|
|
82
|
-
case "index":
|
|
83
|
-
if (handlers.index) return handlers.index(params, log);
|
|
84
|
-
return { indexed: 0 };
|
|
85
|
-
case "setup":
|
|
86
|
-
if (handlers.setup) return handlers.setup(params, log);
|
|
87
|
-
return { ready: true };
|
|
88
|
-
case "event":
|
|
89
|
-
if (handlers.onEvent) return handlers.onEvent(params, log);
|
|
90
|
-
return { accepted: true };
|
|
91
|
-
case "health":
|
|
92
|
-
if (handlers.health) return handlers.health(params, log);
|
|
93
|
-
return { ready: true, diagnostics: [] };
|
|
94
|
-
default:
|
|
95
|
-
throw new Error(`unknown op: ${op}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function run() {
|
|
99
|
-
const log = (level, message) => {
|
|
100
|
-
process.stderr.write(JSON.stringify({ log: { level, message } }) + "\n");
|
|
101
|
-
};
|
|
102
|
-
let buffer = "";
|
|
103
|
-
process.stdin.setEncoding("utf8");
|
|
104
|
-
process.stdin.on("data", (chunk) => {
|
|
105
|
-
buffer += chunk;
|
|
106
|
-
});
|
|
107
|
-
process.stdin.on("end", () => {
|
|
108
|
-
const line = buffer.trim();
|
|
109
|
-
if (!line) {
|
|
110
|
-
process.stderr.write(`${name}: no input received on stdin
|
|
111
|
-
`);
|
|
112
|
-
process.exit(1);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
let req;
|
|
116
|
-
try {
|
|
117
|
-
req = JSON.parse(line);
|
|
118
|
-
} catch {
|
|
119
|
-
process.stderr.write(`${name}: malformed JSON on stdin: ${line.slice(0, 200)}
|
|
120
|
-
`);
|
|
121
|
-
process.exit(1);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
dispatch(req.op, req.params ?? {}, log).then((result) => {
|
|
125
|
-
const response = { ok: true, result };
|
|
126
|
-
process.stdout.write(JSON.stringify(response) + "\n");
|
|
127
|
-
process.exit(0);
|
|
128
|
-
}).catch((err) => {
|
|
129
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
130
|
-
const response = { ok: false, error: { message } };
|
|
131
|
-
process.stdout.write(JSON.stringify(response) + "\n");
|
|
132
|
-
process.exit(1);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
return { definition: def, run };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export {
|
|
140
|
-
runProcess,
|
|
141
|
-
runProcessJson,
|
|
142
|
-
commandExists,
|
|
143
|
-
resolveDependency,
|
|
144
|
-
definePlugin
|
|
145
|
-
};
|