From d03ad9d826d0d073ee4a56450341918cc09ac8dc Mon Sep 17 00:00:00 2001 From: claude-bot Date: Fri, 8 May 2026 20:18:13 +0900 Subject: [PATCH] Patch run.bat to use installed JDK path Co-Authored-By: Claude Opus 4.7 --- src/installer/main.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/installer/main.ts b/src/installer/main.ts index 0ff131f..c91a717 100644 --- a/src/installer/main.ts +++ b/src/installer/main.ts @@ -386,7 +386,14 @@ async function listFilesRecursively(root: string, predicate: (entryPath: string, return results } -async function patchRunBatFiles(root: string, pack: PackDefinition): Promise { +async function patchRunBatFiles(root: string, pack: PackDefinition, jdkPath: string): Promise { + const javaExec = resolveJavaExecutable(jdkPath) + const quotedJavaExec = `"${javaExec}"` + // Match a bare `java` / `java.exe` command invocation: preceded by start-of-line, + // whitespace, or a cmd separator (& | @), and followed by whitespace or EOL. This + // avoids touching path-embedded occurrences like `C:\jdk\bin\java.exe`. + const javaCommandPattern = /(^|[\s&|@])java(?:\.exe)?(?=\s|$)/gim + const runBatFiles = await listFilesRecursively(root, (_entryPath, entryName) => entryName.toLowerCase() === 'run.bat') for (const runBatPath of runBatFiles) { const raw = await fsp.readFile(runBatPath, 'utf8') @@ -394,13 +401,16 @@ async function patchRunBatFiles(root: string, pack: PackDefinition): Promise `${match} -Xms${pack.serverMinRam}M -Xmx${pack.serverMaxRam}M`) + if (!/-Xm[sx]/i.test(next) && /java(\.exe)?/i.test(next)) { + next = next.replace(javaCommandPattern, (_match, prefix: string) => + `${prefix}${quotedJavaExec} -Xms${pack.serverMinRam}M -Xmx${pack.serverMaxRam}M`) + } else { + next = next.replace(javaCommandPattern, (_match, prefix: string) => `${prefix}${quotedJavaExec}`) } if (next !== raw) { await fsp.writeFile(runBatPath, next, 'utf8') - sendLog(`run.bat 램 설정 반영: ${path.relative(root, runBatPath)}`) + sendLog(`run.bat JDK/램 설정 반영: ${path.relative(root, runBatPath)}`) } } } @@ -481,7 +491,7 @@ async function startInstall(payload: InstallPayload): Promise<{ nextStep: number const extractedRoot = await downloadAndExtractPack(packMeta.baseUrl, packMeta.packDefinition, payload.installPath) await ensureEditableConfigFiles(extractedRoot, packMeta.packDefinition) - await patchRunBatFiles(extractedRoot, packMeta.packDefinition) + await patchRunBatFiles(extractedRoot, packMeta.packDefinition, payload.jdkPath) const eulaPath = path.join(extractedRoot, 'eula.txt') if (fs.existsSync(eulaPath)) {