Skip to content

Commit bd5b720

Browse files
Do not override any .env settings in .gitignore files (#10766)
* do not override .env settings in .gitignore files Fixes #10749 * fixup! do not override .env settings in .gitignore files * fixup! do not override .env settings in .gitignore files * fixup! do not override .env settings in .gitignore files
1 parent 7f2386e commit bd5b720

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

.changeset/silly-parks-fall.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
Do not override any `.env` settings in `.gitignore` files
6+
7+
Previously we only looked for `.env*` in the `gitignore` but now we cover more cases such as:
8+
9+
- `.env`
10+
- `.env\*`
11+
- `.env.<local|production|staging|...>`
12+
- `.env\*.<local|production|staging|...>`

packages/create-cloudflare/src/__tests__/templates.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,32 @@ describe("addWranglerToGitIgnore", () => {
320320
`);
321321
});
322322

323+
test("should not add the .env entries if some form of .env entries are already included", () => {
324+
mockGitIgnore(
325+
"my-project/.gitignore",
326+
`
327+
.env
328+
.env.*
329+
!.env.example
330+
`,
331+
);
332+
addWranglerToGitIgnore({
333+
project: { path: "my-project" },
334+
} as unknown as C3Context);
335+
336+
expect(appendFileResults.file).toMatchInlineSnapshot(
337+
`"my-project/.gitignore"`,
338+
);
339+
expect(appendFileResults.content).toMatchInlineSnapshot(`
340+
"
341+
# wrangler files
342+
.wrangler
343+
.dev.vars*
344+
!.dev.vars.example
345+
"
346+
`);
347+
});
348+
323349
test("should not add the .wrangler entry if a .wrangler/ is already included)", () => {
324350
mockGitIgnore(
325351
"my-project/.gitignore",

packages/create-cloudflare/src/templates.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,25 @@ export const addWranglerToGitIgnore = (ctx: C3Context) => {
958958
wranglerGitIgnoreFilesToAdd.push("!.dev.vars.example");
959959
}
960960

961-
const hasDotEnv = existingGitIgnoreContent.match(/^\/?\.env\*(\s|$)/m);
961+
/**
962+
* We check for the following type of occurrences:
963+
*
964+
* ```
965+
* .env
966+
* .env*
967+
* .env.<local|production|staging|...>
968+
* .env*.<local|production|staging|...>
969+
* ```
970+
*
971+
* Any of these may alone on a line or be followed by a space and a trailing comment:
972+
*
973+
* ```
974+
* .env.<local|production|staging> # some trailing comment
975+
* ```
976+
*/
977+
const hasDotEnv = existingGitIgnoreContent.match(
978+
/^\/?\.env\*?(\..*?)?(\s|$)/m,
979+
);
962980
if (!hasDotEnv) {
963981
wranglerGitIgnoreFilesToAdd.push(".env*");
964982
}

0 commit comments

Comments
 (0)