[ci] format

This commit is contained in:
matthewp 2022-09-16 15:31:14 +00:00 committed by fredkbot
parent f3a81d82f6
commit 64aa903f04
19 changed files with 64 additions and 65 deletions

View file

@ -882,7 +882,7 @@ export interface AstroSettings {
renderers: AstroRenderer[]; renderers: AstroRenderer[];
scripts: { scripts: {
stage: InjectedScriptStage; stage: InjectedScriptStage;
content: string content: string;
}[]; }[];
tsConfig: TsConfigJson | undefined; tsConfig: TsConfigJson | undefined;
tsConfigPath: string | undefined; tsConfigPath: string | undefined;

View file

@ -7,7 +7,14 @@ import yargs from 'yargs-parser';
import { z } from 'zod'; import { z } from 'zod';
import add from '../core/add/index.js'; import add from '../core/add/index.js';
import build from '../core/build/index.js'; import build from '../core/build/index.js';
import { openConfig, resolveConfigPath, resolveFlags, resolveRoot, createSettings, loadTSConfig } from '../core/config/index.js'; import {
createSettings,
loadTSConfig,
openConfig,
resolveConfigPath,
resolveFlags,
resolveRoot,
} from '../core/config/index.js';
import devServer from '../core/dev/index.js'; import devServer from '../core/dev/index.js';
import { collectErrorMetadata } from '../core/errors.js'; import { collectErrorMetadata } from '../core/errors.js';
import { debug, error, info, LogOptions } from '../core/logger/core.js'; import { debug, error, info, LogOptions } from '../core/logger/core.js';
@ -210,7 +217,7 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
settings = createSettings({ settings = createSettings({
config: astroConfig, config: astroConfig,
tsConfig: tsconfig?.config, tsConfig: tsconfig?.config,
tsConfigPath: tsconfig?.path tsConfigPath: tsconfig?.path,
}); });
await stop(); await stop();
await startDevServer({ isRestart: true }); await startDevServer({ isRestart: true });

View file

@ -62,7 +62,11 @@ class AstroBuilder {
debug('build', 'Initial setup...'); debug('build', 'Initial setup...');
const { logging } = this; const { logging } = this;
this.timer.init = performance.now(); this.timer.init = performance.now();
this.settings = await runHookConfigSetup({ settings: this.settings, command: 'build', logging }); this.settings = await runHookConfigSetup({
settings: this.settings,
command: 'build',
logging,
});
this.manifest = createRouteManifest({ settings: this.settings }, this.logging); this.manifest = createRouteManifest({ settings: this.settings }, this.logging);
const viteConfig = await createVite( const viteConfig = await createVite(

View file

@ -151,8 +151,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
}), }),
...(viteConfig.plugins || []), ...(viteConfig.plugins || []),
// SSR needs to be last // SSR needs to be last
settings.config.output === 'server' && settings.config.output === 'server' && vitePluginSSR(internals, settings.adapter!),
vitePluginSSR(internals, settings.adapter!),
vitePluginAnalyzer(internals), vitePluginAnalyzer(internals),
], ],
publicDir: ssr ? false : viteConfig.publicDir, publicDir: ssr ? false : viteConfig.publicDir,

View file

@ -1,5 +1,4 @@
import type { GetModuleInfo, OutputChunk } from 'rollup'; import type { GetModuleInfo, OutputChunk } from 'rollup';
import type { AstroConfig } from '../../@types/astro';
import type { BuildInternals } from './internal'; import type { BuildInternals } from './internal';
import type { PageBuildData, StaticBuildOptions } from './types'; import type { PageBuildData, StaticBuildOptions } from './types';

View file

@ -103,7 +103,11 @@ export async function injectManifest(buildOpts: StaticBuildOptions, internals: B
const staticFiles = internals.staticFiles; const staticFiles = internals.staticFiles;
const manifest = buildManifest(buildOpts, internals, Array.from(staticFiles)); const manifest = buildManifest(buildOpts, internals, Array.from(staticFiles));
await runHookBuildSsr({ config: buildOpts.settings.config, manifest, logging: buildOpts.logging }); await runHookBuildSsr({
config: buildOpts.settings.config,
manifest,
logging: buildOpts.logging,
});
const chunk = internals.ssrEntryChunk; const chunk = internals.ssrEntryChunk;
const code = chunk.code; const code = chunk.code;

View file

@ -1,9 +1,9 @@
import type { Arguments as Flags } from 'yargs-parser'; import type { Arguments as Flags } from 'yargs-parser';
import type { AstroConfig, AstroUserConfig, CLIFlags } from '../../@types/astro'; import type { AstroConfig, AstroUserConfig, CLIFlags } from '../../@types/astro';
import fs from 'fs';
import load, { ProloadError, resolve } from '@proload/core'; import load, { ProloadError, resolve } from '@proload/core';
import loadTypeScript from '@proload/plugin-tsm'; import loadTypeScript from '@proload/plugin-tsm';
import fs from 'fs';
import * as colors from 'kleur/colors'; import * as colors from 'kleur/colors';
import path from 'path'; import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url'; import { fileURLToPath, pathToFileURL } from 'url';
@ -27,7 +27,6 @@ export const LEGACY_ASTRO_CONFIG_KEYS = new Set([
'devOptions', 'devOptions',
]); ]);
/** Turn raw config values into normalized values */ /** Turn raw config values into normalized values */
export async function validateConfig( export async function validateConfig(
userConfig: any, userConfig: any,

View file

@ -1,8 +1,3 @@
export type {
AstroConfigSchema
} from './schema';
export { export {
openConfig, openConfig,
resolveConfigPath, resolveConfigPath,
@ -10,11 +5,6 @@ export {
resolveRoot, resolveRoot,
validateConfig, validateConfig,
} from './config.js'; } from './config.js';
export type { AstroConfigSchema } from './schema';
export { export { createSettings } from './settings.js';
createSettings export { loadTSConfig } from './tsconfig.js';
} from './settings.js';
export {
loadTSConfig
} from './tsconfig.js';

View file

@ -1,8 +1,5 @@
import type {
AstroConfig,
AstroSettings,
} from '../../@types/astro';
import type { TsConfigJson } from 'tsconfig-resolver'; import type { TsConfigJson } from 'tsconfig-resolver';
import type { AstroConfig, AstroSettings } from '../../@types/astro';
import jsxRenderer from '../../jsx/renderer.js'; import jsxRenderer from '../../jsx/renderer.js';
@ -12,11 +9,7 @@ export interface CreateSettings {
tsConfigPath?: string; tsConfigPath?: string;
} }
export function createSettings({ export function createSettings({ config, tsConfig, tsConfigPath }: CreateSettings): AstroSettings {
config,
tsConfig,
tsConfigPath,
}: CreateSettings): AstroSettings {
return { return {
config, config,
tsConfig, tsConfig,

View file

@ -28,7 +28,10 @@ export interface DevServer {
} }
/** `astro dev` */ /** `astro dev` */
export default async function dev(settings: AstroSettings, options: DevOptions): Promise<DevServer> { export default async function dev(
settings: AstroSettings,
options: DevOptions
): Promise<DevServer> {
const devStart = performance.now(); const devStart = performance.now();
applyPolyfill(); applyPolyfill();
await options.telemetry.record([]); await options.telemetry.record([]);
@ -58,7 +61,9 @@ export default async function dev(settings: AstroSettings, options: DevOptions):
await viteServer.listen(port); await viteServer.listen(port);
const devServerAddressInfo = viteServer.httpServer!.address() as AddressInfo; const devServerAddressInfo = viteServer.httpServer!.address() as AddressInfo;
const site = settings.config.site ? new URL(settings.config.base, settings.config.site) : undefined; const site = settings.config.site
? new URL(settings.config.base, settings.config.site)
: undefined;
info( info(
options.logging, options.logging,
null, null,
@ -80,7 +85,11 @@ export default async function dev(settings: AstroSettings, options: DevOptions):
warn(options.logging, null, msg.fsStrictWarning()); warn(options.logging, null, msg.fsStrictWarning());
} }
await runHookServerStart({ config: settings.config, address: devServerAddressInfo, logging: options.logging }); await runHookServerStart({
config: settings.config,
address: devServerAddressInfo,
logging: options.logging,
});
return { return {
address: devServerAddressInfo, address: devServerAddressInfo,

View file

@ -1,8 +1,8 @@
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import type { ViteDevServer } from 'vite'; import type { ViteDevServer } from 'vite';
import type { import type {
AstroSettings,
AstroRenderer, AstroRenderer,
AstroSettings,
ComponentInstance, ComponentInstance,
RouteData, RouteData,
RuntimeMode, RuntimeMode,
@ -191,7 +191,9 @@ export async function render(
request, request,
route, route,
routeCache, routeCache,
site: settings.config.site ? new URL(settings.config.base, settings.config.site).toString() : undefined, site: settings.config.site
? new URL(settings.config.base, settings.config.site).toString()
: undefined,
ssr: settings.config.output === 'server', ssr: settings.config.output === 'server',
streaming: true, streaming: true,
}); });

View file

@ -1,8 +1,6 @@
import type { ModuleInfo } from 'rollup'; import type { ModuleInfo } from 'rollup';
import slash from 'slash';
import { fileURLToPath } from 'url';
import vite from 'vite'; import vite from 'vite';
import type { AstroConfig, SSRElement } from '../../../@types/astro'; import type { SSRElement } from '../../../@types/astro';
import type { PluginMetadata as AstroPluginMetadata } from '../../../vite-plugin-astro/types'; import type { PluginMetadata as AstroPluginMetadata } from '../../../vite-plugin-astro/types';
import { viteID } from '../../util.js'; import { viteID } from '../../util.js';
import { createModuleScriptElementWithSrc } from '../ssr-element.js'; import { createModuleScriptElementWithSrc } from '../ssr-element.js';
@ -27,10 +25,7 @@ export async function getScriptsForURL(
return elements; return elements;
} }
function addHoistedScripts( function addHoistedScripts(set: Set<SSRElement>, info: ModuleInfo | null) {
set: Set<SSRElement>,
info: ModuleInfo | null,
) {
if (!info?.meta?.astro) { if (!info?.meta?.astro) {
return; return;
} }

View file

@ -196,11 +196,7 @@ export function createRouteManifest(
): ManifestData { ): ManifestData {
const components: string[] = []; const components: string[] = [];
const routes: RouteData[] = []; const routes: RouteData[] = [];
const validPageExtensions: Set<string> = new Set([ const validPageExtensions: Set<string> = new Set(['.astro', '.md', ...settings.pageExtensions]);
'.astro',
'.md',
...settings.pageExtensions,
]);
const validEndpointExtensions: Set<string> = new Set(['.js', '.ts']); const validEndpointExtensions: Set<string> = new Set(['.js', '.ts']);
function walk(dir: string, parentSegments: RoutePart[][], parentParams: string[]) { function walk(dir: string, parentSegments: RoutePart[][], parentParams: string[]) {

View file

@ -3,8 +3,8 @@ import type { AddressInfo } from 'net';
import type { ViteDevServer } from 'vite'; import type { ViteDevServer } from 'vite';
import { import {
AstroConfig, AstroConfig,
AstroSettings,
AstroRenderer, AstroRenderer,
AstroSettings,
BuildConfig, BuildConfig,
HookParameters, HookParameters,
RouteData, RouteData,

View file

@ -50,9 +50,7 @@ function getReferencedPrivateKeys(source: string, privateEnv: Record<string, any
return references; return references;
} }
export default function envVitePlugin({ export default function envVitePlugin({ settings }: EnvPluginOptions): vite.PluginOption {
settings,
}: EnvPluginOptions): vite.PluginOption {
let privateEnv: Record<string, any> | null; let privateEnv: Record<string, any> | null;
let config: vite.ResolvedConfig; let config: vite.ResolvedConfig;
let replacements: Record<string, string>; let replacements: Record<string, string>;

View file

@ -1,7 +1,7 @@
import type { TransformResult } from 'rollup'; import type { TransformResult } from 'rollup';
import type { TsConfigJson } from 'tsconfig-resolver'; import type { TsConfigJson } from 'tsconfig-resolver';
import type { Plugin, ResolvedConfig } from 'vite'; import type { Plugin, ResolvedConfig } from 'vite';
import type { AstroSettings, AstroRenderer } from '../@types/astro'; import type { AstroRenderer, AstroSettings } from '../@types/astro';
import type { LogOptions } from '../core/logger/core.js'; import type { LogOptions } from '../core/logger/core.js';
import type { PluginMetadata } from '../vite-plugin-astro/types'; import type { PluginMetadata } from '../vite-plugin-astro/types';

View file

@ -6,7 +6,11 @@ import ancestor from 'common-ancestor-path';
import MagicString from 'magic-string'; import MagicString from 'magic-string';
import { isPage } from '../core/util.js'; import { isPage } from '../core/util.js';
export default function astroScriptsPostPlugin({ settings }: { settings: AstroSettings }): VitePlugin { export default function astroScriptsPostPlugin({
settings,
}: {
settings: AstroSettings;
}): VitePlugin {
function normalizeFilename(filename: string) { function normalizeFilename(filename: string) {
if (filename.startsWith('/@fs')) { if (filename.startsWith('/@fs')) {
filename = filename.slice('/@fs'.length); filename = filename.slice('/@fs'.length);

View file

@ -99,7 +99,7 @@ export async function loadFixture(inlineConfig) {
let settings = createSettings({ let settings = createSettings({
config, config,
tsConfig: tsconfig?.config, tsConfig: tsconfig?.config,
tsConfigPath: tsconfig?.path tsConfigPath: tsconfig?.path,
}); });
if (config.integrations.find((integration) => integration.name === '@astrojs/mdx')) { if (config.integrations.find((integration) => integration.name === '@astrojs/mdx')) {
// Enable default JSX integration. It needs to come first, so unshift rather than push! // Enable default JSX integration. It needs to come first, so unshift rather than push!

View file

@ -11,7 +11,7 @@ describe('config.server', () => {
cwd: flags.root || cwd, cwd: flags.root || cwd,
flags, flags,
cmd: 'dev', cmd: 'dev',
logging logging,
}); });
} }
@ -20,7 +20,7 @@ describe('config.server', () => {
const projectRootURL = new URL('../../fixtures/astro-basic/', import.meta.url); const projectRootURL = new URL('../../fixtures/astro-basic/', import.meta.url);
const { astroConfig } = await openConfigWithFlags({ const { astroConfig } = await openConfigWithFlags({
root: fileURLToPath(projectRootURL), root: fileURLToPath(projectRootURL),
host: true host: true,
}); });
expect(astroConfig.server.host).to.equal(true); expect(astroConfig.server.host).to.equal(true);
@ -34,7 +34,7 @@ describe('config.server', () => {
const configFileURL = 'my-config.mjs'; const configFileURL = 'my-config.mjs';
const { astroConfig } = await openConfigWithFlags({ const { astroConfig } = await openConfigWithFlags({
root: fileURLToPath(projectRootURL), root: fileURLToPath(projectRootURL),
config: configFileURL config: configFileURL,
}); });
expect(astroConfig.server.port).to.equal(8080); expect(astroConfig.server.port).to.equal(8080);
}); });
@ -46,7 +46,7 @@ describe('config.server', () => {
const configFileURL = './my-config.mjs'; const configFileURL = './my-config.mjs';
const { astroConfig } = await openConfigWithFlags({ const { astroConfig } = await openConfigWithFlags({
root: fileURLToPath(projectRootURL), root: fileURLToPath(projectRootURL),
config: configFileURL config: configFileURL,
}); });
expect(astroConfig.server.port).to.equal(8080); expect(astroConfig.server.port).to.equal(8080);
}); });
@ -59,13 +59,13 @@ describe('config.server', () => {
try { try {
await openConfigWithFlags({ await openConfigWithFlags({
root: fileURLToPath(projectRootURL), root: fileURLToPath(projectRootURL),
config: configFileURL config: configFileURL,
}); });
expect(false).to.equal(true, 'this should not have resolved'); expect(false).to.equal(true, 'this should not have resolved');
} catch(err) { } catch (err) {
expect(err.message).to.match(/Unable to resolve/); expect(err.message).to.match(/Unable to resolve/);
} }
}); });
}); });
}); });
}) });