Skip to content

Build your personal knowledge base with Trilium Notes

fix(standalone): cyclic dependency breaking prod

Elian Doran2dd1dd1fd002
diff --git a/packages/trilium-core/src/becca/entities/bnote.ts b/packages/trilium-core/src/becca/entities/bnote.ts
index ef59aa37e3..3e9fe6fa35 100644
--- a/packages/trilium-core/src/becca/entities/bnote.ts
+++ b/packages/trilium-core/src/becca/entities/bnote.ts
@@ -20,6 +20,7 @@ import BRevision from "./brevision.js";
import { getLog } from "../../services/log.js";
import { getSql } from "../../services/sql/index.js";
import { formatDownloadTitle, isStringNote, normalize, randomString, replaceAll } from "../../services/utils/index.js";
+import scriptService from "../../services/script.js";
const LABEL = "label";
const RELATION = "relation";
@@ -322,9 +323,6 @@ class BNote extends AbstractBeccaEntity<BNote> {
* @returns the return value of the executed script
*/
executeScript() {
- // Lazy require to avoid circular dependency (script.ts imports BNote as a type).
- // eslint-disable-next-line @typescript-eslint/no-require-imports
- const scriptService = require("../../services/script.js").default;
return scriptService.executeNote(this, { originEntity: this });
}
diff --git a/packages/trilium-core/src/routes/api/script.ts b/packages/trilium-core/src/routes/api/script.ts
index 03326a5a6f..0a46725121 100644
--- a/packages/trilium-core/src/routes/api/script.ts
+++ b/packages/trilium-core/src/routes/api/script.ts
@@ -26,7 +26,7 @@ async function exec(req: Request) {
try {
const body = req.body as ScriptBody;
- const execute = (body: ScriptBody) => scriptService.executeScript(body.script, body.params, body.startNoteId, body.currentNoteId, body.originEntityName, body.originEntityId);
+ const execute = (body: ScriptBody) => scriptService.executeScript(body.script, body.params, body.startNoteId, body.currentNoteId, body.originEntityName, body.originEntityId, becca);
const result = body.transactional ? getSql().transactional(() => execute(body)) : await execute(body);
diff --git a/packages/trilium-core/src/services/script.ts b/packages/trilium-core/src/services/script.ts
index 098e08e1d1..bbe58f8cab 100644
--- a/packages/trilium-core/src/services/script.ts
+++ b/packages/trilium-core/src/services/script.ts
@@ -1,7 +1,7 @@
import { ScriptParams } from "@triliumnext/commons";
import { transform } from "sucrase";
-import becca from "../becca/becca.js";
+import type Becca from "../becca/becca-interface.js";
import type BNote from "../becca/entities/bnote.js";
import type { ApiParams } from "./backend_script_api_interface.js";
import { getLog } from "./log.js";
@@ -76,7 +76,7 @@ ${bundle.script}\r
* This method preserves frontend startNode - that's why we start execution from currentNote and override
* bundle's startNote.
*/
-function executeScript(script: string, params: ScriptParams, startNoteId: string, currentNoteId: string, originEntityName: string, originEntityId: string) {
+function executeScript(script: string, params: ScriptParams, startNoteId: string, currentNoteId: string, originEntityName: string, originEntityId: string, becca: Becca) {
const startNote = becca.getNote(startNoteId);
const currentNote = becca.getNote(currentNoteId);
const originEntity = becca.getEntity(originEntityName, originEntityId);