Skip to content

Commit

Permalink
Changed port in playwright config file (#7428)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oreoezi authored Dec 6, 2024
1 parent 073293f commit f463dd2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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

0 comments on commit f463dd2

Please sign in to comment.