docs: document sharing helper functions/constants across user scripts (#622)#1362
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughTwo ChangesUserScripts Documentation – Shared Code Guidance
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying quickadd with
|
| Latest commit: |
71d6531
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7b933925.quickadd.pages.dev |
| Branch Preview URL: | https://chhoumann-622-userscript-hel.quickadd.pages.dev |
Summary
Documents how to share helper functions and constants across QuickAdd user scripts — the most-requested gap in #622. This is docs-only: it describes an existing, runtime-verified capability (a user script can
require()a shared.jsmodule by absolute path) that was never written down.Adds a new
## Sharing Code Between Scriptssection toUserScripts.mdin both the current (Next) docs and the servedversion-2.13.1snapshot, plus a cross-link from the### Variablessection so users on theparams.variablesworkaround path discover it.Why
The pattern works today because every user script is executed with a
requireargument (src/utils/userScript.ts:36), but it was undocumented, so the only answer people found was passing data throughparams.variablesbetween chained scripts — which the reporter rightly called convoluted, and which can't share functions at all.What the section covers
require(absolute-path)pattern, building the path at runtime fromapp.vault.adapter.getBasePath().instanceof obsidian.FileSystemAdapterguard (mobile has norequire).requireruns arbitrary code immediately).window.require(the script-scopedrequireis a thin wrapper with no.cache/.resolve).Verification
quickadd:run→ user scriptrequire'd a shared module and returnedhello from shared module :: 1,234,567 USD(constant + function + constant). Cache caveat and thewindow.requirecache-bust both confirmed live.cd docs && pnpm buildpasses (onBrokenLinks: 'throw'); both new anchors resolve.Scope
Out of scope by design: a relative-
requiremodule resolver (needs synthetic__dirname, still desktop-only, thin demand) and any runtime code change touserScript.ts.Closes #622
Summary by CodeRabbit
params.variablesfor data transfer between steps