diff --git a/.changeset/tasty-planes-knock.md b/.changeset/tasty-planes-knock.md new file mode 100644 index 000000000000..3a7a3602e461 --- /dev/null +++ b/.changeset/tasty-planes-knock.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Preserve `--root` CLI flag when restarting dev server diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index 9c71b7aa3bb5..79bb41556fe1 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -76,6 +76,7 @@ export async function restartContainer({ beforeRestart, }: RestartContainerParams): Promise<{ container: Container; error: Error | null }> { const { logging, close, resolvedRoot, settings: existingSettings } = container; + const root = flags.root || resolvedRoot; container.restartInFlight = true; if (beforeRestart) { @@ -84,7 +85,7 @@ export async function restartContainer({ const needsStart = isStarted(container); try { const newConfig = await openConfig({ - cwd: resolvedRoot, + cwd: root, flags, cmd: 'dev', logging, @@ -93,7 +94,7 @@ export async function restartContainer({ }); info(logging, 'astro', logMsg + '\n'); let astroConfig = newConfig.astroConfig; - const settings = createSettings(astroConfig, resolvedRoot); + const settings = createSettings(astroConfig, root); await close(); return { container: await createRestartedContainer(container, settings, needsStart),