Skip to content

Commit

Permalink
fix: preserve newline at the end of package.json after update (#14)
Browse files Browse the repository at this point in the history
* fix: add newline at the end of package.json after update

* fix: update with dynamic line-endings
  • Loading branch information
ndom91 committed Apr 29, 2024
1 parent fe30876 commit a530ea8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/monorepo-release/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@ import { Config, defaultConfig } from "./config.js"

async function read(
directory: string,
): Promise<Required<PackageJson & { release?: Partial<Config> }>> {
raw?: boolean
): Promise<Required<PackageJson & { release?: Partial<Config> }> | string> {
const content = await fs.readFile(
path.join(process.cwd(), directory, "package.json"),
"utf8",
)
return JSON.parse(content)
return raw ? content : JSON.parse(content)
}

async function update(
directory: string,
data: Partial<PackageJson>,
): Promise<void> {
const original = await pkgJson.read(directory)
const content = JSON.stringify({ ...original, ...data }, null, 2)
const original = await pkgJson.read(directory, true) as string
let content = JSON.stringify({ ...JSON.parse(original), ...data }, null, 2)
content += original.endsWith("\r\n") ? "\r\n" : "\n"
await fs.writeFile(
path.join(process.cwd(), directory, "package.json"),
content,
"utf8",
)
}

Expand Down Expand Up @@ -69,8 +70,8 @@ export function pluralize(
typeof count === "number"
? count
: count instanceof Set || count instanceof Map
? count.size
: count.length
? count.size
: count.length

const pluralForm = pluralRules.select(count)
switch (pluralForm) {
Expand Down

0 comments on commit a530ea8

Please sign in to comment.