vite-plus 0.1.15-alpha.2 → 0.1.15-alpha.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.
- package/dist/global/{agent-D98pS-to.js → agent-DE6dQKO4.js} +83 -5
- package/dist/global/{compat-Ch3iWOnQ.js → compat-CiHwUbA_.js} +1 -1
- package/dist/global/config.js +1 -1
- package/dist/global/create.js +3 -3
- package/dist/global/migrate.js +31 -6
- package/dist/global/{package-Y1UTfJnZ.js → package-CnlCtq4D.js} +538 -15
- package/dist/global/{report-C7xbSNED.js → report-DGaKL5VQ.js} +1 -0
- package/dist/global/version.js +1 -1
- package/dist/global/{workspace-CIZWj4FM.js → workspace-j8KWxSkv.js} +2 -2
- package/dist/migration/detector.d.ts +1 -0
- package/dist/migration/detector.js +4 -0
- package/dist/migration/migrator.d.ts +19 -0
- package/dist/migration/migrator.js +95 -2
- package/dist/migration/report.d.ts +1 -0
- package/dist/migration/report.js +1 -0
- package/dist/utils/tsconfig.d.ts +2 -0
- package/dist/utils/tsconfig.js +37 -0
- package/package.json +14 -14
- package/templates/monorepo/README.md +2 -2
- package/templates/monorepo/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { r as __toESM, t as __commonJSMin } from "./chunk-BoAXSpZd.js";
|
|
2
2
|
import { _ as YAMLMap, g as YAMLSeq, i as parseDocument, n as parse, y as Scalar } from "./browser-09BZLUYM.js";
|
|
3
|
-
import { c as readJsonFile, d as
|
|
3
|
+
import { _ as isForceOverrideMode, c as readJsonFile, d as modify, f as parse$1, g as VITE_PLUS_VERSION, h as VITE_PLUS_OVERRIDE_PACKAGES, m as VITE_PLUS_NAME, n as detectPackageMetadata, o as editJsonFile, p as BASEURL_TSCONFIG_WARNING, s as isJsonFile, u as applyEdits } from "./package-CnlCtq4D.js";
|
|
4
4
|
import { n as accent } from "./help-HviKaKAU.js";
|
|
5
|
-
import { n as addMigrationWarning, t as addManualStep } from "./report-
|
|
5
|
+
import { n as addMigrationWarning, t as addManualStep } from "./report-DGaKL5VQ.js";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { stripVTControlCharacters, styleText } from "node:util";
|
|
8
8
|
import process$1, { stdin, stdout } from "node:process";
|
|
@@ -3061,6 +3061,28 @@ function hasBaseUrlInTsconfig(projectPath) {
|
|
|
3061
3061
|
return false;
|
|
3062
3062
|
}
|
|
3063
3063
|
}
|
|
3064
|
+
const TSCONFIG_FILE_RE = /^tsconfig(\.[\w-]+)?\.json$/i;
|
|
3065
|
+
function findTsconfigFiles(projectPath) {
|
|
3066
|
+
try {
|
|
3067
|
+
return fs.readdirSync(projectPath).filter((name) => TSCONFIG_FILE_RE.test(name)).map((name) => path.join(projectPath, name));
|
|
3068
|
+
} catch {
|
|
3069
|
+
return [];
|
|
3070
|
+
}
|
|
3071
|
+
}
|
|
3072
|
+
function removeDeprecatedTsconfigFalseOption(filePath, optionName) {
|
|
3073
|
+
let text;
|
|
3074
|
+
try {
|
|
3075
|
+
text = fs.readFileSync(filePath, "utf-8");
|
|
3076
|
+
} catch {
|
|
3077
|
+
return false;
|
|
3078
|
+
}
|
|
3079
|
+
if (parse$1(text)?.compilerOptions?.[optionName] !== false) return false;
|
|
3080
|
+
const edits = modify(text, ["compilerOptions", optionName], void 0, {});
|
|
3081
|
+
if (edits.length === 0) return false;
|
|
3082
|
+
const newText = applyEdits(text, edits);
|
|
3083
|
+
fs.writeFileSync(filePath, newText);
|
|
3084
|
+
return true;
|
|
3085
|
+
}
|
|
3064
3086
|
//#endregion
|
|
3065
3087
|
//#region src/utils/yaml.ts
|
|
3066
3088
|
function readYamlFile(file) {
|
|
@@ -3176,6 +3198,7 @@ function detectConfigs(projectPath) {
|
|
|
3176
3198
|
} catch {}
|
|
3177
3199
|
}
|
|
3178
3200
|
if (fs.existsSync(path.join(projectPath, ".prettierignore"))) configs.prettierIgnore = true;
|
|
3201
|
+
if (fs.existsSync(path.join(projectPath, ".nvmrc"))) configs.nvmrcFile = true;
|
|
3179
3202
|
return configs;
|
|
3180
3203
|
}
|
|
3181
3204
|
//#endregion
|
|
@@ -3541,6 +3564,15 @@ function rewritePrettierPackageJson(packageJsonPath) {
|
|
|
3541
3564
|
function rewritePrettierLintStagedConfigFiles(projectPath, report) {
|
|
3542
3565
|
rewriteToolLintStagedConfigFiles(projectPath, rewritePrettier, "prettier", report);
|
|
3543
3566
|
}
|
|
3567
|
+
function cleanupDeprecatedTsconfigOptions(projectPath, silent = false, report) {
|
|
3568
|
+
const deprecatedOptions = ["esModuleInterop", "allowSyntheticDefaultImports"];
|
|
3569
|
+
const files = findTsconfigFiles(projectPath);
|
|
3570
|
+
for (const filePath of files) for (const name of deprecatedOptions) if (removeDeprecatedTsconfigFalseOption(filePath, name)) {
|
|
3571
|
+
if (report) report.removedConfigCount++;
|
|
3572
|
+
if (!silent) log.success(`✔ Removed ${name}: false from ${displayRelative(filePath)}`);
|
|
3573
|
+
warnMigration(`Removed \`"${name}": false\` from ${displayRelative(filePath)} — this option has been deprecated. See https://github.com/oxc-project/tsgolint/issues/351, https://github.com/microsoft/TypeScript/issues/62529`, report);
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3544
3576
|
/**
|
|
3545
3577
|
* Rewrite standalone project to add vite-plus dependencies
|
|
3546
3578
|
* @param projectPath - The path to the project
|
|
@@ -3564,13 +3596,14 @@ function rewriteStandaloneProject(projectPath, workspaceInfo, skipStagedMigratio
|
|
|
3564
3596
|
...pkg.pnpm,
|
|
3565
3597
|
overrides: {
|
|
3566
3598
|
...pkg.pnpm?.overrides,
|
|
3567
|
-
...VITE_PLUS_OVERRIDE_PACKAGES
|
|
3599
|
+
...VITE_PLUS_OVERRIDE_PACKAGES,
|
|
3600
|
+
...isForceOverrideMode() ? { [VITE_PLUS_NAME]: VITE_PLUS_VERSION } : {}
|
|
3568
3601
|
}
|
|
3569
3602
|
};
|
|
3570
3603
|
for (const key of [...Object.keys(VITE_PLUS_OVERRIDE_PACKAGES), ...REMOVE_PACKAGES]) if (pkg.resolutions?.[key]) delete pkg.resolutions[key];
|
|
3571
3604
|
}
|
|
3572
3605
|
extractedStagedConfig = rewritePackageJson(pkg, packageManager, false, skipStagedMigration);
|
|
3573
|
-
if (!pkg.devDependencies?.["vite-plus"]) pkg.devDependencies = {
|
|
3606
|
+
if (!pkg.devDependencies?.["vite-plus"] || isForceOverrideMode()) pkg.devDependencies = {
|
|
3574
3607
|
...pkg.devDependencies,
|
|
3575
3608
|
[VITE_PLUS_NAME]: VITE_PLUS_VERSION
|
|
3576
3609
|
};
|
|
@@ -3580,6 +3613,7 @@ function rewriteStandaloneProject(projectPath, workspaceInfo, skipStagedMigratio
|
|
|
3580
3613
|
if (mergeStagedConfigToViteConfig(projectPath, extractedStagedConfig, silent, report)) removeLintStagedFromPackageJson(packageJsonPath);
|
|
3581
3614
|
}
|
|
3582
3615
|
if (!skipStagedMigration) rewriteLintStagedConfigFile(projectPath, report);
|
|
3616
|
+
cleanupDeprecatedTsconfigOptions(projectPath, silent, report);
|
|
3583
3617
|
mergeViteConfigFiles(projectPath, silent, report);
|
|
3584
3618
|
injectLintTypeCheckDefaults(projectPath, silent, report);
|
|
3585
3619
|
injectFmtDefaults(projectPath, silent, report);
|
|
@@ -3598,6 +3632,7 @@ function rewriteMonorepo(workspaceInfo, skipStagedMigration, silent = false, rep
|
|
|
3598
3632
|
rewriteRootWorkspacePackageJson(workspaceInfo.rootDir, workspaceInfo.packageManager, skipStagedMigration);
|
|
3599
3633
|
for (const pkg of workspaceInfo.packages) rewriteMonorepoProject(path.join(workspaceInfo.rootDir, pkg.path), workspaceInfo.packageManager, skipStagedMigration, silent, report);
|
|
3600
3634
|
if (!skipStagedMigration) rewriteLintStagedConfigFile(workspaceInfo.rootDir, report);
|
|
3635
|
+
cleanupDeprecatedTsconfigOptions(workspaceInfo.rootDir, silent, report);
|
|
3601
3636
|
mergeViteConfigFiles(workspaceInfo.rootDir, silent, report);
|
|
3602
3637
|
injectLintTypeCheckDefaults(workspaceInfo.rootDir, silent, report);
|
|
3603
3638
|
injectFmtDefaults(workspaceInfo.rootDir, silent, report);
|
|
@@ -3610,6 +3645,7 @@ function rewriteMonorepo(workspaceInfo, skipStagedMigration, silent = false, rep
|
|
|
3610
3645
|
* @param projectPath - The path to the project
|
|
3611
3646
|
*/
|
|
3612
3647
|
function rewriteMonorepoProject(projectPath, packageManager, skipStagedMigration, silent = false, report) {
|
|
3648
|
+
cleanupDeprecatedTsconfigOptions(projectPath, silent, report);
|
|
3613
3649
|
mergeViteConfigFiles(projectPath, silent, report);
|
|
3614
3650
|
mergeTsdownConfigFile(projectPath, silent, report);
|
|
3615
3651
|
const packageJsonPath = path.join(projectPath, "package.json");
|
|
@@ -4326,6 +4362,48 @@ function setPackageManager(projectDir, downloadPackageManager) {
|
|
|
4326
4362
|
return pkg;
|
|
4327
4363
|
});
|
|
4328
4364
|
}
|
|
4365
|
+
/**
|
|
4366
|
+
* Detect a .nvmrc file in the project directory.
|
|
4367
|
+
* Returns undefined if not found or .node-version already exists.
|
|
4368
|
+
*/
|
|
4369
|
+
function detectNodeVersionManagerFile(projectPath) {
|
|
4370
|
+
if (fs.existsSync(path.join(projectPath, ".node-version"))) return;
|
|
4371
|
+
if (detectConfigs(projectPath).nvmrcFile) return { file: ".nvmrc" };
|
|
4372
|
+
}
|
|
4373
|
+
/**
|
|
4374
|
+
* Parse a version alias from a .nvmrc file into a .node-version compatible string.
|
|
4375
|
+
* Accepts the first line of .nvmrc (pre-trimmed).
|
|
4376
|
+
* Returns null for unsupported aliases like "system", "default", "iojs".
|
|
4377
|
+
*/
|
|
4378
|
+
function parseNvmrcVersion(alias) {
|
|
4379
|
+
const version = alias.trim();
|
|
4380
|
+
if (!version) return null;
|
|
4381
|
+
if (version === "node" || version === "stable") return "lts/*";
|
|
4382
|
+
if (version === "iojs" || version === "system" || version === "default") return null;
|
|
4383
|
+
if (version.startsWith("lts/")) return version;
|
|
4384
|
+
const normalized = version.startsWith("v") ? version.slice(1) : version;
|
|
4385
|
+
if (!normalized || !import_semver.default.validRange(normalized)) return null;
|
|
4386
|
+
return normalized;
|
|
4387
|
+
}
|
|
4388
|
+
/**
|
|
4389
|
+
* Migrate .nvmrc to .node-version and remove .nvmrc.
|
|
4390
|
+
* Returns true on success, false if migration was skipped or failed.
|
|
4391
|
+
*/
|
|
4392
|
+
function migrateNodeVersionManagerFile(projectPath, _detection, report) {
|
|
4393
|
+
const sourcePath = path.join(projectPath, ".nvmrc");
|
|
4394
|
+
const nodeVersionPath = path.join(projectPath, ".node-version");
|
|
4395
|
+
const originalAlias = fs.readFileSync(sourcePath, "utf8").split("\n")[0]?.trim() ?? "";
|
|
4396
|
+
const version = parseNvmrcVersion(originalAlias);
|
|
4397
|
+
if (!version) {
|
|
4398
|
+
warnMigration(".nvmrc contains an unsupported version alias. Create .node-version manually with your desired Node.js version.", report);
|
|
4399
|
+
return false;
|
|
4400
|
+
}
|
|
4401
|
+
if (version === "lts/*" && (originalAlias === "node" || originalAlias === "stable")) log.info(`"${originalAlias}" in .nvmrc is not a specific version; automatically mapping to "lts/*"`);
|
|
4402
|
+
fs.writeFileSync(nodeVersionPath, `${version}\n`);
|
|
4403
|
+
fs.unlinkSync(sourcePath);
|
|
4404
|
+
if (report) report.nodeVersionFileMigrated = true;
|
|
4405
|
+
return true;
|
|
4406
|
+
}
|
|
4329
4407
|
const AGENT_ALIASES = {
|
|
4330
4408
|
chatgpt: "chatgpt-codex",
|
|
4331
4409
|
codex: "chatgpt-codex"
|
|
@@ -4626,4 +4704,4 @@ function getMarkedRange(content, startMarker, endMarker) {
|
|
|
4626
4704
|
};
|
|
4627
4705
|
}
|
|
4628
4706
|
//#endregion
|
|
4629
|
-
export {
|
|
4707
|
+
export { selectPackageManager as A, log as B, readYamlFile as C, promptGitHooks as D, downloadPackageManager$1 as E, PackageManager as F, text as G, outro as H, require_semver as I, Ct as K, cancel as L, displayRelative as M, templatesDir as N, runViteFmt as O, DependencyType as P, confirm as R, editYamlFile as S, defaultInteractive as T, select as U, multiselect as V, spinner as W, migratePrettierToOxfmt as _, writeAgentInstructions as a, rewriteMonorepoProject as b, detectEslintProject as c, ensurePreCommitHook as d, hasStagedConfigInViteConfig as f, migrateNodeVersionManagerFile as g, migrateEslintToOxlint as h, updateExistingAgentInstructions as i, upgradeYarn as j, runViteInstall as k, detectNodeVersionManagerFile as l, mergeViteConfigFiles as m, detectExistingAgentTargetPaths as n, checkViteVersion as o, installGitHooks as p, selectAgentTargetPaths as r, checkVitestVersion as s, detectAgentConflicts as t, detectPrettierProject as u, preflightGitHooksSetup as v, cancelAndExit as w, rewriteStandaloneProject as x, rewriteMonorepo as y, intro as z };
|
package/dist/global/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as promptGitHooks, T as defaultInteractive, d as ensurePreCommitHook, f as hasStagedConfigInViteConfig, i as updateExistingAgentInstructions } from "./agent-DE6dQKO4.js";
|
|
2
2
|
import { t as lib_default } from "./lib-DxappLRQ.js";
|
|
3
3
|
import { i as log, t as renderCliDoc } from "./help-HviKaKAU.js";
|
|
4
4
|
import { join } from "node:path";
|
package/dist/global/create.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { r as __toESM, t as __commonJSMin } from "./chunk-BoAXSpZd.js";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as selectPackageManager, B as log, D as promptGitHooks, E as downloadPackageManager$1, F as PackageManager, G as text, K as Ct, L as cancel, M as displayRelative, N as templatesDir, O as runViteFmt, P as DependencyType, R as confirm, T as defaultInteractive, U as select, V as multiselect, W as spinner, a as writeAgentInstructions, b as rewriteMonorepoProject, k as runViteInstall, n as detectExistingAgentTargetPaths, p as installGitHooks, r as selectAgentTargetPaths, x as rewriteStandaloneProject, y as rewriteMonorepo, z as intro } from "./agent-DE6dQKO4.js";
|
|
3
3
|
import { t as lib_default } from "./lib-DxappLRQ.js";
|
|
4
|
-
import { c as readJsonFile, o as editJsonFile, t as checkNpmPackageExists } from "./package-
|
|
4
|
+
import { c as readJsonFile, o as editJsonFile, t as checkNpmPackageExists } from "./package-CnlCtq4D.js";
|
|
5
5
|
import { a as muted, i as log$1, n as accent, o as success, t as renderCliDoc } from "./help-HviKaKAU.js";
|
|
6
|
-
import { a as detectExistingEditor, n as updatePackageJsonWithDeps, o as selectEditor, r as updateWorkspaceConfig, s as writeEditorConfigs, t as detectWorkspace$1 } from "./workspace-
|
|
6
|
+
import { a as detectExistingEditor, n as updatePackageJsonWithDeps, o as selectEditor, r as updateWorkspaceConfig, s as writeEditorConfigs, t as detectWorkspace$1 } from "./workspace-j8KWxSkv.js";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { styleText } from "node:util";
|
|
9
9
|
import color from "picocolors";
|
package/dist/global/migrate.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { r as __toESM } from "./chunk-BoAXSpZd.js";
|
|
2
|
-
import { A as
|
|
2
|
+
import { A as selectPackageManager, B as log, D as promptGitHooks, E as downloadPackageManager$1, F as PackageManager, H as outro, I as require_semver, K as Ct, M as displayRelative, R as confirm, T as defaultInteractive, U as select, W as spinner, _ as migratePrettierToOxfmt, a as writeAgentInstructions, c as detectEslintProject, g as migrateNodeVersionManagerFile, h as migrateEslintToOxlint, j as upgradeYarn, k as runViteInstall, l as detectNodeVersionManagerFile, m as mergeViteConfigFiles, n as detectExistingAgentTargetPaths, o as checkViteVersion, p as installGitHooks, r as selectAgentTargetPaths, s as checkVitestVersion, t as detectAgentConflicts, u as detectPrettierProject, v as preflightGitHooksSetup, w as cancelAndExit, x as rewriteStandaloneProject, y as rewriteMonorepo } from "./agent-DE6dQKO4.js";
|
|
3
3
|
import { t as lib_default } from "./lib-DxappLRQ.js";
|
|
4
|
-
import {
|
|
4
|
+
import { _ as isForceOverrideMode, a as readNearestPackageJson, i as hasVitePlusDependency } from "./package-CnlCtq4D.js";
|
|
5
5
|
import { a as muted, i as log$1, n as accent, t as renderCliDoc } from "./help-HviKaKAU.js";
|
|
6
|
-
import { r as createMigrationReport } from "./report-
|
|
7
|
-
import { i as detectEditorConflicts, o as selectEditor, s as writeEditorConfigs, t as detectWorkspace$1 } from "./workspace-
|
|
6
|
+
import { r as createMigrationReport } from "./report-DGaKL5VQ.js";
|
|
7
|
+
import { i as detectEditorConflicts, o as selectEditor, s as writeEditorConfigs, t as detectWorkspace$1 } from "./workspace-j8KWxSkv.js";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { styleText } from "node:util";
|
|
10
10
|
import { vitePlusHeader } from "../../binding/index.js";
|
|
@@ -68,6 +68,17 @@ async function promptPrettierMigration(projectPath, interactive, packages) {
|
|
|
68
68
|
if (!await migratePrettierToOxfmt(projectPath, interactive, prettierProject.configFile, packages)) cancelAndExit("Prettier migration failed. Fix the issue and re-run `vp migrate`.", 1);
|
|
69
69
|
return true;
|
|
70
70
|
}
|
|
71
|
+
async function confirmNodeVersionFileMigration(interactive) {
|
|
72
|
+
if (interactive) {
|
|
73
|
+
const confirmed = await confirm({
|
|
74
|
+
message: "Migrate .nvmrc to .node-version?",
|
|
75
|
+
initialValue: true
|
|
76
|
+
});
|
|
77
|
+
if (Ct(confirmed)) cancelAndExit();
|
|
78
|
+
return !!confirmed;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
71
82
|
const helpMessage = renderCliDoc({
|
|
72
83
|
usage: "vp migrate [PATH] [OPTIONS]",
|
|
73
84
|
summary: "Migrate standalone Vite, Vitest, Oxlint, Oxfmt, and Prettier projects to unified Vite+.",
|
|
@@ -271,6 +282,9 @@ async function collectMigrationPlan(rootDir, detectedPackageManager, options, pa
|
|
|
271
282
|
let migratePrettier = false;
|
|
272
283
|
if (prettierProject.hasDependency && prettierProject.configFile) migratePrettier = await confirmPrettierMigration(options.interactive);
|
|
273
284
|
else if (prettierProject.hasDependency) warnPackageLevelPrettier();
|
|
285
|
+
const nodeVersionDetection = detectNodeVersionManagerFile(rootDir);
|
|
286
|
+
let migrateNodeVersionFile = false;
|
|
287
|
+
if (nodeVersionDetection) migrateNodeVersionFile = await confirmNodeVersionFileMigration(options.interactive);
|
|
274
288
|
return {
|
|
275
289
|
packageManager,
|
|
276
290
|
shouldSetupHooks,
|
|
@@ -281,7 +295,9 @@ async function collectMigrationPlan(rootDir, detectedPackageManager, options, pa
|
|
|
281
295
|
migrateEslint,
|
|
282
296
|
eslintConfigFile: eslintProject.configFile,
|
|
283
297
|
migratePrettier,
|
|
284
|
-
prettierConfigFile: prettierProject.configFile
|
|
298
|
+
prettierConfigFile: prettierProject.configFile,
|
|
299
|
+
migrateNodeVersionFile,
|
|
300
|
+
nodeVersionDetection
|
|
285
301
|
};
|
|
286
302
|
}
|
|
287
303
|
function formatDuration(durationMs) {
|
|
@@ -305,6 +321,7 @@ function showMigrationSummary(options) {
|
|
|
305
321
|
}
|
|
306
322
|
if (report.eslintMigrated) log$1(`${styleText("gray", "•")} ESLint rules migrated to Oxlint`);
|
|
307
323
|
if (report.prettierMigrated) log$1(`${styleText("gray", "•")} Prettier migrated to Oxfmt`);
|
|
324
|
+
if (report.nodeVersionFileMigrated) log$1(`${styleText("gray", "•")} Node version manager file migrated to .node-version`);
|
|
308
325
|
if (report.gitHooksConfigured) log$1(`${styleText("gray", "•")} Git hooks configured`);
|
|
309
326
|
if (report.warnings.length > 0) {
|
|
310
327
|
log$1(`${styleText("yellow", "!")} Warnings:`);
|
|
@@ -318,7 +335,7 @@ function showMigrationSummary(options) {
|
|
|
318
335
|
async function checkRolldownCompatibility(rootDir, report) {
|
|
319
336
|
try {
|
|
320
337
|
const { resolveConfig } = await import("./src-CXhDaJZD.js");
|
|
321
|
-
const { checkManualChunksCompat } = await import("./compat-
|
|
338
|
+
const { checkManualChunksCompat } = await import("./compat-CiHwUbA_.js");
|
|
322
339
|
checkManualChunksCompat((await resolveConfig({
|
|
323
340
|
root: rootDir,
|
|
324
341
|
logLevel: "silent",
|
|
@@ -370,6 +387,10 @@ async function executeMigrationPlan(workspaceInfoOptional, plan, interactive) {
|
|
|
370
387
|
log.error(`✘ npm@${downloadResult.version} is not supported by auto migration, please upgrade npm to >=8.3.0 first`);
|
|
371
388
|
cancelAndExit("Vite+ cannot automatically migrate this project yet.", 1);
|
|
372
389
|
}
|
|
390
|
+
if (plan.migrateNodeVersionFile && plan.nodeVersionDetection) {
|
|
391
|
+
updateMigrationProgress("Migrating node version file");
|
|
392
|
+
migrateNodeVersionManagerFile(workspaceInfo.rootDir, plan.nodeVersionDetection, report);
|
|
393
|
+
}
|
|
373
394
|
updateMigrationProgress("Installing dependencies");
|
|
374
395
|
const initialInstallSummary = await runViteInstall(workspaceInfo.rootDir, interactive, void 0, { silent: true });
|
|
375
396
|
updateMigrationProgress("Validating toolchain");
|
|
@@ -470,6 +491,10 @@ async function main() {
|
|
|
470
491
|
};
|
|
471
492
|
const eslintMigrated = await promptEslintMigration(workspaceInfoOptional.rootDir, options.interactive, workspaceInfoOptional.packages);
|
|
472
493
|
const prettierMigrated = await promptPrettierMigration(workspaceInfoOptional.rootDir, options.interactive, workspaceInfoOptional.packages);
|
|
494
|
+
const nodeVersionDetection = detectNodeVersionManagerFile(workspaceInfoOptional.rootDir);
|
|
495
|
+
if (nodeVersionDetection) {
|
|
496
|
+
if (await confirmNodeVersionFileMigration(options.interactive) && migrateNodeVersionManagerFile(workspaceInfoOptional.rootDir, nodeVersionDetection, report)) didMigrate = true;
|
|
497
|
+
}
|
|
473
498
|
if (eslintMigrated || prettierMigrated) {
|
|
474
499
|
updateMigrationProgress("Rewriting configs");
|
|
475
500
|
mergeViteConfigFiles(workspaceInfoOptional.rootDir, true, report);
|
|
@@ -504,23 +504,210 @@ var CharacterCodes;
|
|
|
504
504
|
CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed";
|
|
505
505
|
CharacterCodes[CharacterCodes["tab"] = 9] = "tab";
|
|
506
506
|
})(CharacterCodes || (CharacterCodes = {}));
|
|
507
|
-
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
509
|
+
const cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
508
510
|
return " ".repeat(index);
|
|
509
511
|
});
|
|
510
512
|
const maxCachedValues = 200;
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}),
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
})
|
|
522
|
-
|
|
523
|
-
|
|
513
|
+
const cachedBreakLinesWithSpaces = {
|
|
514
|
+
" ": {
|
|
515
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
516
|
+
return "\n" + " ".repeat(index);
|
|
517
|
+
}),
|
|
518
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
519
|
+
return "\r" + " ".repeat(index);
|
|
520
|
+
}),
|
|
521
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
522
|
+
return "\r\n" + " ".repeat(index);
|
|
523
|
+
})
|
|
524
|
+
},
|
|
525
|
+
" ": {
|
|
526
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
527
|
+
return "\n" + " ".repeat(index);
|
|
528
|
+
}),
|
|
529
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
530
|
+
return "\r" + " ".repeat(index);
|
|
531
|
+
}),
|
|
532
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
533
|
+
return "\r\n" + " ".repeat(index);
|
|
534
|
+
})
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
const supportedEols = [
|
|
538
|
+
"\n",
|
|
539
|
+
"\r",
|
|
540
|
+
"\r\n"
|
|
541
|
+
];
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/format.js
|
|
544
|
+
function format$1(documentText, range, options) {
|
|
545
|
+
let initialIndentLevel;
|
|
546
|
+
let formatText;
|
|
547
|
+
let formatTextStart;
|
|
548
|
+
let rangeStart;
|
|
549
|
+
let rangeEnd;
|
|
550
|
+
if (range) {
|
|
551
|
+
rangeStart = range.offset;
|
|
552
|
+
rangeEnd = rangeStart + range.length;
|
|
553
|
+
formatTextStart = rangeStart;
|
|
554
|
+
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) formatTextStart--;
|
|
555
|
+
let endOffset = rangeEnd;
|
|
556
|
+
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) endOffset++;
|
|
557
|
+
formatText = documentText.substring(formatTextStart, endOffset);
|
|
558
|
+
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
559
|
+
} else {
|
|
560
|
+
formatText = documentText;
|
|
561
|
+
initialIndentLevel = 0;
|
|
562
|
+
formatTextStart = 0;
|
|
563
|
+
rangeStart = 0;
|
|
564
|
+
rangeEnd = documentText.length;
|
|
565
|
+
}
|
|
566
|
+
const eol = getEOL(options, documentText);
|
|
567
|
+
const eolFastPathSupported = supportedEols.includes(eol);
|
|
568
|
+
let numberLineBreaks = 0;
|
|
569
|
+
let indentLevel = 0;
|
|
570
|
+
let indentValue;
|
|
571
|
+
if (options.insertSpaces) indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
572
|
+
else indentValue = " ";
|
|
573
|
+
const indentType = indentValue === " " ? " " : " ";
|
|
574
|
+
let scanner = createScanner$1(formatText, false);
|
|
575
|
+
let hasError = false;
|
|
576
|
+
function newLinesAndIndent() {
|
|
577
|
+
if (numberLineBreaks > 1) return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
578
|
+
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
579
|
+
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
580
|
+
if (amountOfSpaces <= 0) return eol;
|
|
581
|
+
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
582
|
+
}
|
|
583
|
+
function scanNext() {
|
|
584
|
+
let token = scanner.scan();
|
|
585
|
+
numberLineBreaks = 0;
|
|
586
|
+
while (token === 15 || token === 14) {
|
|
587
|
+
if (token === 14 && options.keepLines) numberLineBreaks += 1;
|
|
588
|
+
else if (token === 14) numberLineBreaks = 1;
|
|
589
|
+
token = scanner.scan();
|
|
590
|
+
}
|
|
591
|
+
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
592
|
+
return token;
|
|
593
|
+
}
|
|
594
|
+
const editOperations = [];
|
|
595
|
+
function addEdit(text, startOffset, endOffset) {
|
|
596
|
+
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) editOperations.push({
|
|
597
|
+
offset: startOffset,
|
|
598
|
+
length: endOffset - startOffset,
|
|
599
|
+
content: text
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
let firstToken = scanNext();
|
|
603
|
+
if (options.keepLines && numberLineBreaks > 0) addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
604
|
+
if (firstToken !== 17) {
|
|
605
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
606
|
+
addEdit(indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel), formatTextStart, firstTokenStart);
|
|
607
|
+
}
|
|
608
|
+
while (firstToken !== 17) {
|
|
609
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
610
|
+
let secondToken = scanNext();
|
|
611
|
+
let replaceContent = "";
|
|
612
|
+
let needsLineBreak = false;
|
|
613
|
+
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
614
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
615
|
+
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
616
|
+
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
617
|
+
needsLineBreak = secondToken === 12;
|
|
618
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
619
|
+
secondToken = scanNext();
|
|
620
|
+
}
|
|
621
|
+
if (secondToken === 2) {
|
|
622
|
+
if (firstToken !== 1) indentLevel--;
|
|
623
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) replaceContent = newLinesAndIndent();
|
|
624
|
+
else if (options.keepLines) replaceContent = cachedSpaces[1];
|
|
625
|
+
} else if (secondToken === 4) {
|
|
626
|
+
if (firstToken !== 3) indentLevel--;
|
|
627
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) replaceContent = newLinesAndIndent();
|
|
628
|
+
else if (options.keepLines) replaceContent = cachedSpaces[1];
|
|
629
|
+
} else {
|
|
630
|
+
switch (firstToken) {
|
|
631
|
+
case 3:
|
|
632
|
+
case 1:
|
|
633
|
+
indentLevel++;
|
|
634
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) replaceContent = newLinesAndIndent();
|
|
635
|
+
else replaceContent = cachedSpaces[1];
|
|
636
|
+
break;
|
|
637
|
+
case 5:
|
|
638
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) replaceContent = newLinesAndIndent();
|
|
639
|
+
else replaceContent = cachedSpaces[1];
|
|
640
|
+
break;
|
|
641
|
+
case 12:
|
|
642
|
+
replaceContent = newLinesAndIndent();
|
|
643
|
+
break;
|
|
644
|
+
case 13:
|
|
645
|
+
if (numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
646
|
+
else if (!needsLineBreak) replaceContent = cachedSpaces[1];
|
|
647
|
+
break;
|
|
648
|
+
case 6:
|
|
649
|
+
if (options.keepLines && numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
650
|
+
else if (!needsLineBreak) replaceContent = cachedSpaces[1];
|
|
651
|
+
break;
|
|
652
|
+
case 10:
|
|
653
|
+
if (options.keepLines && numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
654
|
+
else if (secondToken === 6 && !needsLineBreak) replaceContent = "";
|
|
655
|
+
break;
|
|
656
|
+
case 7:
|
|
657
|
+
case 8:
|
|
658
|
+
case 9:
|
|
659
|
+
case 11:
|
|
660
|
+
case 2:
|
|
661
|
+
case 4:
|
|
662
|
+
if (options.keepLines && numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
663
|
+
else if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) replaceContent = cachedSpaces[1];
|
|
664
|
+
else if (secondToken !== 5 && secondToken !== 17) hasError = true;
|
|
665
|
+
break;
|
|
666
|
+
case 16:
|
|
667
|
+
hasError = true;
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) replaceContent = newLinesAndIndent();
|
|
671
|
+
}
|
|
672
|
+
if (secondToken === 17) if (options.keepLines && numberLineBreaks > 0) replaceContent = newLinesAndIndent();
|
|
673
|
+
else replaceContent = options.insertFinalNewline ? eol : "";
|
|
674
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
675
|
+
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
676
|
+
firstToken = secondToken;
|
|
677
|
+
}
|
|
678
|
+
return editOperations;
|
|
679
|
+
}
|
|
680
|
+
function repeat(s, count) {
|
|
681
|
+
let result = "";
|
|
682
|
+
for (let i = 0; i < count; i++) result += s;
|
|
683
|
+
return result;
|
|
684
|
+
}
|
|
685
|
+
function computeIndentLevel(content, options) {
|
|
686
|
+
let i = 0;
|
|
687
|
+
let nChars = 0;
|
|
688
|
+
const tabSize = options.tabSize || 4;
|
|
689
|
+
while (i < content.length) {
|
|
690
|
+
let ch = content.charAt(i);
|
|
691
|
+
if (ch === cachedSpaces[1]) nChars++;
|
|
692
|
+
else if (ch === " ") nChars += tabSize;
|
|
693
|
+
else break;
|
|
694
|
+
i++;
|
|
695
|
+
}
|
|
696
|
+
return Math.floor(nChars / tabSize);
|
|
697
|
+
}
|
|
698
|
+
function getEOL(options, text) {
|
|
699
|
+
for (let i = 0; i < text.length; i++) {
|
|
700
|
+
const ch = text.charAt(i);
|
|
701
|
+
if (ch === "\r") {
|
|
702
|
+
if (i + 1 < text.length && text.charAt(i + 1) === "\n") return "\r\n";
|
|
703
|
+
return "\r";
|
|
704
|
+
} else if (ch === "\n") return "\n";
|
|
705
|
+
}
|
|
706
|
+
return options && options.eol || "\n";
|
|
707
|
+
}
|
|
708
|
+
function isEOL(text, offset) {
|
|
709
|
+
return "\r\n".indexOf(text.charAt(offset)) !== -1;
|
|
710
|
+
}
|
|
524
711
|
//#endregion
|
|
525
712
|
//#region ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
526
713
|
var ParseOptions;
|
|
@@ -575,6 +762,123 @@ function parse$1(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
|
575
762
|
return currentParent[0];
|
|
576
763
|
}
|
|
577
764
|
/**
|
|
765
|
+
* Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
|
|
766
|
+
*/
|
|
767
|
+
function parseTree$1(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
768
|
+
let currentParent = {
|
|
769
|
+
type: "array",
|
|
770
|
+
offset: -1,
|
|
771
|
+
length: -1,
|
|
772
|
+
children: [],
|
|
773
|
+
parent: void 0
|
|
774
|
+
};
|
|
775
|
+
function ensurePropertyComplete(endOffset) {
|
|
776
|
+
if (currentParent.type === "property") {
|
|
777
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
778
|
+
currentParent = currentParent.parent;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function onValue(valueNode) {
|
|
782
|
+
currentParent.children.push(valueNode);
|
|
783
|
+
return valueNode;
|
|
784
|
+
}
|
|
785
|
+
visit$1(text, {
|
|
786
|
+
onObjectBegin: (offset) => {
|
|
787
|
+
currentParent = onValue({
|
|
788
|
+
type: "object",
|
|
789
|
+
offset,
|
|
790
|
+
length: -1,
|
|
791
|
+
parent: currentParent,
|
|
792
|
+
children: []
|
|
793
|
+
});
|
|
794
|
+
},
|
|
795
|
+
onObjectProperty: (name, offset, length) => {
|
|
796
|
+
currentParent = onValue({
|
|
797
|
+
type: "property",
|
|
798
|
+
offset,
|
|
799
|
+
length: -1,
|
|
800
|
+
parent: currentParent,
|
|
801
|
+
children: []
|
|
802
|
+
});
|
|
803
|
+
currentParent.children.push({
|
|
804
|
+
type: "string",
|
|
805
|
+
value: name,
|
|
806
|
+
offset,
|
|
807
|
+
length,
|
|
808
|
+
parent: currentParent
|
|
809
|
+
});
|
|
810
|
+
},
|
|
811
|
+
onObjectEnd: (offset, length) => {
|
|
812
|
+
ensurePropertyComplete(offset + length);
|
|
813
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
814
|
+
currentParent = currentParent.parent;
|
|
815
|
+
ensurePropertyComplete(offset + length);
|
|
816
|
+
},
|
|
817
|
+
onArrayBegin: (offset, length) => {
|
|
818
|
+
currentParent = onValue({
|
|
819
|
+
type: "array",
|
|
820
|
+
offset,
|
|
821
|
+
length: -1,
|
|
822
|
+
parent: currentParent,
|
|
823
|
+
children: []
|
|
824
|
+
});
|
|
825
|
+
},
|
|
826
|
+
onArrayEnd: (offset, length) => {
|
|
827
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
828
|
+
currentParent = currentParent.parent;
|
|
829
|
+
ensurePropertyComplete(offset + length);
|
|
830
|
+
},
|
|
831
|
+
onLiteralValue: (value, offset, length) => {
|
|
832
|
+
onValue({
|
|
833
|
+
type: getNodeType(value),
|
|
834
|
+
offset,
|
|
835
|
+
length,
|
|
836
|
+
parent: currentParent,
|
|
837
|
+
value
|
|
838
|
+
});
|
|
839
|
+
ensurePropertyComplete(offset + length);
|
|
840
|
+
},
|
|
841
|
+
onSeparator: (sep, offset, length) => {
|
|
842
|
+
if (currentParent.type === "property") {
|
|
843
|
+
if (sep === ":") currentParent.colonOffset = offset;
|
|
844
|
+
else if (sep === ",") ensurePropertyComplete(offset);
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
onError: (error, offset, length) => {
|
|
848
|
+
errors.push({
|
|
849
|
+
error,
|
|
850
|
+
offset,
|
|
851
|
+
length
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
}, options);
|
|
855
|
+
const result = currentParent.children[0];
|
|
856
|
+
if (result) delete result.parent;
|
|
857
|
+
return result;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Finds the node at the given path in a JSON DOM.
|
|
861
|
+
*/
|
|
862
|
+
function findNodeAtLocation$1(root, path) {
|
|
863
|
+
if (!root) return;
|
|
864
|
+
let node = root;
|
|
865
|
+
for (let segment of path) if (typeof segment === "string") {
|
|
866
|
+
if (node.type !== "object" || !Array.isArray(node.children)) return;
|
|
867
|
+
let found = false;
|
|
868
|
+
for (const propertyNode of node.children) if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
869
|
+
node = propertyNode.children[1];
|
|
870
|
+
found = true;
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
if (!found) return;
|
|
874
|
+
} else {
|
|
875
|
+
const index = segment;
|
|
876
|
+
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) return;
|
|
877
|
+
node = node.children[index];
|
|
878
|
+
}
|
|
879
|
+
return node;
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
578
882
|
* Gets the JSON path of the given JSON DOM node
|
|
579
883
|
*/
|
|
580
884
|
function getNodePath$1(node) {
|
|
@@ -821,6 +1125,188 @@ function visit$1(text, visitor, options = ParseOptions.DEFAULT) {
|
|
|
821
1125
|
if (_scanner.getToken() !== 17) handleError(9, [], []);
|
|
822
1126
|
return true;
|
|
823
1127
|
}
|
|
1128
|
+
function getNodeType(value) {
|
|
1129
|
+
switch (typeof value) {
|
|
1130
|
+
case "boolean": return "boolean";
|
|
1131
|
+
case "number": return "number";
|
|
1132
|
+
case "string": return "string";
|
|
1133
|
+
case "object":
|
|
1134
|
+
if (!value) return "null";
|
|
1135
|
+
else if (Array.isArray(value)) return "array";
|
|
1136
|
+
return "object";
|
|
1137
|
+
default: return "null";
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
function setProperty(text, originalPath, value, options) {
|
|
1141
|
+
const path = originalPath.slice();
|
|
1142
|
+
const root = parseTree$1(text, []);
|
|
1143
|
+
let parent = void 0;
|
|
1144
|
+
let lastSegment = void 0;
|
|
1145
|
+
while (path.length > 0) {
|
|
1146
|
+
lastSegment = path.pop();
|
|
1147
|
+
parent = findNodeAtLocation$1(root, path);
|
|
1148
|
+
if (parent === void 0 && value !== void 0) if (typeof lastSegment === "string") value = { [lastSegment]: value };
|
|
1149
|
+
else value = [value];
|
|
1150
|
+
else break;
|
|
1151
|
+
}
|
|
1152
|
+
if (!parent) {
|
|
1153
|
+
if (value === void 0) throw new Error("Can not delete in empty document");
|
|
1154
|
+
return withFormatting(text, {
|
|
1155
|
+
offset: root ? root.offset : 0,
|
|
1156
|
+
length: root ? root.length : 0,
|
|
1157
|
+
content: JSON.stringify(value)
|
|
1158
|
+
}, options);
|
|
1159
|
+
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
1160
|
+
const existing = findNodeAtLocation$1(parent, [lastSegment]);
|
|
1161
|
+
if (existing !== void 0) if (value === void 0) {
|
|
1162
|
+
if (!existing.parent) throw new Error("Malformed AST");
|
|
1163
|
+
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1164
|
+
let removeBegin;
|
|
1165
|
+
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
1166
|
+
if (propertyIndex > 0) {
|
|
1167
|
+
let previous = parent.children[propertyIndex - 1];
|
|
1168
|
+
removeBegin = previous.offset + previous.length;
|
|
1169
|
+
} else {
|
|
1170
|
+
removeBegin = parent.offset + 1;
|
|
1171
|
+
if (parent.children.length > 1) removeEnd = parent.children[1].offset;
|
|
1172
|
+
}
|
|
1173
|
+
return withFormatting(text, {
|
|
1174
|
+
offset: removeBegin,
|
|
1175
|
+
length: removeEnd - removeBegin,
|
|
1176
|
+
content: ""
|
|
1177
|
+
}, options);
|
|
1178
|
+
} else return withFormatting(text, {
|
|
1179
|
+
offset: existing.offset,
|
|
1180
|
+
length: existing.length,
|
|
1181
|
+
content: JSON.stringify(value)
|
|
1182
|
+
}, options);
|
|
1183
|
+
else {
|
|
1184
|
+
if (value === void 0) return [];
|
|
1185
|
+
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1186
|
+
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
1187
|
+
let edit;
|
|
1188
|
+
if (index > 0) {
|
|
1189
|
+
let previous = parent.children[index - 1];
|
|
1190
|
+
edit = {
|
|
1191
|
+
offset: previous.offset + previous.length,
|
|
1192
|
+
length: 0,
|
|
1193
|
+
content: "," + newProperty
|
|
1194
|
+
};
|
|
1195
|
+
} else if (parent.children.length === 0) edit = {
|
|
1196
|
+
offset: parent.offset + 1,
|
|
1197
|
+
length: 0,
|
|
1198
|
+
content: newProperty
|
|
1199
|
+
};
|
|
1200
|
+
else edit = {
|
|
1201
|
+
offset: parent.offset + 1,
|
|
1202
|
+
length: 0,
|
|
1203
|
+
content: newProperty + ","
|
|
1204
|
+
};
|
|
1205
|
+
return withFormatting(text, edit, options);
|
|
1206
|
+
}
|
|
1207
|
+
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
1208
|
+
const insertIndex = lastSegment;
|
|
1209
|
+
if (insertIndex === -1) {
|
|
1210
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1211
|
+
let edit;
|
|
1212
|
+
if (parent.children.length === 0) edit = {
|
|
1213
|
+
offset: parent.offset + 1,
|
|
1214
|
+
length: 0,
|
|
1215
|
+
content: newProperty
|
|
1216
|
+
};
|
|
1217
|
+
else {
|
|
1218
|
+
const previous = parent.children[parent.children.length - 1];
|
|
1219
|
+
edit = {
|
|
1220
|
+
offset: previous.offset + previous.length,
|
|
1221
|
+
length: 0,
|
|
1222
|
+
content: "," + newProperty
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
return withFormatting(text, edit, options);
|
|
1226
|
+
} else if (value === void 0 && parent.children.length >= 0) {
|
|
1227
|
+
const removalIndex = lastSegment;
|
|
1228
|
+
const toRemove = parent.children[removalIndex];
|
|
1229
|
+
let edit;
|
|
1230
|
+
if (parent.children.length === 1) edit = {
|
|
1231
|
+
offset: parent.offset + 1,
|
|
1232
|
+
length: parent.length - 2,
|
|
1233
|
+
content: ""
|
|
1234
|
+
};
|
|
1235
|
+
else if (parent.children.length - 1 === removalIndex) {
|
|
1236
|
+
let previous = parent.children[removalIndex - 1];
|
|
1237
|
+
let offset = previous.offset + previous.length;
|
|
1238
|
+
edit = {
|
|
1239
|
+
offset,
|
|
1240
|
+
length: parent.offset + parent.length - 2 - offset,
|
|
1241
|
+
content: ""
|
|
1242
|
+
};
|
|
1243
|
+
} else edit = {
|
|
1244
|
+
offset: toRemove.offset,
|
|
1245
|
+
length: parent.children[removalIndex + 1].offset - toRemove.offset,
|
|
1246
|
+
content: ""
|
|
1247
|
+
};
|
|
1248
|
+
return withFormatting(text, edit, options);
|
|
1249
|
+
} else if (value !== void 0) {
|
|
1250
|
+
let edit;
|
|
1251
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1252
|
+
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1253
|
+
const toModify = parent.children[lastSegment];
|
|
1254
|
+
edit = {
|
|
1255
|
+
offset: toModify.offset,
|
|
1256
|
+
length: toModify.length,
|
|
1257
|
+
content: newProperty
|
|
1258
|
+
};
|
|
1259
|
+
} else if (parent.children.length === 0 || lastSegment === 0) edit = {
|
|
1260
|
+
offset: parent.offset + 1,
|
|
1261
|
+
length: 0,
|
|
1262
|
+
content: parent.children.length === 0 ? newProperty : newProperty + ","
|
|
1263
|
+
};
|
|
1264
|
+
else {
|
|
1265
|
+
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
1266
|
+
const previous = parent.children[index - 1];
|
|
1267
|
+
edit = {
|
|
1268
|
+
offset: previous.offset + previous.length,
|
|
1269
|
+
length: 0,
|
|
1270
|
+
content: "," + newProperty
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
return withFormatting(text, edit, options);
|
|
1274
|
+
} else throw new Error(`Can not ${value === void 0 ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
1275
|
+
} else throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
1276
|
+
}
|
|
1277
|
+
function withFormatting(text, edit, options) {
|
|
1278
|
+
if (!options.formattingOptions) return [edit];
|
|
1279
|
+
let newText = applyEdit(text, edit);
|
|
1280
|
+
let begin = edit.offset;
|
|
1281
|
+
let end = edit.offset + edit.content.length;
|
|
1282
|
+
if (edit.length === 0 || edit.content.length === 0) {
|
|
1283
|
+
while (begin > 0 && !isEOL(newText, begin - 1)) begin--;
|
|
1284
|
+
while (end < newText.length && !isEOL(newText, end)) end++;
|
|
1285
|
+
}
|
|
1286
|
+
const edits = format$1(newText, {
|
|
1287
|
+
offset: begin,
|
|
1288
|
+
length: end - begin
|
|
1289
|
+
}, {
|
|
1290
|
+
...options.formattingOptions,
|
|
1291
|
+
keepLines: false
|
|
1292
|
+
});
|
|
1293
|
+
for (let i = edits.length - 1; i >= 0; i--) {
|
|
1294
|
+
const edit = edits[i];
|
|
1295
|
+
newText = applyEdit(newText, edit);
|
|
1296
|
+
begin = Math.min(begin, edit.offset);
|
|
1297
|
+
end = Math.max(end, edit.offset + edit.length);
|
|
1298
|
+
end += edit.content.length - edit.length;
|
|
1299
|
+
}
|
|
1300
|
+
const editLength = text.length - (newText.length - end) - begin;
|
|
1301
|
+
return [{
|
|
1302
|
+
offset: begin,
|
|
1303
|
+
length: editLength,
|
|
1304
|
+
content: newText.substring(begin, end)
|
|
1305
|
+
}];
|
|
1306
|
+
}
|
|
1307
|
+
function applyEdit(text, edit) {
|
|
1308
|
+
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
1309
|
+
}
|
|
824
1310
|
var ScanError;
|
|
825
1311
|
(function(ScanError) {
|
|
826
1312
|
ScanError[ScanError["None"] = 0] = "None";
|
|
@@ -875,6 +1361,43 @@ var ParseErrorCode;
|
|
|
875
1361
|
ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
876
1362
|
ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
877
1363
|
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
1364
|
+
/**
|
|
1365
|
+
* Computes the edit operations needed to modify a value in the JSON document.
|
|
1366
|
+
*
|
|
1367
|
+
* @param documentText The input text
|
|
1368
|
+
* @param path The path of the value to change. The path represents either to the document root, a property or an array item.
|
|
1369
|
+
* If the path points to an non-existing property or item, it will be created.
|
|
1370
|
+
* @param value The new value for the specified property or item. If the value is undefined,
|
|
1371
|
+
* the property or item will be removed.
|
|
1372
|
+
* @param options Options
|
|
1373
|
+
* @returns The edit operations describing the changes to the original document, following the format described in {@linkcode EditResult}.
|
|
1374
|
+
* To apply the edit operations to the input, use {@linkcode applyEdits}.
|
|
1375
|
+
*/
|
|
1376
|
+
function modify(text, path, value, options) {
|
|
1377
|
+
return setProperty(text, path, value, options);
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Applies edits to an input string.
|
|
1381
|
+
* @param text The input text
|
|
1382
|
+
* @param edits Edit operations following the format described in {@linkcode EditResult}.
|
|
1383
|
+
* @returns The text with the applied edits.
|
|
1384
|
+
* @throws An error if the edit operations are not well-formed as described in {@linkcode EditResult}.
|
|
1385
|
+
*/
|
|
1386
|
+
function applyEdits(text, edits) {
|
|
1387
|
+
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
1388
|
+
const diff = a.offset - b.offset;
|
|
1389
|
+
if (diff === 0) return a.length - b.length;
|
|
1390
|
+
return diff;
|
|
1391
|
+
});
|
|
1392
|
+
let lastModifiedOffset = text.length;
|
|
1393
|
+
for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
|
1394
|
+
let e = sortedEdits[i];
|
|
1395
|
+
if (e.offset + e.length <= lastModifiedOffset) text = applyEdit(text, e);
|
|
1396
|
+
else throw new Error("Overlapping edit");
|
|
1397
|
+
lastModifiedOffset = e.offset;
|
|
1398
|
+
}
|
|
1399
|
+
return text;
|
|
1400
|
+
}
|
|
878
1401
|
//#endregion
|
|
879
1402
|
//#region src/utils/json.ts
|
|
880
1403
|
function readJsonFile(file, allowComments) {
|
|
@@ -956,4 +1479,4 @@ async function checkNpmPackageExists(packageName) {
|
|
|
956
1479
|
}
|
|
957
1480
|
}
|
|
958
1481
|
//#endregion
|
|
959
|
-
export { readNearestPackageJson as a, readJsonFile as c,
|
|
1482
|
+
export { isForceOverrideMode as _, readNearestPackageJson as a, readJsonFile as c, modify as d, parse as f, VITE_PLUS_VERSION as g, VITE_PLUS_OVERRIDE_PACKAGES as h, hasVitePlusDependency as i, writeJsonFile as l, VITE_PLUS_NAME as m, detectPackageMetadata as n, editJsonFile as o, BASEURL_TSCONFIG_WARNING as p, getScopeFromPackageName as r, isJsonFile as s, checkNpmPackageExists as t, applyEdits as u };
|
package/dist/global/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as hasVitePlusDependency, m as VITE_PLUS_NAME, n as detectPackageMetadata } from "./package-CnlCtq4D.js";
|
|
2
2
|
import { i as log, n as accent, t as renderCliDoc } from "./help-HviKaKAU.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import fs from "node:fs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as log, C as readYamlFile, F as PackageManager, K as Ct, S as editYamlFile, U as select } from "./agent-DE6dQKO4.js";
|
|
2
2
|
import { g as YAMLSeq, y as Scalar } from "./browser-09BZLUYM.js";
|
|
3
|
-
import { c as readJsonFile, l as writeJsonFile, o as editJsonFile, r as getScopeFromPackageName } from "./package-
|
|
3
|
+
import { c as readJsonFile, l as writeJsonFile, o as editJsonFile, r as getScopeFromPackageName } from "./package-CnlCtq4D.js";
|
|
4
4
|
import path, { posix, win32 } from "node:path";
|
|
5
5
|
import * as actualFS from "node:fs";
|
|
6
6
|
import fs from "node:fs";
|
|
@@ -8,6 +8,7 @@ export interface ConfigFiles {
|
|
|
8
8
|
eslintLegacyConfig?: string;
|
|
9
9
|
prettierConfig?: string;
|
|
10
10
|
prettierIgnore?: boolean;
|
|
11
|
+
nvmrcFile?: boolean;
|
|
11
12
|
}
|
|
12
13
|
export declare const PRETTIER_PACKAGE_JSON_CONFIG = "package.json#prettier";
|
|
13
14
|
export declare const PRETTIER_CONFIG_FILES: readonly [".prettierrc", ".prettierrc.json", ".prettierrc.jsonc", ".prettierrc.yaml", ".prettierrc.yml", ".prettierrc.toml", ".prettierrc.js", ".prettierrc.cjs", ".prettierrc.mjs", ".prettierrc.ts", ".prettierrc.cts", ".prettierrc.mts", "prettier.config.js", "prettier.config.cjs", "prettier.config.mjs", "prettier.config.ts", "prettier.config.cts", "prettier.config.mts"];
|
|
@@ -154,5 +154,9 @@ export function detectConfigs(projectPath) {
|
|
|
154
154
|
if (fs.existsSync(path.join(projectPath, '.prettierignore'))) {
|
|
155
155
|
configs.prettierIgnore = true;
|
|
156
156
|
}
|
|
157
|
+
// Check for .nvmrc (nvm)
|
|
158
|
+
if (fs.existsSync(path.join(projectPath, '.nvmrc'))) {
|
|
159
|
+
configs.nvmrcFile = true;
|
|
160
|
+
}
|
|
157
161
|
return configs;
|
|
158
162
|
}
|
|
@@ -100,3 +100,22 @@ export declare function createPreCommitHook(projectPath: string, dir?: string):
|
|
|
100
100
|
* Called only when hooks are being set up (not with --no-hooks).
|
|
101
101
|
*/
|
|
102
102
|
export declare function rewritePrepareScript(rootDir: string): string | undefined;
|
|
103
|
+
export interface NodeVersionManagerDetection {
|
|
104
|
+
file: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Detect a .nvmrc file in the project directory.
|
|
108
|
+
* Returns undefined if not found or .node-version already exists.
|
|
109
|
+
*/
|
|
110
|
+
export declare function detectNodeVersionManagerFile(projectPath: string): NodeVersionManagerDetection | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Parse a version alias from a .nvmrc file into a .node-version compatible string.
|
|
113
|
+
* Accepts the first line of .nvmrc (pre-trimmed).
|
|
114
|
+
* Returns null for unsupported aliases like "system", "default", "iojs".
|
|
115
|
+
*/
|
|
116
|
+
export declare function parseNvmrcVersion(alias: string): string | null;
|
|
117
|
+
/**
|
|
118
|
+
* Migrate .nvmrc to .node-version and remove .nvmrc.
|
|
119
|
+
* Returns true on success, false if migration was skipped or failed.
|
|
120
|
+
*/
|
|
121
|
+
export declare function migrateNodeVersionManagerFile(projectPath: string, _detection: NodeVersionManagerDetection, report?: MigrationReport): boolean;
|
|
@@ -12,7 +12,7 @@ import { editJsonFile, isJsonFile, readJsonFile } from '../utils/json.js';
|
|
|
12
12
|
import { detectPackageMetadata } from '../utils/package.js';
|
|
13
13
|
import { displayRelative, rulesDir } from '../utils/path.js';
|
|
14
14
|
import { getSpinner } from '../utils/prompts.js';
|
|
15
|
-
import { hasBaseUrlInTsconfig } from '../utils/tsconfig.js';
|
|
15
|
+
import { findTsconfigFiles, hasBaseUrlInTsconfig, removeDeprecatedTsconfigFalseOption, } from '../utils/tsconfig.js';
|
|
16
16
|
import { editYamlFile, scalarString } from '../utils/yaml.js';
|
|
17
17
|
import { PRETTIER_CONFIG_FILES, PRETTIER_PACKAGE_JSON_CONFIG, detectConfigs, } from './detector.js';
|
|
18
18
|
import { addManualStep, addMigrationWarning } from './report.js';
|
|
@@ -480,6 +480,23 @@ function rewritePrettierPackageJson(packageJsonPath) {
|
|
|
480
480
|
function rewritePrettierLintStagedConfigFiles(projectPath, report) {
|
|
481
481
|
rewriteToolLintStagedConfigFiles(projectPath, rewritePrettier, 'prettier', report);
|
|
482
482
|
}
|
|
483
|
+
function cleanupDeprecatedTsconfigOptions(projectPath, silent = false, report) {
|
|
484
|
+
const deprecatedOptions = ['esModuleInterop', 'allowSyntheticDefaultImports'];
|
|
485
|
+
const files = findTsconfigFiles(projectPath);
|
|
486
|
+
for (const filePath of files) {
|
|
487
|
+
for (const name of deprecatedOptions) {
|
|
488
|
+
if (removeDeprecatedTsconfigFalseOption(filePath, name)) {
|
|
489
|
+
if (report) {
|
|
490
|
+
report.removedConfigCount++;
|
|
491
|
+
}
|
|
492
|
+
if (!silent) {
|
|
493
|
+
prompts.log.success(`✔ Removed ${name}: false from ${displayRelative(filePath)}`);
|
|
494
|
+
}
|
|
495
|
+
warnMigration(`Removed \`"${name}": false\` from ${displayRelative(filePath)} — this option has been deprecated. See https://github.com/oxc-project/tsgolint/issues/351, https://github.com/microsoft/TypeScript/issues/62529`, report);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
483
500
|
/**
|
|
484
501
|
* Rewrite standalone project to add vite-plus dependencies
|
|
485
502
|
* @param projectPath - The path to the project
|
|
@@ -510,6 +527,7 @@ export function rewriteStandaloneProject(projectPath, workspaceInfo, skipStagedM
|
|
|
510
527
|
overrides: {
|
|
511
528
|
...pkg.pnpm?.overrides,
|
|
512
529
|
...VITE_PLUS_OVERRIDE_PACKAGES,
|
|
530
|
+
...(isForceOverrideMode() ? { [VITE_PLUS_NAME]: VITE_PLUS_VERSION } : {}),
|
|
513
531
|
},
|
|
514
532
|
};
|
|
515
533
|
// remove packages from `resolutions` field if they exist
|
|
@@ -522,7 +540,7 @@ export function rewriteStandaloneProject(projectPath, workspaceInfo, skipStagedM
|
|
|
522
540
|
}
|
|
523
541
|
extractedStagedConfig = rewritePackageJson(pkg, packageManager, false, skipStagedMigration);
|
|
524
542
|
// ensure vite-plus is in devDependencies
|
|
525
|
-
if (!pkg.devDependencies?.[VITE_PLUS_NAME]) {
|
|
543
|
+
if (!pkg.devDependencies?.[VITE_PLUS_NAME] || isForceOverrideMode()) {
|
|
526
544
|
pkg.devDependencies = {
|
|
527
545
|
...pkg.devDependencies,
|
|
528
546
|
[VITE_PLUS_NAME]: VITE_PLUS_VERSION,
|
|
@@ -539,6 +557,7 @@ export function rewriteStandaloneProject(projectPath, workspaceInfo, skipStagedM
|
|
|
539
557
|
if (!skipStagedMigration) {
|
|
540
558
|
rewriteLintStagedConfigFile(projectPath, report);
|
|
541
559
|
}
|
|
560
|
+
cleanupDeprecatedTsconfigOptions(projectPath, silent, report);
|
|
542
561
|
mergeViteConfigFiles(projectPath, silent, report);
|
|
543
562
|
injectLintTypeCheckDefaults(projectPath, silent, report);
|
|
544
563
|
injectFmtDefaults(projectPath, silent, report);
|
|
@@ -571,6 +590,7 @@ export function rewriteMonorepo(workspaceInfo, skipStagedMigration, silent = fal
|
|
|
571
590
|
if (!skipStagedMigration) {
|
|
572
591
|
rewriteLintStagedConfigFile(workspaceInfo.rootDir, report);
|
|
573
592
|
}
|
|
593
|
+
cleanupDeprecatedTsconfigOptions(workspaceInfo.rootDir, silent, report);
|
|
574
594
|
mergeViteConfigFiles(workspaceInfo.rootDir, silent, report);
|
|
575
595
|
injectLintTypeCheckDefaults(workspaceInfo.rootDir, silent, report);
|
|
576
596
|
injectFmtDefaults(workspaceInfo.rootDir, silent, report);
|
|
@@ -585,6 +605,7 @@ export function rewriteMonorepo(workspaceInfo, skipStagedMigration, silent = fal
|
|
|
585
605
|
* @param projectPath - The path to the project
|
|
586
606
|
*/
|
|
587
607
|
export function rewriteMonorepoProject(projectPath, packageManager, skipStagedMigration, silent = false, report) {
|
|
608
|
+
cleanupDeprecatedTsconfigOptions(projectPath, silent, report);
|
|
588
609
|
mergeViteConfigFiles(projectPath, silent, report);
|
|
589
610
|
mergeTsdownConfigFile(projectPath, silent, report);
|
|
590
611
|
const packageJsonPath = path.join(projectPath, 'package.json');
|
|
@@ -1602,3 +1623,75 @@ function setPackageManager(projectDir, downloadPackageManager) {
|
|
|
1602
1623
|
return pkg;
|
|
1603
1624
|
});
|
|
1604
1625
|
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Detect a .nvmrc file in the project directory.
|
|
1628
|
+
* Returns undefined if not found or .node-version already exists.
|
|
1629
|
+
*/
|
|
1630
|
+
export function detectNodeVersionManagerFile(projectPath) {
|
|
1631
|
+
// already has .node-version — skip detection to avoid false positives and preserve existing file
|
|
1632
|
+
if (fs.existsSync(path.join(projectPath, '.node-version'))) {
|
|
1633
|
+
return undefined;
|
|
1634
|
+
}
|
|
1635
|
+
const configs = detectConfigs(projectPath);
|
|
1636
|
+
if (configs.nvmrcFile) {
|
|
1637
|
+
return { file: '.nvmrc' };
|
|
1638
|
+
}
|
|
1639
|
+
return undefined;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Parse a version alias from a .nvmrc file into a .node-version compatible string.
|
|
1643
|
+
* Accepts the first line of .nvmrc (pre-trimmed).
|
|
1644
|
+
* Returns null for unsupported aliases like "system", "default", "iojs".
|
|
1645
|
+
*/
|
|
1646
|
+
export function parseNvmrcVersion(alias) {
|
|
1647
|
+
const version = alias.trim();
|
|
1648
|
+
if (!version) {
|
|
1649
|
+
return null;
|
|
1650
|
+
}
|
|
1651
|
+
// "node" and "stable" mean "latest stable release" which maps closely to lts/*.
|
|
1652
|
+
// Starting from Node 27, all releases will be LTS, so the gap is shrinking.
|
|
1653
|
+
// We map these to lts/* and log the conversion so users are aware.
|
|
1654
|
+
if (version === 'node' || version === 'stable') {
|
|
1655
|
+
return 'lts/*';
|
|
1656
|
+
}
|
|
1657
|
+
// "iojs", "system", and "default" have no meaningful equivalent and cannot be auto-migrated.
|
|
1658
|
+
if (version === 'iojs' || version === 'system' || version === 'default') {
|
|
1659
|
+
return null;
|
|
1660
|
+
}
|
|
1661
|
+
// LTS aliases (lts/*, lts/iron, etc.) pass through as-is
|
|
1662
|
+
if (version.startsWith('lts/')) {
|
|
1663
|
+
return version;
|
|
1664
|
+
}
|
|
1665
|
+
// Strip optional 'v' prefix, then validate as a semver version or range
|
|
1666
|
+
const normalized = version.startsWith('v') ? version.slice(1) : version;
|
|
1667
|
+
if (!normalized || !semver.validRange(normalized)) {
|
|
1668
|
+
return null;
|
|
1669
|
+
}
|
|
1670
|
+
return normalized;
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* Migrate .nvmrc to .node-version and remove .nvmrc.
|
|
1674
|
+
* Returns true on success, false if migration was skipped or failed.
|
|
1675
|
+
*/
|
|
1676
|
+
export function migrateNodeVersionManagerFile(projectPath, _detection, report) {
|
|
1677
|
+
const sourcePath = path.join(projectPath, '.nvmrc');
|
|
1678
|
+
const nodeVersionPath = path.join(projectPath, '.node-version');
|
|
1679
|
+
const content = fs.readFileSync(sourcePath, 'utf8');
|
|
1680
|
+
const originalAlias = content.split('\n')[0]?.trim() ?? '';
|
|
1681
|
+
const version = parseNvmrcVersion(originalAlias);
|
|
1682
|
+
if (!version) {
|
|
1683
|
+
warnMigration('.nvmrc contains an unsupported version alias. Create .node-version manually with your desired Node.js version.', report);
|
|
1684
|
+
return false;
|
|
1685
|
+
}
|
|
1686
|
+
// TODO: remove this log once Node 27+ makes all releases LTS, at which point
|
|
1687
|
+
// "node"/"stable" and "lts/*" will be effectively equivalent.
|
|
1688
|
+
if (version === 'lts/*' && (originalAlias === 'node' || originalAlias === 'stable')) {
|
|
1689
|
+
prompts.log.info(`"${originalAlias}" in .nvmrc is not a specific version; automatically mapping to "lts/*"`);
|
|
1690
|
+
}
|
|
1691
|
+
fs.writeFileSync(nodeVersionPath, `${version}\n`);
|
|
1692
|
+
fs.unlinkSync(sourcePath);
|
|
1693
|
+
if (report) {
|
|
1694
|
+
report.nodeVersionFileMigrated = true;
|
|
1695
|
+
}
|
|
1696
|
+
return true;
|
|
1697
|
+
}
|
package/dist/migration/report.js
CHANGED
package/dist/utils/tsconfig.d.ts
CHANGED
|
@@ -4,3 +4,5 @@
|
|
|
4
4
|
* so typeAware/typeCheck must be disabled when it is present.
|
|
5
5
|
*/
|
|
6
6
|
export declare function hasBaseUrlInTsconfig(projectPath: string): boolean;
|
|
7
|
+
export declare function findTsconfigFiles(projectPath: string): string[];
|
|
8
|
+
export declare function removeDeprecatedTsconfigFalseOption(filePath: string, optionName: string): boolean;
|
package/dist/utils/tsconfig.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { applyEdits, modify, parse as parseJsonc } from 'jsonc-parser';
|
|
3
4
|
/**
|
|
4
5
|
* Check if tsconfig.json has compilerOptions.baseUrl set.
|
|
5
6
|
* oxlint's TypeScript checker (tsgolint) does not support baseUrl,
|
|
@@ -14,3 +15,39 @@ export function hasBaseUrlInTsconfig(projectPath) {
|
|
|
14
15
|
return false;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
18
|
+
const TSCONFIG_FILE_RE = /^tsconfig(\.[\w-]+)?\.json$/i;
|
|
19
|
+
export function findTsconfigFiles(projectPath) {
|
|
20
|
+
try {
|
|
21
|
+
const entries = fs.readdirSync(projectPath);
|
|
22
|
+
return entries
|
|
23
|
+
.filter((name) => TSCONFIG_FILE_RE.test(name))
|
|
24
|
+
.map((name) => path.join(projectPath, name));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// jsonc-parser is in dependencies (not devDependencies) so it's available at
|
|
31
|
+
// runtime for tsc-compiled code (init-config.ts imports this file).
|
|
32
|
+
// TODO: move back to devDependencies once the bundle refactoring lands
|
|
33
|
+
// https://github.com/voidzero-dev/vite-plus/issues/744
|
|
34
|
+
export function removeDeprecatedTsconfigFalseOption(filePath, optionName) {
|
|
35
|
+
let text;
|
|
36
|
+
try {
|
|
37
|
+
text = fs.readFileSync(filePath, 'utf-8');
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const parsed = parseJsonc(text);
|
|
43
|
+
if (parsed?.compilerOptions?.[optionName] !== false) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const edits = modify(text, ['compilerOptions', optionName], undefined, {});
|
|
47
|
+
if (edits.length === 0) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const newText = applyEdits(text, edits);
|
|
51
|
+
fs.writeFileSync(filePath, newText);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plus",
|
|
3
|
-
"version": "0.1.15-alpha.
|
|
3
|
+
"version": "0.1.15-alpha.3",
|
|
4
4
|
"description": "The Unified Toolchain for the Web",
|
|
5
5
|
"homepage": "https://viteplus.dev/guide",
|
|
6
6
|
"bugs": {
|
|
@@ -313,12 +313,13 @@
|
|
|
313
313
|
"@oxc-project/types": "=0.122.0",
|
|
314
314
|
"cac": "^7.0.0",
|
|
315
315
|
"cross-spawn": "^7.0.5",
|
|
316
|
+
"jsonc-parser": "^3.3.1",
|
|
316
317
|
"oxfmt": "=0.42.0",
|
|
317
318
|
"oxlint": "=1.57.0",
|
|
318
319
|
"oxlint-tsgolint": "=0.17.4",
|
|
319
320
|
"picocolors": "^1.1.1",
|
|
320
|
-
"@voidzero-dev/vite-plus-
|
|
321
|
-
"@voidzero-dev/vite-plus-
|
|
321
|
+
"@voidzero-dev/vite-plus-core": "0.1.15-alpha.3",
|
|
322
|
+
"@voidzero-dev/vite-plus-test": "0.1.15-alpha.3"
|
|
322
323
|
},
|
|
323
324
|
"devDependencies": {
|
|
324
325
|
"@napi-rs/cli": "^3.4.1",
|
|
@@ -331,7 +332,6 @@
|
|
|
331
332
|
"detect-indent": "^7.0.2",
|
|
332
333
|
"detect-newline": "^4.0.1",
|
|
333
334
|
"glob": "^13.0.0",
|
|
334
|
-
"jsonc-parser": "^3.3.1",
|
|
335
335
|
"lint-staged": "^16.2.6",
|
|
336
336
|
"minimatch": "^10.0.3",
|
|
337
337
|
"mri": "^1.2.0",
|
|
@@ -340,9 +340,9 @@
|
|
|
340
340
|
"tsdown": "^0.21.5",
|
|
341
341
|
"validate-npm-package-name": "^7.0.2",
|
|
342
342
|
"yaml": "^2.8.1",
|
|
343
|
-
"@voidzero-dev/vite-plus-prompts": "0.0.0",
|
|
344
343
|
"rolldown": "1.0.0-rc.12",
|
|
345
|
-
"
|
|
344
|
+
"@voidzero-dev/vite-plus-prompts": "0.0.0",
|
|
345
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.15-alpha.3"
|
|
346
346
|
},
|
|
347
347
|
"napi": {
|
|
348
348
|
"binaryName": "vite-plus",
|
|
@@ -362,14 +362,14 @@
|
|
|
362
362
|
"node": "^20.19.0 || >=22.12.0"
|
|
363
363
|
},
|
|
364
364
|
"optionalDependencies": {
|
|
365
|
-
"@voidzero-dev/vite-plus-darwin-arm64": "0.1.15-alpha.
|
|
366
|
-
"@voidzero-dev/vite-plus-darwin-x64": "0.1.15-alpha.
|
|
367
|
-
"@voidzero-dev/vite-plus-linux-arm64-gnu": "0.1.15-alpha.
|
|
368
|
-
"@voidzero-dev/vite-plus-linux-arm64-musl": "0.1.15-alpha.
|
|
369
|
-
"@voidzero-dev/vite-plus-linux-x64-gnu": "0.1.15-alpha.
|
|
370
|
-
"@voidzero-dev/vite-plus-linux-x64-musl": "0.1.15-alpha.
|
|
371
|
-
"@voidzero-dev/vite-plus-win32-x64-msvc": "0.1.15-alpha.
|
|
372
|
-
"@voidzero-dev/vite-plus-win32-arm64-msvc": "0.1.15-alpha.
|
|
365
|
+
"@voidzero-dev/vite-plus-darwin-arm64": "0.1.15-alpha.3",
|
|
366
|
+
"@voidzero-dev/vite-plus-darwin-x64": "0.1.15-alpha.3",
|
|
367
|
+
"@voidzero-dev/vite-plus-linux-arm64-gnu": "0.1.15-alpha.3",
|
|
368
|
+
"@voidzero-dev/vite-plus-linux-arm64-musl": "0.1.15-alpha.3",
|
|
369
|
+
"@voidzero-dev/vite-plus-linux-x64-gnu": "0.1.15-alpha.3",
|
|
370
|
+
"@voidzero-dev/vite-plus-linux-x64-musl": "0.1.15-alpha.3",
|
|
371
|
+
"@voidzero-dev/vite-plus-win32-x64-msvc": "0.1.15-alpha.3",
|
|
372
|
+
"@voidzero-dev/vite-plus-win32-arm64-msvc": "0.1.15-alpha.3"
|
|
373
373
|
},
|
|
374
374
|
"scripts": {
|
|
375
375
|
"build": "oxnode -C dev ./build.ts",
|