@openclaw/diffs-language-pack 2026.5.28-beta.3
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/api.js +2 -0
- package/dist/assets/viewer-runtime.js +259 -0
- package/dist/index.js +116 -0
- package/npm-shrinkwrap.json +12 -0
- package/openclaw.plugin.json +14 -0
- package/package.json +58 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { definePluginEntry } from "./api.js";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
//#region extensions/diffs-language-pack/src/viewer-assets.ts
|
|
6
|
+
const VIEWER_ASSET_PREFIX = "/plugins/diffs-language-pack/assets/";
|
|
7
|
+
const VIEWER_LOADER_PATH = `${VIEWER_ASSET_PREFIX}viewer.js`;
|
|
8
|
+
const VIEWER_RUNTIME_PATH = `${VIEWER_ASSET_PREFIX}viewer-runtime.js`;
|
|
9
|
+
const VIEWER_RUNTIME_RELATIVE_IMPORT_PATH = "./viewer-runtime.js";
|
|
10
|
+
const VIEWER_RUNTIME_CANDIDATE_RELATIVE_PATHS = ["./assets/viewer-runtime.js", "../assets/viewer-runtime.js"];
|
|
11
|
+
let runtimeAssetCache = null;
|
|
12
|
+
function isMissingFileError(error) {
|
|
13
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
14
|
+
}
|
|
15
|
+
async function resolveViewerRuntimeFileUrl() {
|
|
16
|
+
let missingFileError = null;
|
|
17
|
+
for (const relativePath of VIEWER_RUNTIME_CANDIDATE_RELATIVE_PATHS) {
|
|
18
|
+
const candidateUrl = new URL(relativePath, import.meta.url);
|
|
19
|
+
try {
|
|
20
|
+
await fs.stat(fileURLToPath(candidateUrl));
|
|
21
|
+
return candidateUrl;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (isMissingFileError(error)) {
|
|
24
|
+
missingFileError = error;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (missingFileError) throw missingFileError;
|
|
31
|
+
throw new Error("viewer runtime asset candidates were not checked");
|
|
32
|
+
}
|
|
33
|
+
async function getServedViewerAsset(pathname) {
|
|
34
|
+
if (pathname !== VIEWER_LOADER_PATH && pathname !== VIEWER_RUNTIME_PATH) return null;
|
|
35
|
+
const assets = await loadViewerAssets();
|
|
36
|
+
if (pathname === VIEWER_LOADER_PATH) return {
|
|
37
|
+
body: assets.loaderBody,
|
|
38
|
+
contentType: "text/javascript; charset=utf-8"
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
body: assets.runtimeBody,
|
|
42
|
+
contentType: "text/javascript; charset=utf-8"
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function loadViewerAssets() {
|
|
46
|
+
const runtimePath = fileURLToPath(await resolveViewerRuntimeFileUrl());
|
|
47
|
+
const runtimeStat = await fs.stat(runtimePath);
|
|
48
|
+
if (runtimeAssetCache && runtimeAssetCache.mtimeMs === runtimeStat.mtimeMs) return runtimeAssetCache;
|
|
49
|
+
const runtimeBody = await fs.readFile(runtimePath);
|
|
50
|
+
const hash = crypto.createHash("sha1").update(runtimeBody).digest("hex").slice(0, 12);
|
|
51
|
+
runtimeAssetCache = {
|
|
52
|
+
mtimeMs: runtimeStat.mtimeMs,
|
|
53
|
+
runtimeBody,
|
|
54
|
+
loaderBody: `import "${VIEWER_RUNTIME_RELATIVE_IMPORT_PATH}?v=${hash}";\n`
|
|
55
|
+
};
|
|
56
|
+
return runtimeAssetCache;
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region extensions/diffs-language-pack/src/plugin.ts
|
|
60
|
+
function registerDiffsLanguagePackPlugin(api) {
|
|
61
|
+
api.registerHttpRoute({
|
|
62
|
+
path: "/plugins/diffs-language-pack",
|
|
63
|
+
auth: "plugin",
|
|
64
|
+
match: "prefix",
|
|
65
|
+
handler: createDiffsLanguagePackHttpHandler()
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function createDiffsLanguagePackHttpHandler() {
|
|
69
|
+
return async (req, res) => {
|
|
70
|
+
const parsed = parseRequestUrl(req.url);
|
|
71
|
+
if (!parsed?.pathname.startsWith("/plugins/diffs-language-pack/assets/")) return false;
|
|
72
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
73
|
+
respondText(res, 405, "Method not allowed");
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
const asset = await getServedViewerAsset(parsed.pathname);
|
|
77
|
+
if (!asset) {
|
|
78
|
+
respondText(res, 404, "Asset not found");
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
res.statusCode = 200;
|
|
82
|
+
setSharedHeaders(res, asset.contentType);
|
|
83
|
+
if (req.method === "HEAD") res.end();
|
|
84
|
+
else res.end(asset.body);
|
|
85
|
+
return true;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function parseRequestUrl(rawUrl) {
|
|
89
|
+
if (!rawUrl) return null;
|
|
90
|
+
try {
|
|
91
|
+
return new URL(rawUrl, "http://127.0.0.1");
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function respondText(res, statusCode, body) {
|
|
97
|
+
res.statusCode = statusCode;
|
|
98
|
+
setSharedHeaders(res, "text/plain; charset=utf-8");
|
|
99
|
+
res.end(body);
|
|
100
|
+
}
|
|
101
|
+
function setSharedHeaders(res, contentType) {
|
|
102
|
+
res.setHeader("cache-control", "no-store, max-age=0");
|
|
103
|
+
res.setHeader("content-type", contentType);
|
|
104
|
+
res.setHeader("x-content-type-options", "nosniff");
|
|
105
|
+
res.setHeader("referrer-policy", "no-referrer");
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region extensions/diffs-language-pack/index.ts
|
|
109
|
+
var diffs_language_pack_default = definePluginEntry({
|
|
110
|
+
id: "diffs-language-pack",
|
|
111
|
+
name: "Diff Viewer Language Pack",
|
|
112
|
+
description: "Adds syntax highlighting for languages outside the default diffs viewer set.",
|
|
113
|
+
register: registerDiffsLanguagePackPlugin
|
|
114
|
+
});
|
|
115
|
+
//#endregion
|
|
116
|
+
export { diffs_language_pack_default as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "diffs-language-pack",
|
|
3
|
+
"requiresPlugins": ["diffs"],
|
|
4
|
+
"activation": {
|
|
5
|
+
"onStartup": true
|
|
6
|
+
},
|
|
7
|
+
"name": "Diff Viewer Language Pack",
|
|
8
|
+
"description": "Adds syntax highlighting for languages outside the default diffs viewer set.",
|
|
9
|
+
"configSchema": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"additionalProperties": false,
|
|
12
|
+
"properties": {}
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openclaw/diffs-language-pack",
|
|
3
|
+
"version": "2026.5.28-beta.3",
|
|
4
|
+
"description": "OpenClaw diffs viewer syntax highlighting language pack",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/openclaw/openclaw"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"openclaw": {
|
|
11
|
+
"extensions": [
|
|
12
|
+
"./index.ts"
|
|
13
|
+
],
|
|
14
|
+
"install": {
|
|
15
|
+
"npmSpec": "@openclaw/diffs-language-pack",
|
|
16
|
+
"clawhubSpec": "clawhub:@openclaw/diffs-language-pack",
|
|
17
|
+
"localPath": "extensions/diffs-language-pack",
|
|
18
|
+
"defaultChoice": "npm",
|
|
19
|
+
"minHostVersion": ">=2026.5.27"
|
|
20
|
+
},
|
|
21
|
+
"compat": {
|
|
22
|
+
"pluginApi": ">=2026.5.28-beta.3"
|
|
23
|
+
},
|
|
24
|
+
"assetScripts": {
|
|
25
|
+
"build": "node ../../scripts/build-diffs-viewer-runtime.mjs full"
|
|
26
|
+
},
|
|
27
|
+
"build": {
|
|
28
|
+
"openclawVersion": "2026.5.28-beta.3",
|
|
29
|
+
"staticAssets": [
|
|
30
|
+
{
|
|
31
|
+
"source": "./assets/viewer-runtime.js",
|
|
32
|
+
"output": "assets/viewer-runtime.js"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"release": {
|
|
37
|
+
"publishToClawHub": true,
|
|
38
|
+
"publishToNpm": true
|
|
39
|
+
},
|
|
40
|
+
"runtimeExtensions": [
|
|
41
|
+
"./dist/index.js"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist/**",
|
|
46
|
+
"openclaw.plugin.json",
|
|
47
|
+
"npm-shrinkwrap.json"
|
|
48
|
+
],
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"openclaw": ">=2026.5.28-beta.3"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"openclaw": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"bundledDependencies": []
|
|
58
|
+
}
|