0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Respect original package.json indentation (#6375)

* fix(#6338): respect original indentation

* chore: add changeset
This commit is contained in:
Nate Moore 2023-02-27 10:09:54 -06:00 committed by GitHub
parent 71743aeca7
commit 754c5ca9aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'create-astro': patch
---
Respect original `package.json` indentation

View file

@ -50,17 +50,19 @@ const FILES_TO_UPDATE = {
'package.json': (file: string, overrides: { name: string }) =>
fs.promises
.readFile(file, 'utf-8')
.then((value) =>
.then((value) => {
// Match first indent in the file or fallback to `\t`
const indent = /(^\s+)/m.exec(value)?.[1] ?? '\t';
fs.promises.writeFile(
file,
JSON.stringify(
Object.assign(JSON.parse(value), Object.assign(overrides, { private: undefined })),
null,
'\t'
indent
),
'utf-8'
)
),
}),
};
export default async function copyTemplate(tmpl: string, ctx: Context) {