crossnote
crossnote copied to clipboard
Doesn't exit correctly
const mume = require("@shd101wyy/mume");
async function main() {
await mume.init();
const engine = new mume.MarkdownEngine({
filePath: "./xxx.md",
config: {
previewTheme: "github-light.css",
codeBlockTheme: 'github.css', //"auto.css",
breakOnSingleNewLine: true,
printBackground: true,
enableScriptExecution: false, // <= for running code chunks
mathRenderingOption: ''
},
});
// html export
await engine.htmlExport({ offline: true});
}
main();
It won't exit forever, I have tried to debug it and break it when the process need exit. The callstack is here:
async_hooks.js in nodejs
function emitHookFactory(symbol, name) {
// Called from native. The asyncId stack handling is taken care of there
// before this is called.
// eslint-disable-next-line func-style
const fn = function(asyncId) {
active_hooks.call_depth += 1;
// Use a single try/catch for all hook to avoid setting up one per
// iteration.
try {
for (var i = 0; i < active_hooks.array.length; i++) { // <------- BREAK HERE
if (typeof active_hooks.array[i][symbol] === 'function') {
active_hooks.array[i][symbol](asyncId);
}
}
} catch (e) {
fatalError(e);
} finally {
active_hooks.call_depth -= 1;
}
// Hooks can only be restored if there have been no recursive hook calls.
// Also the active hooks do not need to be restored if enable()/disable()
// weren't called during hook execution, in which case
// active_hooks.tmp_array will be null.
if (active_hooks.call_depth === 0 && active_hooks.tmp_array !== null) {
restoreActiveHooks();
}
};
// Set the name property of the anonymous function as it looks good in the
// stack trace.
Object.defineProperty(fn, 'name', {
value: name
});
return fn;
}
It seems to do something with an asyncId which doesn't exist in AsyncHook's promiseIds array. I haven't used nodejs for long time so I can't tell where goes wrong.
This one seems to work for me in one experiment:
async function renderFile(relativePathToFile) {
const filePath = resolve(__dirname, relativePathToFile);
console.log(`==== FILE ${relativePathToFile}`);
console.log("initializing...");
await mume.init();
console.log("starting engine...");
const engine = new mume.MarkdownEngine({
filePath,
config: {
previewTheme: "github-light.css",
enableScriptExecution: true,
// revealjsTheme: "white.css"
codeBlockTheme: "default.css",
printBackground: true,
},
});
console.log("exporting to html...");
await engine.htmlExport({ offline: false, runAllCodeChunks: true });
console.log("done.");
}
Does this code work for you?
@kachkaev Unfortunately not, the output is
==== FILE xxx.md initializing... starting engine... exporting to html... done.
And it doesn't exit.
I'm using window7 with node 9.11.1 and run it in vscode's terminal(use cmd).
It may be caused by some exception in a promise that's hard to track. It'd be great if I could share a small git repo that reproduces the behaviour, that is including mume and a markdown file.
@kachkaev I have just used the empty markdown file to do the test, the result is the same. The mume is installed by npm just yesterday. Maybe it is related to node's version?
Not sure. This could be to do with Windows 7 though. Do you have an opportunity to try your code on the other os?
@kachkaev No, I have another windows 10, I will try it later.
Using pkg 4.3.1 to package script to exe file and run it on my windows 10. Same result, the process doesn't exit.
Will this still happen if you use an empty markdown file?
@shd101wyy Yes, used the same code provided by kachkaev with empty markdown file.
Can reproduce. Using Windows 7 32bit here.