mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
improve compatibility with common js, #3436
This commit is contained in:
parent
5af506e268
commit
6def541e78
1
package-lock.json
generated
1
package-lock.json
generated
@ -5,6 +5,7 @@
|
|||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
|
"name": "trilium",
|
||||||
"version": "0.57.5",
|
"version": "0.57.5",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
|
@ -99,7 +99,7 @@ function getScriptBundleForFrontend(note) {
|
|||||||
return;
|
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;
|
bundle.noteId = bundle.note.noteId;
|
||||||
delete bundle.note;
|
delete bundle.note;
|
||||||
|
|
||||||
@ -165,13 +165,12 @@ function getScriptBundle(note, root = true, scriptEnv = null, includedNoteIds =
|
|||||||
|
|
||||||
if (note.isJavaScript()) {
|
if (note.isJavaScript()) {
|
||||||
bundle.script += `
|
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 ? ', ' : '') +
|
${root ? 'return ' : ''}${isFrontend ? 'await' : ''} ((${isFrontend ? 'async' : ''} function(exports, module, require, api` + (modules.length > 0 ? ', ' : '') +
|
||||||
modules.map(child => sanitizeVariableName(child.title)).join(', ') + `) {
|
modules.map(child => sanitizeVariableName(child.title)).join(', ') + `) {
|
||||||
try {
|
try {
|
||||||
${backendOverrideContent || note.getContent()};
|
${backendOverrideContent || note.getContent()};
|
||||||
} catch (e) { throw new Error("Load of script note \\"${note.title}\\" (${note.noteId}) failed with: " + e.message); }
|
} 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];
|
for (const exportKey in exports) module.exports[exportKey] = exports[exportKey];
|
||||||
return module.exports;
|
return module.exports;
|
||||||
}).call({}, {}, apiContext.modules['${note.noteId}'], apiContext.require(${JSON.stringify(moduleNoteIds)}), apiContext.apis['${note.noteId}']` + (modules.length > 0 ? ', ' : '') +
|
}).call({}, {}, apiContext.modules['${note.noteId}'], apiContext.require(${JSON.stringify(moduleNoteIds)}), apiContext.apis['${note.noteId}']` + (modules.length > 0 ? ', ' : '') +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user