This commit is contained in:
Vanessa 2023-12-04 16:23:38 +08:00
parent 5c5f7da1e6
commit 47d06a6309

View file

@ -8,10 +8,10 @@ import {API} from "./API";
import {getFrontend, isMobile, isWindow} from "../util/functions"; import {getFrontend, isMobile, isWindow} from "../util/functions";
import {Constants} from "../constants"; import {Constants} from "../constants";
const requireFunc = (key: string) => {
const modules = { const modules = {
siyuan: API siyuan: API
}; };
const requireFunc = (key: string) => {
// @ts-ignore // @ts-ignore
return modules[key] return modules[key]
?? window.require?.(key); ?? window.require?.(key);
@ -44,6 +44,7 @@ const loadPluginJS = async (app: App, item: IPluginData) => {
const exportsObj: { [key: string]: any } = {}; const exportsObj: { [key: string]: any } = {};
const moduleObj = {exports: exportsObj}; const moduleObj = {exports: exportsObj};
try { try {
debugger
runCode(item.js, "plugin:" + encodeURIComponent(item.name))(requireFunc, moduleObj, exportsObj); runCode(item.js, "plugin:" + encodeURIComponent(item.name))(requireFunc, moduleObj, exportsObj);
} catch (e) { } catch (e) {
console.error(`plugin ${item.name} run error:`, e); console.error(`plugin ${item.name} run error:`, e);