Skip to content

Commit f7df1e3

Browse files
petebacondarwingabivlj
authored andcommitted
.gitignore stuff (#8440)
* vite-plugin: add .gitignore update to README * c3: tighten up .gitignore processing
1 parent e9a37b6 commit f7df1e3

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

.changeset/deep-owls-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
tighten up .gitignore processing

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("addWranglerToGitIgnore", () => {
8787
8888
# wrangler files
8989
.wrangler
90-
.dev.vars
90+
.dev.vars*
9191
"
9292
`);
9393
});
@@ -202,7 +202,7 @@ describe("addWranglerToGitIgnore", () => {
202202
203203
# wrangler files
204204
.wrangler
205-
.dev.vars
205+
.dev.vars*
206206
"
207207
`);
208208
});
@@ -239,7 +239,7 @@ describe("addWranglerToGitIgnore", () => {
239239
);
240240
expect(appendFileResults.content).toMatchInlineSnapshot(`
241241
"
242-
.dev.vars
242+
.dev.vars*
243243
"
244244
`);
245245
});

packages/create-cloudflare/src/helpers/__tests__/args.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,18 @@ describe("Cli", () => {
112112
]);
113113
});
114114

115-
const stringArgs = [
116-
"--framework",
117-
"--template",
118-
"--type",
119-
"--existing-script",
120-
];
115+
const stringArgs = ["framework", "template", "type", "existing-script"];
121116
test.each(stringArgs)("%s requires an argument", async (arg) => {
122-
await expect(parseArgs(["my-react-project", arg])).resolves.toEqual({
117+
const logSpy = vi.spyOn(console, "error").mockImplementation(() => {});
118+
await expect(
119+
parseArgs(["my-react-project", `--${arg}`]),
120+
).resolves.toEqual({
123121
type: "unknown",
124122
args: null,
125123
});
124+
expect(logSpy).toHaveBeenCalledWith(
125+
expect.stringContaining(`Not enough arguments following: ${arg}`),
126+
);
126127
});
127128
});
128129
});

packages/create-cloudflare/src/templates.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,21 @@ export const addWranglerToGitIgnore = (ctx: C3Context) => {
836836
}
837837

838838
const existingGitIgnoreContent = readFile(gitIgnorePath);
839+
const wranglerGitIgnoreFilesToAdd: string[] = [];
839840

840-
const wranglerGitIgnoreFiles = [".wrangler", ".dev.vars"] as const;
841-
const wranglerGitIgnoreFilesToAdd = wranglerGitIgnoreFiles.filter(
842-
(file) =>
843-
!existingGitIgnoreContent.match(
844-
new RegExp(`\n${file}${file === ".wrangler" ? "/?" : ""}\\s+(#'*)?`),
845-
),
841+
const hasDotWrangler = existingGitIgnoreContent.match(
842+
/^\/?\.wrangler(\/|\s|$)/m,
846843
);
844+
if (!hasDotWrangler) {
845+
wranglerGitIgnoreFilesToAdd.push(".wrangler");
846+
}
847+
848+
const hasDotDevDotVars = existingGitIgnoreContent.match(
849+
/^\/?\.dev\.vars(\.?\*)?(\s|$)/m,
850+
);
851+
if (!hasDotDevDotVars) {
852+
wranglerGitIgnoreFilesToAdd.push(".dev.vars*");
853+
}
847854

848855
if (wranglerGitIgnoreFilesToAdd.length === 0) {
849856
return;
@@ -857,7 +864,7 @@ export const addWranglerToGitIgnore = (ctx: C3Context) => {
857864
...(!existingGitIgnoreContent.match(/\n\s*$/) ? [""] : []),
858865
];
859866

860-
if (wranglerGitIgnoreFilesToAdd.length === wranglerGitIgnoreFiles.length) {
867+
if (wranglerGitIgnoreFilesToAdd.length > 1) {
861868
linesToAppend.push("# wrangler files");
862869
}
863870

packages/vite-plugin-cloudflare/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ The `directory` in the output configuration will automatically point to the clie
140140
> This output file is a snapshot of your configuration at the time of the build and is modified to reference your build artifacts.
141141
> It is the configuration that is used for preview and deployment.
142142
143+
#### Update the .gitignore file
144+
145+
Wrangler will use and/or generate temporary files that should not be stored in git. Add the following lines to the `.gitignore` file:
146+
147+
```gitignore
148+
.wrangler
149+
.dev.vars
150+
```
151+
143152
#### Run the development server
144153

145154
Run `npm run dev` to verify that your application is working as expected.

0 commit comments

Comments
 (0)