Skip to content

Commit

Permalink
Respect original package.json indentation (#6375)
Browse files Browse the repository at this point in the history
* fix(#6338): respect original indentation

* chore: add changeset
  • Loading branch information
natemoo-re authored Feb 27, 2023
1 parent 71743ae commit 754c5ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-balloons-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Respect original `package.json` indentation
8 changes: 5 additions & 3 deletions packages/create-astro/src/actions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 754c5ca

Please sign in to comment.