obsidian-dev-utils 87.0.2 → 87.0.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 (71) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/demo-vault-helper/main.js +232 -0
  3. package/dist/demo-vault-helper/manifest.json +9 -0
  4. package/dist/dev/main.js +37464 -0
  5. package/dist/dev/manifest.json +9 -0
  6. package/dist/lib/cjs/__merged.cjs +13 -1
  7. package/dist/lib/cjs/__merged.d.cts +4 -2
  8. package/dist/lib/cjs/generated-during-build.cjs +1 -1
  9. package/dist/lib/cjs/obsidian/code-block-reg-exp.cjs +138 -0
  10. package/dist/lib/cjs/obsidian/code-block-reg-exp.d.cts +33 -0
  11. package/dist/lib/cjs/obsidian/command-handlers/open-demo-vault-command-handler.cjs +13 -6
  12. package/dist/lib/cjs/obsidian/command-handlers/open-demo-vault-command-handler.d.cts +13 -5
  13. package/dist/lib/cjs/obsidian/community-plugins.cjs +25 -1
  14. package/dist/lib/cjs/obsidian/community-plugins.d.cts +28 -0
  15. package/dist/lib/cjs/obsidian/demo-vault-helper.cjs +159 -0
  16. package/dist/lib/cjs/obsidian/demo-vault-helper.d.cts +40 -0
  17. package/dist/lib/cjs/obsidian/desktop-demo-vault-opener.cjs +17 -13
  18. package/dist/lib/cjs/obsidian/desktop-demo-vault-opener.d.cts +13 -5
  19. package/dist/lib/cjs/obsidian/index.cjs +7 -1
  20. package/dist/lib/cjs/obsidian/index.d.cts +2 -0
  21. package/dist/lib/cjs/obsidian/markdown-code-block-processor.cjs +12 -10
  22. package/dist/lib/cjs/obsidian/plugin/obsidian-plugin-repo-paths.cjs +2 -1
  23. package/dist/lib/cjs/obsidian/plugin/obsidian-plugin-repo-paths.d.cts +2 -0
  24. package/dist/lib/cjs/reg-exp.cjs +11 -1
  25. package/dist/lib/cjs/reg-exp.d.cts +34 -0
  26. package/dist/lib/cjs/script-utils/demo-vault-coverage.cjs +289 -0
  27. package/dist/lib/cjs/script-utils/demo-vault-coverage.d.cts +264 -0
  28. package/dist/lib/cjs/script-utils/demo-vault.cjs +36 -3
  29. package/dist/lib/cjs/script-utils/demo-vault.d.cts +5 -5
  30. package/dist/lib/cjs/script-utils/index.cjs +4 -1
  31. package/dist/lib/cjs/script-utils/index.d.cts +1 -0
  32. package/dist/lib/cjs/script-utils/linters/eslint-config.cjs +14 -1
  33. package/dist/lib/cjs/script-utils/linters/eslint-rules/require-method-template.cjs +4 -5
  34. package/dist/lib/cjs/script-utils/obsidian-dev-utils-repo-paths.cjs +2 -1
  35. package/dist/lib/cjs/script-utils/obsidian-dev-utils-repo-paths.d.cts +2 -0
  36. package/dist/lib/cjs/script-utils/version.cjs +2 -2
  37. package/dist/lib/esm/__merged.d.mts +4 -2
  38. package/dist/lib/esm/__merged.mjs +11 -1
  39. package/dist/lib/esm/generated-during-build.mjs +1 -1
  40. package/dist/lib/esm/obsidian/code-block-reg-exp.d.mts +33 -0
  41. package/dist/lib/esm/obsidian/code-block-reg-exp.mjs +30 -0
  42. package/dist/lib/esm/obsidian/command-handlers/open-demo-vault-command-handler.d.mts +13 -5
  43. package/dist/lib/esm/obsidian/command-handlers/open-demo-vault-command-handler.mjs +13 -6
  44. package/dist/lib/esm/obsidian/community-plugins.d.mts +28 -0
  45. package/dist/lib/esm/obsidian/community-plugins.mjs +24 -1
  46. package/dist/lib/esm/obsidian/demo-vault-helper.d.mts +40 -0
  47. package/dist/lib/esm/obsidian/demo-vault-helper.mjs +56 -0
  48. package/dist/lib/esm/obsidian/desktop-demo-vault-opener.d.mts +13 -5
  49. package/dist/lib/esm/obsidian/desktop-demo-vault-opener.mjs +17 -13
  50. package/dist/lib/esm/obsidian/index.d.mts +2 -0
  51. package/dist/lib/esm/obsidian/index.mjs +5 -1
  52. package/dist/lib/esm/obsidian/markdown-code-block-processor.mjs +15 -10
  53. package/dist/lib/esm/obsidian/plugin/obsidian-plugin-repo-paths.d.mts +2 -0
  54. package/dist/lib/esm/obsidian/plugin/obsidian-plugin-repo-paths.mjs +2 -1
  55. package/dist/lib/esm/reg-exp.d.mts +34 -0
  56. package/dist/lib/esm/reg-exp.mjs +11 -2
  57. package/dist/lib/esm/script-utils/demo-vault-coverage.d.mts +264 -0
  58. package/dist/lib/esm/script-utils/demo-vault-coverage.mjs +190 -0
  59. package/dist/lib/esm/script-utils/demo-vault.d.mts +5 -5
  60. package/dist/lib/esm/script-utils/demo-vault.mjs +31 -5
  61. package/dist/lib/esm/script-utils/index.d.mts +1 -0
  62. package/dist/lib/esm/script-utils/index.mjs +3 -1
  63. package/dist/lib/esm/script-utils/linters/eslint-config.mjs +14 -1
  64. package/dist/lib/esm/script-utils/linters/eslint-rules/require-method-template.mjs +4 -5
  65. package/dist/lib/esm/script-utils/obsidian-dev-utils-repo-paths.d.mts +2 -0
  66. package/dist/lib/esm/script-utils/obsidian-dev-utils-repo-paths.mjs +2 -1
  67. package/dist/lib/esm/script-utils/version.mjs +2 -2
  68. package/obsidian/code-block-reg-exp/package.json +6 -0
  69. package/obsidian/demo-vault-helper/package.json +6 -0
  70. package/package.json +6 -5
  71. package/script-utils/demo-vault-coverage/package.json +6 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 87.0.3
4
+
5
+ - fix(reg-exp): prevent code-block scan from freezing on unterminated fences
6
+ - chore: update libs
7
+ - test: demo vault
8
+ - feat: universal demo-vault-helper bootstrap plugin
9
+
3
10
  ## 87.0.2
4
11
 
5
12
  - fix: exclude nested node_modules from markdown lint/link-check globs
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // demo-vault-helper/main.ts
21
+ var main_exports = {};
22
+ __export(main_exports, {
23
+ default: () => DemoVaultHelperPlugin
24
+ });
25
+ module.exports = __toCommonJS(main_exports);
26
+ var import_obsidian2 = require("obsidian");
27
+
28
+ // src/obsidian/community-plugins.ts
29
+ var import_obsidian = require("obsidian");
30
+
31
+ // src/function.ts
32
+ function noop() {
33
+ }
34
+ var noopAsyncSingletonPromise = Promise.resolve();
35
+
36
+ // src/value-wrapper.ts
37
+ var ValueWrapper = class _ValueWrapper {
38
+ /**
39
+ * Gets the wrapped value.
40
+ *
41
+ * @returns The wrapped value.
42
+ * @throws An {@link Error} if the value has not been set.
43
+ */
44
+ get value() {
45
+ if (!this.hasValue) {
46
+ throw new Error("Value is not set");
47
+ }
48
+ return this._value;
49
+ }
50
+ /**
51
+ * Sets the wrapped value.
52
+ *
53
+ * @param value - The value to wrap.
54
+ */
55
+ set value(value) {
56
+ this._value = value;
57
+ this.hasValue = true;
58
+ }
59
+ _value = null;
60
+ hasValue = false;
61
+ /**
62
+ * Creates a new value wrapper. Use {@link ValueWrapper.of} or {@link ValueWrapper.unset} instead.
63
+ */
64
+ constructor() {
65
+ noop();
66
+ }
67
+ /**
68
+ * Make wrapper from the value.
69
+ *
70
+ * @typeParam T - Type of the value to wrap.
71
+ * @param value - The value to wrap.
72
+ * @returns The wrapper.
73
+ */
74
+ static of(value) {
75
+ const wrapper = new _ValueWrapper();
76
+ wrapper.value = value;
77
+ return wrapper;
78
+ }
79
+ /**
80
+ * Make the wrapper with unset value.
81
+ *
82
+ * @typeParam T - Type of the value to wrap.
83
+ * @returns The wrapper.
84
+ */
85
+ static unset() {
86
+ return new _ValueWrapper();
87
+ }
88
+ };
89
+
90
+ // src/obsidian-dev-utils-state.ts
91
+ function getObsidianDevUtilsState(key, defaultValue) {
92
+ const wrapper = globalThis;
93
+ wrapper.__obsidianDevUtils ??= {};
94
+ return wrapper.__obsidianDevUtils[key] ??= ValueWrapper.of(defaultValue);
95
+ }
96
+
97
+ // src/obsidian/community-plugins.ts
98
+ var COMMUNITY_PLUGINS_STATE_KEY = "communityPluginEntriesPromise";
99
+ var COMMUNITY_PLUGINS_URL = "https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-plugins.json";
100
+ var DATA_JSON_INDENT = 2;
101
+ async function configureCommunityPlugin(params) {
102
+ const { app, settings } = params;
103
+ const pluginId = await resolveCommunityPluginId(params);
104
+ const dataPath = `${app.vault.configDir}/plugins/${pluginId}/data.json`;
105
+ let data = {};
106
+ if (await app.vault.adapter.exists(dataPath)) {
107
+ const parsed = JSON.parse(await app.vault.adapter.read(dataPath));
108
+ if (parsed !== null && typeof parsed === "object") {
109
+ data = parsed;
110
+ }
111
+ }
112
+ const serializedBefore = JSON.stringify(data);
113
+ Object.assign(data, settings);
114
+ if (JSON.stringify(data) === serializedBefore) {
115
+ return false;
116
+ }
117
+ const serialized = String(JSON.stringify(data, null, DATA_JSON_INDENT));
118
+ await app.vault.adapter.write(dataPath, `${serialized}
119
+ `);
120
+ return true;
121
+ }
122
+ async function disableCommunityPlugin(params) {
123
+ const { app } = params;
124
+ const pluginId = await resolveCommunityPluginId(params);
125
+ if (!app.plugins.enabledPlugins.has(pluginId)) {
126
+ return;
127
+ }
128
+ await app.plugins.disablePluginAndSave(pluginId);
129
+ }
130
+ async function enableCommunityPlugin(params) {
131
+ const { app } = params;
132
+ const pluginId = await resolveCommunityPluginId(params);
133
+ if (app.plugins.enabledPlugins.has(pluginId)) {
134
+ return;
135
+ }
136
+ await app.plugins.enablePluginAndSave(pluginId);
137
+ }
138
+ async function getCommunityPluginRepo(pluginId) {
139
+ const entries = await getCommunityPluginEntries();
140
+ const entry = entries.find((candidate) => candidate.id === pluginId);
141
+ return entry?.repo ?? null;
142
+ }
143
+ async function getLatestReleaseVersion(repo) {
144
+ const response = await (0, import_obsidian.requestUrl)(`https://api.github.com/repos/${repo}/releases/latest`);
145
+ const release = response.json;
146
+ return release.tag_name;
147
+ }
148
+ async function installCommunityPlugin(params) {
149
+ const { app } = params;
150
+ const pluginId = await resolveCommunityPluginId(params);
151
+ if (app.plugins.manifests[pluginId]) {
152
+ return;
153
+ }
154
+ const repo = await getCommunityPluginRepo(pluginId);
155
+ if (!repo) {
156
+ throw new Error(`Plugin '${pluginId}' was not found in the Obsidian community plugins registry.`);
157
+ }
158
+ const version = await getLatestReleaseVersion(repo);
159
+ const manifest = await getPluginManifest(repo, version);
160
+ await app.plugins.installPlugin(repo, version, manifest);
161
+ }
162
+ async function fetchCommunityPluginEntries() {
163
+ const response = await (0, import_obsidian.requestUrl)(COMMUNITY_PLUGINS_URL);
164
+ return response.json;
165
+ }
166
+ async function getCommunityPluginEntries() {
167
+ const cache = getObsidianDevUtilsState(COMMUNITY_PLUGINS_STATE_KEY, null);
168
+ cache.value ??= fetchCommunityPluginEntries();
169
+ try {
170
+ return await cache.value;
171
+ } catch (error) {
172
+ cache.value = null;
173
+ throw error;
174
+ }
175
+ }
176
+ async function getPluginManifest(repo, version) {
177
+ const response = await (0, import_obsidian.requestUrl)(`https://github.com/${repo}/releases/download/${version}/manifest.json`);
178
+ return response.json;
179
+ }
180
+ async function resolveCommunityPluginId(ref) {
181
+ if ("pluginId" in ref) {
182
+ return ref.pluginId;
183
+ }
184
+ const entries = await getCommunityPluginEntries();
185
+ const entry = entries.find((candidate) => candidate.name === ref.pluginName);
186
+ if (!entry) {
187
+ throw new Error(`Plugin named '${ref.pluginName}' was not found in the Obsidian community plugins registry.`);
188
+ }
189
+ return entry.id;
190
+ }
191
+
192
+ // src/obsidian/demo-vault-helper.ts
193
+ var CODE_SCRIPT_TOOLKIT_PLUGIN_ID = "fix-require-modules";
194
+ var CODE_SCRIPT_TOOLKIT_MODULES_ROOT = "_assets/CodeScriptToolkit";
195
+ var CODE_SCRIPT_TOOLKIT_SETTINGS = {
196
+ invocableScriptsFolder: "Invocables",
197
+ modulesRoot: CODE_SCRIPT_TOOLKIT_MODULES_ROOT,
198
+ shouldHandleProtocolUrls: true,
199
+ startupScriptPath: "startup.ts"
200
+ };
201
+ async function bootstrapDemoVault(params) {
202
+ const { app } = params;
203
+ await installCommunityPlugin({ app, pluginId: CODE_SCRIPT_TOOLKIT_PLUGIN_ID });
204
+ const didSettingsChange = await configureCommunityPlugin({
205
+ app,
206
+ pluginId: CODE_SCRIPT_TOOLKIT_PLUGIN_ID,
207
+ settings: CODE_SCRIPT_TOOLKIT_SETTINGS
208
+ });
209
+ if (!app.plugins.enabledPlugins.has(CODE_SCRIPT_TOOLKIT_PLUGIN_ID)) {
210
+ await enableCommunityPlugin({ app, pluginId: CODE_SCRIPT_TOOLKIT_PLUGIN_ID });
211
+ } else if (didSettingsChange) {
212
+ await disableCommunityPlugin({ app, pluginId: CODE_SCRIPT_TOOLKIT_PLUGIN_ID });
213
+ await enableCommunityPlugin({ app, pluginId: CODE_SCRIPT_TOOLKIT_PLUGIN_ID });
214
+ }
215
+ }
216
+
217
+ // demo-vault-helper/main.ts
218
+ var DemoVaultHelperPlugin = class extends import_obsidian2.Plugin {
219
+ onload() {
220
+ this.app.workspace.onLayoutReady(() => {
221
+ void this.bootstrap();
222
+ });
223
+ }
224
+ async bootstrap() {
225
+ try {
226
+ await bootstrapDemoVault({ app: this.app });
227
+ } catch (error) {
228
+ new import_obsidian2.Notice(`Demo Vault Helper failed to bootstrap: ${String(error)}`);
229
+ console.error(error);
230
+ }
231
+ }
232
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "author": "mnaoumov",
3
+ "description": "Bootstraps a demo vault: installs, configures, and enables CodeScript Toolkit so the demo notes' code-buttons work with no manual setup.",
4
+ "id": "demo-vault-helper",
5
+ "isDesktopOnly": true,
6
+ "minAppVersion": "1.11.0",
7
+ "name": "Demo Vault Helper",
8
+ "version": "0.0.0"
9
+ }