-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and improve Astro config loading flow (#7879)
- Loading branch information
Showing
57 changed files
with
737 additions
and
822 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Refactor and improve Astro config loading flow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
import type yargs from 'yargs-parser'; | ||
import _build from '../../core/build/index.js'; | ||
import type { LogOptions } from '../../core/logger/core.js'; | ||
import { loadSettings } from '../load-settings.js'; | ||
import { printHelp } from '../../core/messages.js'; | ||
import { flagsToAstroInlineConfig } from '../flags.js'; | ||
|
||
interface BuildOptions { | ||
flags: yargs.Arguments; | ||
logging: LogOptions; | ||
} | ||
|
||
export async function build({ flags, logging }: BuildOptions) { | ||
const settings = await loadSettings({ cmd: 'build', flags, logging }); | ||
if (!settings) return; | ||
export async function build({ flags }: BuildOptions) { | ||
if (flags?.help || flags?.h) { | ||
printHelp({ | ||
commandName: 'astro build', | ||
usage: '[...flags]', | ||
tables: { | ||
Flags: [ | ||
['--drafts', `Include Markdown draft pages in the build.`], | ||
['--help (-h)', 'See all available flags.'], | ||
], | ||
}, | ||
description: `Builds your site for deployment.`, | ||
}); | ||
return; | ||
} | ||
|
||
await _build(settings, { | ||
flags, | ||
logging, | ||
const inlineConfig = flagsToAstroInlineConfig(flags); | ||
|
||
await _build(inlineConfig, { | ||
teardownCompiler: true, | ||
mode: flags.mode, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import fs from 'node:fs'; | ||
import { cyan } from 'kleur/colors'; | ||
import type yargs from 'yargs-parser'; | ||
import { resolveConfigPath, resolveFlags } from '../../core/config/index.js'; | ||
import devServer from '../../core/dev/index.js'; | ||
import { info, type LogOptions } from '../../core/logger/core.js'; | ||
import { handleConfigError, loadSettings } from '../load-settings.js'; | ||
import { printHelp } from '../../core/messages.js'; | ||
import { flagsToAstroInlineConfig } from '../flags.js'; | ||
|
||
interface DevOptions { | ||
flags: yargs.Arguments; | ||
logging: LogOptions; | ||
} | ||
|
||
export async function dev({ flags, logging }: DevOptions) { | ||
const settings = await loadSettings({ cmd: 'dev', flags, logging }); | ||
if (!settings) return; | ||
export async function dev({ flags }: DevOptions) { | ||
if (flags.help || flags.h) { | ||
printHelp({ | ||
commandName: 'astro dev', | ||
usage: '[...flags]', | ||
tables: { | ||
Flags: [ | ||
['--port', `Specify which port to run on. Defaults to 3000.`], | ||
['--host', `Listen on all addresses, including LAN and public addresses.`], | ||
['--host <custom-address>', `Expose on a network IP address at <custom-address>`], | ||
['--open', 'Automatically open the app in the browser on server start'], | ||
['--help (-h)', 'See all available flags.'], | ||
], | ||
}, | ||
description: `Check ${cyan( | ||
'https://docs.astro.build/en/reference/cli-reference/#astro-dev' | ||
)} for more information.`, | ||
}); | ||
return; | ||
} | ||
|
||
const root = flags.root; | ||
const configFlag = resolveFlags(flags).config; | ||
const configFlagPath = configFlag ? await resolveConfigPath({ cwd: root, flags, fs }) : undefined; | ||
const inlineConfig = flagsToAstroInlineConfig(flags); | ||
|
||
return await devServer(settings, { | ||
configFlag, | ||
configFlagPath, | ||
flags, | ||
logging, | ||
handleConfigError(e) { | ||
handleConfigError(e, { cmd: 'dev', cwd: root, flags, logging }); | ||
info(logging, 'astro', 'Continuing with previous valid configuration\n'); | ||
}, | ||
}); | ||
return await devServer(inlineConfig); | ||
} |
Oops, something went wrong.