mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	commonjs modules should have "this" available
This commit is contained in:
		
							parent
							
								
									25f8df1e03
								
							
						
					
					
						commit
						763f885cc7
					
				| @ -127,15 +127,15 @@ async function getScriptBundle(note, root = true, scriptEnv = null, includedNote | |||||||
|     if (note.isJavaScript()) { |     if (note.isJavaScript()) { | ||||||
|         bundle.script += ` |         bundle.script += ` | ||||||
| apiContext.modules['${note.noteId}'] = {}; | apiContext.modules['${note.noteId}'] = {}; | ||||||
| ${root ? 'return ' : ''}await (async function(exports, module, require, api` + (modules.length > 0 ? ', ' : '') +
 | ${root ? 'return ' : ''}await ((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 { | ||||||
| ${note.content}; | ${note.content}; | ||||||
| } 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 = {}; | 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]; | ||||||
| })({}, 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 ? ', ' : '') +
 | ||||||
|             modules.map(mod => `apiContext.modules['${mod.noteId}'].exports`).join(', ') + `);
 |             modules.map(mod => `apiContext.modules['${mod.noteId}'].exports`).join(', ') + `));
 | ||||||
| `;
 | `;
 | ||||||
|     } |     } | ||||||
|     else if (note.isHtml()) { |     else if (note.isHtml()) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 azivner
						azivner