Skip to content

Commit 4cf9750

Browse files
committed
mock-runtime: improve logging
1 parent 71eebac commit 4cf9750

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

mock-runtime.mjs

+12-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ let setImmediatePromise = () => new Promise(resolve => {
1414
setImmediate(resolve);
1515
});
1616

17-
const rel_path_cache = {};
18-
const import_cache = {};
17+
export const import_cache = new Map();
1918

2019
let nix_path_parsed = (() => {
2120
let nixpath = process.env.NIX_PATH;
@@ -55,16 +54,18 @@ async function importTail(real_path) {
5554
}
5655
}
5756
try {
58-
console.log(' ' + fmtTdif(process.hrtime(tstart)) + '\tloaded');
57+
console.log(real_path + ' ' + fmtTdif(process.hrtime(tstart)) + '\tloaded');
5958
let trld = translate_inline_srcmap(fdat, real_path);
60-
console.log(' ' + fmtTdif(process.hrtime(tstart)) + '\ttranslated');
59+
console.log(real_path + ' ' + fmtTdif(process.hrtime(tstart)) + '\ttranslated');
6160
let stru;
6261
stru = (new Function('nixRt', 'nixBlti', trld));
6362
// call the yield here to allow any hanging events to proceed
64-
await setImmediatePromise();
63+
//await setImmediatePromise();
6564
stru = stru(buildRT(real_path), nixBlti);
66-
console.log(' ' + fmtTdif(process.hrtime(tstart)) + '\tevaluated');
67-
import_cache[real_path] = stru;
65+
console.log(real_path + ' ' + fmtTdif(process.hrtime(tstart)) + '\tevaluated');
66+
import_cache.set(real_path, stru);
67+
console.debug(real_path + ' -res-> ');
68+
console.debug(stru);
6869
return stru;
6970
} catch (e) {
7071
console.log(real_path, e);
@@ -77,7 +78,10 @@ export function import_(xpath) {
7778
return xpath.then(import_);
7879
if (xpath instanceof Error)
7980
throw xpath;
80-
return import_cache[xpath] = importTail(xpath);
81+
if (!import_cache.has(xpath)) {
82+
import_cache.set(xpath, importTail(xpath));
83+
}
84+
return import_cache.get(xpath);
8185
}
8286

8387
function buildRT(opath) {

0 commit comments

Comments
 (0)