obsidian-plugin-dev-kit 0.0.0-stage → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +223 -2
  3. package/bin/opdk.js +34 -0
  4. package/dist/build/args.d.ts +10 -0
  5. package/dist/build/args.js +45 -0
  6. package/dist/build/bundle-check.d.ts +17 -0
  7. package/dist/build/bundle-check.js +42 -0
  8. package/dist/build/bundle-file.d.ts +4 -0
  9. package/dist/build/bundle-file.js +29 -0
  10. package/dist/build/commands.d.ts +5 -0
  11. package/dist/build/commands.js +109 -0
  12. package/dist/build/config.d.ts +3 -0
  13. package/dist/build/config.js +103 -0
  14. package/dist/build/css-imports.d.ts +23 -0
  15. package/dist/build/css-imports.js +50 -0
  16. package/dist/build/css-step.d.ts +10 -0
  17. package/dist/build/css-step.js +27 -0
  18. package/dist/build/css.d.ts +24 -0
  19. package/dist/build/css.js +47 -0
  20. package/dist/build/options.d.ts +55 -0
  21. package/dist/build/options.js +70 -0
  22. package/dist/build/release.d.ts +5 -0
  23. package/dist/build/release.js +34 -0
  24. package/dist/build/report.d.ts +7 -0
  25. package/dist/build/report.js +16 -0
  26. package/dist/build/vault.d.ts +26 -0
  27. package/dist/build/vault.js +290 -0
  28. package/dist/build-info.json +1 -0
  29. package/dist/cli/argv.d.ts +14 -0
  30. package/dist/cli/argv.js +18 -0
  31. package/dist/cli/commands.d.ts +3 -0
  32. package/dist/cli/commands.js +7 -0
  33. package/dist/cli/main.d.ts +2 -0
  34. package/dist/cli/main.js +23 -0
  35. package/dist/cli/process-reporter.d.ts +5 -0
  36. package/dist/cli/process-reporter.js +15 -0
  37. package/dist/cli/registry.d.ts +4 -0
  38. package/dist/cli/registry.js +15 -0
  39. package/dist/cli/reporter.d.ts +53 -0
  40. package/dist/cli/reporter.js +100 -0
  41. package/dist/cli/run.d.ts +9 -0
  42. package/dist/cli/run.js +61 -0
  43. package/dist/cli/types.d.ts +27 -0
  44. package/dist/cli/types.js +1 -0
  45. package/dist/cli/version.d.ts +13 -0
  46. package/dist/cli/version.js +61 -0
  47. package/dist/config/define-config.d.ts +3 -0
  48. package/dist/config/define-config.js +4 -0
  49. package/dist/config/load-config.d.ts +6 -0
  50. package/dist/config/load-config.js +70 -0
  51. package/dist/config/manifest.d.ts +3 -0
  52. package/dist/config/manifest.js +72 -0
  53. package/dist/config/types.d.ts +146 -0
  54. package/dist/config/types.js +23 -0
  55. package/dist/demo/args.d.ts +4 -0
  56. package/dist/demo/args.js +13 -0
  57. package/dist/demo/checks.d.ts +56 -0
  58. package/dist/demo/checks.js +124 -0
  59. package/dist/demo/commands.d.ts +3 -0
  60. package/dist/demo/commands.js +65 -0
  61. package/dist/demo/config.d.ts +57 -0
  62. package/dist/demo/config.js +337 -0
  63. package/dist/demo/ffmpeg-run.d.ts +18 -0
  64. package/dist/demo/ffmpeg-run.js +59 -0
  65. package/dist/demo/ffmpeg.d.ts +63 -0
  66. package/dist/demo/ffmpeg.js +111 -0
  67. package/dist/demo/films.d.ts +46 -0
  68. package/dist/demo/films.js +134 -0
  69. package/dist/demo/phone-layout.d.ts +38 -0
  70. package/dist/demo/phone-layout.js +98 -0
  71. package/dist/demo/phone-render.d.ts +28 -0
  72. package/dist/demo/phone-render.js +124 -0
  73. package/dist/demo/published.d.ts +16 -0
  74. package/dist/demo/published.js +72 -0
  75. package/dist/demo/run.d.ts +31 -0
  76. package/dist/demo/run.js +397 -0
  77. package/dist/demo/stills.d.ts +21 -0
  78. package/dist/demo/stills.js +62 -0
  79. package/dist/e2e/artifacts.d.ts +27 -0
  80. package/dist/e2e/artifacts.js +90 -0
  81. package/dist/e2e/cleanup.d.ts +54 -0
  82. package/dist/e2e/cleanup.js +109 -0
  83. package/dist/e2e/config.d.ts +9 -0
  84. package/dist/e2e/config.js +42 -0
  85. package/dist/e2e/create-test.d.ts +37 -0
  86. package/dist/e2e/create-test.js +109 -0
  87. package/dist/e2e/demo/clip.d.ts +21 -0
  88. package/dist/e2e/demo/clip.js +44 -0
  89. package/dist/e2e/demo/create-demo.d.ts +42 -0
  90. package/dist/e2e/demo/create-demo.js +439 -0
  91. package/dist/e2e/demo/manifest.d.ts +76 -0
  92. package/dist/e2e/demo/manifest.js +168 -0
  93. package/dist/e2e/demo/names.d.ts +18 -0
  94. package/dist/e2e/demo/names.js +44 -0
  95. package/dist/e2e/demo/options.d.ts +22 -0
  96. package/dist/e2e/demo/options.js +59 -0
  97. package/dist/e2e/demo/ownership.d.ts +27 -0
  98. package/dist/e2e/demo/ownership.js +65 -0
  99. package/dist/e2e/demo/page-scripts.d.ts +82 -0
  100. package/dist/e2e/demo/page-scripts.js +250 -0
  101. package/dist/e2e/demo/png.d.ts +8 -0
  102. package/dist/e2e/demo/png.js +23 -0
  103. package/dist/e2e/demo/presets.d.ts +43 -0
  104. package/dist/e2e/demo/presets.js +20 -0
  105. package/dist/e2e/demo/privacy.d.ts +18 -0
  106. package/dist/e2e/demo/privacy.js +30 -0
  107. package/dist/e2e/demo/still-options.d.ts +22 -0
  108. package/dist/e2e/demo/still-options.js +68 -0
  109. package/dist/e2e/demo/types.d.ts +184 -0
  110. package/dist/e2e/demo/types.js +1 -0
  111. package/dist/e2e/electron-binary.d.ts +15 -0
  112. package/dist/e2e/electron-binary.js +30 -0
  113. package/dist/e2e/fixtures.d.ts +62 -0
  114. package/dist/e2e/fixtures.js +68 -0
  115. package/dist/e2e/gate.d.ts +4 -0
  116. package/dist/e2e/gate.js +8 -0
  117. package/dist/e2e/global-setup.d.ts +11 -0
  118. package/dist/e2e/global-setup.js +17 -0
  119. package/dist/e2e/helpers/commands.d.ts +14 -0
  120. package/dist/e2e/helpers/commands.js +56 -0
  121. package/dist/e2e/helpers/create-helpers.d.ts +24 -0
  122. package/dist/e2e/helpers/create-helpers.js +582 -0
  123. package/dist/e2e/helpers/device-metrics.d.ts +21 -0
  124. package/dist/e2e/helpers/device-metrics.js +25 -0
  125. package/dist/e2e/helpers/ime.d.ts +13 -0
  126. package/dist/e2e/helpers/ime.js +19 -0
  127. package/dist/e2e/helpers/layout-page-scripts.d.ts +103 -0
  128. package/dist/e2e/helpers/layout-page-scripts.js +224 -0
  129. package/dist/e2e/helpers/layout.d.ts +83 -0
  130. package/dist/e2e/helpers/layout.js +148 -0
  131. package/dist/e2e/helpers/mobile.d.ts +31 -0
  132. package/dist/e2e/helpers/mobile.js +26 -0
  133. package/dist/e2e/helpers/page-scripts.d.ts +194 -0
  134. package/dist/e2e/helpers/page-scripts.js +467 -0
  135. package/dist/e2e/helpers/settings.d.ts +8 -0
  136. package/dist/e2e/helpers/settings.js +16 -0
  137. package/dist/e2e/helpers/settle.d.ts +28 -0
  138. package/dist/e2e/helpers/settle.js +33 -0
  139. package/dist/e2e/helpers/types.d.ts +193 -0
  140. package/dist/e2e/helpers/types.js +1 -0
  141. package/dist/e2e/helpers/view-mode.d.ts +23 -0
  142. package/dist/e2e/helpers/view-mode.js +35 -0
  143. package/dist/e2e/index.d.ts +14 -0
  144. package/dist/e2e/index.js +4 -0
  145. package/dist/e2e/internals.d.ts +155 -0
  146. package/dist/e2e/internals.js +8 -0
  147. package/dist/e2e/obsidian-path.d.ts +17 -0
  148. package/dist/e2e/obsidian-path.js +31 -0
  149. package/dist/e2e/options.d.ts +123 -0
  150. package/dist/e2e/options.js +244 -0
  151. package/dist/e2e/page-scripts.d.ts +45 -0
  152. package/dist/e2e/page-scripts.js +53 -0
  153. package/dist/e2e/peers.d.ts +9 -0
  154. package/dist/e2e/peers.js +19 -0
  155. package/dist/e2e/plugins.d.ts +32 -0
  156. package/dist/e2e/plugins.js +119 -0
  157. package/dist/e2e/process-tree.d.ts +33 -0
  158. package/dist/e2e/process-tree.js +133 -0
  159. package/dist/e2e/readiness.d.ts +23 -0
  160. package/dist/e2e/readiness.js +63 -0
  161. package/dist/e2e/seed.d.ts +34 -0
  162. package/dist/e2e/seed.js +122 -0
  163. package/dist/e2e/session.d.ts +71 -0
  164. package/dist/e2e/session.js +266 -0
  165. package/dist/e2e/vault.d.ts +52 -0
  166. package/dist/e2e/vault.js +146 -0
  167. package/dist/e2e/version.d.ts +25 -0
  168. package/dist/e2e/version.js +40 -0
  169. package/dist/eslint/index.d.ts +2 -0
  170. package/dist/eslint/index.js +1 -0
  171. package/dist/eslint/obsidian-plugin.d.ts +49 -0
  172. package/dist/eslint/obsidian-plugin.js +115 -0
  173. package/dist/index.d.ts +3 -0
  174. package/dist/index.js +1 -0
  175. package/dist/kit/args.d.ts +7 -0
  176. package/dist/kit/args.js +21 -0
  177. package/dist/kit/commands.d.ts +3 -0
  178. package/dist/kit/commands.js +52 -0
  179. package/dist/kit/files.d.ts +3 -0
  180. package/dist/kit/files.js +24 -0
  181. package/dist/kit/pins.d.ts +89 -0
  182. package/dist/kit/pins.js +178 -0
  183. package/dist/kit/remote.d.ts +13 -0
  184. package/dist/kit/remote.js +33 -0
  185. package/dist/kit/runners.d.ts +11 -0
  186. package/dist/kit/runners.js +53 -0
  187. package/dist/kit/terminal-text.d.ts +6 -0
  188. package/dist/kit/terminal-text.js +20 -0
  189. package/dist/kit/upgrade.d.ts +26 -0
  190. package/dist/kit/upgrade.js +162 -0
  191. package/dist/peers/resolve.d.ts +8 -0
  192. package/dist/peers/resolve.js +28 -0
  193. package/dist/peers/versions.d.ts +30 -0
  194. package/dist/peers/versions.js +32 -0
  195. package/dist/release/api-check.d.ts +27 -0
  196. package/dist/release/api-check.js +119 -0
  197. package/dist/release/args.d.ts +40 -0
  198. package/dist/release/args.js +120 -0
  199. package/dist/release/assets.d.ts +21 -0
  200. package/dist/release/assets.js +35 -0
  201. package/dist/release/build-check.d.ts +43 -0
  202. package/dist/release/build-check.js +184 -0
  203. package/dist/release/build-script.d.ts +12 -0
  204. package/dist/release/build-script.js +30 -0
  205. package/dist/release/build-tagged.d.ts +26 -0
  206. package/dist/release/build-tagged.js +52 -0
  207. package/dist/release/bump.d.ts +24 -0
  208. package/dist/release/bump.js +58 -0
  209. package/dist/release/changelog.d.ts +25 -0
  210. package/dist/release/changelog.js +148 -0
  211. package/dist/release/check.d.ts +38 -0
  212. package/dist/release/check.js +150 -0
  213. package/dist/release/commands.d.ts +3 -0
  214. package/dist/release/commands.js +154 -0
  215. package/dist/release/committed-tree.d.ts +63 -0
  216. package/dist/release/committed-tree.js +118 -0
  217. package/dist/release/config.d.ts +3 -0
  218. package/dist/release/config.js +28 -0
  219. package/dist/release/gh-access.d.ts +14 -0
  220. package/dist/release/gh-access.js +45 -0
  221. package/dist/release/gh.d.ts +10 -0
  222. package/dist/release/gh.js +33 -0
  223. package/dist/release/git.d.ts +49 -0
  224. package/dist/release/git.js +111 -0
  225. package/dist/release/interrupt.d.ts +30 -0
  226. package/dist/release/interrupt.js +60 -0
  227. package/dist/release/json.d.ts +33 -0
  228. package/dist/release/json.js +81 -0
  229. package/dist/release/kit-check.d.ts +8 -0
  230. package/dist/release/kit-check.js +51 -0
  231. package/dist/release/manifest-rules.d.ts +23 -0
  232. package/dist/release/manifest-rules.js +255 -0
  233. package/dist/release/preflight.d.ts +10 -0
  234. package/dist/release/preflight.js +65 -0
  235. package/dist/release/problems.d.ts +24 -0
  236. package/dist/release/problems.js +11 -0
  237. package/dist/release/project-files.d.ts +14 -0
  238. package/dist/release/project-files.js +16 -0
  239. package/dist/release/publish-command.d.ts +21 -0
  240. package/dist/release/publish-command.js +83 -0
  241. package/dist/release/publish-git.d.ts +37 -0
  242. package/dist/release/publish-git.js +108 -0
  243. package/dist/release/publish-state.d.ts +29 -0
  244. package/dist/release/publish-state.js +70 -0
  245. package/dist/release/publish-verify.d.ts +41 -0
  246. package/dist/release/publish-verify.js +112 -0
  247. package/dist/release/publish-wait.d.ts +25 -0
  248. package/dist/release/publish-wait.js +56 -0
  249. package/dist/release/publish.d.ts +35 -0
  250. package/dist/release/publish.js +181 -0
  251. package/dist/release/release-assets.d.ts +39 -0
  252. package/dist/release/release-assets.js +68 -0
  253. package/dist/release/release.d.ts +37 -0
  254. package/dist/release/release.js +179 -0
  255. package/dist/release/remote.d.ts +12 -0
  256. package/dist/release/remote.js +15 -0
  257. package/dist/release/reproducible.d.ts +16 -0
  258. package/dist/release/reproducible.js +34 -0
  259. package/dist/release/run-tests.d.ts +5 -0
  260. package/dist/release/run-tests.js +17 -0
  261. package/dist/release/semver.d.ts +8 -0
  262. package/dist/release/semver.js +60 -0
  263. package/dist/release/version-rules.d.ts +28 -0
  264. package/dist/release/version-rules.js +63 -0
  265. package/dist/release/versions-json.d.ts +15 -0
  266. package/dist/release/versions-json.js +88 -0
  267. package/dist/release/workflow-run.d.ts +44 -0
  268. package/dist/release/workflow-run.js +71 -0
  269. package/dist/scanner/code-checks.d.ts +41 -0
  270. package/dist/scanner/code-checks.js +82 -0
  271. package/dist/scanner/commands.d.ts +3 -0
  272. package/dist/scanner/commands.js +43 -0
  273. package/dist/scanner/config.d.ts +7 -0
  274. package/dist/scanner/config.js +25 -0
  275. package/dist/scanner/css-check.d.ts +26 -0
  276. package/dist/scanner/css-check.js +63 -0
  277. package/dist/scanner/eslint-nesting.d.ts +16 -0
  278. package/dist/scanner/eslint-nesting.js +45 -0
  279. package/dist/scanner/findings.d.ts +23 -0
  280. package/dist/scanner/findings.js +21 -0
  281. package/dist/scanner/git-files.d.ts +16 -0
  282. package/dist/scanner/git-files.js +73 -0
  283. package/dist/scanner/lint.d.ts +47 -0
  284. package/dist/scanner/lint.js +163 -0
  285. package/dist/scanner/meta-checks.d.ts +8 -0
  286. package/dist/scanner/meta-checks.js +22 -0
  287. package/dist/scanner/outside-project.d.ts +19 -0
  288. package/dist/scanner/outside-project.js +20 -0
  289. package/dist/scanner/run.d.ts +19 -0
  290. package/dist/scanner/run.js +78 -0
  291. package/dist/scanner/scanner-config.d.ts +114 -0
  292. package/dist/scanner/scanner-config.js +207 -0
  293. package/dist/scanner/typescript-gate.d.ts +30 -0
  294. package/dist/scanner/typescript-gate.js +73 -0
  295. package/dist/vitest/build-config.d.ts +17 -0
  296. package/dist/vitest/build-config.js +106 -0
  297. package/dist/vitest/define-unit-config.d.ts +27 -0
  298. package/dist/vitest/define-unit-config.js +45 -0
  299. package/dist/vitest/dom/elements.d.ts +87 -0
  300. package/dist/vitest/dom/elements.js +291 -0
  301. package/dist/vitest/dom/index.d.ts +1 -0
  302. package/dist/vitest/dom/index.js +1 -0
  303. package/dist/vitest/dom/install.d.ts +8 -0
  304. package/dist/vitest/dom/install.js +261 -0
  305. package/dist/vitest/dom/setup.d.ts +1 -0
  306. package/dist/vitest/dom/setup.js +3 -0
  307. package/dist/vitest/index.d.ts +3 -0
  308. package/dist/vitest/index.js +2 -0
  309. package/dist/vitest/options.d.ts +92 -0
  310. package/dist/vitest/options.js +136 -0
  311. package/dist/vitest/peers.d.ts +10 -0
  312. package/dist/vitest/peers.js +51 -0
  313. package/dist/vitest/workspace-root.d.ts +7 -0
  314. package/dist/vitest/workspace-root.js +39 -0
  315. package/docs/build.md +232 -0
  316. package/docs/ci.md +182 -0
  317. package/docs/demo.md +364 -0
  318. package/docs/e2e.md +563 -0
  319. package/docs/release.md +374 -0
  320. package/docs/scanner.md +204 -0
  321. package/docs/unit.md +291 -0
  322. package/package.json +100 -4
  323. package/plugins/opdk/skills/audit/SKILL.md +81 -0
  324. package/plugins/opdk/skills/build/SKILL.md +79 -0
  325. package/plugins/opdk/skills/demo/SKILL.md +102 -0
  326. package/plugins/opdk/skills/e2e/SKILL.md +132 -0
  327. package/plugins/opdk/skills/release/SKILL.md +84 -0
  328. package/plugins/opdk/skills/scanner/SKILL.md +60 -0
  329. package/plugins/opdk/skills/unit/SKILL.md +90 -0
@@ -0,0 +1,123 @@
1
+ import { type DemoOptions, type ResolvedDemoOptions } from "./demo/options.js";
2
+ import type { SeedVaultSource } from "./demo/privacy.js";
3
+ /** One plugin to install into the test vault. */
4
+ export interface PluginOption {
5
+ /** Plugin folder holding the built `main.js` and `manifest.json` (and `styles.css` when the plugin has one). Relative to the directory `playwright test` runs in. */
6
+ readonly dir: string;
7
+ /**
8
+ * Overrides the top-level `staleBuildCheck` for this plugin. Default: the plugin in the current directory follows
9
+ * the top-level option, every other plugin is not checked. A dependency plugin built in a sibling repository is
10
+ * usually older than that repository's latest source change, and only its owner knows whether it needs a rebuild.
11
+ * Set `true` to check one. `OPDK_E2E_ALLOW_STALE_BUILD=1` still turns every check off.
12
+ */
13
+ readonly staleBuildCheck?: boolean;
14
+ }
15
+ /** Size of the Obsidian window, in points. */
16
+ export interface WindowOption {
17
+ readonly width: number;
18
+ readonly height: number;
19
+ }
20
+ /** Time budgets, in milliseconds. */
21
+ export interface TimeoutOptions {
22
+ /** `_electron.launch`. Default 45000. */
23
+ readonly launch?: number;
24
+ /** From the window opening until the workspace and every plugin are loaded. Default 30000. */
25
+ readonly ready?: number;
26
+ /** How long `app.close()` may take before the process tree is killed. Default 5000. */
27
+ readonly close?: number;
28
+ /**
29
+ * How long stopping the Obsidian trace may take. Default 60000: the stop writes every snapshot and screenshot of
30
+ * the test to a zip, so it grows with the length of the test (a 60 s test with many DOM snapshots needed more
31
+ * than `close`).
32
+ */
33
+ readonly trace?: number;
34
+ /** How long each kind of wait inside the `obsidian` helpers may take. */
35
+ readonly helpers?: HelperTimeouts;
36
+ }
37
+ /**
38
+ * Time budgets of the waits inside the `obsidian` helpers, in milliseconds. Each wait that runs out fails with a
39
+ * message that names the wait and this option. Keep them below the Playwright test timeout (60000 in the preset),
40
+ * or the test is killed before the helper can explain what it waited for.
41
+ */
42
+ export interface HelperTimeouts {
43
+ /** A plugin's settings tab to register (`openSettings(tab)`). Default 15000: one plugin's cold start needed a few seconds. */
44
+ readonly settings?: number;
45
+ /** Every markdown file to have its metadata cached (`waitForMetadataCache()`). Default 45000: one big vault took up to a minute. */
46
+ readonly metadataCache?: number;
47
+ /** CodeMirror to leave a composition and to show the composed text (`editor().compose()`). Default 5000. */
48
+ readonly compose?: number;
49
+ /** The body to get the class of the theme (`setTheme()`). Default 5000. */
50
+ readonly theme?: number;
51
+ /** A dialog, the palette, the editor or a view to appear or go away (`openCommandPalette()`, `openFile()`, `editor().type()`, `closeSettings()` and others). Default 10000. */
52
+ readonly ui?: number;
53
+ }
54
+ /** Options of `createObsidianTest`. */
55
+ export interface ObsidianTestOptions {
56
+ /** Vault copied into a fresh temp folder for every test. Overridden by the env var `OPDK_E2E_VAULT`. Relative to the directory `playwright test` runs in. */
57
+ readonly seedVault: string;
58
+ /** Plugins to install. Default: the plugin in the current directory. */
59
+ readonly plugins?: readonly PluginOption[];
60
+ /** `data.json` content per plugin id, written before Obsidian starts. Replaces a `data.json` the seed vault has for that plugin. */
61
+ readonly data?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
62
+ /** Obsidian window size. Default: whatever Obsidian opens with. */
63
+ readonly window?: WindowOption;
64
+ /** Obsidian's `app.asar`. Default: the macOS install. Overridden by the env var `OBSIDIAN_PATH`. */
65
+ readonly obsidianPath?: string;
66
+ /** Extra Electron command-line arguments, for example `--use-mock-keychain`. */
67
+ readonly electronArgs?: readonly string[];
68
+ /** Fail the test when the running Obsidian is not this `x.y.z`. Overridden by the env var `OBSIDIAN_VERSION`. */
69
+ readonly version?: string;
70
+ readonly timeouts?: TimeoutOptions;
71
+ /**
72
+ * Refuse the plugin in the current directory when its `main.js` is older than its newest source file. Default
73
+ * `true`. Other entries of `plugins` are not checked unless they set `staleBuildCheck: true` themselves; an entry's
74
+ * own value wins over this one. The env var `OPDK_E2E_ALLOW_STALE_BUILD=1` turns every check off for one run.
75
+ */
76
+ readonly staleBuildCheck?: boolean;
77
+ /** Remove `opdk-e2e-*` temp folders older than this many hours when a worker starts. `false` disables it. Default 2. */
78
+ readonly sweepAfterHours?: number | false;
79
+ /** Where the `demo` fixture writes films and stills, the pixel density it shoots at, and the selectors that must never be in a picture. */
80
+ readonly demo?: DemoOptions;
81
+ }
82
+ export declare const DEFAULT_TIMEOUTS: {
83
+ readonly launch: 45000;
84
+ readonly ready: 30000;
85
+ readonly close: 5000;
86
+ readonly trace: 60000;
87
+ };
88
+ export declare const DEFAULT_HELPER_TIMEOUTS: {
89
+ readonly settings: 15000;
90
+ readonly metadataCache: 45000;
91
+ readonly compose: 5000;
92
+ readonly theme: 5000;
93
+ readonly ui: 10000;
94
+ };
95
+ export declare const DEFAULT_SWEEP_HOURS = 2;
96
+ /** `ObsidianTestOptions` with defaults applied, paths absolute and env overrides folded in. */
97
+ export interface ResolvedOptions {
98
+ readonly cwd: string;
99
+ readonly seedVault: string;
100
+ /** Whether `seedVault` is the option or the `OPDK_E2E_VAULT` override. Capturing from an override needs `allowForeignVault`. */
101
+ readonly seedVaultSource: SeedVaultSource;
102
+ /** Absolute plugin folders, in install order. */
103
+ readonly pluginDirs: readonly string[];
104
+ readonly data: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
105
+ readonly window: WindowOption | undefined;
106
+ /** As given in the option, not resolved: `findObsidianAsar` resolves it and `OBSIDIAN_PATH` wins over it. */
107
+ readonly obsidianPath: string | undefined;
108
+ readonly electronArgs: readonly string[];
109
+ readonly expectedVersion: string | null;
110
+ readonly timeouts: Required<Omit<TimeoutOptions, "helpers">>;
111
+ readonly helperTimeouts: Required<HelperTimeouts>;
112
+ /** Absolute folders of the plugins whose build is checked for staleness; empty when `OPDK_E2E_ALLOW_STALE_BUILD=1`. */
113
+ readonly staleCheckDirs: readonly string[];
114
+ readonly sweepAfterHours: number | false;
115
+ readonly demo: ResolvedDemoOptions;
116
+ }
117
+ export interface ResolveContext {
118
+ /** Directory relative paths are resolved against; `process.cwd()` in the fixture. */
119
+ readonly cwd: string;
120
+ readonly env: Readonly<Record<string, string | undefined>>;
121
+ }
122
+ /** Checks the options and folds in the env overrides. Pure: no disk access, so a typo fails at import time of `fixtures.ts`. Every error names the offending key. */
123
+ export declare function resolveOptions(value: unknown, context: ResolveContext): ResolvedOptions;
@@ -0,0 +1,244 @@
1
+ import path from "node:path";
2
+ import { resolveDemoOptions } from "./demo/options.js";
3
+ import { isExplicitVersion, normalizeVersion } from "./version.js";
4
+ export const DEFAULT_TIMEOUTS = { launch: 45_000, ready: 30_000, close: 5_000, trace: 60_000 };
5
+ export const DEFAULT_HELPER_TIMEOUTS = { settings: 15_000, metadataCache: 45_000, compose: 5_000, theme: 5_000, ui: 10_000 };
6
+ export const DEFAULT_SWEEP_HOURS = 2;
7
+ const OPTION_KEYS = [
8
+ "seedVault",
9
+ "plugins",
10
+ "data",
11
+ "window",
12
+ "obsidianPath",
13
+ "electronArgs",
14
+ "version",
15
+ "timeouts",
16
+ "staleBuildCheck",
17
+ "sweepAfterHours",
18
+ "demo",
19
+ ];
20
+ const PLUGIN_KEYS = ["dir", "staleBuildCheck"];
21
+ const TIMEOUT_KEYS = ["launch", "ready", "close", "trace", "helpers"];
22
+ const HELPER_TIMEOUT_KEYS = ["settings", "metadataCache", "compose", "theme", "ui"];
23
+ const SOURCE = "createObsidianTest";
24
+ /** Checks the options and folds in the env overrides. Pure: no disk access, so a typo fails at import time of `fixtures.ts`. Every error names the offending key. */
25
+ export function resolveOptions(value, context) {
26
+ if (!isRecord(value)) {
27
+ throw new Error(`${SOURCE}: options must be an object with at least { seedVault }.`);
28
+ }
29
+ for (const key of Object.keys(value)) {
30
+ if (!OPTION_KEYS.includes(key)) {
31
+ throw new Error(`${SOURCE}: unknown option "${key}". Known options: ${OPTION_KEYS.join(", ")}.`);
32
+ }
33
+ }
34
+ const { cwd, env } = context;
35
+ const seedFromOption = requireString(value, "seedVault");
36
+ const envVault = env.OPDK_E2E_VAULT;
37
+ const fromEnv = envVault !== undefined && envVault !== "";
38
+ const seedVault = path.resolve(cwd, fromEnv ? envVault : seedFromOption);
39
+ const plugins = resolvePlugins(value, cwd);
40
+ return {
41
+ cwd,
42
+ seedVault,
43
+ seedVaultSource: fromEnv ? "env" : "option",
44
+ pluginDirs: plugins.map((plugin) => plugin.dir),
45
+ data: resolveData(value),
46
+ window: resolveWindow(value),
47
+ obsidianPath: optionalString(value, "obsidianPath"),
48
+ electronArgs: resolveElectronArgs(value),
49
+ expectedVersion: resolveVersion(value, env),
50
+ timeouts: resolveTimeouts(value),
51
+ helperTimeouts: resolveHelperTimeouts(value),
52
+ staleCheckDirs: resolveStaleCheckDirs(value, plugins, cwd, env),
53
+ sweepAfterHours: resolveSweep(value),
54
+ demo: resolveDemoOptions(own(value, "demo"), cwd),
55
+ };
56
+ }
57
+ function resolvePlugins(options, cwd) {
58
+ const value = own(options, "plugins");
59
+ if (value === undefined) {
60
+ return [{ dir: cwd, staleBuildCheck: undefined }];
61
+ }
62
+ if (!Array.isArray(value) || value.length === 0) {
63
+ throw new Error(`${SOURCE}: "plugins" must be a non-empty array of { dir, staleBuildCheck? }.`);
64
+ }
65
+ const plugins = value.map((item, index) => {
66
+ if (!isRecord(item) || typeof item.dir !== "string" || item.dir === "") {
67
+ throw new Error(`${SOURCE}: "plugins[${String(index)}]" must be an object { dir: "<plugin folder>" }.`);
68
+ }
69
+ for (const key of Object.keys(item)) {
70
+ if (!PLUGIN_KEYS.includes(key)) {
71
+ throw new Error(`${SOURCE}: unknown key "plugins[${String(index)}].${key}". Known keys: ${PLUGIN_KEYS.join(", ")}.`);
72
+ }
73
+ }
74
+ const check = own(item, "staleBuildCheck");
75
+ if (check !== undefined && typeof check !== "boolean") {
76
+ throw new Error(`${SOURCE}: "plugins[${String(index)}].staleBuildCheck" must be a boolean.`);
77
+ }
78
+ return { dir: path.resolve(cwd, item.dir), staleBuildCheck: check };
79
+ });
80
+ const duplicate = plugins.find((plugin, index) => plugins.findIndex((other) => other.dir === plugin.dir) !== index);
81
+ if (duplicate !== undefined) {
82
+ throw new Error(`${SOURCE}: "plugins" lists ${duplicate.dir} twice.`);
83
+ }
84
+ return plugins;
85
+ }
86
+ function resolveData(options) {
87
+ const value = own(options, "data");
88
+ if (value === undefined) {
89
+ return {};
90
+ }
91
+ if (!isRecord(value)) {
92
+ throw new Error(`${SOURCE}: "data" must be an object keyed by plugin id, for example { "my-plugin": { ... } }.`);
93
+ }
94
+ const result = {};
95
+ for (const [id, content] of Object.entries(value)) {
96
+ if (!isRecord(content)) {
97
+ throw new Error(`${SOURCE}: "data[${JSON.stringify(id)}]" must be an object (it becomes data.json).`);
98
+ }
99
+ result[id] = content;
100
+ }
101
+ return result;
102
+ }
103
+ function resolveWindow(options) {
104
+ const value = own(options, "window");
105
+ if (value === undefined) {
106
+ return undefined;
107
+ }
108
+ if (!isRecord(value)) {
109
+ throw new Error(`${SOURCE}: "window" must be an object { width, height }.`);
110
+ }
111
+ for (const key of Object.keys(value)) {
112
+ if (key !== "width" && key !== "height") {
113
+ throw new Error(`${SOURCE}: unknown key "window.${key}". Known keys: width, height.`);
114
+ }
115
+ }
116
+ return { width: positiveInteger(value, "width", "window.width"), height: positiveInteger(value, "height", "window.height") };
117
+ }
118
+ function resolveElectronArgs(options) {
119
+ const value = own(options, "electronArgs");
120
+ if (value === undefined) {
121
+ return [];
122
+ }
123
+ const args = [];
124
+ if (!Array.isArray(value)) {
125
+ throw new Error(`${SOURCE}: "electronArgs" must be an array of non-empty strings.`);
126
+ }
127
+ for (const item of value) {
128
+ if (typeof item !== "string" || item === "") {
129
+ throw new Error(`${SOURCE}: "electronArgs" must be an array of non-empty strings.`);
130
+ }
131
+ args.push(item);
132
+ }
133
+ const reserved = args.find((arg) => arg.startsWith("--user-data-dir"));
134
+ if (reserved !== undefined) {
135
+ throw new Error(`${SOURCE}: "electronArgs" must not contain ${reserved}. The kit gives every test its own user-data folder.`);
136
+ }
137
+ return args;
138
+ }
139
+ function resolveVersion(options, env) {
140
+ const fromEnv = normalizeVersion(env.OBSIDIAN_VERSION);
141
+ const fromOption = optionalString(options, "version");
142
+ const chosen = fromEnv ?? normalizeVersion(fromOption);
143
+ if (chosen === null) {
144
+ return null;
145
+ }
146
+ if (!isExplicitVersion(chosen)) {
147
+ const source = fromEnv === null ? 'the "version" option' : "OBSIDIAN_VERSION";
148
+ throw new Error(`${SOURCE}: ${source} is "${chosen}", which is not an explicit x.y.z version. ` +
149
+ `The kit verifies the installed Obsidian; it does not download versions or resolve channels such as "latest".`);
150
+ }
151
+ return chosen;
152
+ }
153
+ function resolveTimeouts(options) {
154
+ const value = own(options, "timeouts");
155
+ if (value === undefined) {
156
+ return { ...DEFAULT_TIMEOUTS };
157
+ }
158
+ if (!isRecord(value)) {
159
+ throw new Error(`${SOURCE}: "timeouts" must be an object { launch, ready, close, trace, helpers }.`);
160
+ }
161
+ for (const key of Object.keys(value)) {
162
+ if (!TIMEOUT_KEYS.includes(key)) {
163
+ throw new Error(`${SOURCE}: unknown key "timeouts.${key}". Known keys: ${TIMEOUT_KEYS.join(", ")}.`);
164
+ }
165
+ }
166
+ return {
167
+ launch: own(value, "launch") === undefined ? DEFAULT_TIMEOUTS.launch : positiveInteger(value, "launch", "timeouts.launch"),
168
+ ready: own(value, "ready") === undefined ? DEFAULT_TIMEOUTS.ready : positiveInteger(value, "ready", "timeouts.ready"),
169
+ close: own(value, "close") === undefined ? DEFAULT_TIMEOUTS.close : positiveInteger(value, "close", "timeouts.close"),
170
+ trace: own(value, "trace") === undefined ? DEFAULT_TIMEOUTS.trace : positiveInteger(value, "trace", "timeouts.trace"),
171
+ };
172
+ }
173
+ function resolveHelperTimeouts(options) {
174
+ const timeouts = own(options, "timeouts");
175
+ const value = isRecord(timeouts) ? own(timeouts, "helpers") : undefined;
176
+ if (value === undefined) {
177
+ return { ...DEFAULT_HELPER_TIMEOUTS };
178
+ }
179
+ if (!isRecord(value)) {
180
+ throw new Error(`${SOURCE}: "timeouts.helpers" must be an object { ${HELPER_TIMEOUT_KEYS.join(", ")} }.`);
181
+ }
182
+ for (const key of Object.keys(value)) {
183
+ if (!HELPER_TIMEOUT_KEYS.includes(key)) {
184
+ throw new Error(`${SOURCE}: unknown key "timeouts.helpers.${key}". Known keys: ${HELPER_TIMEOUT_KEYS.join(", ")}.`);
185
+ }
186
+ }
187
+ const pick = (key) => own(value, key) === undefined ? DEFAULT_HELPER_TIMEOUTS[key] : positiveInteger(value, key, `timeouts.helpers.${key}`);
188
+ return { settings: pick("settings"), metadataCache: pick("metadataCache"), compose: pick("compose"), theme: pick("theme"), ui: pick("ui") };
189
+ }
190
+ /**
191
+ * Which plugins get the staleness check. The plugin in the current directory follows the top-level option (default
192
+ * on); the others are checked only when they ask for it. An entry's own value always wins.
193
+ */
194
+ function resolveStaleCheckDirs(options, plugins, cwd, env) {
195
+ const value = own(options, "staleBuildCheck");
196
+ if (value !== undefined && typeof value !== "boolean") {
197
+ throw new Error(`${SOURCE}: "staleBuildCheck" must be a boolean.`);
198
+ }
199
+ if (env.OPDK_E2E_ALLOW_STALE_BUILD === "1") {
200
+ return [];
201
+ }
202
+ const global = value ?? true;
203
+ return plugins.filter((plugin) => plugin.staleBuildCheck ?? (plugin.dir === cwd && global)).map((plugin) => plugin.dir);
204
+ }
205
+ function resolveSweep(options) {
206
+ const value = own(options, "sweepAfterHours");
207
+ if (value === undefined) {
208
+ return DEFAULT_SWEEP_HOURS;
209
+ }
210
+ if (value === false) {
211
+ return false;
212
+ }
213
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
214
+ throw new Error(`${SOURCE}: "sweepAfterHours" must be a positive number of hours or false.`);
215
+ }
216
+ return value;
217
+ }
218
+ function positiveInteger(record, key, label) {
219
+ const value = own(record, key);
220
+ if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
221
+ throw new Error(`${SOURCE}: "${label}" is required and must be a positive integer.`);
222
+ }
223
+ return value;
224
+ }
225
+ function requireString(record, key) {
226
+ const value = own(record, key);
227
+ if (typeof value !== "string" || value === "") {
228
+ throw new Error(`${SOURCE}: "${key}" is required and must be a non-empty string.`);
229
+ }
230
+ return value;
231
+ }
232
+ function optionalString(record, key) {
233
+ const value = own(record, key);
234
+ if (value !== undefined && typeof value !== "string") {
235
+ throw new Error(`${SOURCE}: "${key}" must be a string.`);
236
+ }
237
+ return value;
238
+ }
239
+ function isRecord(value) {
240
+ return typeof value === "object" && value !== null && !Array.isArray(value);
241
+ }
242
+ function own(record, key) {
243
+ return Object.hasOwn(record, key) ? record[key] : undefined;
244
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Functions Playwright serializes and runs inside Obsidian. Each one must be self-contained: it cannot use
3
+ * imports or other functions of this file, because only its source text crosses into the page. They are exported
4
+ * so tests can run them against a fake `globalThis`.
5
+ */
6
+ /** Init script: marks community plugins as trusted for the vault, so Obsidian never shows the "Do you trust the author" dialog. */
7
+ export declare function applyTrust(key: string): void;
8
+ /** What `isReady` is still waiting for. A plugin id is in at most one of `missing` and `loading`. */
9
+ export interface ReadinessState {
10
+ hasApp: boolean;
11
+ layoutReady: boolean;
12
+ /** Not in `app.plugins.plugins` yet: Obsidian has not started loading it. */
13
+ missing: string[];
14
+ /** `app.plugins.loadingPluginId` is this id: Obsidian is inside its `onload()`. */
15
+ loading: string[];
16
+ }
17
+ /**
18
+ * Reads the readiness state of the window. Obsidian registers `plugins[id]` before it awaits the plugin's `onload()`
19
+ * and sets `app.plugins.loadingPluginId` to the id while that runs (cleared to null once `loadPlugin` resolves), so
20
+ * "present in `plugins`" alone is not "loaded": commands and settings tabs that `onload()` adds after an `await`
21
+ * would not exist yet.
22
+ */
23
+ export declare function readinessState(ids: readonly string[]): ReadinessState;
24
+ /**
25
+ * True once the workspace layout is ready and, for every plugin in `ids`, `plugins[id]` exists and Obsidian is no
26
+ * longer inside that plugin's `onload()`. Written out in full (not as a call to `readinessState`) because only this
27
+ * function's own source text crosses into the page.
28
+ */
29
+ export declare function isReady(ids: readonly string[]): boolean;
30
+ /** The Obsidian version, asked the same way Obsidian's own shell asks. `null` when the renderer cannot answer. */
31
+ export declare function readRunningVersion(): string | null;
32
+ /** The slice of Electron's main-process module `resizeMainWindow` uses. */
33
+ export interface ElectronMain {
34
+ BrowserWindow: {
35
+ getAllWindows(): {
36
+ setSize(width: number, height: number): void;
37
+ center(): void;
38
+ }[];
39
+ };
40
+ }
41
+ /** Runs in the main process (`app.evaluate`): sizes and centres the first window. */
42
+ export declare function resizeMainWindow({ BrowserWindow }: ElectronMain, size: {
43
+ width: number;
44
+ height: number;
45
+ }): void;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Functions Playwright serializes and runs inside Obsidian. Each one must be self-contained: it cannot use
3
+ * imports or other functions of this file, because only its source text crosses into the page. They are exported
4
+ * so tests can run them against a fake `globalThis`.
5
+ */
6
+ /** Init script: marks community plugins as trusted for the vault, so Obsidian never shows the "Do you trust the author" dialog. */
7
+ export function applyTrust(key) {
8
+ globalThis.localStorage?.setItem(key, "true");
9
+ }
10
+ /**
11
+ * Reads the readiness state of the window. Obsidian registers `plugins[id]` before it awaits the plugin's `onload()`
12
+ * and sets `app.plugins.loadingPluginId` to the id while that runs (cleared to null once `loadPlugin` resolves), so
13
+ * "present in `plugins`" alone is not "loaded": commands and settings tabs that `onload()` adds after an `await`
14
+ * would not exist yet.
15
+ */
16
+ export function readinessState(ids) {
17
+ const app = globalThis.app;
18
+ const loaded = app?.plugins?.plugins;
19
+ const loadingId = app?.plugins?.loadingPluginId;
20
+ const loading = ids.filter((id) => loadingId === id);
21
+ return {
22
+ hasApp: app !== undefined,
23
+ layoutReady: app?.workspace?.layoutReady === true,
24
+ missing: ids.filter((id) => loadingId !== id && loaded?.[id] === undefined),
25
+ loading,
26
+ };
27
+ }
28
+ /**
29
+ * True once the workspace layout is ready and, for every plugin in `ids`, `plugins[id]` exists and Obsidian is no
30
+ * longer inside that plugin's `onload()`. Written out in full (not as a call to `readinessState`) because only this
31
+ * function's own source text crosses into the page.
32
+ */
33
+ export function isReady(ids) {
34
+ const app = globalThis.app;
35
+ const loaded = app?.plugins?.plugins;
36
+ const loadingId = app?.plugins?.loadingPluginId;
37
+ return (app?.workspace?.layoutReady === true &&
38
+ loaded !== undefined &&
39
+ ids.every((id) => loaded[id] !== undefined && loadingId !== id));
40
+ }
41
+ /** The Obsidian version, asked the same way Obsidian's own shell asks. `null` when the renderer cannot answer. */
42
+ export function readRunningVersion() {
43
+ const globals = globalThis;
44
+ const electron = globals.require?.("electron");
45
+ const version = electron?.ipcRenderer?.sendSync?.("version");
46
+ return typeof version === "string" ? version : null;
47
+ }
48
+ /** Runs in the main process (`app.evaluate`): sizes and centres the first window. */
49
+ export function resizeMainWindow({ BrowserWindow }, size) {
50
+ const window = BrowserWindow.getAllWindows()[0];
51
+ window?.setSize(size.width, size.height);
52
+ window?.center();
53
+ }
@@ -0,0 +1,9 @@
1
+ import { type PeerProblem, type VersionReader } from "../peers/versions.js";
2
+ /**
3
+ * What the e2e module needs from the plugin's `node_modules`, as a list of problems (empty when all is well). The
4
+ * kit declares no peer dependency on these: npm checks an optional peer whenever it is installed, so a plugin on an
5
+ * older Playwright or Electron could not install the kit at all, even if it never runs e2e.
6
+ */
7
+ export declare function findE2ePeerProblems(read: VersionReader): PeerProblem[];
8
+ /** Throws one error with every problem and the command that fixes them; `source` names the caller in the message. */
9
+ export declare function assertE2ePeers(read: VersionReader, source: string): void;
@@ -0,0 +1,19 @@
1
+ import { checkRule, formatPeerError } from "../peers/versions.js";
2
+ /** The oldest Playwright the kit's e2e module has been run on. */
3
+ const PLAYWRIGHT = { name: "@playwright/test", minMajor: 1, maxMajor: 1, minMinor: 62, range: "^1.62.0" };
4
+ /** The oldest Electron the kit's e2e module has been run on; later versions are accepted. */
5
+ const ELECTRON = { name: "electron", minMajor: 39, range: ">=39.0.0" };
6
+ /**
7
+ * What the e2e module needs from the plugin's `node_modules`, as a list of problems (empty when all is well). The
8
+ * kit declares no peer dependency on these: npm checks an optional peer whenever it is installed, so a plugin on an
9
+ * older Playwright or Electron could not install the kit at all, even if it never runs e2e.
10
+ */
11
+ export function findE2ePeerProblems(read) {
12
+ return [PLAYWRIGHT, ELECTRON].flatMap((rule) => checkRule(rule, read(rule.name)) ?? []);
13
+ }
14
+ /** Throws one error with every problem and the command that fixes them; `source` names the caller in the message. */
15
+ export function assertE2ePeers(read, source) {
16
+ const problems = findE2ePeerProblems(read);
17
+ if (problems.length > 0)
18
+ throw new Error(formatPeerError(source, problems));
19
+ }
@@ -0,0 +1,32 @@
1
+ /** A built plugin ready to be copied into the test vault. */
2
+ export interface PluginSource {
3
+ /** From the plugin's `manifest.json`. */
4
+ readonly id: string;
5
+ readonly dir: string;
6
+ readonly mainJs: string;
7
+ readonly manifestJson: string;
8
+ /** `undefined` when the plugin has no `styles.css`. */
9
+ readonly stylesCss: string | undefined;
10
+ }
11
+ /** Reads the id from `<dir>/manifest.json` and checks that the build output is there. */
12
+ export declare function readPluginSource(dir: string): PluginSource;
13
+ /** Rejects two plugins with the same id (the second would silently overwrite the first in the vault). */
14
+ export declare function assertUniqueIds(sources: readonly PluginSource[]): void;
15
+ /** Rejects `data` for a plugin that is not installed: the entry would be written for nobody, usually a typo in the id. */
16
+ export declare function assertDataIdsInstalled(data: Readonly<Record<string, unknown>>, sources: readonly PluginSource[]): void;
17
+ /** Newest modification time among the non-test files under `<dir>/src`, or `undefined` when there is no `src` folder. */
18
+ export declare function newestSourceFile(dir: string): {
19
+ file: string;
20
+ mtimeMs: number;
21
+ } | undefined;
22
+ /**
23
+ * Refuses a plugin whose `main.js` is older than its newest source file: the e2e would test code that no longer
24
+ * exists. It compares modification times, not content. A plugin folder without `src/` (a prebuilt dist) is not checked.
25
+ */
26
+ export declare function assertBuildFresh(source: PluginSource): void;
27
+ /** Copies the build output into `.obsidian/plugins/<id>/`. Other files already there (a seeded `data.json`) stay. */
28
+ export declare function installPlugin(vaultPath: string, source: PluginSource): void;
29
+ /** Lists the ids in `community-plugins.json`, keeping any the seed vault already enables. */
30
+ export declare function writeCommunityPlugins(vaultPath: string, ids: readonly string[]): string[];
31
+ /** Writes `.obsidian/plugins/<id>/data.json`, replacing the seed's. */
32
+ export declare function writePluginData(vaultPath: string, id: string, data: Readonly<Record<string, unknown>>): void;
@@ -0,0 +1,119 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { readManifest } from "../config/manifest.js";
4
+ import { writeJson } from "./vault.js";
5
+ /** Reads the id from `<dir>/manifest.json` and checks that the build output is there. */
6
+ export function readPluginSource(dir) {
7
+ const manifest = readManifest(dir);
8
+ const mainJs = path.join(dir, "main.js");
9
+ if (!fs.existsSync(mainJs)) {
10
+ throw new Error(`Plugin "${manifest.id}" has no built main.js in ${dir}. Run \`opdk build\` there first.`);
11
+ }
12
+ const stylesCss = path.join(dir, "styles.css");
13
+ return {
14
+ id: manifest.id,
15
+ dir,
16
+ mainJs,
17
+ manifestJson: path.join(dir, "manifest.json"),
18
+ stylesCss: fs.existsSync(stylesCss) ? stylesCss : undefined,
19
+ };
20
+ }
21
+ /** Rejects two plugins with the same id (the second would silently overwrite the first in the vault). */
22
+ export function assertUniqueIds(sources) {
23
+ const seen = new Map();
24
+ for (const source of sources) {
25
+ const earlier = seen.get(source.id);
26
+ if (earlier !== undefined) {
27
+ throw new Error(`Plugins ${earlier} and ${source.dir} both have the id "${source.id}". Each plugin id can be installed once.`);
28
+ }
29
+ seen.set(source.id, source.dir);
30
+ }
31
+ }
32
+ /** Rejects `data` for a plugin that is not installed: the entry would be written for nobody, usually a typo in the id. */
33
+ export function assertDataIdsInstalled(data, sources) {
34
+ const ids = sources.map((source) => source.id);
35
+ for (const id of Object.keys(data)) {
36
+ if (!ids.includes(id)) {
37
+ throw new Error(`The data option has an entry for "${id}", but the installed plugins are: ${ids.join(", ")}.`);
38
+ }
39
+ }
40
+ }
41
+ const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/;
42
+ /** Newest modification time among the non-test files under `<dir>/src`, or `undefined` when there is no `src` folder. */
43
+ export function newestSourceFile(dir) {
44
+ const srcDir = path.join(dir, "src");
45
+ if (!fs.existsSync(srcDir)) {
46
+ return undefined;
47
+ }
48
+ let newest;
49
+ const walk = (current) => {
50
+ for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
51
+ const full = path.join(current, entry.name);
52
+ if (entry.isDirectory()) {
53
+ walk(full);
54
+ }
55
+ else if (entry.isFile() && !TEST_FILE.test(entry.name)) {
56
+ const { mtimeMs } = fs.statSync(full);
57
+ if (newest === undefined || mtimeMs > newest.mtimeMs) {
58
+ newest = { file: full, mtimeMs };
59
+ }
60
+ }
61
+ }
62
+ };
63
+ walk(srcDir);
64
+ return newest;
65
+ }
66
+ /**
67
+ * Refuses a plugin whose `main.js` is older than its newest source file: the e2e would test code that no longer
68
+ * exists. It compares modification times, not content. A plugin folder without `src/` (a prebuilt dist) is not checked.
69
+ */
70
+ export function assertBuildFresh(source) {
71
+ const newest = newestSourceFile(source.dir);
72
+ if (newest === undefined) {
73
+ return;
74
+ }
75
+ const built = fs.statSync(source.mainJs).mtimeMs;
76
+ if (built < newest.mtimeMs) {
77
+ throw new Error(`Stale build: main.js of "${source.id}" (${new Date(built).toISOString()}) is older than ` +
78
+ `${path.relative(source.dir, newest.file)} (${new Date(newest.mtimeMs).toISOString()}). ` +
79
+ `Run \`opdk build\` in ${source.dir}. To skip this check for this plugin, set staleBuildCheck: false on its entry in the plugins option ` +
80
+ `(or at the top level for the plugin in the current directory); OPDK_E2E_ALLOW_STALE_BUILD=1 skips it for every plugin in one run.`);
81
+ }
82
+ }
83
+ /** Copies the build output into `.obsidian/plugins/<id>/`. Other files already there (a seeded `data.json`) stay. */
84
+ export function installPlugin(vaultPath, source) {
85
+ const target = path.join(vaultPath, ".obsidian", "plugins", source.id);
86
+ fs.mkdirSync(target, { recursive: true });
87
+ fs.copyFileSync(source.mainJs, path.join(target, "main.js"));
88
+ fs.copyFileSync(source.manifestJson, path.join(target, "manifest.json"));
89
+ if (source.stylesCss !== undefined) {
90
+ fs.copyFileSync(source.stylesCss, path.join(target, "styles.css"));
91
+ }
92
+ }
93
+ /** Lists the ids in `community-plugins.json`, keeping any the seed vault already enables. */
94
+ export function writeCommunityPlugins(vaultPath, ids) {
95
+ const file = path.join(vaultPath, ".obsidian", "community-plugins.json");
96
+ let existing;
97
+ try {
98
+ existing = JSON.parse(fs.readFileSync(file, "utf8"));
99
+ }
100
+ catch (error) {
101
+ if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) {
102
+ throw new Error(`${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
103
+ }
104
+ }
105
+ const kept = [];
106
+ if (existing !== undefined) {
107
+ if (!Array.isArray(existing) || !existing.every((item) => typeof item === "string")) {
108
+ throw new Error(`${file} must be a JSON array of plugin ids.`);
109
+ }
110
+ kept.push(...existing);
111
+ }
112
+ const all = [...new Set([...kept, ...ids])];
113
+ writeJson(file, all);
114
+ return all;
115
+ }
116
+ /** Writes `.obsidian/plugins/<id>/data.json`, replacing the seed's. */
117
+ export function writePluginData(vaultPath, id, data) {
118
+ writeJson(path.join(vaultPath, ".obsidian", "plugins", id, "data.json"), data);
119
+ }