fix: resolve circular import crash in rnotes converters
Bun evaluates the converters Map after the circular import from obsidian.ts triggers registerConverter(), causing "Cannot access before initialization". Lazy-load converter modules via require() to break the cycle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4822895ca4
commit
aceeedb366
|
|
@ -73,16 +73,26 @@ export function registerConverter(converter: NoteConverter): void {
|
|||
}
|
||||
|
||||
export function getConverter(id: string): NoteConverter | undefined {
|
||||
ensureConvertersLoaded();
|
||||
return converters.get(id);
|
||||
}
|
||||
|
||||
export function getAllConverters(): NoteConverter[] {
|
||||
ensureConvertersLoaded();
|
||||
return Array.from(converters.values());
|
||||
}
|
||||
|
||||
// ── Import converters on module load ──
|
||||
// These register themselves when imported
|
||||
import './obsidian';
|
||||
import './logseq';
|
||||
import './notion';
|
||||
import './google-docs';
|
||||
// ── Lazy-load converters to avoid circular init ──
|
||||
// Each converter imports registerConverter from this file; importing them
|
||||
// synchronously at the module level causes a "Cannot access before
|
||||
// initialization" error in Bun because the converters Map hasn't been
|
||||
// assigned yet when the circular import triggers registerConverter().
|
||||
let _loaded = false;
|
||||
export function ensureConvertersLoaded(): void {
|
||||
if (_loaded) return;
|
||||
_loaded = true;
|
||||
require('./obsidian');
|
||||
require('./logseq');
|
||||
require('./notion');
|
||||
require('./google-docs');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue