Skip to content
Merged
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
12 changes: 4 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ web_modules/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
Expand Down Expand Up @@ -232,5 +225,8 @@ dist/**

.e2e-test-report/

.dev.vars
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.node-cache/
13 changes: 4 additions & 9 deletions fixtures/container-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ web_modules/

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
Expand Down Expand Up @@ -168,6 +160,9 @@ dist

# wrangler project

.dev.vars
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.wrangler/
worker-configuration.d.ts
112 changes: 107 additions & 5 deletions packages/create-cloudflare/src/__tests__/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ describe("addWranglerToGitIgnore", () => {
# wrangler files
.wrangler
.dev.vars*
!.dev.vars.example
.env*
!.env.example
"
`);
});
Expand All @@ -97,7 +100,10 @@ describe("addWranglerToGitIgnore", () => {
"my-project/.gitignore",
`
node_modules
.dev.vars
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.vscode
.wrangler
`,
Expand All @@ -116,7 +122,10 @@ describe("addWranglerToGitIgnore", () => {
`
node_modules
.wrangler # This is for wrangler
.dev.vars # this is for wrangler and getPlatformProxy
.dev.vars* # this is for wrangler and getPlatformProxy
!.dev.vars.example # more comments
.env* # even more
!.env.example # and a final one
.vscode
`,
);
Expand All @@ -128,12 +137,68 @@ describe("addWranglerToGitIgnore", () => {
expect(appendFileResults.content).toBeUndefined();
});

test("should append to the gitignore file the missing wrangler files when some is already present (without including the section heading)", () => {
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)", () => {
mockGitIgnore(
"my-project/.gitignore",
`
node_modules
.dev.vars
.dev.vars*
.vscode`,
);
addWranglerToGitIgnore({
project: { path: "my-project" },
} as unknown as C3Context);

expect(appendFileResults.file).toMatchInlineSnapshot(
`"my-project/.gitignore"`,
);
expect(appendFileResults.content).toMatchInlineSnapshot(`
"

# wrangler files
.wrangler
!.dev.vars.example
.env*
!.env.example
"
`);
});

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)", () => {
mockGitIgnore(
"my-project/.gitignore",
`
node_modules
.wrangler
.dev.vars*
.vscode`,
);
addWranglerToGitIgnore({
project: { path: "my-project" },
} as unknown as C3Context);

expect(appendFileResults.file).toMatchInlineSnapshot(
`"my-project/.gitignore"`,
);
expect(appendFileResults.content).toMatchInlineSnapshot(`
"

!.dev.vars.example
.env*
!.env.example
"
`);
});

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)", () => {
mockGitIgnore(
"my-project/.gitignore",
`
node_modules
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.vscode`,
);
addWranglerToGitIgnore({
Expand All @@ -156,7 +221,10 @@ describe("addWranglerToGitIgnore", () => {
"my-project/.gitignore",
`
node_modules
.dev.vars
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.vscode

`,
Expand Down Expand Up @@ -203,6 +271,9 @@ describe("addWranglerToGitIgnore", () => {
# wrangler files
.wrangler
.dev.vars*
!.dev.vars.example
.env*
!.env.example
"
`);
});
Expand All @@ -221,6 +292,34 @@ describe("addWranglerToGitIgnore", () => {
expect(writeFileResults.content).toBeUndefined();
});

test("should add the wildcard .dev.vars* entry even if a .dev.vars is already included", () => {
mockGitIgnore(
"my-project/.gitignore",
`
node_modules
.dev.vars
.vscode
`,
);
addWranglerToGitIgnore({
project: { path: "my-project" },
} as unknown as C3Context);

expect(appendFileResults.file).toMatchInlineSnapshot(
`"my-project/.gitignore"`,
);
expect(appendFileResults.content).toMatchInlineSnapshot(`
"
# wrangler files
.wrangler
.dev.vars*
!.dev.vars.example
.env*
!.env.example
"
`);
});

test("should not add the .wrangler entry if a .wrangler/ is already included)", () => {
mockGitIgnore(
"my-project/.gitignore",
Expand All @@ -240,6 +339,9 @@ describe("addWranglerToGitIgnore", () => {
expect(appendFileResults.content).toMatchInlineSnapshot(`
"
.dev.vars*
!.dev.vars.example
.env*
!.env.example
"
`);
});
Expand Down
23 changes: 21 additions & 2 deletions packages/create-cloudflare/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,12 +916,31 @@ export const addWranglerToGitIgnore = (ctx: C3Context) => {
}

const hasDotDevDotVars = existingGitIgnoreContent.match(
/^\/?\.dev\.vars(\.?\*)?(\s|$)/m,
/^\/?\.dev\.vars\*(\s|$)/m,
);
if (!hasDotDevDotVars) {
wranglerGitIgnoreFilesToAdd.push(".dev.vars*");
}

const hasDotDevVarsExample = existingGitIgnoreContent.match(
/^!\/?\.dev\.vars\.example(\s|$)/m,
);
if (!hasDotDevVarsExample) {
wranglerGitIgnoreFilesToAdd.push("!.dev.vars.example");
}

const hasDotEnv = existingGitIgnoreContent.match(/^\/?\.env\*(\s|$)/m);
if (!hasDotEnv) {
wranglerGitIgnoreFilesToAdd.push(".env*");
}

const hasDotEnvExample = existingGitIgnoreContent.match(
/^!\/?\.env\.example(\s|$)/m,
);
if (!hasDotEnvExample) {
wranglerGitIgnoreFilesToAdd.push("!.env.example");
}

if (wranglerGitIgnoreFilesToAdd.length === 0) {
return;
}
Expand All @@ -934,7 +953,7 @@ export const addWranglerToGitIgnore = (ctx: C3Context) => {
...(!existingGitIgnoreContent.match(/\n\s*$/) ? [""] : []),
];

if (wranglerGitIgnoreFilesToAdd.length > 1) {
if (!hasDotWrangler && wranglerGitIgnoreFilesToAdd.length > 1) {
linesToAppend.push("# wrangler files");
}

Expand Down
13 changes: 4 additions & 9 deletions packages/create-cloudflare/templates/common/js/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ web_modules/

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
Expand Down Expand Up @@ -168,5 +160,8 @@ dist

# wrangler project

.dev.vars
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.wrangler/
8 changes: 0 additions & 8 deletions packages/create-cloudflare/templates/common/ts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ web_modules/

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ web_modules/

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
Expand Down Expand Up @@ -168,5 +160,8 @@ dist

# wrangler project

.dev.vars
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.wrangler/
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ jspm_packages/

\*.tgz

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# public

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

# wrangler project

.dev.vars
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.wrangler/
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ web_modules/

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
Expand Down Expand Up @@ -168,5 +160,8 @@ dist

# wrangler project

.dev.vars
.dev.vars*
!.dev.vars.example
.env*
!.env.example
.wrangler/
Loading
Loading