From fddccc471ba5b68b9f0defd0d60ed75bded9e55d Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Wed, 1 May 2024 16:48:38 +0900 Subject: [PATCH] chore(deps): vite v6.0.0-alpha.8 (#62) --- .../src/features/unocss/plugin.ts | 52 ++++++++----- package.json | 2 +- pnpm-lock.yaml | 76 +++++++++---------- 3 files changed, 70 insertions(+), 60 deletions(-) diff --git a/examples/react-server/src/features/unocss/plugin.ts b/examples/react-server/src/features/unocss/plugin.ts index 2b8c63a5..89fcd9b7 100644 --- a/examples/react-server/src/features/unocss/plugin.ts +++ b/examples/react-server/src/features/unocss/plugin.ts @@ -1,6 +1,6 @@ import { debounce, objectHas, tinyassert } from "@hiogawa/utils"; import vitePluginUnocss, { type UnocssVitePluginAPI } from "@unocss/vite"; -import { DevEnvironment, type Plugin } from "vite"; +import { DevEnvironment, type Plugin, type PluginOption } from "vite"; import { invalidateModule } from "../style/plugin"; import { createVirtualPlugin } from "../utils/plugin"; @@ -8,34 +8,42 @@ import { createVirtualPlugin } from "../utils/plugin"; // https://github.com/unocss/unocss/tree/47eafba27619ed26579df60fe3fdeb6122b5093c/packages/vite/src/modes/global // https://github.com/tailwindlabs/tailwindcss/blob/719c0d488378002ff752e8dc7199c843930bb296/packages/%40tailwindcss-vite/src/index.ts -export function vitePluginSharedUnocss(): Plugin { +// TODO: +// reading `uno.config.ts` is adding more than 1 sec on startup time. is it normal? + +export function vitePluginSharedUnocss(): PluginOption { // reuse original plugin to grab internal unocss instance and transform plugins - const originPlugins = vitePluginUnocss(); - const transformPlugins = originPlugins.filter((p) => - p.name.startsWith("unocss:transformers:"), - ); - const apiPlugin = originPlugins.find((p) => p.name === "unocss:api"); + const originalPlugins = vitePluginUnocss(); + const apiPlugin = originalPlugins.find((p) => p.name === "unocss:api"); tinyassert(apiPlugin); const ctx = (apiPlugin.api as UnocssVitePluginAPI).getContext(); - return { + // reuse unocss transform plugins with sharedDuringBuild + const transformPlugins = originalPlugins + .filter((plugin) => plugin.name.startsWith("unocss:transformers:")) + .map((plugin) => ({ + ...plugin, + sharedDuringBuild: true, + })); + + const mainPlugin: Plugin = { name: vitePluginSharedUnocss.name, sharedDuringBuild: true, - create(environment) { - const plugins: Plugin[] = [...transformPlugins]; - // [dev, build] - // extract tokens by intercepting transform - plugins.push({ - name: vitePluginSharedUnocss.name + ":extract", - transform(code, id) { - if (ctx.filter(code, id)) { - ctx.tasks.push(ctx.extract(code, id)); - } - }, - }); + // extract tokens by intercepting transform + transform: { + order: "post", + handler(code, id) { + if (ctx.filter(code, id)) { + ctx.tasks.push(ctx.extract(code, id)); + } + }, + }, + + create(environment) { + const plugins: Plugin[] = []; - // Following plugins are naturally applied to the environments + // Following plugins are applied only to the environments // which import "virtual:unocss.css". // So, even though we only need to handle "client" environment case, // such artificial restriction is not necessary. @@ -110,4 +118,6 @@ export function vitePluginSharedUnocss(): Plugin { return plugins; }, }; + + return [...transformPlugins, mainPlugin]; } diff --git a/package.json b/package.json index fd1ec400..c3bcd855 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "tsup": "^8.0.2", "tsx": "^4.7.1", "typescript": "^5.4.3", - "vite": "6.0.0-alpha.7", + "vite": "6.0.0-alpha.8", "vitest": "^1.5.1", "wrangler": "^3.48.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 95f13926..e7118d5a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,7 +5,7 @@ settings: excludeLinksFromLockfile: false overrides: - vite: 6.0.0-alpha.7 + vite: 6.0.0-alpha.8 importers: @@ -22,7 +22,7 @@ importers: version: 1.6.4-pre.1 '@hiogawa/vite-plugin-ssr-middleware': specifier: ^0.0.3 - version: 0.0.3(vite@6.0.0-alpha.7) + version: 0.0.3(vite@6.0.0-alpha.8) '@playwright/test': specifier: ^1.42.1 version: 1.42.1 @@ -34,7 +34,7 @@ importers: version: 20.11.30 '@vitejs/plugin-react': specifier: ^4.2.1 - version: 4.2.1(vite@6.0.0-alpha.7) + version: 4.2.1(vite@6.0.0-alpha.8) esbuild: specifier: ^0.20.2 version: 0.20.2 @@ -54,8 +54,8 @@ importers: specifier: ^5.4.3 version: 5.4.3 vite: - specifier: 6.0.0-alpha.7 - version: 6.0.0-alpha.7(@types/node@20.11.30) + specifier: 6.0.0-alpha.8 + version: 6.0.0-alpha.8(@types/node@20.11.30) vitest: specifier: ^1.5.1 version: 1.5.1(@types/node@20.11.30) @@ -111,13 +111,13 @@ importers: version: 18.2.22 '@unocss/vite': specifier: ^0.59.4 - version: 0.59.4(vite@6.0.0-alpha.7) + version: 0.59.4(vite@6.0.0-alpha.8) happy-dom: specifier: ^14.7.1 version: 14.7.1 unocss: specifier: ^0.59.4 - version: 0.59.4(postcss@8.4.38)(vite@6.0.0-alpha.7) + version: 0.59.4(postcss@8.4.38)(vite@6.0.0-alpha.8) examples/react-ssr: dependencies: @@ -177,7 +177,7 @@ importers: version: link:../../packages/workerd '@vitejs/plugin-vue': specifier: ^5.0.4 - version: 5.0.4(vite@6.0.0-alpha.7)(vue@3.4.23) + version: 5.0.4(vite@6.0.0-alpha.8)(vue@3.4.23) vue-tsc: specifier: ^2.0.13 version: 2.0.13(typescript@5.4.3) @@ -202,7 +202,7 @@ importers: version: link:../../packages/workerd '@vitejs/plugin-vue': specifier: ^5.0.4 - version: 5.0.4(vite@6.0.0-alpha.7)(vue@3.4.23) + version: 5.0.4(vite@6.0.0-alpha.8)(vue@3.4.23) vue-tsc: specifier: ^2.0.13 version: 2.0.13(typescript@5.4.3) @@ -216,8 +216,8 @@ importers: packages/ssr-middleware: dependencies: vite: - specifier: 6.0.0-alpha.7 - version: 6.0.0-alpha.7(@types/node@20.11.30) + specifier: 6.0.0-alpha.8 + version: 6.0.0-alpha.8(@types/node@20.11.30) packages/workerd: dependencies: @@ -225,8 +225,8 @@ importers: specifier: ^3.20240404.0 version: 3.20240404.0 vite: - specifier: 6.0.0-alpha.7 - version: 6.0.0-alpha.7(@types/node@20.11.30) + specifier: 6.0.0-alpha.8 + version: 6.0.0-alpha.8(@types/node@20.11.30) wrangler: specifier: ^3.48.0 version: 3.48.0(@cloudflare/workers-types@4.20240405.0) @@ -1346,12 +1346,12 @@ packages: resolution: {integrity: sha512-L8g6kQuPKJXKoqF1XuFYXXHQ3Z4VXuEX8tlOz/gPO6uP2VQ95JUyONsr93RpVTLc/GGblXY30/YK4r56kJzzgQ==} dev: true - /@hiogawa/vite-plugin-ssr-middleware@0.0.3(vite@6.0.0-alpha.7): + /@hiogawa/vite-plugin-ssr-middleware@0.0.3(vite@6.0.0-alpha.8): resolution: {integrity: sha512-84bzaAuImty4s4vHjOk5MQMzmDs0W0GP43fOTFhsBfj/MSJCNJ68elmPNZWs57WkIEzcdB4haY/P8Nf4ZGH8Qw==} peerDependencies: - vite: 6.0.0-alpha.7 + vite: 6.0.0-alpha.8 dependencies: - vite: 6.0.0-alpha.7(@types/node@20.11.30) + vite: 6.0.0-alpha.8(@types/node@20.11.30) dev: true /@iconify/types@2.0.0: @@ -1663,18 +1663,18 @@ packages: csstype: 3.1.3 dev: true - /@unocss/astro@0.59.4(vite@6.0.0-alpha.7): + /@unocss/astro@0.59.4(vite@6.0.0-alpha.8): resolution: {integrity: sha512-DU3OR5MMR1Uvvec4/wB9EetDASHRg19Moy6z/MiIhn8JWJ0QzWYgSeJcfUX8exomMYv6WUEQJL+CyLI34Wmn8w==} peerDependencies: - vite: 6.0.0-alpha.7 + vite: 6.0.0-alpha.8 peerDependenciesMeta: vite: optional: true dependencies: '@unocss/core': 0.59.4 '@unocss/reset': 0.59.4 - '@unocss/vite': 0.59.4(vite@6.0.0-alpha.7) - vite: 6.0.0-alpha.7(@types/node@20.11.30) + '@unocss/vite': 0.59.4(vite@6.0.0-alpha.8) + vite: 6.0.0-alpha.8(@types/node@20.11.30) transitivePeerDependencies: - rollup dev: true @@ -1857,10 +1857,10 @@ packages: '@unocss/core': 0.59.4 dev: true - /@unocss/vite@0.59.4(vite@6.0.0-alpha.7): + /@unocss/vite@0.59.4(vite@6.0.0-alpha.8): resolution: {integrity: sha512-q7GN7vkQYn79n7vYIUlaa7gXGwc7pk0Qo3z3ZFwWGE43/DtZnn2Hwl5UjgBAgi9McA+xqHJEHRsJnI7HJPHUYA==} peerDependencies: - vite: 6.0.0-alpha.7 + vite: 6.0.0-alpha.8 dependencies: '@ampproject/remapping': 2.3.0 '@rollup/pluginutils': 5.1.0 @@ -1872,35 +1872,35 @@ packages: chokidar: 3.6.0 fast-glob: 3.3.2 magic-string: 0.30.10 - vite: 6.0.0-alpha.7(@types/node@20.11.30) + vite: 6.0.0-alpha.8(@types/node@20.11.30) transitivePeerDependencies: - rollup dev: true - /@vitejs/plugin-react@4.2.1(vite@6.0.0-alpha.7): + /@vitejs/plugin-react@4.2.1(vite@6.0.0-alpha.8): resolution: {integrity: sha512-oojO9IDc4nCUUi8qIR11KoQm0XFFLIwsRBwHRR4d/88IWghn1y6ckz/bJ8GHDCsYEJee8mDzqtJxh15/cisJNQ==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: - vite: 6.0.0-alpha.7 + vite: 6.0.0-alpha.8 dependencies: '@babel/core': 7.24.3 '@babel/plugin-transform-react-jsx-self': 7.24.1(@babel/core@7.24.3) '@babel/plugin-transform-react-jsx-source': 7.24.1(@babel/core@7.24.3) '@types/babel__core': 7.20.5 react-refresh: 0.14.0 - vite: 6.0.0-alpha.7(@types/node@20.11.30) + vite: 6.0.0-alpha.8(@types/node@20.11.30) transitivePeerDependencies: - supports-color dev: true - /@vitejs/plugin-vue@5.0.4(vite@6.0.0-alpha.7)(vue@3.4.23): + /@vitejs/plugin-vue@5.0.4(vite@6.0.0-alpha.8)(vue@3.4.23): resolution: {integrity: sha512-WS3hevEszI6CEVEx28F8RjTX97k3KsrcY6kvTg7+Whm5y3oYvcqzVeGCU3hxSAn4uY2CLCkeokkGKpoctccilQ==} engines: {node: ^18.0.0 || >=20.0.0} peerDependencies: - vite: 6.0.0-alpha.7 + vite: 6.0.0-alpha.8 vue: ^3.2.25 dependencies: - vite: 6.0.0-alpha.7(@types/node@20.11.30) + vite: 6.0.0-alpha.8(@types/node@20.11.30) vue: 3.4.23(typescript@5.4.3) dev: true @@ -4020,19 +4020,19 @@ packages: dependencies: '@fastify/busboy': 2.1.1 - /unocss@0.59.4(postcss@8.4.38)(vite@6.0.0-alpha.7): + /unocss@0.59.4(postcss@8.4.38)(vite@6.0.0-alpha.8): resolution: {integrity: sha512-QmCVjRObvVu/gsGrJGVt0NnrdhFFn314BUZn2WQyXV9rIvHLRmG5bIu0j5vibJkj7ZhFchTrnTM1pTFXP1xt5g==} engines: {node: '>=14'} peerDependencies: '@unocss/webpack': 0.59.4 - vite: 6.0.0-alpha.7 + vite: 6.0.0-alpha.8 peerDependenciesMeta: '@unocss/webpack': optional: true vite: optional: true dependencies: - '@unocss/astro': 0.59.4(vite@6.0.0-alpha.7) + '@unocss/astro': 0.59.4(vite@6.0.0-alpha.8) '@unocss/cli': 0.59.4 '@unocss/core': 0.59.4 '@unocss/extractor-arbitrary-variants': 0.59.4 @@ -4051,8 +4051,8 @@ packages: '@unocss/transformer-compile-class': 0.59.4 '@unocss/transformer-directives': 0.59.4 '@unocss/transformer-variant-group': 0.59.4 - '@unocss/vite': 0.59.4(vite@6.0.0-alpha.7) - vite: 6.0.0-alpha.7(@types/node@20.11.30) + '@unocss/vite': 0.59.4(vite@6.0.0-alpha.8) + vite: 6.0.0-alpha.8(@types/node@20.11.30) transitivePeerDependencies: - postcss - rollup @@ -4088,7 +4088,7 @@ packages: debug: 4.3.4 pathe: 1.1.2 picocolors: 1.0.0 - vite: 6.0.0-alpha.7(@types/node@20.11.30) + vite: 6.0.0-alpha.8(@types/node@20.11.30) transitivePeerDependencies: - '@types/node' - less @@ -4100,8 +4100,8 @@ packages: - terser dev: true - /vite@6.0.0-alpha.7(@types/node@20.11.30): - resolution: {integrity: sha512-dmnsi0DuW2zmEJ6RhHv9cWaBoKeTycjjMtSL5ZGA3C5wgCaKgPgUL1aqiieecRyHb+Bx2jn/3hy00KNrE95LWw==} + /vite@6.0.0-alpha.8(@types/node@20.11.30): + resolution: {integrity: sha512-dqiMCoVfSQ5YlfxkC5NUtQ386WQkh33zfVH3o5DqhssBV0lw4AtQKxBXrv2HyjI/wWX8AcA1HW0tlIor3sYFRA==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: @@ -4178,7 +4178,7 @@ packages: strip-literal: 2.1.0 tinybench: 2.8.0 tinypool: 0.8.4 - vite: 6.0.0-alpha.7(@types/node@20.11.30) + vite: 6.0.0-alpha.8(@types/node@20.11.30) vite-node: 1.5.1(@types/node@20.11.30) why-is-node-running: 2.2.2 transitivePeerDependencies: