Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Vite to 6.0.0 #12524

Merged
merged 13 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-brooms-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': major
---

Bumps Vite to 6.0.0-beta.10 and handles its breaking changes
5 changes: 5 additions & 0 deletions .changeset/eighty-crabs-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/solid-js': major
---

Patches the solid plugin to handle Vite 6
5 changes: 5 additions & 0 deletions .changeset/lemon-frogs-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/svelte': major
---

Updates `@sveltejs/vite-plugin-svelte` to v5 beta to handle Vite 6
2 changes: 1 addition & 1 deletion examples/with-tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"astro": "^5.0.0-beta.10",
"autoprefixer": "^10.4.20",
"canvas-confetti": "^1.9.3",
"postcss": "^8.4.47",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.14"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
},
"pnpm": {
"overrides": {
"vitest>vite": "6.0.0-beta.6",
"vite-node>vite": "6.0.0-beta.6"
"vitest>vite": "6.0.0-beta.10",
"vite-node>vite": "6.0.0-beta.10"
},
"peerDependencyRules": {
"allowAny": [
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@astrojs/tailwind": "workspace:*",
"astro": "workspace:*",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.47",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.14"
}
}
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"ultrahtml": "^1.5.3",
"unist-util-visit": "^5.0.0",
"vfile": "^6.0.3",
"vite": "6.0.0-beta.6",
"vite": "6.0.0-beta.10",
"vitefu": "^1.0.3",
"which-pm": "^3.0.0",
"xxhash-wasm": "^1.0.2",
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ export async function createVite(
replacement: 'astro/components',
},
],
conditions: ['astro'],
// Astro imports in third-party packages should use the same version as root
dedupe: ['astro'],
},
Expand Down
14 changes: 13 additions & 1 deletion packages/astro/src/vite-plugin-astro/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
CompileMetadata,
} from './types.js';

import { normalizePath } from 'vite';
import { defaultClientConditions, defaultServerConditions, normalizePath } from 'vite';
import type { AstroConfig } from '../types/public/config.js';
import { hasSpecialQueries, normalizeFilename } from '../vite-plugin-utils/index.js';
import { type CompileAstroResult, compileAstro } from './compile.js';
Expand Down Expand Up @@ -43,6 +43,18 @@ export default function astro({ settings, logger }: AstroPluginOptions): vite.Pl
const prePlugin: vite.Plugin = {
name: 'astro:build',
enforce: 'pre', // run transforms before other plugins can
async configEnvironment(name, viteConfig, opts) {
viteConfig.resolve ??= {};
// Emulate Vite default fallback for `resolve.conditions` if not set
if (viteConfig.resolve.conditions == null) {
if (viteConfig.consumer === 'client' || name === 'client' || opts.isSsrTargetWebworker) {
viteConfig.resolve.conditions = [...defaultClientConditions];
} else {
viteConfig.resolve.conditions = [...defaultServerConditions];
}
}
viteConfig.resolve.conditions.push('astro');
},
configResolved(viteConfig) {
// Initialize `compile` function to simplify usage later
compile = (code, filename) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/fixtures/postcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@astrojs/vue": "workspace:*",
"astro": "workspace:*",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.47",
"postcss": "^8.4.49",
"solid-js": "^1.9.3",
"svelte": "^5.1.16",
"vue": "^3.5.12"
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/fixtures/tailwindcss-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@astrojs/tailwind": "workspace:*",
"astro": "workspace:*",
"postcss": "^8.4.47",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.14"
}
}
2 changes: 1 addition & 1 deletion packages/astro/test/fixtures/tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@astrojs/tailwind": "workspace:*",
"astro": "workspace:*",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.47",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.14"
}
}
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"typescript": "^5.6.3",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
}
}
2 changes: 1 addition & 1 deletion packages/integrations/alpinejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@playwright/test": "1.48.2",
"astro": "workspace:*",
"astro-scripts": "workspace:*",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
},
"publishConfig": {
"provenance": true
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/markdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"astro-scripts": "workspace:*",
"devalue": "^5.1.1",
"linkedom": "^0.18.5",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
},
"engines": {
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"remark-toc": "^9.0.0",
"shiki": "^1.22.2",
"unified": "^11.0.5",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
},
"engines": {
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@preact/signals": "^1.3.0",
"babel-plugin-transform-hook-names": "^1.0.2",
"preact-render-to-string": "^6.5.11",
"vite": "^5.4.10"
"vite": "6.0.0-beta.10"
},
"devDependencies": {
"astro": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"dependencies": {
"@vitejs/plugin-react": "^4.3.3",
"ultrahtml": "^1.5.3",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
},
"devDependencies": {
"@types/react": "^18.3.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"vite-plugin-solid": "^2.10.2",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
},
"devDependencies": {
"astro": "workspace:*",
Expand Down
67 changes: 37 additions & 30 deletions packages/integrations/solid/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
AstroRenderer,
ContainerRenderer,
} from 'astro';
import { defaultClientConditions, defaultServerConditions } from 'vite';
import type { PluginOption, UserConfig } from 'vite';
import solid, { type Options as ViteSolidPluginOptions } from 'vite-plugin-solid';

Expand Down Expand Up @@ -46,42 +47,14 @@ async function getDevtoolsPlugin(logger: AstroIntegrationLogger, retrieve: boole
}

async function getViteConfiguration(
isDev: boolean,
{ include, exclude }: Options,
devtoolsPlugin: DevtoolsPlugin | null,
) {
// https://github.com/solidjs/vite-plugin-solid
// We inject the dev mode only if the user explicitly wants it or if we are in dev (serve) mode
const nestedDeps = ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'];
const config: UserConfig = {
resolve: {
conditions: ['solid', ...(isDev ? ['development'] : [])],
dedupe: nestedDeps,
alias: [{ find: /^solid-refresh$/, replacement: '/@solid-refresh' }],
},
optimizeDeps: {
include: [...nestedDeps],
exclude: ['@astrojs/solid-js/server.js'],
},
plugins: [
solid({ include, exclude, dev: isDev, ssr: true }),
{
name: '@astrojs/solid:config-overrides',
enforce: 'post',
config() {
return {
esbuild: {
// To support using alongside other JSX frameworks, still let
// esbuild compile stuff. Solid goes first anyways.
include: /\.(m?ts|[jt]sx)$/,
},
};
},
},
],
ssr: {
external: ['babel-preset-solid'],
},
plugins: [solidPlugin({ include, exclude })],
};

if (devtoolsPlugin) {
Expand All @@ -91,6 +64,40 @@ async function getViteConfiguration(
return config;
}

// Apply patch for https://github.com/solidjs/vite-plugin-solid/pull/163
function solidPlugin({ include, exclude }: Options) {
const plugin = solid({ include, exclude, ssr: true });

// patch the config hook so it doesn't return `resolve.conditions`
const _config = plugin.config;
plugin.config = async function () {
// @ts-expect-error ignore errors due to hacky patch
// eslint-disable-next-line prefer-rest-params
const c = await _config.apply(plugin, arguments);
if (c?.resolve?.conditions) {
c.resolve.conditions = undefined;
}
return c;
};

plugin.configEnvironment = async function (name, config, opts) {
config.resolve ??= {};
// Emulate Vite default fallback for `resolve.conditions` if not set
if (config.resolve.conditions == null) {
// @ts-ignore These exports only exist in Vite 6
const {} = await import('vite');
if (config.consumer === 'client' || name === 'client' || opts.isSsrTargetWebworker) {
config.resolve.conditions = [...defaultClientConditions];
} else {
config.resolve.conditions = [...defaultServerConditions];
}
}
config.resolve.conditions.push('solid');
};

return plugin;
}

function getRenderer(): AstroRenderer {
return {
name: '@astrojs/solid-js',
Expand Down Expand Up @@ -128,7 +135,7 @@ export default function (options: Options = {}): AstroIntegration {

addRenderer(getRenderer());
updateConfig({
vite: await getViteConfiguration(command === 'dev', options, devtoolsPlugin),
vite: await getViteConfiguration(options, devtoolsPlugin),
});

if (devtoolsPlugin) {
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"dev": "astro-scripts dev \"src/**/*.ts\""
},
"dependencies": {
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@sveltejs/vite-plugin-svelte": "^5.0.0-beta.0",
"svelte2tsx": "^0.7.22",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
},
"devDependencies": {
"astro": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/tailwind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
},
"dependencies": {
"autoprefixer": "^10.4.20",
"postcss": "^8.4.47",
"postcss": "^8.4.49",
"postcss-load-config": "^4.0.2"
},
"devDependencies": {
"astro": "workspace:*",
"astro-scripts": "workspace:*",
"tailwindcss": "^3.4.14",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
},
"peerDependencies": {
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@vitejs/plugin-vue-jsx": "^4.0.1",
"@vue/compiler-sfc": "^3.5.12",
"vite-plugin-vue-devtools": "^7.6.3",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
},
"devDependencies": {
"astro": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
"astro": "workspace:*",
"astro-scripts": "workspace:*",
"typescript": "^5.6.3",
"vite": "6.0.0-beta.6"
"vite": "6.0.0-beta.10"
}
}
Loading
Loading