Skip to content

Commit

Permalink
fix(javascript/bump_version): json file with last blank line (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaddollxz authored May 17, 2024
1 parent a849fdf commit f17f42f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions denoified-actions/javascript/bump_version/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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":(.*?)"(?<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);
Expand Down

0 comments on commit f17f42f

Please sign in to comment.