@valaxyjs/devtools 1.0.0-rc.12 → 1.0.0-rc.13

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 (78) hide show
  1. package/README.md +14 -1
  2. package/dist/client/assets/FeedbackEmptyState-6lTUwFgn.js +1 -0
  3. package/dist/client/assets/LayoutCard-ZKe9PNVY.js +1 -0
  4. package/dist/client/assets/Teleport-Rn3Nqhbz.js +3 -0
  5. package/dist/client/assets/VDCheckbox-daRKoTGK.js +1 -0
  6. package/dist/client/assets/VDCodeBlock-BtPCxwvt.js +1 -0
  7. package/dist/client/assets/VDCodeBlock-C3pmQBwJ.css +1 -0
  8. package/dist/client/assets/VDNumberField-ko0BYjUy.js +1 -0
  9. package/dist/client/assets/VDPostListItem-CHPpKGrl.js +1 -0
  10. package/dist/client/assets/VDPostPanel-TTV6v3vH.js +1 -0
  11. package/dist/client/assets/VDSelect-Cu_aXlTc.js +1 -0
  12. package/dist/client/assets/VDToggleGroup-DQu5ibPP.js +1 -0
  13. package/dist/client/assets/addons-BeZTS6wo.js +1 -0
  14. package/dist/client/assets/addons-D7_qAb67.css +1 -0
  15. package/dist/client/assets/app-djZMc7np.js +3 -0
  16. package/dist/client/assets/archives-DyxjvxXC.js +1 -0
  17. package/dist/client/assets/batch-edit-e_0tefQi.js +1 -0
  18. package/dist/client/assets/{browser-agent-rpc-BXhoSh1z-BPEkUHEg.js → browser-agent-rpc-BXhoSh1z-DKEQfrSa.js} +1 -1
  19. package/dist/client/assets/categories-D8m60Fso.js +1 -0
  20. package/dist/client/assets/collections-Boilukwl.js +1 -0
  21. package/dist/client/assets/config-DoNtHUjQ.js +1 -0
  22. package/dist/client/assets/debug-x5mwtm5I.js +1 -0
  23. package/dist/client/assets/editor-CHXt0bEP.js +1 -0
  24. package/dist/client/assets/index-BkcKXtGA.js +4 -0
  25. package/dist/client/assets/index-D2Bg3cBy.css +1 -0
  26. package/dist/client/assets/pages-C0Hm1R05.js +1 -0
  27. package/dist/client/assets/posts-BjJqEMcb.js +1 -0
  28. package/dist/client/assets/{rpc-D36U2nIU.js → rpc-_85YyBhb.js} +3 -3
  29. package/dist/client/assets/runtime-dom.esm-bundler-COvr_-s-.js +2 -0
  30. package/dist/client/assets/settings-D1-tIv7g.js +1 -0
  31. package/dist/client/assets/splitpanes.esm-CnpdH7BM.js +1 -0
  32. package/dist/client/assets/tags-DiOGZThc.js +1 -0
  33. package/dist/client/assets/{virtual_intlify-i18n-0-CRury7qB.js → virtual_intlify-i18n-0-BOFXizJp.js} +1 -1
  34. package/dist/client/assets/{virtual_intlify-i18n-1-FM-gmUYx.js → virtual_intlify-i18n-1-CPnPqlXp.js} +1 -1
  35. package/dist/client/index.html +7 -6
  36. package/dist/client-api.d.mts +1 -0
  37. package/dist/client-api.d.ts +1 -0
  38. package/dist/index.d.mts +3 -5
  39. package/dist/index.d.ts +3 -5
  40. package/dist/index.mjs +40 -9
  41. package/dist/node/definition.d.mts +2 -1
  42. package/dist/node/definition.d.ts +2 -1
  43. package/dist/node/definition.mjs +411 -41
  44. package/dist/node/mcp.mjs +1 -1
  45. package/dist/plugin.d.mts +1 -0
  46. package/dist/plugin.d.ts +1 -0
  47. package/dist/shared/{devtools.DV0tVpWA.d.mts → devtools.BEU7Q82S.d.mts} +91 -5
  48. package/dist/shared/{devtools.lzRAl5dD.d.ts → devtools.D4CJIUQe.d.ts} +91 -5
  49. package/dist/shared/{devtools.B-vZo-vB.mjs → devtools.mygDTMGI.mjs} +1 -1
  50. package/dist/shared/rpc.d.mts +3 -5
  51. package/dist/shared/rpc.d.ts +3 -5
  52. package/package.json +8 -3
  53. package/dist/client/assets/FeedbackEmptyState-Dj1YkJE0.js +0 -1
  54. package/dist/client/assets/LayoutCard-qUVYVRud.js +0 -1
  55. package/dist/client/assets/PopperContent-CgXMlFkV.js +0 -3
  56. package/dist/client/assets/VDCheckbox-CH2V3bFJ.js +0 -1
  57. package/dist/client/assets/VDNumberField-DVmMsYPC.js +0 -1
  58. package/dist/client/assets/VDPostListItem-D3Rn_PcJ.js +0 -1
  59. package/dist/client/assets/VDPostPanel-BWZUkoQC.js +0 -1
  60. package/dist/client/assets/VDSelect-4SBTowKT.js +0 -1
  61. package/dist/client/assets/VDToggleGroup-BOVPTJ4m.js +0 -1
  62. package/dist/client/assets/addons-CF1AfuFX.js +0 -1
  63. package/dist/client/assets/archives-CDa7i8eC.js +0 -1
  64. package/dist/client/assets/batch-edit-DIvZaav7.js +0 -1
  65. package/dist/client/assets/categories-Bk3lMeb1.js +0 -1
  66. package/dist/client/assets/collections-BHxAwkoL.js +0 -1
  67. package/dist/client/assets/config-B09dyTTS.js +0 -1
  68. package/dist/client/assets/debug-CMQbsCep.js +0 -1
  69. package/dist/client/assets/debug-DcFlBZjk.css +0 -1
  70. package/dist/client/assets/index-Cyol-EzD.css +0 -1
  71. package/dist/client/assets/index-DUZ9khG8.js +0 -4
  72. package/dist/client/assets/pages-BWRkr8em.js +0 -1
  73. package/dist/client/assets/posts-mlMGwcAv.js +0 -1
  74. package/dist/client/assets/runtime-core.esm-bundler-B8D2lM98.js +0 -3
  75. package/dist/client/assets/runtime-dom.esm-bundler-Btnku4nR.js +0 -2
  76. package/dist/client/assets/settings-BZuYgjIU.js +0 -1
  77. package/dist/client/assets/splitpanes.esm-CrBmgK88.js +0 -1
  78. package/dist/client/assets/tags-DUuGVO-R.js +0 -1
package/dist/index.mjs CHANGED
@@ -6,21 +6,22 @@ import { R as RESOURCES_STATE, r as resolveDevtoolsBase, a as DEVTOOLS_FRAME_ID,
6
6
  import { createValaxyDevframe } from './node/definition.mjs';
7
7
  import process from 'node:process';
8
8
  import pathe from 'pathe';
9
- import '@valaxyjs/utils';
9
+ import { addons } from '@valaxyjs/utils';
10
10
  import 'devframe';
11
11
  import 'valibot';
12
- import './shared/devtools.B-vZo-vB.mjs';
12
+ import './shared/devtools.mygDTMGI.mjs';
13
13
  import 'fs-extra';
14
14
  import 'node:path';
15
15
  import 'node:url';
16
+ import 'node:crypto';
17
+ import 'cross-spawn';
18
+ import 'fast-glob';
19
+ import 'node:fs/promises';
16
20
  import 'magicast';
17
- import 'dayjs';
18
21
  import 'devframe/utils/launch-editor';
19
- import 'fast-glob';
22
+ import 'dayjs';
20
23
  import 'gray-matter';
21
24
  import 'js-yaml';
22
- import 'node:fs/promises';
23
- import 'node:crypto';
24
25
 
25
26
  const NAMESPACE = "valaxy:devtools";
26
27
 
@@ -30,14 +31,14 @@ async function watchResources(server, ctx, options) {
30
31
  let timer;
31
32
  const changed = (_event, file) => {
32
33
  const relative = pathe.relative(root, file);
33
- if (!relative.startsWith("pages/") && !["site.config.ts", "valaxy.config.ts"].includes(relative))
34
+ if (!relative.startsWith("pages/") && !["site.config.ts", "valaxy.config.ts", "valaxy.config.mts", "valaxy.config.js", "valaxy.config.mjs", "package.json", "pnpm-lock.yaml"].includes(relative))
34
35
  return;
35
36
  clearTimeout(timer);
36
37
  timer = setTimeout(() => state.mutate((value) => {
37
38
  value.revision++;
38
39
  }), 100);
39
40
  };
40
- server.watcher.add([pathe.join(root, "pages"), pathe.join(root, "site.config.ts"), pathe.join(root, "valaxy.config.ts")]);
41
+ server.watcher.add(["pages", "site.config.ts", "valaxy.config.ts", "valaxy.config.mts", "valaxy.config.js", "valaxy.config.mjs", "package.json", "pnpm-lock.yaml"].map((file) => pathe.join(root, file)));
41
42
  server.watcher.on("all", changed);
42
43
  return () => {
43
44
  clearTimeout(timer);
@@ -135,6 +136,36 @@ function ValaxyDevtools(options = {}) {
135
136
  };
136
137
  }
137
138
 
138
- const safelist = [];
139
+ const editorPresentations = [
140
+ { commands: ["code"], name: "Visual Studio Code", icon: "i-vscode-icons:file-type-vscode" },
141
+ { commands: ["code-insiders"], name: "VS Code Insiders", icon: "i-vscode-icons:file-type-vscode-insiders" },
142
+ { commands: ["cursor"], name: "Cursor", icon: "i-simple-icons:cursor" },
143
+ { commands: ["zed"], name: "Zed", icon: "i-simple-icons:zedindustries" },
144
+ { commands: ["webstorm", "wstorm"], name: "WebStorm", icon: "i-simple-icons:webstorm" },
145
+ { commands: ["codium", "vscodium"], name: "VSCodium", icon: "i-simple-icons:vscodium" },
146
+ { commands: ["subl", "sublime", "sublime_text"], name: "Sublime Text", icon: "i-simple-icons:sublimetext" },
147
+ { commands: ["idea"], name: "IntelliJ IDEA", icon: "i-simple-icons:intellijidea" },
148
+ { commands: ["trae"], name: "Trae", icon: "i-simple-icons:trae" },
149
+ { commands: ["atom"], name: "Atom", icon: "i-simple-icons:atom" },
150
+ { commands: ["pycharm", "charm"], name: "PyCharm", icon: "i-simple-icons:pycharm" },
151
+ { commands: ["phpstorm"], name: "PhpStorm", icon: "i-simple-icons:phpstorm" },
152
+ { commands: ["rubymine"], name: "RubyMine", icon: "i-simple-icons:rubymine" },
153
+ { commands: ["clion"], name: "CLion", icon: "i-simple-icons:clion" },
154
+ { commands: ["goland"], name: "GoLand", icon: "i-simple-icons:goland" },
155
+ { commands: ["rider"], name: "Rider", icon: "i-simple-icons:rider" },
156
+ { commands: ["notepad++"], name: "Notepad++", icon: "i-simple-icons:notepadplusplus" },
157
+ { commands: ["vim"], name: "Vim", icon: "i-simple-icons:vim" },
158
+ { commands: ["mvim"], name: "MacVim", icon: "i-simple-icons:vim" },
159
+ { commands: ["gvim"], name: "gVim", icon: "i-simple-icons:vim" },
160
+ { commands: ["emacs"], name: "Emacs", icon: "i-simple-icons:gnuemacs" },
161
+ { commands: ["emacsclient"], name: "Emacs Client", icon: "i-simple-icons:gnuemacs" },
162
+ { commands: ["mate"], name: "TextMate", icon: "i-ph:code" },
163
+ { commands: ["rmate"], name: "Remote TextMate", icon: "i-ph:code" },
164
+ { commands: ["antigravity"], name: "Antigravity", icon: "i-ph:code" },
165
+ { commands: ["appcode"], name: "AppCode", icon: "i-ph:code" },
166
+ { commands: ["joe"], name: "JOE", icon: "i-ph:terminal" }
167
+ ];
168
+
169
+ const safelist = [...addons.map((addon) => addon.icon), ...editorPresentations.map((editor) => editor.icon)];
139
170
 
140
171
  export { ValaxyDevtools, createValaxyDevframe, ValaxyDevtools as default, safelist };
@@ -1,9 +1,10 @@
1
1
  import '../plugin.mjs';
2
+ export { a as createRpcFunctions, c as createValaxyDevframe } from '../shared/devtools.BEU7Q82S.mjs';
2
3
  import '../shared/rpc.mjs';
3
4
  import 'devframe/rpc';
4
5
  import 'devframe';
5
6
  import '../shared/devtools.BOLo8y6t.mjs';
6
- export { a as createRpcFunctions, c as createValaxyDevframe } from '../shared/devtools.DV0tVpWA.mjs';
7
7
  import 'valibot';
8
+ import 'devframe/utils/launch-editor';
8
9
  import 'valaxy';
9
10
  import '../shared/devtools.O-VZ9RtQ.mjs';
@@ -1,9 +1,10 @@
1
1
  import '../plugin.js';
2
+ export { a as createRpcFunctions, c as createValaxyDevframe } from '../shared/devtools.D4CJIUQe.js';
2
3
  import '../shared/rpc.js';
3
4
  import 'devframe/rpc';
4
5
  import 'devframe';
5
6
  import '../shared/devtools.CNAj6Cjx.js';
6
- export { a as createRpcFunctions, c as createValaxyDevframe } from '../shared/devtools.lzRAl5dD.js';
7
7
  import 'valibot';
8
+ import 'devframe/utils/launch-editor';
8
9
  import 'valaxy';
9
10
  import '../shared/devtools.O-VZ9RtQ.js';
@@ -1,26 +1,408 @@
1
- import { normalizeRepositoryUrl } from '@valaxyjs/utils';
1
+ import process from 'node:process';
2
+ import { addons, normalizeRepositoryUrl } from '@valaxyjs/utils';
2
3
  import { defineDevframe, defineRpcFunction } from 'devframe';
4
+ import pathe, { resolve as resolve$1 } from 'pathe';
3
5
  import * as v from 'valibot';
4
- import { a as resolveInsideRoot, r as resolvePageFile, p as pkg } from '../shared/devtools.B-vZo-vB.mjs';
6
+ import { a as resolveInsideRoot, r as resolvePageFile, p as pkg } from '../shared/devtools.mygDTMGI.mjs';
5
7
  import { dirname, resolve } from 'node:path';
6
8
  import { fileURLToPath } from 'node:url';
7
9
  import { R as RESOURCES_STATE, c as resolveAddonBase, d as DEVTOOLS_ID, r as resolveDevtoolsBase, b as resolveDevtoolsLogo } from '../shared/devtools.CBhjeyeH.mjs';
10
+ import { randomUUID, createHash } from 'node:crypto';
11
+ import spawn from 'cross-spawn';
12
+ import fg from 'fast-glob';
8
13
  import fs from 'fs-extra';
9
- import pathe from 'pathe';
10
- import { generateCode, parseModule } from 'magicast';
11
- import process from 'node:process';
14
+ import { realpath, readFile, writeFile } from 'node:fs/promises';
15
+ import { parseModule, generateCode } from 'magicast';
16
+ import { KNOWN_EDITORS } from 'devframe/utils/launch-editor';
12
17
  import dayjs from 'dayjs';
13
- import { launchEditor } from 'devframe/utils/launch-editor';
14
- import fg from 'fast-glob';
15
18
  import matter from 'gray-matter';
16
19
  import { dump, JSON_SCHEMA, load } from 'js-yaml';
17
- import { realpath, readFile, writeFile } from 'node:fs/promises';
18
- import { createHash } from 'node:crypto';
19
20
 
20
21
  const packageRoot = dirname(fileURLToPath(import.meta.resolve("@valaxyjs/devtools/package.json")));
21
22
  const DIR_DIST = resolve(packageRoot, "dist");
22
23
  const DIR_CLIENT = resolve(DIR_DIST, "client");
23
24
 
25
+ const pendingWrites = /* @__PURE__ */ new Map();
26
+ async function updatePageFile(file, update) {
27
+ const canonical = await realpath(file);
28
+ const previous = pendingWrites.get(canonical) || Promise.resolve();
29
+ const operation = previous.catch(() => {
30
+ }).then(async () => {
31
+ const { content, result } = update(await readFile(canonical, "utf8"));
32
+ await writeFile(canonical, content, "utf8");
33
+ return result;
34
+ });
35
+ pendingWrites.set(canonical, operation);
36
+ try {
37
+ return await operation;
38
+ } finally {
39
+ if (pendingWrites.get(canonical) === operation)
40
+ pendingWrites.delete(canonical);
41
+ }
42
+ }
43
+
44
+ function walk(node, visit) {
45
+ if (!node || typeof node !== "object")
46
+ return;
47
+ if (Array.isArray(node)) {
48
+ node.forEach((child) => walk(child, visit));
49
+ return;
50
+ }
51
+ const value = node;
52
+ if (typeof value.type !== "string")
53
+ return;
54
+ visit(value);
55
+ for (const [key, child] of Object.entries(value)) {
56
+ if (!["loc", "tokens", "comments", "original", "leadingComments", "trailingComments"].includes(key))
57
+ walk(child, visit);
58
+ }
59
+ }
60
+ function removeAddonFromConfig(source, name) {
61
+ const mod = parseModule(source);
62
+ const imports = mod.imports.$items.filter((item) => item.from === name);
63
+ const bindings = new Set(imports.map((item) => item.local));
64
+ const exported = mod.exports.default;
65
+ const value = exported?.$type === "function-call" ? exported.$args[0] : exported;
66
+ if (!value || value.$type !== "object")
67
+ throw new Error("This configuration is dynamic. Remove the addon references in your editor first.");
68
+ const entries = value.addons;
69
+ if (entries != null && entries.$type !== "array")
70
+ throw new Error("The addons list is dynamic. Remove the addon references in your editor first.");
71
+ const shortName = name.replace(/^valaxy-addon-/, "");
72
+ let changed = imports.length > 0;
73
+ if (entries) {
74
+ for (let index = entries.length - 1; index >= 0; index--) {
75
+ const item = entries[index];
76
+ const matches = typeof item === "string" ? item === name || item === shortName : item?.$type === "function-call" ? bindings.has(item.$callee) : item?.$type === "object" ? item.name === name || item.name === shortName : false;
77
+ if (matches) {
78
+ entries.splice(index, 1);
79
+ changed = true;
80
+ }
81
+ }
82
+ }
83
+ for (const item of imports)
84
+ delete mod.imports[item.local];
85
+ let remaining = false;
86
+ walk(mod.$ast, (node) => {
87
+ if (node.type === "Identifier" && bindings.has(String(node.name)))
88
+ remaining = true;
89
+ if (["StringLiteral", "Literal"].includes(String(node.type)) && typeof node.value === "string" && (node.value === name || node.value.startsWith(`${name}/`)))
90
+ remaining = true;
91
+ });
92
+ if (remaining)
93
+ throw new Error("This addon is referenced outside a simple addons entry. Remove those references in your editor first.");
94
+ return changed ? generateCode(mod).code : source;
95
+ }
96
+
97
+ const configNames = ["valaxy.config.ts", "valaxy.config.mts", "valaxy.config.js", "valaxy.config.mjs"];
98
+ const dependencyFields = ["dependencies", "devDependencies", "optionalDependencies"];
99
+ const states = /* @__PURE__ */ new Map();
100
+ const busyWorkspaces = /* @__PURE__ */ new Set();
101
+ function assertAddonName(name) {
102
+ if (!/^valaxy-addon-[a-z0-9][a-z0-9._-]*$/.test(name) || name.length > 214)
103
+ throw new Error("Expected a valaxy-addon-* npm package name.");
104
+ }
105
+ function safeUrl(value) {
106
+ if (typeof value !== "string")
107
+ return void 0;
108
+ try {
109
+ const url = new URL(normalizeRepositoryUrl(value));
110
+ return ["http:", "https:"].includes(url.protocol) ? url.href : void 0;
111
+ } catch {
112
+ return void 0;
113
+ }
114
+ }
115
+ async function fetchAddonPackage(name) {
116
+ assertAddonName(name);
117
+ const response = await fetch(`https://registry.npmjs.org/${encodeURIComponent(name)}/latest`, {
118
+ signal: AbortSignal.timeout(1e4),
119
+ redirect: "error",
120
+ headers: { accept: "application/json" }
121
+ });
122
+ if (!response.ok)
123
+ throw new Error(`npm registry request failed (${response.status}).`);
124
+ const raw = await response.text();
125
+ if (raw.length > 1e6)
126
+ throw new Error("Package metadata is too large.");
127
+ const data = JSON.parse(raw);
128
+ if (data.name !== name || typeof data.version !== "string" || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(data.version))
129
+ throw new Error("The registry returned invalid package metadata.");
130
+ return {
131
+ name,
132
+ version: data.version,
133
+ description: typeof data.description === "string" ? data.description.slice(0, 2e3) : "",
134
+ homepage: safeUrl(data.homepage),
135
+ repository: safeUrl(typeof data.repository === "string" ? data.repository : data.repository?.url),
136
+ license: typeof data.license === "string" ? data.license : void 0,
137
+ peerDependencies: Object.fromEntries(Object.entries(data.peerDependencies || {}).filter((entry) => typeof entry[1] === "string"))
138
+ };
139
+ }
140
+ function runAddonPackageManager(root, args, onLog) {
141
+ return new Promise((resolve, reject) => {
142
+ const child = spawn("pnpm", args, { cwd: root, shell: false, stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, FORCE_COLOR: "0" } });
143
+ let timedOut = false;
144
+ const timer = setTimeout(() => {
145
+ timedOut = true;
146
+ child.kill();
147
+ }, 3e5);
148
+ const stop = () => child.kill();
149
+ process.once("exit", stop);
150
+ const cleanup = () => {
151
+ clearTimeout(timer);
152
+ process.off("exit", stop);
153
+ };
154
+ child.stdout?.on("data", (data) => onLog(String(data)));
155
+ child.stderr?.on("data", (data) => onLog(String(data)));
156
+ child.once("error", (error) => {
157
+ cleanup();
158
+ reject(new Error(`Could not start pnpm: ${error.message}`));
159
+ });
160
+ child.once("close", (code) => {
161
+ cleanup();
162
+ if (timedOut)
163
+ reject(new Error("Package operation timed out. Check the project dependency files before retrying."));
164
+ else if (code !== 0)
165
+ reject(new Error(`pnpm exited with code ${code}. Check the log and project dependency files before retrying.`));
166
+ else resolve();
167
+ });
168
+ });
169
+ }
170
+ async function optionalRead(file) {
171
+ try {
172
+ return await fs.readFile(file, "utf8");
173
+ } catch (error) {
174
+ if (error.code === "ENOENT")
175
+ return void 0;
176
+ throw error;
177
+ }
178
+ }
179
+ async function workspaceRoot(root) {
180
+ let current = root;
181
+ while (true) {
182
+ if (await fs.pathExists(pathe.join(current, "pnpm-workspace.yaml")))
183
+ return current;
184
+ const parent = pathe.dirname(current);
185
+ if (parent === current)
186
+ return root;
187
+ current = parent;
188
+ }
189
+ }
190
+ async function snapshot$1(root) {
191
+ const packageFile = await resolveInsideRoot(root, "package.json");
192
+ const packageSource = await optionalRead(packageFile);
193
+ const pkg = packageSource ? JSON.parse(packageSource) : {};
194
+ const workspace = await workspaceRoot(root);
195
+ const files = /* @__PURE__ */ new Map([[packageFile, packageSource]]);
196
+ const configs = [];
197
+ for (const name of configNames) {
198
+ const file = await resolveInsideRoot(root, name);
199
+ const source = await optionalRead(file);
200
+ files.set(file, source);
201
+ if (source !== void 0)
202
+ configs.push({ path: file, source });
203
+ }
204
+ for (const name of ["pnpm-lock.yaml", "pnpm-workspace.yaml"]) {
205
+ const file = await resolveInsideRoot(workspace, name);
206
+ files.set(file, await optionalRead(file));
207
+ }
208
+ const otherLock = await Promise.all(["package-lock.json", "yarn.lock", "bun.lock", "bun.lockb"].map((name) => fs.pathExists(pathe.join(root, name))));
209
+ const declaredManager = typeof pkg.packageManager === "string" ? pkg.packageManager : "";
210
+ const managementError = !packageSource ? "This project has no package.json." : declaredManager && !declaredManager.startsWith("pnpm@") ? "This project uses another package manager. Manage its addons in your terminal." : !declaredManager && otherLock.some(Boolean) ? "A non-pnpm lockfile was found. Manage this project with its existing package manager." : configs.length > 1 ? "Multiple Valaxy configuration files were found. Keep a single configuration before managing addons." : void 0;
211
+ const revision = createHash("sha256").update(JSON.stringify([...files])).digest("hex");
212
+ return { pkg, configs, workspace, revision, managementError };
213
+ }
214
+ async function installedPackage(root, name) {
215
+ let current = root;
216
+ while (true) {
217
+ const source = await optionalRead(pathe.join(current, "node_modules", name, "package.json"));
218
+ if (source) {
219
+ const pkg = JSON.parse(source);
220
+ return pkg.name === name ? pkg : void 0;
221
+ }
222
+ const parent = pathe.dirname(current);
223
+ if (parent === current)
224
+ return void 0;
225
+ current = parent;
226
+ }
227
+ }
228
+ async function assertNoOtherReferences(root, name, configFile) {
229
+ const files = await fg("**/*.{ts,mts,cts,js,mjs,cjs,jsx,tsx,vue}", { cwd: root, absolute: true, followSymbolicLinks: false, ignore: ["**/node_modules/**", "**/dist/**", "**/.valaxy/**", "**/.output/**", "**/.nuxt/**"] });
230
+ if (files.length > 5e3)
231
+ throw new Error("This project is too large to check automatically. Remove the addon using your editor and package manager.");
232
+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
233
+ const reference = new RegExp(`['"\`]${escaped}(?:/[^'"\`\\n]*)?['"\`]`);
234
+ const remaining = [];
235
+ for (const file of files) {
236
+ if (pathe.normalize(file) !== configFile && reference.test(await fs.readFile(await resolveInsideRoot(root, file), "utf8")))
237
+ remaining.push(pathe.relative(root, file));
238
+ }
239
+ if (remaining.length)
240
+ throw new Error(`Remove this addon's other source references first: ${remaining.slice(0, 10).join(", ")}`);
241
+ }
242
+ function createAddonManager(options, dependencies = {}) {
243
+ const rootPath = pathe.resolve(options.userRoot || process.cwd());
244
+ const fetchPackage = dependencies.fetchPackage || fetchAddonPackage;
245
+ const run = dependencies.run || runAddonPackageManager;
246
+ async function context() {
247
+ const root = pathe.normalize(await fs.realpath(rootPath));
248
+ let state = states.get(root);
249
+ if (!state) {
250
+ state = { plans: /* @__PURE__ */ new Map(), jobs: /* @__PURE__ */ new Map() };
251
+ states.set(root, state);
252
+ }
253
+ return { root, state };
254
+ }
255
+ async function inventory() {
256
+ const { root, state } = await context();
257
+ const current = await snapshot$1(root);
258
+ const active = options.getAddons?.() || [];
259
+ const declared = Object.assign({}, ...dependencyFields.map((field) => current.pkg[field] || {}));
260
+ const names = /* @__PURE__ */ new Set([...Object.keys(declared), ...active.map((addon) => addon.name)]);
261
+ const installed = [];
262
+ for (const name of names) {
263
+ if (!/^valaxy-addon-[a-z0-9][a-z0-9._-]*$/.test(name))
264
+ continue;
265
+ const enabled = active.find((addon) => addon.name === name);
266
+ const pkg = await installedPackage(root, name);
267
+ if (!declared[name] && !pkg && !enabled)
268
+ continue;
269
+ installed.push({ name, version: pkg?.version || enabled?.version, description: pkg?.description, specifier: declared[name], direct: Object.hasOwn(declared, name), enabled: !!enabled });
270
+ }
271
+ return { installed: installed.sort((a, b) => a.name.localeCompare(b.name)), packageManager: current.managementError ? null : "pnpm", managementError: current.managementError, configFile: current.configs[0]?.path, operation: state.operation ? structuredClone(state.operation) : void 0 };
272
+ }
273
+ async function prepare(action, name) {
274
+ assertAddonName(name);
275
+ if (action !== "install" && action !== "remove")
276
+ throw new Error("Unknown addon operation.");
277
+ const { root, state } = await context();
278
+ const current = await snapshot$1(root);
279
+ if (current.managementError)
280
+ throw new Error(current.managementError);
281
+ if (busyWorkspaces.has(current.workspace))
282
+ throw new Error("A package operation is already running in this workspace.");
283
+ const direct = dependencyFields.some((field) => Object.hasOwn(current.pkg[field] || {}, name));
284
+ if (action === "install" && direct)
285
+ throw new Error("This addon is already declared in package.json.");
286
+ if (action === "remove" && !direct)
287
+ throw new Error("Only direct dependencies of this project can be removed.");
288
+ if (action === "install" && !addons.some((addon) => addon.name === name))
289
+ throw new Error("This addon is not in the curated catalog. Install it in your terminal after reviewing it.");
290
+ const plan = { id: randomUUID(), action, name, command: "" };
291
+ let args;
292
+ if (action === "install") {
293
+ const details = await fetchPackage(name);
294
+ if (details.name !== name || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(details.version))
295
+ throw new Error("Invalid package version.");
296
+ plan.version = details.version;
297
+ args = ["add", "--save-exact", "--ignore-scripts", "--registry=https://registry.npmjs.org", `${name}@${details.version}`];
298
+ } else {
299
+ const config = current.configs[0];
300
+ await assertNoOtherReferences(root, name, config?.path);
301
+ if (config) {
302
+ const after = removeAddonFromConfig(config.source, name);
303
+ if (after !== config.source) {
304
+ plan.configFile = config.path;
305
+ plan.configBefore = config.source;
306
+ plan.configAfter = after;
307
+ } else if (options.getAddons?.().some((addon) => addon.name === name)) {
308
+ throw new Error("This addon is enabled by an inherited or dynamic configuration. Remove that reference first.");
309
+ }
310
+ }
311
+ args = ["remove", "--ignore-scripts", name];
312
+ }
313
+ if (root === current.workspace && await fs.pathExists(pathe.join(root, "pnpm-workspace.yaml")))
314
+ args.push("--workspace-root");
315
+ plan.command = `pnpm ${args.join(" ")}`;
316
+ for (const [id, entry] of state.plans) {
317
+ if (entry.expires < Date.now() || state.plans.size >= 20)
318
+ state.plans.delete(id);
319
+ }
320
+ state.plans.set(plan.id, { plan, args, revision: current.revision, expires: Date.now() + 3e5 });
321
+ return structuredClone(plan);
322
+ }
323
+ async function apply(id) {
324
+ const { root, state } = await context();
325
+ if (state.jobs.has(id))
326
+ return structuredClone(state.jobs.get(id));
327
+ const stored = state.plans.get(id);
328
+ if (!stored || stored.expires < Date.now())
329
+ throw new Error("The operation preview expired. Review a new preview before continuing.");
330
+ const current = await snapshot$1(root);
331
+ if (current.revision !== stored.revision)
332
+ throw new Error("Project configuration or dependencies changed. Review a new preview before continuing.");
333
+ if (stored.plan.action === "remove")
334
+ await assertNoOtherReferences(root, stored.plan.name, current.configs[0]?.path);
335
+ if (state.jobs.has(id))
336
+ return structuredClone(state.jobs.get(id));
337
+ if (busyWorkspaces.has(current.workspace))
338
+ throw new Error("A package operation is already running in this workspace.");
339
+ busyWorkspaces.add(current.workspace);
340
+ const operation = { ...stored.plan, status: "running", log: "" };
341
+ state.jobs.set(id, operation);
342
+ state.plans.delete(id);
343
+ state.operation = operation;
344
+ while (state.jobs.size > 20)
345
+ state.jobs.delete(state.jobs.keys().next().value);
346
+ const log = (text) => {
347
+ operation.log = (operation.log + text).slice(-2e4);
348
+ };
349
+ void (async () => {
350
+ let configChanged = false;
351
+ try {
352
+ if (operation.configFile) {
353
+ await resolveInsideRoot(root, operation.configFile);
354
+ await updatePageFile(operation.configFile, (source) => {
355
+ if (source !== operation.configBefore)
356
+ throw new Error("Configuration changed after preview. No package command was run.");
357
+ return { content: operation.configAfter, result: void 0 };
358
+ });
359
+ configChanged = true;
360
+ }
361
+ await run(root, stored.args, log);
362
+ const updated = await snapshot$1(root);
363
+ const declared = dependencyFields.some((field) => Object.hasOwn(updated.pkg[field] || {}, operation.name));
364
+ if (declared !== (operation.action === "install"))
365
+ throw new Error("pnpm finished but package.json did not reflect the requested change.");
366
+ if (operation.action === "install" && (await installedPackage(root, operation.name))?.version !== operation.version)
367
+ throw new Error("The installed addon version does not match the reviewed version. Check the project dependencies.");
368
+ operation.status = "succeeded";
369
+ } catch (error) {
370
+ operation.status = "failed";
371
+ operation.error = error instanceof Error ? error.message : String(error);
372
+ if (configChanged && operation.configFile) {
373
+ try {
374
+ const updated = await snapshot$1(root);
375
+ if (!dependencyFields.some((field) => Object.hasOwn(updated.pkg[field] || {}, operation.name)))
376
+ throw new Error("The dependency was already removed. Its configuration references remain removed; inspect the dependency files before retrying.");
377
+ await resolveInsideRoot(root, operation.configFile);
378
+ await updatePageFile(operation.configFile, (source) => {
379
+ if (source !== operation.configAfter)
380
+ throw new Error("Configuration was edited externally; it was preserved instead of restoring the preview.");
381
+ return { content: operation.configBefore, result: void 0 };
382
+ });
383
+ } catch (rollbackError) {
384
+ log(`
385
+ ${String(rollbackError)}
386
+ `);
387
+ }
388
+ }
389
+ } finally {
390
+ busyWorkspaces.delete(current.workspace);
391
+ }
392
+ })();
393
+ return structuredClone(operation);
394
+ }
395
+ return { inventory, prepare, apply, details: fetchPackage };
396
+ }
397
+
398
+ function getEditorOptions(env = process.env) {
399
+ const configured = env.LAUNCH_EDITOR || env.VISUAL || env.EDITOR;
400
+ return {
401
+ editor: KNOWN_EDITORS.find((editor) => editor === configured),
402
+ editors: [...KNOWN_EDITORS]
403
+ };
404
+ }
405
+
24
406
  const DANGEROUS_FIELD_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
25
407
  function validateFieldPath(fieldPath) {
26
408
  const parts = fieldPath.split(".");
@@ -313,25 +695,6 @@ async function migration(path, frontmatter, validateFrontmatter = () => {
313
695
  }
314
696
  }
315
697
 
316
- const pendingWrites = /* @__PURE__ */ new Map();
317
- async function updatePageFile(file, update) {
318
- const canonical = await realpath(file);
319
- const previous = pendingWrites.get(canonical) || Promise.resolve();
320
- const operation = previous.catch(() => {
321
- }).then(async () => {
322
- const { content, result } = update(await readFile(canonical, "utf8"));
323
- await writeFile(canonical, content, "utf8");
324
- return result;
325
- });
326
- pendingWrites.set(canonical, operation);
327
- try {
328
- return await operation;
329
- } finally {
330
- if (pendingWrites.get(canonical) === operation)
331
- pendingWrites.delete(canonical);
332
- }
333
- }
334
-
335
698
  function snapshot(content) {
336
699
  return { content, revision: createHash("sha256").update(content).digest("hex") };
337
700
  }
@@ -397,14 +760,11 @@ function getFunctions(devtoolsOptions, validateFrontmatter = () => {
397
760
  return {
398
761
  getPostContent: (filePath) => readPostContent(userRoot, filePath),
399
762
  updatePostContent: (req) => writePostContent(userRoot, req.filePath, req.content, req.revision),
400
- async openInEditor({ file, line = 0, column = 0 }) {
401
- const resolved = await resolveInsideRoot(userRoot, file);
402
- launchEditor(`${resolved}:${line}:${column}`, process.env.EDITOR);
403
- },
404
763
  async getOptions() {
405
764
  return {
406
765
  userRoot,
407
- siteUrl: devtoolsOptions.siteUrl?.()
766
+ siteUrl: devtoolsOptions.siteUrl?.(),
767
+ ...getEditorOptions()
408
768
  };
409
769
  },
410
770
  async getPostList() {
@@ -734,13 +1094,6 @@ function createRpcFunctions(functions) {
734
1094
  args: [filePaths, v.record(v.string(), v.string())],
735
1095
  returns: success,
736
1096
  handler: functions.runMigration
737
- }),
738
- defineRpcFunction({
739
- name: "open-in-editor",
740
- type: "action",
741
- args: [v.object({ file: v.string(), line: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0))), column: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0))) })],
742
- returns: v.void(),
743
- handler: functions.openInEditor
744
1097
  })
745
1098
  ];
746
1099
  }
@@ -774,7 +1127,10 @@ function createValaxyDevframe(options = {}) {
774
1127
  basePath: resolveDevtoolsBase(options.base),
775
1128
  clientAssets: DIR_CLIENT,
776
1129
  capabilities: { dev: true, build: false },
777
- services: [{ package: "@devframes/service-shiki", options: { langs: ["json"] } }],
1130
+ services: [
1131
+ { package: "@devframes/service-shiki", options: { langs: ["json"] } },
1132
+ { package: "@devframes/service-open", options: { editor: getEditorOptions().editor, roots: [resolve$1(options.userRoot || process.cwd())] } }
1133
+ ],
778
1134
  async setup(ctx) {
779
1135
  await ctx.rpc.sharedState.get(RESOURCES_STATE, { initialValue: { revision: 0 } });
780
1136
  plugins = await resolveDevtoolsPlugins(options);
@@ -789,6 +1145,8 @@ function createValaxyDevframe(options = {}) {
789
1145
  const scoped = ctx.scope(DEVTOOLS_ID);
790
1146
  for (const fn of createRpcFunctions(functions))
791
1147
  scoped.rpc.register(fn);
1148
+ for (const fn of createAddonRpc(createAddonManager(options)))
1149
+ scoped.rpc.register(fn);
792
1150
  const manifest = createManifest(plugins, options.base);
793
1151
  for (const fn of createExtensionRpc(manifest, plugins, data))
794
1152
  scoped.rpc.register(fn);
@@ -802,6 +1160,18 @@ function createValaxyDevframe(options = {}) {
802
1160
  });
803
1161
  return Object.assign(definition, { dispose });
804
1162
  }
1163
+ function createAddonRpc(manager) {
1164
+ const name = v.pipe(v.string(), v.maxLength(214), v.regex(/^valaxy-addon-[a-z0-9][a-z0-9._-]*$/));
1165
+ const plan = v.object({ id: v.string(), action: v.picklist(["install", "remove"]), name: v.string(), version: v.optional(v.string()), command: v.string(), configFile: v.optional(v.string()), configBefore: v.optional(v.string()), configAfter: v.optional(v.string()) });
1166
+ const operation = v.object({ ...plan.entries, status: v.picklist(["running", "succeeded", "failed"]), log: v.string(), error: v.optional(v.string()) });
1167
+ const details = v.object({ name: v.string(), version: v.string(), description: v.string(), homepage: v.optional(v.string()), repository: v.optional(v.string()), license: v.optional(v.string()), peerDependencies: v.record(v.string(), v.string()) });
1168
+ return [
1169
+ defineRpcFunction({ name: "get-addons", type: "query", jsonSerializable: true, handler: manager.inventory }),
1170
+ defineRpcFunction({ name: "get-addon-package", type: "query", jsonSerializable: true, args: [name], returns: details, handler: manager.details }),
1171
+ defineRpcFunction({ name: "prepare-addon-operation", type: "action", jsonSerializable: true, args: [v.picklist(["install", "remove"]), name], returns: plan, handler: manager.prepare }),
1172
+ defineRpcFunction({ name: "apply-addon-operation", type: "action", jsonSerializable: true, args: [v.pipe(v.string(), v.uuid())], returns: operation, handler: manager.apply })
1173
+ ];
1174
+ }
805
1175
  function createExtensionRpc(manifest, plugins, data) {
806
1176
  return [
807
1177
  defineRpcFunction({ name: "get-extensions", type: "query", jsonSerializable: true, handler: () => manifest }),
package/dist/node/mcp.mjs CHANGED
@@ -2,7 +2,7 @@ import { mountMcpHttp } from 'devframe/adapters/mcp';
2
2
  import { createHostContext } from 'devframe/node';
3
3
  import { H3, toNodeHandler } from 'h3';
4
4
  import pathe from 'pathe';
5
- import { r as resolvePageFile, p as pkg } from '../shared/devtools.B-vZo-vB.mjs';
5
+ import { r as resolvePageFile, p as pkg } from '../shared/devtools.mygDTMGI.mjs';
6
6
  import { realpath, stat, readFile } from 'node:fs/promises';
7
7
  import process from 'node:process';
8
8
  import fg from 'fast-glob';
package/dist/plugin.d.mts CHANGED
@@ -2,6 +2,7 @@ import { DevframeScopedNodeContext } from 'devframe';
2
2
  import { b as ValaxyEditorField, c as ValaxyEditorContext, d as ValaxyEditorActionResult, a as ValaxyDevtoolsData } from './shared/devtools.BOLo8y6t.mjs';
3
3
  export { V as ValaxyDevtoolsManifest } from './shared/devtools.BOLo8y6t.mjs';
4
4
  import './shared/rpc.mjs';
5
+ import 'devframe/utils/launch-editor';
5
6
  import 'valaxy';
6
7
  import './shared/devtools.O-VZ9RtQ.mjs';
7
8
 
package/dist/plugin.d.ts CHANGED
@@ -2,6 +2,7 @@ import { DevframeScopedNodeContext } from 'devframe';
2
2
  import { b as ValaxyEditorField, c as ValaxyEditorContext, d as ValaxyEditorActionResult, a as ValaxyDevtoolsData } from './shared/devtools.CNAj6Cjx.js';
3
3
  export { V as ValaxyDevtoolsManifest } from './shared/devtools.CNAj6Cjx.js';
4
4
  import './shared/rpc.js';
5
+ import 'devframe/utils/launch-editor';
5
6
  import 'valaxy';
6
7
  import './shared/devtools.O-VZ9RtQ.js';
7
8