Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/spotty-candles-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

fix: remove wrangler.json from hono starter template as create-hono uses wrangler.toml and so both were being generated.
35 changes: 24 additions & 11 deletions packages/create-cloudflare/e2e-tests/frameworks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import { retry } from "helpers/retry";
import { sleep } from "helpers/sleep";
import { fetch } from "undici";
import { beforeAll, describe, expect } from "vitest";
import { resolveWranglerConfigPath } from "wrangler/src/config/config-helpers";
import { deleteProject, deleteWorker } from "../scripts/common";
import { getFrameworkMap } from "../src/templates";
import { getFrameworkToTest } from "./frameworkToTest";
import {
countAllWranglerConfigPaths,
findAllWranglerConfigPaths,
isQuarantineMode,
keys,
kill,
Expand Down Expand Up @@ -673,7 +676,15 @@ describe.concurrent(
const wranglerPath = join(project.path, "node_modules/wrangler");
expect(wranglerPath).toExist();

await addTestVarsToWranglerToml(project.path);
console.log(
JSON.stringify(findAllWranglerConfigPaths(project.path)),
);
expect(
countAllWranglerConfigPaths(project.path) === 1,
"Only one of wrangler.toml, wrangler.json, and wrangler.jsonc should exist.",
).toBe(true);

await addTestVarsToWranglerConfig(project.path);

// Make a request to the deployed project and verify it was successful
await verifyDeployment(
Expand Down Expand Up @@ -765,28 +776,30 @@ const runCli = async (
};

/**
* Either update or create a wrangler.toml to include a `TEST` var.
* Either update or create a wrangler config file to include a `TEST` var.
*
* This is rather than having a wrangler.toml in the e2e test's fixture folder,
* This is rather than having a wrangler config file in the e2e test's fixture folder,
* which overwrites any that comes from the framework's template.
*/
const addTestVarsToWranglerToml = async (projectPath: string) => {
const wranglerTomlPath = join(projectPath, "wrangler.toml");
const wranglerJsonPath = join(projectPath, "wrangler.json");
if (existsSync(wranglerTomlPath)) {
const addTestVarsToWranglerConfig = async (projectPath: string) => {
const { wranglerTomlPath, wranglerJsonPath, wranglerJsoncPath } =
findAllWranglerConfigPaths(projectPath);

const jsonPath = wranglerJsonPath ?? wranglerJsoncPath;

if (wranglerTomlPath) {
const wranglerToml = readToml(wranglerTomlPath);
// Add a TEST var to the wrangler.toml
wranglerToml.vars ??= {};
(wranglerToml.vars as JsonMap).TEST = "C3_TEST";

writeToml(wranglerTomlPath, wranglerToml);
} else if (existsSync(wranglerJsonPath)) {
const wranglerJson = readJSON(wranglerJsonPath);
// Add a TEST var to the wrangler.toml
} else if (jsonPath) {
const wranglerJson = readJSON(jsonPath);
wranglerJson.vars ??= {};
wranglerJson.vars.TEST = "C3_TEST";

writeJSON(wranglerJsonPath, wranglerJson);
writeJSON(jsonPath, wranglerJson);
}
};

Expand Down
26 changes: 26 additions & 0 deletions packages/create-cloudflare/e2e-tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import assert from "assert";
import {
createWriteStream,
existsSync,
mkdirSync,
mkdtempSync,
realpathSync,
rmSync,
} from "fs";
import crypto from "node:crypto";
import { join } from "node:path";
import { tmpdir } from "os";
import path from "path";
import { setTimeout } from "timers/promises";
Expand Down Expand Up @@ -508,3 +510,27 @@ export function kill(proc: ChildProcess) {
(resolve) => proc.pid && treeKill(proc.pid, "SIGINT", () => resolve()),
);
}

export function countAllWranglerConfigPaths(referencePath: string) {
return Object.values(findAllWranglerConfigPaths(referencePath)).filter(
(configPath) => configPath !== undefined,
).length;
}

export function findAllWranglerConfigPaths(projectPath: string) {
const wranglerTomlPath = join(projectPath, "wrangler.toml");
const wranglerJsonPath = join(projectPath, "wrangler.json");
const wranglerJsoncPath = join(projectPath, "wrangler.jsonc");

return {
wranglerTomlPath: existsSync(wranglerTomlPath)
? wranglerTomlPath
: undefined,
wranglerJsonPath: existsSync(wranglerJsonPath)
? wranglerJsonPath
: undefined,
wranglerJsoncPath: existsSync(wranglerJsoncPath)
? wranglerJsoncPath
: undefined,
};
}
1 change: 1 addition & 0 deletions packages/create-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"dotenv": "^16.0.0",
"esbuild": "0.17.19",
"execa": "^7.1.1",
"find-up": "^6.3.0",
"glob": "^10.3.3",
"haikunator": "^2.1.2",
"indent-string": "^5.0.0",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "<TBD>"
main = "src/index.ts"
compatibility_date = "<TBD>"

[observability]
enabled = true
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading