vite-plus 0.1.2 → 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 (41) 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 +86 -166
  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 -83
  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-MTwAF3M9.js → workspace-lRm8huz4.js} +1625 -2816
  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/utils/agent.d.ts +15 -1
  28. package/dist/utils/agent.js +104 -20
  29. package/dist/utils/constants.d.ts +1 -0
  30. package/dist/utils/constants.js +2 -0
  31. package/dist/utils/editor.d.ts +16 -3
  32. package/dist/utils/editor.js +55 -17
  33. package/dist/utils/prompts.d.ts +32 -3
  34. package/dist/utils/prompts.js +32 -8
  35. package/dist/utils/tsconfig.d.ts +6 -0
  36. package/dist/utils/tsconfig.js +16 -0
  37. package/package.json +13 -13
  38. package/templates/monorepo/package.json +1 -1
  39. package/dist/global/wrap-ansi-BJxjUEQR.js +0 -4
  40. package/dist/oxlint-config.d.ts +0 -498
  41. 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, o as VITE_PLUS_NAME, 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
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
  }
@@ -88,21 +76,15 @@ function getStableSkillsDir(root) {
88
76
  const resolvedSkillsDir = join(pkgRoot, "skills");
89
77
  const logicalSkillsDir = join(root, "node_modules", VITE_PLUS_NAME, "skills");
90
78
  try {
91
- if (realpathSync(logicalSkillsDir) === realpathSync(resolvedSkillsDir)) {
92
- return logicalSkillsDir;
93
- }
79
+ if (realpathSync(logicalSkillsDir) === realpathSync(resolvedSkillsDir)) return logicalSkillsDir;
94
80
  } catch {}
95
81
  return resolvedSkillsDir;
96
82
  }
97
83
  function linkSkillsForSpecificAgents(root, agentConfigs) {
98
84
  const skillsDir = getStableSkillsDir(root);
99
85
  const skills = parseSkills(skillsDir);
100
- if (skills.length === 0) {
101
- return 0;
102
- }
103
- if (agentConfigs.length === 0) {
104
- return 0;
105
- }
86
+ if (skills.length === 0) return 0;
87
+ if (agentConfigs.length === 0) return 0;
106
88
  let totalLinked = 0;
107
89
  for (const agent of agentConfigs) {
108
90
  log.info(`${agent.displayName} → ${agent.skillsDir}`);
@@ -110,16 +92,11 @@ function linkSkillsForSpecificAgents(root, agentConfigs) {
110
92
  }
111
93
  return totalLinked;
112
94
  }
113
-
114
95
  //#endregion
115
96
  //#region src/config/agent.ts
116
97
  function detectInstructionFilePath(root, agentConfigs) {
117
- if (agentConfigs.some((a) => a.skillsDir === ".claude/skills")) {
118
- return "CLAUDE.md";
119
- }
120
- if (existsSync(join(root, "CLAUDE.md"))) {
121
- return "CLAUDE.md";
122
- }
98
+ if (agentConfigs.some((a) => a.skillsDir === ".claude/skills")) return "CLAUDE.md";
99
+ if (existsSync(join(root, "CLAUDE.md"))) return "CLAUDE.md";
123
100
  return "AGENTS.md";
124
101
  }
125
102
  async function pickAgentWhenUndetected() {
@@ -152,19 +129,15 @@ async function pickAgentWhenUndetected() {
152
129
  cancel("Setup cancelled.");
153
130
  process.exit(0);
154
131
  }
155
- if (choice === "generic") {
156
- return {
157
- instructionFilePath: "AGENTS.md",
158
- agents: []
159
- };
160
- }
132
+ if (choice === "generic") return {
133
+ instructionFilePath: "AGENTS.md",
134
+ agents: []
135
+ };
161
136
  const selected = getAgentById(choice);
162
- if (!selected) {
163
- return {
164
- instructionFilePath: "AGENTS.md",
165
- agents: []
166
- };
167
- }
137
+ if (!selected) return {
138
+ instructionFilePath: "AGENTS.md",
139
+ agents: []
140
+ };
168
141
  return {
169
142
  instructionFilePath: choice === "claude-code" ? "CLAUDE.md" : "AGENTS.md",
170
143
  agents: [selected]
@@ -172,19 +145,15 @@ async function pickAgentWhenUndetected() {
172
145
  }
173
146
  async function resolveAgentSetup(root, interactive) {
174
147
  const detected = detectAgents(root);
175
- if (detected.length > 0 || !interactive) {
176
- return {
177
- instructionFilePath: detectInstructionFilePath(root, detected),
178
- agents: detected
179
- };
180
- }
148
+ if (detected.length > 0 || !interactive) return {
149
+ instructionFilePath: detectInstructionFilePath(root, detected),
150
+ agents: detected
151
+ };
181
152
  return pickAgentWhenUndetected();
182
153
  }
183
154
  function getOwnVersion() {
184
155
  const pkg = JSON.parse(readFileSync(join(pkgRoot, "package.json"), "utf-8"));
185
- if (typeof pkg.version !== "string") {
186
- throw new Error("vite-plus package.json is missing a \"version\" field");
187
- }
156
+ if (typeof pkg.version !== "string") throw new Error("vite-plus package.json is missing a \"version\" field");
188
157
  return pkg.version;
189
158
  }
190
159
  function readAgentPrompt() {
@@ -198,9 +167,7 @@ function hasExistingAgentInstructions(root) {
198
167
  const fullPath = join(root, file);
199
168
  if (existsSync(fullPath)) {
200
169
  const content = readFileSync(fullPath, "utf-8");
201
- if (MARKER_OPEN_RE.test(content)) {
202
- return true;
203
- }
170
+ if (MARKER_OPEN_RE.test(content)) return true;
204
171
  }
205
172
  }
206
173
  return false;
@@ -209,8 +176,7 @@ function injectAgentBlock(root, filePath) {
209
176
  const fullPath = join(root, filePath);
210
177
  const version = getOwnVersion();
211
178
  const promptContent = readAgentPrompt();
212
- const openMarker = `<!--injected-by-vite-plus-v${version}-->`;
213
- const block = `${openMarker}\n${promptContent}\n${MARKER_CLOSE}`;
179
+ const block = `${`<!--injected-by-vite-plus-v${version}-->`}\n${promptContent}\n${MARKER_CLOSE}`;
214
180
  if (existsSync(fullPath)) {
215
181
  const existing = readFileSync(fullPath, "utf-8");
216
182
  const match = existing.match(MARKER_OPEN_RE);
@@ -221,16 +187,14 @@ function injectAgentBlock(root, filePath) {
221
187
  }
222
188
  const updated = existing.replace(MARKER_BLOCK_RE, block);
223
189
  if (updated === existing) {
224
- const separator = existing.endsWith("\n") ? "\n" : "\n\n";
225
- writeFileSync(fullPath, existing + separator + block + "\n");
190
+ writeFileSync(fullPath, existing + (existing.endsWith("\n") ? "\n" : "\n\n") + block + "\n");
226
191
  log.warn(`Existing Vite+ block in ${filePath} was malformed; appended fresh block`);
227
192
  } else {
228
193
  writeFileSync(fullPath, updated);
229
194
  log.success(`Updated Vite+ instructions in ${filePath} (v${match[1]} → v${version})`);
230
195
  }
231
196
  } else {
232
- const separator = existing.endsWith("\n") ? "\n" : "\n\n";
233
- writeFileSync(fullPath, existing + separator + block + "\n");
197
+ writeFileSync(fullPath, existing + (existing.endsWith("\n") ? "\n" : "\n\n") + block + "\n");
234
198
  log.success(`Added Vite+ instructions to ${filePath}`);
235
199
  }
236
200
  } else {
@@ -241,17 +205,13 @@ function injectAgentBlock(root, filePath) {
241
205
  function writeMcpConfigForTarget(root, target) {
242
206
  const fullPath = join(root, target.filePath);
243
207
  let existing = {};
244
- if (existsSync(fullPath)) {
245
- try {
246
- existing = readJsonFile(fullPath);
247
- } catch {
248
- log.warn(`Could not parse ${target.filePath} — skipping MCP config. Please add the config manually.`);
249
- return;
250
- }
251
- }
252
- if (!existing[target.rootKey]) {
253
- 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;
254
213
  }
214
+ if (!existing[target.rootKey]) existing[target.rootKey] = {};
255
215
  if (existing[target.rootKey]["vite-plus"]) {
256
216
  log.info(`${target.filePath} already has vite-plus MCP config`);
257
217
  return;
@@ -266,9 +226,7 @@ function writeMcpConfigForTarget(root, target) {
266
226
  log.success(`Added vite-plus MCP server to ${target.filePath}`);
267
227
  }
268
228
  function pickMcpTarget(root, targets) {
269
- if (targets.length === 1) {
270
- return targets[0];
271
- }
229
+ if (targets.length === 1) return targets[0];
272
230
  return targets.find((t) => existsSync(join(root, t.filePath))) ?? targets[0];
273
231
  }
274
232
  function setupMcpConfig(root, selectedAgents) {
@@ -281,29 +239,21 @@ function setupMcpConfig(root, selectedAgents) {
281
239
  }
282
240
  const mcpAgents = [];
283
241
  const hintAgents = [];
284
- for (const agent of selectedAgents) {
285
- if (agent.mcpConfig) {
286
- mcpAgents.push({
287
- agent,
288
- targets: agent.mcpConfig
289
- });
290
- } else if (agent.mcpHint) {
291
- hintAgents.push({
292
- agent,
293
- hint: agent.mcpHint
294
- });
295
- }
296
- }
297
- for (const { agent, hint } of hintAgents) {
298
- log.info(`${agent.displayName}: ${hint}`);
299
- }
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}`);
300
251
  for (const { agent, targets } of mcpAgents) {
301
252
  const target = pickMcpTarget(root, targets);
302
253
  log.info(`${agent.displayName} MCP target: ${target.filePath}`);
303
254
  writeMcpConfigForTarget(root, target);
304
255
  }
305
256
  }
306
-
307
257
  //#endregion
308
258
  //#region src/config/hooks.ts
309
259
  const HOOKS = [
@@ -324,15 +274,10 @@ const HOOKS = [
324
274
  ];
325
275
  function nestedDirname(depth) {
326
276
  let expr = "\"$0\"";
327
- for (let i = 0; i < depth; i++) {
328
- expr = `"$(dirname ${expr})"`;
329
- }
277
+ for (let i = 0; i < depth; i++) expr = `"$(dirname ${expr})"`;
330
278
  return expr;
331
279
  }
332
280
  function hookScript(dir) {
333
- const segments = dir.split("/").filter((s) => s !== "" && s !== ".").length;
334
- const depth = segments + 2;
335
- const rootExpr = nestedDirname(depth);
336
281
  return `#!/usr/bin/env sh
337
282
  { [ "$HUSKY" = "2" ] || [ "$VITE_GIT_HOOKS" = "2" ]; } && set -x
338
283
  n=$(basename "$0")
@@ -346,7 +291,7 @@ i="\${XDG_CONFIG_HOME:-$HOME/.config}/vite-plus/hooks-init.sh"
346
291
 
347
292
  { [ "\${HUSKY-}" = "0" ] || [ "\${VITE_GIT_HOOKS-}" = "0" ]; } && exit 0
348
293
 
349
- d=${rootExpr}
294
+ d=${nestedDirname(dir.split("/").filter((s) => s !== "" && s !== ".").length + 2)}
350
295
  export PATH="$d/node_modules/.bin:$PATH"
351
296
  sh -e "$s" "$@"
352
297
  c=$?
@@ -356,31 +301,23 @@ c=$?
356
301
  exit $c`;
357
302
  }
358
303
  function install(dir = ".vite-hooks") {
359
- if (process.env.HUSKY === "0" || process.env.VITE_GIT_HOOKS === "0") {
360
- return {
361
- message: "skip install (git hooks disabled)",
362
- isError: false
363
- };
364
- }
365
- if (dir.includes("..")) {
366
- return {
367
- message: ".. not allowed",
368
- isError: false
369
- };
370
- }
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
+ };
371
312
  const prefixResult = spawnSync("git", ["rev-parse", "--show-prefix"]);
372
- if (prefixResult.status == null) {
373
- return {
374
- message: "git command not found",
375
- isError: true
376
- };
377
- }
378
- if (prefixResult.status !== 0) {
379
- return {
380
- message: ".git can't be found",
381
- isError: false
382
- };
383
- }
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
+ };
384
321
  const internal = (x = "") => join(dir, "_", x);
385
322
  const rel = prefixResult.stdout.toString().trim().replace(/\/$/, "");
386
323
  const target = rel ? `${rel}/${dir}/_` : `${dir}/_`;
@@ -390,42 +327,33 @@ function install(dir = ".vite-hooks") {
390
327
  "core.hooksPath"
391
328
  ]);
392
329
  const existingHooksPath = checkResult.status === 0 ? checkResult.stdout?.toString().trim() : "";
393
- if (existingHooksPath && existingHooksPath !== target) {
394
- return {
395
- message: `core.hooksPath is already set to "${existingHooksPath}", skipping`,
396
- isError: false
397
- };
398
- }
330
+ if (existingHooksPath && existingHooksPath !== target) return {
331
+ message: `core.hooksPath is already set to "${existingHooksPath}", skipping`,
332
+ isError: false
333
+ };
399
334
  const { status, stderr } = spawnSync("git", [
400
335
  "config",
401
336
  "core.hooksPath",
402
337
  target
403
338
  ]);
404
- if (status == null) {
405
- return {
406
- message: "git command not found",
407
- isError: true
408
- };
409
- }
410
- if (status) {
411
- return {
412
- message: "" + stderr,
413
- isError: true
414
- };
415
- }
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
+ };
416
347
  rmSync(internal("husky.sh"), { force: true });
417
348
  mkdirSync(internal(), { recursive: true });
418
349
  writeFileSync(internal(".gitignore"), "*");
419
350
  writeFileSync(internal("h"), hookScript(dir), { mode: 493 });
420
- for (const hook of HOOKS) {
421
- writeFileSync(internal(hook), `#!/usr/bin/env sh\n. "$(dirname "$0")/h"`, { mode: 493 });
422
- }
351
+ for (const hook of HOOKS) writeFileSync(internal(hook), `#!/usr/bin/env sh\n. "$(dirname "$0")/h"`, { mode: 493 });
423
352
  return {
424
353
  message: "",
425
354
  isError: false
426
355
  };
427
356
  }
428
-
429
357
  //#endregion
430
358
  //#region src/config/bin.ts
431
359
  async function main() {
@@ -463,19 +391,14 @@ async function main() {
463
391
  const hooksOnly = args["hooks-only"];
464
392
  const interactive = defaultInteractive();
465
393
  const root = process.cwd();
466
- const hooksDir = dir ?? ".vite-hooks";
467
- const isFirstHooksRun = !existsSync(join(root, hooksDir, "pre-commit"));
394
+ const isFirstHooksRun = !existsSync(join(root, dir ?? ".vite-hooks", "pre-commit"));
468
395
  let shouldSetupHooks = true;
469
- if (interactive && isFirstHooksRun && !dir) {
470
- shouldSetupHooks = await promptGitHooks({ interactive });
471
- }
396
+ if (interactive && isFirstHooksRun && !dir) shouldSetupHooks = await promptGitHooks({ interactive });
472
397
  if (shouldSetupHooks) {
473
398
  const { message, isError } = install(dir);
474
399
  if (message) {
475
400
  log$1(message);
476
- if (isError) {
477
- process.exit(1);
478
- }
401
+ if (isError) process.exit(1);
479
402
  }
480
403
  }
481
404
  if (!hooksOnly && process.env.npm_lifecycle_event !== "prepare") {
@@ -483,11 +406,8 @@ async function main() {
483
406
  const agentSetup = await resolveAgentSetup(root, interactive && isFirstAgentRun);
484
407
  injectAgentBlock(root, agentSetup.instructionFilePath);
485
408
  setupMcpConfig(root, agentSetup.agents);
486
- if (agentSetup.agents.length > 0) {
487
- linkSkillsForSpecificAgents(root, agentSetup.agents);
488
- }
409
+ if (agentSetup.agents.length > 0) linkSkillsForSpecificAgents(root, agentSetup.agents);
489
410
  }
490
411
  }
491
- void main();
492
-
493
- //#endregion
412
+ main();
413
+ //#endregion