From f6485830b89d5df9277d9ae76576243737a0ed01 Mon Sep 17 00:00:00 2001 From: Pascal Martineau Date: Fri, 29 May 2026 08:54:30 -0400 Subject: [PATCH] fix: local site url from env + cwd --- src/commands/sync.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/commands/sync.ts b/src/commands/sync.ts index 200296a..54a0f99 100644 --- a/src/commands/sync.ts +++ b/src/commands/sync.ts @@ -1,5 +1,5 @@ import { existsSync, mkdirSync, readdirSync } from "node:fs"; -import { join } from "node:path"; +import { basename, join } from "node:path"; import { consola } from "consola"; import prompts from "prompts"; import type { WPopContext } from "../lib/context"; @@ -74,7 +74,7 @@ export async function sync(context: WPopContext, options: SyncOptions): Promise< let localSiteurl: string | undefined; if (components.has("database") && !options.skipSearchReplace) { - localSiteurl = await readLocalOption(context, "siteurl"); + localSiteurl = resolveLocalSiteurl(context) ?? (await readLocalOption(context, "siteurl")); } for (const component of CONTENT_SYNC_COMPONENTS) { @@ -382,6 +382,19 @@ async function runSearchReplace( await run(context, "wp", ["cache", "flush"], { cwd: context.cwd }); } +function resolveLocalSiteurl(context: WPopContext): string | undefined { + const protocol = process.env.WEBSIMPLE_STACK_PROTOCOL?.trim(); + const domain = process.env.WEBSIMPLE_STACK_DOMAIN?.trim(); + if (!protocol || !domain) { + return undefined; + } + const subdomain = basename(context.cwd); + if (!subdomain) { + return undefined; + } + return `${protocol}://${subdomain}.${domain}`; +} + async function readLocalOption(context: WPopContext, option: string): Promise { const result = await run(context, "wp", ["option", "get", option], { capture: true,