From b90450c42d7e5303c7453d14c95a7bbf034d104a Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Mon, 30 Jan 2023 14:27:16 -0600 Subject: [PATCH 1/4] fix(#5985): preserve `--root` CLI flag on restart --- .changeset/tasty-planes-knock.md | 5 +++++ packages/astro/src/core/dev/restart.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/tasty-planes-knock.md 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), From 6a52157121acbeed0d605c80dad4f76ddf732f0d Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Mon, 6 Feb 2023 15:50:42 -0600 Subject: [PATCH 2/4] fix: resolve --root relative to automatic root --- packages/astro/src/core/dev/restart.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index 79bb41556fe1..b20d7a551510 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -1,8 +1,10 @@ +import { fileURLToPath, pathToFileURL } from 'url'; import * as vite from 'vite'; import type { AstroSettings } from '../../@types/astro'; import { createSettings, openConfig } from '../config/index.js'; import { createSafeError } from '../errors/index.js'; import { info } from '../logger/core.js'; +import { prependForwardSlash, appendForwardSlash } from '../path.js'; import type { Container, CreateContainerParams } from './container'; import { createContainer, isStarted, startContainer } from './container.js'; @@ -76,8 +78,9 @@ 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; + // Resolve `flags.root` relative to `resolvedRoot` + const root = flags.root ? fileURLToPath(new URL('.' + prependForwardSlash(appendForwardSlash(flags.root)), pathToFileURL(resolvedRoot))) : resolvedRoot; if (beforeRestart) { beforeRestart(); From 7a06d9c4b7df769e6367f08d0b01c3d712f6503d Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 9 Feb 2023 12:52:22 -0600 Subject: [PATCH 3/4] chore: revert container changes --- packages/astro/src/core/dev/restart.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/astro/src/core/dev/restart.ts b/packages/astro/src/core/dev/restart.ts index b20d7a551510..9c71b7aa3bb5 100644 --- a/packages/astro/src/core/dev/restart.ts +++ b/packages/astro/src/core/dev/restart.ts @@ -1,10 +1,8 @@ -import { fileURLToPath, pathToFileURL } from 'url'; import * as vite from 'vite'; import type { AstroSettings } from '../../@types/astro'; import { createSettings, openConfig } from '../config/index.js'; import { createSafeError } from '../errors/index.js'; import { info } from '../logger/core.js'; -import { prependForwardSlash, appendForwardSlash } from '../path.js'; import type { Container, CreateContainerParams } from './container'; import { createContainer, isStarted, startContainer } from './container.js'; @@ -79,8 +77,6 @@ export async function restartContainer({ }: RestartContainerParams): Promise<{ container: Container; error: Error | null }> { const { logging, close, resolvedRoot, settings: existingSettings } = container; container.restartInFlight = true; - // Resolve `flags.root` relative to `resolvedRoot` - const root = flags.root ? fileURLToPath(new URL('.' + prependForwardSlash(appendForwardSlash(flags.root)), pathToFileURL(resolvedRoot))) : resolvedRoot; if (beforeRestart) { beforeRestart(); @@ -88,7 +84,7 @@ export async function restartContainer({ const needsStart = isStarted(container); try { const newConfig = await openConfig({ - cwd: root, + cwd: resolvedRoot, flags, cmd: 'dev', logging, @@ -97,7 +93,7 @@ export async function restartContainer({ }); info(logging, 'astro', logMsg + '\n'); let astroConfig = newConfig.astroConfig; - const settings = createSettings(astroConfig, root); + const settings = createSettings(astroConfig, resolvedRoot); await close(); return { container: await createRestartedContainer(container, settings, needsStart), From 0ad7666d7dd99961c4ce2b70065acfe034f7c786 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 9 Feb 2023 12:59:54 -0600 Subject: [PATCH 4/4] fix: pass flags.root to restart container --- packages/astro/src/core/dev/dev.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/astro/src/core/dev/dev.ts b/packages/astro/src/core/dev/dev.ts index 4fcac87fafd1..378a7157ef19 100644 --- a/packages/astro/src/core/dev/dev.ts +++ b/packages/astro/src/core/dev/dev.ts @@ -44,6 +44,7 @@ export default async function dev( beforeRestart: () => console.clear(), params: { settings, + root: options.flags?.root, logging: options.logging, isRestart: options.isRestart, },