From 0e58e72ab3b36156fb32bf983fe56c7621a11106 Mon Sep 17 00:00:00 2001 From: Zheeeng Date: Tue, 15 Feb 2022 15:21:55 +0800 Subject: [PATCH 001/167] chore: prefer using nullish-coalescing over or logic operator (#6790) --- packages/playground/testUtils.ts | 4 ++-- packages/vite/src/node/ssr/ssrManifestPlugin.ts | 2 +- packages/vite/src/node/ssr/ssrStacktrace.ts | 2 +- packages/vite/src/node/utils.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/playground/testUtils.ts b/packages/playground/testUtils.ts index 3c6cba769b3ffe..0ae0c6e8766e95 100644 --- a/packages/playground/testUtils.ts +++ b/packages/playground/testUtils.ts @@ -56,7 +56,7 @@ async function toEl(el: string | ElementHandle): Promise { export async function getColor(el: string | ElementHandle): Promise { el = await toEl(el) const rgb = await el.evaluate((el) => getComputedStyle(el as Element).color) - return hexToNameMap[rgbToHex(rgb)] || rgb + return hexToNameMap[rgbToHex(rgb)] ?? rgb } export async function getBg(el: string | ElementHandle): Promise { @@ -119,7 +119,7 @@ export async function untilUpdated( if (isBuild && !runInBuild) return const maxTries = process.env.CI ? 100 : 50 for (let tries = 0; tries < maxTries; tries++) { - const actual = (await poll()) || '' + const actual = (await poll()) ?? '' if (actual.indexOf(expected) > -1 || tries === maxTries - 1) { expect(actual).toMatch(expected) break diff --git a/packages/vite/src/node/ssr/ssrManifestPlugin.ts b/packages/vite/src/node/ssr/ssrManifestPlugin.ts index a92550e39d4ed0..351c91349a3ca3 100644 --- a/packages/vite/src/node/ssr/ssrManifestPlugin.ts +++ b/packages/vite/src/node/ssr/ssrManifestPlugin.ts @@ -29,7 +29,7 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin { for (const id in chunk.modules) { const normalizedId = normalizePath(relative(config.root, id)) const mappedChunks = - ssrManifest[normalizedId] || (ssrManifest[normalizedId] = []) + ssrManifest[normalizedId] ?? (ssrManifest[normalizedId] = []) if (!chunk.isEntry) { mappedChunks.push(base + chunk.fileName) } diff --git a/packages/vite/src/node/ssr/ssrStacktrace.ts b/packages/vite/src/node/ssr/ssrStacktrace.ts index 75fcd8d2933c6f..0d847cb7da7041 100644 --- a/packages/vite/src/node/ssr/ssrStacktrace.ts +++ b/packages/vite/src/node/ssr/ssrStacktrace.ts @@ -46,7 +46,7 @@ export function ssrRewriteStacktrace( return input } - const source = `${pos.source}:${pos.line || 0}:${pos.column || 0}` + const source = `${pos.source}:${pos.line ?? 0}:${pos.column ?? 0}` if (!varName || varName === 'eval') { return ` at ${source}` } else { diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 2b2ba6fb859107..3012e6d57e6c65 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -222,7 +222,7 @@ export function injectQuery(url: string, queryToInject: string): string { } pathname = decodeURIComponent(pathname) return `${pathname}?${queryToInject}${search ? `&` + search.slice(1) : ''}${ - hash || '' + hash ?? '' }` } @@ -518,7 +518,7 @@ export async function processSrcSet( ) return ret.reduce((prev, { url, descriptor }, index) => { - descriptor = descriptor || '' + descriptor ??= '' return (prev += url + ` ${descriptor}${index === ret.length - 1 ? '' : ', '}`) }, '') From 3480f27d4db7f7ebd27164d9185e7b387762274e Mon Sep 17 00:00:00 2001 From: Zheeeng Date: Tue, 15 Feb 2022 15:22:33 +0800 Subject: [PATCH 002/167] chore(types): correct typing in jestPerTestSetup (#6786) --- scripts/jestPerTestSetup.ts | 24 +++++++++++++----------- scripts/tsconfig.json | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/scripts/jestPerTestSetup.ts b/scripts/jestPerTestSetup.ts index 89209c3ffcbf69..9c15edf9f059bf 100644 --- a/scripts/jestPerTestSetup.ts +++ b/scripts/jestPerTestSetup.ts @@ -10,8 +10,7 @@ import type { Logger } from 'vite' import { createServer, build } from 'vite' -import type { Page } from 'playwright-chromium' -// eslint-disable-next-line node/no-extraneous-import +import type { Page, ConsoleMessage } from 'playwright-chromium' import type { RollupError, RollupWatcher, RollupWatcherEvent } from 'rollup' const isBuildTest = !!process.env.VITE_TEST_BUILD @@ -45,13 +44,15 @@ let server: ViteDevServer | http.Server let tempDir: string let rootDir: string -const setBeforeAllError = (err) => ((global as any).beforeAllError = err) -const getBeforeAllError = () => (global as any).beforeAllError +const setBeforeAllError = (err: Error | null) => { + global.beforeAllError = err +} +const getBeforeAllError = () => global.beforeAllError //init with null so old errors don't carry over setBeforeAllError(null) -const logs = ((global as any).browserLogs = []) -const onConsole = (msg) => { +const logs: string[] = (global.browserLogs = []) +const onConsole = (msg: ConsoleMessage) => { logs.push(msg.text()) } @@ -145,7 +146,7 @@ beforeAll(async () => { await page.goto(url) } } - } catch (e) { + } catch (e: any) { // jest doesn't exit if our setup has error here // https://github.com/facebook/jest/issues/2713 setBeforeAllError(e) @@ -172,11 +173,12 @@ afterAll(async () => { function startStaticServer(): Promise { // check if the test project has base config const configFile = resolve(rootDir, 'vite.config.js') - let config: UserConfig + let config: UserConfig | undefined try { config = require(configFile) } catch (e) {} - const base = (config?.base || '/') === '/' ? '' : config.base + // fallback internal base to '' + const base = (config?.base ?? '/') === '/' ? '' : config?.base ?? '' // @ts-ignore if (config && config.__test__) { @@ -219,10 +221,10 @@ export async function notifyRebuildComplete( watcher: RollupWatcher ): Promise { let callback: (event: RollupWatcherEvent) => void - await new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { callback = (event) => { if (event.code === 'END') { - resolve(true) + resolve() } } watcher.on('event', callback) diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 6a32b899cb43ab..5c70fcc7f15823 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -8,6 +8,6 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "types": ["node"] + "types": ["node", "jest"] } } From a9a1ae2db6a81a2fd31db370b58686e442047d9e Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 15 Feb 2022 17:17:28 +0100 Subject: [PATCH 003/167] fix: revert update dotenv-expand #6703, fix #6858 (#6934) --- packages/vite/package.json | 2 +- packages/vite/src/node/config.ts | 2 +- pnpm-lock.yaml | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/vite/package.json b/packages/vite/package.json index 94029dc45cc008..728f6e00b84c7f 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -87,7 +87,7 @@ "cross-spawn": "^7.0.3", "debug": "^4.3.3", "dotenv": "^14.3.2", - "dotenv-expand": "^6.0.1", + "dotenv-expand": "^5.1.0", "es-module-lexer": "^0.9.3", "estree-walker": "^2.0.2", "etag": "^1.8.1", diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index f73f4fb8662d6b..2a607dd6ba9948 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -21,7 +21,7 @@ import { resolvePlugins } from './plugins' import colors from 'picocolors' import type { ESBuildOptions } from './plugins/esbuild' import dotenv from 'dotenv' -import { expand as dotenvExpand } from 'dotenv-expand' +import dotenvExpand from 'dotenv-expand' import type { Alias, AliasOptions } from 'types/alias' import { CLIENT_ENTRY, ENV_ENTRY, DEFAULT_ASSETS_RE } from './constants' import type { InternalResolveOptions, ResolveOptions } from './plugins/resolve' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab4083cb6a7635..418cf16f0eb6b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -770,7 +770,7 @@ importers: cross-spawn: ^7.0.3 debug: ^4.3.3 dotenv: ^14.3.2 - dotenv-expand: ^6.0.1 + dotenv-expand: ^5.1.0 es-module-lexer: ^0.9.3 esbuild: ^0.14.14 estree-walker: ^2.0.2 @@ -848,7 +848,7 @@ importers: cross-spawn: 7.0.3 debug: 4.3.3 dotenv: 14.3.2 - dotenv-expand: 6.0.1 + dotenv-expand: 5.1.0 es-module-lexer: 0.9.3 estree-walker: 2.0.2 etag: 1.8.1 @@ -4212,9 +4212,8 @@ packages: is-obj: 2.0.0 dev: true - /dotenv-expand/6.0.1: - resolution: {integrity: sha512-GNHcCOyRKLCXWnH3L/+sJ04PQxxgTOZDCPuQQnqkqPMGIilyoxHZ2JUNmh2VWKCfzVKH/AZsqcbuSYlDDVb/xw==} - engines: {node: '>=12'} + /dotenv-expand/5.1.0: + resolution: {integrity: sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==} dev: true /dotenv/14.3.2: From ac9652b0fc9aa947da4a62ff9553e23aee1dee8f Mon Sep 17 00:00:00 2001 From: patak-dev Date: Tue, 15 Feb 2022 18:07:13 +0100 Subject: [PATCH 004/167] release: v2.8.3 --- packages/vite/CHANGELOG.md | 9 +++++++++ packages/vite/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 13226de36642eb..fb262e6e13e783 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,12 @@ +## [2.8.3](https://github.com/vitejs/vite/compare/v2.8.2...v2.8.3) (2022-02-15) + + +### Bug Fixes + +* revert update dotenv-expand [#6703](https://github.com/vitejs/vite/issues/6703), fix [#6858](https://github.com/vitejs/vite/issues/6858) ([#6934](https://github.com/vitejs/vite/issues/6934)) ([a9a1ae2](https://github.com/vitejs/vite/commit/a9a1ae2db6a81a2fd31db370b58686e442047d9e)) + + + ## [2.8.2](https://github.com/vitejs/vite/compare/v2.8.1...v2.8.2) (2022-02-14) diff --git a/packages/vite/package.json b/packages/vite/package.json index 728f6e00b84c7f..0eff7b535822df 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.8.2", + "version": "2.8.3", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From 3f27d58036bfe4149e563a105c08c2d4771db288 Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 15 Feb 2022 22:33:41 +0100 Subject: [PATCH 005/167] chore(deps): avoid updating dotenv-expand to v6+ (#6936) --- .github/renovate.json5 | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 763dfcfc467d9d..06fe0e7ea2aaff 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -28,6 +28,7 @@ "react-router", // `react-router:v6.0.0+` has breaking changes "react-router-dom", // `react-router-dom:v6.0.0+` has breaking changes "source-map", // `source-map:v0.7.0+` needs more investigation + "dotenv-expand", // `dotenv-expand:6.0.0+` has breaking changes (#6858) // ESM Only => https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-move-my-commonjs-project-to-esm "node-fetch", From e2349569cf96e506e0d5fff1d043727a77fdad70 Mon Sep 17 00:00:00 2001 From: ocavue Date: Wed, 16 Feb 2022 21:20:45 +0800 Subject: [PATCH 006/167] docs: add backticks (#6945) --- docs/config/index.md | 2 +- packages/vite/src/node/config.ts | 2 +- packages/vite/src/node/optimizer/index.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index ba84c49b2f5820..d4ee7a96a6fa67 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -923,7 +923,7 @@ export default defineConfig({ - **Type:** `string | string[]` - By default, Vite will crawl your index.html to detect dependencies that need to be pre-bundled. If build.rollupOptions.input is specified, Vite will crawl those entry points instead. + By default, Vite will crawl your `index.html` to detect dependencies that need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite will crawl those entry points instead. If neither of these fit your needs, you can specify custom entries using this option - the value should be a [fast-glob pattern](https://github.com/mrmlnc/fast-glob#basic-syntax) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 2a607dd6ba9948..fbda8d5166cb1b 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -92,7 +92,7 @@ export interface UserConfig { * the performance. You can use `--force` flag or manually delete the directory * to regenerate the cache files. The value can be either an absolute file * system path or a path relative to . - * Default to `.vite` when no package.json is detected. + * Default to `.vite` when no `package.json` is detected. * @default 'node_modules/.vite' */ cacheDir?: string diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 6102e832841a89..c13a26c63b3c1c 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -30,8 +30,8 @@ export type ExportsData = ReturnType & { export interface DepOptimizationOptions { /** - * By default, Vite will crawl your index.html to detect dependencies that - * need to be pre-bundled. If build.rollupOptions.input is specified, Vite + * By default, Vite will crawl your `index.html` to detect dependencies that + * need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite * will crawl those entry points instead. * * If neither of these fit your needs, you can specify custom entries using From 4120908c518c8a89354aa93ffd6ebf5436123134 Mon Sep 17 00:00:00 2001 From: yoho <907415276@qq.com> Date: Thu, 17 Feb 2022 21:14:06 +0800 Subject: [PATCH 007/167] docs: import.meta.glob support ?raw (#6953) Co-authored-by: ygj6 <7699524+ygj6@users.noreply.github.com> --- docs/guide/features.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/guide/features.md b/docs/guide/features.md index da8e3b1de092b2..c7fd2424b53cb1 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -298,6 +298,22 @@ const modules = { } ``` +`import.meta.glob` and `import.meta.globEager` also support importing files as strings, similar to [Importing Asset as String](https://vitejs.dev/guide/assets.html#importing-asset-as-string). Here, we use the [Import Assertions](https://github.com/tc39/proposal-import-assertions#synopsis) syntax to import. + +```js +const modules = import.meta.glob('./dir/*.js', { assert: { type: 'raw' } }) +``` + +The above will be transformed into the following: + +```js +// code produced by vite +const modules = { + './dir/foo.js': '{\n "msg": "foo"\n}\n', + './dir/bar.js': '{\n "msg": "bar"\n}\n' +} +``` + Note that: - This is a Vite-only feature and is not a web or ES standard. From 08cf4e106534481fd8eff2e6e4a986270c28f894 Mon Sep 17 00:00:00 2001 From: Sepush Date: Thu, 17 Feb 2022 21:15:51 +0800 Subject: [PATCH 008/167] chore(ci): update issue-helper version (#6955) --- .github/workflows/issue-close-require.yml | 2 +- .github/workflows/issue-labeled.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/issue-close-require.yml b/.github/workflows/issue-close-require.yml index 02ac374b06c426..97f9dd3a449c3c 100644 --- a/.github/workflows/issue-close-require.yml +++ b/.github/workflows/issue-close-require.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: need reproduction - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "close-issues" token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/issue-labeled.yml b/.github/workflows/issue-labeled.yml index a63021952fd73d..b6f3919dfa63a2 100644 --- a/.github/workflows/issue-labeled.yml +++ b/.github/workflows/issue-labeled.yml @@ -10,7 +10,7 @@ jobs: steps: - name: contribution welcome if: github.event.label.name == 'contribution welcome' || github.event.label.name == 'help wanted' - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "create-comment, remove-labels" token: ${{ secrets.GITHUB_TOKEN }} @@ -21,7 +21,7 @@ jobs: - name: remove pending if: github.event.label.name == 'enhancement' || github.event.label.name == 'bug' || (contains(github.event.label.name, 'pending triage') == false && startsWith(github.event.label.name, 'bug:') == true) - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "remove-labels" token: ${{ secrets.GITHUB_TOKEN }} @@ -30,7 +30,7 @@ jobs: - name: need reproduction if: github.event.label.name == 'need reproduction' - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "create-comment, remove-labels" token: ${{ secrets.GITHUB_TOKEN }} From 3f3f4737d5242547fb83f8d2522ba91cc1d96fb0 Mon Sep 17 00:00:00 2001 From: Nurettin Kaya Date: Thu, 17 Feb 2022 13:24:44 -0800 Subject: [PATCH 009/167] fix: normalize postcss dependency messages (#6959) --- .../tailwind/__test__/tailwind.spec.ts | 22 ++++++++++++++++++- packages/playground/tailwind/src/App.vue | 2 +- .../playground/tailwind/tailwind.config.js | 7 +++++- packages/vite/src/node/plugins/css.ts | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/playground/tailwind/__test__/tailwind.spec.ts b/packages/playground/tailwind/__test__/tailwind.spec.ts index 105eb245bf207e..47f6b7ccf49037 100644 --- a/packages/playground/tailwind/__test__/tailwind.spec.ts +++ b/packages/playground/tailwind/__test__/tailwind.spec.ts @@ -5,7 +5,7 @@ test('should render', async () => { }) if (!isBuild) { - test('regenerate CSS and HMR', async () => { + test('regenerate CSS and HMR (glob pattern)', async () => { browserLogs.length = 0 const el = await page.$('#pagetitle') const el2 = await page.$('#helloroot') @@ -37,4 +37,24 @@ if (!isBuild) { browserLogs.length = 0 }) + + test('regenerate CSS and HMR (relative path)', async () => { + browserLogs.length = 0 + const el = await page.$('h1') + + expect(await getColor(el)).toBe('black') + + editFile('src/App.vue', (code) => + code.replace('text-black', 'text-[rgb(11,22,33)]') + ) + + await untilUpdated(() => getColor(el), 'rgb(11, 22, 33)') + + expect(browserLogs).toMatchObject([ + '[vite] css hot updated: /index.css', + '[vite] hot updated: /src/App.vue' + ]) + + browserLogs.length = 0 + }) } diff --git a/packages/playground/tailwind/src/App.vue b/packages/playground/tailwind/src/App.vue index b032d5e0db77e3..25835fc414a06f 100644 --- a/packages/playground/tailwind/src/App.vue +++ b/packages/playground/tailwind/src/App.vue @@ -1,6 +1,6 @@