-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove proload for config loading #5778
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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': major | ||
--- | ||
|
||
Remove proload to load the Astro config. It will now use NodeJS and Vite to load the config only. |
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 |
---|---|---|
|
@@ -115,7 +115,7 @@ export function resolveRoot(cwd?: string | URL): string { | |
} | ||
|
||
/** Merge CLI flags & user config object (CLI flags take priority) */ | ||
function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags, cmd: string) { | ||
function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags) { | ||
astroConfig.server = astroConfig.server || {}; | ||
astroConfig.markdown = astroConfig.markdown || {}; | ||
astroConfig.experimental = astroConfig.experimental || {}; | ||
|
@@ -136,6 +136,23 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags, cmd: strin | |
return astroConfig; | ||
} | ||
|
||
async function search(fsMod: typeof fs, root: string) { | ||
const paths = [ | ||
'astro.config.mjs', | ||
'astro.config.js', | ||
'astro.config.ts', | ||
'astro.config.mts', | ||
'astro.config.cjs', | ||
'astro.config.cts', | ||
].map((p) => path.join(root, p)); | ||
|
||
for (const file of paths) { | ||
if (fsMod.existsSync(file)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous function uses |
||
return file; | ||
} | ||
} | ||
} | ||
|
||
interface LoadConfigOptions { | ||
cwd?: string; | ||
flags?: Flags; | ||
|
@@ -147,41 +164,36 @@ interface LoadConfigOptions { | |
fsMod?: typeof fs; | ||
} | ||
|
||
interface ResolveConfigPathOptions { | ||
cwd?: string; | ||
flags?: Flags; | ||
fs: typeof fs; | ||
} | ||
|
||
/** | ||
* Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file | ||
* Note: currently the same as loadConfig but only returns the `filePath` | ||
* instead of the resolved config | ||
*/ | ||
export async function resolveConfigPath( | ||
configOptions: Pick<LoadConfigOptions, 'cwd' | 'flags'> & { fs: typeof fs } | ||
configOptions: ResolveConfigPathOptions | ||
): Promise<string | undefined> { | ||
const root = resolveRoot(configOptions.cwd); | ||
const flags = resolveFlags(configOptions.flags || {}); | ||
let userConfigPath: string | undefined; | ||
|
||
let userConfigPath: string | undefined; | ||
if (flags?.config) { | ||
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`; | ||
userConfigPath = fileURLToPath(new URL(userConfigPath, `file://${root}/`)); | ||
} | ||
|
||
// Resolve config file path using Proload | ||
// If `userConfigPath` is `undefined`, Proload will search for `astro.config.[cm]?[jt]s` | ||
try { | ||
const config = await loadConfigWithVite({ | ||
configPath: userConfigPath, | ||
root, | ||
fs: configOptions.fs, | ||
}); | ||
return config.filePath; | ||
} catch (e) { | ||
if (flags.config) { | ||
if (!configOptions.fs.existsSync(userConfigPath)) { | ||
throw new AstroError({ | ||
...AstroErrorData.ConfigNotFound, | ||
message: AstroErrorData.ConfigNotFound.message(flags.config), | ||
}); | ||
} | ||
throw e; | ||
} else { | ||
userConfigPath = await search(configOptions.fs, root); | ||
} | ||
|
||
return userConfigPath; | ||
} | ||
|
||
interface OpenConfigResult { | ||
|
@@ -261,30 +273,14 @@ async function tryLoadConfig( | |
} | ||
} | ||
|
||
/** | ||
* Attempt to load an `astro.config.mjs` file | ||
* @deprecated | ||
*/ | ||
export async function loadConfig(configOptions: LoadConfigOptions): Promise<AstroConfig> { | ||
const root = resolveRoot(configOptions.cwd); | ||
const flags = resolveFlags(configOptions.flags || {}); | ||
let userConfig: AstroUserConfig = {}; | ||
|
||
const config = await tryLoadConfig(configOptions, root); | ||
if (config) { | ||
userConfig = config.value; | ||
} | ||
return resolveConfig(userConfig, root, flags, configOptions.cmd); | ||
} | ||
|
||
/** Attempt to resolve an Astro configuration object. Normalize, validate, and return. */ | ||
export async function resolveConfig( | ||
userConfig: AstroUserConfig, | ||
root: string, | ||
flags: CLIFlags = {}, | ||
cmd: string | ||
): Promise<AstroConfig> { | ||
const mergedConfig = mergeCLIFlags(userConfig, flags, cmd); | ||
const mergedConfig = mergeCLIFlags(userConfig, flags); | ||
const validatedConfig = await validateConfig(mergedConfig, root, cmd); | ||
|
||
return validatedConfig; | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removal undoes #5700 (review) since we're already using Vite 4. Thought I'll make this change since this PR is config related.