From 0812599fae221c2a74037ab3b9fc0fd131bf07df Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Mon, 27 Feb 2023 09:49:43 -0600 Subject: [PATCH 1/2] fix(#6338): respect original indentation --- packages/create-astro/src/actions/template.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index 5804fbb58b1d..f99726b1c9f7 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -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) { From 9c00254b99c1ca8c5c00af1daad3c6111380a99f Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Mon, 27 Feb 2023 09:51:57 -0600 Subject: [PATCH 2/2] chore: add changeset --- .changeset/real-balloons-cough.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/real-balloons-cough.md diff --git a/.changeset/real-balloons-cough.md b/.changeset/real-balloons-cough.md new file mode 100644 index 000000000000..d8ba66c63ffc --- /dev/null +++ b/.changeset/real-balloons-cough.md @@ -0,0 +1,5 @@ +--- +'create-astro': patch +--- + +Respect original `package.json` indentation