Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/vercel-gitignore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Add `.vercel` to `.gitignore` when adding the Vercel adapter via `astro add vercel`
37 changes: 37 additions & 0 deletions packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,43 @@ export async function add(names: string[], { flags }: AddOptions) {
defaultConfigContent: STUBS.LIT_NPMRC,
});
}
// The Vercel adapter outputs to .vercel/output which should be gitignored
if (integrations.find((integration) => integration.id === 'vercel')) {
const gitignorePath = new URL('./.gitignore', root);
const gitignoreEntry = '.vercel';

if (existsSync(gitignorePath)) {
const content = await fs.readFile(fileURLToPath(gitignorePath), { encoding: 'utf-8' });
if (!content.includes(gitignoreEntry)) {
logger.info(
'SKIP_FORMAT',
`\n ${magenta(`Astro will add ${green('.vercel')} to ${green('.gitignore')}.`)}\n`,
);

if (await askToContinue({ flags, logger })) {
const newContent = content.endsWith('\n')
? `${content}${gitignoreEntry}\n`
: `${content}\n${gitignoreEntry}\n`;
await fs.writeFile(fileURLToPath(gitignorePath), newContent, { encoding: 'utf-8' });
logger.debug('add', 'Updated .gitignore with .vercel');
}
} else {
logger.debug('add', '.vercel already in .gitignore');
}
} else {
logger.info(
'SKIP_FORMAT',
`\n ${magenta(`Astro will create ${green('.gitignore')} with ${green('.vercel')}.`)}\n`,
);

if (await askToContinue({ flags, logger })) {
await fs.writeFile(fileURLToPath(gitignorePath), `${gitignoreEntry}\n`, {
encoding: 'utf-8',
});
logger.debug('add', 'Created .gitignore with .vercel');
}
}
}
break;
}
case UpdateResult.cancelled: {
Expand Down