Respect original package.json
indentation (#6375)
* fix(#6338): respect original indentation * chore: add changeset
This commit is contained in:
parent
71743aeca7
commit
754c5ca9aa
2 changed files with 10 additions and 3 deletions
5
.changeset/real-balloons-cough.md
Normal file
5
.changeset/real-balloons-cough.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'create-astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Respect original `package.json` indentation
|
|
@ -50,17 +50,19 @@ const FILES_TO_UPDATE = {
|
||||||
'package.json': (file: string, overrides: { name: string }) =>
|
'package.json': (file: string, overrides: { name: string }) =>
|
||||||
fs.promises
|
fs.promises
|
||||||
.readFile(file, 'utf-8')
|
.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(
|
fs.promises.writeFile(
|
||||||
file,
|
file,
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
Object.assign(JSON.parse(value), Object.assign(overrides, { private: undefined })),
|
Object.assign(JSON.parse(value), Object.assign(overrides, { private: undefined })),
|
||||||
null,
|
null,
|
||||||
'\t'
|
indent
|
||||||
),
|
),
|
||||||
'utf-8'
|
'utf-8'
|
||||||
)
|
)
|
||||||
),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function copyTemplate(tmpl: string, ctx: Context) {
|
export default async function copyTemplate(tmpl: string, ctx: Context) {
|
||||||
|
|
Loading…
Reference in a new issue