[ci] format

This commit is contained in:
matthewp 2022-05-06 13:23:09 +00:00 committed by github-actions[bot]
parent 8021998bb6
commit adc94076f7
4 changed files with 103 additions and 69 deletions

View file

@ -176,7 +176,7 @@ export async function cli(args: string[]) {
event.eventCliSession( event.eventCliSession(
{ astroVersion: process.env.PACKAGE_VERSION ?? '', cliCommand: 'check' }, { astroVersion: process.env.PACKAGE_VERSION ?? '', cliCommand: 'check' },
userConfig, userConfig,
flags, flags
) )
); );
const ret = await check(astroConfig); const ret = await check(astroConfig);

View file

@ -442,7 +442,7 @@ export async function openConfig(configOptions: LoadConfigOptions): Promise<Open
astroConfig, astroConfig,
userConfig, userConfig,
flags, flags,
root root,
}; };
} }

View file

@ -19,10 +19,14 @@ interface ConfigInfo {
adapter: string | null; adapter: string | null;
integrations: string[]; integrations: string[];
trailingSlash: undefined | 'always' | 'never' | 'ignore'; trailingSlash: undefined | 'always' | 'never' | 'ignore';
build: undefined | { build:
format: undefined | 'file' | 'directory' | undefined
| {
format: undefined | 'file' | 'directory';
}; };
markdown: undefined | { markdown:
| undefined
| {
mode: undefined | 'md' | 'mdx'; mode: undefined | 'md' | 'mdx';
syntaxHighlight: undefined | 'shiki' | 'prism' | false; syntaxHighlight: undefined | 'shiki' | 'prism' | false;
}; };
@ -85,9 +89,10 @@ function configKeys(obj: Record<string, any> | undefined, parentKey: string): st
export function eventCliSession( export function eventCliSession(
event: EventCliSession, event: EventCliSession,
userConfig?: AstroUserConfig, userConfig?: AstroUserConfig,
flags?: Record<string, any>, flags?: Record<string, any>
): { eventName: string; payload: EventCliSessionInternal }[] { ): { eventName: string; payload: EventCliSessionInternal }[] {
const configValues = userConfig ? { const configValues = userConfig
? {
markdownPlugins: [ markdownPlugins: [
userConfig?.markdown?.remarkPlugins ?? [], userConfig?.markdown?.remarkPlugins ?? [],
userConfig?.markdown?.rehypePlugins ?? [], userConfig?.markdown?.rehypePlugins ?? [],
@ -95,17 +100,22 @@ export function eventCliSession(
adapter: userConfig?.adapter?.name ?? null, adapter: userConfig?.adapter?.name ?? null,
integrations: userConfig?.integrations?.map((i: any) => i.name) ?? [], integrations: userConfig?.integrations?.map((i: any) => i.name) ?? [],
trailingSlash: userConfig?.trailingSlash, trailingSlash: userConfig?.trailingSlash,
build: userConfig?.build ? { build: userConfig?.build
format: userConfig?.build?.format ? {
} : undefined, format: userConfig?.build?.format,
markdown: userConfig?.markdown ? { }
: undefined,
markdown: userConfig?.markdown
? {
mode: userConfig?.markdown?.mode, mode: userConfig?.markdown?.mode,
syntaxHighlight: userConfig.markdown?.syntaxHighlight syntaxHighlight: userConfig.markdown?.syntaxHighlight,
} : undefined, }
} : undefined; : undefined,
}
: undefined;
// Filter out yargs default `_` flag which is the cli command // Filter out yargs default `_` flag which is the cli command
const cliFlags = flags ? Object.keys(flags).filter(name => name != '_'): undefined; const cliFlags = flags ? Object.keys(flags).filter((name) => name != '_') : undefined;
const payload: EventCliSessionInternal = { const payload: EventCliSessionInternal = {
cliCommand: event.cliCommand, cliCommand: event.cliCommand,

View file

@ -32,12 +32,12 @@ describe('Session event', () => {
srcDir: 1, srcDir: 1,
build: { build: {
format: 'file', format: 'file',
} },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
astroVersion: '0.0.0' astroVersion: '0.0.0',
}, },
config config
); );
@ -49,12 +49,12 @@ describe('Session event', () => {
srcDir: 1, srcDir: 1,
build: { build: {
format: 'file', format: 'file',
} },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
astroVersion: '0.0.0' astroVersion: '0.0.0',
}, },
config config
); );
@ -68,13 +68,13 @@ describe('Session event', () => {
srcDir: 1, srcDir: 1,
server: { server: {
host: 'example.com', host: 'example.com',
port: 8033 port: 8033,
} },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
astroVersion: '0.0.0' astroVersion: '0.0.0',
}, },
config config
); );
@ -92,36 +92,45 @@ describe('Session event', () => {
shikiConfig: { shikiConfig: {
lang: 1, lang: 1,
theme: 2, theme: 2,
wrap: 3 wrap: 3,
}, },
syntaxHighlight: 'shiki', syntaxHighlight: 'shiki',
remarkPlugins: [], remarkPlugins: [],
rehypePlugins: [], rehypePlugins: [],
} },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
astroVersion: '0.0.0' astroVersion: '0.0.0',
}, },
config config
); );
expect(payload.configKeys).to.deep.equal(['publicDir', 'markdown', expect(payload.configKeys).to.deep.equal([
'markdown.drafts', 'markdown.mode', 'markdown.shikiConfig', 'publicDir',
'markdown.shikiConfig.lang', 'markdown.shikiConfig.theme', 'markdown.shikiConfig.wrap', 'markdown',
'markdown.syntaxHighlight', 'markdown.remarkPlugins', 'markdown.rehypePlugins']); 'markdown.drafts',
'markdown.mode',
'markdown.shikiConfig',
'markdown.shikiConfig.lang',
'markdown.shikiConfig.theme',
'markdown.shikiConfig.wrap',
'markdown.syntaxHighlight',
'markdown.remarkPlugins',
'markdown.rehypePlugins',
]);
}); });
it('mode', () => { it('mode', () => {
const config = { const config = {
markdown: { markdown: {
mode: 'mdx', mode: 'mdx',
} },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
astroVersion: '0.0.0' astroVersion: '0.0.0',
}, },
config config
); );
@ -132,12 +141,12 @@ describe('Session event', () => {
const config = { const config = {
markdown: { markdown: {
syntaxHighlight: 'shiki', syntaxHighlight: 'shiki',
} },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
astroVersion: '0.0.0' astroVersion: '0.0.0',
}, },
config config
); );
@ -198,7 +207,12 @@ describe('Session event', () => {
}, },
config config
); );
expect(payload.configKeys).is.deep.equal(['vite', 'vite.resolve', 'vite.resolve.alias', 'vite.resolve.dedupe']); expect(payload.configKeys).is.deep.equal([
'vite',
'vite.resolve',
'vite.resolve.alias',
'vite.resolve.dedupe',
]);
}); });
it('vite.css keys are captured', async () => { it('vite.css keys are captured', async () => {
@ -363,7 +377,12 @@ describe('Session event', () => {
}, },
config config
); );
expect(payload.configKeys).is.deep.equal(['vite', 'vite.ssr', 'vite.ssr.external', 'vite.ssr.target']); expect(payload.configKeys).is.deep.equal([
'vite',
'vite.ssr',
'vite.ssr.external',
'vite.ssr.target',
]);
}); });
it('vite.worker keys are captured', async () => { it('vite.worker keys are captured', async () => {
@ -383,7 +402,12 @@ describe('Session event', () => {
}, },
config config
); );
expect(payload.configKeys).is.deep.equal(['vite', 'vite.worker', 'vite.worker.format', 'vite.worker.plugins']); expect(payload.configKeys).is.deep.equal([
'vite',
'vite.worker',
'vite.worker.format',
'vite.worker.plugins',
]);
}); });
}); });
@ -399,7 +423,7 @@ describe('Session event', () => {
experimentalSsr: true, experimentalSsr: true,
experimentalIntegrations: true, experimentalIntegrations: true,
drafts: true, drafts: true,
} };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -416,8 +440,8 @@ describe('Session event', () => {
'config', 'config',
'experimentalSsr', 'experimentalSsr',
'experimentalIntegrations', 'experimentalIntegrations',
'drafts' 'drafts',
]); ]);
}) });
}) });
}); });