[ci] format
This commit is contained in:
parent
e33fc9bc46
commit
7d1f86d4b7
2 changed files with 13 additions and 10 deletions
|
@ -11,12 +11,12 @@ import path from 'path';
|
||||||
import postcssrc from 'postcss-load-config';
|
import postcssrc from 'postcss-load-config';
|
||||||
import { BUNDLED_THEMES } from 'shiki';
|
import { BUNDLED_THEMES } from 'shiki';
|
||||||
import { fileURLToPath, pathToFileURL } from 'url';
|
import { fileURLToPath, pathToFileURL } from 'url';
|
||||||
|
import * as vite from 'vite';
|
||||||
import { mergeConfig as mergeViteConfig } from 'vite';
|
import { mergeConfig as mergeViteConfig } from 'vite';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { LogOptions } from './logger/core.js';
|
import { LogOptions } from './logger/core.js';
|
||||||
import { appendForwardSlash, prependForwardSlash, trimSlashes } from './path.js';
|
import { appendForwardSlash, prependForwardSlash, trimSlashes } from './path.js';
|
||||||
import { arraify, isObject } from './util.js';
|
import { arraify, isObject } from './util.js';
|
||||||
import * as vite from 'vite';
|
|
||||||
|
|
||||||
load.use([loadTypeScript]);
|
load.use([loadTypeScript]);
|
||||||
|
|
||||||
|
@ -410,8 +410,6 @@ export async function resolveConfigURL(
|
||||||
const flags = resolveFlags(configOptions.flags || {});
|
const flags = resolveFlags(configOptions.flags || {});
|
||||||
let userConfigPath: string | undefined;
|
let userConfigPath: string | undefined;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (flags?.config) {
|
if (flags?.config) {
|
||||||
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
|
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
|
||||||
userConfigPath = fileURLToPath(new URL(userConfigPath, `file://${root}/`));
|
userConfigPath = fileURLToPath(new URL(userConfigPath, `file://${root}/`));
|
||||||
|
@ -478,7 +476,12 @@ interface TryLoadConfigResult {
|
||||||
filePath?: string;
|
filePath?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function tryLoadConfig(configOptions: LoadConfigOptions, flags: CLIFlags, userConfigPath: string | undefined, root: string): Promise<TryLoadConfigResult | undefined> {
|
async function tryLoadConfig(
|
||||||
|
configOptions: LoadConfigOptions,
|
||||||
|
flags: CLIFlags,
|
||||||
|
userConfigPath: string | undefined,
|
||||||
|
root: string
|
||||||
|
): Promise<TryLoadConfigResult | undefined> {
|
||||||
try {
|
try {
|
||||||
// Automatically load config file using Proload
|
// Automatically load config file using Proload
|
||||||
// If `userConfigPath` is `undefined`, Proload will search for `astro.config.[cm]?[jt]s`
|
// If `userConfigPath` is `undefined`, Proload will search for `astro.config.[cm]?[jt]s`
|
||||||
|
@ -489,30 +492,30 @@ async function tryLoadConfig(configOptions: LoadConfigOptions, flags: CLIFlags,
|
||||||
});
|
});
|
||||||
|
|
||||||
return config as TryLoadConfigResult;
|
return config as TryLoadConfigResult;
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
if (e instanceof ProloadError && flags.config) {
|
if (e instanceof ProloadError && flags.config) {
|
||||||
throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
|
throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const configURL = await resolveConfigURL(configOptions);
|
const configURL = await resolveConfigURL(configOptions);
|
||||||
if(!configURL) {
|
if (!configURL) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to use Vite DevServer
|
// Fallback to use Vite DevServer
|
||||||
const viteServer = await vite.createServer({
|
const viteServer = await vite.createServer({
|
||||||
server: { middlewareMode: true, hmr: false },
|
server: { middlewareMode: true, hmr: false },
|
||||||
appType: 'custom'
|
appType: 'custom',
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
const mod = await viteServer.ssrLoadModule(fileURLToPath(configURL));
|
const mod = await viteServer.ssrLoadModule(fileURLToPath(configURL));
|
||||||
|
|
||||||
if(mod?.default) {
|
if (mod?.default) {
|
||||||
return {
|
return {
|
||||||
value: mod.default,
|
value: mod.default,
|
||||||
filePath: fileURLToPath(configURL),
|
filePath: fileURLToPath(configURL),
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
} finally {
|
} finally {
|
||||||
await viteServer.close();
|
await viteServer.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe('MDX Page', () => {
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: new URL('./fixtures/mdx-page/', import.meta.url)
|
root: new URL('./fixtures/mdx-page/', import.meta.url),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue