mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
Ensure that the generated package.json and tsconfig.json end with a newline. (#12186)
This commit is contained in:
parent
1f93fca1d3
commit
49c4f64673
3 changed files with 11 additions and 3 deletions
5
.changeset/tidy-bugs-yawn.md
Normal file
5
.changeset/tidy-bugs-yawn.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'create-astro': minor
|
||||
---
|
||||
|
||||
Ensures new line at the end of the generated `package.json` and `tsconfig.json` files
|
|
@ -108,7 +108,7 @@ const FILES_TO_UPDATE = {
|
|||
parsedPackageJson.dependencies['@astrojs/check'] = `^${astroCheckVersion}`;
|
||||
parsedPackageJson.dependencies.typescript = `^${typescriptVersion}`;
|
||||
|
||||
await writeFile(file, JSON.stringify(parsedPackageJson, null, indent), 'utf-8');
|
||||
await writeFile(file, JSON.stringify(parsedPackageJson, null, indent) + '\n', 'utf-8');
|
||||
} catch (err) {
|
||||
// if there's no package.json (which is very unlikely), then do nothing
|
||||
if (err && (err as any).code === 'ENOENT') return;
|
||||
|
@ -124,7 +124,7 @@ const FILES_TO_UPDATE = {
|
|||
extends: `astro/tsconfigs/${options.value}`,
|
||||
});
|
||||
|
||||
await writeFile(file, JSON.stringify(result, null, 2));
|
||||
await writeFile(file, JSON.stringify(result, null, 2) + '\n');
|
||||
} else {
|
||||
throw new Error(
|
||||
"There was an error applying the requested TypeScript settings. This could be because the template's tsconfig.json is malformed",
|
||||
|
@ -135,7 +135,7 @@ const FILES_TO_UPDATE = {
|
|||
// If the template doesn't have a tsconfig.json, let's add one instead
|
||||
await writeFile(
|
||||
file,
|
||||
JSON.stringify({ extends: `astro/tsconfigs/${options.value}` }, null, 2),
|
||||
JSON.stringify({ extends: `astro/tsconfigs/${options.value}` }, null, 2) + '\n',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ describe('typescript: setup tsconfig', async () => {
|
|||
assert.deepEqual(JSON.parse(fs.readFileSync(tsconfig, { encoding: 'utf-8' })), {
|
||||
extends: 'astro/tsconfigs/strict',
|
||||
});
|
||||
assert(fs.readFileSync(tsconfig, { encoding: 'utf-8' }).endsWith('\n'), 'The file does not end with a newline');
|
||||
});
|
||||
|
||||
it('exists', async () => {
|
||||
|
@ -100,6 +101,7 @@ describe('typescript: setup tsconfig', async () => {
|
|||
assert.deepEqual(JSON.parse(fs.readFileSync(tsconfig, { encoding: 'utf-8' })), {
|
||||
extends: 'astro/tsconfigs/strict',
|
||||
});
|
||||
assert(fs.readFileSync(tsconfig, { encoding: 'utf-8' }).endsWith('\n'), 'The file does not end with a newline');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -124,6 +126,7 @@ describe('typescript: setup package', async () => {
|
|||
);
|
||||
|
||||
await setupTypeScript('strictest', { cwd: fileURLToPath(root), install: false });
|
||||
assert(fs.readFileSync(packageJson, { encoding: 'utf-8' }).endsWith('\n'), 'The file does not end with a newline');
|
||||
const { scripts, dependencies } = JSON.parse(
|
||||
fs.readFileSync(packageJson, { encoding: 'utf-8' }),
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue