1+ import { existsSync } from "node:fs" ;
12import { platform } from "node:os" ;
23import { logRaw , updateStatus } from "@cloudflare/cli" ;
34import { blue , brandColor , dim } from "@cloudflare/cli/colors" ;
@@ -28,6 +29,7 @@ const configure = async (ctx: C3Context) => {
2829 } ) ;
2930
3031 updateSvelteConfig ( ) ;
32+ updatePlaywrightConfig ( usesTypescript ( ctx ) ) ;
3133 updateTypeDefinitions ( ctx ) ;
3234} ;
3335
@@ -49,6 +51,34 @@ const updateSvelteConfig = () => {
4951 } ) ;
5052} ;
5153
54+ const updatePlaywrightConfig = ( shouldUseTypescript : boolean ) => {
55+ const filePath = `playwright.config.${ shouldUseTypescript ? "ts" : "js" } ` ;
56+ if ( ! existsSync ( filePath ) ) {
57+ return ;
58+ }
59+
60+ updateStatus ( `Changing webServer port in ${ blue ( filePath ) } ` ) ;
61+
62+ transformFile ( filePath , {
63+ visitObjectExpression : function ( n ) {
64+ const portProp = n . node . properties . find ( ( prop ) => {
65+ if ( ! ( "key" in prop ) || ! ( "name" in prop . key ) ) {
66+ return false ;
67+ }
68+
69+ return prop . key . name === "port" ;
70+ } ) ;
71+
72+ if ( ! portProp || ! ( "value" in portProp ) || ! ( "value" in portProp . value ) ) {
73+ return this . traverse ( n ) ;
74+ }
75+
76+ portProp . value . value = 8788 ;
77+ return false ;
78+ } ,
79+ } ) ;
80+ } ;
81+
5282const updateTypeDefinitions = ( ctx : C3Context ) => {
5383 if ( ! usesTypescript ( ctx ) ) {
5484 return ;
0 commit comments