Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed port in playwright config file #7428

Merged
merged 3 commits into from
Dec 6, 2024
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
5 changes: 5 additions & 0 deletions .changeset/lovely-kiwis-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

Use correct port in playwright config file for generated SvelteKit apps
30 changes: 30 additions & 0 deletions packages/create-cloudflare/templates/svelte/c3.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { existsSync } from "node:fs";
import { platform } from "node:os";
import { logRaw, updateStatus } from "@cloudflare/cli";
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
Expand Down Expand Up @@ -28,6 +29,7 @@ const configure = async (ctx: C3Context) => {
});

updateSvelteConfig();
updatePlaywrightConfig(usesTypescript(ctx));
updateTypeDefinitions(ctx);
};

Expand All @@ -49,6 +51,34 @@ const updateSvelteConfig = () => {
});
};

const updatePlaywrightConfig = (shouldUseTypescript: boolean) => {
const filePath = `playwright.config.${shouldUseTypescript ? "ts" : "js"}`;
if (!existsSync(filePath)) {
return;
}

updateStatus(`Changing webServer port in ${blue(filePath)}`);

transformFile(filePath, {
visitObjectExpression: function (n) {
const portProp = n.node.properties.find((prop) => {
if (!("key" in prop) || !("name" in prop.key)) {
return false;
}

return prop.key.name === "port";
});

if (!portProp || !("value" in portProp) || !("value" in portProp.value)) {
return this.traverse(n);
}

portProp.value.value = 8788;
return false;
},
});
};

const updateTypeDefinitions = (ctx: C3Context) => {
if (!usesTypescript(ctx)) {
return;
Expand Down
Loading