MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / requireOrInstall

Function requireOrInstall

quote/quote.ts:103–113  ·  view source on GitHub ↗
(pkg: string)

Source from the content-addressed store, hash-verified

101 fs.mkdirSync(path.dirname(filePath), { recursive: true });
102 const data = await fetchToBuffer(url);
103 if (fs.existsSync(filePath)) {
104 const old = fs.readFileSync(filePath);
105 if (old.length === data.length && old.equals(data)) return;
106 }
107 fs.writeFileSync(filePath, data);
108}
109
110function requireOrInstall(pkg: string): any {
111 try {
112 return require(pkg);
113 } catch (err: any) {
114 const code = err?.code;
115 if (code !== "MODULE_NOT_FOUND" && code !== "ERR_MODULE_NOT_FOUND") throw err;
116 console.warn("quote loader installing npm package", { pkg });

Callers 3

getSharpFunction · 0.85
getCanvasFunction · 0.85
getQuoteGenFunction · 0.85

Calls 1

warnMethod · 0.80

Tested by

no test coverage detected