[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,13 +19,17 @@ 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
}; | {
markdown: undefined | { format: undefined | 'file' | 'directory';
mode: undefined | 'md' | 'mdx'; };
syntaxHighlight: undefined | 'shiki' | 'prism' | false; markdown:
}; | undefined
| {
mode: undefined | 'md' | 'mdx';
syntaxHighlight: undefined | 'shiki' | 'prism' | false;
};
} }
interface EventCliSessionInternal extends EventCliSession { interface EventCliSessionInternal extends EventCliSession {
@ -85,27 +89,33 @@ 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: [ ? {
userConfig?.markdown?.remarkPlugins ?? [], markdownPlugins: [
userConfig?.markdown?.rehypePlugins ?? [], userConfig?.markdown?.remarkPlugins ?? [],
].flat(1), userConfig?.markdown?.rehypePlugins ?? [],
adapter: userConfig?.adapter?.name ?? null, ].flat(1),
integrations: userConfig?.integrations?.map((i: any) => i.name) ?? [], adapter: userConfig?.adapter?.name ?? null,
trailingSlash: userConfig?.trailingSlash, integrations: userConfig?.integrations?.map((i: any) => i.name) ?? [],
build: userConfig?.build ? { trailingSlash: userConfig?.trailingSlash,
format: userConfig?.build?.format build: userConfig?.build
} : undefined, ? {
markdown: userConfig?.markdown ? { format: userConfig?.build?.format,
mode: userConfig?.markdown?.mode, }
syntaxHighlight: userConfig.markdown?.syntaxHighlight : undefined,
} : undefined, markdown: userConfig?.markdown
} : undefined; ? {
mode: userConfig?.markdown?.mode,
syntaxHighlight: userConfig.markdown?.syntaxHighlight,
}
: 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
); );
@ -159,7 +168,7 @@ describe('Session event', () => {
publicDir: 'some/dir', publicDir: 'some/dir',
}, },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -178,7 +187,7 @@ describe('Session event', () => {
'vite.publicDir', 'vite.publicDir',
]); ]);
}); });
it('vite.resolve keys are captured', async () => { it('vite.resolve keys are captured', async () => {
const config = { const config = {
vite: { vite: {
@ -190,7 +199,7 @@ describe('Session event', () => {
}, },
}, },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -198,9 +207,14 @@ 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 () => {
const config = { const config = {
vite: { vite: {
@ -213,7 +227,7 @@ describe('Session event', () => {
}, },
}, },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -230,7 +244,7 @@ describe('Session event', () => {
'vite.css.postcss', 'vite.css.postcss',
]); ]);
}); });
it('vite.server keys are captured', async () => { it('vite.server keys are captured', async () => {
const config = { const config = {
vite: { vite: {
@ -244,7 +258,7 @@ describe('Session event', () => {
}, },
}, },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -262,7 +276,7 @@ describe('Session event', () => {
'vite.server.fs.allow', 'vite.server.fs.allow',
]); ]);
}); });
it('vite.build keys are captured', async () => { it('vite.build keys are captured', async () => {
const config = { const config = {
vite: { vite: {
@ -275,7 +289,7 @@ describe('Session event', () => {
}, },
}, },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -291,7 +305,7 @@ describe('Session event', () => {
'vite.build.cssTarget', 'vite.build.cssTarget',
]); ]);
}); });
it('vite.preview keys are captured', async () => { it('vite.preview keys are captured', async () => {
const config = { const config = {
vite: { vite: {
@ -304,7 +318,7 @@ describe('Session event', () => {
}, },
}, },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -320,7 +334,7 @@ describe('Session event', () => {
'vite.preview.another', 'vite.preview.another',
]); ]);
}); });
it('vite.optimizeDeps keys are captured', async () => { it('vite.optimizeDeps keys are captured', async () => {
const config = { const config = {
vite: { vite: {
@ -330,7 +344,7 @@ describe('Session event', () => {
}, },
}, },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -345,7 +359,7 @@ describe('Session event', () => {
'vite.optimizeDeps.exclude', 'vite.optimizeDeps.exclude',
]); ]);
}); });
it('vite.ssr keys are captured', async () => { it('vite.ssr keys are captured', async () => {
const config = { const config = {
vite: { vite: {
@ -355,7 +369,7 @@ describe('Session event', () => {
}, },
}, },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -363,9 +377,14 @@ 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 () => {
const config = { const config = {
vite: { vite: {
@ -375,7 +394,7 @@ describe('Session event', () => {
}, },
}, },
}; };
const [{ payload }] = events.eventCliSession( const [{ payload }] = events.eventCliSession(
{ {
cliCommand: 'dev', cliCommand: 'dev',
@ -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',
]); ]);
}) });
}) });
}); });