Skip to content

Build your personal knowledge base with Trilium Notes

improve compatibility with common js, #3436

zadam6def541e78c3
diff --git a/package-lock.json b/package-lock.json
index 701daf498b..b6e2c904e1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5,6 +5,7 @@
"requires": true,
"packages": {
"": {
+ "name": "trilium",
"version": "0.57.5",
"hasInstallScript": true,
"license": "AGPL-3.0-only",
diff --git a/src/services/script.js b/src/services/script.js
index 74b404b0bc..a9b4ea241a 100644
--- a/src/services/script.js
+++ b/src/services/script.js
@@ -99,7 +99,7 @@ function getScriptBundleForFrontend(note) {
return;
}
- // for frontend we return just noteIds because frontend needs to use its own entity instances
+ // for frontend, we return just noteIds because frontend needs to use its own entity instances
bundle.noteId = bundle.note.noteId;
delete bundle.note;
@@ -165,13 +165,12 @@ function getScriptBundle(note, root = true, scriptEnv = null, includedNoteIds =
if (note.isJavaScript()) {
bundle.script += `
-apiContext.modules['${note.noteId}'] = {};
+apiContext.modules['${note.noteId}'] = { exports: {} };
${root ? 'return ' : ''}${isFrontend ? 'await' : ''} ((${isFrontend ? 'async' : ''} function(exports, module, require, api` + (modules.length > 0 ? ', ' : '') +
modules.map(child => sanitizeVariableName(child.title)).join(', ') + `) {
try {
${backendOverrideContent || note.getContent()};
} catch (e) { throw new Error("Load of script note \\"${note.title}\\" (${note.noteId}) failed with: " + e.message); }
-if (!module.exports) module.exports = {};
for (const exportKey in exports) module.exports[exportKey] = exports[exportKey];
return module.exports;
}).call({}, {}, apiContext.modules['${note.noteId}'], apiContext.require(${JSON.stringify(moduleNoteIds)}), apiContext.apis['${note.noteId}']` + (modules.length > 0 ? ', ' : '') +