Skip to content

Commit 7782a9b

Browse files
committed
Make .dev.vars and .env consistent and remove deprecated templates
1 parent 4a4049c commit 7782a9b

File tree

30 files changed

+220
-986
lines changed

30 files changed

+220
-986
lines changed

.gitignore

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ web_modules/
108108
# Yarn Integrity file
109109
.yarn-integrity
110110

111-
# dotenv environment variable files
112-
.env
113-
.env.development.local
114-
.env.test.local
115-
.env.production.local
116-
.env.local
117-
118111
# parcel-bundler cache (https://parceljs.org/)
119112
.cache
120113
.parcel-cache
@@ -232,5 +225,8 @@ dist/**
232225

233226
.e2e-test-report/
234227

235-
.dev.vars
228+
.dev.vars*
229+
!.dev.vars.example
230+
.env*
231+
!.env.example
236232
.node-cache/

fixtures/container-app/.gitignore

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ web_modules/
9292

9393
.yarn-integrity
9494

95-
# dotenv environment variable files
96-
97-
.env
98-
.env.development.local
99-
.env.test.local
100-
.env.production.local
101-
.env.local
102-
10395
# parcel-bundler cache (https://parceljs.org/)
10496

10597
.cache
@@ -168,6 +160,9 @@ dist
168160

169161
# wrangler project
170162

171-
.dev.vars
163+
.dev.vars*
164+
!.dev.vars.example
165+
.env*
166+
!.env.example
172167
.wrangler/
173168
worker-configuration.d.ts

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

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ describe("addWranglerToGitIgnore", () => {
8888
# wrangler files
8989
.wrangler
9090
.dev.vars*
91+
!.dev.vars.example
92+
.env*
93+
!.env.example
9194
"
9295
`);
9396
});
@@ -97,7 +100,10 @@ describe("addWranglerToGitIgnore", () => {
97100
"my-project/.gitignore",
98101
`
99102
node_modules
100-
.dev.vars
103+
.dev.vars*
104+
!.dev.vars.example
105+
.env*
106+
!.env.example
101107
.vscode
102108
.wrangler
103109
`,
@@ -116,7 +122,10 @@ describe("addWranglerToGitIgnore", () => {
116122
`
117123
node_modules
118124
.wrangler # This is for wrangler
119-
.dev.vars # this is for wrangler and getPlatformProxy
125+
.dev.vars* # this is for wrangler and getPlatformProxy
126+
!.dev.vars.example # more comments
127+
.env* # even more
128+
!.env.example # and a final one
120129
.vscode
121130
`,
122131
);
@@ -128,12 +137,68 @@ describe("addWranglerToGitIgnore", () => {
128137
expect(appendFileResults.content).toBeUndefined();
129138
});
130139

131-
test("should append to the gitignore file the missing wrangler files when some is already present (without including the section heading)", () => {
140+
test("should append to the gitignore file the missing wrangler files when some are already present (should add the section heading if including .wrangler and some others)", () => {
132141
mockGitIgnore(
133142
"my-project/.gitignore",
134143
`
135144
node_modules
136-
.dev.vars
145+
.dev.vars*
146+
.vscode`,
147+
);
148+
addWranglerToGitIgnore({
149+
project: { path: "my-project" },
150+
} as unknown as C3Context);
151+
152+
expect(appendFileResults.file).toMatchInlineSnapshot(
153+
`"my-project/.gitignore"`,
154+
);
155+
expect(appendFileResults.content).toMatchInlineSnapshot(`
156+
"
157+
158+
# wrangler files
159+
.wrangler
160+
!.dev.vars.example
161+
.env*
162+
!.env.example
163+
"
164+
`);
165+
});
166+
167+
test("should append to the gitignore file the missing wrangler files when some are already present (should not add the section heading if .wrangler already exists)", () => {
168+
mockGitIgnore(
169+
"my-project/.gitignore",
170+
`
171+
node_modules
172+
.wrangler
173+
.dev.vars*
174+
.vscode`,
175+
);
176+
addWranglerToGitIgnore({
177+
project: { path: "my-project" },
178+
} as unknown as C3Context);
179+
180+
expect(appendFileResults.file).toMatchInlineSnapshot(
181+
`"my-project/.gitignore"`,
182+
);
183+
expect(appendFileResults.content).toMatchInlineSnapshot(`
184+
"
185+
186+
!.dev.vars.example
187+
.env*
188+
!.env.example
189+
"
190+
`);
191+
});
192+
193+
test("should append to the gitignore file the missing wrangler files when some are already present (should not add the section heading if only adding .wrangler)", () => {
194+
mockGitIgnore(
195+
"my-project/.gitignore",
196+
`
197+
node_modules
198+
.dev.vars*
199+
!.dev.vars.example
200+
.env*
201+
!.env.example
137202
.vscode`,
138203
);
139204
addWranglerToGitIgnore({
@@ -156,7 +221,10 @@ describe("addWranglerToGitIgnore", () => {
156221
"my-project/.gitignore",
157222
`
158223
node_modules
159-
.dev.vars
224+
.dev.vars*
225+
!.dev.vars.example
226+
.env*
227+
!.env.example
160228
.vscode
161229
162230
`,
@@ -203,6 +271,9 @@ describe("addWranglerToGitIgnore", () => {
203271
# wrangler files
204272
.wrangler
205273
.dev.vars*
274+
!.dev.vars.example
275+
.env*
276+
!.env.example
206277
"
207278
`);
208279
});
@@ -221,6 +292,34 @@ describe("addWranglerToGitIgnore", () => {
221292
expect(writeFileResults.content).toBeUndefined();
222293
});
223294

295+
test("should add the wildcard .dev.vars* entry even if a .dev.vars is already included", () => {
296+
mockGitIgnore(
297+
"my-project/.gitignore",
298+
`
299+
node_modules
300+
.dev.vars
301+
.vscode
302+
`,
303+
);
304+
addWranglerToGitIgnore({
305+
project: { path: "my-project" },
306+
} as unknown as C3Context);
307+
308+
expect(appendFileResults.file).toMatchInlineSnapshot(
309+
`"my-project/.gitignore"`,
310+
);
311+
expect(appendFileResults.content).toMatchInlineSnapshot(`
312+
"
313+
# wrangler files
314+
.wrangler
315+
.dev.vars*
316+
!.dev.vars.example
317+
.env*
318+
!.env.example
319+
"
320+
`);
321+
});
322+
224323
test("should not add the .wrangler entry if a .wrangler/ is already included)", () => {
225324
mockGitIgnore(
226325
"my-project/.gitignore",
@@ -240,6 +339,9 @@ describe("addWranglerToGitIgnore", () => {
240339
expect(appendFileResults.content).toMatchInlineSnapshot(`
241340
"
242341
.dev.vars*
342+
!.dev.vars.example
343+
.env*
344+
!.env.example
243345
"
244346
`);
245347
});

packages/create-cloudflare/src/templates.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,31 @@ export const addWranglerToGitIgnore = (ctx: C3Context) => {
916916
}
917917

918918
const hasDotDevDotVars = existingGitIgnoreContent.match(
919-
/^\/?\.dev\.vars(\.?\*)?(\s|$)/m,
919+
/^\/?\.dev\.vars\*(\s|$)/m,
920920
);
921921
if (!hasDotDevDotVars) {
922922
wranglerGitIgnoreFilesToAdd.push(".dev.vars*");
923923
}
924924

925+
const hasDotDevVarsExample = existingGitIgnoreContent.match(
926+
/^!\/?\.dev\.vars\.example(\s|$)/m,
927+
);
928+
if (!hasDotDevVarsExample) {
929+
wranglerGitIgnoreFilesToAdd.push("!.dev.vars.example");
930+
}
931+
932+
const hasDotEnv = existingGitIgnoreContent.match(/^\/?\.env\*(\s|$)/m);
933+
if (!hasDotEnv) {
934+
wranglerGitIgnoreFilesToAdd.push(".env*");
935+
}
936+
937+
const hasDotEnvExample = existingGitIgnoreContent.match(
938+
/^!\/?\.env\.example(\s|$)/m,
939+
);
940+
if (!hasDotEnvExample) {
941+
wranglerGitIgnoreFilesToAdd.push("!.env.example");
942+
}
943+
925944
if (wranglerGitIgnoreFilesToAdd.length === 0) {
926945
return;
927946
}
@@ -934,7 +953,7 @@ export const addWranglerToGitIgnore = (ctx: C3Context) => {
934953
...(!existingGitIgnoreContent.match(/\n\s*$/) ? [""] : []),
935954
];
936955

937-
if (wranglerGitIgnoreFilesToAdd.length > 1) {
956+
if (!hasDotWrangler && wranglerGitIgnoreFilesToAdd.length > 1) {
938957
linesToAppend.push("# wrangler files");
939958
}
940959

packages/create-cloudflare/templates/common/js/.gitignore

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ web_modules/
9292

9393
.yarn-integrity
9494

95-
# dotenv environment variable files
96-
97-
.env
98-
.env.development.local
99-
.env.test.local
100-
.env.production.local
101-
.env.local
102-
10395
# parcel-bundler cache (https://parceljs.org/)
10496

10597
.cache
@@ -168,5 +160,8 @@ dist
168160

169161
# wrangler project
170162

171-
.dev.vars
163+
.dev.vars*
164+
!.dev.vars.example
165+
.env*
166+
!.env.example
172167
.wrangler/

packages/create-cloudflare/templates/common/ts/.gitignore

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ web_modules/
9292

9393
.yarn-integrity
9494

95-
# dotenv environment variable files
96-
97-
.env
98-
.env.development.local
99-
.env.test.local
100-
.env.production.local
101-
.env.local
102-
10395
# parcel-bundler cache (https://parceljs.org/)
10496

10597
.cache

packages/create-cloudflare/templates/hello-world-durable-object-with-assets/js/.gitignore

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ web_modules/
9292

9393
.yarn-integrity
9494

95-
# dotenv environment variable files
96-
97-
.env
98-
.env.development.local
99-
.env.test.local
100-
.env.production.local
101-
.env.local
102-
10395
# parcel-bundler cache (https://parceljs.org/)
10496

10597
.cache
@@ -168,5 +160,8 @@ dist
168160

169161
# wrangler project
170162

171-
.dev.vars
163+
.dev.vars*
164+
!.dev.vars.example
165+
.env*
166+
!.env.example
172167
.wrangler/

packages/create-cloudflare/templates/hello-world-durable-object-with-assets/py/.gitignore

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ jspm_packages/
4848

4949
\*.tgz
5050

51-
# dotenv environment variable files
52-
53-
.env
54-
.env.development.local
55-
.env.test.local
56-
.env.production.local
57-
.env.local
58-
5951
# public
6052

6153
# Stores VSCode versions used for testing VSCode extensions
@@ -64,5 +56,8 @@ jspm_packages/
6456

6557
# wrangler project
6658

67-
.dev.vars
59+
.dev.vars*
60+
!.dev.vars.example
61+
.env*
62+
!.env.example
6863
.wrangler/

packages/create-cloudflare/templates/hello-world-durable-object-with-assets/ts/.gitignore

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ web_modules/
9292

9393
.yarn-integrity
9494

95-
# dotenv environment variable files
96-
97-
.env
98-
.env.development.local
99-
.env.test.local
100-
.env.production.local
101-
.env.local
102-
10395
# parcel-bundler cache (https://parceljs.org/)
10496

10597
.cache
@@ -168,5 +160,8 @@ dist
168160

169161
# wrangler project
170162

171-
.dev.vars
163+
.dev.vars*
164+
!.dev.vars.example
165+
.env*
166+
!.env.example
172167
.wrangler/

0 commit comments

Comments
 (0)