fix: compatibility with Obsidian 1.7+; migrate build to esbuild - #81
Open
edejong-source wants to merge 2 commits into
Open
fix: compatibility with Obsidian 1.7+; migrate build to esbuild#81edejong-source wants to merge 2 commits into
edejong-source wants to merge 2 commits into
Conversation
The Rollup 2.58 + @rollup/plugin-typescript 8.3 toolchain no longer runs cleanly on current Node — the TypeScript plugin's load hook is not transforming the entry point, producing an "Unexpected token" parse error on the first \`import type\` statement. esbuild handles TypeScript + Svelte natively, reads tsconfig path mappings, and is the build used by the current obsidian-sample-plugin template. The new \`esbuild.config.mjs\` mirrors the previous behaviour (inline source maps for dev, none for prod; \`obsidian\` + node builtins external; Svelte CSS inlined into the JS bundle). \`package.json\` scripts point at the new config; the rollup dependencies and \`rollup.config.js\` remain in tree for now and can be removed in a follow-up.
Two crashes prevented the plugin from loading on current Obsidian: 1. \`obsidian-community-lib\`'s \`openView\` calls \`getRightLeaf(false)\` and \`getLeftLeaf(false)\` without a null check. Obsidian 1.7+ returns null from these when the sidebar panel doesn't exist, causing an unhandled TypeError on the subsequent \`setViewState\`. This commit ships a local \`openView\` shadow that falls back to \`getLeaf(true)\` (a new center tab) when the preferred side is unavailable. 2. The \`resolvedLinksComplete\` indexing-wait used strict equality (\`=== noFiles\`) against the total markdown count. But Obsidian's \`metadataCache.resolvedLinks\` omits notes that have no outgoing links, so the equality never satisfies on vaults that contain any link-less note and the plugin hung in its onload wait loop indefinitely. Changed to \`>= noFiles\`. Closes SkepticMystic#78. Diagnosis originally posted in the issue thread by @northbridgetechnology.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #78. The plugin currently doesn't load on Obsidian 1.7+ — two compatibility issues, plus a build that no longer runs on current Node.
Source fixes
1. Null-safe sidebar leaf opening.
obsidian-community-lib'sopenViewcallsapp.workspace.getRightLeaf(false)/getLeftLeaf(false)and immediately awaitssetViewStateon the result. Obsidian 1.7+ returnsnullfrom those when the sidebar panel doesn't exist, producing an unhandledTypeErroron load.This PR ships a local
openViewshadow insrc/main.tsthat falls back toapp.workspace.getLeaf(true)(a new center tab) when the side leaf is unavailable. Removes the dependency on the upstream helper for view opening only —waitis still imported fromobsidian-community-lib.2.
resolvedLinksindexing-wait infinite loop.resolvedLinksCompletecomparedObject.keys(resolvedLinks).length === noFilesagainst the total markdown count. Obsidian'smetadataCache.resolvedLinksomits notes that have no outgoing links, so equality never satisfies on any vault containing link-less notes — the onloadawait wait(1000)loop spins forever. Changed===to>=.Diagnosis for both originally posted in the issue thread by @northbridgetechnology.
Build migration
The Rollup 2.58 +
@rollup/plugin-typescript8.3 toolchain no longer transforms the entry TypeScript on current Node — the plugin'sloadhook silently returnsnull, and Rollup falls back to its native JS parser which dies on the firstimport typestatement.Rather than chase that, this PR migrates to esbuild + esbuild-svelte, which is what the current
obsidian-sample-plugintemplate uses. The newesbuild.config.mjsmirrors the previous behaviour (inline source maps for dev, none for prod;obsidian+ node builtins external; Svelte CSS inlined into the JS bundle).package.jsonscripts now invoke it. Build is ~10× faster.The old
rollup.config.jsand rollup deps are left in tree — happy to remove them in a follow-up if you'd prefer that as a separate change.Testing
npm run buildproduces a 769KBmain.jswith the patches inlined