obsidian-integration-testing 4.3.0 → 5.0.0

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 (62) hide show
  1. package/README.md +51 -54
  2. package/dist/lib/cjs/global-setup-core.cjs +39 -12
  3. package/dist/lib/cjs/global-setup-core.d.cts +1 -1
  4. package/dist/lib/cjs/index.cjs +1 -4
  5. package/dist/lib/cjs/index.d.cts +2 -3
  6. package/dist/lib/cjs/kill-process-tree.cjs +57 -0
  7. package/dist/lib/cjs/kill-process-tree.d.cts +16 -0
  8. package/dist/lib/cjs/library.cjs +1 -1
  9. package/dist/lib/cjs/obsidian-config.cjs +11 -85
  10. package/dist/lib/cjs/obsidian-config.d.cts +12 -72
  11. package/dist/lib/cjs/obsidian-installer.cjs +180 -0
  12. package/dist/lib/cjs/obsidian-installer.d.cts +45 -0
  13. package/dist/lib/cjs/obsidian-instance.cjs +100 -0
  14. package/dist/lib/cjs/obsidian-instance.d.cts +55 -0
  15. package/dist/lib/cjs/obsidian-version-switch.cjs +105 -0
  16. package/dist/lib/cjs/obsidian-version-switch.d.cts +63 -0
  17. package/dist/lib/cjs/obsidian-version.cjs +85 -0
  18. package/dist/lib/cjs/obsidian-version.d.cts +111 -0
  19. package/dist/lib/cjs/setup-lock.cjs +158 -0
  20. package/dist/lib/cjs/setup-lock.d.cts +55 -0
  21. package/dist/lib/cjs/transport-desktop-cdp.cjs +121 -7
  22. package/dist/lib/cjs/transport-desktop-cdp.d.cts +75 -14
  23. package/dist/lib/cjs/transport-factory.cjs +63 -32
  24. package/dist/lib/cjs/transport-options.cjs +1 -1
  25. package/dist/lib/cjs/transport-options.d.cts +37 -14
  26. package/dist/lib/cjs/transport.cjs +1 -1
  27. package/dist/lib/cjs/transport.d.cts +1 -1
  28. package/dist/lib/cjs/vitest/global-setup.cjs +2 -2
  29. package/dist/lib/cjs/vitest/typings.d.cts +1 -1
  30. package/dist/lib/esm/global-setup-core.d.mts +1 -1
  31. package/dist/lib/esm/global-setup-core.mjs +39 -12
  32. package/dist/lib/esm/index.d.mts +2 -3
  33. package/dist/lib/esm/index.mjs +1 -3
  34. package/dist/lib/esm/kill-process-tree.d.mts +16 -0
  35. package/dist/lib/esm/kill-process-tree.mjs +23 -0
  36. package/dist/lib/esm/library.mjs +1 -1
  37. package/dist/lib/esm/obsidian-config.d.mts +12 -72
  38. package/dist/lib/esm/obsidian-config.mjs +10 -78
  39. package/dist/lib/esm/obsidian-installer.d.mts +45 -0
  40. package/dist/lib/esm/obsidian-installer.mjs +158 -0
  41. package/dist/lib/esm/obsidian-instance.d.mts +55 -0
  42. package/dist/lib/esm/obsidian-instance.mjs +75 -0
  43. package/dist/lib/esm/obsidian-version-switch.d.mts +63 -0
  44. package/dist/lib/esm/obsidian-version-switch.mjs +89 -0
  45. package/dist/lib/esm/obsidian-version.d.mts +111 -0
  46. package/dist/lib/esm/obsidian-version.mjs +55 -0
  47. package/dist/lib/esm/setup-lock.d.mts +55 -0
  48. package/dist/lib/esm/setup-lock.mjs +132 -0
  49. package/dist/lib/esm/transport-desktop-cdp.d.mts +75 -14
  50. package/dist/lib/esm/transport-desktop-cdp.mjs +125 -7
  51. package/dist/lib/esm/transport-factory.mjs +68 -28
  52. package/dist/lib/esm/transport-options.d.mts +37 -14
  53. package/dist/lib/esm/transport.d.mts +1 -1
  54. package/dist/lib/esm/vitest/global-setup.mjs +2 -2
  55. package/dist/lib/esm/vitest/typings.d.mts +1 -1
  56. package/dist/obsidian-integration-testing-5.0.0.tgz +0 -0
  57. package/package.json +16 -15
  58. package/dist/lib/cjs/transport-desktop-cli.cjs +0 -540
  59. package/dist/lib/cjs/transport-desktop-cli.d.cts +0 -154
  60. package/dist/lib/esm/transport-desktop-cli.d.mts +0 -154
  61. package/dist/lib/esm/transport-desktop-cli.mjs +0 -520
  62. package/dist/obsidian-integration-testing-4.3.0.tgz +0 -0
@@ -1,154 +0,0 @@
1
- /**
2
- * @file
3
- *
4
- * Desktop CLI transport — evaluates expressions via `obsidian eval` and manages
5
- * vaults via Electron IPC.
6
- */
7
- import type { ObsidianTransport, TransportEvalOptions } from './transport.cjs';
8
- interface InvokeAndWriteResultParams {
9
- evaluate(): Promise<unknown>;
10
- readonly resultPath: string;
11
- serializeError(error: unknown): string;
12
- }
13
- /**
14
- * Transport that communicates with Desktop Obsidian via the `obsidian eval` CLI command
15
- * and manages vaults via Electron IPC.
16
- */
17
- export declare class DesktopCliTransport implements ObsidianTransport {
18
- /**
19
- * Indicates whether this transport is for a mobile platform. Always `false` for this transport.
20
- */
21
- readonly isMobile = false;
22
- /**
23
- * Evaluates a JavaScript expression inside Obsidian via `obsidian eval`.
24
- *
25
- * Writes the expression to a temporary `.cjs` file and executes a tiny
26
- * `require().invoke()` call via the CLI. The result is written to a
27
- * `.result.json` file by the script, avoiding CLI stdout size limits
28
- * and IPC buffer issues.
29
- *
30
- * Handles auto-start: if Obsidian is not running, launches it via URI protocol
31
- * and retries until it becomes available.
32
- *
33
- * @param expression - The JavaScript expression to evaluate.
34
- * @param options - Evaluation options.
35
- * @returns The normalized result string (transport-specific prefixes stripped).
36
- */
37
- evaluate(expression: string, options: TransportEvalOptions): Promise<string>;
38
- /**
39
- * Runs CLI-specific preflight checks.
40
- *
41
- * Verifies that the vault is registered, CLI is enabled in Obsidian settings,
42
- * and the `obsidian` CLI binary is available in PATH. If the vault is registered
43
- * but not open, opens it via URI protocol and polls until it is ready.
44
- *
45
- * @param vaultPath - The absolute path to the vault folder.
46
- */
47
- preflightCheck(vaultPath: string): Promise<void>;
48
- /**
49
- * Registers a vault in the running Obsidian instance via Electron IPC.
50
- *
51
- * Uses `vault-open` IPC to register and open the vault, then polls until
52
- * the vault's CLI is ready and `getBasePath()` matches `vaultPath`.
53
- *
54
- * @param vaultPath - The absolute path to the vault folder.
55
- */
56
- registerVault(vaultPath: string): Promise<void>;
57
- /**
58
- * Unregisters a vault from the running Obsidian instance.
59
- *
60
- * Schedules the vault window to close, waits, then removes the vault
61
- * from the registry via `vault-remove` IPC.
62
- *
63
- * @param vaultPath - The absolute path to the vault folder.
64
- */
65
- unregisterVault(vaultPath: string): Promise<void>;
66
- /**
67
- * Checks whether the Obsidian CLI binary is available in the system PATH.
68
- */
69
- private assertCliAvailable;
70
- /**
71
- * Dismisses the "Do you trust the author of this vault?" dialog if present.
72
- *
73
- * Clicks the "Trust author and enable plugins" button (`.mod-cta`) inside any
74
- * modal whose text includes "Do you trust the author". Acts as a safety net
75
- * for both registration paths:
76
- *
77
- * - First vault registered via config file (no prior `enable-plugin-<id>` entry).
78
- * - Subsequent vault registered while another vault is already open. The
79
- * `enable-plugin-<newVaultId>` write happens in the existing vault's renderer,
80
- * but the new vault's renderer may read `localStorage` before that cross-renderer
81
- * write becomes visible (race observed in Obsidian 1.13.0).
82
- *
83
- * @param vaultPath - The vault path to evaluate in.
84
- */
85
- private dismissTrustDialog;
86
- /**
87
- * Sets `enable-plugin-<vaultId>` in Obsidian's localStorage to prevent
88
- * the "Do you trust the author of this vault?" dialog from appearing
89
- * when a vault with community plugins is opened for the first time.
90
- *
91
- * Must be called after the `vault-open` IPC (so the vault ID exists in
92
- * `obsidian.json`) and before the new vault window finishes loading.
93
- *
94
- * @param vaultPath - The absolute path to the vault folder.
95
- * @param evalTargetVaultPath - The vault path to use as eval target (an existing, loaded vault).
96
- * localStorage is shared across all Obsidian windows (same Electron origin), so the
97
- * `localStorage.setItem` call can run in any loaded vault window.
98
- */
99
- private enablePluginsInLocalStorage;
100
- /**
101
- * Launches Obsidian binary and retries the eval until it responds.
102
- *
103
- * @param command - The CLI command array to retry.
104
- * @param cwd - The working directory.
105
- */
106
- private ensureObsidianRunningAndRetry;
107
- /**
108
- * Returns the path of an already-open vault to use as an `obsidian eval`
109
- * target, or `undefined` if there is none.
110
- *
111
- * The `open` flag in `obsidian.json` is only trustworthy while Obsidian is
112
- * running — a killed or crashed process never resets it, leaving the user's
113
- * last-session vault marked open. Acting on that stale flag would target the
114
- * (possibly heavy) last-session vault and cause auto-start to reopen it.
115
- * When Obsidian is not running we therefore report no open vault, so callers
116
- * fall back to the direct-config path that opens only the temp vault.
117
- *
118
- * @returns The absolute path to an open vault, or `undefined`.
119
- */
120
- private getOpenEvalTargetVaultPath;
121
- /**
122
- * Kills the running Obsidian process (if any) and waits for it to exit.
123
- */
124
- private killObsidian;
125
- /**
126
- * Polls until the vault is ready and responding to eval calls.
127
- *
128
- * Each `obsidian eval` in the loop is given a per-call timeout. The overall
129
- * deadline is only re-checked between awaits, so without it a single hung
130
- * eval (e.g. a vault window that opened but never finished loading) would
131
- * block past the deadline forever instead of failing and retrying.
132
- *
133
- * @param vaultPath - The absolute path to the vault folder.
134
- */
135
- private pollVaultReady;
136
- /**
137
- * Restarts Obsidian by killing the running process and relaunching it.
138
- *
139
- * Used when a config change (like enabling CLI) requires a restart to take effect.
140
- *
141
- * @param vaultPath - The vault path to use for polling after restart.
142
- */
143
- private restartObsidian;
144
- }
145
- /**
146
- * Evaluates an expression, writes the result to a JSON file.
147
- *
148
- * Serialized via `toString()` and executed inside the Obsidian process.
149
- * Must NOT reference any outer scope.
150
- *
151
- * @param params - The invocation parameters.
152
- */
153
- export declare function invokeAndWriteResult(params: InvokeAndWriteResultParams): Promise<void>;
154
- export {};
@@ -1,154 +0,0 @@
1
- /**
2
- * @file
3
- *
4
- * Desktop CLI transport — evaluates expressions via `obsidian eval` and manages
5
- * vaults via Electron IPC.
6
- */
7
- import type { ObsidianTransport, TransportEvalOptions } from './transport.mjs';
8
- interface InvokeAndWriteResultParams {
9
- evaluate(): Promise<unknown>;
10
- readonly resultPath: string;
11
- serializeError(error: unknown): string;
12
- }
13
- /**
14
- * Transport that communicates with Desktop Obsidian via the `obsidian eval` CLI command
15
- * and manages vaults via Electron IPC.
16
- */
17
- export declare class DesktopCliTransport implements ObsidianTransport {
18
- /**
19
- * Indicates whether this transport is for a mobile platform. Always `false` for this transport.
20
- */
21
- readonly isMobile = false;
22
- /**
23
- * Evaluates a JavaScript expression inside Obsidian via `obsidian eval`.
24
- *
25
- * Writes the expression to a temporary `.cjs` file and executes a tiny
26
- * `require().invoke()` call via the CLI. The result is written to a
27
- * `.result.json` file by the script, avoiding CLI stdout size limits
28
- * and IPC buffer issues.
29
- *
30
- * Handles auto-start: if Obsidian is not running, launches it via URI protocol
31
- * and retries until it becomes available.
32
- *
33
- * @param expression - The JavaScript expression to evaluate.
34
- * @param options - Evaluation options.
35
- * @returns The normalized result string (transport-specific prefixes stripped).
36
- */
37
- evaluate(expression: string, options: TransportEvalOptions): Promise<string>;
38
- /**
39
- * Runs CLI-specific preflight checks.
40
- *
41
- * Verifies that the vault is registered, CLI is enabled in Obsidian settings,
42
- * and the `obsidian` CLI binary is available in PATH. If the vault is registered
43
- * but not open, opens it via URI protocol and polls until it is ready.
44
- *
45
- * @param vaultPath - The absolute path to the vault folder.
46
- */
47
- preflightCheck(vaultPath: string): Promise<void>;
48
- /**
49
- * Registers a vault in the running Obsidian instance via Electron IPC.
50
- *
51
- * Uses `vault-open` IPC to register and open the vault, then polls until
52
- * the vault's CLI is ready and `getBasePath()` matches `vaultPath`.
53
- *
54
- * @param vaultPath - The absolute path to the vault folder.
55
- */
56
- registerVault(vaultPath: string): Promise<void>;
57
- /**
58
- * Unregisters a vault from the running Obsidian instance.
59
- *
60
- * Schedules the vault window to close, waits, then removes the vault
61
- * from the registry via `vault-remove` IPC.
62
- *
63
- * @param vaultPath - The absolute path to the vault folder.
64
- */
65
- unregisterVault(vaultPath: string): Promise<void>;
66
- /**
67
- * Checks whether the Obsidian CLI binary is available in the system PATH.
68
- */
69
- private assertCliAvailable;
70
- /**
71
- * Dismisses the "Do you trust the author of this vault?" dialog if present.
72
- *
73
- * Clicks the "Trust author and enable plugins" button (`.mod-cta`) inside any
74
- * modal whose text includes "Do you trust the author". Acts as a safety net
75
- * for both registration paths:
76
- *
77
- * - First vault registered via config file (no prior `enable-plugin-<id>` entry).
78
- * - Subsequent vault registered while another vault is already open. The
79
- * `enable-plugin-<newVaultId>` write happens in the existing vault's renderer,
80
- * but the new vault's renderer may read `localStorage` before that cross-renderer
81
- * write becomes visible (race observed in Obsidian 1.13.0).
82
- *
83
- * @param vaultPath - The vault path to evaluate in.
84
- */
85
- private dismissTrustDialog;
86
- /**
87
- * Sets `enable-plugin-<vaultId>` in Obsidian's localStorage to prevent
88
- * the "Do you trust the author of this vault?" dialog from appearing
89
- * when a vault with community plugins is opened for the first time.
90
- *
91
- * Must be called after the `vault-open` IPC (so the vault ID exists in
92
- * `obsidian.json`) and before the new vault window finishes loading.
93
- *
94
- * @param vaultPath - The absolute path to the vault folder.
95
- * @param evalTargetVaultPath - The vault path to use as eval target (an existing, loaded vault).
96
- * localStorage is shared across all Obsidian windows (same Electron origin), so the
97
- * `localStorage.setItem` call can run in any loaded vault window.
98
- */
99
- private enablePluginsInLocalStorage;
100
- /**
101
- * Launches Obsidian binary and retries the eval until it responds.
102
- *
103
- * @param command - The CLI command array to retry.
104
- * @param cwd - The working directory.
105
- */
106
- private ensureObsidianRunningAndRetry;
107
- /**
108
- * Returns the path of an already-open vault to use as an `obsidian eval`
109
- * target, or `undefined` if there is none.
110
- *
111
- * The `open` flag in `obsidian.json` is only trustworthy while Obsidian is
112
- * running — a killed or crashed process never resets it, leaving the user's
113
- * last-session vault marked open. Acting on that stale flag would target the
114
- * (possibly heavy) last-session vault and cause auto-start to reopen it.
115
- * When Obsidian is not running we therefore report no open vault, so callers
116
- * fall back to the direct-config path that opens only the temp vault.
117
- *
118
- * @returns The absolute path to an open vault, or `undefined`.
119
- */
120
- private getOpenEvalTargetVaultPath;
121
- /**
122
- * Kills the running Obsidian process (if any) and waits for it to exit.
123
- */
124
- private killObsidian;
125
- /**
126
- * Polls until the vault is ready and responding to eval calls.
127
- *
128
- * Each `obsidian eval` in the loop is given a per-call timeout. The overall
129
- * deadline is only re-checked between awaits, so without it a single hung
130
- * eval (e.g. a vault window that opened but never finished loading) would
131
- * block past the deadline forever instead of failing and retrying.
132
- *
133
- * @param vaultPath - The absolute path to the vault folder.
134
- */
135
- private pollVaultReady;
136
- /**
137
- * Restarts Obsidian by killing the running process and relaunching it.
138
- *
139
- * Used when a config change (like enabling CLI) requires a restart to take effect.
140
- *
141
- * @param vaultPath - The vault path to use for polling after restart.
142
- */
143
- private restartObsidian;
144
- }
145
- /**
146
- * Evaluates an expression, writes the result to a JSON file.
147
- *
148
- * Serialized via `toString()` and executed inside the Obsidian process.
149
- * Must NOT reference any outer scope.
150
- *
151
- * @param params - The invocation parameters.
152
- */
153
- export declare function invokeAndWriteResult(params: InvokeAndWriteResultParams): Promise<void>;
154
- export {};