File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change 1
- import { writeFile } from 'node:fs/promises'
1
+ import { readFile , writeFile } from 'node:fs/promises'
2
2
import path from 'node:path'
3
3
import { RE_DTS } from 'rolldown-plugin-dts/filename'
4
4
import { slash } from '../utils/general'
@@ -61,14 +61,16 @@ export async function writeExports(
61
61
updatedPkg . publishConfig . exports = publishExports
62
62
}
63
63
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 ,
71
69
)
70
+ if ( original . endsWith ( '\n' ) ) contents += '\n'
71
+ if ( contents !== original ) {
72
+ await writeFile ( pkg . packageJsonPath , contents , 'utf8' )
73
+ }
72
74
}
73
75
74
76
type SubExport = Partial < Record < 'cjs' | 'es' | 'src' , string > >
You can’t perform that action at this time.
0 commit comments