Files
SenMeshNet/electron/plugins/moduleResources.cjs
zhaolei 2f9f8da48e
Some checks failed
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
Initial commit: NetMesh smart ops platform with 3D topology, inspection reports, RCA and AI ops assistant
2026-10-15 13:53:04 +08:00

60 lines
2.3 KiB
JavaScript

"use strict";
const path = require("node:path");
const { pathToFileURL } = require("node:url");
const MODULE_SPECIFIER_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
const MODULE_ENTRY_PATTERN = /^[A-Za-z0-9_-][A-Za-z0-9._-]*(?:\/[A-Za-z0-9_-][A-Za-z0-9._-]*)*$/;
function normalizePluginModuleResources(resources) {
if (!Array.isArray(resources) || resources.length < 1 || resources.length > 32) {
throw new TypeError("Plugin host module resources must contain between 1 and 32 entries");
}
const specifiers = new Set();
return Object.freeze(resources.map((resource, index) => {
if (!resource || typeof resource !== "object" || Array.isArray(resource)) {
throw new TypeError("Plugin host module resource must be an object");
}
const { specifier, directory, entry = "index.js" } = resource;
if (typeof specifier !== "string" || !MODULE_SPECIFIER_PATTERN.test(specifier)) {
throw new TypeError(`Invalid plugin host module specifier: ${String(specifier)}`);
}
if (specifiers.has(specifier)) throw new Error(`Duplicate plugin host module specifier: ${specifier}`);
specifiers.add(specifier);
if (typeof directory !== "string" || !path.isAbsolute(directory)) {
throw new TypeError(`Plugin host module directory must be absolute: ${specifier}`);
}
if (typeof entry !== "string" || !MODULE_ENTRY_PATTERN.test(entry) || entry.includes("\\")) {
throw new TypeError(`Invalid plugin host module entry: ${specifier}`);
}
return Object.freeze({ directory, entry, route: `m${index}`, specifier });
}));
}
function createDefaultPluginModuleResources(appRoot, additional = []) {
return normalizePluginModuleResources([
{
specifier: "@netcatty/plugin-sdk",
directory: path.join(appRoot, "node_modules", "@netcatty", "plugin-sdk", "dist"),
},
{
specifier: "@netcatty/plugin-contract",
directory: path.join(appRoot, "node_modules", "@netcatty", "plugin-contract", "dist"),
},
...additional,
]);
}
function createUtilityModuleMappings(resources) {
return Object.freeze(Object.fromEntries(resources.map((resource) => [
resource.specifier,
pathToFileURL(path.join(resource.directory, ...resource.entry.split("/"))).href,
])));
}
module.exports = {
createDefaultPluginModuleResources,
createUtilityModuleMappings,
normalizePluginModuleResources,
};