mirror of
https://github.com/withastro/astro.git
synced 2025-02-24 22:46:02 -05:00
feat: support all config file names
This commit is contained in:
parent
275f28b22d
commit
21ef62cd35
1 changed files with 13 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { build as esbuild } from 'esbuild';
|
import { build as esbuild } from 'esbuild';
|
||||||
import { VIRTUAL_MODULE_ID } from './consts.js';
|
import { CONFIG_FILE_NAMES, VIRTUAL_MODULE_ID } from './consts.js';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import {
|
import {
|
||||||
getConfigVirtualModContents,
|
getConfigVirtualModContents,
|
||||||
|
@ -9,6 +9,7 @@ import {
|
||||||
import type { DBTables } from './types.js';
|
import type { DBTables } from './types.js';
|
||||||
import { writeFile, unlink } from 'node:fs/promises';
|
import { writeFile, unlink } from 'node:fs/promises';
|
||||||
import { getDbDirUrl } from './utils.js';
|
import { getDbDirUrl } from './utils.js';
|
||||||
|
import { existsSync } from 'node:fs';
|
||||||
|
|
||||||
type ExecuteFileParams =
|
type ExecuteFileParams =
|
||||||
| {
|
| {
|
||||||
|
@ -45,12 +46,20 @@ export async function executeFile(params: ExecuteFileParams): Promise<void> {
|
||||||
export async function loadConfigFile(
|
export async function loadConfigFile(
|
||||||
root: URL
|
root: URL
|
||||||
): Promise<{ mod: { default?: unknown } | undefined; dependencies: string[] }> {
|
): Promise<{ mod: { default?: unknown } | undefined; dependencies: string[] }> {
|
||||||
// TODO: support any file extension
|
let configFileUrl: URL | undefined;
|
||||||
const fileUrl = new URL('config.ts', getDbDirUrl(root));
|
for (const fileName of CONFIG_FILE_NAMES) {
|
||||||
|
const fileUrl = new URL(fileName, getDbDirUrl(root));
|
||||||
|
if (existsSync(fileUrl)) {
|
||||||
|
configFileUrl = fileUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!configFileUrl) {
|
||||||
|
return { mod: undefined, dependencies: [] };
|
||||||
|
}
|
||||||
const { code, dependencies } = await bundleFile({
|
const { code, dependencies } = await bundleFile({
|
||||||
virtualModContents: getConfigVirtualModContents(),
|
virtualModContents: getConfigVirtualModContents(),
|
||||||
root,
|
root,
|
||||||
fileUrl,
|
fileUrl: configFileUrl,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
mod: await importBundledFile({ code, root }),
|
mod: await importBundledFile({ code, root }),
|
||||||
|
|
Loading…
Add table
Reference in a new issue