vite-plus 0.1.2 → 0.1.4

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-CpNB3GIY.js} +475 -1350
  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 +626 -615
  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 +330 -86
  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 +1353 -2112
  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-CiqQdO1L.js} +1711 -2834
  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 +33 -4
  34. package/dist/utils/prompts.js +34 -10
  35. package/dist/utils/tsconfig.d.ts +6 -0
  36. package/dist/utils/tsconfig.js +16 -0
  37. package/package.json +14 -14
  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,22 +1,77 @@
1
- import { i as __toESM } from "./chunk-CtfvYSle.js";
2
- import { C as log, E as outro, S as intro, c as upgradeYarn, f as selectAgentTargetPaths, i as promptGitHooks, k as Ct, n as defaultInteractive, o as runViteInstall, p as writeAgentInstructions, r as downloadPackageManager$1, s as selectPackageManager, t as cancelAndExit, x as confirm, y as PackageManager } from "./prompts-CAIahN1u.js";
3
- import { t as lib_default } from "./lib-CibYHP32.js";
4
- import { a as selectEditor, c as checkVitestVersion, d as rewriteMonorepo, l as installGitHooks, m as require_semver, o as writeEditorConfigs, p as rewriteStandaloneProject, s as checkViteVersion, t as detectWorkspace$1, u as preflightGitHooksSetup } from "./workspace-MTwAF3M9.js";
5
- import "./browser-CY4NBwxR.js";
6
- import "./json-Bfvtp2rL.js";
7
- import { i as readNearestPackageJson, r as hasVitePlusDependency } from "./package-Pq2biU7_.js";
8
- import { a as renderCliDoc, n as log$1, r as muted, t as accent } from "./terminal-Cb-NuRkb.js";
1
+ import { i as __toESM } from "./chunk-CgnkrU7a.js";
2
+ import { A as select, E as log, N as Ct, S as PackageManager, a as selectAgentTargetPaths, c as defaultInteractive, d as promptGitHooks, g as displayRelative, h as upgradeYarn, j as spinner, k as outro, l as downloadPackageManager$1, m as selectPackageManager, o as writeAgentInstructions, p as runViteInstall, s as cancelAndExit, t as detectAgentConflicts, w as confirm } from "./agent-CpNB3GIY.js";
3
+ import { t as lib_default } from "./lib-DxappLRQ.js";
4
+ import { _ as rewriteMonorepo, b as createMigrationReport, c as checkViteVersion, d as detectPrettierProject, f as installGitHooks, g as preflightGitHooksSetup, h as migratePrettierToOxfmt, i as detectEditorConflicts, l as checkVitestVersion, m as migrateEslintToOxlint, o as selectEditor, p as mergeViteConfigFiles, s as writeEditorConfigs, t as detectWorkspace$1, u as detectEslintProject, x as require_semver, y as rewriteStandaloneProject } from "./workspace-CiqQdO1L.js";
5
+ import "./browser-CBapUTD0.js";
6
+ import "./json-BRdVJ52a.js";
7
+ import { i as readNearestPackageJson, r as hasVitePlusDependency } from "./package-YAMvX5PJ.js";
8
+ import { i as muted, n as accent, r as log$1, t as renderCliDoc } from "./help-BAGHa8fD.js";
9
9
  import path from "node:path";
10
10
  import { styleText } from "node:util";
11
- import colors from "picocolors";
12
11
  import { vitePlusHeader } from "../../binding/index.js";
13
-
14
12
  //#region src/migration/bin.ts
15
13
  var import_semver = /* @__PURE__ */ __toESM(require_semver(), 1);
16
- const { green } = colors;
14
+ function warnPackageLevelEslint() {
15
+ log.warn("ESLint detected in workspace packages but no root config found. Package-level ESLint must be migrated manually.");
16
+ }
17
+ function warnLegacyEslintConfig(legacyConfigFile) {
18
+ log.warn(`Legacy ESLint configuration detected (${legacyConfigFile}). Automatic migration to Oxlint requires ESLint v9+ with flat config format (eslint.config.*). Please upgrade to ESLint v9 first: https://eslint.org/docs/latest/use/migrate-to-9.0.0`);
19
+ }
20
+ async function confirmEslintMigration(interactive) {
21
+ if (interactive) {
22
+ const confirmed = await confirm({
23
+ message: "Migrate ESLint rules to Oxlint using @oxlint/migrate?",
24
+ initialValue: true
25
+ });
26
+ if (Ct(confirmed)) cancelAndExit();
27
+ return !!confirmed;
28
+ }
29
+ return true;
30
+ }
31
+ async function promptEslintMigration(projectPath, interactive, packages) {
32
+ const eslintProject = detectEslintProject(projectPath, packages);
33
+ if (eslintProject.hasDependency && !eslintProject.configFile && eslintProject.legacyConfigFile) {
34
+ warnLegacyEslintConfig(eslintProject.legacyConfigFile);
35
+ return false;
36
+ }
37
+ if (!eslintProject.hasDependency) return false;
38
+ if (!eslintProject.configFile) {
39
+ warnPackageLevelEslint();
40
+ return false;
41
+ }
42
+ if (!await confirmEslintMigration(interactive)) return false;
43
+ if (!await migrateEslintToOxlint(projectPath, interactive, eslintProject.configFile, packages)) cancelAndExit("ESLint migration failed. Fix the issue and re-run `vp migrate`.", 1);
44
+ return true;
45
+ }
46
+ function warnPackageLevelPrettier() {
47
+ log.warn("Prettier detected in workspace packages but no root config found. Package-level Prettier must be migrated manually.");
48
+ }
49
+ async function confirmPrettierMigration(interactive) {
50
+ if (interactive) {
51
+ const confirmed = await confirm({
52
+ message: "Migrate Prettier to Oxfmt?",
53
+ initialValue: true
54
+ });
55
+ if (Ct(confirmed)) cancelAndExit();
56
+ return !!confirmed;
57
+ }
58
+ log.info("Prettier configuration detected. Auto-migrating to Oxfmt...");
59
+ return true;
60
+ }
61
+ async function promptPrettierMigration(projectPath, interactive, packages) {
62
+ const prettierProject = detectPrettierProject(projectPath, packages);
63
+ if (!prettierProject.hasDependency) return false;
64
+ if (!prettierProject.configFile) {
65
+ warnPackageLevelPrettier();
66
+ return false;
67
+ }
68
+ if (!await confirmPrettierMigration(interactive)) return false;
69
+ if (!await migratePrettierToOxfmt(projectPath, interactive, prettierProject.configFile, packages)) cancelAndExit("Prettier migration failed. Fix the issue and re-run `vp migrate`.", 1);
70
+ return true;
71
+ }
17
72
  const helpMessage = renderCliDoc({
18
73
  usage: "vp migrate [PATH] [OPTIONS]",
19
- summary: "Migrate standalone Vite, Vitest, Oxlint, and Oxfmt projects to unified Vite+.",
74
+ summary: "Migrate standalone Vite, Vitest, Oxlint, Oxfmt, and Prettier projects to unified Vite+.",
20
75
  sections: [
21
76
  {
22
77
  title: "Arguments",
@@ -78,8 +133,7 @@ const helpMessage = renderCliDoc({
78
133
  ]
79
134
  });
80
135
  function parseArgs() {
81
- const args = process.argv.slice(3);
82
- const parsed = lib_default(args, {
136
+ const parsed = lib_default(process.argv.slice(3), {
83
137
  alias: { h: "help" },
84
138
  boolean: [
85
139
  "help",
@@ -90,11 +144,8 @@ function parseArgs() {
90
144
  });
91
145
  const interactive = parsed.interactive;
92
146
  let projectPath = parsed._[0];
93
- if (projectPath) {
94
- projectPath = path.resolve(process.cwd(), projectPath);
95
- } else {
96
- projectPath = process.cwd();
97
- }
147
+ if (projectPath) projectPath = path.resolve(process.cwd(), projectPath);
148
+ else projectPath = process.cwd();
98
149
  return {
99
150
  projectPath,
100
151
  options: {
@@ -106,112 +157,305 @@ function parseArgs() {
106
157
  }
107
158
  };
108
159
  }
109
- async function main() {
110
- const { projectPath, options } = parseArgs();
111
- if (options.help) {
112
- log$1(vitePlusHeader() + "\n");
113
- log$1(helpMessage);
114
- return;
115
- }
116
- intro(vitePlusHeader());
117
- const workspaceInfoOptional = await detectWorkspace$1(projectPath);
118
- const rootPkg = readNearestPackageJson(workspaceInfoOptional.rootDir);
119
- if (hasVitePlusDependency(rootPkg)) {
120
- const hasHooksToMigrate = rootPkg?.devDependencies?.husky || rootPkg?.dependencies?.husky || rootPkg?.devDependencies?.["lint-staged"] || rootPkg?.dependencies?.["lint-staged"];
121
- if (!hasHooksToMigrate) {
122
- outro(`This project is already using Vite+! ${accent(`Happy coding!`)}`);
123
- return;
124
- }
125
- const shouldSetupHooks = await promptGitHooks(options);
126
- if (shouldSetupHooks && installGitHooks(workspaceInfoOptional.rootDir)) {
127
- outro(green("✔ Migration completed!"));
128
- } else {
129
- outro(`This project is already using Vite+! ${accent(`Happy coding!`)}`);
130
- }
131
- return;
132
- }
133
- if (options.interactive) {
134
- log.info([
135
- styleText("bold", "Migration plan:"),
136
- "- Inspect workspace and package manager",
137
- `- Run ${accent("vp install")} to prepare dependencies`,
138
- "- Rewrite configs and dependencies for Vite+"
139
- ].join("\n") + "\n");
140
- const approved = await confirm({
141
- message: "Migrate this project to Vite+?",
142
- initialValue: true
143
- });
144
- if (Ct(approved) || !approved) {
145
- cancelAndExit("Migration cancelled");
160
+ async function collectMigrationPlan(rootDir, detectedPackageManager, options, packages) {
161
+ const packageManager = detectedPackageManager ?? await selectPackageManager(options.interactive, true);
162
+ let shouldSetupHooks = await promptGitHooks(options);
163
+ if (shouldSetupHooks) {
164
+ const reason = preflightGitHooksSetup(rootDir);
165
+ if (reason) {
166
+ log.warn(`⚠ ${reason}`);
167
+ shouldSetupHooks = false;
146
168
  }
147
169
  }
148
- const packageManager = workspaceInfoOptional.packageManager ?? await selectPackageManager(options.interactive);
149
- let shouldSetupHooks = await promptGitHooks(options);
150
170
  const selectedAgentTargetPaths = await selectAgentTargetPaths({
151
171
  interactive: options.interactive,
152
172
  agent: options.agent,
153
173
  onCancel: () => cancelAndExit()
154
174
  });
175
+ const agentConflicts = await detectAgentConflicts({
176
+ projectRoot: rootDir,
177
+ targetPaths: selectedAgentTargetPaths
178
+ });
179
+ const agentConflictDecisions = /* @__PURE__ */ new Map();
180
+ for (const conflict of agentConflicts) if (options.interactive) {
181
+ const action = await select({
182
+ message: `Agent instructions already exist at ${conflict.targetPath}.`,
183
+ options: [{
184
+ label: "Append",
185
+ value: "append",
186
+ hint: "Add template content to the end"
187
+ }, {
188
+ label: "Skip",
189
+ value: "skip",
190
+ hint: "Leave existing file unchanged"
191
+ }],
192
+ initialValue: "skip"
193
+ });
194
+ if (Ct(action)) cancelAndExit();
195
+ agentConflictDecisions.set(conflict.targetPath, action);
196
+ } else agentConflictDecisions.set(conflict.targetPath, "skip");
155
197
  const selectedEditor = await selectEditor({
156
198
  interactive: options.interactive,
157
199
  editor: options.editor,
158
200
  onCancel: () => cancelAndExit()
159
201
  });
160
- const downloadResult = await downloadPackageManager$1(packageManager, workspaceInfoOptional.packageManagerVersion, options.interactive);
202
+ const editorConflicts = detectEditorConflicts({
203
+ projectRoot: rootDir,
204
+ editorId: selectedEditor
205
+ });
206
+ const editorConflictDecisions = /* @__PURE__ */ new Map();
207
+ for (const conflict of editorConflicts) if (options.interactive) {
208
+ const action = await select({
209
+ message: `${conflict.displayPath} already exists.`,
210
+ options: [{
211
+ label: "Merge",
212
+ value: "merge",
213
+ hint: "Merge new settings into existing file"
214
+ }, {
215
+ label: "Skip",
216
+ value: "skip",
217
+ hint: "Leave existing file unchanged"
218
+ }],
219
+ initialValue: "skip"
220
+ });
221
+ if (Ct(action)) cancelAndExit();
222
+ editorConflictDecisions.set(conflict.fileName, action);
223
+ } else editorConflictDecisions.set(conflict.fileName, "merge");
224
+ const eslintProject = detectEslintProject(rootDir, packages);
225
+ let migrateEslint = false;
226
+ if (eslintProject.hasDependency && !eslintProject.configFile && eslintProject.legacyConfigFile) warnLegacyEslintConfig(eslintProject.legacyConfigFile);
227
+ else if (eslintProject.hasDependency && eslintProject.configFile) migrateEslint = await confirmEslintMigration(options.interactive);
228
+ else if (eslintProject.hasDependency) warnPackageLevelEslint();
229
+ const prettierProject = detectPrettierProject(rootDir, packages);
230
+ let migratePrettier = false;
231
+ if (prettierProject.hasDependency && prettierProject.configFile) migratePrettier = await confirmPrettierMigration(options.interactive);
232
+ else if (prettierProject.hasDependency) warnPackageLevelPrettier();
233
+ return {
234
+ packageManager,
235
+ shouldSetupHooks,
236
+ selectedAgentTargetPaths,
237
+ agentConflictDecisions,
238
+ selectedEditor,
239
+ editorConflictDecisions,
240
+ migrateEslint,
241
+ eslintConfigFile: eslintProject.configFile,
242
+ migratePrettier,
243
+ prettierConfigFile: prettierProject.configFile
244
+ };
245
+ }
246
+ function formatDuration(durationMs) {
247
+ if (durationMs < 1e3) return `${Math.max(1, durationMs)}ms`;
248
+ const durationSeconds = durationMs / 1e3;
249
+ if (durationSeconds < 10) return `${durationSeconds.toFixed(1)}s`;
250
+ return `${Math.round(durationSeconds)}s`;
251
+ }
252
+ function showMigrationSummary(options) {
253
+ const { projectRoot, packageManager, packageManagerVersion, installDurationMs, report, updatedExistingVitePlus } = options;
254
+ const projectLabel = displayRelative(projectRoot) || ".";
255
+ const configUpdates = report.createdViteConfigCount + report.mergedConfigCount + report.mergedStagedConfigCount + report.inlinedLintStagedConfigCount + report.removedConfigCount + report.tsdownImportCount;
256
+ log$1(`${styleText("magenta", "◇")} ${updatedExistingVitePlus ? "Updated" : "Migrated"} ${accent(projectLabel)}${updatedExistingVitePlus ? "" : " to Vite+"}`);
257
+ log$1(`${styleText("gray", "•")} Node ${process.versions.node} ${packageManager} ${packageManagerVersion}`);
258
+ if (installDurationMs > 0) log$1(`${styleText("green", "✓")} Dependencies installed in ${formatDuration(installDurationMs)}`);
259
+ if (configUpdates > 0 || report.rewrittenImportFileCount > 0) {
260
+ const parts = [];
261
+ if (configUpdates > 0) parts.push(`${configUpdates} ${configUpdates === 1 ? "config update" : "config updates"} applied`);
262
+ if (report.rewrittenImportFileCount > 0) parts.push(`${report.rewrittenImportFileCount} ${report.rewrittenImportFileCount === 1 ? "file had" : "files had"} imports rewritten`);
263
+ log$1(`${styleText("gray", "•")} ${parts.join(", ")}`);
264
+ }
265
+ if (report.eslintMigrated) log$1(`${styleText("gray", "•")} ESLint rules migrated to Oxlint`);
266
+ if (report.prettierMigrated) log$1(`${styleText("gray", "•")} Prettier migrated to Oxfmt`);
267
+ if (report.gitHooksConfigured) log$1(`${styleText("gray", "•")} Git hooks configured`);
268
+ if (report.warnings.length > 0) {
269
+ log$1(`${styleText("yellow", "!")} Warnings:`);
270
+ for (const warning of report.warnings) log$1(` - ${warning}`);
271
+ }
272
+ if (report.manualSteps.length > 0) {
273
+ log$1(`${styleText("blue", "→")} Manual follow-up:`);
274
+ for (const step of report.manualSteps) log$1(` - ${step}`);
275
+ }
276
+ }
277
+ async function executeMigrationPlan(workspaceInfoOptional, plan, interactive) {
278
+ const report = createMigrationReport();
279
+ const migrationProgress = interactive ? spinner({ indicator: "timer" }) : void 0;
280
+ let migrationProgressStarted = false;
281
+ const updateMigrationProgress = (message) => {
282
+ if (!migrationProgress) return;
283
+ if (migrationProgressStarted) {
284
+ migrationProgress.message(message);
285
+ return;
286
+ }
287
+ migrationProgress.start(message);
288
+ migrationProgressStarted = true;
289
+ };
290
+ const clearMigrationProgress = () => {
291
+ if (migrationProgress && migrationProgressStarted) {
292
+ migrationProgress.clear();
293
+ migrationProgressStarted = false;
294
+ }
295
+ };
296
+ const failMigrationProgress = (message) => {
297
+ if (migrationProgress && migrationProgressStarted) {
298
+ migrationProgress.error(message);
299
+ migrationProgressStarted = false;
300
+ }
301
+ };
302
+ updateMigrationProgress("Preparing migration");
303
+ const downloadResult = await downloadPackageManager$1(plan.packageManager, workspaceInfoOptional.packageManagerVersion, interactive, true);
161
304
  const workspaceInfo = {
162
305
  ...workspaceInfoOptional,
163
- packageManager,
306
+ packageManager: plan.packageManager,
164
307
  downloadPackageManager: downloadResult
165
308
  };
166
- if (packageManager === PackageManager.yarn && import_semver.default.satisfies(downloadResult.version, ">=4.0.0 <4.10.0")) {
167
- await upgradeYarn(workspaceInfo.rootDir, options.interactive);
168
- } else if (packageManager === PackageManager.pnpm && import_semver.default.satisfies(downloadResult.version, "< 9.5.0")) {
309
+ if (plan.packageManager === PackageManager.yarn && import_semver.default.satisfies(downloadResult.version, ">=4.0.0 <4.10.0")) {
310
+ updateMigrationProgress("Upgrading Yarn");
311
+ await upgradeYarn(workspaceInfo.rootDir, interactive, true);
312
+ } else if (plan.packageManager === PackageManager.pnpm && import_semver.default.satisfies(downloadResult.version, "< 9.5.0")) {
313
+ failMigrationProgress("Migration failed");
169
314
  log.error(`✘ pnpm@${downloadResult.version} is not supported by auto migration, please upgrade pnpm to >=9.5.0 first`);
170
315
  cancelAndExit("Vite+ cannot automatically migrate this project yet.", 1);
171
- } else if (packageManager === PackageManager.npm && import_semver.default.satisfies(downloadResult.version, "< 8.3.0")) {
316
+ } else if (plan.packageManager === PackageManager.npm && import_semver.default.satisfies(downloadResult.version, "< 8.3.0")) {
317
+ failMigrationProgress("Migration failed");
172
318
  log.error(`✘ npm@${downloadResult.version} is not supported by auto migration, please upgrade npm to >=8.3.0 first`);
173
319
  cancelAndExit("Vite+ cannot automatically migrate this project yet.", 1);
174
320
  }
175
- await runViteInstall(workspaceInfo.rootDir, options.interactive);
321
+ updateMigrationProgress("Installing dependencies");
322
+ const initialInstallSummary = await runViteInstall(workspaceInfo.rootDir, interactive, void 0, { silent: true });
323
+ updateMigrationProgress("Validating toolchain");
176
324
  const isViteSupported = checkViteVersion(workspaceInfo.rootDir);
177
325
  const isVitestSupported = checkVitestVersion(workspaceInfo.rootDir);
178
326
  if (!isViteSupported || !isVitestSupported) {
327
+ failMigrationProgress("Migration failed");
179
328
  cancelAndExit("Vite+ cannot automatically migrate this project yet.", 1);
180
329
  }
181
- if (shouldSetupHooks) {
182
- const reason = preflightGitHooksSetup(workspaceInfo.rootDir);
183
- if (reason) {
184
- log.warn(`⚠ ${reason}`);
185
- shouldSetupHooks = false;
330
+ if (plan.migrateEslint) {
331
+ updateMigrationProgress("Migrating ESLint");
332
+ if (!await migrateEslintToOxlint(workspaceInfo.rootDir, interactive, plan.eslintConfigFile, workspaceInfo.packages, {
333
+ silent: true,
334
+ report
335
+ })) {
336
+ failMigrationProgress("Migration failed");
337
+ cancelAndExit("ESLint migration failed. Fix the issue and re-run `vp migrate`.", 1);
186
338
  }
187
339
  }
188
- const skipStagedMigration = !shouldSetupHooks;
189
- if (workspaceInfo.isMonorepo) {
190
- rewriteMonorepo(workspaceInfo, skipStagedMigration);
191
- } else {
192
- rewriteStandaloneProject(workspaceInfo.rootDir, workspaceInfo, skipStagedMigration);
340
+ if (plan.migratePrettier) {
341
+ updateMigrationProgress("Migrating Prettier");
342
+ if (!await migratePrettierToOxfmt(workspaceInfo.rootDir, interactive, plan.prettierConfigFile, workspaceInfo.packages, {
343
+ silent: true,
344
+ report
345
+ })) {
346
+ failMigrationProgress("Migration failed");
347
+ cancelAndExit("Prettier migration failed. Fix the issue and re-run `vp migrate`.", 1);
348
+ }
193
349
  }
194
- if (shouldSetupHooks) {
195
- installGitHooks(workspaceInfo.rootDir);
350
+ const skipStagedMigration = !plan.shouldSetupHooks;
351
+ updateMigrationProgress("Rewriting configs");
352
+ if (workspaceInfo.isMonorepo) rewriteMonorepo(workspaceInfo, skipStagedMigration, true, report);
353
+ else rewriteStandaloneProject(workspaceInfo.rootDir, workspaceInfo, skipStagedMigration, true, report);
354
+ if (plan.shouldSetupHooks) {
355
+ updateMigrationProgress("Configuring git hooks");
356
+ installGitHooks(workspaceInfo.rootDir, true, report);
196
357
  }
358
+ updateMigrationProgress("Writing agent instructions");
197
359
  await writeAgentInstructions({
198
360
  projectRoot: workspaceInfo.rootDir,
199
- targetPaths: selectedAgentTargetPaths,
200
- interactive: options.interactive
361
+ targetPaths: plan.selectedAgentTargetPaths,
362
+ interactive,
363
+ conflictDecisions: plan.agentConflictDecisions,
364
+ silent: true
201
365
  });
366
+ updateMigrationProgress("Writing editor configs");
202
367
  await writeEditorConfigs({
203
368
  projectRoot: workspaceInfo.rootDir,
204
- editorId: selectedEditor,
205
- interactive: options.interactive
369
+ editorId: plan.selectedEditor,
370
+ interactive,
371
+ conflictDecisions: plan.editorConflictDecisions,
372
+ silent: true
373
+ });
374
+ const installArgs = plan.packageManager === PackageManager.npm ? ["--force"] : void 0;
375
+ updateMigrationProgress("Installing dependencies");
376
+ const finalInstallSummary = await runViteInstall(workspaceInfo.rootDir, interactive, installArgs, { silent: true });
377
+ clearMigrationProgress();
378
+ return {
379
+ installDurationMs: initialInstallSummary.durationMs + finalInstallSummary.durationMs,
380
+ packageManagerVersion: downloadResult.version,
381
+ report
382
+ };
383
+ }
384
+ async function main() {
385
+ const { projectPath, options } = parseArgs();
386
+ if (options.help) {
387
+ log$1(vitePlusHeader() + "\n");
388
+ log$1(helpMessage);
389
+ return;
390
+ }
391
+ log$1(`${vitePlusHeader()}\n`);
392
+ const workspaceInfoOptional = await detectWorkspace$1(projectPath);
393
+ const resolvedPackageManager = workspaceInfoOptional.packageManager ?? "unknown";
394
+ const rootPkg = readNearestPackageJson(workspaceInfoOptional.rootDir);
395
+ if (hasVitePlusDependency(rootPkg)) {
396
+ let didMigrate = false;
397
+ let installDurationMs = 0;
398
+ const report = createMigrationReport();
399
+ const migrationProgress = options.interactive ? spinner({ indicator: "timer" }) : void 0;
400
+ let migrationProgressStarted = false;
401
+ const updateMigrationProgress = (message) => {
402
+ if (!migrationProgress) return;
403
+ if (migrationProgressStarted) {
404
+ migrationProgress.message(message);
405
+ return;
406
+ }
407
+ migrationProgress.start(message);
408
+ migrationProgressStarted = true;
409
+ };
410
+ const clearMigrationProgress = () => {
411
+ if (migrationProgress && migrationProgressStarted) {
412
+ migrationProgress.clear();
413
+ migrationProgressStarted = false;
414
+ }
415
+ };
416
+ const eslintMigrated = await promptEslintMigration(workspaceInfoOptional.rootDir, options.interactive, workspaceInfoOptional.packages);
417
+ const prettierMigrated = await promptPrettierMigration(workspaceInfoOptional.rootDir, options.interactive, workspaceInfoOptional.packages);
418
+ if (eslintMigrated || prettierMigrated) {
419
+ updateMigrationProgress("Rewriting configs");
420
+ mergeViteConfigFiles(workspaceInfoOptional.rootDir, true, report);
421
+ updateMigrationProgress("Installing dependencies");
422
+ const installSummary = await runViteInstall(workspaceInfoOptional.rootDir, options.interactive, void 0, { silent: true });
423
+ installDurationMs += installSummary.durationMs;
424
+ didMigrate = true;
425
+ report.eslintMigrated = eslintMigrated;
426
+ report.prettierMigrated = prettierMigrated;
427
+ }
428
+ if (rootPkg?.devDependencies?.husky || rootPkg?.dependencies?.husky || rootPkg?.devDependencies?.["lint-staged"] || rootPkg?.dependencies?.["lint-staged"]) {
429
+ const shouldSetupHooks = await promptGitHooks(options);
430
+ if (shouldSetupHooks) updateMigrationProgress("Configuring git hooks");
431
+ if (shouldSetupHooks && installGitHooks(workspaceInfoOptional.rootDir, true, report)) didMigrate = true;
432
+ }
433
+ if (didMigrate) {
434
+ clearMigrationProgress();
435
+ showMigrationSummary({
436
+ projectRoot: workspaceInfoOptional.rootDir,
437
+ packageManager: resolvedPackageManager,
438
+ packageManagerVersion: workspaceInfoOptional.packageManagerVersion,
439
+ installDurationMs,
440
+ report,
441
+ updatedExistingVitePlus: true
442
+ });
443
+ } else outro(`This project is already using Vite+! ${accent(`Happy coding!`)}`);
444
+ return;
445
+ }
446
+ const plan = await collectMigrationPlan(workspaceInfoOptional.rootDir, workspaceInfoOptional.packageManager, options, workspaceInfoOptional.packages);
447
+ const result = await executeMigrationPlan(workspaceInfoOptional, plan, options.interactive);
448
+ showMigrationSummary({
449
+ projectRoot: workspaceInfoOptional.rootDir,
450
+ packageManager: plan.packageManager,
451
+ packageManagerVersion: result.packageManagerVersion,
452
+ installDurationMs: result.installDurationMs,
453
+ report: result.report
206
454
  });
207
- const installArgs = packageManager === PackageManager.npm ? ["--force"] : undefined;
208
- await runViteInstall(workspaceInfo.rootDir, options.interactive, installArgs);
209
- outro(green("✔ Migration completed!"));
210
455
  }
211
456
  main().catch((err) => {
212
457
  log.error(err.message);
213
458
  console.error(err);
214
459
  process.exit(1);
215
460
  });
216
-
217
- //#endregion
461
+ //#endregion
@@ -1,19 +1,15 @@
1
- import { o as VITE_PLUS_NAME, r as readJsonFile } from "./json-Bfvtp2rL.js";
1
+ import { r as readJsonFile } from "./json-BRdVJ52a.js";
2
2
  import path from "node:path";
3
3
  import fs from "node:fs";
4
4
  import { createRequire } from "node:module";
5
-
6
5
  //#region src/utils/package.ts
7
6
  function getScopeFromPackageName(packageName) {
8
- if (packageName.startsWith("@")) {
9
- return packageName.split("/")[0];
10
- }
7
+ if (packageName.startsWith("@")) return packageName.split("/")[0];
11
8
  return "";
12
9
  }
13
10
  function detectPackageMetadata(projectPath, packageName) {
14
11
  try {
15
- const require = createRequire(path.join(projectPath, "noop.js"));
16
- const pkgFilePath = require.resolve(`${packageName}/package.json`);
12
+ const pkgFilePath = createRequire(path.join(projectPath, "noop.js")).resolve(`${packageName}/package.json`);
17
13
  const pkg = JSON.parse(fs.readFileSync(pkgFilePath, "utf8"));
18
14
  return {
19
15
  name: pkg.name,
@@ -32,16 +28,13 @@ function detectPackageMetadata(projectPath, packageName) {
32
28
  function readNearestPackageJson(currentDir) {
33
29
  do {
34
30
  const packageJsonPath = path.join(currentDir, "package.json");
35
- if (fs.existsSync(packageJsonPath)) {
36
- return readJsonFile(packageJsonPath);
37
- }
31
+ if (fs.existsSync(packageJsonPath)) return readJsonFile(packageJsonPath);
38
32
  currentDir = path.dirname(currentDir);
39
33
  } while (currentDir !== path.dirname(currentDir));
40
34
  return null;
41
35
  }
42
36
  function hasVitePlusDependency(pkg) {
43
- return Boolean(pkg?.dependencies?.[VITE_PLUS_NAME] || pkg?.devDependencies?.[VITE_PLUS_NAME]);
37
+ return Boolean(pkg?.dependencies?.["vite-plus"] || pkg?.devDependencies?.["vite-plus"]);
44
38
  }
45
-
46
39
  //#endregion
47
- export { readNearestPackageJson as i, getScopeFromPackageName as n, hasVitePlusDependency as r, detectPackageMetadata as t };
40
+ export { readNearestPackageJson as i, getScopeFromPackageName as n, hasVitePlusDependency as r, detectPackageMetadata as t };
@@ -1,48 +1,34 @@
1
- import { a as ansiStyles, i as isWide, r as isFullWidth } from "./strip-ansi-BL-dgd7n.js";
2
-
1
+ import { a as ansiStyles, i as isWide, r as isFullWidth } from "./strip-ansi-CE-VDMdw.js";
3
2
  //#region ../../node_modules/.pnpm/is-fullwidth-code-point@5.1.0/node_modules/is-fullwidth-code-point/index.js
4
3
  function isFullwidthCodePoint(codePoint) {
5
- if (!Number.isInteger(codePoint)) {
6
- return false;
7
- }
4
+ if (!Number.isInteger(codePoint)) return false;
8
5
  return isFullWidth(codePoint) || isWide(codePoint);
9
6
  }
10
-
11
7
  //#endregion
12
8
  //#region ../../node_modules/.pnpm/slice-ansi@7.1.2/node_modules/slice-ansi/index.js
13
9
  const ESCAPES = new Set([27, 155]);
14
10
  const CODE_POINT_0 = "0".codePointAt(0);
15
11
  const CODE_POINT_9 = "9".codePointAt(0);
16
12
  const MAX_ANSI_SEQUENCE_LENGTH = 19;
17
- const endCodesSet = new Set();
18
- const endCodesMap = new Map();
13
+ const endCodesSet = /* @__PURE__ */ new Set();
14
+ const endCodesMap = /* @__PURE__ */ new Map();
19
15
  for (const [start, end] of ansiStyles.codes) {
20
16
  endCodesSet.add(ansiStyles.color.ansi(end));
21
17
  endCodesMap.set(ansiStyles.color.ansi(start), ansiStyles.color.ansi(end));
22
18
  }
23
19
  function getEndCode(code) {
24
- if (endCodesSet.has(code)) {
25
- return code;
26
- }
27
- if (endCodesMap.has(code)) {
28
- return endCodesMap.get(code);
29
- }
20
+ if (endCodesSet.has(code)) return code;
21
+ if (endCodesMap.has(code)) return endCodesMap.get(code);
30
22
  code = code.slice(2);
31
- if (code.includes(";")) {
32
- code = code[0] + "0";
33
- }
23
+ if (code.includes(";")) code = code[0] + "0";
34
24
  const returnValue = ansiStyles.codes.get(Number.parseInt(code, 10));
35
- if (returnValue) {
36
- return ansiStyles.color.ansi(returnValue);
37
- }
25
+ if (returnValue) return ansiStyles.color.ansi(returnValue);
38
26
  return ansiStyles.reset.open;
39
27
  }
40
28
  function findNumberIndex(string) {
41
29
  for (let index = 0; index < string.length; index++) {
42
30
  const codePoint = string.codePointAt(index);
43
- if (codePoint >= CODE_POINT_0 && codePoint <= CODE_POINT_9) {
44
- return index;
45
- }
31
+ if (codePoint >= CODE_POINT_0 && codePoint <= CODE_POINT_9) return index;
46
32
  }
47
33
  return -1;
48
34
  }
@@ -51,9 +37,7 @@ function parseAnsiCode(string, offset) {
51
37
  const startIndex = findNumberIndex(string);
52
38
  if (startIndex !== -1) {
53
39
  let endIndex = string.indexOf("m", startIndex);
54
- if (endIndex === -1) {
55
- endIndex = string.length;
56
- }
40
+ if (endIndex === -1) endIndex = string.length;
57
41
  return string.slice(0, endIndex + 1);
58
42
  }
59
43
  }
@@ -84,30 +68,22 @@ function tokenize(string, endCharacter = Number.POSITIVE_INFINITY) {
84
68
  });
85
69
  index += character.length;
86
70
  visibleCount += isFullWidth ? 2 : character.length;
87
- if (visibleCount >= endCharacter) {
88
- break;
89
- }
71
+ if (visibleCount >= endCharacter) break;
90
72
  }
91
73
  return returnValue;
92
74
  }
93
75
  function reduceAnsiCodes(codes) {
94
76
  let returnValue = [];
95
- for (const code of codes) {
96
- if (code.code === ansiStyles.reset.open) {
97
- returnValue = [];
98
- } else if (endCodesSet.has(code.code)) {
99
- returnValue = returnValue.filter((returnValueCode) => returnValueCode.endCode !== code.code);
100
- } else {
101
- returnValue = returnValue.filter((returnValueCode) => returnValueCode.endCode !== code.endCode);
102
- returnValue.push(code);
103
- }
77
+ for (const code of codes) if (code.code === ansiStyles.reset.open) returnValue = [];
78
+ else if (endCodesSet.has(code.code)) returnValue = returnValue.filter((returnValueCode) => returnValueCode.endCode !== code.code);
79
+ else {
80
+ returnValue = returnValue.filter((returnValueCode) => returnValueCode.endCode !== code.endCode);
81
+ returnValue.push(code);
104
82
  }
105
83
  return returnValue;
106
84
  }
107
85
  function undoAnsiCodes(codes) {
108
- const reduced = reduceAnsiCodes(codes);
109
- const endCodes = reduced.map(({ endCode }) => endCode);
110
- return endCodes.reverse().join("");
86
+ return reduceAnsiCodes(codes).map(({ endCode }) => endCode).reverse().join("");
111
87
  }
112
88
  function sliceAnsi(string, start, end) {
113
89
  const tokens = tokenize(string, end);
@@ -116,29 +92,22 @@ function sliceAnsi(string, start, end) {
116
92
  let returnValue = "";
117
93
  let include = false;
118
94
  for (const token of tokens) {
119
- if (end !== undefined && position >= end) {
120
- break;
121
- }
95
+ if (end !== void 0 && position >= end) break;
122
96
  if (token.type === "ansi") {
123
97
  activeCodes.push(token);
124
- if (include) {
125
- returnValue += token.code;
126
- }
98
+ if (include) returnValue += token.code;
127
99
  } else {
128
100
  if (!include && position >= start) {
129
101
  include = true;
130
102
  activeCodes = reduceAnsiCodes(activeCodes);
131
103
  returnValue = activeCodes.map(({ code }) => code).join("");
132
104
  }
133
- if (include) {
134
- returnValue += token.value;
135
- }
105
+ if (include) returnValue += token.value;
136
106
  position += token.isFullWidth ? 2 : token.value.length;
137
107
  }
138
108
  }
139
109
  returnValue += undoAnsiCodes(activeCodes);
140
110
  return returnValue;
141
111
  }
142
-
143
112
  //#endregion
144
- export { sliceAnsi as t };
113
+ export { sliceAnsi as t };