Skip to content

Commit ba20fd5

Browse files
committed
feat(exports): auto indent & eof
closes #346
1 parent 845feb8 commit ba20fd5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/features/exports.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFile } from 'node:fs/promises'
1+
import { readFile, writeFile } from 'node:fs/promises'
22
import path from 'node:path'
33
import { RE_DTS } from 'rolldown-plugin-dts/filename'
44
import { slash } from '../utils/general'
@@ -61,14 +61,16 @@ export async function writeExports(
6161
updatedPkg.publishConfig.exports = publishExports
6262
}
6363

64-
await writeFile(
65-
pkg.packageJsonPath,
66-
`${JSON.stringify(
67-
{ ...pkg, ...generated, packageJsonPath: undefined },
68-
null,
69-
2,
70-
)}\n`,
64+
const original = await readFile(pkg.packageJsonPath, 'utf8')
65+
let contents = JSON.stringify(
66+
updatedPkg,
67+
null,
68+
original.includes('\t') ? '\t' : 2,
7169
)
70+
if (original.endsWith('\n')) contents += '\n'
71+
if (contents !== original) {
72+
await writeFile(pkg.packageJsonPath, contents, 'utf8')
73+
}
7274
}
7375

7476
type SubExport = Partial<Record<'cjs' | 'es' | 'src', string>>

0 commit comments

Comments
 (0)