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

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,33 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { repositoryFreeEnvironment } from "./git.js";
4
+ const execFileAsync = promisify(execFile);
5
+ /** Where to get gh; part of the message of every "gh is missing" failure. */
6
+ export const GH_INSTALL_HINT = "Install the GitHub CLI from https://cli.github.com and sign in with `gh auth login`.";
7
+ /** The real thing. `gh` never prompts: a missing sign-in is an error with a fix, not a question on the terminal. */
8
+ export function createRunGh(cwd, baseEnv = process.env) {
9
+ const env = { ...repositoryFreeEnvironment(baseEnv), GH_PROMPT_DISABLED: "1", GIT_TERMINAL_PROMPT: "0", GH_NO_UPDATE_NOTIFIER: "1" };
10
+ const exec = async (args, encoding) => {
11
+ try {
12
+ const { stdout } = await execFileAsync("gh", [...args], { cwd, env, encoding, maxBuffer: 256 * 1024 * 1024 });
13
+ return stdout;
14
+ }
15
+ catch (error) {
16
+ throw new Error(describeGhFailure(args, error), { cause: error });
17
+ }
18
+ };
19
+ return {
20
+ text: async (args) => String(await exec(args, "utf8")),
21
+ bytes: async (args) => {
22
+ const out = await exec(args, "buffer");
23
+ return Buffer.isBuffer(out) ? out : Buffer.from(out);
24
+ },
25
+ };
26
+ }
27
+ export function describeGhFailure(args, error) {
28
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
29
+ return `gh is not installed or not on PATH. ${GH_INSTALL_HINT}`;
30
+ }
31
+ const stderr = error instanceof Error && "stderr" in error ? String(error.stderr).trim() : "";
32
+ return `gh ${args.join(" ")} failed: ${stderr === "" ? String(error) : stderr}`;
33
+ }
@@ -0,0 +1,49 @@
1
+ /** Runs `git <args>` in the plugin folder and returns stdout. Rejects with git's own message when git fails. */
2
+ export type RunGit = (args: readonly string[]) => Promise<string>;
3
+ /**
4
+ * `env` without the variables that locate a repository, so git looks at the plugin folder and not at the repository
5
+ * of an outer hook. Everything else stays: `GIT_SSH_COMMAND`, `GIT_ASKPASS`, `GIT_CONFIG_*` and the like decide
6
+ * whether `git fetch` and `git ls-remote` can reach the remote at all.
7
+ */
8
+ export declare function repositoryFreeEnvironment(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
9
+ /** `git ls-remote` only lists refs; a host that does not answer in this time is down or unreachable, not slow. */
10
+ export declare const LS_REMOTE_TIMEOUT_MS = 60000;
11
+ /**
12
+ * The environment of a command that talks to the remote: no password prompt on the terminal, and ssh in batch mode
13
+ * (no passphrase, host key or password question either) unless the user chose their own ssh through `GIT_SSH_COMMAND`,
14
+ * `GIT_SSH` or `core.sshCommand`.
15
+ */
16
+ export declare function remoteEnvironment(env: NodeJS.ProcessEnv, hasOwnSsh: boolean): NodeJS.ProcessEnv;
17
+ /**
18
+ * The real thing. `baseEnv` is the process environment unless a test passes a hermetic one; the user's git config
19
+ * is respected either way.
20
+ */
21
+ export declare function createRunGit(cwd: string, baseEnv?: NodeJS.ProcessEnv, lsRemoteTimeoutMs?: number): RunGit;
22
+ /** What preflight needs to know about the repository. Gathered by `collectFacts`, judged by `preflightProblems`. */
23
+ export interface RepoFacts {
24
+ readonly insideRepo: boolean;
25
+ /** Lines of `git status --porcelain`: changed and untracked files. */
26
+ readonly dirty: readonly string[];
27
+ /** Undefined on a detached HEAD. */
28
+ readonly branch: string | undefined;
29
+ /** From the config, else `origin/HEAD`; undefined when neither gives one. */
30
+ readonly defaultBranch: string | undefined;
31
+ readonly hasOrigin: boolean;
32
+ /** Why `git fetch origin` failed, if it did. */
33
+ readonly fetchError: string | undefined;
34
+ /** Commits on origin's default branch that this branch lacks; undefined when origin has no such branch. */
35
+ readonly behind: number | undefined;
36
+ readonly ahead: number | undefined;
37
+ readonly localTag: boolean;
38
+ readonly remoteTag: "present" | "absent" | "unreachable";
39
+ readonly remoteTagError: string | undefined;
40
+ }
41
+ export interface FactsInput {
42
+ readonly run: RunGit;
43
+ readonly version: string;
44
+ readonly defaultBranchOverride: string | undefined;
45
+ }
46
+ /** Stdout trimmed, or undefined when git fails: for questions whose answer "no" is a normal outcome. */
47
+ export declare function tryGit(run: RunGit, args: readonly string[]): Promise<string | undefined>;
48
+ /** Reads the repository state. `git fetch origin` is the only thing that writes (remote-tracking refs); nothing is pushed. */
49
+ export declare function collectFacts({ run, version, defaultBranchOverride }: FactsInput): Promise<RepoFacts>;
@@ -0,0 +1,111 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ const execFileAsync = promisify(execFile);
4
+ /** The variables that tell git which repository to use. An outer hook or worktree session exports them. */
5
+ const REPOSITORY_LOCATION_VARIABLES = new Set([
6
+ "GIT_DIR",
7
+ "GIT_WORK_TREE",
8
+ "GIT_INDEX_FILE",
9
+ "GIT_OBJECT_DIRECTORY",
10
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
11
+ "GIT_COMMON_DIR",
12
+ "GIT_PREFIX",
13
+ ]);
14
+ /**
15
+ * `env` without the variables that locate a repository, so git looks at the plugin folder and not at the repository
16
+ * of an outer hook. Everything else stays: `GIT_SSH_COMMAND`, `GIT_ASKPASS`, `GIT_CONFIG_*` and the like decide
17
+ * whether `git fetch` and `git ls-remote` can reach the remote at all.
18
+ */
19
+ export function repositoryFreeEnvironment(env) {
20
+ return Object.fromEntries(Object.entries(env).filter(([name]) => !REPOSITORY_LOCATION_VARIABLES.has(name)));
21
+ }
22
+ /** Commands that talk to the remote: they must fail with a message instead of waiting for a password on the terminal. */
23
+ const REMOTE_COMMANDS = new Set(["fetch", "ls-remote", "push"]);
24
+ /** `git ls-remote` only lists refs; a host that does not answer in this time is down or unreachable, not slow. */
25
+ export const LS_REMOTE_TIMEOUT_MS = 60_000;
26
+ /**
27
+ * The environment of a command that talks to the remote: no password prompt on the terminal, and ssh in batch mode
28
+ * (no passphrase, host key or password question either) unless the user chose their own ssh through `GIT_SSH_COMMAND`,
29
+ * `GIT_SSH` or `core.sshCommand`.
30
+ */
31
+ export function remoteEnvironment(env, hasOwnSsh) {
32
+ const own = hasOwnSsh || (env.GIT_SSH_COMMAND ?? "") !== "" || (env.GIT_SSH ?? "") !== "";
33
+ return { ...env, GIT_TERMINAL_PROMPT: "0", ...(!own && { GIT_SSH_COMMAND: "ssh -o BatchMode=yes" }) };
34
+ }
35
+ /**
36
+ * The real thing. `baseEnv` is the process environment unless a test passes a hermetic one; the user's git config
37
+ * is respected either way.
38
+ */
39
+ export function createRunGit(cwd, baseEnv = process.env, lsRemoteTimeoutMs = LS_REMOTE_TIMEOUT_MS) {
40
+ const base = repositoryFreeEnvironment(baseEnv);
41
+ let ownSsh;
42
+ const hasOwnSsh = () => (ownSsh ??= execFileAsync("git", ["config", "--get", "core.sshCommand"], { cwd, env: base, encoding: "utf8" }).then(({ stdout }) => stdout.trim() !== "", () => false));
43
+ return async (args) => {
44
+ const env = REMOTE_COMMANDS.has(args[0] ?? "") ? remoteEnvironment(base, await hasOwnSsh()) : base;
45
+ try {
46
+ const { stdout } = await execFileAsync("git", [...args], { cwd, env, encoding: "utf8", maxBuffer: 64 * 1024 * 1024, ...(args[0] === "ls-remote" && { timeout: lsRemoteTimeoutMs }) });
47
+ return stdout;
48
+ }
49
+ catch (error) {
50
+ throw new Error(describeGitFailure(args, error, lsRemoteTimeoutMs), { cause: error });
51
+ }
52
+ };
53
+ }
54
+ function describeGitFailure(args, error, lsRemoteTimeoutMs) {
55
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
56
+ return "git is not installed or not on PATH.";
57
+ }
58
+ if (args[0] === "ls-remote" && error instanceof Error && "killed" in error && error.killed === true) {
59
+ return `git ${args.join(" ")} did not answer in ${String(lsRemoteTimeoutMs / 1000)} seconds and was stopped.`;
60
+ }
61
+ const stderr = error instanceof Error && "stderr" in error && typeof error.stderr === "string" ? error.stderr.trim() : "";
62
+ const credentials = /terminal prompts disabled|could not read (?:Username|Password)/i.test(stderr)
63
+ ? "\nGit asked for credentials and opdk never waits for a prompt. Sign in first (a credential helper, `gh auth login` or an SSH key) and rerun."
64
+ : "";
65
+ return `git ${args.join(" ")} failed: ${stderr === "" ? String(error) : stderr}${credentials}`;
66
+ }
67
+ const message = (error) => (error instanceof Error ? error.message : String(error));
68
+ /** Stdout trimmed, or undefined when git fails: for questions whose answer "no" is a normal outcome. */
69
+ export async function tryGit(run, args) {
70
+ try {
71
+ return (await run(args)).trim();
72
+ }
73
+ catch {
74
+ return undefined;
75
+ }
76
+ }
77
+ /** Reads the repository state. `git fetch origin` is the only thing that writes (remote-tracking refs); nothing is pushed. */
78
+ export async function collectFacts({ run, version, defaultBranchOverride }) {
79
+ if ((await tryGit(run, ["rev-parse", "--is-inside-work-tree"])) !== "true") {
80
+ return { insideRepo: false, dirty: [], branch: undefined, defaultBranch: undefined, hasOrigin: false, fetchError: undefined, behind: undefined, ahead: undefined, localTag: false, remoteTag: "absent", remoteTagError: undefined };
81
+ }
82
+ const dirty = (await run(["status", "--porcelain"])).split("\n").filter((line) => line !== "");
83
+ const branch = await tryGit(run, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
84
+ const hasOrigin = (await tryGit(run, ["remote", "get-url", "origin"])) !== undefined;
85
+ let fetchError;
86
+ let remoteTag = "absent";
87
+ let remoteTagError;
88
+ if (hasOrigin) {
89
+ try {
90
+ // --no-tags: only the branches are updated, so a tag that exists on origin alone is not copied into the repository.
91
+ await run(["fetch", "--quiet", "--no-tags", "origin"]);
92
+ }
93
+ catch (error) {
94
+ fetchError = message(error);
95
+ }
96
+ try {
97
+ const listed = await run(["ls-remote", "--tags", "origin", `refs/tags/${version}`]);
98
+ remoteTag = listed.trim() === "" ? "absent" : "present";
99
+ }
100
+ catch (error) {
101
+ remoteTag = "unreachable";
102
+ remoteTagError = message(error);
103
+ }
104
+ }
105
+ const symbolic = hasOrigin ? await tryGit(run, ["symbolic-ref", "--quiet", "refs/remotes/origin/HEAD"]) : undefined;
106
+ const defaultBranch = defaultBranchOverride ?? symbolic?.replace(/^refs\/remotes\/origin\//, "");
107
+ const counts = defaultBranch === undefined ? undefined : await tryGit(run, ["rev-list", "--left-right", "--count", `HEAD...refs/remotes/origin/${defaultBranch}`]);
108
+ const [ahead, behind] = counts?.split(/\s+/).map(Number) ?? [];
109
+ const localTag = (await tryGit(run, ["rev-parse", "--quiet", "--verify", `refs/tags/${version}`])) !== undefined;
110
+ return { insideRepo: true, dirty, branch, defaultBranch, hasOrigin, fetchError, behind, ahead, localTag, remoteTag, remoteTagError };
111
+ }
@@ -0,0 +1,30 @@
1
+ import type { Reporter } from "../cli/reporter.js";
2
+ /** The exit code of a process ended by Ctrl+C (128 + SIGINT). */
3
+ export declare const INTERRUPTED_EXIT = 130;
4
+ /** What the CLI offers to a command that must clean up when the user presses Ctrl+C. */
5
+ export interface InterruptHooks {
6
+ /** Registers a SIGINT listener and returns what removes it (`CommandContext.onInterrupt`). */
7
+ readonly onInterrupt: (listener: () => void) => () => void;
8
+ /** Ends the process. Injected so a test can see the exit code without ending the test run. */
9
+ readonly exit: (code: number) => void;
10
+ }
11
+ /** Things to undo when the command ends early: restore edited files, remove temp folders. Each runs once. */
12
+ export declare class CleanupSet {
13
+ private readonly actions;
14
+ /** Registers an action and returns what takes it off the list again (the normal path cleans up by itself). */
15
+ add(action: () => void): () => void;
16
+ /** Runs every action, even when one throws, then throws the first error so nothing is swallowed. */
17
+ run(): void;
18
+ }
19
+ export interface InterruptGuard {
20
+ /** Whether Ctrl+C arrived while the guard was active. */
21
+ interrupted(): boolean;
22
+ /** Unregisters the listener. */
23
+ stop(): void;
24
+ }
25
+ /**
26
+ * While the guard is active, Ctrl+C runs the cleanups and exits with 130. Registering a SIGINT listener removes
27
+ * Node's default exit, so the listener must end the process itself. Without hooks (a test, a non-CLI caller) it
28
+ * does nothing.
29
+ */
30
+ export declare function guardInterrupt(hooks: InterruptHooks | undefined, cleanups: CleanupSet, reporter: Reporter): InterruptGuard;
@@ -0,0 +1,60 @@
1
+ /** The exit code of a process ended by Ctrl+C (128 + SIGINT). */
2
+ export const INTERRUPTED_EXIT = 130;
3
+ /** Things to undo when the command ends early: restore edited files, remove temp folders. Each runs once. */
4
+ export class CleanupSet {
5
+ actions = new Set();
6
+ /** Registers an action and returns what takes it off the list again (the normal path cleans up by itself). */
7
+ add(action) {
8
+ this.actions.add(action);
9
+ return () => {
10
+ this.actions.delete(action);
11
+ };
12
+ }
13
+ /** Runs every action, even when one throws, then throws the first error so nothing is swallowed. */
14
+ run() {
15
+ const errors = [];
16
+ for (const action of [...this.actions]) {
17
+ this.actions.delete(action);
18
+ try {
19
+ action();
20
+ }
21
+ catch (error) {
22
+ errors.push(error);
23
+ }
24
+ }
25
+ if (errors.length > 0) {
26
+ throw errors[0];
27
+ }
28
+ }
29
+ }
30
+ /**
31
+ * While the guard is active, Ctrl+C runs the cleanups and exits with 130. Registering a SIGINT listener removes
32
+ * Node's default exit, so the listener must end the process itself. Without hooks (a test, a non-CLI caller) it
33
+ * does nothing.
34
+ */
35
+ export function guardInterrupt(hooks, cleanups, reporter) {
36
+ let seen = false;
37
+ let active = true;
38
+ const unregister = hooks?.onInterrupt(() => {
39
+ seen = true;
40
+ reporter.warn("release", "interrupted: restoring the files and removing the temp folders");
41
+ try {
42
+ cleanups.run();
43
+ }
44
+ catch (error) {
45
+ reporter.failure("release", `cleanup after Ctrl+C failed: ${error instanceof Error ? error.message : String(error)}`, {
46
+ hint: "Look at `git status` and restore the changed files with git; remove opdk-release-* folders from the temp directory.",
47
+ });
48
+ }
49
+ hooks.exit(INTERRUPTED_EXIT);
50
+ }) ?? (() => undefined);
51
+ return {
52
+ interrupted: () => seen,
53
+ stop: () => {
54
+ if (active) {
55
+ active = false;
56
+ unregister();
57
+ }
58
+ },
59
+ };
60
+ }
@@ -0,0 +1,33 @@
1
+ export type JsonRecord = Record<string, unknown>;
2
+ export declare function asRecord(value: unknown): JsonRecord | undefined;
3
+ /** A file as the release module reads it: its text and parsed value, or why there is neither. */
4
+ export type Loaded = {
5
+ readonly kind: "ok";
6
+ readonly text: string;
7
+ readonly value: unknown;
8
+ } | {
9
+ readonly kind: "missing";
10
+ } | {
11
+ readonly kind: "invalid";
12
+ readonly message: string;
13
+ };
14
+ export declare function loadJson(file: string): Loaded;
15
+ /** The text of a file, or undefined when it does not exist. Other read errors throw. */
16
+ export declare function loadText(file: string): string | undefined;
17
+ /** What is wrong with a file's formatting and what to do about it. */
18
+ export interface FormatIssue {
19
+ readonly message: string;
20
+ readonly hint: string;
21
+ }
22
+ /**
23
+ * Whether `JSON.stringify` would write the file back unchanged. Returns undefined when it would, else what to tell
24
+ * the owner. Prettier is no fix: it keeps `{"1.7.1": "1.5.0"}` on one line, so the hint rewrites the file with the
25
+ * same `JSON.stringify` call (and the file's own indent) that opdk uses.
26
+ */
27
+ export declare function findFormatIssue(originalText: string, parsed: unknown, fileName: string): FormatIssue | undefined;
28
+ /**
29
+ * Rewrites a JSON file's text from a changed value, keeping its indentation, final newline and line endings (all
30
+ * CRLF or all LF). It refuses a file that `JSON.stringify` would not write back unchanged (mixed line endings,
31
+ * hand-aligned values): reformatting the whole file in a release commit hides the one line that matters.
32
+ */
33
+ export declare function stringifyLike(originalText: string, parsed: unknown, changed: unknown, fileName: string): string;
@@ -0,0 +1,81 @@
1
+ import { readFileSync } from "node:fs";
2
+ export function asRecord(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
4
+ }
5
+ export function loadJson(file) {
6
+ let text;
7
+ try {
8
+ text = readFileSync(file, "utf8");
9
+ }
10
+ catch (error) {
11
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
12
+ return { kind: "missing" };
13
+ }
14
+ throw new Error(`Cannot read ${file}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
15
+ }
16
+ try {
17
+ return { kind: "ok", text, value: JSON.parse(text) };
18
+ }
19
+ catch (error) {
20
+ return { kind: "invalid", message: error instanceof Error ? error.message : String(error) };
21
+ }
22
+ }
23
+ /** The text of a file, or undefined when it does not exist. Other read errors throw. */
24
+ export function loadText(file) {
25
+ try {
26
+ return readFileSync(file, "utf8");
27
+ }
28
+ catch (error) {
29
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
30
+ return undefined;
31
+ }
32
+ throw new Error(`Cannot read ${file}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
33
+ }
34
+ }
35
+ function layoutOf(originalText) {
36
+ // A file whose every line ends in CRLF is compared and written as LF, then converted back; a file that mixes the two is refused.
37
+ const crlf = originalText.includes("\r\n") && !originalText.replace(/\r\n/g, "").includes("\n");
38
+ const text = crlf ? originalText.replace(/\r\n/g, "\n") : originalText;
39
+ const indent = detectIndent(text);
40
+ const finalNewline = text.endsWith("\n") ? "\n" : "";
41
+ return { crlf, text, indent, write: (value) => `${JSON.stringify(value, null, indent)}${finalNewline}` };
42
+ }
43
+ /**
44
+ * Whether `JSON.stringify` would write the file back unchanged. Returns undefined when it would, else what to tell
45
+ * the owner. Prettier is no fix: it keeps `{"1.7.1": "1.5.0"}` on one line, so the hint rewrites the file with the
46
+ * same `JSON.stringify` call (and the file's own indent) that opdk uses.
47
+ */
48
+ export function findFormatIssue(originalText, parsed, fileName) {
49
+ const layout = layoutOf(originalText);
50
+ if (layout.write(parsed) === layout.text) {
51
+ return undefined;
52
+ }
53
+ const indent = typeof layout.indent === "number" ? String(layout.indent) : "'\\t'";
54
+ const script = `const fs = require('fs'); const f = '${fileName}'; fs.writeFileSync(f, JSON.stringify(JSON.parse(fs.readFileSync(f, 'utf8')), null, ${indent}) + '\\n')`;
55
+ return {
56
+ message: `${fileName} is not formatted the way JSON.stringify writes it (indent, line endings or spacing), so opdk would reformat the whole file.`,
57
+ hint: `Rewrite it once with \`node -e "${script}"\` and run opdk again.`,
58
+ };
59
+ }
60
+ /**
61
+ * Rewrites a JSON file's text from a changed value, keeping its indentation, final newline and line endings (all
62
+ * CRLF or all LF). It refuses a file that `JSON.stringify` would not write back unchanged (mixed line endings,
63
+ * hand-aligned values): reformatting the whole file in a release commit hides the one line that matters.
64
+ */
65
+ export function stringifyLike(originalText, parsed, changed, fileName) {
66
+ const issue = findFormatIssue(originalText, parsed, fileName);
67
+ if (issue !== undefined) {
68
+ throw new Error(`${issue.message} ${issue.hint}`);
69
+ }
70
+ const layout = layoutOf(originalText);
71
+ const result = layout.write(changed);
72
+ return layout.crlf ? result.replace(/\n/g, "\r\n") : result;
73
+ }
74
+ function detectIndent(text) {
75
+ const match = /^([ \t]+)\S/m.exec(text);
76
+ const indent = match?.[1];
77
+ if (indent === undefined) {
78
+ return 2;
79
+ }
80
+ return indent.includes("\t") ? "\t" : indent.length;
81
+ }
@@ -0,0 +1,8 @@
1
+ import { type WorkflowFile } from "../kit/pins.js";
2
+ import { type GroupResult } from "./problems.js";
3
+ import type { ProjectFiles } from "./project-files.js";
4
+ /**
5
+ * The `kit` group: package.json, the lockfile and the workflow `uses:` lines name one kit release. A plugin that
6
+ * does not use the kit, or does not call its workflows, has fewer places to compare and passes.
7
+ */
8
+ export declare function checkKit(files: ProjectFiles, workflows: readonly WorkflowFile[]): GroupResult;
@@ -0,0 +1,51 @@
1
+ import { judgePins, readKitPins, shortSha } from "../kit/pins.js";
2
+ import { errorProblem } from "./problems.js";
3
+ import { valueOf } from "./project-files.js";
4
+ /** What the places agree on, as a sentence for the `✓` line. */
5
+ function agreement(verdict, hasPackageJson, lockVersion, hasLock) {
6
+ // An npm install names no tag in package.json; the lockfile's version, when there is a lockfile, is the release then.
7
+ const named = verdict.tag ?? lockVersion ?? (verdict.commit === undefined ? "one release" : shortSha(verdict.commit));
8
+ const where = [
9
+ ...(hasPackageJson ? ["package.json"] : []),
10
+ ...(hasLock ? ["package-lock.json"] : []),
11
+ ...(verdict.usesCount > 0 ? [`${String(verdict.usesCount)} workflow ${verdict.usesCount === 1 ? "line" : "lines"}`] : []),
12
+ ];
13
+ const commit = verdict.commit === undefined ? "" : ` (${shortSha(verdict.commit)})`;
14
+ return `the kit is ${named}${commit} in ${where.join(", ")}`;
15
+ }
16
+ /**
17
+ * The `kit` group: package.json, the lockfile and the workflow `uses:` lines name one kit release. A plugin that
18
+ * does not use the kit, or does not call its workflows, has fewer places to compare and passes.
19
+ */
20
+ export function checkKit(files, workflows) {
21
+ const pins = readKitPins({ packageJson: valueOf(files.packageJson), lock: valueOf(files.lock), workflows });
22
+ const verdict = judgePins(pins);
23
+ if (pins.packageJson.length === 0 && pins.uses.length === 0) {
24
+ return { group: "kit", passed: "obsidian-plugin-dev-kit is not a git dependency and no workflow calls it", problems: [] };
25
+ }
26
+ if (verdict.reasons.length === 0) {
27
+ return { group: "kit", passed: agreement(verdict, pins.packageJson.length > 0, pins.lock?.version, pins.lock !== undefined), problems: [] };
28
+ }
29
+ if (pins.packageJson.length === 0 && pins.lock?.version !== undefined) {
30
+ // Installed from npm: `opdk kit upgrade` handles only git-tag installs, so name the manual steps.
31
+ const version = pins.lock.version;
32
+ return {
33
+ group: "kit",
34
+ passed: "",
35
+ problems: [
36
+ errorProblem("kit", "the kit is not pinned to one release.", `The kit is installed from npm, which \`opdk kit upgrade\` does not handle yet. Point every \`uses:\` line of the kit's workflows at the commit of v${version} with the comment \`# v${version}\` (the commit: \`git ls-remote https://github.com/Dimagious/obsidian-plugin-dev-kit 'refs/tags/v${version}^{}'\`; without \`^{}\` it prints the tag object, not the commit), or install the version the workflows name with \`npm install -D -E obsidian-plugin-dev-kit@X.Y.Z\`. Then commit the result.`, [...verdict.reasons, ...verdict.places]),
37
+ ],
38
+ };
39
+ }
40
+ // `opdk kit upgrade` only takes vX.Y.Z; a branch or other ref in package.json cannot be named there.
41
+ const named = verdict.tag !== undefined && /^v\d+\.\d+\.\d+$/.test(verdict.tag) ? verdict.tag : undefined;
42
+ const upgrade = named === undefined ? "`opdk kit upgrade`" : `\`opdk kit upgrade ${named}\``;
43
+ const latest = named !== undefined ? " (`opdk kit upgrade` alone takes the latest release)" : " (it takes the latest release; `opdk kit upgrade vX.Y.Z` names one)";
44
+ return {
45
+ group: "kit",
46
+ passed: "",
47
+ problems: [
48
+ errorProblem("kit", "the kit is not pinned to one release.", `Run ${upgrade} to rewrite the lockfile and the workflow pins to one commit${latest}, then commit the result.`, [...verdict.reasons, ...verdict.places]),
49
+ ],
50
+ };
51
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The manifest.json rules of the release check.
3
+ *
4
+ * Source: the official GitHub Action obsidianmd/obsidian-workflows (v1.2.3), `src/manifest.ts`
5
+ * (`validatePluginManifest`, `validateDescription`, `validateAuthor`, `validateUrl`), read on 2026-11-11, with the
6
+ * same split between errors and warnings. Where the action is more lenient than the scanner's lint rule
7
+ * `obsidianmd/validate-manifest` (eslint-plugin-obsidianmd 0.5.1), the lint rule wins for the three things the
8
+ * developer docs (docs.obsidian.md/Reference/Manifest) call required: `author`, `minAppVersion` and `isDesktopOnly`
9
+ * are errors here, the action only recommends them. `helpUrl` is a known field because the lint rule accepts it.
10
+ *
11
+ * Deliberate differences from the action:
12
+ * - It skips the "obsidian" / "plugin" word check on the id of a plugin that is already in the directory, because an
13
+ * id can never change. The kit cannot know that, so an id with such a word is a warning here, and a name with one
14
+ * is an error as in the action.
15
+ * - `helpUrl` is accepted and its URL is checked like the others.
16
+ * - The action's `author-url-own-repo` check (authorUrl points at the plugin's own repository) needs the repository
17
+ * URL, which the kit does not read; the general warning "authorUrl links to a repository" covers it.
18
+ * - A URL field with the wrong type (`authorUrl`, `helpUrl` not a string; `fundingUrl` neither a string nor an object
19
+ * of strings, arrays included) is an error here.
20
+ */
21
+ import { type Problem } from "./problems.js";
22
+ /** All findings for the parsed contents of manifest.json. */
23
+ export declare function checkManifestRules(value: unknown): Problem[];