Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Aug 2, 2022
1 parent e33fc9b commit 7d1f86d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions packages/astro/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import path from 'path';
import postcssrc from 'postcss-load-config';
import { BUNDLED_THEMES } from 'shiki';
import { fileURLToPath, pathToFileURL } from 'url';
import * as vite from 'vite';
import { mergeConfig as mergeViteConfig } from 'vite';
import { z } from 'zod';
import { LogOptions } from './logger/core.js';
import { appendForwardSlash, prependForwardSlash, trimSlashes } from './path.js';
import { arraify, isObject } from './util.js';
import * as vite from 'vite';

load.use([loadTypeScript]);

Expand Down Expand Up @@ -410,8 +410,6 @@ export async function resolveConfigURL(
const flags = resolveFlags(configOptions.flags || {});
let userConfigPath: string | undefined;



if (flags?.config) {
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
userConfigPath = fileURLToPath(new URL(userConfigPath, `file:https://${root}/`));
Expand Down Expand Up @@ -478,7 +476,12 @@ interface TryLoadConfigResult {
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 {
// Automatically load config file using Proload
// If `userConfigPath` is `undefined`, Proload will search for `astro.config.[cm]?[jt]s`
Expand All @@ -489,30 +492,30 @@ async function tryLoadConfig(configOptions: LoadConfigOptions, flags: CLIFlags,
});

return config as TryLoadConfigResult;
} catch(e) {
} catch (e) {
if (e instanceof ProloadError && flags.config) {
throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
}

const configURL = await resolveConfigURL(configOptions);
if(!configURL) {
if (!configURL) {
throw e;
}

// Fallback to use Vite DevServer
const viteServer = await vite.createServer({
server: { middlewareMode: true, hmr: false },
appType: 'custom'
appType: 'custom',
});
try {
const mod = await viteServer.ssrLoadModule(fileURLToPath(configURL));

if(mod?.default) {
if (mod?.default) {
return {
value: mod.default,
filePath: fileURLToPath(configURL),
};
};
}
} finally {
await viteServer.close();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/mdx/test/mdx-page.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('MDX Page', () => {

before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/mdx-page/', import.meta.url)
root: new URL('./fixtures/mdx-page/', import.meta.url),
});
});

Expand Down

0 comments on commit 7d1f86d

Please sign in to comment.