diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..12d512c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +## 0.2.0 + +Append new rules to existing `.htaccess` file instead of overwriting it. + +## 0.1.2 + +Fix redirects by checking the `redirect` field. + +## 0.1.1 + +Initial release. diff --git a/src/htaccess.ts b/src/htaccess.ts index ef04fb6..a2b4119 100644 --- a/src/htaccess.ts +++ b/src/htaccess.ts @@ -1,4 +1,5 @@ import type { AstroIntegration } from "astro"; +import { existsSync } from "node:fs"; import { writeFile } from "node:fs/promises"; import path, { posix as pathPosix } from "node:path"; import { fileURLToPath, URL } from "node:url"; @@ -176,7 +177,8 @@ export const integration = ({ generateHtaccessFile, errorPages, redirects, custo .map((fn) => fn()) .flat(); if (!error) { - await writeFile(path.join(assetsDir, ".htaccess"), htaccess.join("\n")); + const htaccessPath = path.join(assetsDir, ".htaccess"); + await writeFile(htaccessPath, [existsSync(htaccessPath) ? "\n" : "", htaccess.join("\n")], { flag: 'a' }); logger.info(`Generated .htaccess with ${htaccess.length} ${htaccess.length === 1 ? "rule" : "rules"}`); } },