chore(dev): make the plugin bundle debuggable in Obsidian - #57
Open
luoxuanzao wants to merge 1 commit into
Open
Conversation
Obsidian appends its own sourceURL after plugin code and strips sourceMappingURL directives, so breakpoints in an attached Chromium debugger never resolved to Qoderian sources. The SDK timer patches also ran after esbuild emitted its map, shifting every position that followed. Wrap the dev bundle so both directives land in the order Chromium expects, bypass the directive stripping during reload, and keep patched regions line- and column-neutral.
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.
Summary
esbuild.config.mjs: new dev-onlyexposeDevSourceMapToDebuggerplugin rewritesmain.jsinto anevalwrapper sosourceMappingURLlands aftersourceURL— the order Chromium requires to associate a map. The two directives are assembled from split string literals at runtime so Obsidian's source scanner cannot strip them while reading the wrapper.scripts/dev-reloader/main.js: during a reload, temporarily setslocalStorage['debug-plugin']and guardsvault.adapter.readto append a/* nosourcemap */marker to the target plugin'smain.js, bypassing Obsidian's directive stripping. Previous values are restored in afinally; the restore is idempotent, so the failure path calling it twice is a no-op.scripts/renderer-safe-unref.js: the SDK timer patches run after esbuild emits its source map, so any change in length shifted every mapping that followed. NewpreserveFollowingGeneratedPositionskeeps the matched region's newline count and ending column intact..vscode/launch.json(new) +.gitignore: share the "Attach to Obsidian" config (127.0.0.1:9222,app://obsidian.md/*) by allowing that one file through the ignore rule.sourceURLafter plugin code and stripssourceMappingURLdirectives, so the inline map esbuild emitted was invisible to the debugger. Combined with the position-shifting SDK patches, dev-time debugging of the renderer was effectively unusable.Production output is untouched — the wrapper plugin is registered only when
prodis false.Verification
npm run typechecknpm run lintnpm run testnpm run buildnpm run release:checknpm run audit:prod— fails on pre-existing transitive advisories (fast-urihigh,qsmoderate). This branch touches nopackage.json/lockfile, so the failure is inherited frommain, not introduced here.Safety
launch.jsonreferences only127.0.0.1:9222and${workspaceFolder}.CHANGELOG.md— dev-only tooling with no user-visible behavior change, soCHANGELOG.mdwas not updated. Say the word if you'd rather have an entry.