Skip to content

Commit 84eb7e7

Browse files
fix(cli): forward missing flags in background dev/preview server spawning (#17770)
Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com>
1 parent 640df64 commit 84eb7e7

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎.changeset/few-toys-rhyme.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes `--mode`, `--site`, `--base`, `--out-dir`, `--verbose`, `--silent`, and `--open` flags being silently dropped when using `astro dev --background` or `astro preview --background`

‎packages/astro/src/cli/server.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ export function buildBackgroundArgs(command: ServerCommand, flags: Flags): strin
124124
if (flags.root) args.push('--root', String(flags.root));
125125
if (flags.allowedHosts) args.push('--allowed-hosts', String(flags.allowedHosts));
126126
if (flags.json) args.push('--json');
127+
if (flags.mode) args.push('--mode', String(flags.mode));
128+
if (flags.site) args.push('--site', String(flags.site));
129+
if (flags.base) args.push('--base', String(flags.base));
130+
if (flags.outDir) args.push('--out-dir', String(flags.outDir));
131+
if (flags.verbose) args.push('--verbose');
132+
if (flags.silent) args.push('--silent');
133+
if (flags.open != null) {
134+
if (typeof flags.open === 'string') {
135+
args.push('--open', flags.open);
136+
} else if (flags.open) {
137+
args.push('--open');
138+
}
139+
}
127140
return args;
128141
}
129142

‎packages/astro/test/units/dev/dev-output.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,47 @@ describe('shared server utilities', () => {
213213
);
214214
});
215215

216+
it('forwards --mode, --site, --base, --out-dir, --verbose, --silent, and --open', () => {
217+
assert.deepEqual(
218+
buildBackgroundArgs('dev', {
219+
_: [],
220+
mode: 'staging',
221+
site: 'https://example.com',
222+
base: '/app',
223+
outDir: 'build',
224+
verbose: true,
225+
silent: false,
226+
open: '/dashboard',
227+
}),
228+
[
229+
'dev',
230+
'--mode',
231+
'staging',
232+
'--site',
233+
'https://example.com',
234+
'--base',
235+
'/app',
236+
'--out-dir',
237+
'build',
238+
'--verbose',
239+
'--open',
240+
'/dashboard',
241+
],
242+
);
243+
});
244+
245+
it('forwards boolean --open without a value', () => {
246+
assert.deepEqual(buildBackgroundArgs('dev', { _: [], open: true }), ['dev', '--open']);
247+
});
248+
249+
it('does not forward --open when false', () => {
250+
assert.deepEqual(buildBackgroundArgs('dev', { _: [], open: false }), ['dev']);
251+
});
252+
253+
it('forwards --silent', () => {
254+
assert.deepEqual(buildBackgroundArgs('dev', { _: [], silent: true }), ['dev', '--silent']);
255+
});
256+
216257
it('uses separate dev and preview log files', () => {
217258
const root = new URL('file:///project/');
218259
assert.equal(getLogFileURL(root).href, 'file:///project/.astro/dev.log');

0 commit comments

Comments
 (0)