From f17f42fd833a06209effa0870eb3151160a0669d Mon Sep 17 00:00:00 2001 From: shaddollxz <56341682+shaddollxz@users.noreply.github.com> Date: Fri, 17 May 2024 14:30:21 +0800 Subject: [PATCH] fix(javascript/bump_version): json file with last blank line (#89) --- .../javascript/bump_version/main.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/denoified-actions/javascript/bump_version/main.ts b/denoified-actions/javascript/bump_version/main.ts index 37420fa..cb4a093 100755 --- a/denoified-actions/javascript/bump_version/main.ts +++ b/denoified-actions/javascript/bump_version/main.ts @@ -31,7 +31,9 @@ if (!fileExists(packageFile)) { ); } -const packageInfo = JSON.parse(await Deno.readTextFile(packageFile)) as { +const packageContent = await Deno.readTextFile(packageFile); + +const packageInfo = JSON.parse(packageContent) as { version: string; name: string; }; @@ -40,7 +42,17 @@ const newVersion = format(increment(parse(packageInfo.version), bumpKind)); packageInfo.version = newVersion; -await Deno.writeTextFile(packageFile, JSON.stringify(packageInfo, null, " ")); +await Deno.writeTextFile( + packageFile, + packageContent.replace( + /"version":(.*?)"(?.+?)"/, + (match, ...arg) => { + const groups = arg.at(-1); + + return match.replace(groups.version, newVersion); + }, + ), +); const rootPath = new Path(Deno.cwd()); const repo = new Repo(rootPath);