0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

[ci] format

This commit is contained in:
Matthew Phillips 2024-05-07 17:13:57 +00:00 committed by astrobot-houston
parent d47baa466a
commit cceeafb62a

View file

@ -21,21 +21,21 @@ const versionsConfig = {
18: { 18: {
server: '@astrojs/react/server.js', server: '@astrojs/react/server.js',
client: '@astrojs/react/client.js', client: '@astrojs/react/client.js',
externals: ['react-dom/server', 'react-dom/client'] externals: ['react-dom/server', 'react-dom/client'],
}, },
19: { 19: {
server: '@astrojs/react/server.js', server: '@astrojs/react/server.js',
client: '@astrojs/react/client.js', client: '@astrojs/react/client.js',
externals: ['react-dom/server', 'react-dom/client'] externals: ['react-dom/server', 'react-dom/client'],
} },
}; };
type SupportedReactVersion = keyof (typeof versionsConfig); type SupportedReactVersion = keyof typeof versionsConfig;
type ReactVersionConfig = (typeof versionsConfig)[SupportedReactVersion]; type ReactVersionConfig = (typeof versionsConfig)[SupportedReactVersion];
function getReactMajorVersion(): number { function getReactMajorVersion(): number {
const matches = /\d+\./.exec(ReactVersion); const matches = /\d+\./.exec(ReactVersion);
if(!matches) { if (!matches) {
return NaN; return NaN;
} }
return Number(matches[0]); return Number(matches[0]);
@ -75,12 +75,10 @@ function optionsPlugin(experimentalReactChildren: boolean): vite.Plugin {
}; };
} }
function getViteConfiguration({ function getViteConfiguration(
include, { include, exclude, babel, experimentalReactChildren }: ReactIntegrationOptions = {},
exclude, reactConfig: ReactVersionConfig
babel, ) {
experimentalReactChildren,
}: ReactIntegrationOptions = {}, reactConfig: ReactVersionConfig) {
return { return {
optimizeDeps: { optimizeDeps: {
include: [ include: [
@ -90,9 +88,7 @@ function getViteConfiguration({
'react/jsx-dev-runtime', 'react/jsx-dev-runtime',
'react-dom', 'react-dom',
], ],
exclude: [ exclude: [reactConfig.server],
reactConfig.server,
],
}, },
plugins: [react({ include, exclude, babel }), optionsPlugin(!!experimentalReactChildren)], plugins: [react({ include, exclude, babel }), optionsPlugin(!!experimentalReactChildren)],
resolve: { resolve: {
@ -119,7 +115,7 @@ export default function ({
experimentalReactChildren, experimentalReactChildren,
}: ReactIntegrationOptions = {}): AstroIntegration { }: ReactIntegrationOptions = {}): AstroIntegration {
const majorVersion = getReactMajorVersion(); const majorVersion = getReactMajorVersion();
if(isUnsupportedVersion(majorVersion)) { if (isUnsupportedVersion(majorVersion)) {
throw new Error(`Unsupported React version: ${majorVersion}.`); throw new Error(`Unsupported React version: ${majorVersion}.`);
} }
const versionConfig = versionsConfig[majorVersion as SupportedReactVersion]; const versionConfig = versionsConfig[majorVersion as SupportedReactVersion];
@ -130,7 +126,10 @@ export default function ({
'astro:config:setup': ({ command, addRenderer, updateConfig, injectScript }) => { 'astro:config:setup': ({ command, addRenderer, updateConfig, injectScript }) => {
addRenderer(getRenderer(versionConfig)); addRenderer(getRenderer(versionConfig));
updateConfig({ updateConfig({
vite: getViteConfiguration({ include, exclude, babel, experimentalReactChildren }, versionConfig), vite: getViteConfiguration(
{ include, exclude, babel, experimentalReactChildren },
versionConfig
),
}); });
if (command === 'dev') { if (command === 'dev') {
const preamble = FAST_REFRESH_PREAMBLE.replace(`__BASE__`, '/'); const preamble = FAST_REFRESH_PREAMBLE.replace(`__BASE__`, '/');