I have been trying to use __dirname for fs.readFile. But __dirname doesn't seem to give me the correct file path.
To be more specific, I am trying to develop a plugin for the Obsidian app and the path to the plugin folder should look something like
something/.obsidian/plugins/
But when I print the path with
console.log(__dirname)
It gives me
Applications/obsidian.app/Contents/Resources/electron.asar/renderer
I am not sure if this would be a problem specific to the Obsidian app, but shouldn't __dirname return the path to my current file in the repository?
My code is in TypeScript by the way, let me know if any further clarification is needed.
but shouldn't __dirname return the path to my current file in the repository?
Yes it most certainly should.
I am not sure if this would be a problem specific to the Obsidian app
Most likely, yes. Maybe they aren't require
ing or import
ing your plugin files directly. They are probably doing some kind of "read the file then eval it" type thing or else a "copy the plugin to the local folder before running it" type of thing.
It seems this is indeed a problem. Here is a related forum post