vite-plus 0.1.1 → 0.1.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 (43) hide show
  1. package/binding/index.cjs +2 -0
  2. package/binding/index.d.cts +32 -0
  3. package/dist/global/{prompts-CAIahN1u.js → agent-BE4Xze8Q.js} +380 -1280
  4. package/dist/global/{browser-CY4NBwxR.js → browser-CBapUTD0.js} +579 -1023
  5. package/dist/global/{browser-DFpJ6sKb.js → browser-EZnNDcaO.js} +2 -3
  6. package/dist/global/{chunk-CtfvYSle.js → chunk-CgnkrU7a.js} +13 -22
  7. package/dist/global/{cli-truncate-BxinOqz5.js → cli-truncate-Da6Y8aM8.js} +25 -74
  8. package/dist/global/config.js +95 -165
  9. package/dist/global/create.js +353 -496
  10. package/dist/global/{terminal-Cb-NuRkb.js → help-BAGHa8fD.js} +22 -54
  11. package/dist/global/{json-Bfvtp2rL.js → json-BRdVJ52a.js} +24 -58
  12. package/dist/global/{lib-CibYHP32.js → lib-DxappLRQ.js} +19 -43
  13. package/dist/global/{log-update-DdU6_LCN.js → log-update-C8WCYCbc.js} +102 -281
  14. package/dist/global/mcp.js +97 -169
  15. package/dist/global/migrate.js +223 -72
  16. package/dist/global/{package-Pq2biU7_.js → package-YAMvX5PJ.js} +6 -13
  17. package/dist/global/{slice-ansi-BhwAwMdF.js → slice-ansi-Fap0ehe9.js} +21 -52
  18. package/dist/global/{src-C6aLHRsS.js → src-DwSJ0s0I.js} +28 -110
  19. package/dist/global/staged.js +654 -1521
  20. package/dist/global/{strip-ansi-BL-dgd7n.js → strip-ansi-CE-VDMdw.js} +20 -67
  21. package/dist/global/version.js +16 -37
  22. package/dist/global/{workspace-De4OKHV7.js → workspace-lRm8huz4.js} +1645 -2806
  23. package/dist/global/wrap-ansi-Ou9oAs-a.js +3 -0
  24. package/dist/global/{wrap-ansi-Iww6Ak1s.js → wrap-ansi-eywLlPVQ.js} +29 -80
  25. package/dist/index.d.ts +1 -1
  26. package/dist/init-config.js +10 -2
  27. package/dist/run-config.d.ts +17 -0
  28. package/dist/utils/agent.d.ts +15 -1
  29. package/dist/utils/agent.js +104 -20
  30. package/dist/utils/constants.d.ts +1 -0
  31. package/dist/utils/constants.js +2 -0
  32. package/dist/utils/editor.d.ts +16 -3
  33. package/dist/utils/editor.js +55 -17
  34. package/dist/utils/prompts.d.ts +32 -3
  35. package/dist/utils/prompts.js +32 -8
  36. package/dist/utils/skills.js +18 -2
  37. package/dist/utils/tsconfig.d.ts +6 -0
  38. package/dist/utils/tsconfig.js +16 -0
  39. package/package.json +13 -13
  40. package/templates/monorepo/package.json +1 -1
  41. package/dist/global/wrap-ansi-BJxjUEQR.js +0 -4
  42. package/dist/oxlint-config.d.ts +0 -498
  43. package/dist/oxlint-config.js +0 -309
@@ -1,29 +1,21 @@
1
- import { C as log, D as select, T as note, b as cancel, d as getAgentById, h as pkgRoot, i as promptGitHooks, k as Ct, l as detectAgents, n as defaultInteractive } from "./prompts-CAIahN1u.js";
2
- import { t as lib_default } from "./lib-CibYHP32.js";
3
- import { i as writeJsonFile, r as readJsonFile } from "./json-Bfvtp2rL.js";
4
- import { a as renderCliDoc, n as log$1 } from "./terminal-Cb-NuRkb.js";
1
+ import { A as select, C as cancel, E as log, M as Ct, O as note, _ as pkgRoot, c as defaultInteractive, d as promptGitHooks, i as getAgentById, n as detectAgents } from "./agent-BE4Xze8Q.js";
2
+ import { t as lib_default } from "./lib-DxappLRQ.js";
3
+ import { i as writeJsonFile, r as readJsonFile, s as VITE_PLUS_NAME } from "./json-BRdVJ52a.js";
4
+ import { r as log$1, t as renderCliDoc } from "./help-BAGHa8fD.js";
5
5
  import { dirname, join, relative } from "node:path";
6
- import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
6
+ import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
7
7
  import { vitePlusHeader } from "../../binding/index.js";
8
8
  import { spawnSync } from "node:child_process";
9
-
10
9
  //#region src/utils/skills.ts
11
10
  function parseSkills(skillsDir) {
12
- if (!existsSync(skillsDir)) {
13
- return [];
14
- }
11
+ if (!existsSync(skillsDir)) return [];
15
12
  const entries = readdirSync(skillsDir, { withFileTypes: true });
16
13
  const skills = [];
17
14
  for (const entry of entries) {
18
- if (!entry.isDirectory()) {
19
- continue;
20
- }
15
+ if (!entry.isDirectory()) continue;
21
16
  const skillMd = join(skillsDir, entry.name, "SKILL.md");
22
- if (!existsSync(skillMd)) {
23
- continue;
24
- }
25
- const content = readFileSync(skillMd, "utf-8");
26
- const frontmatter = content.match(/^---\n([\s\S]*?)\n---/);
17
+ if (!existsSync(skillMd)) continue;
18
+ const frontmatter = readFileSync(skillMd, "utf-8").match(/^---\n([\s\S]*?)\n---/);
27
19
  if (!frontmatter) {
28
20
  log.warn(` Skipping ${entry.name}: SKILL.md is missing valid frontmatter`);
29
21
  continue;
@@ -49,18 +41,14 @@ function pathExists(p) {
49
41
  }
50
42
  function linkSkills(root, skillsDir, skills, agentSkillsDir) {
51
43
  const targetDir = join(root, agentSkillsDir);
52
- if (!existsSync(targetDir)) {
53
- mkdirSync(targetDir, { recursive: true });
54
- }
44
+ if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });
55
45
  let linked = 0;
56
46
  for (const skill of skills) {
57
47
  const linkPath = join(targetDir, skill.dirName);
58
- const sourcePath = join(skillsDir, skill.dirName);
59
- const relativeTarget = relative(targetDir, sourcePath);
48
+ const relativeTarget = relative(targetDir, join(skillsDir, skill.dirName));
60
49
  if (pathExists(linkPath)) {
61
50
  try {
62
- const existing = readlinkSync(linkPath);
63
- if (existing === relativeTarget) {
51
+ if (readlinkSync(linkPath) === relativeTarget) {
64
52
  log.info(` ${skill.name} — already linked`);
65
53
  continue;
66
54
  }
@@ -84,15 +72,19 @@ function linkSkills(root, skillsDir, skills, agentSkillsDir) {
84
72
  }
85
73
  return linked;
86
74
  }
75
+ function getStableSkillsDir(root) {
76
+ const resolvedSkillsDir = join(pkgRoot, "skills");
77
+ const logicalSkillsDir = join(root, "node_modules", VITE_PLUS_NAME, "skills");
78
+ try {
79
+ if (realpathSync(logicalSkillsDir) === realpathSync(resolvedSkillsDir)) return logicalSkillsDir;
80
+ } catch {}
81
+ return resolvedSkillsDir;
82
+ }
87
83
  function linkSkillsForSpecificAgents(root, agentConfigs) {
88
- const skillsDir = join(pkgRoot, "skills");
84
+ const skillsDir = getStableSkillsDir(root);
89
85
  const skills = parseSkills(skillsDir);
90
- if (skills.length === 0) {
91
- return 0;
92
- }
93
- if (agentConfigs.length === 0) {
94
- return 0;
95
- }
86
+ if (skills.length === 0) return 0;
87
+ if (agentConfigs.length === 0) return 0;
96
88
  let totalLinked = 0;
97
89
  for (const agent of agentConfigs) {
98
90
  log.info(`${agent.displayName} → ${agent.skillsDir}`);
@@ -100,16 +92,11 @@ function linkSkillsForSpecificAgents(root, agentConfigs) {
100
92
  }
101
93
  return totalLinked;
102
94
  }
103
-
104
95
  //#endregion
105
96
  //#region src/config/agent.ts
106
97
  function detectInstructionFilePath(root, agentConfigs) {
107
- if (agentConfigs.some((a) => a.skillsDir === ".claude/skills")) {
108
- return "CLAUDE.md";
109
- }
110
- if (existsSync(join(root, "CLAUDE.md"))) {
111
- return "CLAUDE.md";
112
- }
98
+ if (agentConfigs.some((a) => a.skillsDir === ".claude/skills")) return "CLAUDE.md";
99
+ if (existsSync(join(root, "CLAUDE.md"))) return "CLAUDE.md";
113
100
  return "AGENTS.md";
114
101
  }
115
102
  async function pickAgentWhenUndetected() {
@@ -142,19 +129,15 @@ async function pickAgentWhenUndetected() {
142
129
  cancel("Setup cancelled.");
143
130
  process.exit(0);
144
131
  }
145
- if (choice === "generic") {
146
- return {
147
- instructionFilePath: "AGENTS.md",
148
- agents: []
149
- };
150
- }
132
+ if (choice === "generic") return {
133
+ instructionFilePath: "AGENTS.md",
134
+ agents: []
135
+ };
151
136
  const selected = getAgentById(choice);
152
- if (!selected) {
153
- return {
154
- instructionFilePath: "AGENTS.md",
155
- agents: []
156
- };
157
- }
137
+ if (!selected) return {
138
+ instructionFilePath: "AGENTS.md",
139
+ agents: []
140
+ };
158
141
  return {
159
142
  instructionFilePath: choice === "claude-code" ? "CLAUDE.md" : "AGENTS.md",
160
143
  agents: [selected]
@@ -162,19 +145,15 @@ async function pickAgentWhenUndetected() {
162
145
  }
163
146
  async function resolveAgentSetup(root, interactive) {
164
147
  const detected = detectAgents(root);
165
- if (detected.length > 0 || !interactive) {
166
- return {
167
- instructionFilePath: detectInstructionFilePath(root, detected),
168
- agents: detected
169
- };
170
- }
148
+ if (detected.length > 0 || !interactive) return {
149
+ instructionFilePath: detectInstructionFilePath(root, detected),
150
+ agents: detected
151
+ };
171
152
  return pickAgentWhenUndetected();
172
153
  }
173
154
  function getOwnVersion() {
174
155
  const pkg = JSON.parse(readFileSync(join(pkgRoot, "package.json"), "utf-8"));
175
- if (typeof pkg.version !== "string") {
176
- throw new Error("vite-plus package.json is missing a \"version\" field");
177
- }
156
+ if (typeof pkg.version !== "string") throw new Error("vite-plus package.json is missing a \"version\" field");
178
157
  return pkg.version;
179
158
  }
180
159
  function readAgentPrompt() {
@@ -188,9 +167,7 @@ function hasExistingAgentInstructions(root) {
188
167
  const fullPath = join(root, file);
189
168
  if (existsSync(fullPath)) {
190
169
  const content = readFileSync(fullPath, "utf-8");
191
- if (MARKER_OPEN_RE.test(content)) {
192
- return true;
193
- }
170
+ if (MARKER_OPEN_RE.test(content)) return true;
194
171
  }
195
172
  }
196
173
  return false;
@@ -199,8 +176,7 @@ function injectAgentBlock(root, filePath) {
199
176
  const fullPath = join(root, filePath);
200
177
  const version = getOwnVersion();
201
178
  const promptContent = readAgentPrompt();
202
- const openMarker = `<!--injected-by-vite-plus-v${version}-->`;
203
- const block = `${openMarker}\n${promptContent}\n${MARKER_CLOSE}`;
179
+ const block = `${`<!--injected-by-vite-plus-v${version}-->`}\n${promptContent}\n${MARKER_CLOSE}`;
204
180
  if (existsSync(fullPath)) {
205
181
  const existing = readFileSync(fullPath, "utf-8");
206
182
  const match = existing.match(MARKER_OPEN_RE);
@@ -211,16 +187,14 @@ function injectAgentBlock(root, filePath) {
211
187
  }
212
188
  const updated = existing.replace(MARKER_BLOCK_RE, block);
213
189
  if (updated === existing) {
214
- const separator = existing.endsWith("\n") ? "\n" : "\n\n";
215
- writeFileSync(fullPath, existing + separator + block + "\n");
190
+ writeFileSync(fullPath, existing + (existing.endsWith("\n") ? "\n" : "\n\n") + block + "\n");
216
191
  log.warn(`Existing Vite+ block in ${filePath} was malformed; appended fresh block`);
217
192
  } else {
218
193
  writeFileSync(fullPath, updated);
219
194
  log.success(`Updated Vite+ instructions in ${filePath} (v${match[1]} → v${version})`);
220
195
  }
221
196
  } else {
222
- const separator = existing.endsWith("\n") ? "\n" : "\n\n";
223
- writeFileSync(fullPath, existing + separator + block + "\n");
197
+ writeFileSync(fullPath, existing + (existing.endsWith("\n") ? "\n" : "\n\n") + block + "\n");
224
198
  log.success(`Added Vite+ instructions to ${filePath}`);
225
199
  }
226
200
  } else {
@@ -231,17 +205,13 @@ function injectAgentBlock(root, filePath) {
231
205
  function writeMcpConfigForTarget(root, target) {
232
206
  const fullPath = join(root, target.filePath);
233
207
  let existing = {};
234
- if (existsSync(fullPath)) {
235
- try {
236
- existing = readJsonFile(fullPath);
237
- } catch {
238
- log.warn(`Could not parse ${target.filePath} — skipping MCP config. Please add the config manually.`);
239
- return;
240
- }
241
- }
242
- if (!existing[target.rootKey]) {
243
- existing[target.rootKey] = {};
208
+ if (existsSync(fullPath)) try {
209
+ existing = readJsonFile(fullPath);
210
+ } catch {
211
+ log.warn(`Could not parse ${target.filePath} skipping MCP config. Please add the config manually.`);
212
+ return;
244
213
  }
214
+ if (!existing[target.rootKey]) existing[target.rootKey] = {};
245
215
  if (existing[target.rootKey]["vite-plus"]) {
246
216
  log.info(`${target.filePath} already has vite-plus MCP config`);
247
217
  return;
@@ -256,9 +226,7 @@ function writeMcpConfigForTarget(root, target) {
256
226
  log.success(`Added vite-plus MCP server to ${target.filePath}`);
257
227
  }
258
228
  function pickMcpTarget(root, targets) {
259
- if (targets.length === 1) {
260
- return targets[0];
261
- }
229
+ if (targets.length === 1) return targets[0];
262
230
  return targets.find((t) => existsSync(join(root, t.filePath))) ?? targets[0];
263
231
  }
264
232
  function setupMcpConfig(root, selectedAgents) {
@@ -271,29 +239,21 @@ function setupMcpConfig(root, selectedAgents) {
271
239
  }
272
240
  const mcpAgents = [];
273
241
  const hintAgents = [];
274
- for (const agent of selectedAgents) {
275
- if (agent.mcpConfig) {
276
- mcpAgents.push({
277
- agent,
278
- targets: agent.mcpConfig
279
- });
280
- } else if (agent.mcpHint) {
281
- hintAgents.push({
282
- agent,
283
- hint: agent.mcpHint
284
- });
285
- }
286
- }
287
- for (const { agent, hint } of hintAgents) {
288
- log.info(`${agent.displayName}: ${hint}`);
289
- }
242
+ for (const agent of selectedAgents) if (agent.mcpConfig) mcpAgents.push({
243
+ agent,
244
+ targets: agent.mcpConfig
245
+ });
246
+ else if (agent.mcpHint) hintAgents.push({
247
+ agent,
248
+ hint: agent.mcpHint
249
+ });
250
+ for (const { agent, hint } of hintAgents) log.info(`${agent.displayName}: ${hint}`);
290
251
  for (const { agent, targets } of mcpAgents) {
291
252
  const target = pickMcpTarget(root, targets);
292
253
  log.info(`${agent.displayName} MCP target: ${target.filePath}`);
293
254
  writeMcpConfigForTarget(root, target);
294
255
  }
295
256
  }
296
-
297
257
  //#endregion
298
258
  //#region src/config/hooks.ts
299
259
  const HOOKS = [
@@ -314,15 +274,10 @@ const HOOKS = [
314
274
  ];
315
275
  function nestedDirname(depth) {
316
276
  let expr = "\"$0\"";
317
- for (let i = 0; i < depth; i++) {
318
- expr = `"$(dirname ${expr})"`;
319
- }
277
+ for (let i = 0; i < depth; i++) expr = `"$(dirname ${expr})"`;
320
278
  return expr;
321
279
  }
322
280
  function hookScript(dir) {
323
- const segments = dir.split("/").filter((s) => s !== "" && s !== ".").length;
324
- const depth = segments + 2;
325
- const rootExpr = nestedDirname(depth);
326
281
  return `#!/usr/bin/env sh
327
282
  { [ "$HUSKY" = "2" ] || [ "$VITE_GIT_HOOKS" = "2" ]; } && set -x
328
283
  n=$(basename "$0")
@@ -336,7 +291,7 @@ i="\${XDG_CONFIG_HOME:-$HOME/.config}/vite-plus/hooks-init.sh"
336
291
 
337
292
  { [ "\${HUSKY-}" = "0" ] || [ "\${VITE_GIT_HOOKS-}" = "0" ]; } && exit 0
338
293
 
339
- d=${rootExpr}
294
+ d=${nestedDirname(dir.split("/").filter((s) => s !== "" && s !== ".").length + 2)}
340
295
  export PATH="$d/node_modules/.bin:$PATH"
341
296
  sh -e "$s" "$@"
342
297
  c=$?
@@ -346,31 +301,23 @@ c=$?
346
301
  exit $c`;
347
302
  }
348
303
  function install(dir = ".vite-hooks") {
349
- if (process.env.HUSKY === "0" || process.env.VITE_GIT_HOOKS === "0") {
350
- return {
351
- message: "skip install (git hooks disabled)",
352
- isError: false
353
- };
354
- }
355
- if (dir.includes("..")) {
356
- return {
357
- message: ".. not allowed",
358
- isError: false
359
- };
360
- }
304
+ if (process.env.HUSKY === "0" || process.env.VITE_GIT_HOOKS === "0") return {
305
+ message: "skip install (git hooks disabled)",
306
+ isError: false
307
+ };
308
+ if (dir.includes("..")) return {
309
+ message: ".. not allowed",
310
+ isError: false
311
+ };
361
312
  const prefixResult = spawnSync("git", ["rev-parse", "--show-prefix"]);
362
- if (prefixResult.status == null) {
363
- return {
364
- message: "git command not found",
365
- isError: true
366
- };
367
- }
368
- if (prefixResult.status !== 0) {
369
- return {
370
- message: ".git can't be found",
371
- isError: false
372
- };
373
- }
313
+ if (prefixResult.status == null) return {
314
+ message: "git command not found",
315
+ isError: true
316
+ };
317
+ if (prefixResult.status !== 0) return {
318
+ message: ".git can't be found",
319
+ isError: false
320
+ };
374
321
  const internal = (x = "") => join(dir, "_", x);
375
322
  const rel = prefixResult.stdout.toString().trim().replace(/\/$/, "");
376
323
  const target = rel ? `${rel}/${dir}/_` : `${dir}/_`;
@@ -380,42 +327,33 @@ function install(dir = ".vite-hooks") {
380
327
  "core.hooksPath"
381
328
  ]);
382
329
  const existingHooksPath = checkResult.status === 0 ? checkResult.stdout?.toString().trim() : "";
383
- if (existingHooksPath && existingHooksPath !== target) {
384
- return {
385
- message: `core.hooksPath is already set to "${existingHooksPath}", skipping`,
386
- isError: false
387
- };
388
- }
330
+ if (existingHooksPath && existingHooksPath !== target) return {
331
+ message: `core.hooksPath is already set to "${existingHooksPath}", skipping`,
332
+ isError: false
333
+ };
389
334
  const { status, stderr } = spawnSync("git", [
390
335
  "config",
391
336
  "core.hooksPath",
392
337
  target
393
338
  ]);
394
- if (status == null) {
395
- return {
396
- message: "git command not found",
397
- isError: true
398
- };
399
- }
400
- if (status) {
401
- return {
402
- message: "" + stderr,
403
- isError: true
404
- };
405
- }
339
+ if (status == null) return {
340
+ message: "git command not found",
341
+ isError: true
342
+ };
343
+ if (status) return {
344
+ message: "" + stderr,
345
+ isError: true
346
+ };
406
347
  rmSync(internal("husky.sh"), { force: true });
407
348
  mkdirSync(internal(), { recursive: true });
408
349
  writeFileSync(internal(".gitignore"), "*");
409
350
  writeFileSync(internal("h"), hookScript(dir), { mode: 493 });
410
- for (const hook of HOOKS) {
411
- writeFileSync(internal(hook), `#!/usr/bin/env sh\n. "$(dirname "$0")/h"`, { mode: 493 });
412
- }
351
+ for (const hook of HOOKS) writeFileSync(internal(hook), `#!/usr/bin/env sh\n. "$(dirname "$0")/h"`, { mode: 493 });
413
352
  return {
414
353
  message: "",
415
354
  isError: false
416
355
  };
417
356
  }
418
-
419
357
  //#endregion
420
358
  //#region src/config/bin.ts
421
359
  async function main() {
@@ -453,19 +391,14 @@ async function main() {
453
391
  const hooksOnly = args["hooks-only"];
454
392
  const interactive = defaultInteractive();
455
393
  const root = process.cwd();
456
- const hooksDir = dir ?? ".vite-hooks";
457
- const isFirstHooksRun = !existsSync(join(root, hooksDir, "pre-commit"));
394
+ const isFirstHooksRun = !existsSync(join(root, dir ?? ".vite-hooks", "pre-commit"));
458
395
  let shouldSetupHooks = true;
459
- if (interactive && isFirstHooksRun && !dir) {
460
- shouldSetupHooks = await promptGitHooks({ interactive });
461
- }
396
+ if (interactive && isFirstHooksRun && !dir) shouldSetupHooks = await promptGitHooks({ interactive });
462
397
  if (shouldSetupHooks) {
463
398
  const { message, isError } = install(dir);
464
399
  if (message) {
465
400
  log$1(message);
466
- if (isError) {
467
- process.exit(1);
468
- }
401
+ if (isError) process.exit(1);
469
402
  }
470
403
  }
471
404
  if (!hooksOnly && process.env.npm_lifecycle_event !== "prepare") {
@@ -473,11 +406,8 @@ async function main() {
473
406
  const agentSetup = await resolveAgentSetup(root, interactive && isFirstAgentRun);
474
407
  injectAgentBlock(root, agentSetup.instructionFilePath);
475
408
  setupMcpConfig(root, agentSetup.agents);
476
- if (agentSetup.agents.length > 0) {
477
- linkSkillsForSpecificAgents(root, agentSetup.agents);
478
- }
409
+ if (agentSetup.agents.length > 0) linkSkillsForSpecificAgents(root, agentSetup.agents);
479
410
  }
480
411
  }
481
- void main();
482
-
483
- //#endregion
412
+ main();
413
+ //#endregion