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,103 @@
1
+ import { BUILD_LOADERS } from "../config/types.js";
2
+ const BUILD_KEYS = ["entry", "outfile", "minify", "target", "external", "loader", "css"];
3
+ const CSS_KEYS = ["entry", "outfile"];
4
+ /** Checks and copies the `build` section of `opdk.config.mjs`. Every error names the offending key. */
5
+ export function validateBuildConfig(value, source) {
6
+ if (!isRecord(value)) {
7
+ throw new Error(`${source}: "build" must be an object.`);
8
+ }
9
+ rejectUnknownKeys(value, BUILD_KEYS, "build", source);
10
+ const entry = optionalString(value, "entry", "build.entry", source);
11
+ const outfile = optionalString(value, "outfile", "build.outfile", source);
12
+ const target = optionalString(value, "target", "build.target", source);
13
+ const minify = optionalBoolean(value, "minify", "build.minify", source);
14
+ const external = optionalStringArray(value, "external", "build.external", source);
15
+ const loader = optionalLoaders(value, source);
16
+ const css = optionalCss(value, source);
17
+ return {
18
+ ...(entry !== undefined && { entry }),
19
+ ...(outfile !== undefined && { outfile }),
20
+ ...(minify !== undefined && { minify }),
21
+ ...(target !== undefined && { target }),
22
+ ...(external !== undefined && { external }),
23
+ ...(loader !== undefined && { loader }),
24
+ ...(css !== undefined && { css }),
25
+ };
26
+ }
27
+ function optionalCss(build, source) {
28
+ const value = own(build, "css");
29
+ if (value === undefined || value === false) {
30
+ return value;
31
+ }
32
+ if (!isRecord(value)) {
33
+ throw new Error(`${source}: "build.css" must be an object ({ entry, outfile }) or false.`);
34
+ }
35
+ rejectUnknownKeys(value, CSS_KEYS, "build.css", source);
36
+ const entry = optionalString(value, "entry", "build.css.entry", source);
37
+ const outfile = optionalString(value, "outfile", "build.css.outfile", source);
38
+ return { ...(entry !== undefined && { entry }), ...(outfile !== undefined && { outfile }) };
39
+ }
40
+ function optionalLoaders(build, source) {
41
+ const value = own(build, "loader");
42
+ if (value === undefined) {
43
+ return undefined;
44
+ }
45
+ if (!isRecord(value)) {
46
+ throw new Error(`${source}: "build.loader" must be an object such as { ".png": "dataurl" }.`);
47
+ }
48
+ const result = {};
49
+ for (const [extension, loader] of Object.entries(value)) {
50
+ if (!extension.startsWith(".")) {
51
+ throw new Error(`${source}: "build.loader" key "${extension}" must start with a dot, for example ".png".`);
52
+ }
53
+ const known = BUILD_LOADERS.find((name) => name === loader);
54
+ if (known === undefined) {
55
+ throw new Error(`${source}: "build.loader[${JSON.stringify(extension)}]" must be one of: ${BUILD_LOADERS.join(", ")}.`);
56
+ }
57
+ result[extension] = known;
58
+ }
59
+ return result;
60
+ }
61
+ function optionalStringArray(record, key, label, source) {
62
+ const value = own(record, key);
63
+ if (value === undefined) {
64
+ return undefined;
65
+ }
66
+ if (!Array.isArray(value) || !value.every((item) => typeof item === "string" && item !== "")) {
67
+ throw new Error(`${source}: "${label}" must be an array of non-empty strings.`);
68
+ }
69
+ return value.map(String);
70
+ }
71
+ function optionalString(record, key, label, source) {
72
+ const value = own(record, key);
73
+ if (value === undefined) {
74
+ return undefined;
75
+ }
76
+ if (typeof value !== "string" || value === "") {
77
+ throw new Error(`${source}: "${label}" must be a non-empty string.`);
78
+ }
79
+ return value;
80
+ }
81
+ function optionalBoolean(record, key, label, source) {
82
+ const value = own(record, key);
83
+ if (value !== undefined && typeof value !== "boolean") {
84
+ throw new Error(`${source}: "${label}" must be true or false.`);
85
+ }
86
+ return value;
87
+ }
88
+ function rejectUnknownKeys(record, allowed, label, source) {
89
+ const unknown = Object.keys(record).filter((key) => !allowed.includes(key));
90
+ if (unknown.length > 0) {
91
+ throw new Error(`${source}: unknown key(s) in "${label}": ${unknown.join(", ")}. Allowed keys: ${allowed.join(", ")}.`);
92
+ }
93
+ }
94
+ function own(record, key) {
95
+ return Object.hasOwn(record, key) ? record[key] : undefined;
96
+ }
97
+ function isRecord(value) {
98
+ if (typeof value !== "object" || value === null) {
99
+ return false;
100
+ }
101
+ const prototype = Object.getPrototypeOf(value);
102
+ return prototype === Object.prototype || prototype === null;
103
+ }
@@ -0,0 +1,23 @@
1
+ export interface InlineResult {
2
+ readonly css: string;
3
+ /** Every file read, entry first. A file imported twice is listed twice. */
4
+ readonly files: readonly string[];
5
+ }
6
+ /**
7
+ * An import problem (missing file, cycle). `files` are the ones read before it, so `--watch` can poll them.
8
+ * `missing` is the absolute path that was not found, so `--watch` can poll it too: creating it must trigger a sync.
9
+ */
10
+ export declare class CssImportError extends Error {
11
+ readonly files: readonly string[];
12
+ readonly missing?: string | undefined;
13
+ constructor(message: string, files: readonly string[], missing?: string | undefined);
14
+ }
15
+ /**
16
+ * Inlines `@import "x.css"` directives, recursively, each path relative to the file that imports it.
17
+ * Pure: file contents come from `read`, which returns undefined for a missing file.
18
+ *
19
+ * Two deliberate differences from the plugin script this was ported from: a missing import is an error
20
+ * that names the importing file (that script printed a warning and left the `@import` in), and an import
21
+ * cycle is an error (that script overflowed the stack). Imports of URLs are left in place for the browser.
22
+ */
23
+ export declare function inlineImports(entryFile: string, read: (file: string) => string | undefined): InlineResult;
@@ -0,0 +1,50 @@
1
+ import path from "node:path";
2
+ const IMPORT_PATTERN = /@import\s+['"]([^'"]+)['"];?/g;
3
+ const URL_PATTERN = /^[a-z][a-z0-9+.-]*:/i;
4
+ /**
5
+ * An import problem (missing file, cycle). `files` are the ones read before it, so `--watch` can poll them.
6
+ * `missing` is the absolute path that was not found, so `--watch` can poll it too: creating it must trigger a sync.
7
+ */
8
+ export class CssImportError extends Error {
9
+ files;
10
+ missing;
11
+ constructor(message, files, missing) {
12
+ super(message);
13
+ this.files = files;
14
+ this.missing = missing;
15
+ this.name = "CssImportError";
16
+ }
17
+ }
18
+ /**
19
+ * Inlines `@import "x.css"` directives, recursively, each path relative to the file that imports it.
20
+ * Pure: file contents come from `read`, which returns undefined for a missing file.
21
+ *
22
+ * Two deliberate differences from the plugin script this was ported from: a missing import is an error
23
+ * that names the importing file (that script printed a warning and left the `@import` in), and an import
24
+ * cycle is an error (that script overflowed the stack). Imports of URLs are left in place for the browser.
25
+ */
26
+ export function inlineImports(entryFile, read) {
27
+ const files = [];
28
+ const inline = (file, chain) => {
29
+ const css = read(file);
30
+ if (css === undefined) {
31
+ throw new CssImportError(`CSS file not found: ${file}.`, [...files], file);
32
+ }
33
+ files.push(file);
34
+ const here = [...chain, file];
35
+ return css.replace(IMPORT_PATTERN, (match, importPath) => {
36
+ if (URL_PATTERN.test(importPath)) {
37
+ return match;
38
+ }
39
+ const target = path.resolve(path.dirname(file), importPath);
40
+ if (here.includes(target)) {
41
+ throw new CssImportError(`CSS import cycle: ${[...here, target].join(" -> ")}. Remove one of the @import lines to break it.`, [...files]);
42
+ }
43
+ if (read(target) === undefined) {
44
+ throw new CssImportError(`${file}: @import "${importPath}" not found (looked for ${target}). Fix the path or remove the import.`, [...files], target);
45
+ }
46
+ return inline(target, here);
47
+ });
48
+ };
49
+ return { css: inline(path.resolve(entryFile), []), files };
50
+ }
@@ -0,0 +1,10 @@
1
+ import type { CommandContext } from "../cli/types.js";
2
+ import { type CssResult } from "./css.js";
3
+ import type { ResolvedCss } from "./options.js";
4
+ /**
5
+ * Runs the CSS bundler and logs what happened. Errors (missing import, cycle) propagate.
6
+ * Without a CSS entry a hand-written stylesheet is a normal setup (`·`); with no stylesheet at all the plugin
7
+ * ships none, which is worth a `!`. `announceNoEntry: false` stays quiet about both, so `--watch` says it once.
8
+ * `onRead` is passed to `buildCss`.
9
+ */
10
+ export declare function runCssStep(cwd: string, css: ResolvedCss, out: Pick<CommandContext, "reporter">, announceNoEntry?: boolean, onRead?: (file: string, stamp: string | undefined) => void): CssResult;
@@ -0,0 +1,27 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { buildCss } from "./css.js";
4
+ /**
5
+ * Runs the CSS bundler and logs what happened. Errors (missing import, cycle) propagate.
6
+ * Without a CSS entry a hand-written stylesheet is a normal setup (`·`); with no stylesheet at all the plugin
7
+ * ships none, which is worth a `!`. `announceNoEntry: false` stays quiet about both, so `--watch` says it once.
8
+ * `onRead` is passed to `buildCss`.
9
+ */
10
+ export function runCssStep(cwd, css, out, announceNoEntry = true, onRead) {
11
+ const result = buildCss(cwd, css, onRead);
12
+ if (result.status === "no-entry") {
13
+ if (announceNoEntry) {
14
+ if (existsSync(path.resolve(cwd, css.outfile))) {
15
+ out.reporter.info("css", `no ${css.entry}, keeping ${css.outfile} as is`);
16
+ }
17
+ else {
18
+ out.reporter.warn("css", `no ${css.entry} and no ${css.outfile}, the plugin ships no stylesheet`);
19
+ }
20
+ }
21
+ return result;
22
+ }
23
+ const files = `${String(result.files)} ${result.files === 1 ? "file" : "files"}`;
24
+ const lines = `${String(result.lines)} ${result.lines === 1 ? "line" : "lines"}`;
25
+ out.reporter.success("css", `${css.entry} -> ${css.outfile} (${files}, ${lines})`);
26
+ return result;
27
+ }
@@ -0,0 +1,24 @@
1
+ import type { ResolvedCss } from "./options.js";
2
+ export type CssResult = {
3
+ readonly status: "built";
4
+ readonly files: number;
5
+ readonly lines: number;
6
+ /** Absolute paths of the distinct files that were read, entry first. `--watch` polls exactly these. */
7
+ readonly inputs: readonly string[];
8
+ }
9
+ /** The entry file does not exist: the plugin keeps a hand-written stylesheet. */
10
+ | {
11
+ readonly status: "no-entry";
12
+ };
13
+ /**
14
+ * A cheap fingerprint of a file as the filesystem reports it (mtime and size), or undefined when it does not exist.
15
+ * `--watch` compares the stamp taken when a file was read with a later one to see an edit that `fs.watchFile`
16
+ * missed, see `runVaultBuild`.
17
+ */
18
+ export declare function fileStamp(file: string): string | undefined;
19
+ /**
20
+ * Bundles `css.entry` into `css.outfile` (both relative to cwd).
21
+ * `onRead` is called for every file the bundler looks up, with its stamp taken just before the read
22
+ * (undefined for a missing file), also for the lookups of a run that then fails.
23
+ */
24
+ export declare function buildCss(cwd: string, css: ResolvedCss, onRead?: (file: string, stamp: string | undefined) => void): CssResult;
@@ -0,0 +1,47 @@
1
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { inlineImports } from "./css-imports.js";
4
+ /**
5
+ * A cheap fingerprint of a file as the filesystem reports it (mtime and size), or undefined when it does not exist.
6
+ * `--watch` compares the stamp taken when a file was read with a later one to see an edit that `fs.watchFile`
7
+ * missed, see `runVaultBuild`.
8
+ */
9
+ export function fileStamp(file) {
10
+ try {
11
+ const stats = statSync(file);
12
+ return `${String(stats.mtimeMs)}:${String(stats.size)}`;
13
+ }
14
+ catch (error) {
15
+ if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) {
16
+ return undefined;
17
+ }
18
+ throw error;
19
+ }
20
+ }
21
+ /**
22
+ * Bundles `css.entry` into `css.outfile` (both relative to cwd).
23
+ * `onRead` is called for every file the bundler looks up, with its stamp taken just before the read
24
+ * (undefined for a missing file), also for the lookups of a run that then fails.
25
+ */
26
+ export function buildCss(cwd, css, onRead) {
27
+ const entry = path.resolve(cwd, css.entry);
28
+ if (!existsSync(entry)) {
29
+ return { status: "no-entry" };
30
+ }
31
+ const result = inlineImports(entry, (file) => {
32
+ // Stamp first: an edit between the stamp and the read then looks newer than the stamp, which costs one
33
+ // extra sync, never a lost edit.
34
+ const stamp = fileStamp(file);
35
+ onRead?.(file, stamp);
36
+ return stamp === undefined ? undefined : readFileSync(file, "utf8");
37
+ });
38
+ const outfile = path.resolve(cwd, css.outfile);
39
+ mkdirSync(path.dirname(outfile), { recursive: true });
40
+ writeFileSync(outfile, result.css);
41
+ return {
42
+ status: "built",
43
+ files: result.files.length,
44
+ lines: result.css.split("\n").length,
45
+ inputs: [...new Set(result.files)],
46
+ };
47
+ }
@@ -0,0 +1,55 @@
1
+ import type { BuildOptions } from "esbuild";
2
+ import type { BuildConfig, BuildLoader } from "../config/types.js";
3
+ /**
4
+ * Always external: Obsidian provides them at runtime. `build.external` adds to this list.
5
+ * The CodeMirror packages must stay external or the plugin would load a second copy of the editor.
6
+ */
7
+ export declare const DEFAULT_EXTERNAL: readonly string[];
8
+ /**
9
+ * Obsidian reads `module.exports` as the plugin class. esbuild's cjs output of an ES default export
10
+ * puts it on `module.exports.default`, so the footer unwraps it.
11
+ */
12
+ export declare const CJS_FOOTER = "module.exports = module.exports.default || module.exports;";
13
+ /**
14
+ * Loaders every build starts with; `build.loader` entries merge over it. Two plugins' vault
15
+ * builds had `.css` as text, so an `import "x.css"` meant as a string does not fail with
16
+ * "No loader is configured for .css".
17
+ */
18
+ export declare const DEFAULT_LOADER: Readonly<Record<string, BuildLoader>>;
19
+ export interface ResolvedCss {
20
+ readonly entry: string;
21
+ readonly outfile: string;
22
+ }
23
+ /** The build section with every default filled in. Paths are still relative to the plugin root. */
24
+ export interface ResolvedBuild {
25
+ readonly entry: string;
26
+ readonly outfile: string;
27
+ readonly minify: boolean;
28
+ readonly target: string;
29
+ readonly external: readonly string[];
30
+ readonly loader: Readonly<Record<string, BuildLoader>>;
31
+ readonly css: ResolvedCss | false;
32
+ }
33
+ /** Fills the defaults (one plugin's release build) into the user's `build` section. */
34
+ export declare function resolveBuild(config: BuildConfig | undefined): ResolvedBuild;
35
+ export type BuildTarget = {
36
+ readonly kind: "release";
37
+ }
38
+ /** Dev vault: not minified, written to `<dir>/main.js`. */
39
+ | {
40
+ readonly kind: "vault";
41
+ readonly dir: string;
42
+ };
43
+ /**
44
+ * esbuild options for one build. Platform `browser`, format `cjs` and the footer are fixed on purpose:
45
+ * a plugin that runs on phones cannot use the Node build of its dependencies (see the bundle check).
46
+ * `absWorkingDir` makes module resolution start at the plugin, not at the kit.
47
+ */
48
+ export declare function toEsbuildOptions(build: ResolvedBuild, cwd: string, target: BuildTarget): BuildOptions;
49
+ export interface VaultDir {
50
+ readonly dir: string;
51
+ /** Where the folder came from, so the command can say it: a stray VAULT_PLUGIN is easy to forget. */
52
+ readonly source: "flag" | "env";
53
+ }
54
+ /** Where `opdk build --vault` writes: the flag, else `VAULT_PLUGIN`, else an error that says how to fix it. */
55
+ export declare function resolveVaultDir(flagDir: string | undefined, env: Readonly<Record<string, string | undefined>>, pluginId: string): VaultDir;
@@ -0,0 +1,70 @@
1
+ import path from "node:path";
2
+ /**
3
+ * Always external: Obsidian provides them at runtime. `build.external` adds to this list.
4
+ * The CodeMirror packages must stay external or the plugin would load a second copy of the editor.
5
+ */
6
+ export const DEFAULT_EXTERNAL = ["obsidian", "electron", "@codemirror/state", "@codemirror/view"];
7
+ /**
8
+ * Obsidian reads `module.exports` as the plugin class. esbuild's cjs output of an ES default export
9
+ * puts it on `module.exports.default`, so the footer unwraps it.
10
+ */
11
+ export const CJS_FOOTER = "module.exports = module.exports.default || module.exports;";
12
+ /**
13
+ * Loaders every build starts with; `build.loader` entries merge over it. Two plugins' vault
14
+ * builds had `.css` as text, so an `import "x.css"` meant as a string does not fail with
15
+ * "No loader is configured for .css".
16
+ */
17
+ export const DEFAULT_LOADER = { ".css": "text" };
18
+ /** Fills the defaults (one plugin's release build) into the user's `build` section. */
19
+ export function resolveBuild(config) {
20
+ const css = config?.css;
21
+ return {
22
+ entry: config?.entry ?? "src/main.ts",
23
+ outfile: config?.outfile ?? "main.js",
24
+ minify: config?.minify ?? true,
25
+ target: config?.target ?? "es2020",
26
+ external: [...new Set([...DEFAULT_EXTERNAL, ...(config?.external ?? [])])],
27
+ loader: { ...DEFAULT_LOADER, ...config?.loader },
28
+ css: css === false
29
+ ? false
30
+ : {
31
+ entry: css?.entry ?? "src/styles/main.css",
32
+ outfile: css?.outfile ?? "styles.css",
33
+ },
34
+ };
35
+ }
36
+ /**
37
+ * esbuild options for one build. Platform `browser`, format `cjs` and the footer are fixed on purpose:
38
+ * a plugin that runs on phones cannot use the Node build of its dependencies (see the bundle check).
39
+ * `absWorkingDir` makes module resolution start at the plugin, not at the kit.
40
+ */
41
+ export function toEsbuildOptions(build, cwd, target) {
42
+ const vault = target.kind === "vault";
43
+ return {
44
+ absWorkingDir: cwd,
45
+ entryPoints: [path.resolve(cwd, build.entry)],
46
+ bundle: true,
47
+ outfile: vault ? path.join(path.resolve(cwd, target.dir), "main.js") : path.resolve(cwd, build.outfile),
48
+ minify: vault ? false : build.minify,
49
+ platform: "browser",
50
+ format: "cjs",
51
+ target: build.target,
52
+ external: [...build.external],
53
+ loader: { ...build.loader },
54
+ footer: { js: CJS_FOOTER },
55
+ // The command prints esbuild's messages itself, through the injected stdout/stderr.
56
+ logLevel: "silent",
57
+ };
58
+ }
59
+ /** Where `opdk build --vault` writes: the flag, else `VAULT_PLUGIN`, else an error that says how to fix it. */
60
+ export function resolveVaultDir(flagDir, env, pluginId) {
61
+ if (flagDir !== undefined) {
62
+ return { dir: flagDir, source: "flag" };
63
+ }
64
+ const dir = env.VAULT_PLUGIN;
65
+ if (dir === undefined || dir === "") {
66
+ throw new Error("No dev vault plugin folder given. Pass it as `opdk build --vault <dir>` or set VAULT_PLUGIN to your plugin folder path and rerun. Example:\n" +
67
+ `VAULT_PLUGIN="/absolute/path/to/vault/.obsidian/plugins/${pluginId}" opdk build --vault`);
68
+ }
69
+ return { dir, source: "env" };
70
+ }
@@ -0,0 +1,5 @@
1
+ import type { CommandContext } from "../cli/types.js";
2
+ import type { Manifest } from "../config/types.js";
3
+ import { type ResolvedBuild } from "./options.js";
4
+ /** `opdk build`: CSS, then the bundle, then the Node-only check. Returns the exit code. */
5
+ export declare function runReleaseBuild(manifest: Manifest, build: ResolvedBuild, ctx: CommandContext): Promise<number>;
@@ -0,0 +1,34 @@
1
+ import { statSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { build as esbuildBuild } from "esbuild";
4
+ import { checkBundleFile } from "./bundle-file.js";
5
+ import { runCssStep } from "./css-step.js";
6
+ import { toEsbuildOptions } from "./options.js";
7
+ import { formatKib, isBuildFailure, printMessages } from "./report.js";
8
+ /** `opdk build`: CSS, then the bundle, then the Node-only check. Returns the exit code. */
9
+ export async function runReleaseBuild(manifest, build, ctx) {
10
+ const id = manifest.id;
11
+ if (build.css !== false) {
12
+ runCssStep(ctx.cwd, build.css, ctx);
13
+ }
14
+ ctx.reporter.info("build", `${id}: bundling ${build.entry}`);
15
+ const options = toEsbuildOptions(build, ctx.cwd, { kind: "release" });
16
+ try {
17
+ const result = await esbuildBuild(options);
18
+ await printMessages(result.warnings, "warning", ctx);
19
+ }
20
+ catch (error) {
21
+ if (!isBuildFailure(error)) {
22
+ throw error;
23
+ }
24
+ await printMessages(error.warnings, "warning", ctx);
25
+ await printMessages(error.errors, "error", ctx);
26
+ ctx.reporter.failure("build", `${id}: build failed with ${String(error.errors.length)} error(s).`, {
27
+ hint: "Fix them and rerun `opdk build`.",
28
+ });
29
+ return 1;
30
+ }
31
+ const outfile = path.resolve(ctx.cwd, build.outfile);
32
+ ctx.reporter.success("build", `${id}: ${build.outfile} ${formatKib(statSync(outfile).size)}`);
33
+ return checkBundleFile(outfile, manifest, ctx);
34
+ }
@@ -0,0 +1,7 @@
1
+ import { type BuildFailure, type Message } from "esbuild";
2
+ import type { CommandContext } from "../cli/types.js";
3
+ /** Narrows what esbuild throws when a build has errors. */
4
+ export declare function isBuildFailure(error: unknown): error is BuildFailure;
5
+ /** Prints esbuild errors or warnings in esbuild's own layout to stderr, coloured when the reporter is. */
6
+ export declare function printMessages(messages: readonly Message[], kind: "error" | "warning", ctx: Pick<CommandContext, "reporter">): Promise<void>;
7
+ export declare function formatKib(bytes: number): string;
@@ -0,0 +1,16 @@
1
+ import { formatMessages } from "esbuild";
2
+ /** Narrows what esbuild throws when a build has errors. */
3
+ export function isBuildFailure(error) {
4
+ return error instanceof Error && "errors" in error && Array.isArray(error.errors);
5
+ }
6
+ /** Prints esbuild errors or warnings in esbuild's own layout to stderr, coloured when the reporter is. */
7
+ export async function printMessages(messages, kind, ctx) {
8
+ if (messages.length === 0) {
9
+ return;
10
+ }
11
+ const formatted = await formatMessages([...messages], { kind, color: ctx.reporter.colorStderr, terminalWidth: 100 });
12
+ ctx.reporter.rawStderr(formatted.join(""));
13
+ }
14
+ export function formatKib(bytes) {
15
+ return `${(bytes / 1024).toFixed(1)} KiB`;
16
+ }
@@ -0,0 +1,26 @@
1
+ import type { Reporter } from "../cli/reporter.js";
2
+ import type { Manifest } from "../config/types.js";
3
+ import { type ResolvedBuild } from "./options.js";
4
+ export interface VaultBuildOptions {
5
+ readonly cwd: string;
6
+ readonly manifest: Manifest;
7
+ readonly build: ResolvedBuild;
8
+ /** The plugin folder inside the dev vault. */
9
+ readonly dir: string;
10
+ readonly watch: boolean;
11
+ /** Write into a folder that holds another plugin. Off by default, see `checkVaultTarget`. */
12
+ readonly force?: boolean;
13
+ readonly reporter: Reporter;
14
+ /** Required in watch mode: the build runs until this aborts (SIGINT in the CLI). */
15
+ readonly signal?: AbortSignal;
16
+ /** Called after every asset sync (CSS rebuild and copy). Lets tests await a rebuild without sleeping. */
17
+ readonly onAssetsSynced?: () => void;
18
+ }
19
+ /** `opdk build --vault`: unminified bundle plus styles.css and manifest.json in the dev vault. Returns the exit code. */
20
+ export declare function runVaultBuild(options: VaultBuildOptions): Promise<number>;
21
+ /**
22
+ * Refuses to write into a folder that holds a different plugin. `VAULT_PLUGIN` stays exported in a shell,
23
+ * so a build of plugin B would silently overwrite plugin A's main.js and manifest.json in the dev vault.
24
+ * A folder without a readable manifest is treated as fresh.
25
+ */
26
+ export declare function checkVaultTarget(vaultDir: string, pluginId: string): string | undefined;