From 5c1ee5abf987e25bd39d5af8013ed907a33d4d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 27 Apr 2022 17:23:48 +0900 Subject: [PATCH 001/114] docs: `server.origin` config trailing slash (fix #6622) (#7865) --- docs/config/index.md | 2 +- packages/vite/src/node/config.ts | 2 +- packages/vite/src/node/server/index.ts | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index bab7df7a144987..aaa5dcd47ad361 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -706,7 +706,7 @@ Defines the origin of the generated asset URLs during development. ```js export default defineConfig({ server: { - origin: 'http://127.0.0.1:8080/' + origin: 'http://127.0.0.1:8080' } }) ``` diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index d242ac632c220e..27a107f3e2098c 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -461,7 +461,7 @@ export async function resolveConfig( ) : '' - const server = resolveServerOptions(resolvedRoot, config.server) + const server = resolveServerOptions(resolvedRoot, config.server, logger) const optimizeDeps = config.optimizeDeps || {} diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 99aefea6de292a..29f57adeb5c752 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -56,6 +56,7 @@ import type { OptimizedDeps } from '../optimizer' import { resolveHostname } from '../utils' import { searchForWorkspaceRoot } from './searchRoot' import { CLIENT_DIR } from '../constants' +import type { Logger } from '../logger' import { printCommonServerUrls } from '../logger' import { performance } from 'perf_hooks' import { invalidatePackageData } from '../packages' @@ -92,6 +93,8 @@ export interface ServerOptions extends CommonServerOptions { fs?: FileSystemServeOptions /** * Origin for the generated asset URLs. + * + * @example `http://127.0.0.1:8080` */ origin?: string /** @@ -701,7 +704,8 @@ function resolvedAllowDir(root: string, dir: string): string { export function resolveServerOptions( root: string, - raw?: ServerOptions + raw: ServerOptions | undefined, + logger: Logger ): ResolvedServerOptions { const server: ResolvedServerOptions = { preTransformRequests: true, @@ -727,6 +731,18 @@ export function resolveServerOptions( allow: allowDirs, deny } + + if (server.origin?.endsWith('/')) { + server.origin = server.origin.slice(0, -1) + logger.warn( + colors.yellow( + `${colors.bold('(!)')} server.origin should not end with "/". Using "${ + server.origin + }" instead.` + ) + ) + } + return server } From e48827f58bac0af2a564cacd8213195a9015f8a3 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 27 Apr 2022 20:16:58 +0800 Subject: [PATCH 002/114] fix(css): clean comments before hoist at rules (#7924) --- .../src/node/__tests__/plugins/css.spec.ts | 48 ++++++++++++++++++- packages/vite/src/node/cleanString.ts | 14 ++++-- packages/vite/src/node/plugins/css.ts | 37 +++++++------- 3 files changed, 78 insertions(+), 21 deletions(-) diff --git a/packages/vite/src/node/__tests__/plugins/css.spec.ts b/packages/vite/src/node/__tests__/plugins/css.spec.ts index 078cec2e0f3d77..e0d1f04a6510b2 100644 --- a/packages/vite/src/node/__tests__/plugins/css.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/css.spec.ts @@ -155,10 +155,54 @@ describe('hoist @ rules', () => { }) test('hoist @import and @charset', async () => { - const css = `.foo{color:red;}@import "bla";@charset "utf-8";.bar{color:grren;}@import "baz";` + const css = `.foo{color:red;}@import "bla";@charset "utf-8";.bar{color:green;}@import "baz";` const result = await hoistAtRules(css) expect(result).toBe( - `@charset "utf-8";@import "bla";@import "baz";.foo{color:red;}.bar{color:grren;}` + `@charset "utf-8";@import "bla";@import "baz";.foo{color:red;}.bar{color:green;}` + ) + }) + + test('dont hoist @import in comments', async () => { + const css = `.foo{color:red;}/* @import "bla"; */@import "bar";` + const result = await hoistAtRules(css) + expect(result).toBe(`@import "bar";.foo{color:red;}/* @import "bla"; */`) + }) + + test('dont hoist @charset in comments', async () => { + const css = `.foo{color:red;}/* @charset "utf-8"; */@charset "utf-8";` + const result = await hoistAtRules(css) + expect(result).toBe( + `@charset "utf-8";.foo{color:red;}/* @charset "utf-8"; */` + ) + }) + + test('dont hoist @import and @charset in comments', async () => { + const css = ` + .foo{color:red;} + /* + @import "bla"; + */ + @charset "utf-8"; + /* + @charset "utf-8"; + @import "bar"; + */ + @import "baz"; + ` + const result = await hoistAtRules(css) + expect(result).toBe( + `@charset "utf-8";@import "baz"; + .foo{color:red;} + /* + @import "bla"; + */ + + /* + @charset "utf-8"; + @import "bar"; + */ + + ` ) }) }) diff --git a/packages/vite/src/node/cleanString.ts b/packages/vite/src/node/cleanString.ts index 3d623dce79c0d3..9b9ef656f4e017 100644 --- a/packages/vite/src/node/cleanString.ts +++ b/packages/vite/src/node/cleanString.ts @@ -1,10 +1,14 @@ import type { RollupError } from 'rollup' +import { multilineCommentsRE, singlelineCommentsRE } from './utils' + // bank on the non-overlapping nature of regex matches and combine all filters into one giant regex // /`([^`\$\{\}]|\$\{(`|\g<1>)*\})*`/g can match nested string template // but js not support match expression(\g<0>). so clean string template(`...`) in other ways. -const stringsRE = /"([^"\r\n]|(?<=\\)")*"|'([^'\r\n]|(?<=\\)')*'/.source -const commentsRE = /\/\*(.|[\r\n])*?\*\/|\/\/.*/.source -const cleanerRE = new RegExp(`${stringsRE}|${commentsRE}`, 'g') +const stringsRE = /"([^"\r\n]|(?<=\\)")*"|'([^'\r\n]|(?<=\\)')*'/g +const cleanerRE = new RegExp( + `${stringsRE.source}|${multilineCommentsRE.source}|${singlelineCommentsRE.source}`, + 'g' +) const blankReplacer = (s: string) => ' '.repeat(s.length) const stringBlankReplacer = (s: string) => @@ -26,6 +30,10 @@ export function emptyString(raw: string): string { return res } +export function emptyCssComments(raw: string) { + return raw.replace(multilineCommentsRE, blankReplacer) +} + const enum LexerState { // template string inTemplateString, diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 83e18aabecdb33..fef1b6cb7ac515 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -48,6 +48,7 @@ import { transform, formatMessages } from 'esbuild' import { addToHTMLProxyTransformResult } from './html' import { injectSourcesContent, getCodeWithSourcemap } from '../server/sourcemap' import type { RawSourceMap } from '@ampproject/remapping' +import { emptyCssComments } from '../cleanString' // const debug = createDebugger('vite:css') @@ -1117,30 +1118,34 @@ async function minifyCSS(css: string, config: ResolvedConfig) { export async function hoistAtRules(css: string) { const s = new MagicString(css) + const cleanCss = emptyCssComments(css) + let match: RegExpExecArray | null + // #1845 // CSS @import can only appear at top of the file. We need to hoist all @import // to top when multiple files are concatenated. // match until semicolon that's not in quotes - s.replace( - /@import\s*(?:url\([^\)]*\)|"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'|[^;]*).*?;/gm, - (match) => { - s.appendLeft(0, match) - return '' - } - ) + const atImportRE = + /@import\s*(?:url\([^\)]*\)|"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'|[^;]*).*?;/gm + while ((match = atImportRE.exec(cleanCss))) { + s.remove(match.index, match.index + match[0].length) + // Use `appendLeft` instead of `prepend` to preserve original @import order + s.appendLeft(0, match[0]) + } + // #6333 // CSS @charset must be the top-first in the file, hoist the first to top + const atCharsetRE = + /@charset\s*(?:"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'|[^;]*).*?;/gm let foundCharset = false - s.replace( - /@charset\s*(?:"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'|[^;]*).*?;/gm, - (match) => { - if (!foundCharset) { - s.prepend(match) - foundCharset = true - } - return '' + while ((match = atCharsetRE.exec(cleanCss))) { + s.remove(match.index, match.index + match[0].length) + if (!foundCharset) { + s.prepend(match[0]) + foundCharset = true } - ) + } + return s.toString() } From 206e1f2cd48b86396f57338ad494da3e1939b647 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 28 Apr 2022 01:06:06 +0800 Subject: [PATCH 003/114] docs: clarify loadEnv (#7872) --- docs/config/index.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index aaa5dcd47ad361..7f051399d1a1e7 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -94,7 +94,7 @@ If the config needs to call async function, it can export a async function inste export default defineConfig(async ({ command, mode }) => { const data = await asyncFunction() return { - // build specific config + // vite config } }) ``` @@ -109,10 +109,14 @@ Note that Vite doesn't load `.env` files by default as the files to load can onl import { defineConfig, loadEnv } from 'vite' export default defineConfig(({ command, mode }) => { - // Load env file based on `mode` in the current working directory - const env = loadEnv(mode, process.cwd()) + // Load env file based on `mode` in the current working directory. + // Set the third parameter to '' to load all env regardless of the `VITE_` prefix. + const env = loadEnv(mode, process.cwd(), '') return { - // build specific config + // vite config + define: { + __APP_ENV__: env.APP_ENV + } } }) ``` From 50672e4f8bc6d23cef735b922e8e0439acb5fe27 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 28 Apr 2022 01:20:53 +0800 Subject: [PATCH 004/114] fix: use NODE_ENV in optimizer (#7673) --- packages/playground/optimize-deps/.env | 1 + .../optimize-deps/__tests__/optimize-deps.spec.ts | 4 ++++ packages/playground/optimize-deps/dep-node-env/index.js | 1 + packages/playground/optimize-deps/dep-node-env/package.json | 5 +++++ packages/playground/optimize-deps/index.html | 6 ++++++ packages/playground/optimize-deps/package.json | 1 + packages/vite/src/node/optimizer/index.ts | 4 ++-- pnpm-lock.yaml | 5 +++++ 8 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 packages/playground/optimize-deps/.env create mode 100644 packages/playground/optimize-deps/dep-node-env/index.js create mode 100644 packages/playground/optimize-deps/dep-node-env/package.json diff --git a/packages/playground/optimize-deps/.env b/packages/playground/optimize-deps/.env new file mode 100644 index 00000000000000..995fca4af2ee24 --- /dev/null +++ b/packages/playground/optimize-deps/.env @@ -0,0 +1 @@ +NODE_ENV=production \ No newline at end of file diff --git a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts index d95a6d984cd9aa..e832408370969a 100644 --- a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -62,6 +62,10 @@ test('import * from optimized dep', async () => { expect(await page.textContent('.import-star')).toMatch(`[success]`) }) +test('import from dep with process.env.NODE_ENV', async () => { + expect(await page.textContent('.node-env')).toMatch(`prod`) +}) + test('import from dep with .notjs files', async () => { expect(await page.textContent('.not-js')).toMatch(`[success]`) }) diff --git a/packages/playground/optimize-deps/dep-node-env/index.js b/packages/playground/optimize-deps/dep-node-env/index.js new file mode 100644 index 00000000000000..8548c37894539f --- /dev/null +++ b/packages/playground/optimize-deps/dep-node-env/index.js @@ -0,0 +1 @@ +export const env = process.env.NODE_ENV === 'production' ? 'prod' : 'dev' diff --git a/packages/playground/optimize-deps/dep-node-env/package.json b/packages/playground/optimize-deps/dep-node-env/package.json new file mode 100644 index 00000000000000..59a00fb153c522 --- /dev/null +++ b/packages/playground/optimize-deps/dep-node-env/package.json @@ -0,0 +1,5 @@ +{ + "name": "dep-node-env", + "private": true, + "version": "1.0.0" +} diff --git a/packages/playground/optimize-deps/index.html b/packages/playground/optimize-deps/index.html index 2be896d00acba9..521d54379863d9 100644 --- a/packages/playground/optimize-deps/index.html +++ b/packages/playground/optimize-deps/index.html @@ -38,6 +38,9 @@

Optimizing force included dep even when it's linked

import * as ...

+

Import from dependency with process.env.NODE_ENV

+
+

Import from dependency with .notjs files

@@ -88,6 +91,9 @@

Reused variable names

text('.import-star', `[success] ${keys.join(', ')}`) } + import { env } from 'dep-node-env' + text('.node-env', env) + import { notjsValue } from 'dep-not-js' text('.not-js', notjsValue) diff --git a/packages/playground/optimize-deps/package.json b/packages/playground/optimize-deps/package.json index 2752e691da6fb2..904db5fc65f0ad 100644 --- a/packages/playground/optimize-deps/package.json +++ b/packages/playground/optimize-deps/package.json @@ -17,6 +17,7 @@ "dep-esbuild-plugin-transform": "file:./dep-esbuild-plugin-transform", "dep-linked": "link:./dep-linked", "dep-linked-include": "link:./dep-linked-include", + "dep-node-env": "file:./dep-node-env", "dep-not-js": "file:./dep-not-js", "dep-with-dynamic-import": "file:./dep-with-dynamic-import", "lodash-es": "^4.17.21", diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 3828cb2fbce18b..4e4fb5a8c895ae 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -445,7 +445,7 @@ export async function runOptimizeDeps( } const define: Record = { - 'process.env.NODE_ENV': JSON.stringify(config.mode) + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || config.mode) } for (const key in config.define) { const value = config.define[key] @@ -790,7 +790,7 @@ export function getDepHash(config: ResolvedConfig): string { // only a subset of config options that can affect dep optimization content += JSON.stringify( { - mode: config.mode, + mode: process.env.NODE_ENV || config.mode, root: config.root, define: config.define, resolve: config.resolve, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad65e136bd1b56..a0ee11e84690b1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -317,6 +317,7 @@ importers: dep-esbuild-plugin-transform: file:./dep-esbuild-plugin-transform dep-linked: link:./dep-linked dep-linked-include: link:./dep-linked-include + dep-node-env: file:./dep-node-env dep-not-js: file:./dep-not-js dep-with-dynamic-import: file:./dep-with-dynamic-import lodash-es: ^4.17.21 @@ -336,6 +337,7 @@ importers: dep-esbuild-plugin-transform: link:dep-esbuild-plugin-transform dep-linked: link:dep-linked dep-linked-include: link:dep-linked-include + dep-node-env: link:dep-node-env dep-not-js: link:dep-not-js dep-with-dynamic-import: link:dep-with-dynamic-import lodash-es: 4.17.21 @@ -371,6 +373,9 @@ importers: dependencies: react: 17.0.2 + packages/playground/optimize-deps/dep-node-env: + specifiers: {} + packages/playground/optimize-deps/dep-not-js: specifiers: {} From 7f535aca8e8683506b2535c3256292abce7b0615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Thu, 28 Apr 2022 03:43:27 +0900 Subject: [PATCH 005/114] chore(css): catch postcss config error (fix #2793) (#7934) --- packages/vite/src/node/plugins/css.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index fef1b6cb7ac515..f310abc9bc7c56 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -942,14 +942,22 @@ async function resolvePostcssConfig( plugins: inlineOptions.plugins || [] } } else { + const searchPath = + typeof inlineOptions === 'string' ? inlineOptions : config.root try { - const searchPath = - typeof inlineOptions === 'string' ? inlineOptions : config.root // @ts-ignore result = await postcssrc({}, searchPath) } catch (e) { if (!/No PostCSS Config found/.test(e.message)) { - throw e + if (e instanceof Error) { + const { name, message, stack } = e + e.name = 'Failed to load PostCSS config' + e.message = `Failed to load PostCSS config (searchPath: ${searchPath}): [${name}] ${message}\n${stack}` + e.stack = '' // add stack to message to retain stack + throw e + } else { + throw new Error(`Failed to load PostCSS config: ${e}`) + } } result = null } From 274c10eb9e9451620981da808e143bc50b8c2a38 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 28 Apr 2022 13:45:55 +0800 Subject: [PATCH 006/114] fix(css): support postcss.config.ts (#7935) --- packages/playground/tailwind/package.json | 3 ++- .../tailwind/{postcss.config.js => postcss.config.ts} | 2 +- packages/vite/rollup.config.js | 5 +++++ pnpm-lock.yaml | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) rename packages/playground/tailwind/{postcss.config.js => postcss.config.ts} (85%) diff --git a/packages/playground/tailwind/package.json b/packages/playground/tailwind/package.json index ff79908d386e96..1feeb8dfb89e31 100644 --- a/packages/playground/tailwind/package.json +++ b/packages/playground/tailwind/package.json @@ -15,6 +15,7 @@ "vue-router": "^4.0.0" }, "devDependencies": { - "@vitejs/plugin-vue": "workspace:*" + "@vitejs/plugin-vue": "workspace:*", + "ts-node": "^10.4.0" } } diff --git a/packages/playground/tailwind/postcss.config.js b/packages/playground/tailwind/postcss.config.ts similarity index 85% rename from packages/playground/tailwind/postcss.config.js rename to packages/playground/tailwind/postcss.config.ts index b73493f7f96fae..381d8cbd107f81 100644 --- a/packages/playground/tailwind/postcss.config.js +++ b/packages/playground/tailwind/postcss.config.ts @@ -1,4 +1,4 @@ -// postcss.config.js +// postcss.config.ts module.exports = { plugins: { tailwindcss: { config: __dirname + '/tailwind.config.js' }, diff --git a/packages/vite/rollup.config.js b/packages/vite/rollup.config.js index 31ab56cd07e02e..93f4f33bdec398 100644 --- a/packages/vite/rollup.config.js +++ b/packages/vite/rollup.config.js @@ -171,6 +171,11 @@ const createNodeConfig = (isProduction) => { 'lilconfig/dist/index.js': { pattern: /: require,/g, replacement: `: eval('require'),` + }, + // postcss-load-config calls require after register ts-node + 'postcss-load-config/src/index.js': { + src: `require(configFile)`, + replacement: `eval('require')(configFile)` } }), commonjs({ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a0ee11e84690b1..0f0711811935b6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -661,6 +661,7 @@ importers: '@vitejs/plugin-vue': workspace:* autoprefixer: ^10.4.0 tailwindcss: ^2.2.19 + ts-node: ^10.4.0 vue: ^3.2.25 vue-router: ^4.0.0 dependencies: @@ -670,6 +671,7 @@ importers: vue-router: 4.0.12_vue@3.2.26 devDependencies: '@vitejs/plugin-vue': link:../../plugin-vue + ts-node: 10.4.0_233d9fcfccc8abc8f146a08357d842da packages/playground/tailwind-sourcemap: specifiers: From 71b1443aa56c1e28959eaa40dc8a5fed652480c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sat, 30 Apr 2022 03:23:51 +0900 Subject: [PATCH 007/114] chore: add core.symlinks description to CONTRIBUTING.md (#7962) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c7020c97a84c80..bed97a0d7d4300 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -69,7 +69,7 @@ And re-run `pnpm install` to link the package. Each package under `packages/playground/` contains a `__tests__` directory. The tests are run using [Jest](https://jestjs.io/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `jest.config.js` and `scripts/jest*` files. -Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). +Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). Also you may want to [set git `core.symlinks` to `true` to solve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242). Each test can be run under either dev server mode or build mode. From f7d2d713befe916c4d84b5e1705e20386948a61f Mon Sep 17 00:00:00 2001 From: patak Date: Sat, 30 Apr 2022 06:13:30 +0200 Subject: [PATCH 008/114] fix: inject esbuild helpers in IIFE and UMD wrappers (#7948) --- packages/playground/lib/__tests__/lib.spec.ts | 12 +++++++++ packages/playground/lib/src/main.js | 3 +++ packages/vite/src/node/plugins/esbuild.ts | 25 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/packages/playground/lib/__tests__/lib.spec.ts b/packages/playground/lib/__tests__/lib.spec.ts index 382fb16510ce6f..f1e93e90d8357b 100644 --- a/packages/playground/lib/__tests__/lib.spec.ts +++ b/packages/playground/lib/__tests__/lib.spec.ts @@ -9,10 +9,22 @@ if (isBuild) { test('umd', async () => { expect(await page.textContent('.umd')).toBe('It works') + const code = fs.readFileSync( + path.join(testDir, 'dist/my-lib-custom-filename.umd.js'), + 'utf-8' + ) + // esbuild helpers are injected inside of the UMD wrapper + expect(code).toMatch(/^\(function\(/) }) test('iife', async () => { expect(await page.textContent('.iife')).toBe('It works') + const code = fs.readFileSync( + path.join(testDir, 'dist/my-lib-custom-filename.iife.js'), + 'utf-8' + ) + // esbuild helpers are injected inside of the IIFE wrapper + expect(code).toMatch(/^var MyLib=function\(\){"use strict";/) }) test('Library mode does not include `preload`', async () => { diff --git a/packages/playground/lib/src/main.js b/packages/playground/lib/src/main.js index 2422edf5829a0e..cb2fb3b842dc4f 100644 --- a/packages/playground/lib/src/main.js +++ b/packages/playground/lib/src/main.js @@ -1,3 +1,6 @@ export default function myLib(sel) { + // Force esbuild spread helpers (https://github.com/evanw/esbuild/issues/951) + console.log({ ...'foo' }) + document.querySelector(sel).textContent = 'It works' } diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 9e8bae24424d76..bc4a1f780a54d5 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -26,6 +26,11 @@ import { searchForWorkspaceRoot } from '..' const debug = createDebugger('vite:esbuild') +const INJECT_HELPERS_IIFE_RE = + /(.*)(var [^\s]+=function\(.*\){"use strict";)(.*)/ +const INJECT_HELPERS_UMD_RE = + /(.*)(\(function\(.*\){.+amd.+function\(.*\){"use strict";)(.*)/ + let server: ViteDevServer export interface ESBuildOptions extends TransformOptions { @@ -254,6 +259,26 @@ export const buildEsbuildPlugin = (config: ResolvedConfig): Plugin => { } : undefined) }) + + if (config.build.lib) { + // #7188, esbuild adds helpers out of the UMD and IIFE wrappers, and the + // names are minified potentially causing collision with other globals. + // We use a regex to inject the helpers inside the wrappers. + // We don't need to create a MagicString here because both the helpers and + // the headers don't modify the sourcemap + const injectHelpers = + opts.format === 'umd' + ? INJECT_HELPERS_UMD_RE + : opts.format === 'iife' + ? INJECT_HELPERS_IIFE_RE + : undefined + if (injectHelpers) { + res.code = res.code.replace( + injectHelpers, + (_, helpers, header, rest) => header + helpers + rest + ) + } + } return res } } From 2b4aab0bf45e9fb67aa8f5453a3db6beb7519c9f Mon Sep 17 00:00:00 2001 From: Tedy <1197633750@qq.com> Date: Sat, 30 Apr 2022 12:14:16 +0800 Subject: [PATCH 009/114] chore: fix typo (#7967) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bed97a0d7d4300..621f8de145835f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,7 +42,7 @@ Some errors are masked and hidden away because of the layers of abstraction and 1. In the sources panel in the right column, click the play button to resume execution and allow the tests to run which will open a Chromium instance. -1. Focusing the Chomium instance, you can open the browser devtools and inspect the console there to find the underlying problems. +1. Focusing the Chromium instance, you can open the browser devtools and inspect the console there to find the underlying problems. 1. To close everything, just stop the test process back in your terminal. From a9fa60b37e373adbf240b184fa801fa19aacfcf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sat, 30 Apr 2022 13:15:45 +0900 Subject: [PATCH 010/114] chore: bump vue in ssr-vue (#7965) --- packages/playground/ssr-vue/package.json | 2 +- pnpm-lock.yaml | 37 ++++++++++++++---------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/playground/ssr-vue/package.json b/packages/playground/ssr-vue/package.json index 4a385336a97603..02aa3b89bc0dbb 100644 --- a/packages/playground/ssr-vue/package.json +++ b/packages/playground/ssr-vue/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "example-external-component": "file:example-external-component", - "vue": "^3.2.25", + "vue": "^3.2.33", "vue-router": "^4.0.0", "vuex": "^4.0.2" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0f0711811935b6..73be476b1c911b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -622,14 +622,14 @@ importers: example-external-component: file:example-external-component express: ^4.17.1 serve-static: ^1.14.1 - vue: ^3.2.25 + vue: ^3.2.33 vue-router: ^4.0.0 vuex: ^4.0.2 dependencies: example-external-component: link:example-external-component - vue: 3.2.26 - vue-router: 4.0.12_vue@3.2.26 - vuex: 4.0.2_vue@3.2.26 + vue: 3.2.33 + vue-router: 4.0.12_vue@3.2.33 + vuex: 4.0.2_vue@3.2.33 devDependencies: '@vitejs/plugin-vue': link:../../plugin-vue '@vitejs/plugin-vue-jsx': link:../../plugin-vue-jsx @@ -2893,7 +2893,6 @@ packages: '@vue/shared': 3.2.33 estree-walker: 2.0.2 source-map: 0.6.1 - dev: true /@vue/compiler-dom/3.2.26: resolution: {integrity: sha512-smBfaOW6mQDxcT3p9TKT6mE22vjxjJL50GFVJiI0chXYGU/xzC05QRGrW3HHVuJrmLTLx5zBhsZ2dIATERbarg==} @@ -2912,7 +2911,6 @@ packages: dependencies: '@vue/compiler-core': 3.2.33 '@vue/shared': 3.2.33 - dev: true /@vue/compiler-sfc/3.2.26: resolution: {integrity: sha512-ePpnfktV90UcLdsDQUh2JdiTuhV0Skv2iYXxfNMOK/F3Q+2BO0AulcVcfoksOpTJGmhhfosWfMyEaEf0UaWpIw==} @@ -2955,7 +2953,6 @@ packages: magic-string: 0.25.7 postcss: 8.4.12 source-map: 0.6.1 - dev: true /@vue/compiler-ssr/3.2.26: resolution: {integrity: sha512-2mywLX0ODc4Zn8qBoA2PDCsLEZfpUGZcyoFRLSOjyGGK6wDy2/5kyDOWtf0S0UvtoyVq95OTSGIALjZ4k2q/ag==} @@ -2974,7 +2971,6 @@ packages: dependencies: '@vue/compiler-dom': 3.2.33 '@vue/shared': 3.2.33 - dev: true /@vue/devtools-api/6.0.0-beta.21.1: resolution: {integrity: sha512-FqC4s3pm35qGVeXRGOjTsRzlkJjrBLriDS9YXbflHLsfA9FrcKzIyWnLXoNm+/7930E8rRakXuAc2QkC50swAw==} @@ -3006,7 +3002,6 @@ packages: '@vue/shared': 3.2.33 estree-walker: 2.0.2 magic-string: 0.25.7 - dev: true /@vue/reactivity/3.2.26: resolution: {integrity: sha512-h38bxCZLW6oFJVDlCcAiUKFnXI8xP8d+eO0pcDxx+7dQfSPje2AO6M9S9QO6MrxQB7fGP0DH0dYQ8ksf6hrXKQ==} @@ -3022,7 +3017,6 @@ packages: resolution: {integrity: sha512-62Sq0mp9/0bLmDuxuLD5CIaMG2susFAGARLuZ/5jkU1FCf9EDbwUuF+BO8Ub3Rbodx0ziIecM/NsmyjardBxfQ==} dependencies: '@vue/shared': 3.2.33 - dev: true /@vue/runtime-core/3.2.26: resolution: {integrity: sha512-BcYi7qZ9Nn+CJDJrHQ6Zsmxei2hDW0L6AB4vPvUQGBm2fZyC0GXd/4nVbyA2ubmuhctD5RbYY8L+5GUJszv9mQ==} @@ -3041,7 +3035,6 @@ packages: dependencies: '@vue/reactivity': 3.2.33 '@vue/shared': 3.2.33 - dev: true /@vue/runtime-dom/3.2.26: resolution: {integrity: sha512-dY56UIiZI+gjc4e8JQBwAifljyexfVCkIAu/WX8snh8vSOt/gMSEGwPRcl2UpYpBYeyExV8WCbgvwWRNt9cHhQ==} @@ -3063,7 +3056,6 @@ packages: '@vue/runtime-core': 3.2.33 '@vue/shared': 3.2.33 csstype: 2.6.19 - dev: true /@vue/server-renderer/3.2.26_vue@3.2.26: resolution: {integrity: sha512-Jp5SggDUvvUYSBIvYEhy76t4nr1vapY/FIFloWmQzn7UxqaHrrBpbxrqPcTrSgGrcaglj0VBp22BKJNre4aA1w==} @@ -3091,7 +3083,6 @@ packages: '@vue/compiler-ssr': 3.2.33 '@vue/shared': 3.2.33 vue: 3.2.33 - dev: true /@vue/shared/3.2.26: resolution: {integrity: sha512-vPV6Cq+NIWbH5pZu+V+2QHE9y1qfuTq49uNWw4f7FDEeZaDU2H2cx5jcUZOAKW7qTrUS4k6qZPbMy1x4N96nbA==} @@ -3101,7 +3092,6 @@ packages: /@vue/shared/3.2.33: resolution: {integrity: sha512-UBc1Pg1T3yZ97vsA2ueER0F6GbJebLHYlEi4ou1H5YL4KWvMOOWwpYo9/QpWq93wxKG6Wo13IY74Hcn/f7c7Bg==} - dev: true /@wessberg/stringutil/1.0.19: resolution: {integrity: sha512-9AZHVXWlpN8Cn9k5BC/O0Dzb9E9xfEMXzYrNunwvkUTvuK7xgQPVRZpLo+jWCOZ5r8oBa8NIrHuPEu1hzbb6bg==} @@ -9537,6 +9527,15 @@ packages: vue: 3.2.26 dev: false + /vue-router/4.0.12_vue@3.2.33: + resolution: {integrity: sha512-CPXvfqe+mZLB1kBWssssTiWg4EQERyqJZes7USiqfW9B5N2x+nHlnsM1D3b5CaJ6qgCvMmYJnz+G0iWjNCvXrg==} + peerDependencies: + vue: ^3.0.0 + dependencies: + '@vue/devtools-api': 6.0.0-beta.21.1 + vue: 3.2.33 + dev: false + /vue/3.2.26: resolution: {integrity: sha512-KD4lULmskL5cCsEkfhERVRIOEDrfEL9CwAsLYpzptOGjaGFNWo3BQ9g8MAb7RaIO71rmVOziZ/uEN/rHwcUIhg==} dependencies: @@ -9563,7 +9562,6 @@ packages: '@vue/runtime-dom': 3.2.33 '@vue/server-renderer': 3.2.33_vue@3.2.33 '@vue/shared': 3.2.33 - dev: true /vuex/4.0.2_vue@3.2.26: resolution: {integrity: sha512-M6r8uxELjZIK8kTKDGgZTYX/ahzblnzC4isU1tpmEuOIIKmV+TRdc+H4s8ds2NuZ7wpUTdGRzJRtoj+lI+pc0Q==} @@ -9574,6 +9572,15 @@ packages: vue: 3.2.26 dev: false + /vuex/4.0.2_vue@3.2.33: + resolution: {integrity: sha512-M6r8uxELjZIK8kTKDGgZTYX/ahzblnzC4isU1tpmEuOIIKmV+TRdc+H4s8ds2NuZ7wpUTdGRzJRtoj+lI+pc0Q==} + peerDependencies: + vue: ^3.0.2 + dependencies: + '@vue/devtools-api': 6.0.0-beta.21.1 + vue: 3.2.33 + dev: false + /w3c-hr-time/1.0.2: resolution: {integrity: sha512-z8P5DvDNjKDoFIHK7q8r8lackT6l+jo/Ye3HOle7l9nICP9lf1Ci25fy9vHd0JOWewkIFzXIEig3TdKT7JQ5fQ==} dependencies: From a30a5489ccac56ec668546af840984367c356a38 Mon Sep 17 00:00:00 2001 From: yoho Date: Sat, 30 Apr 2022 12:19:24 +0800 Subject: [PATCH 011/114] fix: inline style hmr, transform style code inplace (#7869) --- .../assets/__tests__/assets.spec.ts | 7 +- packages/playground/assets/index.html | 20 +++++- .../css-sourcemap/__tests__/serve.spec.ts | 62 ------------------ packages/playground/hmr/__tests__/hmr.spec.ts | 12 +++- packages/playground/hmr/icon.png | Bin 0 -> 3395 bytes packages/playground/hmr/index.html | 9 +++ packages/playground/ssr-html/index.html | 5 ++ packages/vite/src/node/plugins/css.ts | 9 ++- .../src/node/server/middlewares/indexHtml.ts | 41 ++++++++++-- 9 files changed, 91 insertions(+), 74 deletions(-) create mode 100644 packages/playground/hmr/icon.png diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index 75c0e57952db24..19dd52f71e114a 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -1,4 +1,3 @@ -import { createHash } from 'crypto' import { findAssetFile, getBg, @@ -296,6 +295,11 @@ describe('css and assets in css in build watch', () => { } }) +test('inline style test', async () => { + expect(await getBg('.inline-style')).toMatch(assetMatch) + expect(await getBg('.style-url-assets')).toMatch(assetMatch) +}) + if (!isBuild) { test('@import in html style tag hmr', async () => { await untilUpdated(() => getColor('.import-css'), 'rgb(0, 136, 255)') @@ -304,6 +308,7 @@ if (!isBuild) { (code) => code.replace('#0088ff', '#00ff88'), true ) + await page.waitForNavigation() await untilUpdated(() => getColor('.import-css'), 'rgb(0, 255, 136)') }) } diff --git a/packages/playground/assets/index.html b/packages/playground/assets/index.html index 6678a2da7c2106..99c2c2fe69ae70 100644 --- a/packages/playground/assets/index.html +++ b/packages/playground/assets/index.html @@ -207,7 +207,10 @@

url

background-size: 10px 10px; } -
+
inline style
use style class
@@ -235,6 +238,21 @@

import module css

+

style in svg

+ + + + + + + + diff --git a/packages/playground/css-sourcemap/__tests__/serve.spec.ts b/packages/playground/css-sourcemap/__tests__/serve.spec.ts index 11e33a78af8424..becd792e82293a 100644 --- a/packages/playground/css-sourcemap/__tests__/serve.spec.ts +++ b/packages/playground/css-sourcemap/__tests__/serve.spec.ts @@ -17,68 +17,6 @@ if (!isBuild) { throw new Error('Not found') } - test('inline css', async () => { - const css = await getStyleTagContentIncluding('.inline ') - const map = extractSourcemap(css) - expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { - "mappings": "AAGO;AACP,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACX,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACf,CAAC,CAAC,CAAC;", - "sources": Array [ - "/root/index.html", - ], - "sourcesContent": Array [ - " - - - - -
-

CSS Sourcemap

- -

<inline>

- -

<linked>: no import

-

<linked>: with import

- -

<imported>: no import

-

<imported>: with import

- -

<imported sass>

-

<imported sass> with module

- -

<imported less> with string additionalData

- -

<imported stylus>

-
- - - - - ", - ], - "version": 3, - } - `) - }) - test('linked css', async () => { const res = await page.request.get( new URL('./linked.css', page.url()).href, diff --git a/packages/playground/hmr/__tests__/hmr.spec.ts b/packages/playground/hmr/__tests__/hmr.spec.ts index 40b2bdf31b7956..34612ee1e7d3d5 100644 --- a/packages/playground/hmr/__tests__/hmr.spec.ts +++ b/packages/playground/hmr/__tests__/hmr.spec.ts @@ -1,4 +1,4 @@ -import { isBuild, editFile, untilUpdated } from '../../testUtils' +import { isBuild, editFile, untilUpdated, getBg } from '../../testUtils' test('should render', async () => { expect(await page.textContent('.app')).toBe('1') @@ -195,6 +195,16 @@ if (!isBuild) { expect(await btn.textContent()).toBe('Counter 1') }) + test('css in html hmr', async () => { + await page.goto(viteTestUrl) + expect(await getBg('.import-image')).toMatch('icon') + await page.goto(viteTestUrl + '/foo/') + expect(await getBg('.import-image')).toMatch('icon') + editFile('index.html', (code) => code.replace('url("./icon.png")', '')) + await page.waitForNavigation() + expect(await getBg('.import-image')).toMatch('') + }) + test('HTML', async () => { await page.goto(viteTestUrl + '/counter/index.html') let btn = await page.$('button') diff --git a/packages/playground/hmr/icon.png b/packages/playground/hmr/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..4388bfdca3d4d778d2f25a5861599f8f19a1177c GIT binary patch literal 3395 zcmaJ^dpy(o8y`aCQb$M{Gf69KbDPa&mJzw-a@=pT&3zZ!m|LaXQi-Stqav};(cC3M zM}?d^vCOT0I;N7*N=fvaPM!1nKF&@kJcVR{+lVnpAW=nV5g|H(io-_}8K6*NcqG{pEa>P0gCYr*U~dy=m^0Oe z7!hfoL?e16xp?A}qVY%q7;OczNI;1QNJIt>lt79h(@_bQ;BUMr(S5@W1%tkYFrqEN ze~R*PJ`A#<(1;)t15+!P8!LgB{xFgOZ^M8V*o?+;j% zjYbGVxnu3V=Mq_#;0OkTih@F!Or`4OCV95o&O>x)4w-L)G}xSjtYevz@Q}3MqS^c z=?r(`-!lF&n(moMB|_babV?izFPcY~_7AYAcmJMfBT%FUg{9!*NJKKj0c!~sc?<}V z1e6KP(DZx{!kk~eI~MsL4MCDJ0}i3B?ug#`N698}~# z2*4l^2$-pjof!hNA>QZ!0*1A7WRL!P>~qu#$^9z(m!0H z_1U=owYMVUugxctMe9xz?e+DZ*aiSVrr80D@l4=N_`ae9j3}c&b|M6c^Scw&#v42` zs@=W24^$JB&ZnFHq$6hgI?L<)7qPYdpMFDMm5r*2NZZ#;hNLU%;UMB}lBX&zgLa?a z^q;(Rv!#SE3*p7_>9&tfp}FA;>iv!v_p|!wd;>mn_^936qi>ng*>kFww|a^}qJTRK znA`1@E!Y|;+Yc3d2h!d=ZZPN&V<0ppw;;&qMLk zs8GnX$?aj;YSC%6t7ryd|Y^9Qc9F|ZTi%4o)Pe;3_TsRPSb<*4*B>QW0CG(vI z>y^yW0M4}!mMf3!4z1fO+L~w1pRfz#LUd11)b_hvE5tyLhoKw+{E?+obcpiN*0LU8 z+U$wi{2kPnH5r4PMp&T>SNDmqNn*??;K@i|?J!$E9U15d+24QdeF^V4qsj`m?4KR1 zo+530cOpA+R_oI`YVpGHn|g}#XF^ggiIq#Q$r!(y$dA${=6vmyc6@muL~LaHK9;_U zM6ianv&69LoqCIN7iY5Nk~w}(YQ_@J^_HeBva+0R_9?+f_e~4spT$RYhq*aCNMrO$ zANmbE3u(ID)?XQ7A$ZW2RXgnhnaPNg>o$T&swba`imtoDTfX-ox*^fNY~&|)r*EP9 zDjZoQYgH3!&1P!g6r^)r`PMo_8VTHjZZPV`=6oa69GQI3%5zMi(iWaa;uA~o4%J^) zTvx7E_z4|v`9%k4yvRr!>a=q&CRMXs)EtsGU0BaC=tm1rZCwe$9zABiZcVuVM#f_O zEcY-xE#-a$$qK0SptY*~;s&%&{MxjMyzUJK)Ro2HOShN#i zdmd(sJrh3Lv2smAU0Uf)tzU1B4BTO~oK-hJav|YH;*QbtQMXN4?1g)YYj*9zWn;WS zf1=g6CNYN>p%StDbcLOA=ocrq)8-NU#|p81bRF3}y8w-f<_em-45$3L1@~e-{F^+_ zxkl==Ne8Vus0W)|3%}tC9-OE+5bT+_6f|Q*jZeS-JXh8E3%`TziByq04bJ6a1d7>H z;RYj*F8l4WsVGR4UERkbN(jGxSrPD|EDl*hJV;*`c%6d`F)1W~@pz_2+lh zX8Y6jap-cIJ8qTxvL@N3GJ-7LiuUjog<%wMNATus+JP&V$uD}fv7BWwUYMmGCIMGj z{8~4f?dWx0LX>Y-qi=!s6hE7+ubMW78h!`|R=KV%8FK zd9Sek(lv`S^5+9xYR`{X>yATq2OfeBt(}qyYA3{aLq|2d#^vB$R4#D)8lf9t!Y;+P z_6W7^{$}!gg?;4KjI39niyeEj#~ble%M>uw{nu#b`CHdh{gg9q+d8BrP^@~lDBI@d z7PMHwiV3pH(=wk3x<4;S!E(K=DJ>2!RAm*jrN_O@8jfGh%FKDK2Jufl-PsHs+4lH9 zDVKmh4;9;;mTf^PV;hRc zGZ1`0sMNGF2Q#}5#R#bM)tW_A=dSME$5(a2i}Ihk4u>_zBv%vI*myG)hHABMyPQj@ zM)WDfPOZ2LDPxwQFP3s9qT2x$(n(71$z;Qxd;tB$vX<;ZX<>Nsq(dQ>mhaX*MIFCf zb0p{bXj}2S`bD#rpHdTdNv!#{OR);Jsq8JJ*l1;(96~iudG#aZgj0Qo3WuL}YVZek z(SM)#(x7!4_(saUC6(W&b$isUNe3O4T~w_02Y#{Bs)T0h-r|>RiXN`FZb$o39EXiL z*RJ#X)VH`&nA(%q0JE_w3>ZQUex|DOv-oSu#vm zNS0_maoG$tauoZ;v)jT-lc=;EaufphG>)@S1@N~a5rr)*{bw*r-?o*rX6>8&zHcc*`CR~1#1jSw~d|R zwXi;)w4*Di+agG^bKz87RbPQwK!stmYMB_=wK@dlhtu9wFD@&T*Rq=*u7gj@78PR;rI9VW}r3UUH0!vA30jS z9UC??hXtMukpyu2>X*~v8;@W;`1_RbZHs(`$_8)1P;u9mwi4Rc0`sT=V!Y1o!I{Qq zTuHw3d^RR%uB5r{Ro1<>F8RPbj_b`$75gQNggjNu*H}~8;-HRVpN?w*H+KzOf}(^U z)d8)S!qI%E&Bf@3i1yh^Px1-jguC#MCUGbC&Rv0bg=h2Ms1B6?sLoFXEM>DdK;(^h zBZ=9iZF8CfgvLGLDUDAC>!hByzwDss&zxy_dFFE+ps2snc=RE+p+zrQ*E_9YM0{{Y z!fhZyCOLFWcsB~(RGiu+Zuz#hisxiIQ_CT@V-K)JH skXH~y@{pZ%H2RLzTI|$xG-@5%4N!D?9MV?={PtVpVC#adKM-=_zfn5szW@LL literal 0 HcmV?d00001 diff --git a/packages/playground/hmr/index.html b/packages/playground/hmr/index.html index 0add7c26011a01..65a2ed381b027a 100644 --- a/packages/playground/hmr/index.html +++ b/packages/playground/hmr/index.html @@ -1,5 +1,13 @@ +
@@ -8,3 +16,4 @@
+
diff --git a/packages/playground/ssr-html/index.html b/packages/playground/ssr-html/index.html index c37dcc7e366ae8..995c828caae1a8 100644 --- a/packages/playground/ssr-html/index.html +++ b/packages/playground/ssr-html/index.html @@ -4,6 +4,11 @@ SSR HTML +

SSR Dynamic HTML

diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index f310abc9bc7c56..8b01d48c696465 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -301,6 +301,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { const inlined = inlineRE.test(id) const modules = cssModulesCache.get(config)!.get(id) + const isHTMLProxy = htmlProxyRE.test(id) const modulesCode = modules && dataToEsm(modules, { namedExports: true, preferConst: true }) @@ -323,6 +324,10 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { cssContent = getCodeWithSourcemap('css', css, sourcemap) } + if (isHTMLProxy) { + return cssContent + } + return [ `import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${JSON.stringify( path.posix.join(config.base, CLIENT_PUBLIC_PATH) @@ -347,7 +352,6 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // and then use the cache replace inline-style-flag when `generateBundle` in vite:build-html plugin const inlineCSS = inlineCSSRE.test(id) const query = parseRequest(id) - const isHTMLProxy = htmlProxyRE.test(id) if (inlineCSS && isHTMLProxy) { addToHTMLProxyTransformResult( `${cleanUrl(id)}_${Number.parseInt(query!.index)}`, @@ -718,12 +722,11 @@ async function compileCSS( postcssConfig && postcssConfig.plugins ? postcssConfig.plugins.slice() : [] if (needInlineImport) { - const isHTMLProxy = htmlProxyRE.test(id) postcssPlugins.unshift( (await import('postcss-import')).default({ async resolve(id, basedir) { const publicFile = checkPublicFile(id, config) - if (isHTMLProxy && publicFile) { + if (publicFile) { return publicFile } diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index ca2538bd9507ed..8638492b1c2001 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -16,14 +16,25 @@ import { import type { ResolvedConfig, ViteDevServer } from '../..' import { send } from '../send' import { CLIENT_PUBLIC_PATH, FS_PREFIX } from '../../constants' -import { cleanUrl, fsPathFromId, normalizePath, injectQuery } from '../../utils' +import { + cleanUrl, + fsPathFromId, + normalizePath, + injectQuery, + ensureWatchedFile +} from '../../utils' import type { ModuleGraph } from '../moduleGraph' +interface AssetNode { + start: number + end: number + code: string +} + export function createDevHtmlTransformFn( server: ViteDevServer ): (url: string, html: string, originalUrl: string) => Promise { const [preHooks, postHooks] = resolveHtmlTransforms(server.config.plugins) - return (url: string, html: string, originalUrl: string): Promise => { return applyHtmlTransforms(html, [...preHooks, devHtmlHook, ...postHooks], { path: url, @@ -94,14 +105,15 @@ const devHtmlHook: IndexHtmlTransformHook = async ( html, { path: htmlPath, filename, server, originalUrl } ) => { - const { config, moduleGraph } = server! + const { config, moduleGraph, watcher } = server! const base = config.base || '/' const s = new MagicString(html) let inlineModuleIndex = -1 const filePath = cleanUrl(htmlPath) + const styleUrl: AssetNode[] = [] - const addInlineModule = (node: ElementNode, ext: 'js' | 'css') => { + const addInlineModule = (node: ElementNode, ext: 'js') => { inlineModuleIndex++ const url = filePath.replace(normalizePath(config.root), '') @@ -128,7 +140,6 @@ const devHtmlHook: IndexHtmlTransformHook = async ( if (module) { server?.moduleGraph.invalidateModule(module) } - s.overwrite( node.loc.start.offset, node.loc.end.offset, @@ -154,7 +165,12 @@ const devHtmlHook: IndexHtmlTransformHook = async ( } if (node.tag === 'style' && node.children.length) { - addInlineModule(node, 'css') + const children = node.children[0] as TextNode + styleUrl.push({ + start: children.loc.start.offset, + end: children.loc.end.offset, + code: children.content + }) } // elements with [href/src] attrs @@ -172,6 +188,19 @@ const devHtmlHook: IndexHtmlTransformHook = async ( } }) + await Promise.all( + styleUrl.map(async ({ start, end, code }, index) => { + const url = filename + `?html-proxy&${index}.css` + + // ensure module in graph after successful load + const mod = await moduleGraph.ensureEntryFromUrl(url, false) + ensureWatchedFile(watcher, mod.file, config.root) + + const result = await server!.pluginContainer.transform(code, url) + s.overwrite(start, end, result?.code || '') + }) + ) + html = s.toString() return { From aebaf66cdb5bd9c39225462621e6f55275790463 Mon Sep 17 00:00:00 2001 From: Anthony Campolo <12433465+ajcwebdev@users.noreply.github.com> Date: Sat, 30 Apr 2022 13:20:23 -0500 Subject: [PATCH 012/114] docs: grammar fix in getting started guide (#7972) --- docs/guide/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/index.md b/docs/guide/index.md index ff0d3f21b90e65..5af7c29c17ac3c 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -113,7 +113,7 @@ Running `vite` starts the dev server using the current working directory as root ## Command Line Interface -In a project where Vite is installed, you can use the `vite` binary in your npm scripts, or run it directly with `npx vite`. Here is the default npm scripts in a scaffolded Vite project: +In a project where Vite is installed, you can use the `vite` binary in your npm scripts, or run it directly with `npx vite`. Here are the default npm scripts in a scaffolded Vite project: ```json5 From 891e7fc4fa3e047be43df5c1a4703cda4a4a1f54 Mon Sep 17 00:00:00 2001 From: TrickyPi <33021497+TrickyPi@users.noreply.github.com> Date: Sun, 1 May 2022 03:11:37 +0800 Subject: [PATCH 013/114] fix(ssr): failed ssrLoadModule call throws same error (#7177) Co-authored-by: Rich Harris --- packages/vite/src/node/server/moduleGraph.ts | 1 + .../__tests__/fixtures/ssrModuleLoader-bad.js | 2 ++ .../ssr/__tests__/ssrModuleLoader.spec.ts | 29 +++++++++++++++++++ packages/vite/src/node/ssr/ssrModuleLoader.ts | 5 ++++ 4 files changed, 37 insertions(+) create mode 100644 packages/vite/src/node/ssr/__tests__/fixtures/ssrModuleLoader-bad.js create mode 100644 packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts diff --git a/packages/vite/src/node/server/moduleGraph.ts b/packages/vite/src/node/server/moduleGraph.ts index 9c9f0d84bb738f..1d7ae407f110c5 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -33,6 +33,7 @@ export class ModuleNode { transformResult: TransformResult | null = null ssrTransformResult: TransformResult | null = null ssrModule: Record | null = null + ssrError: Error | null = null lastHMRTimestamp = 0 lastInvalidationTimestamp = 0 diff --git a/packages/vite/src/node/ssr/__tests__/fixtures/ssrModuleLoader-bad.js b/packages/vite/src/node/ssr/__tests__/fixtures/ssrModuleLoader-bad.js new file mode 100644 index 00000000000000..a51a0519d34003 --- /dev/null +++ b/packages/vite/src/node/ssr/__tests__/fixtures/ssrModuleLoader-bad.js @@ -0,0 +1,2 @@ +export const bad = 1 +throw new Error('it is an expected error') diff --git a/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts new file mode 100644 index 00000000000000..6a45a2b70509d0 --- /dev/null +++ b/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts @@ -0,0 +1,29 @@ +import { resolve } from 'path' +import { createServer } from '../../index' + +const badjs = resolve(__dirname, './fixtures/ssrModuleLoader-bad.js') +const THROW_MESSAGE = 'it is an expected error' + +test('always throw error when evaluating an wrong SSR module', async () => { + const viteServer = await createServer() + const spy = jest.spyOn(console, 'error').mockImplementation(() => {}) + const expectedErrors = [] + for (const i of [0, 1]) { + try { + await viteServer.ssrLoadModule(badjs) + } catch (e) { + expectedErrors.push(e) + } + } + await viteServer.close() + expect(expectedErrors).toHaveLength(2) + expect(expectedErrors[0]).toBe(expectedErrors[1]) + expectedErrors.forEach((error) => { + expect(error?.message).toContain(THROW_MESSAGE) + }) + expect(spy).toBeCalledTimes(1) + const [firstParameter] = spy.mock.calls[0] + expect(firstParameter).toContain('Error when evaluating SSR module') + expect(firstParameter).toContain(THROW_MESSAGE) + spy.mockClear() +}) diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index de31c6a20266c5..8b3a423f58aeab 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -77,6 +77,10 @@ async function instantiateModule( const { moduleGraph } = server const mod = await moduleGraph.ensureEntryFromUrl(url, true) + if (mod.ssrError) { + throw mod.ssrError + } + if (mod.ssrModule) { return mod.ssrModule } @@ -202,6 +206,7 @@ async function instantiateModule( ssrExportAll ) } catch (e) { + mod.ssrError = e if (e.stack && fixStacktrace !== false) { const stacktrace = ssrRewriteStacktrace(e.stack, moduleGraph) rebindErrorStacktrace(e, stacktrace) From a5bdb9fa706850c45134c25b77aea2dee1ea03d4 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Sun, 1 May 2022 03:28:39 +0800 Subject: [PATCH 014/114] feat(create-vite): scaffold directory with only .git (#7971) --- packages/create-vite/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/create-vite/index.js b/packages/create-vite/index.js index cc0a78639755bb..fceef9d9885a05 100755 --- a/packages/create-vite/index.js +++ b/packages/create-vite/index.js @@ -313,7 +313,8 @@ function copyDir(srcDir, destDir) { } function isEmpty(path) { - return fs.readdirSync(path).length === 0 + const files = fs.readdirSync(path) + return files.length === 0 || (files.length === 1 && files[0] === '.git') } function emptyDir(dir) { From f6ae60db74e0fcdb8ecf47df5c8b6df86d2c3ad6 Mon Sep 17 00:00:00 2001 From: yoho Date: Sun, 1 May 2022 14:47:34 +0800 Subject: [PATCH 015/114] fix: inline css hash (#7974) --- packages/playground/html/inline/shared_a.html | 1 + packages/playground/html/vite.config.js | 1 + packages/vite/src/node/plugins/asset.ts | 2 +- packages/vite/src/node/plugins/css.ts | 5 +++-- packages/vite/src/node/plugins/html.ts | 17 +++++++++-------- 5 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 packages/playground/html/inline/shared_a.html diff --git a/packages/playground/html/inline/shared_a.html b/packages/playground/html/inline/shared_a.html new file mode 100644 index 00000000000000..31fbd8fcc34bdf --- /dev/null +++ b/packages/playground/html/inline/shared_a.html @@ -0,0 +1 @@ +

inline a

diff --git a/packages/playground/html/vite.config.js b/packages/playground/html/vite.config.js index 1703e02cc05366..bfe48675cbc18f 100644 --- a/packages/playground/html/vite.config.js +++ b/packages/playground/html/vite.config.js @@ -17,6 +17,7 @@ module.exports = { zeroJS: resolve(__dirname, 'zeroJS.html'), noHead: resolve(__dirname, 'noHead.html'), noBody: resolve(__dirname, 'noBody.html'), + inlinea: resolve(__dirname, 'inline/shared_a.html'), inline1: resolve(__dirname, 'inline/shared-1.html'), inline2: resolve(__dirname, 'inline/shared-2.html'), inline3: resolve(__dirname, 'inline/unique.html'), diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 633438cf3cb0d4..f2eed2bc28bc5a 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -337,7 +337,7 @@ async function fileToBuiltUrl( return url } -export function getAssetHash(content: Buffer): string { +export function getAssetHash(content: Buffer | string): string { return createHash('sha256').update(content).digest('hex').slice(0, 8) } diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 8b01d48c696465..cff7eaaf3e4c52 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -33,7 +33,8 @@ import { getAssetFilename, assetUrlRE, fileToUrl, - checkPublicFile + checkPublicFile, + getAssetHash } from './asset' import MagicString from 'magic-string' import type * as PostCSS from 'postcss' @@ -354,7 +355,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { const query = parseRequest(id) if (inlineCSS && isHTMLProxy) { addToHTMLProxyTransformResult( - `${cleanUrl(id)}_${Number.parseInt(query!.index)}`, + `${getAssetHash(cleanUrl(id))}_${Number.parseInt(query!.index)}`, css ) return `export default ''` diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index ed4250f1965869..c33811008ccb17 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -23,7 +23,8 @@ import { checkPublicFile, assetUrlRE, urlToBuiltUrl, - getAssetFilename + getAssetFilename, + getAssetHash } from './asset' import { isCSSRequest } from './css' import { modulePreloadPolyfillId } from './modulePreloadPolyfill' @@ -44,7 +45,7 @@ interface ScriptAssetsUrl { } const htmlProxyRE = /\?html-proxy=?[&inline\-css]*&index=(\d+)\.(js|css)$/ -const inlineCSSRE = /__VITE_INLINE_CSS__([^_]+_\d+)__/g +const inlineCSSRE = /__VITE_INLINE_CSS__([a-z\d]{8}_\d+)__/g // Do not allow preceding '.', but do allow preceding '...' for spread operations const inlineImportRE = /(?() // HTML Proxy Transform result are stored by config -// `${importer}_${query.index}` -> transformed css code -// PS: key like `/vite/packages/playground/assets/index.html_1` +// `${hash(importer)}_${query.index}` -> transformed css code +// PS: key like `hash(/vite/packages/playground/assets/index.html)_1`) export const htmlProxyResult = new Map() export function htmlInlineProxyPlugin(config: ResolvedConfig): Plugin { @@ -373,12 +374,12 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { addToHTMLProxyCache(config, filePath, inlineModuleIndex, { code }) // will transform with css plugin and cache result with css-post plugin js += `\nimport "${id}?html-proxy&inline-css&index=${inlineModuleIndex}.css"` - + const hash = getAssetHash(cleanUrl(id)) // will transform in `applyHtmlTransforms` s.overwrite( styleNode.loc.start.offset, styleNode.loc.end.offset, - `"__VITE_INLINE_CSS__${cleanUrl(id)}_${inlineModuleIndex}__"`, + `"__VITE_INLINE_CSS__${hash}_${inlineModuleIndex}__"`, { contentOnly: true } ) } @@ -392,12 +393,12 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { code: styleNode.content }) js += `\nimport "${id}?html-proxy&inline-css&index=${inlineModuleIndex}.css"` - + const hash = getAssetHash(cleanUrl(id)) // will transform in `applyHtmlTransforms` s.overwrite( styleNode.loc.start.offset, styleNode.loc.end.offset, - `__VITE_INLINE_CSS__${cleanUrl(id)}_${inlineModuleIndex}__`, + `__VITE_INLINE_CSS__${hash}_${inlineModuleIndex}__`, { contentOnly: true } ) } From 7f9f8f1f84b6fcf3cee45208f929050a842bd535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Mon, 2 May 2022 03:51:18 +0900 Subject: [PATCH 016/114] fix(css): sourcemap crash with postcss (#7982) --- packages/playground/vue-sourcemap/Css.vue | 11 ++++++ .../vue-sourcemap/__tests__/serve.spec.ts | 39 +++++++++++++++++-- .../playground/vue-sourcemap/package.json | 3 +- .../vue-sourcemap/postcss.config.js | 3 ++ packages/vite/src/node/plugins/css.ts | 19 +++------ pnpm-lock.yaml | 2 + 6 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 packages/playground/vue-sourcemap/postcss.config.js diff --git a/packages/playground/vue-sourcemap/Css.vue b/packages/playground/vue-sourcemap/Css.vue index 19668de8d33965..4f677c7b84dfbd 100644 --- a/packages/playground/vue-sourcemap/Css.vue +++ b/packages/playground/vue-sourcemap/Css.vue @@ -2,6 +2,7 @@

<css>

<css> module

<css> scoped

+

<css> scoped with nested

+ + diff --git a/packages/playground/vue-sourcemap/__tests__/serve.spec.ts b/packages/playground/vue-sourcemap/__tests__/serve.spec.ts index 08b4c04face111..7dfa271deea322 100644 --- a/packages/playground/vue-sourcemap/__tests__/serve.spec.ts +++ b/packages/playground/vue-sourcemap/__tests__/serve.spec.ts @@ -80,7 +80,7 @@ if (!isBuild) { const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` Object { - "mappings": ";AAOA;EACE,UAAU;AACZ", + "mappings": ";AAQA;EACE,UAAU;AACZ", "sources": Array [ "/root/Css.vue", ], @@ -89,6 +89,7 @@ if (!isBuild) {

<css>

<css> module

<css> scoped

+

<css> scoped with nested

+ + ", ], "version": 3, @@ -120,7 +131,7 @@ if (!isBuild) { const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` Object { - "mappings": ";AAaA;EACE,UAAU;AACZ", + "mappings": ";AAcA;EACE,UAAU;AACZ", "sources": Array [ "/root/Css.vue", ], @@ -129,6 +140,7 @@ if (!isBuild) {

<css>

<css> module

<css> scoped

+

<css> scoped with nested

+ + ", ], "version": 3, @@ -160,7 +182,7 @@ if (!isBuild) { const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` Object { - "mappings": ";AAmBA;EACE,UAAU;AACZ", + "mappings": ";AAoBA;EACE,UAAU;AACZ", "sources": Array [ "/root/Css.vue", ], @@ -169,6 +191,7 @@ if (!isBuild) {

<css>

<css> module

<css> scoped

+

<css> scoped with nested

+ + ", ], "version": 3, diff --git a/packages/playground/vue-sourcemap/package.json b/packages/playground/vue-sourcemap/package.json index 286940b01efa58..25bd2b725b7e65 100644 --- a/packages/playground/vue-sourcemap/package.json +++ b/packages/playground/vue-sourcemap/package.json @@ -11,7 +11,8 @@ "devDependencies": { "@vitejs/plugin-vue": "workspace:*", "less": "^4.1.2", - "sass": "^1.43.4" + "sass": "^1.43.4", + "postcss-nested": "^5.0.6" }, "dependencies": { "vue": "^3.2.31" diff --git a/packages/playground/vue-sourcemap/postcss.config.js b/packages/playground/vue-sourcemap/postcss.config.js new file mode 100644 index 00000000000000..9ea26b495d91b5 --- /dev/null +++ b/packages/playground/vue-sourcemap/postcss.config.js @@ -0,0 +1,3 @@ +module.exports = { + plugins: [require('postcss-nested')] +} diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index cff7eaaf3e4c52..b3ea3338cecc04 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -877,32 +877,23 @@ export function formatPostcssSourceMap( ): ExistingRawSourceMap { const inputFileDir = path.dirname(file) - const sources: string[] = [] - const sourcesContent: string[] = [] - for (const [i, source] of rawMap.sources.entries()) { - // remove from sources, to prevent source map to be combined incorrectly - if (source === '') continue - + const sources = rawMap.sources.map((source) => { const cleanSource = cleanUrl(decodeURIComponent(source)) // postcss returns virtual files if (/^<.+>$/.test(cleanSource)) { - sources.push(`\0${cleanSource}`) - } else { - sources.push(normalizePath(path.resolve(inputFileDir, cleanSource))) + return `\0${cleanSource}` } - if (rawMap.sourcesContent) { - sourcesContent.push(rawMap.sourcesContent[i]) - } - } + return normalizePath(path.resolve(inputFileDir, cleanSource)) + }) return { file, mappings: rawMap.mappings, names: rawMap.names, sources, - sourcesContent, + sourcesContent: rawMap.sourcesContent, version: rawMap.version } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 73be476b1c911b..7c177126794187 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -730,6 +730,7 @@ importers: specifiers: '@vitejs/plugin-vue': workspace:* less: ^4.1.2 + postcss-nested: ^5.0.6 sass: ^1.43.4 vue: ^3.2.31 dependencies: @@ -737,6 +738,7 @@ importers: devDependencies: '@vitejs/plugin-vue': link:../../plugin-vue less: 4.1.2 + postcss-nested: 5.0.6 sass: 1.45.1 packages/playground/wasm: From 025eebf7e634e2fdc40fde02b5f82278d5ef05c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Mon, 2 May 2022 04:50:25 +0900 Subject: [PATCH 017/114] fix(css): dynamic import css in package fetches removed js (fixes #7955, #6823) (#7969) --- .../dynamic-import/__tests__/dynamic-import.spec.ts | 7 ++++++- packages/playground/dynamic-import/index.html | 1 + packages/playground/dynamic-import/nested/deps.js | 3 +++ packages/playground/dynamic-import/nested/index.js | 5 +++++ packages/playground/dynamic-import/package.json | 6 +++++- packages/playground/dynamic-import/pkg/index.js | 1 + packages/playground/dynamic-import/pkg/package.json | 7 +++++++ packages/playground/dynamic-import/pkg/pkg.css | 3 +++ packages/vite/src/node/plugins/importAnalysisBuild.ts | 5 ++++- pnpm-lock.yaml | 6 ++++++ 10 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 packages/playground/dynamic-import/nested/deps.js create mode 100644 packages/playground/dynamic-import/pkg/index.js create mode 100644 packages/playground/dynamic-import/pkg/package.json create mode 100644 packages/playground/dynamic-import/pkg/pkg.css diff --git a/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts b/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts index c7157ef4652ec6..4730b5e990a1c3 100644 --- a/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts +++ b/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts @@ -1,4 +1,4 @@ -import { isBuild, untilUpdated } from '../../testUtils' +import { getColor, isBuild, untilUpdated } from '../../testUtils' test('should load literal dynamic import', async () => { await page.click('.baz') @@ -59,3 +59,8 @@ test('should load dynamic import with css', async () => { true ) }) + +test('should load dynamic import with css in package', async () => { + await page.click('.pkg-css') + await untilUpdated(() => getColor('.pkg-css'), 'blue', true) +}) diff --git a/packages/playground/dynamic-import/index.html b/packages/playground/dynamic-import/index.html index c87ef2a17f48d5..8e18204a7e4296 100644 --- a/packages/playground/dynamic-import/index.html +++ b/packages/playground/dynamic-import/index.html @@ -8,6 +8,7 @@ +
diff --git a/packages/playground/dynamic-import/nested/deps.js b/packages/playground/dynamic-import/nested/deps.js new file mode 100644 index 00000000000000..88fd4787941fd0 --- /dev/null +++ b/packages/playground/dynamic-import/nested/deps.js @@ -0,0 +1,3 @@ +/* don't include dynamic import inside this file */ + +import 'pkg' diff --git a/packages/playground/dynamic-import/nested/index.js b/packages/playground/dynamic-import/nested/index.js index 5518c56a35a2cc..f84ec00380d604 100644 --- a/packages/playground/dynamic-import/nested/index.js +++ b/packages/playground/dynamic-import/nested/index.js @@ -70,6 +70,11 @@ document.querySelector('.css').addEventListener('click', async () => { text('.view', 'dynamic import css') }) +document.querySelector('.pkg-css').addEventListener('click', async () => { + await import('./deps') + text('.view', 'dynamic import css in package') +}) + function text(el, text) { document.querySelector(el).textContent = text } diff --git a/packages/playground/dynamic-import/package.json b/packages/playground/dynamic-import/package.json index a6b6d5f863f1b8..3aac1090af5be4 100644 --- a/packages/playground/dynamic-import/package.json +++ b/packages/playground/dynamic-import/package.json @@ -6,6 +6,10 @@ "dev": "vite", "build": "vite build", "debug": "node --inspect-brk ../../vite/bin/vite", - "preview": "vite preview" + "preview": "vite preview", + "postinstall": "ts-node ../../../scripts/patchFileDeps.ts" + }, + "dependencies": { + "pkg": "file:./pkg" } } diff --git a/packages/playground/dynamic-import/pkg/index.js b/packages/playground/dynamic-import/pkg/index.js new file mode 100644 index 00000000000000..20f705c0b4a8c9 --- /dev/null +++ b/packages/playground/dynamic-import/pkg/index.js @@ -0,0 +1 @@ +import('./pkg.css') diff --git a/packages/playground/dynamic-import/pkg/package.json b/packages/playground/dynamic-import/pkg/package.json new file mode 100644 index 00000000000000..1eab564572e245 --- /dev/null +++ b/packages/playground/dynamic-import/pkg/package.json @@ -0,0 +1,7 @@ +{ + "name": "pkg", + "type": "module", + "private": true, + "version": "1.0.0", + "main": "index.js" +} diff --git a/packages/playground/dynamic-import/pkg/pkg.css b/packages/playground/dynamic-import/pkg/pkg.css new file mode 100644 index 00000000000000..349d669b6829bf --- /dev/null +++ b/packages/playground/dynamic-import/pkg/pkg.css @@ -0,0 +1,3 @@ +.pkg-css { + color: blue; +} diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index ff315d008f57a5..7e684db2b4cc6b 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -24,6 +24,8 @@ export const preloadBaseMarker = `__VITE_PRELOAD_BASE__` const preloadHelperId = 'vite/preload-helper' const preloadMarkerWithQuote = `"${preloadMarker}"` as const +const dynamicImportPrefixRE = /import\s*\(/ + /** * Helper for preloading CSS and direct imports of async chunks in parallel to * the async chunk itself. @@ -118,7 +120,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { async transform(source, importer) { if ( importer.includes('node_modules') && - !source.includes('import.meta.glob') + !source.includes('import.meta.glob') && + !dynamicImportPrefixRE.test(source) ) { return } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c177126794187..43c9d6d049d250 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -185,6 +185,12 @@ importers: specifiers: {} packages/playground/dynamic-import: + specifiers: + pkg: file:./pkg + dependencies: + pkg: link:pkg + + packages/playground/dynamic-import/pkg: specifiers: {} packages/playground/env: From b877d30a05691bb6ea2da4e67b931a5a3d32809f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 2 May 2022 09:35:14 +0200 Subject: [PATCH 018/114] chore(deps): update all non-major dependencies (#7949) --- package.json | 12 +- packages/plugin-legacy/package.json | 4 +- packages/plugin-react/package.json | 4 +- packages/plugin-vue-jsx/package.json | 2 +- packages/vite/package.json | 18 +- pnpm-lock.yaml | 606 ++++++++++++++++----------- 6 files changed, 381 insertions(+), 265 deletions(-) diff --git a/package.json b/package.json index 1bfa2c4e77619c..cf18c4ee36e894 100644 --- a/package.json +++ b/package.json @@ -34,24 +34,24 @@ "ci-docs": "run-s build-vite build-plugin-vue build-docs" }, "devDependencies": { - "@microsoft/api-extractor": "^7.22.2", + "@microsoft/api-extractor": "^7.23.0", "@types/fs-extra": "^9.0.13", "@types/jest": "^27.4.1", "@types/node": "^17.0.25", "@types/prompts": "^2.0.14", "@types/semver": "^7.3.9", - "@typescript-eslint/eslint-plugin": "^5.20.0", - "@typescript-eslint/parser": "^5.20.0", + "@typescript-eslint/eslint-plugin": "^5.21.0", + "@typescript-eslint/parser": "^5.21.0", "conventional-changelog-cli": "^2.2.2", "cross-env": "^7.0.3", "esbuild": "^0.14.27", - "eslint": "^8.13.0", + "eslint": "^8.14.0", "eslint-define-config": "^1.4.0", "eslint-plugin-node": "^11.1.0", "execa": "^5.1.1", "fs-extra": "^10.1.0", "jest": "^27.5.1", - "lint-staged": "^12.4.0", + "lint-staged": "^12.4.1", "minimist": "^1.2.6", "node-fetch": "^2.6.6", "npm-run-all": "^4.1.5", @@ -85,7 +85,7 @@ "eslint --ext .ts" ] }, - "packageManager": "pnpm@6.32.9", + "packageManager": "pnpm@6.32.11", "pnpm": { "overrides": { "vite": "workspace:*", diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index adc97e974f2d37..1ba92ee5fd8565 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -22,8 +22,8 @@ }, "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme", "dependencies": { - "@babel/standalone": "^7.17.9", - "core-js": "^3.22.2", + "@babel/standalone": "^7.17.11", + "core-js": "^3.22.3", "magic-string": "^0.26.1", "regenerator-runtime": "^0.13.9", "systemjs": "^6.12.1" diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json index 8c93db98aac027..5698472c9dc113 100644 --- a/packages/plugin-react/package.json +++ b/packages/plugin-react/package.json @@ -33,13 +33,13 @@ }, "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-react#readme", "dependencies": { - "@babel/core": "^7.17.9", + "@babel/core": "^7.17.10", "@babel/plugin-transform-react-jsx": "^7.17.3", "@babel/plugin-transform-react-jsx-development": "^7.16.7", "@babel/plugin-transform-react-jsx-self": "^7.16.7", "@babel/plugin-transform-react-jsx-source": "^7.16.7", "@rollup/pluginutils": "^4.2.1", - "react-refresh": "^0.12.0", + "react-refresh": "^0.13.0", "resolve": "^1.22.0" } } diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 487d207a0df24d..32f346f6ea0024 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -22,7 +22,7 @@ }, "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-vue-jsx#readme", "dependencies": { - "@babel/core": "^7.17.9", + "@babel/core": "^7.17.10", "@babel/plugin-syntax-import-meta": "^7.10.4", "@babel/plugin-transform-typescript": "^7.16.8", "@rollup/pluginutils": "^4.2.1", diff --git a/packages/vite/package.json b/packages/vite/package.json index b2caecf4e228ca..39b95bbab97769 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -44,7 +44,7 @@ "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!", "dependencies": { "esbuild": "^0.14.27", - "postcss": "^8.4.12", + "postcss": "^8.4.13", "resolve": "^1.22.0", "rollup": "^2.59.0" }, @@ -52,9 +52,9 @@ "fsevents": "~2.3.2" }, "devDependencies": { - "@ampproject/remapping": "^2.1.2", - "@babel/parser": "^7.17.9", - "@babel/types": "^7.17.0", + "@ampproject/remapping": "^2.2.0", + "@babel/parser": "^7.17.10", + "@babel/types": "^7.17.10", "@jridgewell/trace-mapping": "^0.3.9", "@rollup/plugin-alias": "^3.1.9", "@rollup/plugin-commonjs": "^21.1.0", @@ -72,12 +72,12 @@ "@types/micromatch": "^4.0.2", "@types/mime": "^2.0.3", "@types/node": "^17.0.25", - "@types/resolve": "^1.20.1", + "@types/resolve": "^1.20.2", "@types/sass": "~1.43.1", "@types/stylus": "^0.48.37", "@types/ws": "^8.5.3", "@vue/compiler-dom": "^3.2.33", - "acorn": "^8.7.0", + "acorn": "^8.7.1", "cac": "6.7.9", "chokidar": "^3.5.3", "connect": "^3.7.0", @@ -112,11 +112,11 @@ "source-map-js": "^1.0.2", "source-map-support": "^0.5.21", "strip-ansi": "^6.0.1", - "terser": "^5.12.1", + "terser": "^5.13.1", "tsconfck": "^1.2.2", - "tslib": "^2.3.1", + "tslib": "^2.4.0", "types": "link:./types", - "ws": "^8.5.0" + "ws": "^8.6.0" }, "peerDependencies": { "less": "*", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43c9d6d049d250..57fa85d5aaacf7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,24 +10,24 @@ importers: .: specifiers: - '@microsoft/api-extractor': ^7.22.2 + '@microsoft/api-extractor': ^7.23.0 '@types/fs-extra': ^9.0.13 '@types/jest': ^27.4.1 '@types/node': ^17.0.25 '@types/prompts': ^2.0.14 '@types/semver': ^7.3.9 - '@typescript-eslint/eslint-plugin': ^5.20.0 - '@typescript-eslint/parser': ^5.20.0 + '@typescript-eslint/eslint-plugin': ^5.21.0 + '@typescript-eslint/parser': ^5.21.0 conventional-changelog-cli: ^2.2.2 cross-env: ^7.0.3 esbuild: ^0.14.27 - eslint: ^8.13.0 + eslint: ^8.14.0 eslint-define-config: ^1.4.0 eslint-plugin-node: ^11.1.0 execa: ^5.1.1 fs-extra: ^10.1.0 jest: ^27.5.1 - lint-staged: ^12.4.0 + lint-staged: ^12.4.1 minimist: ^1.2.6 node-fetch: ^2.6.6 npm-run-all: ^4.1.5 @@ -46,24 +46,24 @@ importers: vite: workspace:* vitepress: ^0.22.3 devDependencies: - '@microsoft/api-extractor': 7.22.2 + '@microsoft/api-extractor': 7.23.0 '@types/fs-extra': 9.0.13 '@types/jest': 27.4.1 '@types/node': 17.0.25 '@types/prompts': 2.0.14 '@types/semver': 7.3.9 - '@typescript-eslint/eslint-plugin': 5.20.0_0df7beb8e4d849cfe6bb8e844ccdebfd - '@typescript-eslint/parser': 5.20.0_eslint@8.13.0+typescript@4.5.4 + '@typescript-eslint/eslint-plugin': 5.21.0_85142f655c5c9420758b0f4908692036 + '@typescript-eslint/parser': 5.21.0_eslint@8.14.0+typescript@4.5.4 conventional-changelog-cli: 2.2.2 cross-env: 7.0.3 esbuild: 0.14.27 - eslint: 8.13.0 + eslint: 8.14.0 eslint-define-config: 1.4.0 - eslint-plugin-node: 11.1.0_eslint@8.13.0 + eslint-plugin-node: 11.1.0_eslint@8.14.0 execa: 5.1.1 fs-extra: 10.1.0 jest: 27.5.1_ts-node@10.4.0 - lint-staged: 12.4.0 + lint-staged: 12.4.1 minimist: 1.2.6 node-fetch: 2.6.6 npm-run-all: 4.1.5 @@ -758,36 +758,36 @@ importers: packages/plugin-legacy: specifiers: - '@babel/standalone': ^7.17.9 - core-js: ^3.22.2 + '@babel/standalone': ^7.17.11 + core-js: ^3.22.3 magic-string: ^0.26.1 regenerator-runtime: ^0.13.9 systemjs: ^6.12.1 dependencies: - '@babel/standalone': 7.17.9 - core-js: 3.22.2 + '@babel/standalone': 7.17.11 + core-js: 3.22.3 magic-string: 0.26.1 regenerator-runtime: 0.13.9 systemjs: 6.12.1 packages/plugin-react: specifiers: - '@babel/core': ^7.17.9 + '@babel/core': ^7.17.10 '@babel/plugin-transform-react-jsx': ^7.17.3 '@babel/plugin-transform-react-jsx-development': ^7.16.7 '@babel/plugin-transform-react-jsx-self': ^7.16.7 '@babel/plugin-transform-react-jsx-source': ^7.16.7 '@rollup/pluginutils': ^4.2.1 - react-refresh: ^0.12.0 + react-refresh: ^0.13.0 resolve: ^1.22.0 dependencies: - '@babel/core': 7.17.9 - '@babel/plugin-transform-react-jsx': 7.17.3_@babel+core@7.17.9 - '@babel/plugin-transform-react-jsx-development': 7.16.7_@babel+core@7.17.9 - '@babel/plugin-transform-react-jsx-self': 7.16.7_@babel+core@7.17.9 - '@babel/plugin-transform-react-jsx-source': 7.16.7_@babel+core@7.17.9 + '@babel/core': 7.17.10 + '@babel/plugin-transform-react-jsx': 7.17.3_@babel+core@7.17.10 + '@babel/plugin-transform-react-jsx-development': 7.16.7_@babel+core@7.17.10 + '@babel/plugin-transform-react-jsx-self': 7.16.7_@babel+core@7.17.10 + '@babel/plugin-transform-react-jsx-source': 7.16.7_@babel+core@7.17.10 '@rollup/pluginutils': 4.2.1 - react-refresh: 0.12.0 + react-refresh: 0.13.0 resolve: 1.22.0 packages/plugin-vue: @@ -812,25 +812,25 @@ importers: packages/plugin-vue-jsx: specifiers: - '@babel/core': ^7.17.9 + '@babel/core': ^7.17.10 '@babel/plugin-syntax-import-meta': ^7.10.4 '@babel/plugin-transform-typescript': ^7.16.8 '@rollup/pluginutils': ^4.2.1 '@vue/babel-plugin-jsx': ^1.1.1 hash-sum: ^2.0.0 dependencies: - '@babel/core': 7.17.9 - '@babel/plugin-syntax-import-meta': 7.10.4_@babel+core@7.17.9 - '@babel/plugin-transform-typescript': 7.16.8_@babel+core@7.17.9 + '@babel/core': 7.17.10 + '@babel/plugin-syntax-import-meta': 7.10.4_@babel+core@7.17.10 + '@babel/plugin-transform-typescript': 7.16.8_@babel+core@7.17.10 '@rollup/pluginutils': 4.2.1 - '@vue/babel-plugin-jsx': 1.1.1_@babel+core@7.17.9 + '@vue/babel-plugin-jsx': 1.1.1_@babel+core@7.17.10 hash-sum: 2.0.0 packages/vite: specifiers: - '@ampproject/remapping': ^2.1.2 - '@babel/parser': ^7.17.9 - '@babel/types': ^7.17.0 + '@ampproject/remapping': ^2.2.0 + '@babel/parser': ^7.17.10 + '@babel/types': ^7.17.10 '@jridgewell/trace-mapping': ^0.3.9 '@rollup/plugin-alias': ^3.1.9 '@rollup/plugin-commonjs': ^21.1.0 @@ -848,12 +848,12 @@ importers: '@types/micromatch': ^4.0.2 '@types/mime': ^2.0.3 '@types/node': ^17.0.25 - '@types/resolve': ^1.20.1 + '@types/resolve': ^1.20.2 '@types/sass': ~1.43.1 '@types/stylus': ^0.48.37 '@types/ws': ^8.5.3 '@vue/compiler-dom': ^3.2.33 - acorn: ^8.7.0 + acorn: ^8.7.1 cac: 6.7.9 chokidar: ^3.5.3 connect: ^3.7.0 @@ -881,7 +881,7 @@ importers: open: ^8.4.0 periscopic: ^2.0.3 picocolors: ^1.0.0 - postcss: ^8.4.12 + postcss: ^8.4.13 postcss-import: ^14.1.0 postcss-load-config: ^3.1.4 postcss-modules: ^4.3.1 @@ -893,29 +893,29 @@ importers: source-map-js: ^1.0.2 source-map-support: ^0.5.21 strip-ansi: ^6.0.1 - terser: ^5.12.1 + terser: ^5.13.1 tsconfck: ^1.2.2 - tslib: ^2.3.1 + tslib: ^2.4.0 types: link:./types - ws: ^8.5.0 + ws: ^8.6.0 dependencies: esbuild: 0.14.27 - postcss: 8.4.12 + postcss: 8.4.13 resolve: 1.22.0 rollup: 2.62.0 optionalDependencies: fsevents: 2.3.2 devDependencies: - '@ampproject/remapping': 2.1.2 - '@babel/parser': 7.17.9 - '@babel/types': 7.17.0 + '@ampproject/remapping': 2.2.0 + '@babel/parser': 7.17.10 + '@babel/types': 7.17.10 '@jridgewell/trace-mapping': 0.3.9 '@rollup/plugin-alias': 3.1.9_rollup@2.62.0 '@rollup/plugin-commonjs': 21.1.0_rollup@2.62.0 '@rollup/plugin-dynamic-import-vars': 1.4.3_rollup@2.62.0 '@rollup/plugin-json': 4.1.0_rollup@2.62.0 '@rollup/plugin-node-resolve': 13.2.1_rollup@2.62.0 - '@rollup/plugin-typescript': 8.3.2_7c5ff569c0887b4f0035eb7cb6988163 + '@rollup/plugin-typescript': 8.3.2_83df2083f1d8ae39f870809a13a7071e '@rollup/pluginutils': 4.2.1 '@types/convert-source-map': 1.5.2 '@types/cross-spawn': 6.0.2 @@ -926,12 +926,12 @@ importers: '@types/micromatch': 4.0.2 '@types/mime': 2.0.3 '@types/node': 17.0.25 - '@types/resolve': 1.20.1 + '@types/resolve': 1.20.2 '@types/sass': 1.43.1 '@types/stylus': 0.48.37 '@types/ws': 8.5.3 '@vue/compiler-dom': 3.2.33 - acorn: 8.7.0 + acorn: 8.7.1 cac: 6.7.9 chokidar: 3.5.3 connect: 3.7.0 @@ -957,20 +957,20 @@ importers: open: 8.4.0 periscopic: 2.0.3 picocolors: 1.0.0 - postcss-import: 14.1.0_postcss@8.4.12 - postcss-load-config: 3.1.4_postcss@8.4.12+ts-node@10.4.0 - postcss-modules: 4.3.1_postcss@8.4.12 + postcss-import: 14.1.0_postcss@8.4.13 + postcss-load-config: 3.1.4_postcss@8.4.13+ts-node@10.4.0 + postcss-modules: 4.3.1_postcss@8.4.13 resolve.exports: 1.1.0 rollup-plugin-license: 2.7.0_rollup@2.62.0 sirv: 2.0.2 source-map-js: 1.0.2 source-map-support: 0.5.21 strip-ansi: 6.0.1 - terser: 5.12.1 + terser: 5.13.1 tsconfck: 1.2.2_typescript@4.5.4 - tslib: 2.3.1 + tslib: 2.4.0 types: link:types - ws: 8.5.0 + ws: 8.6.0 packages: @@ -1096,6 +1096,15 @@ packages: engines: {node: '>=6.0.0'} dependencies: '@jridgewell/trace-mapping': 0.3.9 + dev: false + + /@ampproject/remapping/2.2.0: + resolution: {integrity: sha512-qRmjj8nj9qmLTQXXmaR1cck3UXSRMPrbsLJAasZpF+t3riI71BXed5ebIOYwQntykeZuhjsdweEc9BxH5Jc26w==} + engines: {node: '>=6.0.0'} + dependencies: + '@jridgewell/gen-mapping': 0.1.1 + '@jridgewell/trace-mapping': 0.3.9 + dev: true /@babel/code-frame/7.16.0: resolution: {integrity: sha512-IF4EOMEV+bfYwOmNxGzSnjR2EmQod7f1UXOpZM3l4i4o4QNwzjtJAu/HxdjHq0aYBvdqMuQEY1eg0nqW9ZPORA==} @@ -1114,25 +1123,25 @@ packages: engines: {node: '>=6.9.0'} dev: true - /@babel/compat-data/7.17.7: - resolution: {integrity: sha512-p8pdE6j0a29TNGebNm7NzYZWB3xVZJBZ7XGs42uAKzQo8VQ3F0By/cQCtUEABwIqw5zo6WA4NbmxsfzADzMKnQ==} + /@babel/compat-data/7.17.10: + resolution: {integrity: sha512-GZt/TCsG70Ms19gfZO1tM4CVnXsPgEPBCpJu+Qz3L0LUDsY5nZqFZglIoPC1kIYOtNBZlrnFT+klg12vFGZXrw==} engines: {node: '>=6.9.0'} dev: false - /@babel/core/7.17.2: - resolution: {integrity: sha512-R3VH5G42VSDolRHyUO4V2cfag8WHcZyxdq5Z/m8Xyb92lW/Erm/6kM+XtRFGf3Mulre3mveni2NHfEUws8wSvw==} + /@babel/core/7.17.10: + resolution: {integrity: sha512-liKoppandF3ZcBnIYFjfSDHZLKdLHGJRkoWtG8zQyGJBQfIYobpnVGI5+pLBNtS6psFLDzyq8+h5HiVljW9PNA==} engines: {node: '>=6.9.0'} dependencies: - '@ampproject/remapping': 2.1.0 + '@ampproject/remapping': 2.1.2 '@babel/code-frame': 7.16.7 - '@babel/generator': 7.17.0 - '@babel/helper-compilation-targets': 7.16.7_@babel+core@7.17.2 - '@babel/helper-module-transforms': 7.16.7 - '@babel/helpers': 7.17.2 - '@babel/parser': 7.17.0 + '@babel/generator': 7.17.10 + '@babel/helper-compilation-targets': 7.17.10_@babel+core@7.17.10 + '@babel/helper-module-transforms': 7.17.7 + '@babel/helpers': 7.17.9 + '@babel/parser': 7.17.10 '@babel/template': 7.16.7 - '@babel/traverse': 7.17.0 - '@babel/types': 7.17.0 + '@babel/traverse': 7.17.10 + '@babel/types': 7.17.10 convert-source-map: 1.8.0 debug: 4.3.4 gensync: 1.0.0-beta.2 @@ -1140,21 +1149,21 @@ packages: semver: 6.3.0 transitivePeerDependencies: - supports-color - dev: true + dev: false - /@babel/core/7.17.9: - resolution: {integrity: sha512-5ug+SfZCpDAkVp9SFIZAzlW18rlzsOcJGaetCjkySnrXXDUw9AR8cDUm1iByTmdWM6yxX6/zycaV76w3YTF2gw==} + /@babel/core/7.17.2: + resolution: {integrity: sha512-R3VH5G42VSDolRHyUO4V2cfag8WHcZyxdq5Z/m8Xyb92lW/Erm/6kM+XtRFGf3Mulre3mveni2NHfEUws8wSvw==} engines: {node: '>=6.9.0'} dependencies: - '@ampproject/remapping': 2.1.2 + '@ampproject/remapping': 2.1.0 '@babel/code-frame': 7.16.7 - '@babel/generator': 7.17.9 - '@babel/helper-compilation-targets': 7.17.7_@babel+core@7.17.9 - '@babel/helper-module-transforms': 7.17.7 - '@babel/helpers': 7.17.9 - '@babel/parser': 7.17.9 + '@babel/generator': 7.17.0 + '@babel/helper-compilation-targets': 7.16.7_@babel+core@7.17.2 + '@babel/helper-module-transforms': 7.16.7 + '@babel/helpers': 7.17.2 + '@babel/parser': 7.17.0 '@babel/template': 7.16.7 - '@babel/traverse': 7.17.9 + '@babel/traverse': 7.17.0 '@babel/types': 7.17.0 convert-source-map: 1.8.0 debug: 4.3.4 @@ -1163,7 +1172,7 @@ packages: semver: 6.3.0 transitivePeerDependencies: - supports-color - dev: false + dev: true /@babel/generator/7.16.5: resolution: {integrity: sha512-kIvCdjZqcdKqoDbVVdt5R99icaRtrtYhYK/xux5qiWCBmfdvEYMFZ68QCrpE5cbFM1JsuArUNs1ZkuKtTtUcZA==} @@ -1192,13 +1201,13 @@ packages: source-map: 0.5.7 dev: true - /@babel/generator/7.17.9: - resolution: {integrity: sha512-rAdDousTwxbIxbz5I7GEQ3lUip+xVCXooZNbsydCWs3xA7ZsYOv+CFRdzGxRX78BmQHu9B1Eso59AOZQOJDEdQ==} + /@babel/generator/7.17.10: + resolution: {integrity: sha512-46MJZZo9y3o4kmhBVc7zW7i8dtR1oIK/sdO5NcfcZRhTGYi+KKJRtHNgsU6c4VUcJmUNV/LQdebD/9Dlv4K+Tg==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.17.0 + '@babel/types': 7.17.10 + '@jridgewell/gen-mapping': 0.1.1 jsesc: 2.5.2 - source-map: 0.5.7 dev: false /@babel/helper-annotate-as-pure/7.16.7: @@ -1221,26 +1230,26 @@ packages: semver: 6.3.0 dev: true - /@babel/helper-compilation-targets/7.17.7_@babel+core@7.17.9: - resolution: {integrity: sha512-UFzlz2jjd8kroj0hmCFV5zr+tQPi1dpC2cRsDV/3IEW8bJfCPrPpmcSN6ZS8RqIq4LXcmpipCQFPddyFA5Yc7w==} + /@babel/helper-compilation-targets/7.17.10_@babel+core@7.17.10: + resolution: {integrity: sha512-gh3RxjWbauw/dFiU/7whjd0qN9K6nPJMqe6+Er7rOavFh0CQUSwhAE3IcTho2rywPJFxej6TUUHDkWcYI6gGqQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/compat-data': 7.17.7 - '@babel/core': 7.17.9 + '@babel/compat-data': 7.17.10 + '@babel/core': 7.17.10 '@babel/helper-validator-option': 7.16.7 - browserslist: 4.19.1 + browserslist: 4.20.3 semver: 6.3.0 dev: false - /@babel/helper-create-class-features-plugin/7.16.10_@babel+core@7.17.9: + /@babel/helper-create-class-features-plugin/7.16.10_@babel+core@7.17.10: resolution: {integrity: sha512-wDeej0pu3WN/ffTxMNCPW5UCiOav8IcLRxSIyp/9+IF2xJUM9h/OYjg0IJLHaL6F8oU8kqMz9nc1vryXhMsgXg==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.17.9 + '@babel/core': 7.17.10 '@babel/helper-annotate-as-pure': 7.16.7 '@babel/helper-environment-visitor': 7.16.7 '@babel/helper-function-name': 7.16.7 @@ -1256,7 +1265,7 @@ packages: resolution: {integrity: sha512-SLLb0AAn6PkUeAfKJCCOl9e1R53pQlGAfc4y4XuMRZfqeMYLE0dM1LMhqbGAlGQY0lfw5/ohoYWAe9V1yibRag==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.17.0 + '@babel/types': 7.17.10 /@babel/helper-function-name/7.16.7: resolution: {integrity: sha512-QfDfEnIUyyBSR3HtrtGECuZ6DAyCkYFp7GHl75vFtTnn6pjKeK0T1DB5lLkFvBea8MdaiUABx3osbgLyInoejA==} @@ -1271,7 +1280,7 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/template': 7.16.7 - '@babel/types': 7.17.0 + '@babel/types': 7.17.10 dev: false /@babel/helper-get-function-arity/7.16.7: @@ -1291,7 +1300,7 @@ packages: resolution: {integrity: sha512-m04d/0Op34H5v7pbZw6pSKP7weA6lsMvfiIAMeIvkY/R4xQtBSMFEigu9QTZ2qB/9l22vsxtM8a+Q8CzD255fg==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.17.0 + '@babel/types': 7.17.10 /@babel/helper-member-expression-to-functions/7.16.7: resolution: {integrity: sha512-VtJ/65tYiU/6AbMTDwyoXGPKHgTsfRarivm+YbB5uAzKUyuPjgZSgAFeG87FCigc7KNHu2Pegh1XIT3lXjvz3Q==} @@ -1338,8 +1347,8 @@ packages: '@babel/helper-split-export-declaration': 7.16.7 '@babel/helper-validator-identifier': 7.16.7 '@babel/template': 7.16.7 - '@babel/traverse': 7.17.9 - '@babel/types': 7.17.0 + '@babel/traverse': 7.17.10 + '@babel/types': 7.17.10 transitivePeerDependencies: - supports-color dev: false @@ -1383,14 +1392,14 @@ packages: resolution: {integrity: sha512-txyMCGroZ96i+Pxr3Je3lzEJjqwaRC9buMUgtomcrLe5Nd0+fk1h0LLA+ixUF5OW7AhHuQ7Es1WcQJZmZsz2XA==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.17.0 + '@babel/types': 7.17.10 dev: false /@babel/helper-split-export-declaration/7.16.7: resolution: {integrity: sha512-xbWoy/PFoxSWazIToT9Sif+jJTlrMcndIsaOKvTA6u7QEo7ilkRZpjew18/W3c7nm8fXdUDXh02VXTbZ0pGDNw==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.17.0 + '@babel/types': 7.17.10 /@babel/helper-validator-identifier/7.15.7: resolution: {integrity: sha512-K4JvCtQqad9OY2+yTU8w+E82ywk/fe+ELNlt1G8z3bVGlZfn/hOcQQsUhGhW/N+tb3fxK800wLtKOE/aM0m72w==} @@ -1420,8 +1429,8 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/template': 7.16.7 - '@babel/traverse': 7.17.9 - '@babel/types': 7.17.0 + '@babel/traverse': 7.17.10 + '@babel/types': 7.17.10 transitivePeerDependencies: - supports-color dev: false @@ -1459,6 +1468,11 @@ packages: hasBin: true dev: true + /@babel/parser/7.17.10: + resolution: {integrity: sha512-n2Q6i+fnJqzOaq2VkdXxy2TCPCWQZHiCo0XqmrCvDWcZQKRyZzYi4Z0yxlBuN0w+r2ZHmre+Q087DSrw3pbJDQ==} + engines: {node: '>=6.0.0'} + hasBin: true + /@babel/parser/7.17.8: resolution: {integrity: sha512-BoHhDJrJXqcg+ZL16Xv39H9n+AqJ4pcDrQBGZN+wHxIysrLZ3/ECwCBUch/1zUNhnsXULcONU3Ei5Hmkfk6kiQ==} engines: {node: '>=6.0.0'} @@ -1506,23 +1520,23 @@ packages: '@babel/helper-plugin-utils': 7.16.7 dev: true - /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.17.2: + /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.17.10: resolution: {integrity: sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.2 + '@babel/core': 7.17.10 '@babel/helper-plugin-utils': 7.16.5 - dev: true + dev: false - /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.17.9: + /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.17.2: resolution: {integrity: sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.9 + '@babel/core': 7.17.2 '@babel/helper-plugin-utils': 7.16.5 - dev: false + dev: true /@babel/plugin-syntax-json-strings/7.8.3_@babel+core@7.17.2: resolution: {integrity: sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA==} @@ -1542,23 +1556,23 @@ packages: '@babel/helper-plugin-utils': 7.16.7 dev: true - /@babel/plugin-syntax-jsx/7.16.5_@babel+core@7.17.9: + /@babel/plugin-syntax-jsx/7.16.5_@babel+core@7.17.10: resolution: {integrity: sha512-42OGssv9NPk4QHKVgIHlzeLgPOW5rGgfV5jzG90AhcXXIv6hu/eqj63w4VgvRxdvZY3AlYeDgPiSJ3BqAd1Y6Q==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.9 + '@babel/core': 7.17.10 '@babel/helper-plugin-utils': 7.16.7 dev: false - /@babel/plugin-syntax-jsx/7.16.7_@babel+core@7.17.9: + /@babel/plugin-syntax-jsx/7.16.7_@babel+core@7.17.10: resolution: {integrity: sha512-Esxmk7YjA8QysKeT3VhTXvF6y77f/a91SIs4pWb4H2eWGQkCKFgQaG6hdoEVZtGsrAcb2K5BW66XsOErD4WU3Q==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.9 + '@babel/core': 7.17.10 '@babel/helper-plugin-utils': 7.16.7 dev: false @@ -1635,80 +1649,80 @@ packages: '@babel/helper-plugin-utils': 7.16.7 dev: true - /@babel/plugin-syntax-typescript/7.16.7_@babel+core@7.17.2: + /@babel/plugin-syntax-typescript/7.16.7_@babel+core@7.17.10: resolution: {integrity: sha512-YhUIJHHGkqPgEcMYkPCKTyGUdoGKWtopIycQyjJH8OjvRgOYsXsaKehLVPScKJWAULPxMa4N1vCe6szREFlZ7A==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.2 + '@babel/core': 7.17.10 '@babel/helper-plugin-utils': 7.16.7 - dev: true + dev: false - /@babel/plugin-syntax-typescript/7.16.7_@babel+core@7.17.9: + /@babel/plugin-syntax-typescript/7.16.7_@babel+core@7.17.2: resolution: {integrity: sha512-YhUIJHHGkqPgEcMYkPCKTyGUdoGKWtopIycQyjJH8OjvRgOYsXsaKehLVPScKJWAULPxMa4N1vCe6szREFlZ7A==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.9 + '@babel/core': 7.17.2 '@babel/helper-plugin-utils': 7.16.7 - dev: false + dev: true - /@babel/plugin-transform-react-jsx-development/7.16.7_@babel+core@7.17.9: + /@babel/plugin-transform-react-jsx-development/7.16.7_@babel+core@7.17.10: resolution: {integrity: sha512-RMvQWvpla+xy6MlBpPlrKZCMRs2AGiHOGHY3xRwl0pEeim348dDyxeH4xBsMPbIMhujeq7ihE702eM2Ew0Wo+A==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.9 - '@babel/plugin-transform-react-jsx': 7.17.3_@babel+core@7.17.9 + '@babel/core': 7.17.10 + '@babel/plugin-transform-react-jsx': 7.17.3_@babel+core@7.17.10 dev: false - /@babel/plugin-transform-react-jsx-self/7.16.7_@babel+core@7.17.9: + /@babel/plugin-transform-react-jsx-self/7.16.7_@babel+core@7.17.10: resolution: {integrity: sha512-oe5VuWs7J9ilH3BCCApGoYjHoSO48vkjX2CbA5bFVhIuO2HKxA3vyF7rleA4o6/4rTDbk6r8hBW7Ul8E+UZrpA==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.9 + '@babel/core': 7.17.10 '@babel/helper-plugin-utils': 7.16.7 dev: false - /@babel/plugin-transform-react-jsx-source/7.16.7_@babel+core@7.17.9: + /@babel/plugin-transform-react-jsx-source/7.16.7_@babel+core@7.17.10: resolution: {integrity: sha512-rONFiQz9vgbsnaMtQlZCjIRwhJvlrPET8TabIUK2hzlXw9B9s2Ieaxte1SCOOXMbWRHodbKixNf3BLcWVOQ8Bw==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.9 + '@babel/core': 7.17.10 '@babel/helper-plugin-utils': 7.16.7 dev: false - /@babel/plugin-transform-react-jsx/7.17.3_@babel+core@7.17.9: + /@babel/plugin-transform-react-jsx/7.17.3_@babel+core@7.17.10: resolution: {integrity: sha512-9tjBm4O07f7mzKSIlEmPdiE6ub7kfIe6Cd+w+oQebpATfTQMAgW+YOuWxogbKVTulA+MEO7byMeIUtQ1z+z+ZQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.9 + '@babel/core': 7.17.10 '@babel/helper-annotate-as-pure': 7.16.7 '@babel/helper-module-imports': 7.16.7 '@babel/helper-plugin-utils': 7.16.7 - '@babel/plugin-syntax-jsx': 7.16.7_@babel+core@7.17.9 + '@babel/plugin-syntax-jsx': 7.16.7_@babel+core@7.17.10 '@babel/types': 7.17.0 dev: false - /@babel/plugin-transform-typescript/7.16.8_@babel+core@7.17.9: + /@babel/plugin-transform-typescript/7.16.8_@babel+core@7.17.10: resolution: {integrity: sha512-bHdQ9k7YpBDO2d0NVfkj51DpQcvwIzIusJ7mEUaMlbZq3Kt/U47j24inXZHQ5MDiYpCs+oZiwnXyKedE8+q7AQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.17.9 - '@babel/helper-create-class-features-plugin': 7.16.10_@babel+core@7.17.9 + '@babel/core': 7.17.10 + '@babel/helper-create-class-features-plugin': 7.16.10_@babel+core@7.17.10 '@babel/helper-plugin-utils': 7.16.7 - '@babel/plugin-syntax-typescript': 7.16.7_@babel+core@7.17.9 + '@babel/plugin-syntax-typescript': 7.16.7_@babel+core@7.17.10 transitivePeerDependencies: - supports-color dev: false @@ -1719,8 +1733,8 @@ packages: dependencies: regenerator-runtime: 0.13.9 - /@babel/standalone/7.17.9: - resolution: {integrity: sha512-9wL9AtDlga8avxUrBvQJmhUtJWrelsUL0uV+TcP+49Sb6Pj8/bNIzQzU4dDp0NAPOvnZR/7msFIKsKoCl/W1/w==} + /@babel/standalone/7.17.11: + resolution: {integrity: sha512-47wVYBeTktYHwtzlFuK7qqV/H5X6mU4MUNqpQ9iiJOqnP8rWL0eX0GWLKRsv8D8suYzhuS1K/dtwgGr+26U7Gg==} engines: {node: '>=6.9.0'} dev: false @@ -1738,8 +1752,8 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/code-frame': 7.16.7 - '@babel/parser': 7.17.8 - '@babel/types': 7.17.0 + '@babel/parser': 7.17.10 + '@babel/types': 7.17.10 /@babel/traverse/7.16.10: resolution: {integrity: sha512-yzuaYXoRJBGMlBhsMJoUW7G1UmSb/eXr/JHYM/MsOJgavJibLwASijW7oXBdw3NQ6T0bW7Ty5P/VarOs9cHmqw==} @@ -1795,18 +1809,18 @@ packages: - supports-color dev: true - /@babel/traverse/7.17.9: - resolution: {integrity: sha512-PQO8sDIJ8SIwipTPiR71kJQCKQYB5NGImbOviK8K+kg5xkNSYXLBupuX9QhatFowrsvo9Hj8WgArg3W7ijNAQw==} + /@babel/traverse/7.17.10: + resolution: {integrity: sha512-VmbrTHQteIdUUQNTb+zE12SHS/xQVIShmBPhlNP12hD5poF2pbITW1Z4172d03HegaQWhLffdkRJYtAzp0AGcw==} engines: {node: '>=6.9.0'} dependencies: '@babel/code-frame': 7.16.7 - '@babel/generator': 7.17.9 + '@babel/generator': 7.17.10 '@babel/helper-environment-visitor': 7.16.7 '@babel/helper-function-name': 7.17.9 '@babel/helper-hoist-variables': 7.16.7 '@babel/helper-split-export-declaration': 7.16.7 - '@babel/parser': 7.17.9 - '@babel/types': 7.17.0 + '@babel/parser': 7.17.10 + '@babel/types': 7.17.10 debug: 4.3.4 globals: 11.12.0 transitivePeerDependencies: @@ -1834,6 +1848,13 @@ packages: '@babel/helper-validator-identifier': 7.16.7 to-fast-properties: 2.0.0 + /@babel/types/7.17.10: + resolution: {integrity: sha512-9O26jG0mBYfGkUYCYZRnBwbVLd1UZOICEr2Em6InB6jVfsAv1GKgwXHmrSg+WFWDmeKTA6vyTZiN8tCSM5Oo3A==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/helper-validator-identifier': 7.16.7 + to-fast-properties: 2.0.0 + /@bcoe/v8-coverage/0.2.3: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true @@ -1965,8 +1986,8 @@ packages: resolution: {integrity: sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA==} dev: false - /@eslint/eslintrc/1.2.1: - resolution: {integrity: sha512-bxvbYnBPN1Gibwyp6NrpnFzA3YtRL3BBAyEAFVIpNTm2Rn4Vy87GA5M4aSn3InRrlsbX5N0GW7XIx+U4SAEKdQ==} + /@eslint/eslintrc/1.2.2: + resolution: {integrity: sha512-lTVWHs7O2hjBFZunXTZYnYqtB9GakA1lnxIf+gKq2nY5gxkkNi/lQvveW6t8gFdOHTg6nG50Xs95PrLqVpcaLg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: ajv: 6.12.6 @@ -2213,10 +2234,21 @@ packages: chalk: 4.1.2 dev: true + /@jridgewell/gen-mapping/0.1.1: + resolution: {integrity: sha512-sQXCasFk+U8lWYEe66WxRDOE9PjVz4vSM51fTu3Hw+ClTpUSQb718772vH3pyS5pShp6lvQM7SxgIDXXXmOX7w==} + engines: {node: '>=6.0.0'} + dependencies: + '@jridgewell/set-array': 1.1.0 + '@jridgewell/sourcemap-codec': 1.4.10 + /@jridgewell/resolve-uri/3.0.5: resolution: {integrity: sha512-VPeQ7+wH0itvQxnG+lIzWgkysKIr3L9sslimFW55rHMdGu/qCQ5z5h9zq4gI8uBtqkpHhsF4Z/OwExufUCThew==} engines: {node: '>=6.0.0'} + /@jridgewell/set-array/1.1.0: + resolution: {integrity: sha512-SfJxIxNVYLTsKwzB3MoOQ1yxf4w/E6MdkvTgrgAt1bfxjSrLUoHMKrDOykwN14q65waezZIdqDneUIPh4/sKxg==} + engines: {node: '>=6.0.0'} + /@jridgewell/sourcemap-codec/1.4.10: resolution: {integrity: sha512-Ht8wIW5v165atIX1p+JvKR5ONzUyF4Ac8DZIQ5kZs9zrb6M8SJNXpx1zn04rn65VjBMygRoMXcyYwNK0fT7bEg==} @@ -2250,30 +2282,30 @@ packages: - supports-color dev: false - /@microsoft/api-extractor-model/7.17.1: - resolution: {integrity: sha512-DCDtD8TdEpNk2lW4JvXgwwpxKy70P0JLad55iahwO8A+C63KYsrHIpAzo0FUauh5pwJ0v5QVNIJ+OBgKGteemg==} + /@microsoft/api-extractor-model/7.17.2: + resolution: {integrity: sha512-fYfCeBeLm7jnZligC64qHiH4/vzswFLDfyPpX+uKO36OI2kIeMHrYG0zaezmuinKvE4vg1dAz38zZeDbPvBKGg==} dependencies: '@microsoft/tsdoc': 0.14.1 '@microsoft/tsdoc-config': 0.16.1 - '@rushstack/node-core-library': 3.45.3 + '@rushstack/node-core-library': 3.45.4 dev: true - /@microsoft/api-extractor/7.22.2: - resolution: {integrity: sha512-G7vXz6UHz+qoaUGPf2k5Md4bSpHii9nFys3sIe3bmFUbmhAe+HfSB/dCn1PsLhW7tZfEXwMHTj7fbL5vcZkrEw==} + /@microsoft/api-extractor/7.23.0: + resolution: {integrity: sha512-fbdX05RVE1EMA7nvyRHuS9nx1pryhjgURDx6pQlE/9yOXQ5PO7MpYdfWGaRsQwyYuU3+tPxgro819c0R3AK6KA==} hasBin: true dependencies: - '@microsoft/api-extractor-model': 7.17.1 + '@microsoft/api-extractor-model': 7.17.2 '@microsoft/tsdoc': 0.14.1 '@microsoft/tsdoc-config': 0.16.1 - '@rushstack/node-core-library': 3.45.3 - '@rushstack/rig-package': 0.3.10 - '@rushstack/ts-command-line': 4.10.9 + '@rushstack/node-core-library': 3.45.4 + '@rushstack/rig-package': 0.3.11 + '@rushstack/ts-command-line': 4.10.10 colors: 1.2.5 lodash: 4.17.21 resolve: 1.17.0 semver: 7.3.7 source-map: 0.6.1 - typescript: 4.5.4 + typescript: 4.6.4 dev: true /@microsoft/tsdoc-config/0.16.1: @@ -2411,7 +2443,7 @@ packages: rollup: 2.62.0 dev: true - /@rollup/plugin-typescript/8.3.2_7c5ff569c0887b4f0035eb7cb6988163: + /@rollup/plugin-typescript/8.3.2_83df2083f1d8ae39f870809a13a7071e: resolution: {integrity: sha512-MtgyR5LNHZr3GyN0tM7gNO9D0CS+Y+vflS4v/PHmrX17JCkHUYKvQ5jN5o3cz1YKllM3duXUqu3yOHwMPUxhDg==} engines: {node: '>=8.0.0'} peerDependencies: @@ -2422,7 +2454,7 @@ packages: '@rollup/pluginutils': 3.1.0_rollup@2.62.0 resolve: 1.22.0 rollup: 2.62.0 - tslib: 2.3.1 + tslib: 2.4.0 typescript: 4.5.4 dev: true @@ -2445,8 +2477,8 @@ packages: estree-walker: 2.0.2 picomatch: 2.3.1 - /@rushstack/node-core-library/3.45.3: - resolution: {integrity: sha512-Rn0mxqC3MPb+YbvaeFcRWfcYHLwyZ99/ffYA8chpq5OpqoY+Mr1ycTbMvzl5AxWf1pYmi/2+Eo3iTOsQdYR8xw==} + /@rushstack/node-core-library/3.45.4: + resolution: {integrity: sha512-FMoEQWjK7nWAO2uFgV1eVpVhY9ZDGOdIIomi9zTej64cKJ+8/Nvu+ny0xKaUDEjw/ALftN2D2ml7L0RDpW/Z9g==} dependencies: '@types/node': 12.20.24 colors: 1.2.5 @@ -2459,15 +2491,15 @@ packages: z-schema: 5.0.2 dev: true - /@rushstack/rig-package/0.3.10: - resolution: {integrity: sha512-4Z2HhXM4YBWOi4ZYFQNK6Yxz641v+cvc8NKiaNZh+RIdNb3D4Rfpy3XUkggbCozpfDriBfL1+KaXlJtfJfAIXw==} + /@rushstack/rig-package/0.3.11: + resolution: {integrity: sha512-uI1/g5oQPtyrT9nStoyX/xgZSLa2b+srRFaDk3r1eqC7zA5th4/bvTGl2QfV3C9NcP+coSqmk5mFJkUfH6i3Lw==} dependencies: resolve: 1.17.0 strip-json-comments: 3.1.1 dev: true - /@rushstack/ts-command-line/4.10.9: - resolution: {integrity: sha512-TE3eZgHNVHOY3p8lp38FoNEJUr0+swPb24sCcYuwlC+MHgMGXyJNM+p7l3TKSBRiY01XShoL2k601oGwL00KlA==} + /@rushstack/ts-command-line/4.10.10: + resolution: {integrity: sha512-F+MH7InPDXqX40qvvcEsnvPpmg566SBpfFqj2fcCh8RjM6AyOoWlXc8zx7giBD3ZN85NVAEjZAgrcLU0z+R2yg==} dependencies: '@types/argparse': 1.0.38 argparse: 1.0.10 @@ -2679,8 +2711,8 @@ packages: '@types/node': 17.0.25 dev: true - /@types/resolve/1.20.1: - resolution: {integrity: sha512-Ku5+GPFa12S3W26Uwtw+xyrtIpaZsGYHH6zxNbZlstmlvMYSZRzOwzwsXbxlVUbHyUucctSyuFtu6bNxwYomIw==} + /@types/resolve/1.20.2: + resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} dev: true /@types/sass/1.43.1: @@ -2731,8 +2763,8 @@ packages: dev: true optional: true - /@typescript-eslint/eslint-plugin/5.20.0_0df7beb8e4d849cfe6bb8e844ccdebfd: - resolution: {integrity: sha512-fapGzoxilCn3sBtC6NtXZX6+P/Hef7VDbyfGqTTpzYydwhlkevB+0vE0EnmHPVTVSy68GUncyJ/2PcrFBeCo5Q==} + /@typescript-eslint/eslint-plugin/5.21.0_85142f655c5c9420758b0f4908692036: + resolution: {integrity: sha512-fTU85q8v5ZLpoZEyn/u1S2qrFOhi33Edo2CZ0+q1gDaWWm0JuPh3bgOyU8lM0edIEYgKLDkPFiZX2MOupgjlyg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: '@typescript-eslint/parser': ^5.0.0 @@ -2742,12 +2774,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.20.0_eslint@8.13.0+typescript@4.5.4 - '@typescript-eslint/scope-manager': 5.20.0 - '@typescript-eslint/type-utils': 5.20.0_eslint@8.13.0+typescript@4.5.4 - '@typescript-eslint/utils': 5.20.0_eslint@8.13.0+typescript@4.5.4 + '@typescript-eslint/parser': 5.21.0_eslint@8.14.0+typescript@4.5.4 + '@typescript-eslint/scope-manager': 5.21.0 + '@typescript-eslint/type-utils': 5.21.0_eslint@8.14.0+typescript@4.5.4 + '@typescript-eslint/utils': 5.21.0_eslint@8.14.0+typescript@4.5.4 debug: 4.3.4 - eslint: 8.13.0 + eslint: 8.14.0 functional-red-black-tree: 1.0.1 ignore: 5.2.0 regexpp: 3.2.0 @@ -2758,8 +2790,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.20.0_eslint@8.13.0+typescript@4.5.4: - resolution: {integrity: sha512-UWKibrCZQCYvobmu3/N8TWbEeo/EPQbS41Ux1F9XqPzGuV7pfg6n50ZrFo6hryynD8qOTTfLHtHjjdQtxJ0h/w==} + /@typescript-eslint/parser/5.21.0_eslint@8.14.0+typescript@4.5.4: + resolution: {integrity: sha512-8RUwTO77hstXUr3pZoWZbRQUxXcSXafZ8/5gpnQCfXvgmP9gpNlRGlWzvfbEQ14TLjmtU8eGnONkff8U2ui2Eg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 @@ -2768,26 +2800,26 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 5.20.0 - '@typescript-eslint/types': 5.20.0 - '@typescript-eslint/typescript-estree': 5.20.0_typescript@4.5.4 + '@typescript-eslint/scope-manager': 5.21.0 + '@typescript-eslint/types': 5.21.0 + '@typescript-eslint/typescript-estree': 5.21.0_typescript@4.5.4 debug: 4.3.4 - eslint: 8.13.0 + eslint: 8.14.0 typescript: 4.5.4 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/scope-manager/5.20.0: - resolution: {integrity: sha512-h9KtuPZ4D/JuX7rpp1iKg3zOH0WNEa+ZIXwpW/KWmEFDxlA/HSfCMhiyF1HS/drTICjIbpA6OqkAhrP/zkCStg==} + /@typescript-eslint/scope-manager/5.21.0: + resolution: {integrity: sha512-XTX0g0IhvzcH/e3393SvjRCfYQxgxtYzL3UREteUneo72EFlt7UNoiYnikUtmGVobTbhUDByhJ4xRBNe+34kOQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.20.0 - '@typescript-eslint/visitor-keys': 5.20.0 + '@typescript-eslint/types': 5.21.0 + '@typescript-eslint/visitor-keys': 5.21.0 dev: true - /@typescript-eslint/type-utils/5.20.0_eslint@8.13.0+typescript@4.5.4: - resolution: {integrity: sha512-WxNrCwYB3N/m8ceyoGCgbLmuZwupvzN0rE8NBuwnl7APgjv24ZJIjkNzoFBXPRCGzLNkoU/WfanW0exvp/+3Iw==} + /@typescript-eslint/type-utils/5.21.0_eslint@8.14.0+typescript@4.5.4: + resolution: {integrity: sha512-MxmLZj0tkGlkcZCSE17ORaHl8Th3JQwBzyXL/uvC6sNmu128LsgjTX0NIzy+wdH2J7Pd02GN8FaoudJntFvSOw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: '*' @@ -2796,22 +2828,22 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/utils': 5.20.0_eslint@8.13.0+typescript@4.5.4 + '@typescript-eslint/utils': 5.21.0_eslint@8.14.0+typescript@4.5.4 debug: 4.3.4 - eslint: 8.13.0 + eslint: 8.14.0 tsutils: 3.21.0_typescript@4.5.4 typescript: 4.5.4 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/types/5.20.0: - resolution: {integrity: sha512-+d8wprF9GyvPwtoB4CxBAR/s0rpP25XKgnOvMf/gMXYDvlUC3rPFHupdTQ/ow9vn7UDe5rX02ovGYQbv/IUCbg==} + /@typescript-eslint/types/5.21.0: + resolution: {integrity: sha512-XnOOo5Wc2cBlq8Lh5WNvAgHzpjnEzxn4CJBwGkcau7b/tZ556qrWXQz4DJyChYg8JZAD06kczrdgFPpEQZfDsA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree/5.20.0_typescript@4.5.4: - resolution: {integrity: sha512-36xLjP/+bXusLMrT9fMMYy1KJAGgHhlER2TqpUVDYUQg4w0q/NW/sg4UGAgVwAqb8V4zYg43KMUpM8vV2lve6w==} + /@typescript-eslint/typescript-estree/5.21.0_typescript@4.5.4: + resolution: {integrity: sha512-Y8Y2T2FNvm08qlcoSMoNchh9y2Uj3QmjtwNMdRQkcFG7Muz//wfJBGBxh8R7HAGQFpgYpdHqUpEoPQk+q9Kjfg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: typescript: '*' @@ -2819,8 +2851,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 5.20.0 - '@typescript-eslint/visitor-keys': 5.20.0 + '@typescript-eslint/types': 5.21.0 + '@typescript-eslint/visitor-keys': 5.21.0 debug: 4.3.4 globby: 11.0.4 is-glob: 4.0.3 @@ -2831,29 +2863,29 @@ packages: - supports-color dev: true - /@typescript-eslint/utils/5.20.0_eslint@8.13.0+typescript@4.5.4: - resolution: {integrity: sha512-lHONGJL1LIO12Ujyx8L8xKbwWSkoUKFSO+0wDAqGXiudWB2EO7WEUT+YZLtVbmOmSllAjLb9tpoIPwpRe5Tn6w==} + /@typescript-eslint/utils/5.21.0_eslint@8.14.0+typescript@4.5.4: + resolution: {integrity: sha512-q/emogbND9wry7zxy7VYri+7ydawo2HDZhRZ5k6yggIvXa7PvBbAAZ4PFH/oZLem72ezC4Pr63rJvDK/sTlL8Q==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: '@types/json-schema': 7.0.9 - '@typescript-eslint/scope-manager': 5.20.0 - '@typescript-eslint/types': 5.20.0 - '@typescript-eslint/typescript-estree': 5.20.0_typescript@4.5.4 - eslint: 8.13.0 + '@typescript-eslint/scope-manager': 5.21.0 + '@typescript-eslint/types': 5.21.0 + '@typescript-eslint/typescript-estree': 5.21.0_typescript@4.5.4 + eslint: 8.14.0 eslint-scope: 5.1.1 - eslint-utils: 3.0.0_eslint@8.13.0 + eslint-utils: 3.0.0_eslint@8.14.0 transitivePeerDependencies: - supports-color - typescript dev: true - /@typescript-eslint/visitor-keys/5.20.0: - resolution: {integrity: sha512-1flRpNF+0CAQkMNlTJ6L/Z5jiODG/e5+7mk6XwtPOUS3UrTz3UOiAg9jG2VtKsWI6rZQfy4C6a232QNRZTRGlg==} + /@typescript-eslint/visitor-keys/5.21.0: + resolution: {integrity: sha512-SX8jNN+iHqAF0riZQMkm7e8+POXa/fXw5cxL+gjpyP+FI+JVNhii53EmQgDAfDcBpFekYSlO0fGytMQwRiMQCA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.20.0 + '@typescript-eslint/types': 5.21.0 eslint-visitor-keys: 3.3.0 dev: true @@ -2861,11 +2893,11 @@ packages: resolution: {integrity: sha512-hz4R8tS5jMn8lDq6iD+yWL6XNB699pGIVLk7WSJnn1dbpjaazsjZQkieJoRX6gW5zpYSCFqQ7jUquPNY65tQYA==} dev: false - /@vue/babel-plugin-jsx/1.1.1_@babel+core@7.17.9: + /@vue/babel-plugin-jsx/1.1.1_@babel+core@7.17.10: resolution: {integrity: sha512-j2uVfZjnB5+zkcbc/zsOc0fSNGCMMjaEXP52wdwdIfn0qjFfEYpYZBFKFg+HHnQeJCVrjOeO0YxgaL7DMrym9w==} dependencies: '@babel/helper-module-imports': 7.16.0 - '@babel/plugin-syntax-jsx': 7.16.5_@babel+core@7.17.9 + '@babel/plugin-syntax-jsx': 7.16.5_@babel+core@7.17.10 '@babel/template': 7.16.0 '@babel/traverse': 7.16.5 '@babel/types': 7.16.0 @@ -2897,7 +2929,7 @@ packages: /@vue/compiler-core/3.2.33: resolution: {integrity: sha512-AAmr52ji3Zhk7IKIuigX2osWWsb2nQE5xsdFYjdnmtQ4gymmqXbjLvkSE174+fF3A3kstYrTgGkqgOEbsdLDpw==} dependencies: - '@babel/parser': 7.17.9 + '@babel/parser': 7.17.10 '@vue/shared': 3.2.33 estree-walker: 2.0.2 source-map: 0.6.1 @@ -3137,12 +3169,12 @@ packages: acorn-walk: 7.2.0 dev: true - /acorn-jsx/5.3.2_acorn@8.7.0: + /acorn-jsx/5.3.2_acorn@8.7.1: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: - acorn: 8.7.0 + acorn: 8.7.1 dev: true /acorn-node/1.8.2: @@ -3173,6 +3205,12 @@ packages: hasBin: true dev: true + /acorn/8.7.1: + resolution: {integrity: sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==} + engines: {node: '>=0.4.0'} + hasBin: true + dev: true + /add-stream/1.0.0: resolution: {integrity: sha1-anmQQ3ynNtXhKI25K9MmbV9csqo=} dev: true @@ -3530,6 +3568,18 @@ packages: node-releases: 2.0.1 picocolors: 1.0.0 + /browserslist/4.20.3: + resolution: {integrity: sha512-NBhymBQl1zM0Y5dQT/O+xiLP9/rzOIQdKM/eMJBAq7yBgaB6krIYLGejrwVYnSHZdqjscB1SPuAjHwxjvN6Wdg==} + engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} + hasBin: true + dependencies: + caniuse-lite: 1.0.30001334 + electron-to-chromium: 1.4.129 + escalade: 3.1.1 + node-releases: 2.0.4 + picocolors: 1.0.0 + dev: false + /bs-logger/0.2.6: resolution: {integrity: sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==} engines: {node: '>= 6'} @@ -3614,6 +3664,10 @@ packages: /caniuse-lite/1.0.30001294: resolution: {integrity: sha512-LiMlrs1nSKZ8qkNhpUf5KD0Al1KCBE3zaT7OLOwEkagXMEDij98SiOovn9wxVGQpklk9vVC/pUSqgYmkmKOS8g==} + /caniuse-lite/1.0.30001334: + resolution: {integrity: sha512-kbaCEBRRVSoeNs74sCuq92MJyGrMtjWVfhltoHUCW4t4pXFvGjUBrfo47weBRViHkiV3eBYyIsfl956NtHGazw==} + dev: false + /chalk/2.4.2: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} engines: {node: '>=4'} @@ -4093,8 +4147,8 @@ packages: is-what: 3.14.1 dev: true - /core-js/3.22.2: - resolution: {integrity: sha512-Z5I2vzDnEIqO2YhELVMFcL1An2CIsFe9Q7byZhs8c/QxummxZlAHw33TUHbIte987LkisOgL0LwQ1P9D6VISnA==} + /core-js/3.22.3: + resolution: {integrity: sha512-1t+2a/d2lppW1gkLXx3pKPVGbBdxXAkqztvWb1EJ8oF8O2gIGiytzflNiFEehYwVK/t2ryUsGBoOFFvNx95mbg==} requiresBuild: true dev: false @@ -4470,6 +4524,10 @@ packages: resolution: {integrity: sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=} dev: true + /electron-to-chromium/1.4.129: + resolution: {integrity: sha512-GgtN6bsDtHdtXJtlMYZWGB/uOyjZWjmRDumXTas7dGBaB9zUyCjzHet1DY2KhyHN8R0GLbzZWqm4efeddqqyRQ==} + dev: false + /electron-to-chromium/1.4.29: resolution: {integrity: sha512-N2Jbwxo5Rum8G2YXeUxycs1sv4Qme/ry71HG73bv8BvZl+I/4JtRgK/En+ST/Wh/yF1fqvVCY4jZBgMxnhjtBA==} @@ -4804,25 +4862,25 @@ packages: engines: {node: '>= 14.6.0', npm: '>= 6.0.0', pnpm: '>= 6.32.9'} dev: true - /eslint-plugin-es/3.0.1_eslint@8.13.0: + /eslint-plugin-es/3.0.1_eslint@8.14.0: resolution: {integrity: sha512-GUmAsJaN4Fc7Gbtl8uOBlayo2DqhwWvEzykMHSCZHU3XdJ+NSzzZcVhXh3VxX5icqQ+oQdIEawXX8xkR3mIFmQ==} engines: {node: '>=8.10.0'} peerDependencies: eslint: '>=4.19.1' dependencies: - eslint: 8.13.0 + eslint: 8.14.0 eslint-utils: 2.1.0 regexpp: 3.2.0 dev: true - /eslint-plugin-node/11.1.0_eslint@8.13.0: + /eslint-plugin-node/11.1.0_eslint@8.14.0: resolution: {integrity: sha512-oUwtPJ1W0SKD0Tr+wqu92c5xuCeQqB3hSCHasn/ZgjFdA9iDGNkNf2Zi9ztY7X+hNuMib23LNGRm6+uN+KLE3g==} engines: {node: '>=8.10.0'} peerDependencies: eslint: '>=5.16.0' dependencies: - eslint: 8.13.0 - eslint-plugin-es: 3.0.1_eslint@8.13.0 + eslint: 8.14.0 + eslint-plugin-es: 3.0.1_eslint@8.14.0 eslint-utils: 2.1.0 ignore: 5.2.0 minimatch: 3.0.4 @@ -4853,13 +4911,13 @@ packages: eslint-visitor-keys: 1.3.0 dev: true - /eslint-utils/3.0.0_eslint@8.13.0: + /eslint-utils/3.0.0_eslint@8.14.0: resolution: {integrity: sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==} engines: {node: ^10.0.0 || ^12.0.0 || >= 14.0.0} peerDependencies: eslint: '>=5' dependencies: - eslint: 8.13.0 + eslint: 8.14.0 eslint-visitor-keys: 2.1.0 dev: true @@ -4878,12 +4936,12 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /eslint/8.13.0: - resolution: {integrity: sha512-D+Xei61eInqauAyTJ6C0q6x9mx7kTUC1KZ0m0LSEexR0V+e94K12LmWX076ZIsldwfQ2RONdaJe0re0TRGQbRQ==} + /eslint/8.14.0: + resolution: {integrity: sha512-3/CE4aJX7LNEiE3i6FeodHmI/38GZtWCsAtsymScmzYapx8q1nVVb+eLcLSzATmCPXw5pT4TqVs1E0OmxAd9tw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} hasBin: true dependencies: - '@eslint/eslintrc': 1.2.1 + '@eslint/eslintrc': 1.2.2 '@humanwhocodes/config-array': 0.9.2 ajv: 6.12.6 chalk: 4.1.2 @@ -4892,7 +4950,7 @@ packages: doctrine: 3.0.0 escape-string-regexp: 4.0.0 eslint-scope: 7.1.1 - eslint-utils: 3.0.0_eslint@8.13.0 + eslint-utils: 3.0.0_eslint@8.14.0 eslint-visitor-keys: 3.3.0 espree: 9.3.1 esquery: 1.4.0 @@ -4926,8 +4984,8 @@ packages: resolution: {integrity: sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - acorn: 8.7.0 - acorn-jsx: 5.3.2_acorn@8.7.0 + acorn: 8.7.1 + acorn-jsx: 5.3.2_acorn@8.7.1 eslint-visitor-keys: 3.3.0 dev: true @@ -5619,13 +5677,13 @@ packages: resolution: {integrity: sha1-Bupvg2ead0njhs/h/oEq5dsiPe0=} dev: true - /icss-utils/5.1.0_postcss@8.4.12: + /icss-utils/5.1.0_postcss@8.4.13: resolution: {integrity: sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==} engines: {node: ^10 || ^12 || >= 14} peerDependencies: postcss: ^8.1.0 dependencies: - postcss: 8.4.12 + postcss: 8.4.13 dev: true /ignore/5.2.0: @@ -6505,7 +6563,7 @@ packages: optional: true dependencies: abab: 2.0.5 - acorn: 8.7.0 + acorn: 8.7.1 acorn-globals: 6.0.0 cssom: 0.4.4 cssstyle: 2.3.0 @@ -6673,8 +6731,8 @@ packages: /lines-and-columns/1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} - /lint-staged/12.4.0: - resolution: {integrity: sha512-3X7MR0h9b7qf4iXf/1n7RlVAx+EzpAZXoCEMhVSpaBlgKDfH2ewf+QUm7BddFyq29v4dgPP+8+uYpWuSWx035A==} + /lint-staged/12.4.1: + resolution: {integrity: sha512-PTXgzpflrQ+pODQTG116QNB+Q6uUTDg5B5HqGvNhoQSGt8Qy+MA/6zSnR8n38+sxP5TapzeQGTvoKni0KRS8Vg==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} hasBin: true dependencies: @@ -6785,6 +6843,10 @@ packages: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} dev: true + /lodash.sortby/4.7.0: + resolution: {integrity: sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=} + dev: true + /lodash.topath/4.5.2: resolution: {integrity: sha1-NhY1Hzu6YZlKCTGYlmC9AyVP0Ak=} dev: false @@ -7104,6 +7166,12 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true + /nanoid/3.3.3: + resolution: {integrity: sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + dev: false + /natural-compare/1.4.0: resolution: {integrity: sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=} dev: true @@ -7179,6 +7247,10 @@ packages: /node-releases/2.0.1: resolution: {integrity: sha512-CqyzN6z7Q6aMeF/ktcMVTzhAHCEpf8SOarwpzpf8pNBY2k5/oM34UHldUwp8VKI7uxct2HxSRdJjBaZeESzcxA==} + /node-releases/2.0.4: + resolution: {integrity: sha512-gbMzqQtTtDz/00jQzZ21PQzdI9PyLYqUSvD0p3naOhX4odFji0ZxYdnVwPTxmSwkmxhcFImpozceidSG+AgoPQ==} + dev: false + /nopt/5.0.0: resolution: {integrity: sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==} engines: {node: '>=6'} @@ -7615,13 +7687,13 @@ packages: engines: {node: '>=12.13.0'} dev: true - /postcss-import/14.1.0_postcss@8.4.12: + /postcss-import/14.1.0_postcss@8.4.13: resolution: {integrity: sha512-flwI+Vgm4SElObFVPpTIT7SU7R3qk2L7PyduMcokiaVKuWv9d/U+Gm/QAd8NDLuykTWTkcrjOeD2Pp1rMeBTGw==} engines: {node: '>=10.0.0'} peerDependencies: postcss: ^8.0.0 dependencies: - postcss: 8.4.12 + postcss: 8.4.13 postcss-value-parser: 4.2.0 read-cache: 1.0.0 resolve: 1.22.0 @@ -7677,7 +7749,7 @@ packages: yaml: 1.10.2 dev: false - /postcss-load-config/3.1.4_postcss@8.4.12+ts-node@10.4.0: + /postcss-load-config/3.1.4_postcss@8.4.13+ts-node@10.4.0: resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==} engines: {node: '>= 10'} peerDependencies: @@ -7690,53 +7762,53 @@ packages: optional: true dependencies: lilconfig: 2.0.5 - postcss: 8.4.12 + postcss: 8.4.13 ts-node: 10.4.0_233d9fcfccc8abc8f146a08357d842da yaml: 1.10.2 dev: true - /postcss-modules-extract-imports/3.0.0_postcss@8.4.12: + /postcss-modules-extract-imports/3.0.0_postcss@8.4.13: resolution: {integrity: sha512-bdHleFnP3kZ4NYDhuGlVK+CMrQ/pqUm8bx/oGL93K6gVwiclvX5x0n76fYMKuIGKzlABOy13zsvqjb0f92TEXw==} engines: {node: ^10 || ^12 || >= 14} peerDependencies: postcss: ^8.1.0 dependencies: - postcss: 8.4.12 + postcss: 8.4.13 dev: true - /postcss-modules-local-by-default/4.0.0_postcss@8.4.12: + /postcss-modules-local-by-default/4.0.0_postcss@8.4.13: resolution: {integrity: sha512-sT7ihtmGSF9yhm6ggikHdV0hlziDTX7oFoXtuVWeDd3hHObNkcHRo9V3yg7vCAY7cONyxJC/XXCmmiHHcvX7bQ==} engines: {node: ^10 || ^12 || >= 14} peerDependencies: postcss: ^8.1.0 dependencies: - icss-utils: 5.1.0_postcss@8.4.12 - postcss: 8.4.12 + icss-utils: 5.1.0_postcss@8.4.13 + postcss: 8.4.13 postcss-selector-parser: 6.0.8 postcss-value-parser: 4.2.0 dev: true - /postcss-modules-scope/3.0.0_postcss@8.4.12: + /postcss-modules-scope/3.0.0_postcss@8.4.13: resolution: {integrity: sha512-hncihwFA2yPath8oZ15PZqvWGkWf+XUfQgUGamS4LqoP1anQLOsOJw0vr7J7IwLpoY9fatA2qiGUGmuZL0Iqlg==} engines: {node: ^10 || ^12 || >= 14} peerDependencies: postcss: ^8.1.0 dependencies: - postcss: 8.4.12 + postcss: 8.4.13 postcss-selector-parser: 6.0.8 dev: true - /postcss-modules-values/4.0.0_postcss@8.4.12: + /postcss-modules-values/4.0.0_postcss@8.4.13: resolution: {integrity: sha512-RDxHkAiEGI78gS2ofyvCsu7iycRv7oqw5xMWn9iMoR0N/7mf9D50ecQqUo5BZ9Zh2vH4bCUR/ktCqbB9m8vJjQ==} engines: {node: ^10 || ^12 || >= 14} peerDependencies: postcss: ^8.1.0 dependencies: - icss-utils: 5.1.0_postcss@8.4.12 - postcss: 8.4.12 + icss-utils: 5.1.0_postcss@8.4.13 + postcss: 8.4.13 dev: true - /postcss-modules/4.3.1_postcss@8.4.12: + /postcss-modules/4.3.1_postcss@8.4.13: resolution: {integrity: sha512-ItUhSUxBBdNamkT3KzIZwYNNRFKmkJrofvC2nWab3CPKhYBQ1f27XXh1PAPE27Psx58jeelPsxWB/+og+KEH0Q==} peerDependencies: postcss: ^8.0.0 @@ -7744,11 +7816,11 @@ packages: generic-names: 4.0.0 icss-replace-symbols: 1.1.0 lodash.camelcase: 4.3.0 - postcss: 8.4.12 - postcss-modules-extract-imports: 3.0.0_postcss@8.4.12 - postcss-modules-local-by-default: 4.0.0_postcss@8.4.12 - postcss-modules-scope: 3.0.0_postcss@8.4.12 - postcss-modules-values: 4.0.0_postcss@8.4.12 + postcss: 8.4.13 + postcss-modules-extract-imports: 3.0.0_postcss@8.4.13 + postcss-modules-local-by-default: 4.0.0_postcss@8.4.13 + postcss-modules-scope: 3.0.0_postcss@8.4.13 + postcss-modules-values: 4.0.0_postcss@8.4.13 string-hash: 1.1.3 dev: true @@ -7800,6 +7872,15 @@ packages: picocolors: 1.0.0 source-map-js: 1.0.2 + /postcss/8.4.13: + resolution: {integrity: sha512-jtL6eTBrza5MPzy8oJLFuUscHDXTV5KcLlqAWHl5q5WYRfnNRGSmOZmOZ1T6Gy7A99mOZfqungmZMpMmCVJ8ZA==} + engines: {node: ^10 || ^12 || >=14} + dependencies: + nanoid: 3.3.3 + picocolors: 1.0.0 + source-map-js: 1.0.2 + dev: false + /postcss/8.4.5: resolution: {integrity: sha512-jBDboWM8qpaqwkMwItqTQTiFikhs/67OYVvblFFTM7MrZjt6yMKd6r2kgXizEbTTljacm4NldIlZnhbjr84QYg==} engines: {node: ^10 || ^12 || >=14} @@ -8096,8 +8177,8 @@ packages: resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==} dev: true - /react-refresh/0.12.0: - resolution: {integrity: sha512-suLIhrU2IHKL5JEKR/fAwJv7bbeq4kJ+pJopf77jHwuR+HmJS/HbrPIGsTBUVfw7tXPOmYv7UJ7PCaN49e8x4A==} + /react-refresh/0.13.0: + resolution: {integrity: sha512-XP8A9BT0CpRBD+NYLLeIhld/RqG9+gktUjW1FkE+Vm7OCinbG1SshcK5tb9ls4kzvjZr9mOQc7HYgBngEyPAXg==} engines: {node: '>=0.10.0'} dev: false @@ -8392,7 +8473,7 @@ packages: /rxjs/7.5.2: resolution: {integrity: sha512-PwDt186XaL3QN5qXj/H9DGyHhP3/RYYgZZwqBv9Tv8rsAaiwFH1IsJJlcgD37J7UW5a6O67qX0KWKS3/pu0m4w==} dependencies: - tslib: 2.3.1 + tslib: 2.4.0 dev: true /safe-buffer/5.1.2: @@ -8671,6 +8752,13 @@ packages: engines: {node: '>= 8'} dev: true + /source-map/0.8.0-beta.0: + resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==} + engines: {node: '>= 8'} + dependencies: + whatwg-url: 7.1.0 + dev: true + /sourcemap-codec/1.4.8: resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==} @@ -9090,14 +9178,14 @@ packages: supports-hyperlinks: 2.2.0 dev: true - /terser/5.12.1: - resolution: {integrity: sha512-NXbs+7nisos5E+yXwAD+y7zrcTkMqb0dEJxIGtSKPdCBzopf7ni4odPul2aechpV7EXNvOudYOX2bb5tln1jbQ==} + /terser/5.13.1: + resolution: {integrity: sha512-hn4WKOfwnwbYfe48NgrQjqNOH9jzLqRcIfbYytOXCOv46LBfWr9bDS17MQqOi+BWGD0sJK3Sj5NC/gJjiojaoA==} engines: {node: '>=10'} hasBin: true dependencies: - acorn: 8.7.0 + acorn: 8.7.1 commander: 2.20.3 - source-map: 0.7.3 + source-map: 0.8.0-beta.0 source-map-support: 0.5.21 dev: true @@ -9203,6 +9291,12 @@ packages: /tr46/0.0.3: resolution: {integrity: sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=} + /tr46/1.0.1: + resolution: {integrity: sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=} + dependencies: + punycode: 2.1.1 + dev: true + /tr46/2.1.0: resolution: {integrity: sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw==} engines: {node: '>=8'} @@ -9307,6 +9401,10 @@ packages: resolution: {integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==} dev: true + /tslib/2.4.0: + resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} + dev: true + /tsutils/3.21.0_typescript@4.5.4: resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} @@ -9389,6 +9487,12 @@ packages: hasBin: true dev: true + /typescript/4.6.4: + resolution: {integrity: sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==} + engines: {node: '>=4.2.0'} + hasBin: true + dev: true + /typeson-registry/1.0.0-alpha.39: resolution: {integrity: sha512-NeGDEquhw+yfwNhguLPcZ9Oj0fzbADiX4R0WxvoY8nGhy98IbzQy1sezjoEFWOywOboj/DWehI+/aUlRVrJnnw==} engines: {node: '>=10.0.0'} @@ -9626,6 +9730,10 @@ packages: /webidl-conversions/3.0.1: resolution: {integrity: sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=} + /webidl-conversions/4.0.2: + resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==} + dev: true + /webidl-conversions/5.0.0: resolution: {integrity: sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==} engines: {node: '>=8'} @@ -9652,6 +9760,14 @@ packages: tr46: 0.0.3 webidl-conversions: 3.0.1 + /whatwg-url/7.1.0: + resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==} + dependencies: + lodash.sortby: 4.7.0 + tr46: 1.0.1 + webidl-conversions: 4.0.2 + dev: true + /whatwg-url/8.7.0: resolution: {integrity: sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==} engines: {node: '>=10'} @@ -9767,8 +9883,8 @@ packages: optional: true dev: true - /ws/8.5.0: - resolution: {integrity: sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==} + /ws/8.6.0: + resolution: {integrity: sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==} engines: {node: '>=10.0.0'} peerDependencies: bufferutil: ^4.0.1 From cf8a48a6c8b3b1f9ef2a2cf41765d456f85c6cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Mon, 2 May 2022 16:41:05 +0900 Subject: [PATCH 019/114] fix(css): inline css module when ssr, minify issue (fix #5471) (#7807) --- packages/playground/css/__tests__/css.spec.ts | 10 ++++++++- packages/vite/src/node/plugins/css.ts | 22 +++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/playground/css/__tests__/css.spec.ts b/packages/playground/css/__tests__/css.spec.ts index 6ca00e760349b1..9869bb34d2c690 100644 --- a/packages/playground/css/__tests__/css.spec.ts +++ b/packages/playground/css/__tests__/css.spec.ts @@ -15,7 +15,11 @@ import { // in later assertions to ensure CSS HMR doesn't reload the page test('imported css', async () => { const css = await page.textContent('.imported-css') - expect(css).toContain('.imported {') + expect(css).toMatch(/\.imported ?{/) + if (isBuild) { + expect(css.trim()).not.toContain('\n') // check minified + } + const glob = await page.textContent('.imported-css-glob') expect(glob).toContain('.dir-import') const globEager = await page.textContent('.imported-css-globEager') @@ -372,6 +376,10 @@ test('inlined-code', async () => { // should resolve assets expect(code).toContain('background:') expect(code).not.toContain('__VITE_ASSET__') + + if (isBuild) { + expect(code.trim()).not.toContain('\n') // check minified + } }) test('minify css', async () => { diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index b3ea3338cecc04..9ead17822d23a9 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -300,11 +300,17 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { return } + const isHTMLProxy = htmlProxyRE.test(id) const inlined = inlineRE.test(id) const modules = cssModulesCache.get(config)!.get(id) - const isHTMLProxy = htmlProxyRE.test(id) + + // #6984, #7552 + // `foo.module.css` => modulesCode + // `foo.module.css?inline` => cssContent const modulesCode = - modules && dataToEsm(modules, { namedExports: true, preferConst: true }) + modules && + !inlined && + dataToEsm(modules, { namedExports: true, preferConst: true }) if (config.command === 'serve') { if (isDirectCSSRequest(id)) { @@ -366,12 +372,14 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { let code: string if (usedRE.test(id)) { - if (inlined) { - code = `export default ${JSON.stringify( - await minifyCSS(css, config) - )}` + if (modulesCode) { + code = modulesCode } else { - code = modulesCode || `export default ${JSON.stringify(css)}` + let content = css + if (config.build.minify) { + content = await minifyCSS(content, config) + } + code = `export default ${JSON.stringify(content)}` } } else { code = `export default ''` From bf40e5c88db4281b035f67d1789cccf66333ce23 Mon Sep 17 00:00:00 2001 From: xyl66 <492113976@qq.com> Date: Mon, 2 May 2022 17:25:24 +0800 Subject: [PATCH 020/114] fix(plugin-react): React is not defined when component name is lowercase (#6838) --- .../src/jsx-runtime/restore-jsx.spec.ts | 55 +++++++++++++++++++ .../src/jsx-runtime/restore-jsx.ts | 42 ++++++++------ 2 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts new file mode 100644 index 00000000000000..adbd7a60599c25 --- /dev/null +++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts @@ -0,0 +1,55 @@ +import { restoreJSX } from './restore-jsx' +import * as babel from '@babel/core' + +async function jsx(sourceCode: string) { + const [ast] = await restoreJSX(babel, sourceCode, 'test.js') + if (ast === null) { + return ast + } + const { code } = await babel.transformFromAstAsync(ast, null, { + configFile: false + }) + return code +} +// jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react'; +// React__default.createElement(Foo)`) +// Tests adapted from: https://github.com/flying-sheep/babel-plugin-transform-react-createelement-to-jsx/blob/63137b6/test/index.js +describe('restore-jsx', () => { + it('should trans to ', async () => { + expect( + await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react'; + React__default.createElement(foo)`) + ).toBeNull() + expect( + await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react'; + React__default.createElement("h1")`) + ).toMatch(`

;`) + expect( + await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react'; + React__default.createElement(Foo)`) + ).toMatch(`;`) + expect( + await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react'; + React__default.createElement(Foo.Bar)`) + ).toMatch(`;`) + expect( + await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react'; + React__default.createElement(Foo.Bar.Baz)`) + ).toMatch(`;`) + }) + + it('should handle props', async () => { + expect( + await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react'; + React__default.createElement(foo, {hi: there})`) + ).toBeNull() + expect( + await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react'; + React__default.createElement("h1", {hi: there})`) + ).toMatch(`

;`) + expect( + await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react'; + React__default.createElement(Foo, {hi: there})`) + ).toMatch(`;`) + }) +}) diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts index 268153f4ba5d45..dbc2218d2343ff 100644 --- a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts +++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts @@ -20,32 +20,42 @@ export async function restoreJSX( } const [reactAlias, isCommonJS] = parseReactAlias(code) + if (!reactAlias) { return jsxNotFound } - const reactJsxRE = new RegExp( - '\\b' + reactAlias + '\\.(createElement|Fragment)\\b', - 'g' - ) - let hasCompiledJsx = false - code = code.replace(reactJsxRE, (_, prop) => { - hasCompiledJsx = true - // Replace with "React" so JSX can be reverse compiled. - return 'React.' + prop - }) + + const fragmentPattern = `\\b${reactAlias}\\.Fragment\\b` + const createElementPattern = `\\b${reactAlias}\\.createElement\\(\\s*([A-Z"'][\\w$.]*["']?)` + + // Replace the alias with "React" so JSX can be reverse compiled. + code = code + .replace(new RegExp(fragmentPattern, 'g'), () => { + hasCompiledJsx = true + return 'React.Fragment' + }) + .replace(new RegExp(createElementPattern, 'g'), (original, component) => { + if (/^[a-z][\w$]*$/.test(component)) { + // Take care not to replace the alias for `createElement` calls whose + // component is a lowercased variable, since the `restoreJSX` Babel + // plugin leaves them untouched. + return original + } + hasCompiledJsx = true + return ( + 'React.createElement(' + + // Assume `Fragment` is equivalent to `React.Fragment` so modules + // that use `import {Fragment} from 'react'` are reverse compiled. + (component === 'Fragment' ? 'React.Fragment' : component) + ) + }) if (!hasCompiledJsx) { return jsxNotFound } - // Support modules that use `import {Fragment} from 'react'` - code = code.replace( - /createElement\(Fragment,/g, - 'createElement(React.Fragment,' - ) - babelRestoreJSX ||= import('./babel-restore-jsx') const result = await babel.transformAsync(code, { From d58c03088c2eed33417866b46238070fbaffa0f2 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 2 May 2022 15:49:50 +0200 Subject: [PATCH 021/114] chore: update license --- packages/vite/LICENSE.md | 56 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index ccff3f1508a73b..30803708e30a76 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -237,6 +237,33 @@ Repository: git+https://github.com/ampproject/remapping.git --------------------------------------- +## @jridgewell/gen-mapping +License: MIT +By: Justin Ridgewell +Repository: https://github.com/jridgewell/gen-mapping + +> Copyright 2022 Justin Ridgewell +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. + +--------------------------------------- + ## @jridgewell/resolve-uri License: MIT By: Justin Ridgewell @@ -264,6 +291,33 @@ Repository: https://github.com/jridgewell/resolve-uri --------------------------------------- +## @jridgewell/set-array +License: MIT +By: Justin Ridgewell +Repository: https://github.com/jridgewell/set-array + +> Copyright 2022 Justin Ridgewell +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. + +--------------------------------------- + ## @jridgewell/sourcemap-codec License: MIT By: Rich Harris @@ -577,7 +631,7 @@ Repository: https://github.com/acornjs/acorn.git > MIT License > -> Copyright (C) 2012-2020 by various contributors (see AUTHORS) +> Copyright (C) 2012-2022 by various contributors (see AUTHORS) > > Permission is hereby granted, free of charge, to any person obtaining a copy > of this software and associated documentation files (the "Software"), to deal From dde774f0e42dc24ccec7a4710cc842a12f0d785d Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 2 May 2022 15:51:28 +0200 Subject: [PATCH 022/114] release: v2.9.7 --- packages/vite/CHANGELOG.md | 20 ++++++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index c2dc1488d84b21..db8bf085dc04f6 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,23 @@ +## 2.9.7 (2022-05-02) + +* chore: update license ([d58c030](https://github.com/vitejs/vite/commit/d58c030)) +* chore(css): catch postcss config error (fix #2793) (#7934) ([7f535ac](https://github.com/vitejs/vite/commit/7f535ac)), closes [#2793](https://github.com/vitejs/vite/issues/2793) [#7934](https://github.com/vitejs/vite/issues/7934) +* chore(deps): update all non-major dependencies (#7949) ([b877d30](https://github.com/vitejs/vite/commit/b877d30)), closes [#7949](https://github.com/vitejs/vite/issues/7949) +* fix: inject esbuild helpers in IIFE and UMD wrappers (#7948) ([f7d2d71](https://github.com/vitejs/vite/commit/f7d2d71)), closes [#7948](https://github.com/vitejs/vite/issues/7948) +* fix: inline css hash (#7974) ([f6ae60d](https://github.com/vitejs/vite/commit/f6ae60d)), closes [#7974](https://github.com/vitejs/vite/issues/7974) +* fix: inline style hmr, transform style code inplace (#7869) ([a30a548](https://github.com/vitejs/vite/commit/a30a548)), closes [#7869](https://github.com/vitejs/vite/issues/7869) +* fix: use NODE_ENV in optimizer (#7673) ([50672e4](https://github.com/vitejs/vite/commit/50672e4)), closes [#7673](https://github.com/vitejs/vite/issues/7673) +* fix(css): clean comments before hoist at rules (#7924) ([e48827f](https://github.com/vitejs/vite/commit/e48827f)), closes [#7924](https://github.com/vitejs/vite/issues/7924) +* fix(css): dynamic import css in package fetches removed js (fixes #7955, #6823) (#7969) ([025eebf](https://github.com/vitejs/vite/commit/025eebf)), closes [#7955](https://github.com/vitejs/vite/issues/7955) [#6823](https://github.com/vitejs/vite/issues/6823) [#7969](https://github.com/vitejs/vite/issues/7969) +* fix(css): inline css module when ssr, minify issue (fix #5471) (#7807) ([cf8a48a](https://github.com/vitejs/vite/commit/cf8a48a)), closes [#5471](https://github.com/vitejs/vite/issues/5471) [#7807](https://github.com/vitejs/vite/issues/7807) +* fix(css): sourcemap crash with postcss (#7982) ([7f9f8f1](https://github.com/vitejs/vite/commit/7f9f8f1)), closes [#7982](https://github.com/vitejs/vite/issues/7982) +* fix(css): support postcss.config.ts (#7935) ([274c10e](https://github.com/vitejs/vite/commit/274c10e)), closes [#7935](https://github.com/vitejs/vite/issues/7935) +* fix(ssr): failed ssrLoadModule call throws same error (#7177) ([891e7fc](https://github.com/vitejs/vite/commit/891e7fc)), closes [#7177](https://github.com/vitejs/vite/issues/7177) +* fix(worker): import.meta.* (#7706) ([b092697](https://github.com/vitejs/vite/commit/b092697)), closes [#7706](https://github.com/vitejs/vite/issues/7706) +* docs: `server.origin` config trailing slash (fix #6622) (#7865) ([5c1ee5a](https://github.com/vitejs/vite/commit/5c1ee5a)), closes [#6622](https://github.com/vitejs/vite/issues/6622) [#7865](https://github.com/vitejs/vite/issues/7865) + + + ## 2.9.6 (2022-04-26) * fix: `apply` condition skipped for nested plugins (#7741) ([1f2ca53](https://github.com/vitejs/vite/commit/1f2ca53)), closes [#7741](https://github.com/vitejs/vite/issues/7741) diff --git a/packages/vite/package.json b/packages/vite/package.json index 39b95bbab97769..3720837d3a5afc 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.9.6", + "version": "2.9.7", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From f8930432134b8ac556d088b92b812e79c7258940 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 2 May 2022 15:52:58 +0200 Subject: [PATCH 023/114] release: plugin-legacy@1.8.2 --- packages/plugin-legacy/CHANGELOG.md | 9 +++++++++ packages/plugin-legacy/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/plugin-legacy/CHANGELOG.md b/packages/plugin-legacy/CHANGELOG.md index 5c00212554ce8c..035460b5816cb5 100644 --- a/packages/plugin-legacy/CHANGELOG.md +++ b/packages/plugin-legacy/CHANGELOG.md @@ -1,3 +1,12 @@ +## 1.8.2 (2022-05-02) + +* chore(deps): update all non-major dependencies (#7780) ([eba9d05](https://github.com/vitejs/vite/commit/eba9d05)), closes [#7780](https://github.com/vitejs/vite/issues/7780) +* chore(deps): update all non-major dependencies (#7847) ([e29d1d9](https://github.com/vitejs/vite/commit/e29d1d9)), closes [#7847](https://github.com/vitejs/vite/issues/7847) +* chore(deps): update all non-major dependencies (#7949) ([b877d30](https://github.com/vitejs/vite/commit/b877d30)), closes [#7949](https://github.com/vitejs/vite/issues/7949) +* refactor(legacy): remove unneeded dynamic import var init code (#7759) ([12a4e7d](https://github.com/vitejs/vite/commit/12a4e7d)), closes [#7759](https://github.com/vitejs/vite/issues/7759) + + + ## 1.8.1 (2022-04-13) * fix(deps): update all non-major dependencies (#7668) ([485263c](https://github.com/vitejs/vite/commit/485263c)), closes [#7668](https://github.com/vitejs/vite/issues/7668) diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index 1ba92ee5fd8565..948bbb152ce56f 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-legacy", - "version": "1.8.1", + "version": "1.8.2", "license": "MIT", "author": "Evan You", "files": [ From 968ff695d8ddc7e31285699cf4526a324417ef17 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 2 May 2022 15:54:00 +0200 Subject: [PATCH 024/114] release: plugin-react@1.3.2 --- packages/plugin-react/CHANGELOG.md | 8 ++++++++ packages/plugin-react/package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/plugin-react/CHANGELOG.md b/packages/plugin-react/CHANGELOG.md index 958c8270b6f221..01dfee3feb7ffb 100644 --- a/packages/plugin-react/CHANGELOG.md +++ b/packages/plugin-react/CHANGELOG.md @@ -1,3 +1,11 @@ +## 1.3.2 (2022-05-02) + +* fix(plugin-react): React is not defined when component name is lowercase (#6838) ([bf40e5c](https://github.com/vitejs/vite/commit/bf40e5c)), closes [#6838](https://github.com/vitejs/vite/issues/6838) +* chore(deps): update all non-major dependencies (#7780) ([eba9d05](https://github.com/vitejs/vite/commit/eba9d05)), closes [#7780](https://github.com/vitejs/vite/issues/7780) +* chore(deps): update all non-major dependencies (#7949) ([b877d30](https://github.com/vitejs/vite/commit/b877d30)), closes [#7949](https://github.com/vitejs/vite/issues/7949) + + + ## 1.3.1 (2022-04-13) * fix(deps): update all non-major dependencies (#7668) ([485263c](https://github.com/vitejs/vite/commit/485263c)), closes [#7668](https://github.com/vitejs/vite/issues/7668) diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json index 5698472c9dc113..4c8280a3a5ff9a 100644 --- a/packages/plugin-react/package.json +++ b/packages/plugin-react/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-react", - "version": "1.3.1", + "version": "1.3.2", "license": "MIT", "author": "Evan You", "contributors": [ From 2b6d8fec25961b34e2bfcf776be0fb4e499b4cf9 Mon Sep 17 00:00:00 2001 From: Nicolas Hedger <649677+nhedger@users.noreply.github.com> Date: Mon, 2 May 2022 20:36:19 +0200 Subject: [PATCH 025/114] chore(create-vite): update reference to volar vscode extension (#7994) --- packages/create-vite/template-vue-ts/.vscode/extensions.json | 2 +- packages/create-vite/template-vue-ts/README.md | 2 +- packages/create-vite/template-vue/.vscode/extensions.json | 2 +- packages/create-vite/template-vue/README.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/create-vite/template-vue-ts/.vscode/extensions.json b/packages/create-vite/template-vue-ts/.vscode/extensions.json index 3dc5b08bcdc96b..a7cea0b0678120 100644 --- a/packages/create-vite/template-vue-ts/.vscode/extensions.json +++ b/packages/create-vite/template-vue-ts/.vscode/extensions.json @@ -1,3 +1,3 @@ { - "recommendations": ["johnsoncodehk.volar"] + "recommendations": ["Vue.volar"] } diff --git a/packages/create-vite/template-vue-ts/README.md b/packages/create-vite/template-vue-ts/README.md index e432516724c1a7..30b15e215a24b7 100644 --- a/packages/create-vite/template-vue-ts/README.md +++ b/packages/create-vite/template-vue-ts/README.md @@ -4,7 +4,7 @@ This template should help get you started developing with Vue 3 and TypeScript i ## Recommended IDE Setup -- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) +- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) ## Type Support For `.vue` Imports in TS diff --git a/packages/create-vite/template-vue/.vscode/extensions.json b/packages/create-vite/template-vue/.vscode/extensions.json index 3dc5b08bcdc96b..a7cea0b0678120 100644 --- a/packages/create-vite/template-vue/.vscode/extensions.json +++ b/packages/create-vite/template-vue/.vscode/extensions.json @@ -1,3 +1,3 @@ { - "recommendations": ["johnsoncodehk.volar"] + "recommendations": ["Vue.volar"] } diff --git a/packages/create-vite/template-vue/README.md b/packages/create-vite/template-vue/README.md index eea15cef41ea60..02124a7a0a92bc 100644 --- a/packages/create-vite/template-vue/README.md +++ b/packages/create-vite/template-vue/README.md @@ -4,4 +4,4 @@ This template should help get you started developing with Vue 3 in Vite. The tem ## Recommended IDE Setup -- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) +- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) From 1db7c4939a4c589854bb7a3a85002a8f3c42a50c Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 2 May 2022 21:30:44 +0200 Subject: [PATCH 026/114] release: create-vite@2.9.3 --- packages/create-vite/CHANGELOG.md | 7 +++++++ packages/create-vite/package.json | 2 +- packages/create-vite/template-lit-ts/package.json | 2 +- packages/create-vite/template-lit/package.json | 2 +- packages/create-vite/template-preact-ts/package.json | 2 +- packages/create-vite/template-preact/package.json | 2 +- packages/create-vite/template-react-ts/package.json | 2 +- packages/create-vite/template-react/package.json | 2 +- packages/create-vite/template-svelte-ts/package.json | 2 +- packages/create-vite/template-svelte/package.json | 2 +- packages/create-vite/template-vanilla-ts/package.json | 2 +- packages/create-vite/template-vanilla/package.json | 2 +- packages/create-vite/template-vue-ts/package.json | 2 +- packages/create-vite/template-vue/package.json | 2 +- 14 files changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/create-vite/CHANGELOG.md b/packages/create-vite/CHANGELOG.md index 7379feb81239b8..d8759a4e269c97 100644 --- a/packages/create-vite/CHANGELOG.md +++ b/packages/create-vite/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2.9.3 (2022-05-02) + +* chore(create-vite): update reference to volar vscode extension (#7994) ([2b6d8fe](https://github.com/vitejs/vite/commit/2b6d8fe)), closes [#7994](https://github.com/vitejs/vite/issues/7994) +* feat(create-vite): scaffold directory with only .git (#7971) ([a5bdb9f](https://github.com/vitejs/vite/commit/a5bdb9f)), closes [#7971](https://github.com/vitejs/vite/issues/7971) + + + ## 2.9.2 (2022-04-19) * chore: remove useless code in preact template (#7789) ([e5729be](https://github.com/vitejs/vite/commit/e5729be)), closes [#7789](https://github.com/vitejs/vite/issues/7789) diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index 5a21b499d9b75d..b78537705cc14d 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -1,6 +1,6 @@ { "name": "create-vite", - "version": "2.9.2", + "version": "2.9.3", "license": "MIT", "author": "Evan You", "bin": { diff --git a/packages/create-vite/template-lit-ts/package.json b/packages/create-vite/template-lit-ts/package.json index eb6849d447795c..640e57b3f46089 100644 --- a/packages/create-vite/template-lit-ts/package.json +++ b/packages/create-vite/template-lit-ts/package.json @@ -19,7 +19,7 @@ "lit": "^2.0.2" }, "devDependencies": { - "vite": "^2.9.5", + "vite": "^2.9.7", "typescript": "^4.5.4" } } diff --git a/packages/create-vite/template-lit/package.json b/packages/create-vite/template-lit/package.json index 6fc110706147f7..2b413a7effa6be 100644 --- a/packages/create-vite/template-lit/package.json +++ b/packages/create-vite/template-lit/package.json @@ -17,6 +17,6 @@ "lit": "^2.0.2" }, "devDependencies": { - "vite": "^2.9.5" + "vite": "^2.9.7" } } diff --git a/packages/create-vite/template-preact-ts/package.json b/packages/create-vite/template-preact-ts/package.json index ac90637925896f..36c4e2ae644331 100644 --- a/packages/create-vite/template-preact-ts/package.json +++ b/packages/create-vite/template-preact-ts/package.json @@ -13,6 +13,6 @@ "devDependencies": { "@preact/preset-vite": "^2.1.5", "typescript": "^4.5.4", - "vite": "^2.9.5" + "vite": "^2.9.7" } } diff --git a/packages/create-vite/template-preact/package.json b/packages/create-vite/template-preact/package.json index f58b6525abaa52..655779377aba28 100644 --- a/packages/create-vite/template-preact/package.json +++ b/packages/create-vite/template-preact/package.json @@ -12,6 +12,6 @@ }, "devDependencies": { "@preact/preset-vite": "^2.1.5", - "vite": "^2.9.5" + "vite": "^2.9.7" } } diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index 01d981f51c3414..76d8f3d637fabd 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -16,6 +16,6 @@ "@types/react-dom": "^18.0.0", "@vitejs/plugin-react": "^1.3.0", "typescript": "^4.6.3", - "vite": "^2.9.5" + "vite": "^2.9.7" } } diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index 4215fdea104c30..ee8097d84cd7d9 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -15,6 +15,6 @@ "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", "@vitejs/plugin-react": "^1.3.0", - "vite": "^2.9.5" + "vite": "^2.9.7" } } diff --git a/packages/create-vite/template-svelte-ts/package.json b/packages/create-vite/template-svelte-ts/package.json index ae5bf6219d8eee..f415446fa1a2a0 100644 --- a/packages/create-vite/template-svelte-ts/package.json +++ b/packages/create-vite/template-svelte-ts/package.json @@ -17,6 +17,6 @@ "svelte-preprocess": "^4.9.8", "tslib": "^2.3.1", "typescript": "^4.5.4", - "vite": "^2.9.5" + "vite": "^2.9.7" } } diff --git a/packages/create-vite/template-svelte/package.json b/packages/create-vite/template-svelte/package.json index ac224a274d1c10..f64e5f186ac840 100644 --- a/packages/create-vite/template-svelte/package.json +++ b/packages/create-vite/template-svelte/package.json @@ -11,6 +11,6 @@ "devDependencies": { "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30", "svelte": "^3.44.0", - "vite": "^2.9.5" + "vite": "^2.9.7" } } diff --git a/packages/create-vite/template-vanilla-ts/package.json b/packages/create-vite/template-vanilla-ts/package.json index 94a8ccc952012a..09d074177c401c 100644 --- a/packages/create-vite/template-vanilla-ts/package.json +++ b/packages/create-vite/template-vanilla-ts/package.json @@ -9,6 +9,6 @@ }, "devDependencies": { "typescript": "^4.5.4", - "vite": "^2.9.5" + "vite": "^2.9.7" } } diff --git a/packages/create-vite/template-vanilla/package.json b/packages/create-vite/template-vanilla/package.json index ddc9844be1954f..e5eb1951cb04be 100644 --- a/packages/create-vite/template-vanilla/package.json +++ b/packages/create-vite/template-vanilla/package.json @@ -8,6 +8,6 @@ "preview": "vite preview" }, "devDependencies": { - "vite": "^2.9.5" + "vite": "^2.9.7" } } diff --git a/packages/create-vite/template-vue-ts/package.json b/packages/create-vite/template-vue-ts/package.json index c7383d48b09e3b..5072c666e52172 100644 --- a/packages/create-vite/template-vue-ts/package.json +++ b/packages/create-vite/template-vue-ts/package.json @@ -13,7 +13,7 @@ "devDependencies": { "@vitejs/plugin-vue": "^2.3.1", "typescript": "^4.5.4", - "vite": "^2.9.5", + "vite": "^2.9.7", "vue-tsc": "^0.34.7" } } diff --git a/packages/create-vite/template-vue/package.json b/packages/create-vite/template-vue/package.json index e7e9b681db608c..fe24b608b6c401 100644 --- a/packages/create-vite/template-vue/package.json +++ b/packages/create-vite/template-vue/package.json @@ -12,6 +12,6 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^2.3.1", - "vite": "^2.9.5" + "vite": "^2.9.7" } } From e96b90887d4709ed1c968b658e22fbdfdb996cbb Mon Sep 17 00:00:00 2001 From: fishDog <40156382+Bigfish8@users.noreply.github.com> Date: Tue, 3 May 2022 13:44:28 +0800 Subject: [PATCH 027/114] fix(css): var in image-set (#7921) --- .../assets/__tests__/assets.spec.ts | 23 +++++++++++++++ packages/playground/assets/css/css-url.css | 23 +++++++++++++++ packages/playground/assets/index.html | 28 ++++++++++++++++++ packages/vite/src/node/plugins/css.ts | 29 ++++++++++++++----- packages/vite/src/node/utils.ts | 13 +++++---- 5 files changed, 103 insertions(+), 13 deletions(-) diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index 19dd52f71e114a..f1075f6fe1cb39 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -104,6 +104,29 @@ describe('css url() references', () => { }) }) + test('image-set with var', async () => { + const imageSet = await getBg('.css-image-set-with-var') + imageSet.split(', ').forEach((s) => { + expect(s).toMatch(assetMatch) + }) + }) + + test('image-set with mix', async () => { + const imageSet = await getBg('.css-image-set-mix-url-var') + imageSet.split(', ').forEach((s) => { + expect(s).toMatch(assetMatch) + }) + }) + + // not supported in browser now + // https://drafts.csswg.org/css-images-4/#image-set-notation + // test('image-set with multiple descriptor', async () => { + // const imageSet = await getBg('.css-image-set-multiple-descriptor') + // imageSet.split(', ').forEach((s) => { + // expect(s).toMatch(assetMatch) + // }) + // }) + test('relative in @import', async () => { expect(await getBg('.css-url-relative-at-imported')).toMatch(assetMatch) }) diff --git a/packages/playground/assets/css/css-url.css b/packages/playground/assets/css/css-url.css index 8a3f00dee17bd9..9047cd384e7d38 100644 --- a/packages/playground/assets/css/css-url.css +++ b/packages/playground/assets/css/css-url.css @@ -26,6 +26,29 @@ background-size: 10px; } +.css-image-set-with-var { + --bg-img: url('../nested/asset.png'); + background-image: -webkit-image-set(var(--bg-img) 1x, var(--bg-img) 2x); + background-size: 10px; +} + +.css-image-set-mix-url-var { + --bg-img: url('../nested/asset.png'); + background-image: -webkit-image-set( + var(--bg-img) 1x, + url('../nested/asset.png') 2x + ); + background-size: 10px; +} + +.css-image-set-multiple-descriptor { + background-image: -webkit-image-set( + '../nested/asset.png' type('image/png') 1x, + '../nested/asset.png' type('image/png') 2x + ); + background-size: 10px; +} + .css-url-public { background: url('/icon.png'); background-size: 10px; diff --git a/packages/playground/assets/index.html b/packages/playground/assets/index.html index 99c2c2fe69ae70..43eed55236abd3 100644 --- a/packages/playground/assets/index.html +++ b/packages/playground/assets/index.html @@ -46,6 +46,34 @@

CSS url references

>CSS background with image-set() (relative)

+
+ + CSS background image-set() (relative in var) + +
+
+ + CSS background image-set() (mix var and url) + +
+
+ + CSS background image-set() (with multiple descriptor) + +
+
+ + CSS background image-set() (with multiple descriptor) + +
CSS background (relative from @imported file in different dir) { @@ -1054,11 +1057,15 @@ function rewriteCssImageSet( replacer: CssUrlReplacer ): Promise { return asyncReplace(css, cssImageSetRE, async (match) => { - const [matched, rawUrl] = match - const url = await processSrcSet(rawUrl, ({ url }) => - doUrlReplace(url, matched, replacer) - ) - return `image-set(${url})` + const [, rawUrl] = match + const url = await processSrcSet(rawUrl, async ({ url }) => { + // the url maybe url(...) + if (cssUrlRE.test(url)) { + return await rewriteCssUrls(url, replacer) + } + return await doUrlReplace(url, url, replacer) + }) + return url }) } async function doUrlReplace( @@ -1073,7 +1080,13 @@ async function doUrlReplace( wrap = first rawUrl = rawUrl.slice(1, -1) } - if (isExternalUrl(rawUrl) || isDataUrl(rawUrl) || rawUrl.startsWith('#')) { + + if ( + isExternalUrl(rawUrl) || + isDataUrl(rawUrl) || + rawUrl.startsWith('#') || + varRE.test(rawUrl) + ) { return matched } diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index e7a20afbdd5ae7..32b783974dacaf 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -545,6 +545,7 @@ interface ImageCandidate { descriptor: string } const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g +const imageSetUrlRE = /^(?:[\w\-]+\(.*?\)|'.*?'|".*?"|\S*)/ export async function processSrcSet( srcs: string, replacer: (arg: ImageCandidate) => Promise @@ -552,11 +553,13 @@ export async function processSrcSet( const imageCandidates: ImageCandidate[] = srcs .split(',') .map((s) => { - const [url, descriptor] = s - .replace(escapedSpaceCharacters, ' ') - .trim() - .split(' ', 2) - return { url, descriptor } + const src = s.replace(escapedSpaceCharacters, ' ').trim() + const [url] = imageSetUrlRE.exec(src) || [] + + return { + url, + descriptor: src?.slice(url.length).trim() + } }) .filter(({ url }) => !!url) From 749e96f0dcf171795c62eb612b2ad6db5606363c Mon Sep 17 00:00:00 2001 From: Zheeeng Date: Tue, 3 May 2022 15:55:03 +0800 Subject: [PATCH 028/114] chore: fix ts checking on used-before-assigned (#6939) --- scripts/jestPerTestSetup.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/jestPerTestSetup.ts b/scripts/jestPerTestSetup.ts index f4c9db03627c7c..098784ae76c2af 100644 --- a/scripts/jestPerTestSetup.ts +++ b/scripts/jestPerTestSetup.ts @@ -243,14 +243,15 @@ function startStaticServer(config?: InlineConfig): Promise { export async function notifyRebuildComplete( watcher: RollupWatcher ): Promise { - let callback: (event: RollupWatcherEvent) => void - await new Promise((resolve, reject) => { - callback = (event) => { - if (event.code === 'END') { - resolve() - } + let resolveFn: undefined | (() => void) + const callback = (event: RollupWatcherEvent): void => { + if (event.code === 'END') { + resolveFn?.() } - watcher.on('event', callback) + } + watcher.on('event', callback) + await new Promise((resolve) => { + resolveFn = resolve }) return watcher.removeListener('event', callback) } From f1af9416a1123c617675ca0165ac401486b636dc Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 4 May 2022 02:43:32 +0800 Subject: [PATCH 029/114] chore: restore-jsx.spec.ts lint (#8004) --- packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts index adbd7a60599c25..c216e99bc3480d 100644 --- a/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts +++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts @@ -3,7 +3,7 @@ import * as babel from '@babel/core' async function jsx(sourceCode: string) { const [ast] = await restoreJSX(babel, sourceCode, 'test.js') - if (ast === null) { + if (ast == null) { return ast } const { code } = await babel.transformFromAstAsync(ast, null, { From 642d65ba6190a87a2f4d534f545672a1a0f10f1c Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 4 May 2022 02:46:10 +0800 Subject: [PATCH 030/114] fix: only handle merge ssr.noExternal (#8003) --- .../vite/src/node/__tests__/config.spec.ts | 24 +++++++++++++++++++ packages/vite/src/node/config.ts | 6 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/__tests__/config.spec.ts b/packages/vite/src/node/__tests__/config.spec.ts index dd427c19433475..ca7a2e76122cd0 100644 --- a/packages/vite/src/node/__tests__/config.spec.ts +++ b/packages/vite/src/node/__tests__/config.spec.ts @@ -157,6 +157,30 @@ describe('mergeConfig', () => { expect(mergeConfig(baseConfig, newConfig)).toEqual(mergedConfig) }) + + test('handles ssr.noExternal', () => { + const baseConfig = { + ssr: { + noExternal: true + } + } + + const newConfig = { + ssr: { + noExternal: ['foo'] + } + } + + const mergedConfig = { + ssr: { + noExternal: true + } + } + + // merging either ways, `ssr.noExternal: true` should take highest priority + expect(mergeConfig(baseConfig, newConfig)).toEqual(mergedConfig) + expect(mergeConfig(newConfig, baseConfig)).toEqual(mergedConfig) + }) }) describe('resolveConfig', () => { diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 27a107f3e2098c..531fe169f72de0 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -745,7 +745,11 @@ function mergeConfigRecursively( } else if (key === 'assetsInclude' && rootPath === '') { merged[key] = [].concat(existing, value) continue - } else if (key === 'noExternal' && (existing === true || value === true)) { + } else if ( + key === 'noExternal' && + rootPath === 'ssr' && + (existing === true || value === true) + ) { merged[key] = true continue } From f3d15f106f378c3850b62fbebd69fc8f7c7f944b Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 4 May 2022 02:48:11 +0800 Subject: [PATCH 031/114] refactor(plugin-vue): remove querystring import (#7997) --- packages/plugin-vue/src/main.ts | 5 ++--- packages/plugin-vue/src/utils/query.ts | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index 44b1de74721efd..d4417548e2e40c 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -1,4 +1,3 @@ -import qs from 'querystring' import path from 'path' import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc' import type { ResolvedOptions } from '.' @@ -426,8 +425,8 @@ function attrsToQuery( for (const name in attrs) { const value = attrs[name] if (!ignoreList.includes(name)) { - query += `&${qs.escape(name)}${ - value ? `=${qs.escape(String(value))}` : `` + query += `&${encodeURIComponent(name)}${ + value ? `=${encodeURIComponent(value)}` : `` }` } } diff --git a/packages/plugin-vue/src/utils/query.ts b/packages/plugin-vue/src/utils/query.ts index d41cb1be2cf536..060b5f28987bfa 100644 --- a/packages/plugin-vue/src/utils/query.ts +++ b/packages/plugin-vue/src/utils/query.ts @@ -1,5 +1,3 @@ -import qs from 'querystring' - export interface VueQuery { vue?: boolean src?: string @@ -14,7 +12,7 @@ export function parseVueRequest(id: string): { query: VueQuery } { const [filename, rawQuery] = id.split(`?`, 2) - const query = qs.parse(rawQuery) as VueQuery + const query = Object.fromEntries(new URLSearchParams(rawQuery)) as VueQuery if (query.vue != null) { query.vue = true } From d49e3fbfc0227e2e00ffc4a8d4152135c5cd6bb8 Mon Sep 17 00:00:00 2001 From: Saurabh Daware Date: Wed, 4 May 2022 10:32:09 +0530 Subject: [PATCH 032/114] fix: inline js and css paths for virtual html (#7993) Co-authored-by: yoho Co-authored-by: patak-dev --- packages/playground/ssr-html/server.js | 31 ++++++++-- .../src/node/server/middlewares/indexHtml.ts | 57 ++++++++++++++----- 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/packages/playground/ssr-html/server.js b/packages/playground/ssr-html/server.js index ad115f1be01163..1f2cd5331c0157 100644 --- a/packages/playground/ssr-html/server.js +++ b/packages/playground/ssr-html/server.js @@ -14,6 +14,14 @@ const DYNAMIC_SCRIPTS = ` ` +const DYNAMIC_STYLES = ` + +` + async function createServer( root = process.cwd(), isProd = process.env.NODE_ENV === 'production' @@ -42,15 +50,30 @@ async function createServer( // use vite's connect instance as middleware app.use(vite.middlewares) - app.use('*', async (req, res) => { + app.use('*', async (req, res, next) => { try { let [url] = req.originalUrl.split('?') if (url.endsWith('/')) url += 'index.html' + if (url.startsWith('/favicon.ico')) { + return res.status(404).end('404') + } + if (url.startsWith('/@id/__x00__')) { + return next() + } + const htmlLoc = resolve(`.${url}`) - let html = fs.readFileSync(htmlLoc, 'utf8') - html = html.replace('', `${DYNAMIC_SCRIPTS}`) - html = await vite.transformIndexHtml(url, html) + let template = fs.readFileSync(htmlLoc, 'utf-8') + + template = template.replace( + '', + `${DYNAMIC_SCRIPTS}${DYNAMIC_STYLES}` + ) + + // Force calling transformIndexHtml with url === '/', to simulate + // usage by ecosystem that was recommended in the SSR documentation + // as `const url = req.originalUrl` + const html = await vite.transformIndexHtml('/', template) res.status(200).set({ 'Content-Type': 'text/html' }).end(html) } catch (e) { diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 8638492b1c2001..955ee6b708f54d 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -1,6 +1,7 @@ import fs from 'fs' import path from 'path' import MagicString from 'magic-string' +import type { SourceMapInput } from 'rollup' import type { AttributeNode, ElementNode, TextNode } from '@vue/compiler-dom' import { NodeTypes } from '@vue/compiler-dom' import type { Connect } from 'types/connect' @@ -15,7 +16,12 @@ import { } from '../../plugins/html' import type { ResolvedConfig, ViteDevServer } from '../..' import { send } from '../send' -import { CLIENT_PUBLIC_PATH, FS_PREFIX } from '../../constants' +import { + CLIENT_PUBLIC_PATH, + FS_PREFIX, + VALID_ID_PREFIX, + NULL_BYTE_PLACEHOLDER +} from '../../constants' import { cleanUrl, fsPathFromId, @@ -108,32 +114,53 @@ const devHtmlHook: IndexHtmlTransformHook = async ( const { config, moduleGraph, watcher } = server! const base = config.base || '/' + let proxyModulePath: string + let proxyModuleUrl: string + + const trailingSlash = htmlPath.endsWith('/') + if (!trailingSlash && fs.existsSync(filename)) { + proxyModulePath = htmlPath + proxyModuleUrl = base + htmlPath.slice(1) + } else { + // There are users of vite.transformIndexHtml calling it with url '/' + // for SSR integrations #7993, filename is root for this case + // A user may also use a valid name for a virtual html file + // Mark the path as virtual in both cases so sourcemaps aren't processed + // and ids are properly handled + const validPath = `${htmlPath}${trailingSlash ? 'index.html' : ''}` + proxyModulePath = `\0${validPath}` + proxyModuleUrl = `${VALID_ID_PREFIX}${NULL_BYTE_PLACEHOLDER}${validPath}` + } + const s = new MagicString(html) let inlineModuleIndex = -1 - const filePath = cleanUrl(htmlPath) + const proxyCacheUrl = cleanUrl(proxyModulePath).replace( + normalizePath(config.root), + '' + ) const styleUrl: AssetNode[] = [] const addInlineModule = (node: ElementNode, ext: 'js') => { inlineModuleIndex++ - const url = filePath.replace(normalizePath(config.root), '') - const contentNode = node.children[0] as TextNode const code = contentNode.content - const map = new MagicString(html) - .snip(contentNode.loc.start.offset, contentNode.loc.end.offset) - .generateMap({ hires: true }) - map.sources = [filename] - map.file = filename + + let map: SourceMapInput | undefined + if (!proxyModulePath.startsWith('\0')) { + map = new MagicString(html) + .snip(contentNode.loc.start.offset, contentNode.loc.end.offset) + .generateMap({ hires: true }) + map.sources = [filename] + map.file = filename + } // add HTML Proxy to Map - addToHTMLProxyCache(config, url, inlineModuleIndex, { code, map }) + addToHTMLProxyCache(config, proxyCacheUrl, inlineModuleIndex, { code, map }) // inline js module. convert to src="proxy" - const modulePath = `${ - config.base + htmlPath.slice(1) - }?html-proxy&index=${inlineModuleIndex}.${ext}` + const modulePath = `${proxyModuleUrl}?html-proxy&index=${inlineModuleIndex}.${ext}` // invalidate the module so the newly cached contents will be served const module = server?.moduleGraph.getModuleById(modulePath) @@ -190,13 +217,13 @@ const devHtmlHook: IndexHtmlTransformHook = async ( await Promise.all( styleUrl.map(async ({ start, end, code }, index) => { - const url = filename + `?html-proxy&${index}.css` + const url = `${proxyModulePath}?html-proxy&index=${index}.css` // ensure module in graph after successful load const mod = await moduleGraph.ensureEntryFromUrl(url, false) ensureWatchedFile(watcher, mod.file, config.root) - const result = await server!.pluginContainer.transform(code, url) + const result = await server!.pluginContainer.transform(code, mod.id!) s.overwrite(start, end, result?.code || '') }) ) From 72f17f89296d6b2373fb05edcc01959f30c551d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 4 May 2022 17:50:44 +0900 Subject: [PATCH 033/114] fix(css): do not clean id when passing to postcss (fix #7822) (#7827) --- packages/playground/css/__tests__/css.spec.ts | 10 ++++++++++ packages/playground/css/index.html | 3 +++ packages/playground/css/main.js | 3 +++ packages/playground/css/postcss-source-input.css | 1 + packages/playground/css/postcss.config.js | 15 ++++++++++++++- packages/vite/src/node/plugins/css.ts | 4 ++-- 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 packages/playground/css/postcss-source-input.css diff --git a/packages/playground/css/__tests__/css.spec.ts b/packages/playground/css/__tests__/css.spec.ts index 9869bb34d2c690..e666ca40517d57 100644 --- a/packages/playground/css/__tests__/css.spec.ts +++ b/packages/playground/css/__tests__/css.spec.ts @@ -413,3 +413,13 @@ test("relative path rewritten in Less's data-uri", async () => { /^url\("data:image\/svg\+xml,%3Csvg/ ) }) + +test('PostCSS source.input.from includes query', async () => { + const code = await page.textContent('.postcss-source-input') + // should resolve assets + expect(code).toContain( + isBuild + ? '/postcss-source-input.css?used&query=foo' + : '/postcss-source-input.css?query=foo' + ) +}) diff --git a/packages/playground/css/index.html b/packages/playground/css/index.html index fef6a0be393748..15e81192cec7f1 100644 --- a/packages/playground/css/index.html +++ b/packages/playground/css/index.html @@ -135,6 +135,9 @@

CSS

Raw Support


+
+  

PostCSS source.input.from. Should include query

+

 
diff --git a/packages/playground/css/main.js b/packages/playground/css/main.js index 0d03aafbf0ec7f..f728b0251066d1 100644 --- a/packages/playground/css/main.js +++ b/packages/playground/css/main.js @@ -87,3 +87,6 @@ Promise.all(Object.keys(glob).map((key) => glob[key]())).then((res) => { // globEager const globEager = import.meta.globEager('./glob-import/*.css') text('.imported-css-globEager', JSON.stringify(globEager, null, 2)) + +import postcssSourceInput from './postcss-source-input.css?query=foo' +text('.postcss-source-input', postcssSourceInput) diff --git a/packages/playground/css/postcss-source-input.css b/packages/playground/css/postcss-source-input.css new file mode 100644 index 00000000000000..c6c3cb0c16dece --- /dev/null +++ b/packages/playground/css/postcss-source-input.css @@ -0,0 +1 @@ +@source-input; diff --git a/packages/playground/css/postcss.config.js b/packages/playground/css/postcss.config.js index f3d6ac9548b6a9..e90b4f9c987820 100644 --- a/packages/playground/css/postcss.config.js +++ b/packages/playground/css/postcss.config.js @@ -1,5 +1,5 @@ module.exports = { - plugins: [require('postcss-nested'), testDirDep] + plugins: [require('postcss-nested'), testDirDep, testSourceInput] } const fs = require('fs') @@ -35,3 +35,16 @@ function testDirDep() { } } testDirDep.postcss = true + +function testSourceInput() { + return { + postcssPlugin: 'source-input', + AtRule(atRule) { + if (atRule.name === 'source-input') { + atRule.after(`/* ${atRule.source.input.from} */`) + atRule.remove() + } + } + } +} +testSourceInput.postcss = true diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 04c4ebeea95332..cd57acd1690902 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -799,8 +799,8 @@ async function compileCSS( .default(postcssPlugins) .process(code, { ...postcssOptions, - to: cleanUrl(id), - from: cleanUrl(id), + to: id, + from: id, map: { inline: false, annotation: false, From 6420ba0d7d3823aeb6c46c1136e740b6d15f18a3 Mon Sep 17 00:00:00 2001 From: Yoshi Togami <62130798+togami2864@users.noreply.github.com> Date: Wed, 4 May 2022 17:51:27 +0900 Subject: [PATCH 034/114] fix(ssr): allow ssrTransform to parse hashbang (#8005) --- .../node/ssr/__tests__/ssrTransform.spec.ts | 21 +++++++++++++++++-- packages/vite/src/node/ssr/ssrTransform.ts | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts index 14481f98a4a87a..0e9181214c2b82 100644 --- a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts +++ b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts @@ -370,7 +370,7 @@ test('overwrite bindings', async () => { `const a = { inject }\n` + `const b = { test: inject }\n` + `function c() { const { test: inject } = { test: true }; console.log(inject) }\n` + - `const d = inject \n` + + `const d = inject\n` + `function f() { console.log(inject) }\n` + `function e() { const { inject } = { inject: true } }\n` + `function g() { const f = () => { const inject = true }; console.log(inject) }\n`, @@ -383,7 +383,7 @@ test('overwrite bindings', async () => { const a = { inject: __vite_ssr_import_0__.inject } const b = { test: __vite_ssr_import_0__.inject } function c() { const { test: inject } = { test: true }; console.log(inject) } - const d = __vite_ssr_import_0__.inject + const d = __vite_ssr_import_0__.inject function f() { console.log(__vite_ssr_import_0__.inject) } function e() { const { inject } = { inject: true } } function g() { const f = () => { const inject = true }; console.log(__vite_ssr_import_0__.inject) } @@ -719,3 +719,20 @@ export default (function getRandom() { (await ssrTransform(`export default (class A {});`, null, null)).code ).toMatchInlineSnapshot(`"__vite_ssr_exports__.default = (class A {});"`) }) + +// #8002 +test('with hashbang', async () => { + expect( + ( + await ssrTransform( + `#!/usr/bin/env node +console.log("it can parse the hashbang")`, + null, + null + ) + ).code + ).toMatchInlineSnapshot(` + "#!/usr/bin/env node + console.log(\\"it can parse the hashbang\\")" + `) +}) diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts index 238482a0ceac2f..c1aa572864776a 100644 --- a/packages/vite/src/node/ssr/ssrTransform.ts +++ b/packages/vite/src/node/ssr/ssrTransform.ts @@ -37,7 +37,8 @@ export async function ssrTransform( ast = parser.parse(code, { sourceType: 'module', ecmaVersion: 'latest', - locations: true + locations: true, + allowHashBang: true }) } catch (err) { if (!err.loc || !err.loc.line) throw err From e85164ecb07e32bf3bc49ae33c7bd9ba3065482d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 4 May 2022 18:05:18 +0900 Subject: [PATCH 035/114] chore: remove maybeVirtualHtmlSet (#8010) --- packages/vite/src/node/plugins/html.ts | 4 ---- packages/vite/src/node/server/sourcemap.ts | 4 +--- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index c33811008ccb17..bf3d662066630b 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -722,8 +722,6 @@ export function resolveHtmlTransforms( return [preHooks, postHooks] } -export const maybeVirtualHtmlSet = new Set() - export async function applyHtmlTransforms( html: string, hooks: IndexHtmlTransformHook[], @@ -734,8 +732,6 @@ export async function applyHtmlTransforms( const bodyTags: HtmlTagDescriptor[] = [] const bodyPrependTags: HtmlTagDescriptor[] = [] - maybeVirtualHtmlSet.add(ctx.filename) - for (const hook of hooks) { const res = await hook(html, ctx) if (!res) { diff --git a/packages/vite/src/node/server/sourcemap.ts b/packages/vite/src/node/server/sourcemap.ts index 0b9bcf9284754b..88cbafc344c739 100644 --- a/packages/vite/src/node/server/sourcemap.ts +++ b/packages/vite/src/node/server/sourcemap.ts @@ -1,9 +1,8 @@ import path from 'path' import { promises as fs } from 'fs' import type { Logger } from '../logger' -import { createDebugger, normalizePath } from '../utils' +import { createDebugger } from '../utils' import type { SourceMap } from 'rollup' -import { maybeVirtualHtmlSet } from '../plugins/html' const isDebug = !!process.env.DEBUG const debug = createDebugger('vite:sourcemap', { @@ -43,7 +42,6 @@ export async function injectSourcesContent( sourcePath = path.resolve(sourceRoot, sourcePath) } return fs.readFile(sourcePath, 'utf-8').catch(() => { - if (maybeVirtualHtmlSet.has(normalizePath(sourcePath))) return null missingSources.push(sourcePath) return null }) From 67c86dee44f18425bff6c1b1d36ab7f7d56f758b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 4 May 2022 18:30:46 +0900 Subject: [PATCH 036/114] test(css): fix postcss cleanid test (#8013) --- packages/playground/css/postcss.config.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/playground/css/postcss.config.js b/packages/playground/css/postcss.config.js index e90b4f9c987820..33058023541515 100644 --- a/packages/playground/css/postcss.config.js +++ b/packages/playground/css/postcss.config.js @@ -41,7 +41,11 @@ function testSourceInput() { postcssPlugin: 'source-input', AtRule(atRule) { if (atRule.name === 'source-input') { - atRule.after(`/* ${atRule.source.input.from} */`) + atRule.after( + `.source-input::before { content: ${JSON.stringify( + atRule.source.input.from + )}; }` + ) atRule.remove() } } From 0861adec967b692e41ae19dd09a264cf582f3a5e Mon Sep 17 00:00:00 2001 From: patak Date: Wed, 4 May 2022 12:05:56 +0200 Subject: [PATCH 037/114] chore: use pnpm@6 in netlify (#8011) --- netlify.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify.toml b/netlify.toml index ba9d1c55f567c5..ba62bdbe4d6be1 100644 --- a/netlify.toml +++ b/netlify.toml @@ -3,4 +3,4 @@ NPM_FLAGS = "--version" # prevent Netlify npm install [build] publish = "docs/.vitepress/dist" - command = "npx pnpm i --store=node_modules/.pnpm-store && npm run ci-docs" \ No newline at end of file + command = "npx pnpm@6 i --store=node_modules/.pnpm-store --frozen-lockfile && npx pnpm@6 run ci-docs" \ No newline at end of file From 99740949b77509c442a27fb0e017fcbe376f3391 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 4 May 2022 22:32:06 +0800 Subject: [PATCH 038/114] feat: import ts with .js in vue (#7998) --- packages/playground/vue-jsx/TsImport.vue | 8 ++++++++ packages/playground/vue-jsx/TsImportFile.ts | 1 + packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts | 1 + packages/playground/vue-jsx/main.jsx | 2 ++ packages/playground/vue/Main.vue | 2 ++ packages/playground/vue/TsImport.vue | 8 ++++++++ packages/playground/vue/TsImportFile.ts | 1 + packages/playground/vue/__tests__/vue.spec.ts | 4 ++++ packages/plugin-vue/src/main.ts | 5 +++++ packages/vite/src/node/plugins/resolve.ts | 11 +++++++++-- packages/vite/src/node/utils.ts | 2 +- 11 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 packages/playground/vue-jsx/TsImport.vue create mode 100644 packages/playground/vue-jsx/TsImportFile.ts create mode 100644 packages/playground/vue/TsImport.vue create mode 100644 packages/playground/vue/TsImportFile.ts diff --git a/packages/playground/vue-jsx/TsImport.vue b/packages/playground/vue-jsx/TsImport.vue new file mode 100644 index 00000000000000..c63923d51947fa --- /dev/null +++ b/packages/playground/vue-jsx/TsImport.vue @@ -0,0 +1,8 @@ + + + diff --git a/packages/playground/vue-jsx/TsImportFile.ts b/packages/playground/vue-jsx/TsImportFile.ts new file mode 100644 index 00000000000000..62761d5733b432 --- /dev/null +++ b/packages/playground/vue-jsx/TsImportFile.ts @@ -0,0 +1 @@ +export const foo = 'success' diff --git a/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts b/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts index 999fdc19af51ec..275c918684119d 100644 --- a/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts +++ b/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts @@ -9,6 +9,7 @@ test('should render', async () => { expect(await page.textContent('.src-import')).toMatch('5') expect(await page.textContent('.jsx-with-query')).toMatch('6') expect(await page.textContent('.other-ext')).toMatch('Other Ext') + expect(await page.textContent('.ts-import')).toMatch('success') }) test('should update', async () => { diff --git a/packages/playground/vue-jsx/main.jsx b/packages/playground/vue-jsx/main.jsx index e304e7788e49e7..f13e60c45367c0 100644 --- a/packages/playground/vue-jsx/main.jsx +++ b/packages/playground/vue-jsx/main.jsx @@ -7,6 +7,7 @@ import JsxSrcImport from './SrcImport.vue' import JsxSetupSyntax from './setup-syntax-jsx.vue' // eslint-disable-next-line import JsxWithQuery from './Query.jsx?query=true' +import TsImport from './TsImport.vue' function App() { return ( @@ -20,6 +21,7 @@ function App() { + ) } diff --git a/packages/playground/vue/Main.vue b/packages/playground/vue/Main.vue index 87319acdf6f736..c5f3d27402fda7 100644 --- a/packages/playground/vue/Main.vue +++ b/packages/playground/vue/Main.vue @@ -15,6 +15,7 @@
this should be red
+ @@ -33,6 +34,7 @@ import CustomBlock from './CustomBlock.vue' import SrcImport from './src-import/SrcImport.vue' import Slotted from './Slotted.vue' import ScanDep from './ScanDep.vue' +import TsImport from './TsImport.vue' import AsyncComponent from './AsyncComponent.vue' import ReactivityTransform from './ReactivityTransform.vue' import SetupImportTemplate from './setup-import-template/SetupImportTemplate.vue' diff --git a/packages/playground/vue/TsImport.vue b/packages/playground/vue/TsImport.vue new file mode 100644 index 00000000000000..986c383b2b9f4b --- /dev/null +++ b/packages/playground/vue/TsImport.vue @@ -0,0 +1,8 @@ + + + diff --git a/packages/playground/vue/TsImportFile.ts b/packages/playground/vue/TsImportFile.ts new file mode 100644 index 00000000000000..62761d5733b432 --- /dev/null +++ b/packages/playground/vue/TsImportFile.ts @@ -0,0 +1 @@ +export const foo = 'success' diff --git a/packages/playground/vue/__tests__/vue.spec.ts b/packages/playground/vue/__tests__/vue.spec.ts index 025c05f53e8688..0bce5d1e1a03f5 100644 --- a/packages/playground/vue/__tests__/vue.spec.ts +++ b/packages/playground/vue/__tests__/vue.spec.ts @@ -14,6 +14,10 @@ test('template/script latest syntax support', async () => { expect(await page.textContent('.syntax')).toBe('baz') }) +test('import ts with .js extension with lang="ts"', async () => { + expect(await page.textContent('.ts-import')).toBe('success') +}) + test('should remove comments in prod', async () => { expect(await page.innerHTML('.comments')).toBe(isBuild ? `` : ``) }) diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index d4417548e2e40c..1b24856be1ecab 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -211,6 +211,11 @@ export async function transformMain( code: resolvedCode, map: resolvedMap || { mappings: '' + }, + meta: { + vite: { + lang: descriptor.script?.lang || descriptor.scriptSetup?.lang || 'js' + } } } } diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 1b59503a9d43ed..98a2cd8a9f776e 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -128,12 +128,19 @@ export function resolvePlugin(baseOptions: InternalResolveOptions): Plugin { const options: InternalResolveOptions = { isRequire, - ...baseOptions, - isFromTsImporter: isTsRequest(importer ?? ''), scan: resolveOpts?.scan ?? baseOptions.scan } + if (importer) { + if (isTsRequest(importer)) { + options.isFromTsImporter = true + } else { + const moduleLang = this.getModuleInfo(importer)?.meta?.vite?.lang + options.isFromTsImporter = moduleLang && isTsRequest(`.${moduleLang}`) + } + } + let res: string | PartialResolvedId | undefined // resolve pre-bundled deps requests, these could be resolved by diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 32b783974dacaf..688e4c0f9cd44d 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -228,7 +228,7 @@ export const isJSRequest = (url: string): boolean => { const knownTsRE = /\.(ts|mts|cts|tsx)$/ const knownTsOutputRE = /\.(js|mjs|cjs|jsx)$/ -export const isTsRequest = (url: string) => knownTsRE.test(cleanUrl(url)) +export const isTsRequest = (url: string) => knownTsRE.test(url) export const isPossibleTsOutput = (url: string) => knownTsOutputRE.test(cleanUrl(url)) export function getPotentialTsSrcPaths(filePath: string) { From e5fe1c65203a3509e096baeed1ef176d21f93851 Mon Sep 17 00:00:00 2001 From: patak Date: Wed, 4 May 2022 18:35:58 +0200 Subject: [PATCH 039/114] fix: optimized processing folder renaming in win (fix #7939) (#8019) --- packages/vite/src/node/optimizer/index.ts | 23 ++++----- .../src/node/optimizer/registerMissing.ts | 8 ++-- packages/vite/src/node/utils.ts | 48 +++++++++++++++++++ 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 4e4fb5a8c895ae..03df61ae3e3ac2 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -13,7 +13,9 @@ import { normalizePath, writeFile, flattenId, - normalizeId + normalizeId, + removeDirSync, + renameDir } from '../utils' import { esbuildDepPlugin } from './esbuildDepPlugin' import { init, parse } from 'es-module-lexer' @@ -116,7 +118,7 @@ export interface DepOptimizationResult { * the page reload will be delayed until the next rerun so we need * to be able to discard the result */ - commit: () => void + commit: () => Promise cancel: () => void } @@ -194,7 +196,7 @@ export async function optimizeDeps( const result = await runOptimizeDeps(config, depsInfo) - result.commit() + await result.commit() return result.metadata } @@ -376,7 +378,7 @@ export async function runOptimizeDeps( metadata, commit() { // Write metadata file, delete `deps` folder and rename the `processing` folder to `deps` - commitProcessingDepsCacheSync() + return commitProcessingDepsCacheSync() }, cancel } @@ -529,16 +531,16 @@ export async function runOptimizeDeps( metadata, commit() { // Write metadata file, delete `deps` folder and rename the new `processing` folder to `deps` in sync - commitProcessingDepsCacheSync() + return commitProcessingDepsCacheSync() }, cancel } - function commitProcessingDepsCacheSync() { + async function commitProcessingDepsCacheSync() { // Processing is done, we can now replace the depsCacheDir with processingCacheDir // Rewire the file paths from the temporal processing dir to the final deps cache dir removeDirSync(depsCacheDir) - fs.renameSync(processingCacheDir, depsCacheDir) + await renameDir(processingCacheDir, depsCacheDir) } function cancel() { @@ -546,13 +548,6 @@ export async function runOptimizeDeps( } } -function removeDirSync(dir: string) { - if (fs.existsSync(dir)) { - const rmSync = fs.rmSync ?? fs.rmdirSync // TODO: Remove after support for Node 12 is dropped - rmSync(dir, { recursive: true }) - } -} - export async function findKnownImports( config: ResolvedConfig ): Promise { diff --git a/packages/vite/src/node/optimizer/registerMissing.ts b/packages/vite/src/node/optimizer/registerMissing.ts index ee4824389c202b..2262c7be96bb0a 100644 --- a/packages/vite/src/node/optimizer/registerMissing.ts +++ b/packages/vite/src/node/optimizer/registerMissing.ts @@ -189,8 +189,8 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps { ) }) - const commitProcessing = () => { - processingResult.commit() + const commitProcessing = async () => { + await processingResult.commit() // While optimizeDeps is running, new missing deps may be discovered, // in which case they will keep being added to metadata.discovered @@ -240,7 +240,7 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps { } if (!needsReload) { - commitProcessing() + await commitProcessing() if (!isDebugEnabled) { if (newDepsToLogHandle) clearTimeout(newDepsToLogHandle) @@ -270,7 +270,7 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps { } ) } else { - commitProcessing() + await commitProcessing() if (!isDebugEnabled) { if (newDepsToLogHandle) clearTimeout(newDepsToLogHandle) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 688e4c0f9cd44d..d41dd6850ebb56 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -3,6 +3,7 @@ import colors from 'picocolors' import fs from 'fs' import os from 'os' import path from 'path' +import { promisify } from 'util' import { pathToFileURL, URL } from 'url' import { FS_PREFIX, @@ -522,6 +523,15 @@ export function copyDir(srcDir: string, destDir: string): void { } } +export function removeDirSync(dir: string) { + if (fs.existsSync(dir)) { + const rmSync = fs.rmSync ?? fs.rmdirSync // TODO: Remove after support for Node 12 is dropped + rmSync(dir, { recursive: true }) + } +} + +export const renameDir = isWindows ? promisify(gracefulRename) : fs.renameSync + export function ensureWatchedFile( watcher: FSWatcher, file: string | null, @@ -737,3 +747,41 @@ export function parseRequest(id: string): Record | null { } export const blankReplacer = (match: string) => ' '.repeat(match.length) + +// Based on node-graceful-fs + +// The ISC License +// Copyright (c) 2011-2022 Isaac Z. Schlueter, Ben Noordhuis, and Contributors +// https://github.com/isaacs/node-graceful-fs/blob/main/LICENSE + +// On Windows, A/V software can lock the directory, causing this +// to fail with an EACCES or EPERM if the directory contains newly +// created files. The original tried for up to 60 seconds, we only +// wait for 5 seconds, as a longer time would be seen as an error + +const GRACEFUL_RENAME_TIMEOUT = 5000 +function gracefulRename( + from: string, + to: string, + cb: (error: NodeJS.ErrnoException | null) => void +) { + const start = Date.now() + let backoff = 0 + fs.rename(from, to, function CB(er) { + if ( + er && + (er.code === 'EACCES' || er.code === 'EPERM') && + Date.now() - start < GRACEFUL_RENAME_TIMEOUT + ) { + setTimeout(function () { + fs.stat(to, function (stater, st) { + if (stater && stater.code === 'ENOENT') gracefulRename(from, to, CB) + else cb(er) + }) + }, backoff) + if (backoff < 100) backoff += 10 + return + } + if (cb) cb(er) + }) +} From 77865b44b2f69642ca106716f6208a812cab9c24 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Wed, 4 May 2022 19:28:34 +0200 Subject: [PATCH 040/114] release: v2.9.8 --- packages/vite/CHANGELOG.md | 13 +++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index db8bf085dc04f6..3c967f289c1f34 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,16 @@ +## 2.9.8 (2022-05-04) + +* fix: inline js and css paths for virtual html (#7993) ([d49e3fb](https://github.com/vitejs/vite/commit/d49e3fb)), closes [#7993](https://github.com/vitejs/vite/issues/7993) +* fix: only handle merge ssr.noExternal (#8003) ([642d65b](https://github.com/vitejs/vite/commit/642d65b)), closes [#8003](https://github.com/vitejs/vite/issues/8003) +* fix: optimized processing folder renaming in win (fix #7939) (#8019) ([e5fe1c6](https://github.com/vitejs/vite/commit/e5fe1c6)), closes [#7939](https://github.com/vitejs/vite/issues/7939) [#8019](https://github.com/vitejs/vite/issues/8019) +* fix(css): do not clean id when passing to postcss (fix #7822) (#7827) ([72f17f8](https://github.com/vitejs/vite/commit/72f17f8)), closes [#7822](https://github.com/vitejs/vite/issues/7822) [#7827](https://github.com/vitejs/vite/issues/7827) +* fix(css): var in image-set (#7921) ([e96b908](https://github.com/vitejs/vite/commit/e96b908)), closes [#7921](https://github.com/vitejs/vite/issues/7921) +* fix(ssr): allow ssrTransform to parse hashbang (#8005) ([6420ba0](https://github.com/vitejs/vite/commit/6420ba0)), closes [#8005](https://github.com/vitejs/vite/issues/8005) +* feat: import ts with .js in vue (#7998) ([9974094](https://github.com/vitejs/vite/commit/9974094)), closes [#7998](https://github.com/vitejs/vite/issues/7998) +* chore: remove maybeVirtualHtmlSet (#8010) ([e85164e](https://github.com/vitejs/vite/commit/e85164e)), closes [#8010](https://github.com/vitejs/vite/issues/8010) + + + ## 2.9.7 (2022-05-02) * chore: update license ([d58c030](https://github.com/vitejs/vite/commit/d58c030)) diff --git a/packages/vite/package.json b/packages/vite/package.json index 3720837d3a5afc..07d0025c449e75 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.9.7", + "version": "2.9.8", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", From b0e9234251b723a3cfe37d9187dfd71c1a654e77 Mon Sep 17 00:00:00 2001 From: patak-dev Date: Wed, 4 May 2022 19:31:32 +0200 Subject: [PATCH 041/114] release: plugin-vue@2.3.2 --- packages/plugin-vue/CHANGELOG.md | 8 ++++++++ packages/plugin-vue/package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue/CHANGELOG.md b/packages/plugin-vue/CHANGELOG.md index 135daffbfaaa67..4990d5fc10bd50 100644 --- a/packages/plugin-vue/CHANGELOG.md +++ b/packages/plugin-vue/CHANGELOG.md @@ -1,3 +1,11 @@ +## 2.3.2 (2022-05-04) + +* feat: import ts with .js in vue (#7998) ([9974094](https://github.com/vitejs/vite/commit/9974094)), closes [#7998](https://github.com/vitejs/vite/issues/7998) +* refactor(plugin-vue): remove querystring import (#7997) ([f3d15f1](https://github.com/vitejs/vite/commit/f3d15f1)), closes [#7997](https://github.com/vitejs/vite/issues/7997) +* chore(deps): update all non-major dependencies (#7780) ([eba9d05](https://github.com/vitejs/vite/commit/eba9d05)), closes [#7780](https://github.com/vitejs/vite/issues/7780) + + + ## 2.3.1 (2022-03-30) * chore(plugin-vue): revert #7527, lower vite peer dep ([447bbeb](https://github.com/vitejs/vite/commit/447bbeb)), closes [#7527](https://github.com/vitejs/vite/issues/7527) diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index 9f401ac7fa86b1..d9e1e0cc9c4ba1 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue", - "version": "2.3.1", + "version": "2.3.2", "license": "MIT", "author": "Evan You", "files": [ From ba95a2a03ceeb68fe674082677f656ce50fe94d0 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 5 May 2022 02:24:21 +0800 Subject: [PATCH 042/114] fix: handle optimize failure (#8006) --- packages/vite/src/node/optimizer/registerMissing.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/registerMissing.ts b/packages/vite/src/node/optimizer/registerMissing.ts index 2262c7be96bb0a..53cd7e981b1b61 100644 --- a/packages/vite/src/node/optimizer/registerMissing.ts +++ b/packages/vite/src/node/optimizer/registerMissing.ts @@ -296,7 +296,6 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps { // Reset missing deps, let the server rediscover the dependencies metadata.discovered = {} - fullReload() } currentlyProcessing = false From 2b58cb3faaa8f0da983888d0bd1f0f2a3a34de56 Mon Sep 17 00:00:00 2001 From: yoho Date: Thu, 5 May 2022 02:45:48 +0800 Subject: [PATCH 043/114] fix: warn for unresolved css in html (#7911) --- packages/playground/html/index.html | 3 +++ packages/vite/src/node/plugins/html.ts | 29 ++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/playground/html/index.html b/packages/playground/html/index.html index 7320ff2b097db0..783cad93172f7a 100644 --- a/packages/playground/html/index.html +++ b/packages/playground/html/index.html @@ -5,3 +5,6 @@

Hello

+ + + diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index bf3d662066630b..0223c351af6071 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -247,6 +247,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { const s = new MagicString(html) const assetUrls: AttributeNode[] = [] const scriptUrls: ScriptAssetsUrl[] = [] + const styleUrls: ScriptAssetsUrl[] = [] let inlineModuleIndex = -1 let everyScriptIsAsync = true @@ -339,8 +340,13 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { if (!isExcludedUrl(url)) { if (node.tag === 'link' && isCSSRequest(url)) { // CSS references, convert to import - js += `\nimport ${JSON.stringify(url)}` - shouldRemove = true + const importExpression = `\nimport ${JSON.stringify(url)}` + styleUrls.push({ + url, + start: node.loc.start.offset, + end: node.loc.end.offset + }) + js += importExpression } else { assetUrls.push(p) } @@ -470,6 +476,25 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { } } + // ignore if its url can't be resolved + const resolvedStyleUrls = await Promise.all( + styleUrls.map(async (styleUrl) => ({ + ...styleUrl, + resolved: await this.resolve(styleUrl.url, id) + })) + ) + for (const { start, end, url, resolved } of resolvedStyleUrls) { + if (resolved == null) { + config.logger.warnOnce( + `\n${url} doesn't exist at build time, it will remain unchanged to be resolved at runtime` + ) + const importExpression = `\nimport ${JSON.stringify(url)}` + js = js.replace(importExpression, '') + } else { + s.remove(start, end) + } + } + processedHtml.set(id, s.toString()) // inject module preload polyfill only when configured and needed From 70f032f0d84df995a600f0a282ee736f8edef26e Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 4 May 2022 13:08:27 -0700 Subject: [PATCH 044/114] docs: clarify code comments in `optimize-missing-deps` (#7332) --- packages/playground/optimize-missing-deps/server.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/playground/optimize-missing-deps/server.js b/packages/playground/optimize-missing-deps/server.js index b9422feb622584..65675fe0feb589 100644 --- a/packages/playground/optimize-missing-deps/server.js +++ b/packages/playground/optimize-missing-deps/server.js @@ -25,10 +25,11 @@ async function createServer(root = process.cwd()) { let template = fs.readFileSync(resolve('index.html'), 'utf-8') template = await vite.transformIndexHtml(req.originalUrl, template) - // this will import missing deps nest built-in deps that should not be optimized + // `main.js` imports dependencies that are yet to be discovered and optimized, aka "missing" deps. + // Loading `main.js` in SSR should not trigger optimizing the "missing" deps const { name } = await vite.ssrLoadModule('./main.js') - // this will import missing deps that should be optimized correctly + // Loading `main.js` in the client should trigger optimizing the "missing" deps const appHtml = `
${name}
diff --git a/packages/playground/lib/vite.config.js b/packages/playground/lib/vite.config.js index 50cd188b1a40cc..72c040d38d6dcf 100644 --- a/packages/playground/lib/vite.config.js +++ b/packages/playground/lib/vite.config.js @@ -10,7 +10,7 @@ module.exports = { entry: path.resolve(__dirname, 'src/main.js'), name: 'MyLib', formats: ['es', 'umd', 'iife'], - fileName: (format) => `my-lib-custom-filename.${format}.js` + fileName: 'my-lib-custom-filename' } }, plugins: [ diff --git a/packages/playground/resolve-config/__tests__/resolve-config.spec.ts b/packages/playground/resolve-config/__tests__/resolve-config.spec.ts index 13ea5ea6f59a4f..cde329afde2f50 100644 --- a/packages/playground/resolve-config/__tests__/resolve-config.spec.ts +++ b/packages/playground/resolve-config/__tests__/resolve-config.spec.ts @@ -10,42 +10,45 @@ const fromTestDir = (...p: string[]) => path.resolve(testDir, ...p) const build = (configName: string) => { commandSync(`${viteBin} build`, { cwd: fromTestDir(configName) }) } -const getDistFile = (configName: string) => { - return fs.readFileSync(fromTestDir(`${configName}/dist/index.es.js`), 'utf8') +const getDistFile = (configName: string, extension: string) => { + return fs.readFileSync( + fromTestDir(`${configName}/dist/index.es.${extension}`), + 'utf8' + ) } if (isBuild) { it('loads vite.config.js', () => { build('js') - expect(getDistFile('js')).toContain('console.log(true)') + expect(getDistFile('js', 'mjs')).toContain('console.log(true)') }) it('loads vite.config.js with package#type module', () => { build('js-module') - expect(getDistFile('js-module')).toContain('console.log(true)') + expect(getDistFile('js-module', 'js')).toContain('console.log(true)') }) it('loads vite.config.cjs', () => { build('cjs') - expect(getDistFile('cjs')).toContain('console.log(true)') + expect(getDistFile('cjs', 'mjs')).toContain('console.log(true)') }) it('loads vite.config.cjs with package#type module', () => { build('cjs-module') - expect(getDistFile('cjs-module')).toContain('console.log(true)') + expect(getDistFile('cjs-module', 'js')).toContain('console.log(true)') }) it('loads vite.config.mjs', () => { build('mjs') - expect(getDistFile('mjs')).toContain('console.log(true)') + expect(getDistFile('mjs', 'mjs')).toContain('console.log(true)') }) it('loads vite.config.mjs with package#type module', () => { build('mjs-module') - expect(getDistFile('mjs-module')).toContain('console.log(true)') + expect(getDistFile('mjs-module', 'js')).toContain('console.log(true)') }) it('loads vite.config.ts', () => { build('ts') - expect(getDistFile('ts')).toContain('console.log(true)') + expect(getDistFile('ts', 'mjs')).toContain('console.log(true)') }) it('loads vite.config.ts with package#type module', () => { build('ts-module') - expect(getDistFile('ts-module')).toContain('console.log(true)') + expect(getDistFile('ts-module', 'js')).toContain('console.log(true)') }) } else { // this test doesn't support serve mode diff --git a/packages/playground/vue-lib/vite.config.lib.ts b/packages/playground/vue-lib/vite.config.lib.ts index a888382d008a8c..0cc082c7ceea85 100644 --- a/packages/playground/vue-lib/vite.config.lib.ts +++ b/packages/playground/vue-lib/vite.config.lib.ts @@ -10,7 +10,7 @@ export default defineConfig({ entry: path.resolve(__dirname, 'src-lib/index.ts'), name: 'MyVueLib', formats: ['es'], - fileName: (format) => `my-vue-lib.${format}.js` + fileName: 'my-vue-lib' }, rollupOptions: { external: ['vue'], diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index b3ef37e64fd28e..578e3a4c68ff8d 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -1,6 +1,13 @@ +import type { LibraryFormats, LibraryOptions } from '../build' import { resolveLibFilename } from '../build' import { resolve } from 'path' +type FormatsToFileNames = [LibraryFormats, string][] +const baseLibOptions: LibraryOptions = { + fileName: 'my-lib', + entry: 'mylib.js' +} + describe('resolveLibFilename', () => { test('custom filename function', () => { const filename = resolveLibFilename( @@ -25,7 +32,7 @@ describe('resolveLibFilename', () => { resolve(__dirname, 'packages/name') ) - expect(filename).toBe('custom-filename.es.js') + expect(filename).toBe('custom-filename.es.mjs') }) test('package name as filename', () => { @@ -37,7 +44,7 @@ describe('resolveLibFilename', () => { resolve(__dirname, 'packages/name') ) - expect(filename).toBe('mylib.es.js') + expect(filename).toBe('mylib.es.mjs') }) test('custom filename and no package name', () => { @@ -50,7 +57,7 @@ describe('resolveLibFilename', () => { resolve(__dirname, 'packages/noname') ) - expect(filename).toBe('custom-filename.es.js') + expect(filename).toBe('custom-filename.es.mjs') }) test('missing filename', () => { @@ -64,4 +71,42 @@ describe('resolveLibFilename', () => { ) }).toThrow() }) + + test('commonjs package extensions', () => { + const formatsToFilenames: FormatsToFileNames = [ + ['es', 'my-lib.es.mjs'], + ['umd', 'my-lib.umd.js'], + ['cjs', 'my-lib.cjs.js'], + ['iife', 'my-lib.iife.js'] + ] + + for (const [format, expectedFilename] of formatsToFilenames) { + const filename = resolveLibFilename( + baseLibOptions, + format, + resolve(__dirname, 'packages/noname') + ) + + expect(filename).toBe(expectedFilename) + } + }) + + test('module package extensions', () => { + const formatsToFilenames: FormatsToFileNames = [ + ['es', 'my-lib.es.js'], + ['umd', 'my-lib.umd.cjs'], + ['cjs', 'my-lib.cjs.cjs'], + ['iife', 'my-lib.iife.js'] + ] + + for (const [format, expectedFilename] of formatsToFilenames) { + const filename = resolveLibFilename( + baseLibOptions, + format, + resolve(__dirname, 'packages/module') + ) + + expect(filename).toBe(expectedFilename) + } + }) }) diff --git a/packages/vite/src/node/__tests__/packages/module/package.json b/packages/vite/src/node/__tests__/packages/module/package.json new file mode 100644 index 00000000000000..3dbc1ca591c055 --- /dev/null +++ b/packages/vite/src/node/__tests__/packages/module/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index f584f007f2df5e..d4d4085bb829ed 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -38,6 +38,7 @@ import type { DepOptimizationMetadata } from './optimizer' import { getDepsCacheDir, findKnownImports } from './optimizer' import { assetImportMetaUrlPlugin } from './plugins/assetImportMetaUrl' import { loadFallbackPlugin } from './plugins/loadFallback' +import type { PackageData } from './packages' import { watchPackageDataPlugin } from './packages' import { ensureWatchPlugin } from './plugins/ensureWatch' @@ -563,9 +564,11 @@ function prepareOutDir( } } -function getPkgName(root: string) { - const { name } = JSON.parse(lookupFile(root, ['package.json']) || `{}`) +function getPkgJson(root: string): PackageData['data'] { + return JSON.parse(lookupFile(root, ['package.json']) || `{}`) +} +function getPkgName(name: string) { return name?.startsWith('@') ? name.split('/')[1] : name } @@ -578,14 +581,23 @@ export function resolveLibFilename( return libOptions.fileName(format) } - const name = libOptions.fileName || getPkgName(root) + const packageJson = getPkgJson(root) + const name = libOptions.fileName || getPkgName(packageJson.name) if (!name) throw new Error( 'Name in package.json is required if option "build.lib.fileName" is not provided.' ) - return `${name}.${format}.js` + let extension: string + + if (packageJson?.type === 'module') { + extension = format === 'cjs' || format === 'umd' ? 'cjs' : 'js' + } else { + extension = format === 'es' ? 'mjs' : 'js' + } + + return `${name}.${format}.${extension}` } function resolveBuildOutputs( diff --git a/packages/vite/src/node/packages.ts b/packages/vite/src/node/packages.ts index 1424977164de85..1fb2e7b4a21c06 100644 --- a/packages/vite/src/node/packages.ts +++ b/packages/vite/src/node/packages.ts @@ -22,6 +22,8 @@ export interface PackageData { getResolvedCache: (key: string, targetWeb: boolean) => string | undefined data: { [field: string]: any + name: string + type: string version: string main: string module: string From 0e67fe8ae23d4e21db578d9a18a63861e1cdade0 Mon Sep 17 00:00:00 2001 From: yoho Date: Fri, 6 May 2022 04:27:05 +0800 Subject: [PATCH 051/114] fix: vite client types (#7877) Co-authored-by: Bjorn Lu --- docs/guide/env-and-mode.md | 8 ++++++++ packages/vite/client.d.ts | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index b2b1264e85a8e4..d5f45ea1158808 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -81,6 +81,14 @@ interface ImportMeta { } ``` +If your code relies on types from browser environments such as [DOM](https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts) and [WebWorker](https://github.com/microsoft/TypeScript/blob/main/lib/lib.webworker.d.ts), you can update the [lib](https://www.typescriptlang.org/tsconfig#lib) field in `tsconfig.json`. + +```json +{ + "lib": ["WebWorker"] +} +``` + ## Modes By default, the dev server (`dev` command) runs in `development` mode and the `build` command run in `production` mode. diff --git a/packages/vite/client.d.ts b/packages/vite/client.d.ts index aaac1ea986251d..af8e6a6f9d1494 100644 --- a/packages/vite/client.d.ts +++ b/packages/vite/client.d.ts @@ -1,4 +1,3 @@ -/// /// // CSS modules From 95eb45b15fa66b8e9707adfbed315d4a57d5c5ed Mon Sep 17 00:00:00 2001 From: Jonas <30421456+jonaskuske@users.noreply.github.com> Date: Thu, 5 May 2022 22:29:14 +0200 Subject: [PATCH 052/114] feat: allow any JS identifier in define, not ASCII-only (#5972) --- docs/config/index.md | 2 +- packages/playground/define/__tests__/define.spec.ts | 8 ++++++++ packages/playground/define/index.html | 13 +++++++++++++ packages/playground/define/vite.config.js | 6 ++++-- packages/vite/src/node/plugins/define.ts | 12 +++++++----- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index db2dc932efbf30..5862419405aa89 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -164,7 +164,7 @@ export default defineConfig(({ command, mode }) => { - To be consistent with [esbuild behavior](https://esbuild.github.io/api/#define), expressions must either be a JSON object (null, boolean, number, string, array, or object) or a single identifier. - - Replacements are performed only when the match is surrounded by word boundaries (`\b`). + - Replacements are performed only when the match isn't surrounded by other letters, numbers, `_` or `$`. ::: warning Because it's implemented as straightforward text replacements without any syntax analysis, we recommend using `define` for CONSTANTS only. diff --git a/packages/playground/define/__tests__/define.spec.ts b/packages/playground/define/__tests__/define.spec.ts index 709f7a935dc8c1..5d9707e70b47ba 100644 --- a/packages/playground/define/__tests__/define.spec.ts +++ b/packages/playground/define/__tests__/define.spec.ts @@ -20,6 +20,14 @@ test('string', async () => { expect(await page.textContent('.spread-array')).toBe( JSON.stringify([...defines.__STRING__]) ) + expect(await page.textContent('.dollar-identifier')).toBe( + String(defines.$DOLLAR) + ) + expect(await page.textContent('.unicode-identifier')).toBe( + String(defines.ÖUNICODE_LETTERɵ) + ) + expect(await page.textContent('.no-identifier-substring')).toBe(String(true)) + expect(await page.textContent('.no-property')).toBe(String(true)) // html would't need to define replacement expect(await page.textContent('.exp-define')).toBe('__EXP__') expect(await page.textContent('.import-json')).toBe('__EXP__') diff --git a/packages/playground/define/index.html b/packages/playground/define/index.html index da78d192216b11..c89a3fe02218ff 100644 --- a/packages/playground/define/index.html +++ b/packages/playground/define/index.html @@ -9,6 +9,10 @@

Define

process as property:

spread object:

spread array:

+

dollar identifier:

+

unicode identifier:

+

no property:

+

no identifier substring:

define variable in html: __EXP__

import json:

@@ -28,6 +32,15 @@

Define

}) ) text('.spread-array', JSON.stringify([...`"${__STRING__}"`])) + text('.dollar-identifier', $DOLLAR) + text('.unicode-identifier', ÖUNICODE_LETTERɵ) + + // make sure these kinds of use are NOT replaced: + const obj = { [`${'_'}_EXP__`]: true } + text('.no-property', obj.__EXP__) + + window[`${'_'}_EXP__SUBSTR__`] = true + text('.no-identifier-substring', __EXP__SUBSTR__) import dataJson from './data.json' text('.import-json', dataJson.foo) diff --git a/packages/playground/define/vite.config.js b/packages/playground/define/vite.config.js index 848abd09322df6..88173fe654b58d 100644 --- a/packages/playground/define/vite.config.js +++ b/packages/playground/define/vite.config.js @@ -15,7 +15,9 @@ module.exports = { } } }, - __VAR_NAME__: false, - 'process.env.SOMEVAR': '"SOMEVAR"' + 'process.env.SOMEVAR': '"SOMEVAR"', + $DOLLAR: 456, + ÖUNICODE_LETTERɵ: 789, + __VAR_NAME__: false } } diff --git a/packages/vite/src/node/plugins/define.ts b/packages/vite/src/node/plugins/define.ts index 19ca28b34433a0..ca0f446cc1f58e 100644 --- a/packages/vite/src/node/plugins/define.ts +++ b/packages/vite/src/node/plugins/define.ts @@ -68,16 +68,18 @@ export function definePlugin(config: ResolvedConfig): Plugin { const replacementsKeys = Object.keys(replacements) const pattern = replacementsKeys.length ? new RegExp( - // Do not allow preceding '.', but do allow preceding '...' for spread operations - '(? { return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&') }) .join('|') + - // prevent trailing assignments - ')\\b(?!\\s*?=[^=])', - 'g' + // Mustn't be followed by a char that can be part of an identifier + // or an assignment (but allow equality operators) + ')(?![\\p{L}\\p{N}_$]|\\s*?=[^=])', + 'gu' ) : null From c7eeb8d69253d16dc9413d59cc13e45977a8c105 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 6 May 2022 14:07:41 +0800 Subject: [PATCH 053/114] chore: remove redundant pnpm version in ci (#8039) --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4818124be2430f..9768ca4ebc3df2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,8 +47,6 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v2 - with: - version: 6 - name: Set node version to ${{ matrix.node_version }} uses: actions/setup-node@v3 @@ -85,8 +83,6 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v2 - with: - version: 6 - name: Set node version to 16 uses: actions/setup-node@v3 From 63cd53d2480e40db717aff78966240eb6482aba4 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 6 May 2022 16:00:31 +0800 Subject: [PATCH 054/114] fix: use Vitest for unit testing, clean regex bug (#8040) --- .eslintrc.cjs | 4 +- .github/workflows/ci.yml | 3 + CONTRIBUTING.md | 14 ++- jest.config.ts | 4 +- package.json | 8 +- packages/create-vite/__tests__/cli.spec.ts | 1 + .../src/jsx-runtime/babel-restore-jsx.spec.ts | 1 + .../src/jsx-runtime/restore-jsx.spec.ts | 1 + .../vite/src/node/__tests__/asset.spec.ts | 1 + .../vite/src/node/__tests__/build.spec.ts | 1 + .../src/node/__tests__/cleanString.spec.ts | Bin 4284 -> 4756 bytes .../vite/src/node/__tests__/config.spec.ts | 1 + packages/vite/src/node/__tests__/dev.spec.ts | 1 + .../src/node/__tests__/plugins/css.spec.ts | 3 +- .../src/node/__tests__/plugins/define.spec.ts | 1 + .../src/node/__tests__/plugins/import.spec.ts | 1 + packages/vite/src/node/__tests__/scan.spec.ts | 1 + .../vite/src/node/__tests__/utils.spec.ts | 1 + packages/vite/src/node/cleanString.ts | 9 +- .../server/__tests__/pluginContainer.spec.ts | 1 + .../node/server/__tests__/search-root.spec.ts | 1 + .../node/ssr/__tests__/ssrExternal.spec.ts | 1 + .../ssr/__tests__/ssrModuleLoader.spec.ts | 3 +- .../node/ssr/__tests__/ssrTransform.spec.ts | 1 + pnpm-lock.yaml | 97 ++++++++++++++++++ vitest.config.ts | 15 +++ 26 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 vitest.config.ts diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 48a0bd7773b0d7..5e00df0d89e1e0 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -63,7 +63,7 @@ module.exports = defineConfig({ 'node/no-extraneous-import': [ 'error', { - allowModules: ['vite', 'less', 'sass'] + allowModules: ['vite', 'less', 'sass', 'vitest'] } ], 'node/no-extraneous-require': [ @@ -103,7 +103,7 @@ module.exports = defineConfig({ } }, { - files: ['packages/vite/types/**'], + files: ['packages/vite/types/**', '*.spec.ts'], rules: { 'node/no-extraneous-import': 'off' } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9768ca4ebc3df2..5173da859417be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,9 @@ jobs: - name: Build plugin-react run: pnpm run build-plugin-react + - name: Test unit + run: pnpm run test-unit + - name: Test serve run: pnpm run test-serve -- --runInBand diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 621f8de145835f..40d2bb28605167 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,13 +67,15 @@ And re-run `pnpm install` to link the package. ## Running Tests +### Integration Tests + Each package under `packages/playground/` contains a `__tests__` directory. The tests are run using [Jest](https://jestjs.io/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `jest.config.js` and `scripts/jest*` files. Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). Also you may want to [set git `core.symlinks` to `true` to solve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242). -Each test can be run under either dev server mode or build mode. +Each integration test can be run under either dev server mode or build mode. -- `pnpm test` by default runs every test in both serve and build mode. +- `pnpm test` by default runs every integration test in both serve and build mode, and also unit tests. - `pnpm run test-serve` runs tests only under serve mode. This is just calling `jest` so you can pass any Jest flags to this command. Since Jest will attempt to run tests in parallel, if your machine has many cores this may cause flaky test failures with multiple Playwright instances running at the same time. You can force the tests to run in series with `pnpm run test-serve -- --runInBand`. @@ -83,6 +85,14 @@ Each test can be run under either dev server mode or build mode. Note package matching is not available for the `pnpm test` script, which always runs all tests. +### Unit Tests + +Other than tests under `packages/playground/` for integration tests, packages might contains unit tests under their `__tests__` directory. Unit tests are powered by [Vitest](https://vitest.dev/). The detailed config is inside `vitest.config.ts` files. + +- `pnpm run test-unit` runs unit tests under each package. + +- You can also use `pnpm run test-unit -- [match]` to run related tests. + ### Test Env and Helpers Inside playground tests, a global `page` object is automatically available, which is a Playwright [`Page`](https://playwright.dev/docs/api/class-page) instance that has already navigated to the served page of the current playground. So writing a test is as simple as: diff --git a/jest.config.ts b/jest.config.ts index 11663af4e08107..941fccbae2af36 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -3,9 +3,7 @@ import type { Config } from '@jest/types' const config: Config.InitialOptions = { preset: 'ts-jest', - testMatch: process.env.VITE_TEST_BUILD - ? ['**/playground/**/*.spec.[jt]s?(x)'] - : ['**/*.spec.[jt]s?(x)'], + testMatch: ['**/playground/**/*.spec.[jt]s?(x)'], testTimeout: process.env.CI ? 50000 : 20000, globalSetup: './scripts/jestGlobalSetup.cjs', globalTeardown: './scripts/jestGlobalTeardown.cjs', diff --git a/package.json b/package.json index 269f1bb99cb826..843b6a4e030e39 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,11 @@ "preinstall": "npx only-allow pnpm", "format": "prettier --write .", "lint": "eslint packages/*/{src,types}/**", - "test": "run-s test-serve test-build", + "test": "run-s test-serve test-build test-unit", "test-serve": "jest", - "debug-serve": "cross-env VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest", "test-build": "cross-env VITE_TEST_BUILD=1 jest", + "test-unit": "vitest run", + "debug-serve": "cross-env VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest", "debug-build": "cross-env VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 node --inspect-brk ./node_modules/.bin/jest", "docs": "vitepress dev docs", "build-docs": "vitepress build docs", @@ -68,7 +69,8 @@ "ts-node": "^10.4.0", "typescript": "~4.5.4", "vite": "workspace:*", - "vitepress": "^0.22.3" + "vitepress": "^0.22.3", + "vitest": "^0.10.4" }, "simple-git-hooks": { "pre-commit": "pnpm exec lint-staged --concurrent false", diff --git a/packages/create-vite/__tests__/cli.spec.ts b/packages/create-vite/__tests__/cli.spec.ts index c52998172149e6..fbfb606f486885 100644 --- a/packages/create-vite/__tests__/cli.spec.ts +++ b/packages/create-vite/__tests__/cli.spec.ts @@ -3,6 +3,7 @@ import type { ExecaSyncReturnValue, SyncOptions } from 'execa' import { commandSync } from 'execa' import { mkdirpSync, readdirSync, remove, writeFileSync } from 'fs-extra' import { join } from 'path' +import { test, expect, beforeAll, afterEach } from 'vitest' const CLI_PATH = join(__dirname, '..') diff --git a/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts b/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts index 59d6661bedd11b..391007f68c1329 100644 --- a/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts +++ b/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts @@ -1,5 +1,6 @@ import babelRestoreJSX from './babel-restore-jsx' import * as babel from '@babel/core' +import { describe, it, expect } from 'vitest' function jsx(code: string) { return babel.transform(code, { diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts index c216e99bc3480d..4f6a34ee60d915 100644 --- a/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts +++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts @@ -1,5 +1,6 @@ import { restoreJSX } from './restore-jsx' import * as babel from '@babel/core' +import { describe, it, expect } from 'vitest' async function jsx(sourceCode: string) { const [ast] = await restoreJSX(babel, sourceCode, 'test.js') diff --git a/packages/vite/src/node/__tests__/asset.spec.ts b/packages/vite/src/node/__tests__/asset.spec.ts index 6e6b969bcbd38c..8727aa6485eb26 100644 --- a/packages/vite/src/node/__tests__/asset.spec.ts +++ b/packages/vite/src/node/__tests__/asset.spec.ts @@ -1,3 +1,4 @@ +import { describe, test, expect } from 'vitest' import { assetFileNamesToFileName, getAssetHash } from '../plugins/asset' describe('getAssetHash', () => { diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index 578e3a4c68ff8d..b49847f1d955a4 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -1,6 +1,7 @@ import type { LibraryFormats, LibraryOptions } from '../build' import { resolveLibFilename } from '../build' import { resolve } from 'path' +import { describe, test, expect } from 'vitest' type FormatsToFileNames = [LibraryFormats, string][] const baseLibOptions: LibraryOptions = { diff --git a/packages/vite/src/node/__tests__/cleanString.spec.ts b/packages/vite/src/node/__tests__/cleanString.spec.ts index f307c4816b7cd31bdd579b94fab09618e0af1bdb..99ecbcaad444023d10ed467f6cd9b2794fa935bd 100644 GIT binary patch delta 402 zcmdm^I7M|rmP%%BL4Hw*LbXCkYH^8fINqMQ|F)_v38sYgx*{MY}!5N7~sVNYS zCQw2vCPo89X+YJ52KgY1sz=AE$7-wBC`HF9#cC_n#3V$=#U#XP$0UF?>wwfk+#3_4 zmz!FW2&75{igF-kXlm-Gb15h!Og_&fJNX{BOuc7bPG(+ea9(0TaYlZLMgmY$K|u*j if>_DXKy6@v-#~q+LqHBn(B!Js { test('handles configs with different alias schemas', () => { diff --git a/packages/vite/src/node/__tests__/dev.spec.ts b/packages/vite/src/node/__tests__/dev.spec.ts index 3eefd7b4b903c1..cdb0fc123f4b4f 100644 --- a/packages/vite/src/node/__tests__/dev.spec.ts +++ b/packages/vite/src/node/__tests__/dev.spec.ts @@ -1,4 +1,5 @@ import { resolveConfig } from '..' +import { describe, test, expect } from 'vitest' describe('resolveBuildOptions in dev', () => { test('build.rollupOptions should not have input in lib', async () => { diff --git a/packages/vite/src/node/__tests__/plugins/css.spec.ts b/packages/vite/src/node/__tests__/plugins/css.spec.ts index e0d1f04a6510b2..eeacaf482b0c31 100644 --- a/packages/vite/src/node/__tests__/plugins/css.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/css.spec.ts @@ -2,6 +2,7 @@ import { cssUrlRE, cssPlugin, hoistAtRules } from '../../plugins/css' import { resolveConfig } from '../../config' import fs from 'fs' import path from 'path' +import { describe, vi, test, expect } from 'vitest' describe('search css url function', () => { test('some spaces before it', () => { @@ -69,7 +70,7 @@ describe('css path resolutions', () => { await buildStart.call({}) - const mockFs = jest + const mockFs = vi .spyOn(fs, 'readFile') // @ts-ignore jest.spyOn not recognize overrided `fs.readFile` definition. .mockImplementationOnce((p, encoding, callback) => { diff --git a/packages/vite/src/node/__tests__/plugins/define.spec.ts b/packages/vite/src/node/__tests__/plugins/define.spec.ts index 9a65f8f3a51cea..b9acc81cb790d5 100644 --- a/packages/vite/src/node/__tests__/plugins/define.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/define.spec.ts @@ -1,3 +1,4 @@ +import { describe, test, expect } from 'vitest' import { definePlugin } from '../../plugins/define' import { resolveConfig } from '../../config' diff --git a/packages/vite/src/node/__tests__/plugins/import.spec.ts b/packages/vite/src/node/__tests__/plugins/import.spec.ts index f0341e81b50f3c..e232702d57d354 100644 --- a/packages/vite/src/node/__tests__/plugins/import.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/import.spec.ts @@ -1,3 +1,4 @@ +import { describe, test, expect } from 'vitest' import { transformCjsImport } from '../../plugins/importAnalysis' describe('transformCjsImport', () => { diff --git a/packages/vite/src/node/__tests__/scan.spec.ts b/packages/vite/src/node/__tests__/scan.spec.ts index db11bcc45b284c..8d5a275fca0292 100644 --- a/packages/vite/src/node/__tests__/scan.spec.ts +++ b/packages/vite/src/node/__tests__/scan.spec.ts @@ -1,5 +1,6 @@ import { scriptRE, commentRE, importsRE } from '../optimizer/scan' import { multilineCommentsRE, singlelineCommentsRE } from '../utils' +import { describe, test, expect } from 'vitest' describe('optimizer-scan:script-test', () => { const scriptContent = `import { defineComponent } from 'vue' diff --git a/packages/vite/src/node/__tests__/utils.spec.ts b/packages/vite/src/node/__tests__/utils.spec.ts index 1162105c3f19c7..29fd53f3c9a32e 100644 --- a/packages/vite/src/node/__tests__/utils.spec.ts +++ b/packages/vite/src/node/__tests__/utils.spec.ts @@ -4,6 +4,7 @@ import { isWindows, resolveHostname } from '../utils' +import { describe, test, expect } from 'vitest' describe('injectQuery', () => { if (isWindows) { diff --git a/packages/vite/src/node/cleanString.ts b/packages/vite/src/node/cleanString.ts index 9b9ef656f4e017..d990ab75f15d7c 100644 --- a/packages/vite/src/node/cleanString.ts +++ b/packages/vite/src/node/cleanString.ts @@ -5,6 +5,7 @@ import { multilineCommentsRE, singlelineCommentsRE } from './utils' // /`([^`\$\{\}]|\$\{(`|\g<1>)*\})*`/g can match nested string template // but js not support match expression(\g<0>). so clean string template(`...`) in other ways. const stringsRE = /"([^"\r\n]|(?<=\\)")*"|'([^'\r\n]|(?<=\\)')*'/g +const regexRE = /\/.*?(? `${s[0]}${'\0'.repeat(s.length - 2)}${s[0]}` export function emptyString(raw: string): string { - let res = raw.replace(cleanerRE, (s: string) => - s[0] === '/' ? blankReplacer(s) : stringBlankReplacer(s) - ) + let res = raw + .replace(cleanerRE, (s: string) => + s[0] === '/' ? blankReplacer(s) : stringBlankReplacer(s) + ) + .replace(regexRE, (s) => stringBlankReplacer(s)) let lastEnd = 0 let start = 0 diff --git a/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts b/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts index 9fbd07e90aa089..ab0555ae7982e9 100644 --- a/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts +++ b/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts @@ -4,6 +4,7 @@ import type { Plugin } from '../../plugin' import { ModuleGraph } from '../moduleGraph' import type { PluginContainer } from '../pluginContainer' import { createPluginContainer } from '../pluginContainer' +import { describe, it, expect, beforeEach } from 'vitest' let resolveId: (id: string) => any let moduleGraph: ModuleGraph diff --git a/packages/vite/src/node/server/__tests__/search-root.spec.ts b/packages/vite/src/node/server/__tests__/search-root.spec.ts index 7322768286809e..ff9366e8791534 100644 --- a/packages/vite/src/node/server/__tests__/search-root.spec.ts +++ b/packages/vite/src/node/server/__tests__/search-root.spec.ts @@ -1,5 +1,6 @@ import { searchForWorkspaceRoot } from '../searchRoot' import { resolve } from 'path' +import { describe, test, expect } from 'vitest' describe('searchForWorkspaceRoot', () => { test('lerna', () => { diff --git a/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts index ad16534b088e2b..5fb51093405250 100644 --- a/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts +++ b/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts @@ -1,4 +1,5 @@ import { stripNesting } from '../ssrExternal' +import { test, expect } from 'vitest' test('stripNesting', async () => { expect(stripNesting(['c', 'p1>c1', 'p2 > c2'])).toEqual(['c', 'c1', 'c2']) diff --git a/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts index 6a45a2b70509d0..93a04734840d31 100644 --- a/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts +++ b/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts @@ -1,12 +1,13 @@ import { resolve } from 'path' import { createServer } from '../../index' +import { test, vi, expect } from 'vitest' const badjs = resolve(__dirname, './fixtures/ssrModuleLoader-bad.js') const THROW_MESSAGE = 'it is an expected error' test('always throw error when evaluating an wrong SSR module', async () => { const viteServer = await createServer() - const spy = jest.spyOn(console, 'error').mockImplementation(() => {}) + const spy = vi.spyOn(console, 'error').mockImplementation(() => {}) const expectedErrors = [] for (const i of [0, 1]) { try { diff --git a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts index 0e9181214c2b82..9c1fdea5939793 100644 --- a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts +++ b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts @@ -1,6 +1,7 @@ import { transformWithEsbuild } from '../../plugins/esbuild' import { traverseHtml } from '../../plugins/html' import { ssrTransform } from '../ssrTransform' +import { test, expect } from 'vitest' test('default import', async () => { expect( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d3aea697843c5b..3f15dbb27aae88 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,6 +45,7 @@ importers: typescript: ~4.5.4 vite: workspace:* vitepress: ^0.22.3 + vitest: ^0.10.4 devDependencies: '@microsoft/api-extractor': 7.23.0 '@types/fs-extra': 9.0.13 @@ -81,6 +82,7 @@ importers: typescript: 4.5.4 vite: link:packages/vite vitepress: 0.22.3 + vitest: 0.10.4 packages/create-vite: specifiers: @@ -2579,6 +2581,16 @@ packages: resolution: {integrity: sha512-+euflG6ygo4bn0JHtn4pYqcXwRtLvElQ7/nnjDu7iYG56H0+OhCd7d6Ug0IE3WcFpZozBKW2+80FUbv5QGk5AQ==} dev: true + /@types/chai-subset/1.3.3: + resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==} + dependencies: + '@types/chai': 4.3.1 + dev: true + + /@types/chai/4.3.1: + resolution: {integrity: sha512-/zPMqDkzSZ8t3VtxOa4KPq7uzzW978M9Tvh+j7GHKuo6k6GTLxPJ4J5gE5cjfJ26pnXst0N5Hax8Sr0T2Mi9zQ==} + dev: true + /@types/convert-source-map/1.5.2: resolution: {integrity: sha512-tHs++ZeXer40kCF2JpE51Hg7t4HPa18B1b1Dzy96S0eCw8QKECNMYMfwa1edK/x8yCN0r4e6ewvLcc5CsVGkdg==} dev: true @@ -3370,6 +3382,10 @@ packages: resolution: {integrity: sha512-TaTivMB6pYI1kXwrFlEhLeGfOqoDNdTxjCdwRfFFkEA30Eu+k48W34nlok2EYWJfFFzqaEmichdNM7th6M5HNw==} dev: true + /assertion-error/1.1.0: + resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} + dev: true + /astral-regex/2.0.0: resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==} engines: {node: '>=8'} @@ -3666,6 +3682,19 @@ packages: resolution: {integrity: sha512-kbaCEBRRVSoeNs74sCuq92MJyGrMtjWVfhltoHUCW4t4pXFvGjUBrfo47weBRViHkiV3eBYyIsfl956NtHGazw==} dev: false + /chai/4.3.6: + resolution: {integrity: sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==} + engines: {node: '>=4'} + dependencies: + assertion-error: 1.1.0 + check-error: 1.0.2 + deep-eql: 3.0.1 + get-func-name: 2.0.0 + loupe: 2.3.4 + pathval: 1.1.1 + type-detect: 4.0.8 + dev: true + /chalk/2.4.2: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} engines: {node: '>=4'} @@ -3692,6 +3721,10 @@ packages: is-regex: 1.1.4 dev: true + /check-error/1.0.2: + resolution: {integrity: sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=} + dev: true + /chokidar/3.5.2: resolution: {integrity: sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==} engines: {node: '>= 8.10.0'} @@ -4374,6 +4407,13 @@ packages: resolution: {integrity: sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw=} dev: true + /deep-eql/3.0.1: + resolution: {integrity: sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==} + engines: {node: '>=0.12'} + dependencies: + type-detect: 4.0.8 + dev: true + /deep-is/0.1.4: resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} dev: true @@ -5356,6 +5396,10 @@ packages: engines: {node: 6.* || 8.* || >= 10.*} dev: true + /get-func-name/2.0.0: + resolution: {integrity: sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=} + dev: true + /get-intrinsic/1.1.1: resolution: {integrity: sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==} dependencies: @@ -6786,6 +6830,11 @@ packages: engines: {node: '>= 12.13.0'} dev: true + /local-pkg/0.4.1: + resolution: {integrity: sha512-lL87ytIGP2FU5PWwNDo0w3WhIo2gopIAxPg9RxDYF7m4rr5ahuZxP22xnJHIvaLTe4Z9P6uKKY2UHiwyB4pcrw==} + engines: {node: '>=14'} + dev: true + /locate-path/2.0.0: resolution: {integrity: sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=} engines: {node: '>=4'} @@ -6869,6 +6918,12 @@ packages: js-tokens: 4.0.0 dev: false + /loupe/2.3.4: + resolution: {integrity: sha512-OvKfgCC2Ndby6aSTREl5aCCPTNIzlDfQZvZxNUrBrihDhL3xcrYegTblhmEiCrg2kKQz4XsFIaemE5BF4ybSaQ==} + dependencies: + get-func-name: 2.0.0 + dev: true + /lru-cache/6.0.0: resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} engines: {node: '>=10'} @@ -7560,6 +7615,10 @@ packages: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} + /pathval/1.1.1: + resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==} + dev: true + /pend/1.2.0: resolution: {integrity: sha1-elfrVQpng/kRUzH89GY9XI4AelA=} dev: true @@ -9242,6 +9301,16 @@ packages: resolution: {integrity: sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA==} dev: false + /tinypool/0.1.3: + resolution: {integrity: sha512-2IfcQh7CP46XGWGGbdyO4pjcKqsmVqFAPcXfPxcPXmOWt9cYkTP9HcDmGgsfijYoAEc4z9qcpM/BaBz46Y9/CQ==} + engines: {node: '>=14.0.0'} + dev: true + + /tinyspy/0.3.2: + resolution: {integrity: sha512-2+40EP4D3sFYy42UkgkFFB+kiX2Tg3URG/lVvAZFfLxgGpnWl5qQJuBw1gaLttq8UOS+2p3C0WrhJnQigLTT2Q==} + engines: {node: '>=14.0.0'} + dev: true + /tmp/0.2.1: resolution: {integrity: sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==} engines: {node: '>=8.17.0'} @@ -9623,6 +9692,34 @@ packages: - react-dom dev: true + /vitest/0.10.4: + resolution: {integrity: sha512-FJ2av2PVozmyz9nqHRoC3H8j2z0OQXj8P8jS5oyMY9mfPWB06GS5k/1Ot++TkVBLQRHZCcVzjbK4BO7zqAJZGQ==} + engines: {node: '>=v14.16.0'} + hasBin: true + peerDependencies: + '@vitest/ui': '*' + c8: '*' + happy-dom: '*' + jsdom: '*' + peerDependenciesMeta: + '@vitest/ui': + optional: true + c8: + optional: true + happy-dom: + optional: true + jsdom: + optional: true + dependencies: + '@types/chai': 4.3.1 + '@types/chai-subset': 1.3.3 + chai: 4.3.6 + local-pkg: 0.4.1 + tinypool: 0.1.3 + tinyspy: 0.3.2 + vite: link:packages/vite + dev: true + /void-elements/3.1.0: resolution: {integrity: sha1-YU9/v42AHwu18GYfWy9XhXUOTwk=} engines: {node: '>=0.10.0'} diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 00000000000000..78e54e98cc02d9 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + exclude: [ + '**/node_modules/**', + '**/dist/**', + './packages/playground/**/*.*', + './packages/temp/**/*.*' + ] + }, + esbuild: { + target: 'node14' + } +}) From 5280908972219392a0d8daa2a33553868ca7072b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Fri, 6 May 2022 18:26:47 +0900 Subject: [PATCH 055/114] fix(css): hoist external @import for non-split css (#8022) --- packages/playground/lib/__tests__/lib.spec.ts | 7 +++++ packages/playground/lib/__tests__/serve.js | 14 +++++++++- packages/playground/lib/src/dynamic.css | 4 +++ packages/playground/lib/src/index.css | 3 ++ packages/playground/lib/src/main2.js | 5 ++++ .../playground/lib/vite.dyimport.config.js | 1 - packages/vite/src/node/plugins/css.ts | 28 +++++++++++-------- 7 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 packages/playground/lib/src/dynamic.css create mode 100644 packages/playground/lib/src/index.css diff --git a/packages/playground/lib/__tests__/lib.spec.ts b/packages/playground/lib/__tests__/lib.spec.ts index f1e93e90d8357b..cc5887c2777fcb 100644 --- a/packages/playground/lib/__tests__/lib.spec.ts +++ b/packages/playground/lib/__tests__/lib.spec.ts @@ -35,6 +35,13 @@ if (isBuild) { ) expect(code).not.toMatch('__vitePreload') }) + + test('@import hoist', async () => { + serverLogs.forEach((log) => { + // no warning from esbuild css minifier + expect(log).not.toMatch('All "@import" rules must come first') + }) + }) } else { test('dev', async () => { expect(await page.textContent('.demo')).toBe('It works') diff --git a/packages/playground/lib/__tests__/serve.js b/packages/playground/lib/__tests__/serve.js index eac6980286af52..2534545de5c221 100644 --- a/packages/playground/lib/__tests__/serve.js +++ b/packages/playground/lib/__tests__/serve.js @@ -9,6 +9,8 @@ const { ports } = require('../../testUtils') const port = (exports.port = ports.lib) +global.serverLogs = [] + /** * @param {string} root * @param {boolean} isBuildTest @@ -16,6 +18,8 @@ const port = (exports.port = ports.lib) exports.serve = async function serve(root, isBuildTest) { // build first + setupConsoleWarnCollector() + if (!isBuildTest) { const { createServer } = require('vite') process.env.VITE_INLINE = 'inline-serve' @@ -55,7 +59,7 @@ exports.serve = async function serve(root, isBuildTest) { await build({ root, - logLevel: 'silent', + logLevel: 'warn', // output esbuild warns configFile: path.resolve(__dirname, '../vite.dyimport.config.js') }) @@ -89,3 +93,11 @@ exports.serve = async function serve(root, isBuildTest) { }) } } + +function setupConsoleWarnCollector() { + const warn = console.warn + console.warn = (...args) => { + global.serverLogs.push(args.join(' ')) + return warn.call(console, ...args) + } +} diff --git a/packages/playground/lib/src/dynamic.css b/packages/playground/lib/src/dynamic.css new file mode 100644 index 00000000000000..4378c8d328cfbe --- /dev/null +++ b/packages/playground/lib/src/dynamic.css @@ -0,0 +1,4 @@ +@import 'https://cdn.jsdelivr.net/npm/@mdi/font@5.9.55/css/materialdesignicons.min.css'; +.dynamic { + color: red; +} diff --git a/packages/playground/lib/src/index.css b/packages/playground/lib/src/index.css new file mode 100644 index 00000000000000..b0bd670bd9ecad --- /dev/null +++ b/packages/playground/lib/src/index.css @@ -0,0 +1,3 @@ +.index { + color: blue; +} diff --git a/packages/playground/lib/src/main2.js b/packages/playground/lib/src/main2.js index 0c729fad8d165c..f19a16bb128949 100644 --- a/packages/playground/lib/src/main2.js +++ b/packages/playground/lib/src/main2.js @@ -1,4 +1,9 @@ +import './index.css' + export default async function message(sel) { const message = await import('./message.js') + + await import('./dynamic.css') + document.querySelector(sel).textContent = message.default } diff --git a/packages/playground/lib/vite.dyimport.config.js b/packages/playground/lib/vite.dyimport.config.js index 76311f4b8ba138..d738503f0c9d09 100644 --- a/packages/playground/lib/vite.dyimport.config.js +++ b/packages/playground/lib/vite.dyimport.config.js @@ -6,7 +6,6 @@ const path = require('path') */ module.exports = { build: { - minify: false, lib: { entry: path.resolve(__dirname, 'src/main2.js'), formats: ['es'], diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index cd57acd1690902..c61e059867080b 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -443,13 +443,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } }) // only external @imports and @charset should exist at this point - // hoist them to the top of the CSS chunk per spec (#1845 and #6333) - if (css.includes('@import') || css.includes('@charset')) { - css = await hoistAtRules(css) - } - if (minify && config.build.minify) { - css = await minifyCSS(css, config) - } + css = await finalizeCss(css, minify, config) return css } @@ -559,10 +553,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { let extractedCss = outputToExtractedCSSMap.get(opts) if (extractedCss && !hasEmitted) { hasEmitted = true - // minify css - if (config.build.minify) { - extractedCss = await minifyCSS(extractedCss, config) - } + extractedCss = await finalizeCss(extractedCss, true, config) this.emitFile({ name: 'style.css', type: 'asset', @@ -922,6 +913,21 @@ function combineSourcemapsIfExists( : map1 } +async function finalizeCss( + css: string, + minify: boolean, + config: ResolvedConfig +) { + // hoist external @imports and @charset to the top of the CSS chunk per spec (#1845 and #6333) + if (css.includes('@import') || css.includes('@charset')) { + css = await hoistAtRules(css) + } + if (minify && config.build.minify) { + css = await minifyCSS(css, config) + } + return css +} + interface PostCSSConfigResult { options: PostCSS.ProcessOptions plugins: PostCSS.Plugin[] From e0fe2008b248aec4813efba34db9e644b851943a Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Fri, 6 May 2022 14:24:40 +0200 Subject: [PATCH 056/114] fix(plugin-vue): allow overwriting template.transformAssetUrls.includeAbsolute (fix #4836) (#6779) --- packages/plugin-vue/src/template.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-vue/src/template.ts b/packages/plugin-vue/src/template.ts index 72e9588967556e..c7eed9015d6339 100644 --- a/packages/plugin-vue/src/template.ts +++ b/packages/plugin-vue/src/template.ts @@ -139,7 +139,7 @@ export function resolveTemplateCompilerOptions( tags: transformAssetUrls as any } } else { - transformAssetUrls = { ...transformAssetUrls, ...assetUrlOptions } + transformAssetUrls = { ...assetUrlOptions, ...transformAssetUrls } } } else { transformAssetUrls = assetUrlOptions From c7356e0f8e7a8f7476db90204638d9834cb58101 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 6 May 2022 16:42:51 -0400 Subject: [PATCH 057/114] fix: invalidate ssrError when HMR update occurs (#8052) --- packages/vite/src/node/server/hmr.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vite/src/node/server/hmr.ts b/packages/vite/src/node/server/hmr.ts index 8d33554706dee2..8eca99268e93d7 100644 --- a/packages/vite/src/node/server/hmr.ts +++ b/packages/vite/src/node/server/hmr.ts @@ -294,6 +294,7 @@ function invalidate(mod: ModuleNode, timestamp: number, seen: Set) { mod.lastHMRTimestamp = timestamp mod.transformResult = null mod.ssrModule = null + mod.ssrError = null mod.ssrTransformResult = null mod.importers.forEach((importer) => { if (!importer.acceptedHmrDeps.has(mod)) { From 8897da18a084d138dd32a5b4734220520e08e5a4 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 7 May 2022 11:07:05 +0800 Subject: [PATCH 058/114] chore: update workspace setup --- package.json | 2 +- pnpm-lock.yaml | 23 ----------------------- pnpm-workspace.yaml | 2 ++ 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 843b6a4e030e39..eae96bb7fa8dd1 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "preinstall": "npx only-allow pnpm", "format": "prettier --write .", "lint": "eslint packages/*/{src,types}/**", - "test": "run-s test-serve test-build test-unit", + "test": "run-s test-unit test-serve test-build", "test-serve": "jest", "test-build": "cross-env VITE_TEST_BUILD=1 jest", "test-unit": "vitest run", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f15dbb27aae88..d1d5b496892229 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -280,32 +280,9 @@ importers: test-package-d: link:test-package-d test-package-e: link:test-package-e - packages/playground/nested-deps/test-package-a: - specifiers: {} - - packages/playground/nested-deps/test-package-b: - specifiers: {} - - packages/playground/nested-deps/test-package-c: - specifiers: {} - - packages/playground/nested-deps/test-package-d: - specifiers: - test-package-d-nested: link:./test-package-d-nested - dependencies: - test-package-d-nested: link:test-package-d-nested - packages/playground/nested-deps/test-package-d/test-package-d-nested: specifiers: {} - packages/playground/nested-deps/test-package-e: - specifiers: - test-package-e-excluded: link:./test-package-e-excluded - test-package-e-included: link:./test-package-e-included - dependencies: - test-package-e-excluded: link:test-package-e-excluded - test-package-e-included: link:test-package-e-included - packages/playground/nested-deps/test-package-e/test-package-e-excluded: specifiers: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index f8a7dd53d45fb0..a4e6b07cfdf222 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,5 @@ packages: - 'packages/*' - 'packages/playground/**' + - '!packages/temp' + - '!packages/playground/nested-deps/test-package-*' From b44d745360435d9eb607eaca239cc396ae41c1c0 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 7 May 2022 11:32:35 +0800 Subject: [PATCH 059/114] chore: revert workspace change --- pnpm-workspace.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index a4e6b07cfdf222..f8a7dd53d45fb0 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,5 +1,3 @@ packages: - 'packages/*' - 'packages/playground/**' - - '!packages/temp' - - '!packages/playground/nested-deps/test-package-*' From dc323a0a230f57de0d102782dd4e673fb6b2d06c Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 7 May 2022 11:32:52 +0800 Subject: [PATCH 060/114] chore: update lock --- pnpm-lock.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d1d5b496892229..3f15dbb27aae88 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -280,9 +280,32 @@ importers: test-package-d: link:test-package-d test-package-e: link:test-package-e + packages/playground/nested-deps/test-package-a: + specifiers: {} + + packages/playground/nested-deps/test-package-b: + specifiers: {} + + packages/playground/nested-deps/test-package-c: + specifiers: {} + + packages/playground/nested-deps/test-package-d: + specifiers: + test-package-d-nested: link:./test-package-d-nested + dependencies: + test-package-d-nested: link:test-package-d-nested + packages/playground/nested-deps/test-package-d/test-package-d-nested: specifiers: {} + packages/playground/nested-deps/test-package-e: + specifiers: + test-package-e-excluded: link:./test-package-e-excluded + test-package-e-included: link:./test-package-e-included + dependencies: + test-package-e-excluded: link:test-package-e-excluded + test-package-e-included: link:test-package-e-included + packages/playground/nested-deps/test-package-e/test-package-e-excluded: specifiers: {} From fe704f1ff7a5532d9efd9999d9fc8793884e9fe8 Mon Sep 17 00:00:00 2001 From: patak Date: Sat, 7 May 2022 07:20:00 +0200 Subject: [PATCH 061/114] fix: graceful rename in windows (#8036) --- packages/vite/src/node/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index d41dd6850ebb56..29741989ea2326 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -775,8 +775,8 @@ function gracefulRename( ) { setTimeout(function () { fs.stat(to, function (stater, st) { - if (stater && stater.code === 'ENOENT') gracefulRename(from, to, CB) - else cb(er) + if (stater && stater.code === 'ENOENT') fs.rename(from, to, CB) + else CB(er) }) }, backoff) if (backoff < 100) backoff += 10 From 1ffc0107e81d9196284a42dd450b8ff9d038b245 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 7 May 2022 13:30:08 +0800 Subject: [PATCH 062/114] fix: use `strip-literal` to strip string lterals (#8054) --- packages/vite/LICENSE.md | 29 ++++ packages/vite/package.json | 1 + .../src/node/__tests__/cleanString.spec.ts | Bin 4756 -> 0 bytes packages/vite/src/node/cleanString.ts | 145 ------------------ .../src/node/plugins/assetImportMetaUrl.ts | 4 +- packages/vite/src/node/plugins/css.ts | 2 +- packages/vite/src/node/plugins/html.ts | 4 +- .../src/node/plugins/workerImportMetaUrl.ts | 4 +- packages/vite/src/node/utils.ts | 4 + pnpm-lock.yaml | 8 + 10 files changed, 49 insertions(+), 152 deletions(-) delete mode 100644 packages/vite/src/node/__tests__/cleanString.spec.ts delete mode 100644 packages/vite/src/node/cleanString.ts diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index 30803708e30a76..80feb7f95c6941 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -3465,6 +3465,35 @@ Repository: chalk/strip-ansi --------------------------------------- +## strip-literal +License: MIT +By: Anthony Fu +Repository: git+https://github.com/antfu/strip-literal.git + +> MIT License +> +> Copyright (c) 2022 Anthony Fu +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all +> copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. + +--------------------------------------- + ## to-regex-range License: MIT By: Jon Schlinkert, Rouven Weßling diff --git a/packages/vite/package.json b/packages/vite/package.json index 55c86878622111..b508842619033e 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -112,6 +112,7 @@ "source-map-js": "^1.0.2", "source-map-support": "^0.5.21", "strip-ansi": "^6.0.1", + "strip-literal": "^0.2.0", "terser": "^5.13.1", "tsconfck": "^1.2.2", "tslib": "^2.4.0", diff --git a/packages/vite/src/node/__tests__/cleanString.spec.ts b/packages/vite/src/node/__tests__/cleanString.spec.ts deleted file mode 100644 index 99ecbcaad444023d10ed467f6cd9b2794fa935bd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4756 zcmc&&TW{h<6z(&>;>e0LHbgjVyDwE)sqNEBttvID`Vc4bULVgdHr(Vhw5>j>q99dtRn_6|U?$ zQ-ic-GV6`~a&OBt@6aXe3caIwaIOz zZov;=`T@2Ba4bIdu-|I-W1a~^a9k5;`>&T|JS0+-{|<(so8bl=CoX->6U}mGq2=jM z9@YxqK*%adC%hK{aWF>U)_#DBuv`3Ke5HcHE~qi67}q`oNs(6;7+07c2Z8MudX2P7 z<45tN*wS@h$Yx09&G6$nGH%Ypq}hZ6KBGw4d7qsi$A8u~S@~Ya)aXwBlt zDA?wj-s|CKszh%LBr9F&#G0}fOTv8^NHvKfH4(f#?0XXdMf&|Q(sd_rSkvM>3*vR8 z!GBp&6Y7)Py2Y+&Qy%JS`!wi`c<9ESLRGac#e>d>)?_t)i(+2b26-gxhFxivh&brQ z0`v1M%t9r}gaRdiJQ)ji=UL%`zfNh$@mMhPo;fZqSk)<)8)u%zly$M* z#_hWfHQU_AsEavDC$AfGZIGU5j5^C0M|~}0qWCOpYVu2&vv)sevdGLhE0%IH;D8T< z>u4QH6dcqF7>CViGefwD{wk&@IL{QJzltfi(dXIX7)~^%Ep&@CpGz$RNqbmidI@O` zrT&D?+YekgtBs~f z75jD>H84WYV*Ea&kO)vCQ(RRyA&d^5Z;-(6Sg&a+hTF|HK?8lt=k4rUnCt=^&UgO| zphU<~_6wnl`2d_8HJB%u-NpU{a>_Z5OQ(x0Z}30W(^uPeDjVs(KQ$Jo_0m*f zR_HlCzw36qOc!|m%L{$HHdc?H%PbhLO0(ES9_Y+YmHI#hQrw6eJh!}8*8~} z({BlwK;4@@p0%9{!u#8nGKRFhWc>MD;7<#Dsh|hWNf!!!3Zc$0ie|V2QB;lm-;44O zQ@-5etJ2J65a7ZvihOE(M~9o$omCG{>T#rAyoV?6apb*3@xxOTKaQf9nQw_!_AH8c z*Ra8T6A?iWE^)v9{nh1To~60D&-JES71sS;B6lQ8dnwzEvtRwUA9*7J-!<{-h&%Q- DgfAcj diff --git a/packages/vite/src/node/cleanString.ts b/packages/vite/src/node/cleanString.ts deleted file mode 100644 index d990ab75f15d7c..00000000000000 --- a/packages/vite/src/node/cleanString.ts +++ /dev/null @@ -1,145 +0,0 @@ -import type { RollupError } from 'rollup' -import { multilineCommentsRE, singlelineCommentsRE } from './utils' - -// bank on the non-overlapping nature of regex matches and combine all filters into one giant regex -// /`([^`\$\{\}]|\$\{(`|\g<1>)*\})*`/g can match nested string template -// but js not support match expression(\g<0>). so clean string template(`...`) in other ways. -const stringsRE = /"([^"\r\n]|(?<=\\)")*"|'([^'\r\n]|(?<=\\)')*'/g -const regexRE = /\/.*?(? ' '.repeat(s.length) -const stringBlankReplacer = (s: string) => - `${s[0]}${'\0'.repeat(s.length - 2)}${s[0]}` - -export function emptyString(raw: string): string { - let res = raw - .replace(cleanerRE, (s: string) => - s[0] === '/' ? blankReplacer(s) : stringBlankReplacer(s) - ) - .replace(regexRE, (s) => stringBlankReplacer(s)) - - let lastEnd = 0 - let start = 0 - while ((start = res.indexOf('`', lastEnd)) >= 0) { - let clean - ;[clean, lastEnd] = lexStringTemplateExpression(res, start) - res = replaceAt(res, start, lastEnd, clean) - } - - return res -} - -export function emptyCssComments(raw: string) { - return raw.replace(multilineCommentsRE, blankReplacer) -} - -const enum LexerState { - // template string - inTemplateString, - inInterpolationExpression, - inObjectExpression, - // strings - inSingleQuoteString, - inDoubleQuoteString, - // comments - inMultilineCommentsRE, - inSinglelineCommentsRE -} - -function replaceAt( - string: string, - start: number, - end: number, - replacement: string -): string { - return string.slice(0, start) + replacement + string.slice(end) -} - -/** - * lex string template and clean it. - */ -function lexStringTemplateExpression( - code: string, - start: number -): [string, number] { - let state = LexerState.inTemplateString as LexerState - let clean = '`' - const opStack: LexerState[] = [state] - - function pushStack(newState: LexerState) { - state = newState - opStack.push(state) - } - - function popStack() { - opStack.pop() - state = opStack[opStack.length - 1] - } - - let i = start + 1 - outer: for (; i < code.length; i++) { - const char = code.charAt(i) - switch (state) { - case LexerState.inTemplateString: - if (char === '$' && code.charAt(i + 1) === '{') { - pushStack(LexerState.inInterpolationExpression) - clean += '${' - i++ // jump next - } else if (char === '`') { - popStack() - clean += char - if (opStack.length === 0) { - break outer - } - } else { - clean += '\0' - } - break - case LexerState.inInterpolationExpression: - if (char === '{') { - pushStack(LexerState.inObjectExpression) - clean += char - } else if (char === '}') { - popStack() - clean += char - } else if (char === '`') { - pushStack(LexerState.inTemplateString) - clean += char - } else { - clean += char - } - break - case LexerState.inObjectExpression: - if (char === '}') { - popStack() - clean += char - } else if (char === '`') { - pushStack(LexerState.inTemplateString) - clean += char - } else { - clean += char - } - break - default: - throw new Error('unknown string template lexer state') - } - } - - if (opStack.length !== 0) { - error(start) - } - - return [clean, i + 1] -} - -function error(pos: number) { - const err = new Error( - `can not match string template expression.` - ) as RollupError - err.pos = pos - throw err -} diff --git a/packages/vite/src/node/plugins/assetImportMetaUrl.ts b/packages/vite/src/node/plugins/assetImportMetaUrl.ts index b8c16f76d2b93f..217b0d3fee1564 100644 --- a/packages/vite/src/node/plugins/assetImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/assetImportMetaUrl.ts @@ -3,7 +3,7 @@ import MagicString from 'magic-string' import path from 'path' import { fileToUrl } from './asset' import type { ResolvedConfig } from '../config' -import { emptyString } from '../cleanString' +import { stripLiteral } from 'strip-literal' /** * Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL @@ -27,7 +27,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { let s: MagicString | undefined const assetImportMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*,?\s*\)/g - const cleanString = emptyString(code) + const cleanString = stripLiteral(code) let match: RegExpExecArray | null while ((match = assetImportMetaUrlRE.exec(cleanString))) { diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index c61e059867080b..22dfc33f67a509 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -49,7 +49,7 @@ import { transform, formatMessages } from 'esbuild' import { addToHTMLProxyTransformResult } from './html' import { injectSourcesContent, getCodeWithSourcemap } from '../server/sourcemap' import type { RawSourceMap } from '@ampproject/remapping' -import { emptyCssComments } from '../cleanString' +import { emptyCssComments } from '../utils' // const debug = createDebugger('vite:css') diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index 0223c351af6071..6d793c416ce60a 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -36,7 +36,7 @@ import type { TextNode } from '@vue/compiler-dom' import { NodeTypes } from '@vue/compiler-dom' -import { emptyString } from '../cleanString' +import { stripLiteral } from 'strip-literal' interface ScriptAssetsUrl { start: number @@ -308,7 +308,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { } } else if (node.children.length) { const scriptNode = node.children.pop()! as TextNode - const cleanCode = emptyString(scriptNode.content) + const cleanCode = stripLiteral(scriptNode.content) let match: RegExpExecArray | null while ((match = inlineImportRE.exec(cleanCode))) { diff --git a/packages/vite/src/node/plugins/workerImportMetaUrl.ts b/packages/vite/src/node/plugins/workerImportMetaUrl.ts index 3d8970b746349c..bfd8c22dcad372 100644 --- a/packages/vite/src/node/plugins/workerImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/workerImportMetaUrl.ts @@ -10,7 +10,7 @@ import { ENV_ENTRY, ENV_PUBLIC_PATH } from '../constants' import MagicString from 'magic-string' import type { ViteDevServer } from '..' import type { RollupError } from 'rollup' -import { emptyString } from '../cleanString' +import { stripLiteral } from 'strip-literal' type WorkerType = 'classic' | 'module' | 'ignore' const ignoreFlagRE = /\/\*\s*@vite-ignore\s*\*\// @@ -110,7 +110,7 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin { code.includes('new URL') && code.includes(`import.meta.url`) ) { - const cleanString = emptyString(code) + const cleanString = stripLiteral(code) const workerImportMetaUrlRE = /\bnew\s+(Worker|SharedWorker)\s*\(\s*(new\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/g diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 29741989ea2326..ddcaced9832bc1 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -785,3 +785,7 @@ function gracefulRename( if (cb) cb(er) }) } + +export function emptyCssComments(raw: string) { + return raw.replace(multilineCommentsRE, (s) => ' '.repeat(s.length)) +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f15dbb27aae88..a20eb4e3bb7d1f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -893,6 +893,7 @@ importers: source-map-js: ^1.0.2 source-map-support: ^0.5.21 strip-ansi: ^6.0.1 + strip-literal: ^0.2.0 terser: ^5.13.1 tsconfck: ^1.2.2 tslib: ^2.4.0 @@ -966,6 +967,7 @@ importers: source-map-js: 1.0.2 source-map-support: 0.5.21 strip-ansi: 6.0.1 + strip-literal: 0.2.0 terser: 5.13.1 tsconfck: 1.2.2_typescript@4.5.4 tslib: 2.4.0 @@ -9016,6 +9018,12 @@ packages: engines: {node: '>=8'} dev: true + /strip-literal/0.2.0: + resolution: {integrity: sha512-pqhiiFRDifA2CRVH0Gmv6MDbd2b27MS0oIqqy7JCqfL5m2sh68223lmEK2eoBXp4vNaq8G1Wzwd9dfQcWszUlg==} + dependencies: + acorn: 8.7.1 + dev: true + /stylis/4.0.13: resolution: {integrity: sha512-xGPXiFVl4YED9Jh7Euv2V220mriG9u4B2TA6Ybjc1catrstKD2PpIdU3U0RKpkVBC2EhmL/F0sPCr9vrFTNRag==} From 20ea9999765ea372c20acc39e05cd81b98c9f6fe Mon Sep 17 00:00:00 2001 From: Rom Date: Sat, 7 May 2022 21:23:54 +0200 Subject: [PATCH 063/114] feat: new hook `configurePreviewServer` (#7658) --- docs/guide/api-plugin.md | 22 ++++++++++++++++++++++ packages/vite/src/node/index.ts | 1 + packages/vite/src/node/plugin.ts | 10 ++++++++++ packages/vite/src/node/preview.ts | 20 ++++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md index 50353765261e34..76b9984a069828 100644 --- a/docs/guide/api-plugin.md +++ b/docs/guide/api-plugin.md @@ -305,6 +305,28 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo Note `configureServer` is not called when running the production build so your other hooks need to guard against its absence. +### `configurePreviewServer` + +- **Type:** `(server: { middlewares: Connect.Server, httpServer: http.Server }) => (() => void) | void | Promise<(() => void) | void>` +- **Kind:** `async`, `sequential` + + Same as [`configureServer`](/guide/api-plugin.html#configureserver) but for the preview server. It provides the [connect](https://github.com/senchalabs/connect) server and its underlying [http server](https://nodejs.org/api/http.html). Similarly to `configureServer`, the `configurePreviewServer` hook is called before other middlewares are installed. If you want to inject a middleware **after** other middlewares, you can return a function from `configurePreviewServer`, which will be called after internal middlewares are installed: + + ```js + const myPlugin = () => ({ + name: 'configure-preview-server', + configurePreviewServer(server) { + // return a post hook that is called after other middlewares are + // installed + return () => { + server.middlewares.use((req, res, next) => { + // custom handle request... + }) + } + } + }) + ``` + ### `transformIndexHtml` - **Type:** `IndexHtmlTransformHook | { enforce?: 'pre' | 'post', transform: IndexHtmlTransformHook }` diff --git a/packages/vite/src/node/index.ts b/packages/vite/src/node/index.ts index c15359f45b69de..e56f4c6e765756 100644 --- a/packages/vite/src/node/index.ts +++ b/packages/vite/src/node/index.ts @@ -33,6 +33,7 @@ export type { export type { PreviewOptions, PreviewServer, + PreviewServerHook, ResolvedPreviewOptions } from './preview' export type { diff --git a/packages/vite/src/node/plugin.ts b/packages/vite/src/node/plugin.ts index 354b246dd9f182..3bfe789a299987 100644 --- a/packages/vite/src/node/plugin.ts +++ b/packages/vite/src/node/plugin.ts @@ -13,6 +13,7 @@ import type { IndexHtmlTransform } from './plugins/html' import type { ModuleNode } from './server/moduleGraph' import type { ConfigEnv, ResolvedConfig } from './' import type { HmrContext } from './server/hmr' +import type { PreviewServerHook } from './preview' /** * Vite plugins extends the Rollup plugin interface with a few extra @@ -79,6 +80,15 @@ export interface Plugin extends RollupPlugin { * are applied. Hook can be async functions and will be called in series. */ configureServer?: ServerHook + /** + * Configure the preview server. The hook receives the connect server and + * its underlying http server. + * + * The hooks are called before other middlewares are applied. A hook can + * return a post hook that will be called after other middlewares are + * applied. Hooks can be async functions and will be called in series. + */ + configurePreviewServer?: PreviewServerHook /** * Transform index.html. * The hook receives the following arguments: diff --git a/packages/vite/src/node/preview.ts b/packages/vite/src/node/preview.ts index c1670c5d7efa72..e48f2e6231933f 100644 --- a/packages/vite/src/node/preview.ts +++ b/packages/vite/src/node/preview.ts @@ -14,6 +14,7 @@ import corsMiddleware from 'cors' import { proxyMiddleware } from './server/middlewares/proxy' import { resolveHostname } from './utils' import { printCommonServerUrls } from './logger' +import type * as http from 'http' export interface PreviewOptions extends CommonServerOptions {} @@ -53,6 +54,11 @@ export interface PreviewServer { printUrls: () => void } +export type PreviewServerHook = (server: { + middlewares: Connect.Server + httpServer: http.Server +}) => (() => void) | void | Promise<(() => void) | void> + /** * Starts the Vite server in preview mode, to simulate a production deployment * @experimental @@ -69,6 +75,16 @@ export async function preview( await resolveHttpsConfig(config.preview?.https, config.cacheDir) ) + // apply server hooks from plugins + const postHooks: ((() => void) | void)[] = [] + for (const plugin of config.plugins) { + if (plugin.configurePreviewServer) { + postHooks.push( + await plugin.configurePreviewServer({ middlewares: app, httpServer }) + ) + } + } + // cors const { cors } = config.preview if (cors !== false) { @@ -83,6 +99,7 @@ export async function preview( app.use(compression()) + // static assets const distDir = path.resolve(config.root, config.build.outDir) app.use( config.base, @@ -93,6 +110,9 @@ export async function preview( }) ) + // apply post server hooks from plugins + postHooks.forEach((fn) => fn && fn()) + const options = config.preview const hostname = resolveHostname(options.host) const port = options.port ?? 4173 From 9f8381eb70375d460f8b410f44e0b758eb714234 Mon Sep 17 00:00:00 2001 From: "Jeff Yang (Nay Thu Ya Aung)" <32727188+ydcjeff@users.noreply.github.com> Date: Sun, 8 May 2022 01:57:44 +0630 Subject: [PATCH 064/114] refactor: use optional chaining in config `define` of vue-jsx (#8046) --- packages/plugin-vue-jsx/index.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/plugin-vue-jsx/index.js b/packages/plugin-vue-jsx/index.js index 248270765d19a1..929f4fb44cd434 100644 --- a/packages/plugin-vue-jsx/index.js +++ b/packages/plugin-vue-jsx/index.js @@ -48,12 +48,6 @@ function vueJsxPlugin(options = {}) { name: 'vite:vue-jsx', config(config) { - const optionsApi = config.define - ? config.define.__VUE_OPTIONS_API__ - : undefined - const devTools = config.define - ? config.define.__VUE_PROD_DEVTOOLS__ - : undefined return { // only apply esbuild to ts files // since we are handling jsx and tsx now @@ -61,8 +55,8 @@ function vueJsxPlugin(options = {}) { include: /\.ts$/ }, define: { - __VUE_OPTIONS_API__: optionsApi != null ? optionsApi : true, - __VUE_PROD_DEVTOOLS__: devTools != null ? devTools : false + __VUE_OPTIONS_API__: config.define?.__VUE_OPTIONS_API__ ?? true, + __VUE_PROD_DEVTOOLS__: config.define?.__VUE_PROD_DEVTOOLS__ ?? false } } }, From 939848866d365908749ed257706abd47f60493a5 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 8 May 2022 13:13:40 +0800 Subject: [PATCH 065/114] chore: enable ci for v1 and v2 branch --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5173da859417be..b1c663db40e80f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ on: - feat/* - fix/* - perf/* + - v1 + - v2 pull_request: workflow_dispatch: From cc3129e4336e7c09cc3e4beee0f4f5f964bb8b0f Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 8 May 2022 13:28:32 +0800 Subject: [PATCH 066/114] chore: ignore empty chunk test warning (#8063) --- scripts/jestEnv.cjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/jestEnv.cjs b/scripts/jestEnv.cjs index 255b83063efc5a..b576155644a27f 100644 --- a/scripts/jestEnv.cjs +++ b/scripts/jestEnv.cjs @@ -29,13 +29,13 @@ module.exports = class PlaywrightEnvironment extends NodeEnvironment { })) this.global.page = await browser.newPage() - // suppress @vue/ref-transform warning const console = this.global.console const warn = console.warn console.warn = (msg, ...args) => { - if (!msg.includes('@vue/ref-transform')) { - warn.call(console, msg, ...args) - } + // suppress @vue/ref-transform warning + if (msg.includes('@vue/ref-transform')) return + if (msg.includes('Generated an empty chunk')) return + warn.call(console, msg, ...args) } } From ed4c7598d4c1715a8306190f6e8e2aa8d851b95b Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 8 May 2022 13:52:45 +0800 Subject: [PATCH 067/114] docs: version selector (#8065) --- docs/.vitepress/{config.js => config.ts} | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) rename docs/.vitepress/{config.js => config.ts} (94%) diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.ts similarity index 94% rename from docs/.vitepress/config.js rename to docs/.vitepress/config.ts index ee76a29986d3fb..4659ea5ab7ae4f 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.ts @@ -1,9 +1,6 @@ -// @ts-check +import { defineConfig } from 'vitepress' -/** - * @type {import('vitepress').UserConfig} - */ -module.exports = { +export default defineConfig({ title: 'Vite', description: 'Next Generation Frontend Tooling', head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]], @@ -64,6 +61,15 @@ module.exports = { } ] }, + { + text: 'v3 (next)', + items: [ + { + text: 'v2.x (stable)', + link: 'https://v2.vitejs.dev' + } + ] + }, { text: 'Languages', items: [ @@ -169,4 +175,4 @@ module.exports = { ] } } -} +}) From b215493b6c01d9d299094e27a0f6bae694b71eff Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 8 May 2022 15:19:01 +0800 Subject: [PATCH 068/114] docs: note about v3.0 branch (#8064) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 546014a12c7116..e07879c7ece2a6 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ In addition, Vite is highly extensible via its [Plugin API](https://vitejs.dev/g ## Packages +> This branch is for upcoming v3.0, if you are looking for current stable releases, check the [`2.x` branch](https://github.com/vitejs/vite/tree/2.x) instead. + | Package | Version (click for changelogs) | | ------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------- | | [vite](packages/vite) | [![vite version](https://img.shields.io/npm/v/vite.svg?label=%20)](packages/vite/CHANGELOG.md) | From 330e0a90988509454e31067984bf0cdbe2465325 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 8 May 2022 16:16:44 +0800 Subject: [PATCH 069/114] feat!: rework `import.meta.glob` (#7537) --- docs/guide/features.md | 115 ++++- .../assets/__tests__/assets.spec.ts | 4 +- packages/playground/css/main.js | 4 +- .../glob-import/__tests__/glob-import.spec.ts | 4 +- packages/vite/LICENSE.md | 28 ++ packages/vite/package.json | 3 +- .../__snapshots__/fixture.test.ts.snap | 154 ++++++ .../plugins/importGlob/fixture-a/.gitignore | 1 + .../plugins/importGlob/fixture-a/index.ts | 64 +++ .../plugins/importGlob/fixture-a/modules/a.ts | 1 + .../plugins/importGlob/fixture-a/modules/b.ts | 1 + .../importGlob/fixture-a/modules/index.ts | 6 + .../framework/pages/hello.page.js | 4 + .../plugins/importGlob/fixture-a/sibling.ts | 1 + .../plugins/importGlob/fixture-b/a.ts | 1 + .../plugins/importGlob/fixture-b/b.ts | 1 + .../plugins/importGlob/fixture-b/index.ts | 2 + .../plugins/importGlob/fixture.test.ts | 59 +++ .../plugins/importGlob/parse.test.ts | 202 ++++++++ .../plugins/importGlob/utils.test.ts | 31 ++ packages/vite/src/node/config.ts | 18 + packages/vite/src/node/importGlob.ts | 246 --------- packages/vite/src/node/index.ts | 13 +- packages/vite/src/node/optimizer/scan.ts | 78 +-- .../src/node/plugins/assetImportMetaUrl.ts | 6 +- packages/vite/src/node/plugins/css.ts | 13 - .../vite/src/node/plugins/importAnalysis.ts | 44 -- .../src/node/plugins/importAnalysisBuild.ts | 46 +- .../vite/src/node/plugins/importMetaGlob.ts | 465 ++++++++++++++++++ packages/vite/src/node/plugins/index.ts | 2 + packages/vite/src/node/plugins/worker.ts | 4 +- packages/vite/src/node/server/hmr.ts | 37 +- packages/vite/src/node/server/index.ts | 21 +- packages/vite/types/chokidar.d.ts | 6 +- packages/vite/types/importGlob.d.ts | 89 ++++ packages/vite/types/importMeta.d.ts | 14 +- packages/vite/types/shims.d.ts | 8 - pnpm-lock.yaml | 14 +- 38 files changed, 1308 insertions(+), 502 deletions(-) create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/.gitignore create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/index.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/a.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/b.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/index.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/node_modules/framework/pages/hello.page.js create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/sibling.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/a.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/b.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/index.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/fixture.test.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/parse.test.ts create mode 100644 packages/vite/src/node/__tests__/plugins/importGlob/utils.test.ts delete mode 100644 packages/vite/src/node/importGlob.ts create mode 100644 packages/vite/src/node/plugins/importMetaGlob.ts create mode 100644 packages/vite/types/importGlob.d.ts diff --git a/docs/guide/features.md b/docs/guide/features.md index 1a8c03bbd0be22..01798ad0d4ea56 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -282,10 +282,10 @@ for (const path in modules) { } ``` -Matched files are by default lazy loaded via dynamic import and will be split into separate chunks during build. If you'd rather import all the modules directly (e.g. relying on side-effects in these modules to be applied first), you can use `import.meta.globEager` instead: +Matched files are by default lazy-loaded via dynamic import and will be split into separate chunks during build. If you'd rather import all the modules directly (e.g. relying on side-effects in these modules to be applied first), you can pass `{ eager: true }` as the second argument: ```js -const modules = import.meta.globEager('./dir/*.js') +const modules = import.meta.glob('./dir/*.js', { eager: true }) ``` The above will be transformed into the following: @@ -300,7 +300,9 @@ 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)) with the [Import Reflection](https://github.com/tc39/proposal-import-reflection) syntax: +### Glob Import As + +`import.meta.glob` also supports importing files as strings (similar to [Importing Asset as String](https://vitejs.dev/guide/assets.html#importing-asset-as-string)) with the [Import Reflection](https://github.com/tc39/proposal-import-reflection) syntax: ```js const modules = import.meta.glob('./dir/*.js', { as: 'raw' }) @@ -311,18 +313,115 @@ 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' + './dir/foo.js': 'export default "foo"\n', + './dir/bar.js': 'export default "bar"\n' +} +``` + +`{ as: 'url' }` is also supported for loading assets as URLs. + +### Multiple Patterns + +The first argument can be an array of globs, for example + +```js +const modules = import.meta.glob(['./dir/*.js', './another/*.js']) +``` + +### Negative Patterns + +Negative glob patterns are also supported (prefixed with `!`). To ignore some files from the result, you can add exclude glob patterns to the first argument: + +```js +const modules = import.meta.glob(['./dir/*.js', '!**/bar.js']) +``` + +```js +// code produced by vite +const modules = { + './dir/foo.js': () => import('./dir/foo.js') +} +``` + +#### Named Imports + +It's possible to only import parts of the modules with the `import` options. + +```ts +const modules = import.meta.glob('./dir/*.js', { import: 'setup' }) +``` + +```ts +// code produced by vite +const modules = { + './dir/foo.js': () => import('./dir/foo.js').then((m) => m.setup), + './dir/bar.js': () => import('./dir/bar.js').then((m) => m.setup) +} +``` + +When combined with `eager` it's even possible to have tree-shaking enabled for those modules. + +```ts +const modules = import.meta.glob('./dir/*.js', { import: 'setup', eager: true }) +``` + +```ts +// code produced by vite: +import { setup as __glob__0_0 } from './dir/foo.js' +import { setup as __glob__0_1 } from './dir/bar.js' +const modules = { + './dir/foo.js': __glob__0_0, + './dir/bar.js': __glob__0_1 +} +``` + +Set `import` to `default` to import the default export. + +```ts +const modules = import.meta.glob('./dir/*.js', { + import: 'default', + eager: true +}) +``` + +```ts +// code produced by vite: +import __glob__0_0 from './dir/foo.js' +import __glob__0_1 from './dir/bar.js' +const modules = { + './dir/foo.js': __glob__0_0, + './dir/bar.js': __glob__0_1 +} +``` + +#### Custom Queries + +You can also use the `query` option to provide custom queries to imports for other plugins to consume. + +```ts +const modules = import.meta.glob('./dir/*.js', { + query: { foo: 'bar', bar: true } +}) +``` + +```ts +// code produced by vite: +const modules = { + './dir/foo.js': () => + import('./dir/foo.js?foo=bar&bar=true').then((m) => m.setup), + './dir/bar.js': () => + import('./dir/bar.js?foo=bar&bar=true').then((m) => m.setup) } ``` +### Glob Import Caveats + Note that: - This is a Vite-only feature and is not a web or ES standard. - The glob patterns are treated like import specifiers: they must be either relative (start with `./`) or absolute (start with `/`, resolved relative to project root) or an alias path (see [`resolve.alias` option](/config/#resolve-alias)). -- The glob matching is done via `fast-glob` - check out its documentation for [supported glob patterns](https://github.com/mrmlnc/fast-glob#pattern-syntax). -- You should also be aware that glob imports do not accept variables, you need to directly pass the string pattern. -- The glob patterns cannot contain the same quote string (i.e. `'`, `"`, `` ` ``) as outer quotes, e.g. `'/Tom\'s files/**'`, use `"/Tom's files/**"` instead. +- The glob matching is done via [`fast-glob`](https://github.com/mrmlnc/fast-glob) - check out its documentation for [supported glob patterns](https://github.com/mrmlnc/fast-glob#pattern-syntax). +- You should also be aware that all the arguments in the `import.meta.glob` must be **passed as literals**. You can NOT use variables or expressions in them. ## WebAssembly diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index f1075f6fe1cb39..c63ffc7cc1c0c2 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -145,8 +145,8 @@ describe('css url() references', () => { expect(await getBg('.css-url-quotes-base64-inline')).toMatch(match) const icoMatch = isBuild ? `data:image/x-icon;base64` : `favicon.ico` const el = await page.$(`link.ico`) - const herf = await el.getAttribute('href') - expect(herf).toMatch(icoMatch) + const href = await el.getAttribute('href') + expect(href).toMatch(icoMatch) }) test('multiple urls on the same line', async () => { diff --git a/packages/playground/css/main.js b/packages/playground/css/main.js index f728b0251066d1..f6072ae751df76 100644 --- a/packages/playground/css/main.js +++ b/packages/playground/css/main.js @@ -80,7 +80,9 @@ text('.inlined-code', inlined) // glob const glob = import.meta.glob('./glob-import/*.css') -Promise.all(Object.keys(glob).map((key) => glob[key]())).then((res) => { +Promise.all( + Object.keys(glob).map((key) => glob[key]().then((i) => i.default)) +).then((res) => { text('.imported-css-glob', JSON.stringify(res, null, 2)) }) diff --git a/packages/playground/glob-import/__tests__/glob-import.spec.ts b/packages/playground/glob-import/__tests__/glob-import.spec.ts index ebdf6c0ab29193..d738ccec1d4c97 100644 --- a/packages/playground/glob-import/__tests__/glob-import.spec.ts +++ b/packages/playground/glob-import/__tests__/glob-import.spec.ts @@ -42,7 +42,7 @@ const allResult = { }, '/dir/index.js': { globWithAlias: { - './alias.js': { + '/dir/alias.js': { default: 'hi' } }, @@ -67,7 +67,7 @@ const rawResult = { } const relativeRawResult = { - '../glob-import/dir/baz.json': { + './dir/baz.json': { msg: 'baz' } } diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index 80feb7f95c6941..2b43883f1b2b67 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -3606,6 +3606,34 @@ Repository: git+https://github.com/dominikg/tsconfck.git --------------------------------------- +## ufo +License: MIT +Repository: unjs/ufo + +> MIT License +> +> Copyright (c) 2020 Nuxt Contrib +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all +> copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. + +--------------------------------------- + ## unpipe License: MIT By: Douglas Christopher Wilson diff --git a/packages/vite/package.json b/packages/vite/package.json index b508842619033e..2e930f0f1f6741 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -112,11 +112,12 @@ "source-map-js": "^1.0.2", "source-map-support": "^0.5.21", "strip-ansi": "^6.0.1", - "strip-literal": "^0.2.0", + "strip-literal": "^0.3.0", "terser": "^5.13.1", "tsconfck": "^1.2.2", "tslib": "^2.4.0", "types": "link:./types", + "ufo": "^0.8.4", "ws": "^8.6.0" }, "peerDependencies": { diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap b/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap new file mode 100644 index 00000000000000..3b611c60c9cedc --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap @@ -0,0 +1,154 @@ +// Vitest Snapshot v1 + +exports[`fixture > transform 1`] = ` +"import * as __vite_glob_1_0 from \\"./modules/a.ts\\" +import * as __vite_glob_1_1 from \\"./modules/b.ts\\" +import * as __vite_glob_1_2 from \\"./modules/index.ts\\" +import { name as __vite_glob_3_0 } from \\"./modules/a.ts\\" +import { name as __vite_glob_3_1 } from \\"./modules/b.ts\\" +import { name as __vite_glob_3_2 } from \\"./modules/index.ts\\" +import { default as __vite_glob_5_0 } from \\"./modules/a.ts?raw\\" +import { default as __vite_glob_5_1 } from \\"./modules/b.ts?raw\\" +import \\"../../../../../../types/importMeta\\"; +export const basic = { +\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), +\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"), +\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\") +}; +export const basicEager = { +\\"./modules/a.ts\\": __vite_glob_1_0, +\\"./modules/b.ts\\": __vite_glob_1_1, +\\"./modules/index.ts\\": __vite_glob_1_2 +}; +export const ignore = { +\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), +\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\") +}; +export const namedEager = { +\\"./modules/a.ts\\": __vite_glob_3_0, +\\"./modules/b.ts\\": __vite_glob_3_1, +\\"./modules/index.ts\\": __vite_glob_3_2 +}; +export const namedDefault = { +\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]), +\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]), +\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"]) +}; +export const eagerAs = { +\\"./modules/a.ts\\": __vite_glob_5_0, +\\"./modules/b.ts\\": __vite_glob_5_1 +}; +export const excludeSelf = { +\\"./sibling.ts\\": () => import(\\"./sibling.ts\\") +}; +export const customQueryString = { +\\"./sibling.ts\\": () => import(\\"./sibling.ts?custom\\") +}; +export const customQueryObject = { +\\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true\\") +}; +export const parent = { + +}; +export const rootMixedRelative = { +\\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url\\").then(m => m[\\"default\\"]), +\\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url\\").then(m => m[\\"default\\"]), +\\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url\\").then(m => m[\\"default\\"]), +\\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url\\").then(m => m[\\"default\\"]), +\\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url\\").then(m => m[\\"default\\"]), +\\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url\\").then(m => m[\\"default\\"]) +}; +export const cleverCwd1 = { +\\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\") +}; +export const cleverCwd2 = { +\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), +\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"), +\\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"), +\\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\") +}; +" +`; + +exports[`fixture > transform with restoreQueryExtension 1`] = ` +"import * as __vite_glob_1_0 from \\"./modules/a.ts\\" +import * as __vite_glob_1_1 from \\"./modules/b.ts\\" +import * as __vite_glob_1_2 from \\"./modules/index.ts\\" +import { name as __vite_glob_3_0 } from \\"./modules/a.ts\\" +import { name as __vite_glob_3_1 } from \\"./modules/b.ts\\" +import { name as __vite_glob_3_2 } from \\"./modules/index.ts\\" +import { default as __vite_glob_5_0 } from \\"./modules/a.ts?raw\\" +import { default as __vite_glob_5_1 } from \\"./modules/b.ts?raw\\" +import \\"../../../../../../types/importMeta\\"; +export const basic = { +\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), +\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"), +\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\") +}; +export const basicEager = { +\\"./modules/a.ts\\": __vite_glob_1_0, +\\"./modules/b.ts\\": __vite_glob_1_1, +\\"./modules/index.ts\\": __vite_glob_1_2 +}; +export const ignore = { +\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), +\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\") +}; +export const namedEager = { +\\"./modules/a.ts\\": __vite_glob_3_0, +\\"./modules/b.ts\\": __vite_glob_3_1, +\\"./modules/index.ts\\": __vite_glob_3_2 +}; +export const namedDefault = { +\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]), +\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]), +\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"]) +}; +export const eagerAs = { +\\"./modules/a.ts\\": __vite_glob_5_0, +\\"./modules/b.ts\\": __vite_glob_5_1 +}; +export const excludeSelf = { +\\"./sibling.ts\\": () => import(\\"./sibling.ts\\") +}; +export const customQueryString = { +\\"./sibling.ts\\": () => import(\\"./sibling.ts?custom&lang.ts\\") +}; +export const customQueryObject = { +\\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true&lang.ts\\") +}; +export const parent = { + +}; +export const rootMixedRelative = { +\\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]), +\\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]), +\\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]), +\\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url&lang.ts\\").then(m => m[\\"default\\"]), +\\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url&lang.ts\\").then(m => m[\\"default\\"]), +\\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url&lang.ts\\").then(m => m[\\"default\\"]) +}; +export const cleverCwd1 = { +\\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\") +}; +export const cleverCwd2 = { +\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), +\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"), +\\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"), +\\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\") +}; +" +`; + +exports[`fixture > virtual modules 1`] = ` +"{ +\\"/modules/a.ts\\": () => import(\\"/modules/a.ts\\"), +\\"/modules/b.ts\\": () => import(\\"/modules/b.ts\\"), +\\"/modules/index.ts\\": () => import(\\"/modules/index.ts\\") +} +{ +\\"/../fixture-b/a.ts\\": () => import(\\"/../fixture-b/a.ts\\"), +\\"/../fixture-b/b.ts\\": () => import(\\"/../fixture-b/b.ts\\"), +\\"/../fixture-b/index.ts\\": () => import(\\"/../fixture-b/index.ts\\") +}" +`; diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/.gitignore b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/.gitignore new file mode 100644 index 00000000000000..2b9b8877da603f --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/.gitignore @@ -0,0 +1 @@ +!/node_modules/ diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/index.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/index.ts new file mode 100644 index 00000000000000..c5b806da06a4b4 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/index.ts @@ -0,0 +1,64 @@ +import '../../../../../../types/importMeta' + +/* eslint-disable @typescript-eslint/comma-dangle */ +export interface ModuleType { + name: string +} + +export const basic = import.meta.glob('./modules/*.ts') + +export const basicEager = import.meta.glob('./modules/*.ts', { + eager: true +}) + +export const ignore = import.meta.glob(['./modules/*.ts', '!**/index.ts']) + +export const namedEager = import.meta.glob('./modules/*.ts', { + eager: true, + import: 'name' +}) + +export const namedDefault = import.meta.glob('./modules/*.ts', { + import: 'default' +}) + +export const eagerAs = import.meta.glob( + ['./modules/*.ts', '!**/index.ts'], + { eager: true, as: 'raw' } +) + +export const excludeSelf = import.meta.glob( + './*.ts' + // for test: annotation contain ")" + /* + * for test: annotation contain ")" + * */ +) + +export const customQueryString = import.meta.glob('./*.ts', { query: 'custom' }) + +export const customQueryObject = import.meta.glob('./*.ts', { + query: { + foo: 'bar', + raw: true + } +}) + +export const parent = import.meta.glob('../../playground/src/*.ts', { + as: 'url' +}) + +export const rootMixedRelative = import.meta.glob( + ['/*.ts', '../fixture-b/*.ts'], + { as: 'url' } +) + +export const cleverCwd1 = import.meta.glob( + './node_modules/framework/**/*.page.js' +) + +export const cleverCwd2 = import.meta.glob([ + './modules/*.ts', + '../fixture-b/*.ts', + '!**/index.ts' +]) diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/a.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/a.ts new file mode 100644 index 00000000000000..facd48a0875e65 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/a.ts @@ -0,0 +1 @@ +export const name = 'a' diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/b.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/b.ts new file mode 100644 index 00000000000000..0b1eb38d9087a2 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/b.ts @@ -0,0 +1 @@ +export const name = 'b' diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/index.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/index.ts new file mode 100644 index 00000000000000..25b59ae7d30714 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/index.ts @@ -0,0 +1,6 @@ +export { name as a } from './a' +export { name as b } from './b' + +export const name = 'index' + +export default 'indexDefault' diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/node_modules/framework/pages/hello.page.js b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/node_modules/framework/pages/hello.page.js new file mode 100644 index 00000000000000..cbe518a8e79477 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/node_modules/framework/pages/hello.page.js @@ -0,0 +1,4 @@ +// A fake Page file. (This technique of globbing into `node_modules/` +// is used by vite-plugin-ssr frameworks and Hydrogen.) + +export const a = 1 diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/sibling.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/sibling.ts new file mode 100644 index 00000000000000..b286816bf5d63a --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/sibling.ts @@ -0,0 +1 @@ +export const name = 'I am your sibling!' diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/a.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/a.ts new file mode 100644 index 00000000000000..facd48a0875e65 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/a.ts @@ -0,0 +1 @@ +export const name = 'a' diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/b.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/b.ts new file mode 100644 index 00000000000000..0b1eb38d9087a2 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/b.ts @@ -0,0 +1 @@ +export const name = 'b' diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/index.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/index.ts new file mode 100644 index 00000000000000..39bdbfd1a8befb --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/index.ts @@ -0,0 +1,2 @@ +export { name as a } from './a' +export { name as b } from './b' diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture.test.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture.test.ts new file mode 100644 index 00000000000000..985263d91db85a --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture.test.ts @@ -0,0 +1,59 @@ +import { resolve } from 'path' +import { promises as fs } from 'fs' +import { describe, expect, it } from 'vitest' +import { transformGlobImport } from '../../../plugins/importMetaGlob' +import { transformWithEsbuild } from '../../../plugins/esbuild' + +describe('fixture', async () => { + const resolveId = (id: string) => id + const root = resolve(__dirname, '..') + + it('transform', async () => { + const id = resolve(__dirname, './fixture-a/index.ts') + const code = ( + await transformWithEsbuild(await fs.readFile(id, 'utf-8'), id) + ).code + + expect( + (await transformGlobImport(code, id, root, resolveId))?.s.toString() + ).toMatchSnapshot() + }) + + it('virtual modules', async () => { + const root = resolve(__dirname, './fixture-a') + const code = [ + "import.meta.glob('/modules/*.ts')", + "import.meta.glob(['/../fixture-b/*.ts'])" + ].join('\n') + expect( + ( + await transformGlobImport(code, 'virtual:module', root, resolveId) + )?.s.toString() + ).toMatchSnapshot() + + try { + await transformGlobImport( + "import.meta.glob('./modules/*.ts')", + 'virtual:module', + root, + resolveId + ) + expect('no error').toBe('should throw an error') + } catch (err) { + expect(err).toMatchInlineSnapshot( + "[Error: In virtual modules, all globs must start with '/']" + ) + } + }) + + it('transform with restoreQueryExtension', async () => { + const id = resolve(__dirname, './fixture-a/index.ts') + const code = ( + await transformWithEsbuild(await fs.readFile(id, 'utf-8'), id) + ).code + + expect( + (await transformGlobImport(code, id, root, resolveId, true))?.s.toString() + ).toMatchSnapshot() + }) +}) diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/parse.test.ts b/packages/vite/src/node/__tests__/plugins/importGlob/parse.test.ts new file mode 100644 index 00000000000000..df1e0d758e8849 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/parse.test.ts @@ -0,0 +1,202 @@ +import { describe, expect, it } from 'vitest' +import { parseImportGlob } from '../../../plugins/importMetaGlob' + +async function run(input: string) { + const items = await parseImportGlob( + input, + process.cwd(), + process.cwd(), + (id) => id + ) + return items.map((i) => ({ globs: i.globs, options: i.options })) +} + +async function runError(input: string) { + try { + await run(input) + } catch (e) { + return e + } +} + +describe('parse positives', async () => { + it('basic', async () => { + expect( + await run(` + import.meta.importGlob(\'./modules/*.ts\') + `) + ).toMatchInlineSnapshot('[]') + }) + + it('array', async () => { + expect( + await run(` + import.meta.importGlob([\'./modules/*.ts\', './dir/*.{js,ts}\']) + `) + ).toMatchInlineSnapshot('[]') + }) + + it('options with multilines', async () => { + expect( + await run(` + import.meta.importGlob([ + \'./modules/*.ts\', + "!./dir/*.{js,ts}" + ], { + eager: true, + import: 'named' + }) + `) + ).toMatchInlineSnapshot('[]') + }) + + it('options with multilines', async () => { + expect( + await run(` + const modules = import.meta.glob( + '/dir/**' + // for test: annotation contain ")" + /* + * for test: annotation contain ")" + * */ + ) + `) + ).toMatchInlineSnapshot(` + [ + { + "globs": [ + "/dir/**", + ], + "options": {}, + }, + ] + `) + }) + + it('options query', async () => { + expect( + await run(` + const modules = import.meta.glob( + '/dir/**', + { + query: { + foo: 'bar', + raw: true, + } + } + ) + `) + ).toMatchInlineSnapshot(` + [ + { + "globs": [ + "/dir/**", + ], + "options": { + "query": { + "foo": "bar", + "raw": true, + }, + }, + }, + ] + `) + }) +}) + +describe('parse negatives', async () => { + it('syntax error', async () => { + expect(await runError('import.meta.importGlob(')).toMatchInlineSnapshot( + 'undefined' + ) + }) + + it('empty', async () => { + expect(await runError('import.meta.importGlob()')).toMatchInlineSnapshot( + 'undefined' + ) + }) + + it('3 args', async () => { + expect( + await runError('import.meta.importGlob("", {}, {})') + ).toMatchInlineSnapshot('undefined') + }) + + it('in string', async () => { + expect(await runError('"import.meta.importGlob()"')).toBeUndefined() + }) + + it('variable', async () => { + expect(await runError('import.meta.importGlob(hey)')).toMatchInlineSnapshot( + 'undefined' + ) + }) + + it('template', async () => { + // eslint-disable-next-line no-template-curly-in-string + expect( + await runError('import.meta.importGlob(`hi ${hey}`)') + ).toMatchInlineSnapshot('undefined') + }) + + it('be string', async () => { + expect(await runError('import.meta.importGlob(1)')).toMatchInlineSnapshot( + 'undefined' + ) + }) + + it('be array variable', async () => { + expect( + await runError('import.meta.importGlob([hey])') + ).toMatchInlineSnapshot('undefined') + expect( + await runError('import.meta.importGlob(["1", hey])') + ).toMatchInlineSnapshot('undefined') + }) + + it('options', async () => { + expect( + await runError('import.meta.importGlob("hey", hey)') + ).toMatchInlineSnapshot('undefined') + expect( + await runError('import.meta.importGlob("hey", [])') + ).toMatchInlineSnapshot('undefined') + }) + + it('options props', async () => { + expect( + await runError('import.meta.importGlob("hey", { hey: 1 })') + ).toMatchInlineSnapshot('undefined') + expect( + await runError('import.meta.importGlob("hey", { import: hey })') + ).toMatchInlineSnapshot('undefined') + expect( + await runError('import.meta.importGlob("hey", { eager: 123 })') + ).toMatchInlineSnapshot('undefined') + }) + + it('options query', async () => { + expect( + await runError( + 'import.meta.importGlob("./*.js", { as: "raw", query: "hi" })' + ) + ).toMatchInlineSnapshot('undefined') + expect( + await runError('import.meta.importGlob("./*.js", { query: 123 })') + ).toMatchInlineSnapshot('undefined') + expect( + await runError('import.meta.importGlob("./*.js", { query: { foo: {} } })') + ).toMatchInlineSnapshot('undefined') + expect( + await runError( + 'import.meta.importGlob("./*.js", { query: { foo: hey } })' + ) + ).toMatchInlineSnapshot('undefined') + expect( + await runError( + 'import.meta.importGlob("./*.js", { query: { foo: 123, ...a } })' + ) + ).toMatchInlineSnapshot('undefined') + }) +}) diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/utils.test.ts b/packages/vite/src/node/__tests__/plugins/importGlob/utils.test.ts new file mode 100644 index 00000000000000..302df97ec92ede --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/importGlob/utils.test.ts @@ -0,0 +1,31 @@ +import { describe, expect, it } from 'vitest' +import { getCommonBase } from '../../../plugins/importMetaGlob' + +describe('getCommonBase()', async () => { + it('basic', () => { + expect(getCommonBase(['/a/b/*.js', '/a/c/*.js'])).toBe('/a') + }) + it('common base', () => { + expect(getCommonBase(['/a/b/**/*.vue', '/a/b/**/*.jsx'])).toBe('/a/b') + }) + it('static file', () => { + expect( + getCommonBase(['/a/b/**/*.vue', '/a/b/**/*.jsx', '/a/b/foo.js']) + ).toBe('/a/b') + expect(getCommonBase(['/a/b/**/*.vue', '/a/b/**/*.jsx', '/a/foo.js'])).toBe( + '/a' + ) + }) + it('correct `scan()`', () => { + expect(getCommonBase(['/a/*.vue'])).toBe('/a') + expect(getCommonBase(['/a/some.vue'])).toBe('/a') + expect(getCommonBase(['/a/b/**/c/foo.vue', '/a/b/c/**/*.jsx'])).toBe('/a/b') + }) + it('single', () => { + expect(getCommonBase(['/a/b/c/*.vue'])).toBe('/a/b/c') + expect(getCommonBase(['/a/b/c/foo.vue'])).toBe('/a/b/c') + }) + it('no common base', () => { + expect(getCommonBase(['/a/b/*.js', '/c/a/b/*.js'])).toBe('/') + }) +}) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 29dc3fe2045a5a..e7fcaefeb2a799 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -152,6 +152,14 @@ export interface UserConfig { * @alpha */ ssr?: SSROptions + /** + * Experimental features + * + * Features under this field are addressed to be changed that might NOT follow semver. + * Please be careful and always pin Vite's version when using them. + * @experimental + */ + experimental?: ExperimentalOptions /** * Log level. * Default: 'info' @@ -199,6 +207,16 @@ export interface UserConfig { } } +export interface ExperimentalOptions { + /** + * Append fake `&lang.(ext)` when queries are specified, to preseve the file extension for following plugins to process. + * + * @experimental + * @default false + */ + importGlobRestoreExtension?: boolean +} + export type SSRTarget = 'node' | 'webworker' export interface SSROptions { diff --git a/packages/vite/src/node/importGlob.ts b/packages/vite/src/node/importGlob.ts deleted file mode 100644 index ab425bb596c68a..00000000000000 --- a/packages/vite/src/node/importGlob.ts +++ /dev/null @@ -1,246 +0,0 @@ -import path from 'path' -import { promises as fsp } from 'fs' -import glob from 'fast-glob' -import JSON5 from 'json5' -import { - isModernFlag, - preloadMethod, - preloadMarker -} from './plugins/importAnalysisBuild' -import { isCSSRequest } from './plugins/css' -import { - cleanUrl, - singlelineCommentsRE, - multilineCommentsRE, - blankReplacer, - normalizePath -} from './utils' -import type { RollupError } from 'rollup' -import type { Logger } from '.' - -interface GlobParams { - base: string - pattern: string - parentDepth: number - isAbsolute: boolean -} - -interface GlobOptions { - as?: string -} - -function formatGlobRelativePattern(base: string, pattern: string): GlobParams { - let parentDepth = 0 - while (pattern.startsWith('../')) { - pattern = pattern.slice(3) - base = path.resolve(base, '../') - parentDepth++ - } - if (pattern.startsWith('./')) { - pattern = pattern.slice(2) - } - - return { base, pattern, parentDepth, isAbsolute: false } -} - -export async function transformImportGlob( - source: string, - pos: number, - importer: string, - importIndex: number, - root: string, - logger: Logger, - normalizeUrl?: (url: string, pos: number) => Promise<[string, string]>, - resolve?: (url: string, importer?: string) => Promise, - preload = true -): Promise<{ - importsString: string - imports: string[] - exp: string - endIndex: number - isEager: boolean - pattern: string - base: string -}> { - const isEager = source.slice(pos, pos + 21) === 'import.meta.globEager' - const isEagerDefault = - isEager && source.slice(pos + 21, pos + 28) === 'Default' - - const err = (msg: string) => { - const e = new Error(`Invalid glob import syntax: ${msg}`) - ;(e as any).pos = pos - return e - } - - importer = cleanUrl(importer) - const importerBasename = path.basename(importer) - - const [userPattern, options, endIndex] = lexGlobPattern(source, pos) - - let globParams: GlobParams | null = null - if (userPattern.startsWith('/')) { - globParams = { - isAbsolute: true, - base: path.resolve(root), - pattern: userPattern.slice(1), - parentDepth: 0 - } - } else if (userPattern.startsWith('.')) { - globParams = formatGlobRelativePattern(path.dirname(importer), userPattern) - } else if (resolve) { - const resolvedId = await resolve(userPattern, importer) - if (resolvedId) { - const importerDirname = path.dirname(importer) - globParams = formatGlobRelativePattern( - importerDirname, - normalizePath(path.relative(importerDirname, resolvedId)) - ) - } - } - - if (!globParams) { - throw err( - `pattern must start with "." or "/" (relative to project root) or alias path` - ) - } - const { base, parentDepth, isAbsolute, pattern } = globParams - - const files = glob.sync(pattern, { - cwd: base, - // Ignore node_modules by default unless explicitly indicated in the pattern - ignore: /(^|\/)node_modules\//.test(pattern) ? [] : ['**/node_modules/**'] - }) - const imports: string[] = [] - let importsString = `` - let entries = `` - for (let i = 0; i < files.length; i++) { - // skip importer itself - if (files[i] === importerBasename) continue - const file = isAbsolute - ? `/${files[i]}` - : parentDepth - ? `${'../'.repeat(parentDepth)}${files[i]}` - : `./${files[i]}` - let importee = file - if (normalizeUrl) { - ;[importee] = await normalizeUrl(file, pos) - } - imports.push(importee) - - const isRawType = options?.as === 'raw' - if (isRawType) { - entries += ` ${JSON.stringify(file)}: ${JSON.stringify( - await fsp.readFile(path.join(base, files[i]), 'utf-8') - )},` - } else { - const importeeUrl = isCSSRequest(importee) ? `${importee}?used` : importee - if (isEager) { - const identifier = `__glob_${importIndex}_${i}` - // css imports injecting a ?used query to export the css string - importsString += `import ${ - isEagerDefault ? `` : `* as ` - }${identifier} from ${JSON.stringify(importeeUrl)};` - entries += ` ${JSON.stringify(file)}: ${identifier},` - } else { - let imp = `import(${JSON.stringify(importeeUrl)})` - if (!normalizeUrl && preload) { - imp = - `(${isModernFlag}` + - `? ${preloadMethod}(()=>${imp},"${preloadMarker}")` + - `: ${imp})` - } - entries += ` ${JSON.stringify(file)}: () => ${imp},` - } - } - } - - return { - imports, - importsString, - exp: `{${entries}}`, - endIndex, - isEager, - pattern, - base - } -} - -const enum LexerState { - inCall, - inSingleQuoteString, - inDoubleQuoteString, - inTemplateString -} - -function lexGlobPattern( - code: string, - pos: number -): [string, GlobOptions, number] { - let state = LexerState.inCall - let pattern = '' - - let i = code.indexOf(`(`, pos) + 1 - outer: for (; i < code.length; i++) { - const char = code.charAt(i) - switch (state) { - case LexerState.inCall: - if (char === `'`) { - state = LexerState.inSingleQuoteString - } else if (char === `"`) { - state = LexerState.inDoubleQuoteString - } else if (char === '`') { - state = LexerState.inTemplateString - } else if (/\s/.test(char)) { - continue - } else { - error(i) - } - break - case LexerState.inSingleQuoteString: - if (char === `'`) { - break outer - } else { - pattern += char - } - break - case LexerState.inDoubleQuoteString: - if (char === `"`) { - break outer - } else { - pattern += char - } - break - case LexerState.inTemplateString: - if (char === '`') { - break outer - } else { - pattern += char - } - break - default: - throw new Error('unknown import.meta.glob lexer state') - } - } - const noCommentCode = code - .slice(i + 1) - .replace(singlelineCommentsRE, blankReplacer) - .replace(multilineCommentsRE, blankReplacer) - - const endIndex = noCommentCode.indexOf(')') - const optionString = noCommentCode.substring(0, endIndex) - const commaIndex = optionString.indexOf(',') - - let options = {} - if (commaIndex > -1) { - options = JSON5.parse(optionString.substring(commaIndex + 1)) - } - return [pattern, options, endIndex + i + 2] -} - -function error(pos: number) { - const err = new Error( - `import.meta.glob() can only accept string literals.` - ) as RollupError - err.pos = pos - throw err -} diff --git a/packages/vite/src/node/index.ts b/packages/vite/src/node/index.ts index e56f4c6e765756..0d401363b8a3b6 100644 --- a/packages/vite/src/node/index.ts +++ b/packages/vite/src/node/index.ts @@ -74,6 +74,9 @@ export type { TransformOptions as EsbuildTransformOptions } from 'esbuild' export type { ESBuildOptions, ESBuildTransformResult } from './plugins/esbuild' export type { Manifest, ManifestChunk } from './plugins/manifest' export type { ResolveOptions, InternalResolveOptions } from './plugins/resolve' +export type { SplitVendorChunkCache } from './plugins/splitVendorChunk' +import type { ChunkMetadata } from './plugins/metadata' + export type { WebSocketServer, WebSocketClient, @@ -88,6 +91,7 @@ export type { TransformResult } from './server/transformRequest' export type { HmrOptions, HmrContext } from './server/hmr' + export type { HMRPayload, ConnectedPayload, @@ -111,9 +115,12 @@ export type { RollupCommonJSOptions } from 'types/commonjs' export type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars' export type { CustomEventMap, InferCustomEventPayload } from 'types/customEvent' export type { Matcher, AnymatchPattern, AnymatchFn } from 'types/anymatch' -export type { SplitVendorChunkCache } from './plugins/splitVendorChunk' - -import type { ChunkMetadata } from './plugins/metadata' +export type { + ImportGlobFunction, + ImportGlobEagerFunction, + ImportGlobOptions, + KnownAsTypeMap +} from 'types/importGlob' declare module 'rollup' { export interface RenderedChunk { diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index ef59a35b1d22d3..111aefc40dea15 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -1,9 +1,9 @@ import fs from 'fs' import path from 'path' import glob from 'fast-glob' -import type { ResolvedConfig, Logger } from '..' +import type { ResolvedConfig } from '..' import type { Loader, Plugin, OnLoadResult } from 'esbuild' -import { build, transform } from 'esbuild' +import { build } from 'esbuild' import { KNOWN_ASSET_TYPES, JS_TYPES_RE, @@ -25,11 +25,9 @@ import { } from '../utils' import type { PluginContainer } from '../server/pluginContainer' import { createPluginContainer } from '../server/pluginContainer' -import { init, parse } from 'es-module-lexer' -import MagicString from 'magic-string' -import { transformImportGlob } from '../importGlob' import { performance } from 'perf_hooks' import colors from 'picocolors' +import { transformGlobImport } from '../plugins/importMetaGlob' const debug = createDebugger('vite:deps') @@ -300,19 +298,18 @@ function esbuildScanPlugin( (loader.startsWith('ts') ? extractImportPaths(content) : '') const key = `${path}?id=${scriptId++}` - if (contents.includes('import.meta.glob')) { scripts[key] = { - // transformGlob already transforms to js loader: 'js', - contents: await transformGlob( - contents, - path, - config.root, - loader, - resolve, - config.logger - ) + contents: + ( + await transformGlobImport( + contents, + path, + config.root, + resolve + ) + )?.s.toString() || contents } } else { scripts[key] = { @@ -467,20 +464,6 @@ function esbuildScanPlugin( config.optimizeDeps?.esbuildOptions?.loader?.[`.${ext}`] || (ext as Loader) - if (contents.includes('import.meta.glob')) { - return transformGlob( - contents, - id, - config.root, - loader, - resolve, - config.logger - ).then((contents) => ({ - loader, - contents - })) - } - return { loader, contents @@ -490,43 +473,6 @@ function esbuildScanPlugin( } } -async function transformGlob( - source: string, - importer: string, - root: string, - loader: Loader, - resolve: (url: string, importer?: string) => Promise, - logger: Logger -) { - // transform the content first since es-module-lexer can't handle non-js - if (loader !== 'js') { - source = (await transform(source, { loader })).code - } - - await init - const imports = parse(source)[0] - const s = new MagicString(source) - for (let index = 0; index < imports.length; index++) { - const { s: start, e: end, ss: expStart } = imports[index] - const url = source.slice(start, end) - if (url !== 'import.meta') continue - if (source.slice(end, end + 5) !== '.glob') continue - const { importsString, exp, endIndex } = await transformImportGlob( - source, - start, - normalizePath(importer), - index, - root, - logger, - undefined, - resolve - ) - s.prepend(importsString) - s.overwrite(expStart, endIndex, exp, { contentOnly: true }) - } - return s.toString() -} - /** * when using TS + (Vue + `
diff --git a/playground/css-codesplit/inline.css b/playground/css-codesplit/inline.css new file mode 100644 index 00000000000000..b2a2b5f1ead51f --- /dev/null +++ b/playground/css-codesplit/inline.css @@ -0,0 +1,3 @@ +.inline { + color: yellow; +} diff --git a/playground/css-codesplit/main.js b/playground/css-codesplit/main.js index 8c80df2c181511..eb6e703f79e718 100644 --- a/playground/css-codesplit/main.js +++ b/playground/css-codesplit/main.js @@ -1,6 +1,15 @@ import './style.css' import './main.css' -document.getElementById( - 'app' -).innerHTML = `

This should be red

This should be blue

` +import('./async.css') + +import('./inline.css?inline').then((css) => { + document.querySelector('.dynamic-inline').textContent = css.default +}) + +import('./mod.module.css').then((css) => { + document.querySelector('.dynamic-module').textContent = JSON.stringify( + css.default + ) + document.querySelector('.mod').classList.add(css.default.mod) +}) diff --git a/playground/css-codesplit/mod.module.css b/playground/css-codesplit/mod.module.css new file mode 100644 index 00000000000000..7f84410485a32c --- /dev/null +++ b/playground/css-codesplit/mod.module.css @@ -0,0 +1,3 @@ +.mod { + color: yellow; +} From 2d978f7b10fe626ad77cd07b9d1a434af89f8c9a Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Tue, 10 May 2022 02:22:50 +0800 Subject: [PATCH 077/114] chore(plugin-react): add vite peer dep (#8083) --- packages/plugin-react/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json index 813db5ecf23aed..ca8b1d78752b69 100644 --- a/packages/plugin-react/package.json +++ b/packages/plugin-react/package.json @@ -41,5 +41,8 @@ "@rollup/pluginutils": "^4.2.1", "react-refresh": "^0.13.0", "resolve": "^1.22.0" + }, + "peerDependencies": { + "vite": "^2.0.0" } } From f895f94b49fcab278d303ef9ecf7b6a28e7fc24a Mon Sep 17 00:00:00 2001 From: David Jackson <1735971+davidwallacejackson@users.noreply.github.com> Date: Mon, 9 May 2022 11:48:57 -0700 Subject: [PATCH 078/114] fix: increase default HTTPS dev server session memory limit (#6207) --- packages/vite/src/node/http.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts index bfc2ddbe32a302..18140b031937a9 100644 --- a/packages/vite/src/node/http.ts +++ b/packages/vite/src/node/http.ts @@ -104,6 +104,9 @@ export async function resolveHttpServer( } else { return require('http2').createSecureServer( { + // Manually increase the session memory to prevent 502 ENHANCE_YOUR_CALM + // errors on large numbers of requests + maxSessionMemory: 1000, ...httpsOptions, allowHTTP1: true }, From e56d79e17d64abf383bc2c30a5a2f1da6494f1fa Mon Sep 17 00:00:00 2001 From: patak Date: Mon, 9 May 2022 20:49:38 +0200 Subject: [PATCH 079/114] chore: bump Vitest timeout (#8084) --- vitest.config.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vitest.config.ts b/vitest.config.ts index 4026b98c30d640..0a8f8c2ff22648 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -7,7 +7,8 @@ export default defineConfig({ '**/dist/**', './playground/**/*.*', './playground-temp/**/*.*' - ] + ], + testTimeout: 20000 }, esbuild: { target: 'node14' From d7c04e8a0106de857b4e13d35631699d1393f804 Mon Sep 17 00:00:00 2001 From: Jeudi Prando Araujo Date: Mon, 9 May 2022 15:56:14 -0300 Subject: [PATCH 080/114] docs(config-file): update tip note about string replace (#7846) --- docs/config/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/config/index.md b/docs/config/index.md index 5862419405aa89..6e74e7d3b01d5e 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -28,12 +28,14 @@ vite --config my-config.js ``` ::: tip NOTE -Vite will replace `__filename`, `__dirname`, and `import.meta.url` in config files and its deps. Using these as variable names will result in an error: +Vite will replace `__filename`, `__dirname`, and `import.meta.url` in config files and its deps. Using these as variable names or passing as a parameter to a function with string double quote (example `console.log`) will result in an error: ```js const __filename = "value" // will be transformed to const "path/vite.config.js" = "value" + +console.log("import.meta.url") // break error on build ``` ::: From 8167db32ec44047b006a93a7969028101f5d9276 Mon Sep 17 00:00:00 2001 From: Olyno Date: Mon, 9 May 2022 23:03:35 +0200 Subject: [PATCH 081/114] fix(create-vite): allow slash at the end of project path (#6897) --- packages/create-vite/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/create-vite/index.js b/packages/create-vite/index.js index fceef9d9885a05..8310b8c0bddba2 100755 --- a/packages/create-vite/index.js +++ b/packages/create-vite/index.js @@ -132,7 +132,9 @@ async function init() { let targetDir = argv._[0] let template = argv.template || argv.t - const defaultProjectName = !targetDir ? 'vite-project' : targetDir + const defaultProjectName = !targetDir + ? 'vite-project' + : targetDir.trim().replace(/\/+$/g, '') let result = {} @@ -145,7 +147,8 @@ async function init() { message: reset('Project name:'), initial: defaultProjectName, onState: (state) => - (targetDir = state.value.trim() || defaultProjectName) + (targetDir = + state.value.trim().replace(/\/+$/g, '') || defaultProjectName) }, { type: () => From 2b2858c27e58f995494f7a132dfe64cbb0d1f518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Tue, 10 May 2022 10:48:45 +0900 Subject: [PATCH 082/114] test: suppress @vue/reactivity-transform warning (#8087) --- scripts/jestEnv.cjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/jestEnv.cjs b/scripts/jestEnv.cjs index b576155644a27f..a053faef1a69a5 100644 --- a/scripts/jestEnv.cjs +++ b/scripts/jestEnv.cjs @@ -32,8 +32,8 @@ module.exports = class PlaywrightEnvironment extends NodeEnvironment { const console = this.global.console const warn = console.warn console.warn = (msg, ...args) => { - // suppress @vue/ref-transform warning - if (msg.includes('@vue/ref-transform')) return + // suppress @vue/reactivity-transform warning + if (msg.includes('@vue/reactivity-transform')) return if (msg.includes('Generated an empty chunk')) return warn.call(console, msg, ...args) } From 095543fcc5fd978e8b56fd68a7bc1785db339ee7 Mon Sep 17 00:00:00 2001 From: ygj6 <7699524+ygj6@users.noreply.github.com> Date: Tue, 10 May 2022 13:19:12 +0800 Subject: [PATCH 083/114] docs: note for inconsistency between dev and build (#6674) --- docs/config/index.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/config/index.md b/docs/config/index.md index 6e74e7d3b01d5e..666f5f39a5511c 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -186,6 +186,20 @@ export default defineConfig(({ command, mode }) => { ::: + ::: tip NOTE + Since dev and build implement `define` differently, we should avoid some use cases to avoid inconsistency. + + Example: + + ```js + const obj = { + __NAME__, // Don't define object shorthand property names + __KEY__: value // Don't define object key + } + ``` + + ::: + ### plugins - **Type:** `(Plugin | Plugin[])[]` From 7b48e2292e6ae833726a18b16961c9ed3173e33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Tue, 10 May 2022 14:21:24 +0900 Subject: [PATCH 084/114] chore(plugin-vue-jsx): add peer deps (#8086) --- packages/plugin-vue-jsx/package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 91ef19c2049850..11e83bac3321b6 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -28,5 +28,9 @@ "@rollup/pluginutils": "^4.2.1", "@vue/babel-plugin-jsx": "^1.1.1", "hash-sum": "^2.0.0" + }, + "peerDependencies": { + "vite": "^2.0.0", + "vue": "^3.0.0" } } From e10c0c1e28d944a425b954aa71cbf1c8698125b7 Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 10 May 2022 08:00:21 +0200 Subject: [PATCH 085/114] fix: image-set with base64 images (fix #8028) (#8035) --- packages/vite/src/node/plugins/css.ts | 14 +++++++++++--- packages/vite/src/node/utils.ts | 22 ++++++++++++++++++++-- playground/assets/__tests__/assets.spec.ts | 17 ++++++++++++++++- playground/assets/css/css-url.css | 19 +++++++++++++++++++ playground/assets/index.html | 10 ++++++++++ 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 3ffd93bb9f9910..c13a4c83052639 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -1045,18 +1045,26 @@ function rewriteImportCss( }) } -function rewriteCssImageSet( +// TODO: image and cross-fade could contain a "url" that needs to be processed +// https://drafts.csswg.org/css-images-4/#image-notation +// https://drafts.csswg.org/css-images-4/#cross-fade-function +const cssNotProcessedRE = /(gradient|element|cross-fade|image)\(/ + +async function rewriteCssImageSet( css: string, replacer: CssUrlReplacer ): Promise { - return asyncReplace(css, cssImageSetRE, async (match) => { + return await asyncReplace(css, cssImageSetRE, async (match) => { const [, rawUrl] = match const url = await processSrcSet(rawUrl, async ({ url }) => { // the url maybe url(...) if (cssUrlRE.test(url)) { return await rewriteCssUrls(url, replacer) } - return await doUrlReplace(url, url, replacer) + if (!cssNotProcessedRE.test(url)) { + return await doUrlReplace(url, url, replacer) + } + return url }) return url }) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index ddcaced9832bc1..0c25b4592adf6d 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -560,8 +560,7 @@ export async function processSrcSet( srcs: string, replacer: (arg: ImageCandidate) => Promise ): Promise { - const imageCandidates: ImageCandidate[] = srcs - .split(',') + const imageCandidates: ImageCandidate[] = splitSrcSet(srcs) .map((s) => { const src = s.replace(escapedSpaceCharacters, ' ').trim() const [url] = imageSetUrlRE.exec(src) || [] @@ -589,6 +588,25 @@ export async function processSrcSet( }, '') } +function splitSrcSet(srcs: string) { + const parts: string[] = [] + // There could be a ',' inside of url(data:...), linear-gradient(...) or "data:..." + const cleanedSrcs = srcs.replace( + /(?:url|image|gradient|cross-fade)\([^\)]*\)|"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'/g, + blankReplacer + ) + let startIndex = 0 + let splitIndex: number + do { + splitIndex = cleanedSrcs.indexOf(',', startIndex) + parts.push( + srcs.slice(startIndex, splitIndex !== -1 ? splitIndex : undefined) + ) + startIndex = splitIndex + 1 + } while (splitIndex !== -1) + return parts +} + function escapeToLinuxLikePath(path: string) { if (/^[A-Z]:/.test(path)) { return path.replace(/^([A-Z]):\//, '/windows/$1/') diff --git a/playground/assets/__tests__/assets.spec.ts b/playground/assets/__tests__/assets.spec.ts index c63ffc7cc1c0c2..d9f1c8ed761773 100644 --- a/playground/assets/__tests__/assets.spec.ts +++ b/playground/assets/__tests__/assets.spec.ts @@ -118,8 +118,23 @@ describe('css url() references', () => { }) }) - // not supported in browser now + test('image-set with base64', async () => { + const imageSet = await getBg('.css-image-set-base64') + expect(imageSet).toMatch( + `-webkit-image-set(url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA0AgMAAACrwbOMAAADI2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo1MDI2QjVGQTg3RUIxMUVBQUFDMkQ3NTM0MUZGNzU3RSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo1MDI2QjVGOTg3RUIxMUVBQUFDMkQ3NTM0MUZGNzU3RSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ0MgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpBNzc3MDZDRjg3QUIxMUUzQjcwREVFMDM3NzA2QzEyMyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpBNzc3MDZEMDg3QUIxMUUzQjcwREVFMDM3NzA2QzEyMyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqfCcbEAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAADFBMVEVBuoQ0R10/qn8/qX7FyuqbAAAABHRSTlP9/QGEiU0+GwAAAPtJREFUGBkFwbFNXEEUBdDD/QSWmE7YYAogWNeAaMfaEuiD5HfAk9yIAwqYwIGRRvt8zkNdvckrzzcfjqDccdPIYnH1AJ4ywLs7m53Fhkcw0+DLDxZn0PCHQrrg2xWOCpS7m6bFAj/ZDLFY/AJbDDZ/WUzR4B84BRoURBeAo4Si0CBMFvBEGMBmExYbi0loACcBjQKhC3AUQVGaRjBhMxAsFlwQDLYFBA04EaAVEHSBoxAoPmkITBYDAovNhsAAEwINTggAINCFoyCg0CBgYoCAjQsIACCgcYKABhCgHAUClAYCTAMIsF2AAAACtBMIQAEB+jcggE9AAC+A/zyyZDSXstCbAAAAAElFTkSuQmCC") 1x, url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA0CAYAAADWr1sfAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTM4IDc5LjE1OTgyNCwgMjAxNi8wOS8xNC0wMTowOTowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NTAyNkI1RkE4N0VCMTFFQUFBQzJENzUzNDFGRjc1N0UiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NTAyNkI1Rjk4N0VCMTFFQUFBQzJENzUzNDFGRjc1N0UiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIChNYWNpbnRvc2gpIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QTc3NzA2Q0Y4N0FCMTFFM0I3MERFRTAzNzcwNkMxMjMiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QTc3NzA2RDA4N0FCMTFFM0I3MERFRTAzNzcwNkMxMjMiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz6nwnGxAAAJtklEQVR42txZ6W9c1RU/970373nsJHgZ27FThahSV8BCqGQTlIQ2EiUBReqHVpT8Af0r+NA/ogpqqWiDKrZuKYQPLGEpAlEFiqOgICSUBOKQhDjxeGY885bb37n3TGKPZ+4bx0uWK53Ec+cu53fPfkbtfu13B4noF6AQVAEpah0ak3cUSBU8qh46RfWj50ltKJDXXyBKdMtibI+TXlLqm2C87y/+eO/vlVIVnWbUcShFyld8T19ypvLbZKpyALOjVPCqrUcT1mWXYtIzMUV7Rqn315tJJyk+J51OZwb7QA3QkQD/fAL6JWiIXKMOhkOPwp1DFE/OkJ6NAQxn+fhuPhaFOc8DE9loern+hD9SfJVCdaLdOy5gif9rpHfyHp3pCX5cs6X1PfnORkr+SA9FO4bsgkZm1ykngm8ZK06ll0EvgWY6SwDn1fGKcykVfriewh2D5oKskhhw5KmFzLO0MJdO1yfS87UD2Uxc0tXErM+qLYQ5XUspK8el9JvagXSmPmH2W4lfG3wHNMHciXnmIfj+OvCVga8sD+yMYHyZAZ8H/Qk06dySaiNljf/DB0vklWAB1RQqnS0WA18eQE0Dz0++rjyRluOJDHuzWkwZNAPgLPHfPIeHTK/EEzHWKt/zDdh2asBmUUnJg3TDB0rQIuYptby5x6RgPO/JxIes304p44V1DMAzKQUbe4xqa62h2vbFyWuxeUie1RKqvVmXG/sxOaYKPqliQKp3HmEOB43pWaxJaTPvUV6rdK3Z6FloGUt35yD54EGXEwvaU3nSPSIYF7D5T/mio1rzS7Jaa1we4YWDzb1GUpptqJ1OGUl7BJX+jS7HP/OKEPlgRH5/SP5AZMjrCTz+jtdQQckxauEZ/IZ4bKyhYEsv7h6GpmGuhnsznafORwQbtQKGY6F/gy64pMxPnF2JSQ33UM/ecWNX/PJG3RbYsn15qCiYTQdhr49j9m4jQd8zXlkFZv3d/B087SBM4OodC+5kJYIX5r09+8ZIDYYAn4gqOdFeEEwn2gFmMb0BesEpZeOxARAOJ4SXjLbDlljKcbaQ0ebwrRNLy409oH1Xz1H2xrRc3wfaYx1dm/sgQTyYMZ1wZ4nC+4es76gnC3lqP14QTFk7wDymQH8DnXKCZibKiQHY89gY+aUeGwcT66xaw40JMUnWn52t7NWVeKt5GNaUarw1naruxXn9Rrrz9jRjLsd5PtsfZY3aaBZo9tT5qnxKsExRizto59EOccRzJQomHAC0DzsOHxwy3lvXk8VxU1u1VJFPaSW5B177SRtfNaVnq08izNyjQl9UefFe4zNwdoTI4I8XTfznu3NUORYMiyKP10HvD4neZy7VzqBaHEOjnw5TsKnXfgaDRjKqxWuzzRKtTy/Wt2W1ZAukuyX9tr4Ns+vZpheAVfKoOCuDKrNzDB8Ysp9Znd2qnAnvh9r5I8+hDs86HRhfCIlyQqGgbuHDI0Sz9gHaZj0sQXhhpJhbktOVp5Kvak/x31Sg9rarRXVxXvjwKJxk0Z7N/sOjPEf1bCez7LS1Ji/0iduBAUAD6JDpRFsHqfDjDZRdTqyU26gn2ykkXUovzf2KCV66ZGxXL9YeVtsMMb9w1x0U/WTAADWqnGO4wvMhwdA14PmqfbLjClZdTkaqCFPrAor2byIvUsZrd5Syp4BaFYW8RUmDeG8+wwsVRY+Pk7c+MJpkChXfCfhkJ1XuBjCPV0Bvt0nhFwoPiQfbVjixgaKHho3qGSlbgIu9ti/VEdHifJkdVc2aRoizwnv7kT+nNuy5hxZeX3EtygM8DfoX6FPnCcxL1Yap6NGNCCFFk5x0ETra2i7v9TcWqbh3zIbASmzvcHP7qfA6vRzAJIH7JWeYktRPz2a2bHuoZKpEdjgWdBeoWboMTpwea4o3GiF1lXzZPWLh8Y3ca7oAPAd6E/RubjLCkgBz4fYhCu6cl2d73UmX13KSUcDecNugqX2Np9a5mvKu8Di3EoB5HAP9WboGnZMRFiiXb0MhhYjNOrbeVsc5DPPexEqXz+C9HufLHHPT3PyxIbwd6wZIt4DnxCG81lG1JT9miZiaGeVj8L0+m3I2UrdaezY/z65Auj9ab0vPNLOlp+fEGwtPb3cj3aUA5nEWdDA3GTGMpqT6AupFmLLpYWaL9Hag2XZZdVHqcR1cfGzchDhdyWwFpnKTjIPCG600YFad96S+rHeOzZ5tB7Et3jeItLNk8+Fa2j6jYnU2YSyhaNcwFe4dMHv5DD7L1WUTXt5zmtoyADe7Bwfn15cdHZix3cxIzB+ObC+q2Z1Q6pq0E6gynF0A715ErasbqQWbH9JOCC8zSwGwVMA8Phb3X3a2g5BnZ5cRT78Dj7trxMRR7liY+lhdu5ntVnFDFLm4N1a0nr2e5rVtysLDx0tl/noAc9X7TLNH5KxZuC1Tg6puH0SYKtoaumFrYWPbsS0xg+/2UbjVVkNXW67u8aHwkKwFYB6fgQ47nYXXBBSbEBPtGjUtnWy6YcEm/F1q5sLdkO5AQTonuap8Vu7+7HoYv17APF4Fve6KrabEkzhcuH+AAuTFGmmjkeScbdsU7hswxGtMkqJzM7PX5W5aa8BfSDdwyt30I9Nw44qn+MgYef1IKC42SLN9D4TU8+iYCWGmKSfdEceYkju/uBGAebwvDW53KcOeFxlYcBeqqd3DBiznyCHCUPCDdUTsweM0765M7np/OQwvF/A5aYOedDcKmo23zP5qsalovTfny9wL4xQyP18+KXedu5GAmx0G9pizrsrAJCOQsuovUPTIKIU/HzG/SPKczks97dnPODswXY5gBQDXxK72g3a0fURT5yoTY7nw5w6ksVcAzZq/C7mbcv+TO2rLZXYlJMzjtNjXBedN7IlBXuibtq3ph8W5vw1dkLNPrwSjKwWY89oXQf9xNgqaXruaWLulXK8cy5kvOvP3GwC4mWc/50wImj+xaLrmpFRugvPcUvPltQJMUr0cXcHzjpLrF82bAHBN1O+dFTjrHTmrdjMD5vER6B/LZLQmZ3y00sytBuC65LtvLeOMt+SM+q0AmMekNNbK17G3LHsnV4Ox1QLM4wNRy3gJe2LZ88FqMbWagL8CPe2sptpXQ0/L3lsOMGcW3Cv+O+hyF+svy9pjsveWA9z0tn8Afd7F2s9lbW01GVptwJxTHZfE3/Uj17SsOU7ddLRuYsDN8decDOyorFn1sVaAvyT7k8iZNt+dke++vJ0A8+CfMw+3mT8s39HtBviSgDs+b+64zF26HQHz+C/o+Xmfn5c5ul0BXyT7w/U5oTdlbs1GQGs/vgb9cd7fazr+L8AAD0zRYMSYHQAAAAAASUVORK5CYII=") 2x)` + ) + }) + + // TODO: not supported in chrome // https://drafts.csswg.org/css-images-4/#image-set-notation + // + // test('image-set with multiple descriptor', async () => { + // const imageSet = await getBg('.css-image-set-gradient') + // expect(imageSet).toMatch( + // `-webkit-image-set(url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA0AgMAAACrwbOMAAADI2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo1MDI2QjVGQTg3RUIxMUVBQUFDMkQ3NTM0MUZGNzU3RSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo1MDI2QjVGOTg3RUIxMUVBQUFDMkQ3NTM0MUZGNzU3RSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ0MgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpBNzc3MDZDRjg3QUIxMUUzQjcwREVFMDM3NzA2QzEyMyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpBNzc3MDZEMDg3QUIxMUUzQjcwREVFMDM3NzA2QzEyMyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqfCcbEAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAADFBMVEVBuoQ0R10/qn8/qX7FyuqbAAAABHRSTlP9/QGEiU0+GwAAAPtJREFUGBkFwbFNXEEUBdDD/QSWmE7YYAogWNeAaMfaEuiD5HfAk9yIAwqYwIGRRvt8zkNdvckrzzcfjqDccdPIYnH1AJ4ywLs7m53Fhkcw0+DLDxZn0PCHQrrg2xWOCpS7m6bFAj/ZDLFY/AJbDDZ/WUzR4B84BRoURBeAo4Si0CBMFvBEGMBmExYbi0loACcBjQKhC3AUQVGaRjBhMxAsFlwQDLYFBA04EaAVEHSBoxAoPmkITBYDAovNhsAAEwINTggAINCFoyCg0CBgYoCAjQsIACCgcYKABhCgHAUClAYCTAMIsF2AAAACtBMIQAEB+jcggE9AAC+A/zyyZDSXstCbAAAAAElFTkSuQmCC") 1x, linear-gradient(#e66465, #9198e5) 2x)` + // ) + // }) + // // test('image-set with multiple descriptor', async () => { // const imageSet = await getBg('.css-image-set-multiple-descriptor') // imageSet.split(', ').forEach((s) => { diff --git a/playground/assets/css/css-url.css b/playground/assets/css/css-url.css index 9047cd384e7d38..1446f19afa662e 100644 --- a/playground/assets/css/css-url.css +++ b/playground/assets/css/css-url.css @@ -41,6 +41,25 @@ background-size: 10px; } +.css-image-set-base64 { + background-image: -webkit-image-set( + url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA0AgMAAACrwbOMAAADI2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo1MDI2QjVGQTg3RUIxMUVBQUFDMkQ3NTM0MUZGNzU3RSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo1MDI2QjVGOTg3RUIxMUVBQUFDMkQ3NTM0MUZGNzU3RSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ0MgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpBNzc3MDZDRjg3QUIxMUUzQjcwREVFMDM3NzA2QzEyMyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpBNzc3MDZEMDg3QUIxMUUzQjcwREVFMDM3NzA2QzEyMyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqfCcbEAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAADFBMVEVBuoQ0R10/qn8/qX7FyuqbAAAABHRSTlP9/QGEiU0+GwAAAPtJREFUGBkFwbFNXEEUBdDD/QSWmE7YYAogWNeAaMfaEuiD5HfAk9yIAwqYwIGRRvt8zkNdvckrzzcfjqDccdPIYnH1AJ4ywLs7m53Fhkcw0+DLDxZn0PCHQrrg2xWOCpS7m6bFAj/ZDLFY/AJbDDZ/WUzR4B84BRoURBeAo4Si0CBMFvBEGMBmExYbi0loACcBjQKhC3AUQVGaRjBhMxAsFlwQDLYFBA04EaAVEHSBoxAoPmkITBYDAovNhsAAEwINTggAINCFoyCg0CBgYoCAjQsIACCgcYKABhCgHAUClAYCTAMIsF2AAAACtBMIQAEB+jcggE9AAC+A/zyyZDSXstCbAAAAAElFTkSuQmCC) + 1x, + url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA0CAYAAADWr1sfAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTM4IDc5LjE1OTgyNCwgMjAxNi8wOS8xNC0wMTowOTowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NTAyNkI1RkE4N0VCMTFFQUFBQzJENzUzNDFGRjc1N0UiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NTAyNkI1Rjk4N0VCMTFFQUFBQzJENzUzNDFGRjc1N0UiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIChNYWNpbnRvc2gpIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6QTc3NzA2Q0Y4N0FCMTFFM0I3MERFRTAzNzcwNkMxMjMiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6QTc3NzA2RDA4N0FCMTFFM0I3MERFRTAzNzcwNkMxMjMiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz6nwnGxAAAJtklEQVR42txZ6W9c1RU/970373nsJHgZ27FThahSV8BCqGQTlIQ2EiUBReqHVpT8Af0r+NA/ogpqqWiDKrZuKYQPLGEpAlEFiqOgICSUBOKQhDjxeGY885bb37n3TGKPZ+4bx0uWK53Ec+cu53fPfkbtfu13B4noF6AQVAEpah0ak3cUSBU8qh46RfWj50ltKJDXXyBKdMtibI+TXlLqm2C87y/+eO/vlVIVnWbUcShFyld8T19ypvLbZKpyALOjVPCqrUcT1mWXYtIzMUV7Rqn315tJJyk+J51OZwb7QA3QkQD/fAL6JWiIXKMOhkOPwp1DFE/OkJ6NAQxn+fhuPhaFOc8DE9loern+hD9SfJVCdaLdOy5gif9rpHfyHp3pCX5cs6X1PfnORkr+SA9FO4bsgkZm1ykngm8ZK06ll0EvgWY6SwDn1fGKcykVfriewh2D5oKskhhw5KmFzLO0MJdO1yfS87UD2Uxc0tXErM+qLYQ5XUspK8el9JvagXSmPmH2W4lfG3wHNMHciXnmIfj+OvCVga8sD+yMYHyZAZ8H/Qk06dySaiNljf/DB0vklWAB1RQqnS0WA18eQE0Dz0++rjyRluOJDHuzWkwZNAPgLPHfPIeHTK/EEzHWKt/zDdh2asBmUUnJg3TDB0rQIuYptby5x6RgPO/JxIes304p44V1DMAzKQUbe4xqa62h2vbFyWuxeUie1RKqvVmXG/sxOaYKPqliQKp3HmEOB43pWaxJaTPvUV6rdK3Z6FloGUt35yD54EGXEwvaU3nSPSIYF7D5T/mio1rzS7Jaa1we4YWDzb1GUpptqJ1OGUl7BJX+jS7HP/OKEPlgRH5/SP5AZMjrCTz+jtdQQckxauEZ/IZ4bKyhYEsv7h6GpmGuhnsznafORwQbtQKGY6F/gy64pMxPnF2JSQ33UM/ecWNX/PJG3RbYsn15qCiYTQdhr49j9m4jQd8zXlkFZv3d/B087SBM4OodC+5kJYIX5r09+8ZIDYYAn4gqOdFeEEwn2gFmMb0BesEpZeOxARAOJ4SXjLbDlljKcbaQ0ebwrRNLy409oH1Xz1H2xrRc3wfaYx1dm/sgQTyYMZ1wZ4nC+4es76gnC3lqP14QTFk7wDymQH8DnXKCZibKiQHY89gY+aUeGwcT66xaw40JMUnWn52t7NWVeKt5GNaUarw1naruxXn9Rrrz9jRjLsd5PtsfZY3aaBZo9tT5qnxKsExRizto59EOccRzJQomHAC0DzsOHxwy3lvXk8VxU1u1VJFPaSW5B177SRtfNaVnq08izNyjQl9UefFe4zNwdoTI4I8XTfznu3NUORYMiyKP10HvD4neZy7VzqBaHEOjnw5TsKnXfgaDRjKqxWuzzRKtTy/Wt2W1ZAukuyX9tr4Ns+vZpheAVfKoOCuDKrNzDB8Ysp9Znd2qnAnvh9r5I8+hDs86HRhfCIlyQqGgbuHDI0Sz9gHaZj0sQXhhpJhbktOVp5Kvak/x31Sg9rarRXVxXvjwKJxk0Z7N/sOjPEf1bCez7LS1Ji/0iduBAUAD6JDpRFsHqfDjDZRdTqyU26gn2ykkXUovzf2KCV66ZGxXL9YeVtsMMb9w1x0U/WTAADWqnGO4wvMhwdA14PmqfbLjClZdTkaqCFPrAor2byIvUsZrd5Syp4BaFYW8RUmDeG8+wwsVRY+Pk7c+MJpkChXfCfhkJ1XuBjCPV0Bvt0nhFwoPiQfbVjixgaKHho3qGSlbgIu9ti/VEdHifJkdVc2aRoizwnv7kT+nNuy5hxZeX3EtygM8DfoX6FPnCcxL1Yap6NGNCCFFk5x0ETra2i7v9TcWqbh3zIbASmzvcHP7qfA6vRzAJIH7JWeYktRPz2a2bHuoZKpEdjgWdBeoWboMTpwea4o3GiF1lXzZPWLh8Y3ca7oAPAd6E/RubjLCkgBz4fYhCu6cl2d73UmX13KSUcDecNugqX2Np9a5mvKu8Di3EoB5HAP9WboGnZMRFiiXb0MhhYjNOrbeVsc5DPPexEqXz+C9HufLHHPT3PyxIbwd6wZIt4DnxCG81lG1JT9miZiaGeVj8L0+m3I2UrdaezY/z65Auj9ab0vPNLOlp+fEGwtPb3cj3aUA5nEWdDA3GTGMpqT6AupFmLLpYWaL9Hag2XZZdVHqcR1cfGzchDhdyWwFpnKTjIPCG600YFad96S+rHeOzZ5tB7Et3jeItLNk8+Fa2j6jYnU2YSyhaNcwFe4dMHv5DD7L1WUTXt5zmtoyADe7Bwfn15cdHZix3cxIzB+ObC+q2Z1Q6pq0E6gynF0A715ErasbqQWbH9JOCC8zSwGwVMA8Phb3X3a2g5BnZ5cRT78Dj7trxMRR7liY+lhdu5ntVnFDFLm4N1a0nr2e5rVtysLDx0tl/noAc9X7TLNH5KxZuC1Tg6puH0SYKtoaumFrYWPbsS0xg+/2UbjVVkNXW67u8aHwkKwFYB6fgQ47nYXXBBSbEBPtGjUtnWy6YcEm/F1q5sLdkO5AQTonuap8Vu7+7HoYv17APF4Fve6KrabEkzhcuH+AAuTFGmmjkeScbdsU7hswxGtMkqJzM7PX5W5aa8BfSDdwyt30I9Nw44qn+MgYef1IKC42SLN9D4TU8+iYCWGmKSfdEceYkju/uBGAebwvDW53KcOeFxlYcBeqqd3DBiznyCHCUPCDdUTsweM0765M7np/OQwvF/A5aYOedDcKmo23zP5qsalovTfny9wL4xQyP18+KXedu5GAmx0G9pizrsrAJCOQsuovUPTIKIU/HzG/SPKczks97dnPODswXY5gBQDXxK72g3a0fURT5yoTY7nw5w6ksVcAzZq/C7mbcv+TO2rLZXYlJMzjtNjXBedN7IlBXuibtq3ph8W5vw1dkLNPrwSjKwWY89oXQf9xNgqaXruaWLulXK8cy5kvOvP3GwC4mWc/50wImj+xaLrmpFRugvPcUvPltQJMUr0cXcHzjpLrF82bAHBN1O+dFTjrHTmrdjMD5vER6B/LZLQmZ3y00sytBuC65LtvLeOMt+SM+q0AmMekNNbK17G3LHsnV4Ox1QLM4wNRy3gJe2LZ88FqMbWagL8CPe2sptpXQ0/L3lsOMGcW3Cv+O+hyF+svy9pjsveWA9z0tn8Afd7F2s9lbW01GVptwJxTHZfE3/Uj17SsOU7ddLRuYsDN8decDOyorFn1sVaAvyT7k8iZNt+dke++vJ0A8+CfMw+3mT8s39HtBviSgDs+b+64zF26HQHz+C/o+Xmfn5c5ul0BXyT7w/U5oTdlbs1GQGs/vgb9cd7fazr+L8AAD0zRYMSYHQAAAAAASUVORK5CYII=) + 2x + ); + background-size: 10px; +} + +.css-image-set-gradient { + background-image: -webkit-image-set( + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA0AgMAAACrwbOMAAADI2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo1MDI2QjVGQTg3RUIxMUVBQUFDMkQ3NTM0MUZGNzU3RSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo1MDI2QjVGOTg3RUIxMUVBQUFDMkQ3NTM0MUZGNzU3RSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ0MgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpBNzc3MDZDRjg3QUIxMUUzQjcwREVFMDM3NzA2QzEyMyIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpBNzc3MDZEMDg3QUIxMUUzQjcwREVFMDM3NzA2QzEyMyIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqfCcbEAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAADFBMVEVBuoQ0R10/qn8/qX7FyuqbAAAABHRSTlP9/QGEiU0+GwAAAPtJREFUGBkFwbFNXEEUBdDD/QSWmE7YYAogWNeAaMfaEuiD5HfAk9yIAwqYwIGRRvt8zkNdvckrzzcfjqDccdPIYnH1AJ4ywLs7m53Fhkcw0+DLDxZn0PCHQrrg2xWOCpS7m6bFAj/ZDLFY/AJbDDZ/WUzR4B84BRoURBeAo4Si0CBMFvBEGMBmExYbi0loACcBjQKhC3AUQVGaRjBhMxAsFlwQDLYFBA04EaAVEHSBoxAoPmkITBYDAovNhsAAEwINTggAINCFoyCg0CBgYoCAjQsIACCgcYKABhCgHAUClAYCTAMIsF2AAAACtBMIQAEB+jcggE9AAC+A/zyyZDSXstCbAAAAAElFTkSuQmCC' + 1x, + linear-gradient(#e66465, #9198e5) 2x + ); + background-size: 10px; +} + .css-image-set-multiple-descriptor { background-image: -webkit-image-set( '../nested/asset.png' type('image/png') 1x, diff --git a/playground/assets/index.html b/playground/assets/index.html index 43eed55236abd3..fcf0e4ce1e81d7 100644 --- a/playground/assets/index.html +++ b/playground/assets/index.html @@ -56,6 +56,16 @@

CSS url references

CSS background image-set() (mix var and url) +
+ + CSS background image-set() (with base64) + +
+
+ + CSS background image-set() (with gradient) + +
CSS background image-set() (with multiple descriptor) From 85cab7054f5b7774fb796d86329226870fd23cdc Mon Sep 17 00:00:00 2001 From: TMQ <5112895@qq.com> Date: Tue, 10 May 2022 14:11:50 +0800 Subject: [PATCH 086/114] fix(build): use crossorigin for module preloaded --- packages/vite/src/node/plugins/html.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index 40883a86c9af2a..2f1e3af34babb4 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -546,6 +546,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { tag: 'link', attrs: { rel: 'modulepreload', + crossorigin: true, href: toPublicPath(chunk.fileName, config) } }) From 80d113b1d6df6c97ad2a3dcd27be8a7e27103141 Mon Sep 17 00:00:00 2001 From: yoho Date: Tue, 10 May 2022 17:42:29 +0800 Subject: [PATCH 087/114] feat: rework `dynamic-import-vars` (#7756) Co-authored-by: Anthony Fu Co-authored-by: Bjorn Lu --- .../__snapshots__/parse.test.ts.snap | 13 ++ .../plugins/dynamicImportVar/mods/hello.js | 3 + .../plugins/dynamicImportVar/mods/hi.js | 3 + .../plugins/dynamicImportVar/parse.test.ts | 38 +++ packages/vite/src/node/build.ts | 2 - .../src/node/plugins/dynamicImportVars.ts | 217 ++++++++++++++++++ .../vite/src/node/plugins/importAnalysis.ts | 23 +- .../vite/src/node/plugins/importMetaGlob.ts | 22 +- packages/vite/src/node/plugins/index.ts | 2 + packages/vite/src/node/utils.ts | 7 +- packages/vite/types/shims.d.ts | 5 + .../__tests__/dynamic-import.spec.ts | 24 ++ playground/dynamic-import/alias/hello.js | 3 + playground/dynamic-import/alias/hi.js | 3 + playground/dynamic-import/index.html | 14 ++ playground/dynamic-import/nested/hello.js | 3 + playground/dynamic-import/nested/index.js | 14 ++ playground/dynamic-import/vite.config.js | 12 +- 18 files changed, 372 insertions(+), 36 deletions(-) create mode 100644 packages/vite/src/node/__tests__/plugins/dynamicImportVar/__snapshots__/parse.test.ts.snap create mode 100644 packages/vite/src/node/__tests__/plugins/dynamicImportVar/mods/hello.js create mode 100644 packages/vite/src/node/__tests__/plugins/dynamicImportVar/mods/hi.js create mode 100644 packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.test.ts create mode 100644 packages/vite/src/node/plugins/dynamicImportVars.ts create mode 100644 playground/dynamic-import/alias/hello.js create mode 100644 playground/dynamic-import/alias/hi.js create mode 100644 playground/dynamic-import/nested/hello.js diff --git a/packages/vite/src/node/__tests__/plugins/dynamicImportVar/__snapshots__/parse.test.ts.snap b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/__snapshots__/parse.test.ts.snap new file mode 100644 index 00000000000000..be73ec998bc834 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/__snapshots__/parse.test.ts.snap @@ -0,0 +1,13 @@ +// Vitest Snapshot v1 + +exports[`parse positives > ? in url 1`] = `"__variableDynamicImportRuntimeHelper((import.meta.glob(\\"./mo?ds/*.js\\", {\\"as\\":\\"raw\\",\\"import\\":\\"*\\"})), \`./mo?ds/\${base ?? foo}.js\`)"`; + +exports[`parse positives > ? in variables 1`] = `"__variableDynamicImportRuntimeHelper((import.meta.glob(\\"./mods/*.js\\", {\\"as\\":\\"raw\\",\\"import\\":\\"*\\"})), \`./mods/\${base ?? foo}.js\`)"`; + +exports[`parse positives > alias path 1`] = `"__variableDynamicImportRuntimeHelper((import.meta.glob(\\"./mods/*.js\\")), \`./mods/\${base}.js\`)"`; + +exports[`parse positives > basic 1`] = `"__variableDynamicImportRuntimeHelper((import.meta.glob(\\"./mods/*.js\\")), \`./mods/\${base}.js\`)"`; + +exports[`parse positives > with query raw 1`] = `"__variableDynamicImportRuntimeHelper((import.meta.glob(\\"./mods/*.js\\", {\\"as\\":\\"raw\\",\\"import\\":\\"*\\"})), \`./mods/\${base}.js\`)"`; + +exports[`parse positives > with query url 1`] = `"__variableDynamicImportRuntimeHelper((import.meta.glob(\\"./mods/*.js\\")), \`./mods/\${base}.js\`)"`; diff --git a/packages/vite/src/node/__tests__/plugins/dynamicImportVar/mods/hello.js b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/mods/hello.js new file mode 100644 index 00000000000000..67900ef0999962 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/mods/hello.js @@ -0,0 +1,3 @@ +export function hello() { + return 'hello' +} diff --git a/packages/vite/src/node/__tests__/plugins/dynamicImportVar/mods/hi.js b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/mods/hi.js new file mode 100644 index 00000000000000..45d3506803b2b6 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/mods/hi.js @@ -0,0 +1,3 @@ +export function hi() { + return 'hi' +} diff --git a/packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.test.ts b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.test.ts new file mode 100644 index 00000000000000..ef1dcb2238a5b0 --- /dev/null +++ b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.test.ts @@ -0,0 +1,38 @@ +import { describe, expect, it } from 'vitest' +import { transformDynamicImport } from '../../../plugins/dynamicImportVars' +import { resolve } from 'path' + +async function run(input: string) { + const { glob, rawPattern } = await transformDynamicImport( + input, + resolve(__dirname, 'index.js'), + (id) => id.replace('@', resolve(__dirname, './mods/')) + ) + return `__variableDynamicImportRuntimeHelper(${glob}, \`${rawPattern}\`)` +} + +describe('parse positives', () => { + it('basic', async () => { + expect(await run('`./mods/${base}.js`')).toMatchSnapshot() + }) + + it('alias path', async () => { + expect(await run('`@/${base}.js`')).toMatchSnapshot() + }) + + it('with query raw', async () => { + expect(await run('`./mods/${base}.js?raw`')).toMatchSnapshot() + }) + + it('with query url', async () => { + expect(await run('`./mods/${base}.js?url`')).toMatchSnapshot() + }) + + it('? in variables', async () => { + expect(await run('`./mods/${base ?? foo}.js?raw`')).toMatchSnapshot() + }) + + it('? in url', async () => { + expect(await run('`./mo?ds/${base ?? foo}.js?raw`')).toMatchSnapshot() + }) +}) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index d4d4085bb829ed..1bdfa5a35077e6 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -26,7 +26,6 @@ import { copyDir, emptyDir, lookupFile, normalizePath } from './utils' import { manifestPlugin } from './plugins/manifest' import commonjsPlugin from '@rollup/plugin-commonjs' import type { RollupCommonJSOptions } from 'types/commonjs' -import dynamicImportVars from '@rollup/plugin-dynamic-import-vars' import type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars' import type { Logger } from './logger' import type { TransformOptions } from 'esbuild' @@ -285,7 +284,6 @@ export function resolveBuildPlugins(config: ResolvedConfig): { watchPackageDataPlugin(config), commonjsPlugin(options.commonjsOptions), dataURIPlugin(), - dynamicImportVars(options.dynamicImportVarsOptions), assetImportMetaUrlPlugin(config), ...(options.rollupOptions.plugins ? (options.rollupOptions.plugins.filter(Boolean) as Plugin[]) diff --git a/packages/vite/src/node/plugins/dynamicImportVars.ts b/packages/vite/src/node/plugins/dynamicImportVars.ts new file mode 100644 index 00000000000000..c33590cf0343f4 --- /dev/null +++ b/packages/vite/src/node/plugins/dynamicImportVars.ts @@ -0,0 +1,217 @@ +import { posix } from 'path' +import MagicString from 'magic-string' +import { init, parse as parseImports } from 'es-module-lexer' +import type { ImportSpecifier } from 'es-module-lexer' +import type { Plugin } from '../plugin' +import type { ResolvedConfig } from '../config' +import { normalizePath, parseRequest, requestQuerySplitRE } from '../utils' +import { parse as parseJS } from 'acorn' +import { createFilter } from '@rollup/pluginutils' +import { dynamicImportToGlob } from '@rollup/plugin-dynamic-import-vars' + +export const dynamicImportHelperId = '/@vite/dynamic-import-helper' + +interface DynamicImportRequest { + as?: 'raw' +} + +interface DynamicImportPattern { + globParams: DynamicImportRequest | null + userPattern: string + rawPattern: string +} + +const dynamicImportHelper = (glob: Record, path: string) => { + const v = glob[path] + if (v) { + return typeof v === 'function' ? v() : Promise.resolve(v) + } + return new Promise((_, reject) => { + ;(typeof queueMicrotask === 'function' ? queueMicrotask : setTimeout)( + reject.bind(null, new Error('Unknown variable dynamic import: ' + path)) + ) + }) +} + +function parseDynamicImportPattern( + strings: string +): DynamicImportPattern | null { + const filename = strings.slice(1, -1) + const rawQuery = parseRequest(filename) + let globParams: DynamicImportRequest | null = null + const ast = ( + parseJS(strings, { + ecmaVersion: 'latest', + sourceType: 'module' + }) as any + ).body[0].expression + + const userPatternQuery = dynamicImportToGlob(ast, filename) + if (!userPatternQuery) { + return null + } + + const [userPattern] = userPatternQuery.split(requestQuerySplitRE, 2) + const [rawPattern] = filename.split(requestQuerySplitRE, 2) + + if (rawQuery?.raw !== undefined) { + globParams = { as: 'raw' } + } + + return { + globParams, + userPattern, + rawPattern + } +} + +export async function transformDynamicImport( + importSource: string, + importer: string, + resolve: ( + url: string, + importer?: string + ) => Promise | string | undefined +): Promise<{ + glob: string + pattern: string + rawPattern: string +} | null> { + if (importSource[1] !== '.' && importSource[1] !== '/') { + const resolvedFileName = await resolve(importSource.slice(1, -1), importer) + if (!resolvedFileName) { + return null + } + const relativeFileName = posix.relative( + posix.dirname(normalizePath(importer)), + normalizePath(resolvedFileName) + ) + importSource = normalizePath( + '`' + (relativeFileName[0] === '.' ? '' : './') + relativeFileName + '`' + ) + } + + const dynamicImportPattern = parseDynamicImportPattern(importSource) + if (!dynamicImportPattern) { + return null + } + const { globParams, rawPattern, userPattern } = dynamicImportPattern + const params = globParams + ? `, ${JSON.stringify({ ...globParams, import: '*' })}` + : '' + const exp = `(import.meta.glob(${JSON.stringify(userPattern)}${params}))` + + return { + rawPattern, + pattern: userPattern, + glob: exp + } +} + +export function dynamicImportVarsPlugin(config: ResolvedConfig): Plugin { + const resolve = config.createResolver({ + preferRelative: true, + tryIndex: false, + extensions: [] + }) + const { include, exclude, warnOnError } = + config.build.dynamicImportVarsOptions + const filter = createFilter(include, exclude) + const isBuild = config.command === 'build' + return { + name: 'vite:dynamic-import-vars', + + resolveId(id) { + if (id === dynamicImportHelperId) { + return id + } + }, + + load(id) { + if (id === dynamicImportHelperId) { + return 'export default ' + dynamicImportHelper.toString() + } + }, + + async transform(source, importer) { + if (!filter(importer)) { + return + } + + await init + + let imports: readonly ImportSpecifier[] = [] + try { + imports = parseImports(source)[0] + } catch (e: any) { + // ignore as it might not be a JS file, the subsequent plugins will catch the error + return null + } + + if (!imports.length) { + return null + } + + let s: MagicString | undefined + let needDynamicImportHelper = false + + for (let index = 0; index < imports.length; index++) { + const { + s: start, + e: end, + ss: expStart, + se: expEnd, + d: dynamicIndex + } = imports[index] + + if (dynamicIndex === -1 || source[start] !== '`') { + continue + } + + s ||= new MagicString(source) + let result + try { + result = await transformDynamicImport( + source.slice(start, end), + importer, + resolve + ) + } catch (error) { + if (warnOnError) { + this.warn(error) + } else { + this.error(error) + } + } + + if (!result) { + continue + } + + const { rawPattern, glob } = result + + needDynamicImportHelper = true + s.overwrite( + expStart, + expEnd, + `__variableDynamicImportRuntimeHelper(${glob}, \`${rawPattern}\`)` + ) + } + + if (s) { + if (needDynamicImportHelper) { + s.prepend( + `import __variableDynamicImportRuntimeHelper from "${dynamicImportHelperId}";` + ) + } + return { + code: s.toString(), + map: + !isBuild || config.build.sourcemap + ? s.generateMap({ hires: true }) + : null + } + } + } + } +} diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index ed4a2bc934ab5a..f12426aa923cfe 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -490,7 +490,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { const url = rawUrl .replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '') .trim() - if (!hasViteIgnore && !isSupportedDynamicImport(url)) { + if (!hasViteIgnore) { this.warn( `\n` + colors.cyan(importerModule.file) + @@ -651,27 +651,6 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { } } -/** - * https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations - * This is probably less accurate but is much cheaper than a full AST parse. - */ -function isSupportedDynamicImport(url: string) { - url = url.trim().slice(1, -1) - // must be relative - if (!url.startsWith('./') && !url.startsWith('../')) { - return false - } - // must have extension - if (!path.extname(url)) { - return false - } - // must be more specific if importing from same dir - if (url.startsWith('./${') && url.indexOf('/') === url.lastIndexOf('/')) { - return false - } - return true -} - type ImportNameSpecifier = { importedName: string; localName: string } /** diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 5bf4d14a4dc9f0..ed46e35bea8ecf 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -11,7 +11,7 @@ import type { ViteDevServer } from '../server' import type { ModuleNode } from '../server/moduleGraph' import type { ResolvedConfig } from '../config' import { isCSSRequest } from './css' -import type { GeneralImportGlobOptions } from '../../../types/importGlob' +import type { GeneralImportGlobOptions } from 'types/importGlob' import { normalizePath, slash } from '../utils' export interface ParsedImportGlob { @@ -168,12 +168,13 @@ export async function parseImportGlob( for (const property of arg2.properties) { if ( property.type === 'SpreadElement' || - property.key.type !== 'Identifier' + (property.key.type !== 'Identifier' && + property.key.type !== 'Literal') ) throw err('Could only use literals') - const name = property.key.name as keyof GeneralImportGlobOptions - + const name = ((property.key as any).name || + (property.key as any).value) as keyof GeneralImportGlobOptions if (name === 'query') { if (property.value.type === 'ObjectExpression') { const data: Record = {} @@ -260,13 +261,22 @@ const importPrefix = '__vite_glob_' const { basename, dirname, relative, join } = posix +export interface TransformGlobImportResult { + s: MagicString + matches: ParsedImportGlob[] + files: Set +} + +/** + * @param optimizeExport for dynamicImportVar plugin don't need to optimize export. + */ export async function transformGlobImport( code: string, id: string, root: string, resolveId: IdResolver, restoreQueryExtension = false -) { +): Promise { id = slash(id) root = slash(root) const isVirtual = isVirtualModule(id) @@ -288,7 +298,7 @@ export async function transformGlobImport( } }) - if (!matches.length) return + if (!matches.length) return null const s = new MagicString(code) diff --git a/packages/vite/src/node/plugins/index.ts b/packages/vite/src/node/plugins/index.ts index 26d777cf919292..3fd283b07b4e47 100644 --- a/packages/vite/src/node/plugins/index.ts +++ b/packages/vite/src/node/plugins/index.ts @@ -19,6 +19,7 @@ import { ssrRequireHookPlugin } from './ssrRequireHook' import { workerImportMetaUrlPlugin } from './workerImportMetaUrl' import { ensureWatchPlugin } from './ensureWatch' import { metadataPlugin } from './metadata' +import { dynamicImportVarsPlugin } from './dynamicImportVars' import { importGlobPlugin } from './importMetaGlob' export async function resolvePlugins( @@ -73,6 +74,7 @@ export async function resolvePlugins( isBuild && buildHtmlPlugin(config), workerImportMetaUrlPlugin(config), ...buildPlugins.pre, + dynamicImportVarsPlugin(config), importGlobPlugin(config), ...postPlugins, ...buildPlugins.post, diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 0c25b4592adf6d..d84b474b87c33f 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -19,7 +19,7 @@ import type { FSWatcher } from 'chokidar' import remapping from '@ampproject/remapping' import type { DecodedSourceMap, RawSourceMap } from '@ampproject/remapping' import { performance } from 'perf_hooks' -import { parse as parseUrl, URLSearchParams } from 'url' +import { URLSearchParams } from 'url' export function slash(p: string): string { return p.replace(/\\/g, '/') @@ -741,6 +741,7 @@ export function toUpperCaseDriveLetter(pathName: string): string { export const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm export const singlelineCommentsRE = /\/\/.*/g +export const requestQuerySplitRE = /\?(?!.*[\/|\}])/ export const usingDynamicImport = typeof jest === 'undefined' /** @@ -757,11 +758,11 @@ export const dynamicImport = usingDynamicImport : require export function parseRequest(id: string): Record | null { - const { search } = parseUrl(id) + const [_, search] = id.split(requestQuerySplitRE, 2) if (!search) { return null } - return Object.fromEntries(new URLSearchParams(search.slice(1))) + return Object.fromEntries(new URLSearchParams(search)) } export const blankReplacer = (match: string) => ' '.repeat(match.length) diff --git a/packages/vite/types/shims.d.ts b/packages/vite/types/shims.d.ts index 0f49e9c2181e98..587b3344e6ce39 100644 --- a/packages/vite/types/shims.d.ts +++ b/packages/vite/types/shims.d.ts @@ -59,6 +59,7 @@ declare module 'postcss-modules' { declare module '@rollup/plugin-dynamic-import-vars' { import type { Plugin } from 'rollup' + import type { BaseNode } from 'estree' interface Options { include?: string | RegExp | (string | RegExp)[] @@ -68,6 +69,10 @@ declare module '@rollup/plugin-dynamic-import-vars' { const p: (o?: Options) => Plugin export default p + export function dynamicImportToGlob( + ast: BaseNode, + source: string + ): null | string } declare module 'rollup-plugin-web-worker-loader' { diff --git a/playground/dynamic-import/__tests__/dynamic-import.spec.ts b/playground/dynamic-import/__tests__/dynamic-import.spec.ts index 4730b5e990a1c3..95101a039e50f8 100644 --- a/playground/dynamic-import/__tests__/dynamic-import.spec.ts +++ b/playground/dynamic-import/__tests__/dynamic-import.spec.ts @@ -60,6 +60,30 @@ test('should load dynamic import with css', async () => { ) }) +test('should load dynamic import with vars', async () => { + await untilUpdated( + () => page.textContent('.dynamic-import-with-vars'), + 'hello', + true + ) +}) + +test('should load dynamic import with vars alias', async () => { + await untilUpdated( + () => page.textContent('.dynamic-import-with-vars-alias'), + 'hello', + true + ) +}) + +test('should load dynamic import with vars raw', async () => { + await untilUpdated( + () => page.textContent('.dynamic-import-with-vars-raw'), + 'export function hello()', + true + ) +}) + test('should load dynamic import with css in package', async () => { await page.click('.pkg-css') await untilUpdated(() => getColor('.pkg-css'), 'blue', true) diff --git a/playground/dynamic-import/alias/hello.js b/playground/dynamic-import/alias/hello.js new file mode 100644 index 00000000000000..67900ef0999962 --- /dev/null +++ b/playground/dynamic-import/alias/hello.js @@ -0,0 +1,3 @@ +export function hello() { + return 'hello' +} diff --git a/playground/dynamic-import/alias/hi.js b/playground/dynamic-import/alias/hi.js new file mode 100644 index 00000000000000..45d3506803b2b6 --- /dev/null +++ b/playground/dynamic-import/alias/hi.js @@ -0,0 +1,3 @@ +export function hi() { + return 'hi' +} diff --git a/playground/dynamic-import/index.html b/playground/dynamic-import/index.html index 8e18204a7e4296..997ad059ad6821 100644 --- a/playground/dynamic-import/index.html +++ b/playground/dynamic-import/index.html @@ -10,6 +10,20 @@ +

dynamic-import-with-vars

+
todo
+ +

dynamic-import-with-vars-alias

+
todo
+ +

dynamic-import-with-vars-raw

+
todo
+
+ diff --git a/playground/dynamic-import/nested/hello.js b/playground/dynamic-import/nested/hello.js new file mode 100644 index 00000000000000..67900ef0999962 --- /dev/null +++ b/playground/dynamic-import/nested/hello.js @@ -0,0 +1,3 @@ +export function hello() { + return 'hello' +} diff --git a/playground/dynamic-import/nested/index.js b/playground/dynamic-import/nested/index.js index f84ec00380d604..61f817ce7dd7bc 100644 --- a/playground/dynamic-import/nested/index.js +++ b/playground/dynamic-import/nested/index.js @@ -78,3 +78,17 @@ document.querySelector('.pkg-css').addEventListener('click', async () => { function text(el, text) { document.querySelector(el).textContent = text } + +const base = 'hello' + +import(`../alias/${base}.js`).then((mod) => { + text('.dynamic-import-with-vars', mod.hello()) +}) + +import(`@/${base}.js`).then((mod) => { + text('.dynamic-import-with-vars-alias', mod.hello()) +}) + +import(`../alias/${base}.js?raw`).then((mod) => { + text('.dynamic-import-with-vars-raw', JSON.stringify(mod)) +}) diff --git a/playground/dynamic-import/vite.config.js b/playground/dynamic-import/vite.config.js index 010e47d6308d30..50b90639fddd7f 100644 --- a/playground/dynamic-import/vite.config.js +++ b/playground/dynamic-import/vite.config.js @@ -1,7 +1,8 @@ const fs = require('fs') const path = require('path') +const vite = require('vite') -module.exports = { +module.exports = vite.defineConfig({ plugins: [ { name: 'copy', @@ -20,5 +21,10 @@ module.exports = { ) } } - ] -} + ], + resolve: { + alias: { + '@': path.resolve(__dirname, 'alias') + } + } +}) From 780b4f5cdf02adb4ce42c283b60a4d4bb06b8440 Mon Sep 17 00:00:00 2001 From: shir0u <85612853+shir0u@users.noreply.github.com> Date: Tue, 10 May 2022 20:06:29 +1000 Subject: [PATCH 088/114] fix: allow css to be written for systemjs output (#5902) Co-authored-by: patak-dev --- packages/vite/src/node/plugins/css.ts | 8 +++- playground/legacy/__tests__/legacy.spec.ts | 11 ++++++ playground/legacy/dynamic.css | 3 ++ playground/legacy/index.html | 2 + playground/legacy/main.js | 8 ++++ playground/legacy/package.json | 1 + playground/legacy/vite.config-dynamic-css.js | 39 ++++++++++++++++++++ 7 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 playground/legacy/dynamic.css create mode 100644 playground/legacy/vite.config-dynamic-css.js diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index c13a4c83052639..1e1bcef686ea42 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -452,7 +452,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // this is a shared CSS-only chunk that is empty. pureCssChunks.add(chunk.fileName) } - if (opts.format === 'es' || opts.format === 'cjs') { + if ( + opts.format === 'es' || + opts.format === 'cjs' || + opts.format === 'system' + ) { chunkCSS = await processChunkCSS(chunkCSS, { inlined: false, minify: true @@ -513,7 +517,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { .join('|') .replace(/\./g, '\\.') const emptyChunkRE = new RegExp( - opts.format === 'es' + opts.format === 'es' || opts.format === 'system' ? `\\bimport\\s*"[^"]*(?:${emptyChunkFiles})";\n?` : `\\brequire\\(\\s*"[^"]*(?:${emptyChunkFiles})"\\);\n?`, 'g' diff --git a/playground/legacy/__tests__/legacy.spec.ts b/playground/legacy/__tests__/legacy.spec.ts index 89cbadcacb2fd8..9fd3419337568d 100644 --- a/playground/legacy/__tests__/legacy.spec.ts +++ b/playground/legacy/__tests__/legacy.spec.ts @@ -56,6 +56,17 @@ test('correctly emits styles', async () => { expect(await getColor('#app')).toBe('red') }) +// dynamic import css +test('should load dynamic import with css', async () => { + await page.click('#dynamic-css-button') + await untilUpdated( + () => + page.$eval('#dynamic-css', (node) => window.getComputedStyle(node).color), + 'rgb(255, 0, 0)', + true + ) +}) + if (isBuild) { test('should generate correct manifest', async () => { const manifest = readManifest() diff --git a/playground/legacy/dynamic.css b/playground/legacy/dynamic.css new file mode 100644 index 00000000000000..160ee45a8a850a --- /dev/null +++ b/playground/legacy/dynamic.css @@ -0,0 +1,3 @@ +#dynamic-css { + color: red; +} diff --git a/playground/legacy/index.html b/playground/legacy/index.html index d481766463cd4f..cbf6242fad756b 100644 --- a/playground/legacy/index.html +++ b/playground/legacy/index.html @@ -4,4 +4,6 @@

+ +
diff --git a/playground/legacy/main.js b/playground/legacy/main.js index 31579b4717810d..157b6c8448e9c3 100644 --- a/playground/legacy/main.js +++ b/playground/legacy/main.js @@ -42,6 +42,14 @@ import('./immutable-chunk.js') text('#assets', assets.join('\n')) }) +// dynamic css +document + .querySelector('#dynamic-css-button') + .addEventListener('click', async () => { + await import('./dynamic.css') + text('#dynamic-css', 'dynamic import css') + }) + function text(el, text) { document.querySelector(el).textContent = text } diff --git a/playground/legacy/package.json b/playground/legacy/package.json index f8803564f93f12..4f11c234573f40 100644 --- a/playground/legacy/package.json +++ b/playground/legacy/package.json @@ -6,6 +6,7 @@ "dev": "vite", "build": "vite build --debug legacy", "build:custom-filename": "vite --config ./vite.config-custom-filename.js build --debug legacy", + "build:dynamic-css": "vite --config ./vite.config-dynamic-css.js build --debug legacy", "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" }, diff --git a/playground/legacy/vite.config-dynamic-css.js b/playground/legacy/vite.config-dynamic-css.js new file mode 100644 index 00000000000000..10565768ac4d49 --- /dev/null +++ b/playground/legacy/vite.config-dynamic-css.js @@ -0,0 +1,39 @@ +const fs = require('fs') +const path = require('path') +const legacy = require('@vitejs/plugin-legacy').default + +module.exports = { + plugins: [ + legacy({ + targets: 'IE 11' + }) + ], + + build: { + cssCodeSplit: true, + manifest: true, + rollupOptions: { + output: { + chunkFileNames(chunkInfo) { + if (chunkInfo.name === 'immutable-chunk') { + return `assets/${chunkInfo.name}.js` + } + + return `assets/chunk-[name].[hash].js` + } + } + } + }, + + // special test only hook + // for tests, remove ` diff --git a/packages/playground/json/server.js b/packages/playground/json/server.js new file mode 100644 index 00000000000000..d7803b94f4b81a --- /dev/null +++ b/packages/playground/json/server.js @@ -0,0 +1,88 @@ +// @ts-check +const fs = require('fs') +const path = require('path') +const express = require('express') + +const isTest = process.env.NODE_ENV === 'test' || !!process.env.VITE_TEST_BUILD + +async function createServer( + root = process.cwd(), + isProd = process.env.NODE_ENV === 'production' +) { + const resolve = (p) => path.resolve(__dirname, p) + const app = express() + + /** + * @type {import('vite').ViteDevServer} + */ + let vite + vite = await require('vite').createServer({ + root, + logLevel: isTest ? 'error' : 'info', + server: { + middlewareMode: 'ssr', + watch: { + // During tests we edit the files too fast and sometimes chokidar + // misses change events, so enforce polling for consistency + usePolling: true, + interval: 100 + } + }, + json: { + stringify: true + } + }) + // use vite's connect instance as middleware + app.use(vite.middlewares) + + app.use('*', async (req, res) => { + try { + let [url] = req.originalUrl.split('?') + if (url.endsWith('/')) url += 'index.ssr.html' + + if (url === '/json-module') { + console.time('load module') + const json = JSON.stringify(await vite.ssrLoadModule('/test.json')) + console.timeEnd('load module') + res.status(200).end('' + json.length) + return + } + + if (url === '/json-fs') { + console.time('transform module') + const source = fs.readFileSync('./test.json', { encoding: 'utf-8' }) + const json = await vite.ssrTransform( + `export default ${source}`, + null, + './output.json' + ) + console.timeEnd('transform module') + res.status(200).end(String(json.code.length)) + return + } + + const htmlLoc = resolve(`.${url}`) + let html = fs.readFileSync(htmlLoc, 'utf8') + html = await vite.transformIndexHtml(url, html) + + res.status(200).set({ 'Content-Type': 'text/html' }).end(html) + } catch (e) { + vite && vite.ssrFixStacktrace(e) + console.log(e.stack) + res.status(500).end(e.stack) + } + }) + + return { app, vite } +} + +if (!isTest) { + createServer().then(({ app }) => + app.listen(3000, () => { + console.log('http://localhost:3000') + }) + ) +} + +// for test use +exports.createServer = createServer diff --git a/packages/vite/src/node/plugins/json.ts b/packages/vite/src/node/plugins/json.ts index f8419c40f36174..9c142501ff651e 100644 --- a/packages/vite/src/node/plugins/json.ts +++ b/packages/vite/src/node/plugins/json.ts @@ -7,8 +7,8 @@ */ import { dataToEsm } from '@rollup/pluginutils' -import type { Plugin } from 'rollup' import { SPECIAL_QUERY_RE } from '../constants' +import type { Plugin } from '../plugin' export interface JsonOptions { /** @@ -27,6 +27,11 @@ export interface JsonOptions { // Custom json filter for vite const jsonExtRE = /\.json($|\?)(?!commonjs-(proxy|external))/ +const jsonLangs = `\\.(json|json5)($|\\?)` +const jsonLangRE = new RegExp(jsonLangs) +export const isJSONRequest = (request: string): boolean => + jsonLangRE.test(request) + export function jsonPlugin( options: JsonOptions = {}, isBuild: boolean diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 0b499b42c2d457..50ca05e17a748e 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -321,7 +321,11 @@ export async function createServer( pluginContainer: container, ws, moduleGraph, - ssrTransform, + ssrTransform(code: string, inMap: SourceMap | null, url: string) { + return ssrTransform(code, inMap, url, { + json: { stringify: server.config.json?.stringify } + }) + }, transformRequest(url, options) { return transformRequest(url, server, options) }, diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index baafe95e8416f3..f877925f491479 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -238,7 +238,9 @@ async function doTransform( } const result = ssr - ? await ssrTransform(code, map as SourceMap, url) + ? await ssrTransform(code, map as SourceMap, url, { + json: { stringify: !!server.config.json?.stringify } + }) : ({ code, map, diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index 8b3a423f58aeab..9f75641c84e513 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -84,7 +84,6 @@ async function instantiateModule( if (mod.ssrModule) { return mod.ssrModule } - const result = mod.ssrTransformResult || (await transformRequest(url, server, { ssr: true })) diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts index c1aa572864776a..4eeb34ad7e102c 100644 --- a/packages/vite/src/node/ssr/ssrTransform.ts +++ b/packages/vite/src/node/ssr/ssrTransform.ts @@ -12,6 +12,7 @@ import type { import { extract_names as extractNames } from 'periscopic' import { walk as eswalk } from 'estree-walker' import { combineSourcemaps } from '../utils' +import { isJSONRequest } from '../plugins/json' import type { RawSourceMap } from '@ampproject/remapping' type Node = _Node & { @@ -19,6 +20,12 @@ type Node = _Node & { end: number } +interface TransformOptions { + json?: { + stringify?: boolean + } +} + export const ssrModuleExportsKey = `__vite_ssr_exports__` export const ssrImportKey = `__vite_ssr_import__` export const ssrDynamicImportKey = `__vite_ssr_dynamic_import__` @@ -26,6 +33,30 @@ export const ssrExportAllKey = `__vite_ssr_exportAll__` export const ssrImportMetaKey = `__vite_ssr_import_meta__` export async function ssrTransform( + code: string, + inMap: SourceMap | null, + url: string, + options?: TransformOptions +): Promise { + if (options?.json?.stringify && isJSONRequest(url)) { + return ssrTransformJSON(code, inMap) + } + return ssrTransformScript(code, inMap, url) +} + +async function ssrTransformJSON( + code: string, + inMap: SourceMap | null +): Promise { + return { + code: code.replace('export default', `${ssrModuleExportsKey}.default =`), + map: inMap, + deps: [], + dynamicDeps: [] + } +} + +async function ssrTransformScript( code: string, inMap: SourceMap | null, url: string diff --git a/playground/json/package.json b/playground/json/package.json index a32140c1220d1a..b919c42eb6ef5d 100644 --- a/playground/json/package.json +++ b/playground/json/package.json @@ -6,9 +6,14 @@ "dev": "vite", "build": "vite build", "debug": "node --inspect-brk ../../packages/vite/bin/vite", - "preview": "vite preview" + "preview": "vite preview", + "dev:ssr": "node server", + "serve:ssr": "cross-env NODE_ENV=production node server", + "debug:ssr": "node --inspect-brk server" }, "devDependencies": { + "cross-env": "^7.0.3", + "express": "^4.17.1", "json-module": "file:./json-module", "vue": "^3.2.33" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 655b3273279f9e..1a06a82b104080 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -458,9 +458,13 @@ importers: playground/json: specifiers: + cross-env: ^7.0.3 + express: ^4.17.1 json-module: file:./json-module vue: ^3.2.33 devDependencies: + cross-env: 7.0.3 + express: 4.18.1 json-module: link:json-module vue: 3.2.33 From 4abfee61e9e93a7af908adad87cd0cb9d15938ad Mon Sep 17 00:00:00 2001 From: zz <2418184580@qq.com> Date: Tue, 10 May 2022 22:23:20 +0800 Subject: [PATCH 094/114] ci: remove unnecessary actions (#7799) --- .github/workflows/publish.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c58c28adac7b40..72a6ffde2cb62c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -32,14 +32,6 @@ jobs: - name: Install deps run: pnpm install - - name: Creating .npmrc - run: | - cat << EOF > "$HOME/.npmrc" - //registry.npmjs.org/:_authToken=$NPM_TOKEN - EOF - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - name: Publish package run: pnpm run ci-publish -- ${{ github.ref_name }} env: From ae56e4778f4d5adc29341d93557aa02e40e70a89 Mon Sep 17 00:00:00 2001 From: Nick Santos Date: Tue, 10 May 2022 10:51:21 -0400 Subject: [PATCH 095/114] fix(client): wait on the socket host, not the ping host (#6819) --- packages/vite/src/client/client.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index 48917204d8c291..6a7f9b27c3a700 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -201,12 +201,10 @@ async function waitForSuccessfulPing(ms = 1000) { // eslint-disable-next-line no-constant-condition while (true) { try { - const pingResponse = await fetch(`${base}__vite_ping`) - - // success - 2xx status code - if (pingResponse.ok) break - // failure - non-2xx status code - else throw new Error() + // A fetch on a websocket URL will return a successful promise with status 400, + // but will reject a networking error. + await fetch(`${location.protocol}//${socketHost}`) + break } catch (e) { // wait ms before attempting to ping again await new Promise((resolve) => setTimeout(resolve, ms)) From b2c029a086de135bbb04bbe0e35c0a3b4526900e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Livora?= Date: Tue, 10 May 2022 17:04:09 +0200 Subject: [PATCH 096/114] docs: mention middlewares in server.proxy config (#5188) --- docs/config/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/config/index.md b/docs/config/index.md index 666f5f39a5511c..8fc772f345e0ea 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -519,6 +519,8 @@ export default defineConfig(({ command, mode }) => { Uses [`http-proxy`](https://github.com/http-party/node-http-proxy). Full options [here](https://github.com/http-party/node-http-proxy#options). + In some cases, you might also want to configure the underlying dev server (e.g. to add custom middlewares to the internal [connect](https://github.com/senchalabs/connect) app). In order to do that, you need to write your own [plugin](/guide/using-plugins.html) and use [configureServer](/guide/api-plugin.html#configureserver) function. + **Example:** ```js From 1be4646ac1a3912c4e4b90c04176ee613e48ede8 Mon Sep 17 00:00:00 2001 From: Zehua Chen Date: Tue, 10 May 2022 12:45:55 -0400 Subject: [PATCH 097/114] docs: improve instruction for backend integration, close #7778 (#8103) Co-authored-by: Enzo Innocenzi --- docs/guide/backend-integration.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/guide/backend-integration.md b/docs/guide/backend-integration.md index 55a4b87f1ac481..17387bb7819ec0 100644 --- a/docs/guide/backend-integration.md +++ b/docs/guide/backend-integration.md @@ -36,7 +36,12 @@ If you need a custom integration, you can follow the steps in this guide to conf ``` - Also make sure the server is configured to serve static assets in the Vite working directory, otherwise assets such as images won't be loaded properly. + In order to properly serve assets, you have two options: + + - Make sure the server is configured to proxy static assets requests to the Vite server + - Set [`server.origin`](https://vitejs.dev/config/#server-origin) so that generated asset URLs will be resolved using the back-end server URL instead of a relative path + + This is needed for assets such as images to load properly. Note if you are using React with `@vitejs/plugin-react`, you'll also need to add this before the above scripts, since the plugin is not able to modify the HTML you are serving: From 5484c8ce02cc8847ff9e85ba60b482ca170ae867 Mon Sep 17 00:00:00 2001 From: ZxBing0066 Date: Wed, 11 May 2022 00:53:17 +0800 Subject: [PATCH 098/114] chore: remove noop watch close (#6294) --- packages/vite/src/node/build.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 1bdfa5a35077e6..cc254521b8d2aa 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -499,9 +499,6 @@ async function doBuild( } }) - // stop watching - watcher.close() - return watcher } From bb603d3d66506deb353e4d6346d5e8361fdb9e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Mel=C3=A9n?= Date: Wed, 11 May 2022 01:26:46 +0200 Subject: [PATCH 099/114] fix(glob): wrap glob compile output in function invocation (#3682) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tobias Melén Co-authored-by: patak-dev --- .../glob-import/side-effect/writetodom.js | 4 + .../__snapshots__/fixture.test.ts.snap | 120 +++++++++--------- .../vite/src/node/plugins/importMetaGlob.ts | 2 +- .../glob-import/__tests__/glob-import.spec.ts | 27 +++- playground/glob-import/index.html | 9 ++ .../glob-import/side-effect/writedom.js | 4 + 6 files changed, 98 insertions(+), 68 deletions(-) create mode 100644 packages/playground/glob-import/side-effect/writetodom.js create mode 100644 playground/glob-import/side-effect/writedom.js diff --git a/packages/playground/glob-import/side-effect/writetodom.js b/packages/playground/glob-import/side-effect/writetodom.js new file mode 100644 index 00000000000000..e2ab04ba7f5cbe --- /dev/null +++ b/packages/playground/glob-import/side-effect/writetodom.js @@ -0,0 +1,4 @@ +/* global document */ +document && + (document.querySelector('.side-effect-result').textContent = + 'Hello from side effect') diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap b/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap index 23e511a50545f7..61ff6eeb4d2fc7 100644 --- a/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap +++ b/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap @@ -10,67 +10,67 @@ import { name as __vite_glob_3_2 } from \\"./modules/index.ts\\" import { default as __vite_glob_5_0 } from \\"./modules/a.ts?raw\\" import { default as __vite_glob_5_1 } from \\"./modules/b.ts?raw\\" import \\"../../../../../../types/importMeta\\"; -export const basic = { +export const basic = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"), \\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\") -}; -export const basicEager = { +}); +export const basicEager = Object.assign({ \\"./modules/a.ts\\": __vite_glob_1_0, \\"./modules/b.ts\\": __vite_glob_1_1, \\"./modules/index.ts\\": __vite_glob_1_2 -}; -export const ignore = { +}); +export const ignore = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\") -}; -export const namedEager = { +}); +export const namedEager = Object.assign({ \\"./modules/a.ts\\": __vite_glob_3_0, \\"./modules/b.ts\\": __vite_glob_3_1, \\"./modules/index.ts\\": __vite_glob_3_2 -}; -export const namedDefault = { +}); +export const namedDefault = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]), \\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"]) -}; -export const eagerAs = { +}); +export const eagerAs = Object.assign({ \\"./modules/a.ts\\": __vite_glob_5_0, \\"./modules/b.ts\\": __vite_glob_5_1 -}; -export const rawImportModule = { +}); +export const rawImportModule = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\") -}; -export const excludeSelf = { +}); +export const excludeSelf = Object.assign({ \\"./sibling.ts\\": () => import(\\"./sibling.ts\\") -}; -export const customQueryString = { +}); +export const customQueryString = Object.assign({ \\"./sibling.ts\\": () => import(\\"./sibling.ts?custom\\") -}; -export const customQueryObject = { +}); +export const customQueryObject = Object.assign({ \\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true\\") -}; -export const parent = { +}); +export const parent = Object.assign({ -}; -export const rootMixedRelative = { +}); +export const rootMixedRelative = Object.assign({ \\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url\\").then(m => m[\\"default\\"]), \\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url\\").then(m => m[\\"default\\"]), \\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url\\").then(m => m[\\"default\\"]), \\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url\\").then(m => m[\\"default\\"]), \\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url\\").then(m => m[\\"default\\"]), \\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url\\").then(m => m[\\"default\\"]) -}; -export const cleverCwd1 = { +}); +export const cleverCwd1 = Object.assign({ \\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\") -}; -export const cleverCwd2 = { +}); +export const cleverCwd2 = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"), \\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"), \\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\") -}; +}); " `; @@ -84,79 +84,79 @@ import { name as __vite_glob_3_2 } from \\"./modules/index.ts\\" import { default as __vite_glob_5_0 } from \\"./modules/a.ts?raw\\" import { default as __vite_glob_5_1 } from \\"./modules/b.ts?raw\\" import \\"../../../../../../types/importMeta\\"; -export const basic = { +export const basic = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"), \\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\") -}; -export const basicEager = { +}); +export const basicEager = Object.assign({ \\"./modules/a.ts\\": __vite_glob_1_0, \\"./modules/b.ts\\": __vite_glob_1_1, \\"./modules/index.ts\\": __vite_glob_1_2 -}; -export const ignore = { +}); +export const ignore = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\") -}; -export const namedEager = { +}); +export const namedEager = Object.assign({ \\"./modules/a.ts\\": __vite_glob_3_0, \\"./modules/b.ts\\": __vite_glob_3_1, \\"./modules/index.ts\\": __vite_glob_3_2 -}; -export const namedDefault = { +}); +export const namedDefault = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]), \\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"]) -}; -export const eagerAs = { +}); +export const eagerAs = Object.assign({ \\"./modules/a.ts\\": __vite_glob_5_0, \\"./modules/b.ts\\": __vite_glob_5_1 -}; -export const rawImportModule = { +}); +export const rawImportModule = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\") -}; -export const excludeSelf = { +}); +export const excludeSelf = Object.assign({ \\"./sibling.ts\\": () => import(\\"./sibling.ts\\") -}; -export const customQueryString = { +}); +export const customQueryString = Object.assign({ \\"./sibling.ts\\": () => import(\\"./sibling.ts?custom&lang.ts\\") -}; -export const customQueryObject = { +}); +export const customQueryObject = Object.assign({ \\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true&lang.ts\\") -}; -export const parent = { +}); +export const parent = Object.assign({ -}; -export const rootMixedRelative = { +}); +export const rootMixedRelative = Object.assign({ \\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]), \\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]), \\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]), \\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url&lang.ts\\").then(m => m[\\"default\\"]), \\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url&lang.ts\\").then(m => m[\\"default\\"]), \\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url&lang.ts\\").then(m => m[\\"default\\"]) -}; -export const cleverCwd1 = { +}); +export const cleverCwd1 = Object.assign({ \\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\") -}; -export const cleverCwd2 = { +}); +export const cleverCwd2 = Object.assign({ \\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"), \\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"), \\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"), \\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\") -}; +}); " `; exports[`fixture > virtual modules 1`] = ` -"{ +"Object.assign({ \\"/modules/a.ts\\": () => import(\\"/modules/a.ts\\"), \\"/modules/b.ts\\": () => import(\\"/modules/b.ts\\"), \\"/modules/index.ts\\": () => import(\\"/modules/index.ts\\") -} -{ +}) +Object.assign({ \\"/../fixture-b/a.ts\\": () => import(\\"/../fixture-b/a.ts\\"), \\"/../fixture-b/b.ts\\": () => import(\\"/../fixture-b/b.ts\\"), \\"/../fixture-b/index.ts\\": () => import(\\"/../fixture-b/index.ts\\") -}" +})" `; diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index ed46e35bea8ecf..140eb6ca6d1273 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -398,7 +398,7 @@ export async function transformGlobImport( files.forEach((i) => matchedFiles.add(i)) - const replacement = `{\n${objectProps.join(',\n')}\n}` + const replacement = `Object.assign({\n${objectProps.join(',\n')}\n})` s.overwrite(start, end, replacement) return staticImports diff --git a/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts index d738ccec1d4c97..8cc5c61d172236 100644 --- a/playground/glob-import/__tests__/glob-import.spec.ts +++ b/playground/glob-import/__tests__/glob-import.spec.ts @@ -31,6 +31,12 @@ const json = isBuild msg: 'baz' } +const globWithAlias = { + '/dir/alias.js': { + default: 'hi' + } +} + const allResult = { // JSON file should be properly transformed '/dir/alias.js': { @@ -40,14 +46,15 @@ const allResult = { '/dir/foo.js': { msg: 'foo' }, - '/dir/index.js': { - globWithAlias: { - '/dir/alias.js': { - default: 'hi' + '/dir/index.js': isBuild + ? { + modules: filteredResult, + globWithAlias } - }, - modules: filteredResult - }, + : { + globWithAlias, + modules: filteredResult + }, '/dir/nested/bar.js': { modules: { '../baz.json': json @@ -93,6 +100,12 @@ test('import relative glob raw', async () => { ) }) +test('unassigned import processes', async () => { + expect(await page.textContent('.side-effect-result')).toBe( + 'Hello from side effect' + ) +}) + if (!isBuild) { test('hmr for adding/removing files', async () => { addFile('dir/a.js', '') diff --git a/playground/glob-import/index.html b/playground/glob-import/index.html index 8466a6d0495881..6cff2aa0965c59 100644 --- a/playground/glob-import/index.html +++ b/playground/glob-import/index.html @@ -2,6 +2,7 @@

 

 

+

 
 
 
+
+
diff --git a/playground/glob-import/side-effect/writedom.js b/playground/glob-import/side-effect/writedom.js
new file mode 100644
index 00000000000000..e2ab04ba7f5cbe
--- /dev/null
+++ b/playground/glob-import/side-effect/writedom.js
@@ -0,0 +1,4 @@
+/* global document */
+document &&
+  (document.querySelector('.side-effect-result').textContent =
+    'Hello from side effect')

From 8148f67f4a78265ca666737b15709c3c7578e370 Mon Sep 17 00:00:00 2001
From: Anthony Fu 
Date: Wed, 11 May 2022 14:33:20 +0800
Subject: [PATCH 100/114] test: migrate to vitest (#8076)

---
 .eslintrc.cjs                                 |    9 +-
 .github/workflows/ci.yml                      |    4 +-
 CONTRIBUTING.md                               |   12 +-
 jest.config.ts                                |   24 -
 package.json                                  |   15 +-
 .../src/node/__tests__/plugins/css.spec.ts    |   38 +-
 packages/vite/src/node/server/index.ts        |    2 +-
 packages/vite/src/node/ssr/ssrModuleLoader.ts |    1 +
 packages/vite/src/node/utils.ts               |    2 +
 playground/assets/__tests__/assets.spec.ts    |  100 +-
 .../__tests__/backend-integration.spec.ts     |   47 +-
 .../__tests__/{serve.js => serve.ts}          |   23 +-
 .../cli/__tests__/{serve.js => serve.ts}      |   21 +-
 .../__tests__/css-codesplit.spec.ts           |    4 +-
 .../__tests__/css-codesplit.spec.ts           |    4 +-
 .../css-sourcemap/__tests__/build.spec.ts     |   16 +-
 .../css-sourcemap/__tests__/serve.spec.ts     |   54 +-
 playground/css/__tests__/css.spec.ts          |   12 +-
 .../data-uri/__tests__/data-uri.spec.ts       |   10 +-
 playground/define/__tests__/define.spec.ts    |    1 +
 .../env-nested/__tests__/env-nested.spec.ts   |    2 +-
 playground/env/__tests__/env.spec.ts          |    2 +-
 .../__tests__/file-delete-restore.spec.ts     |   17 +-
 .../fs-serve/__tests__/fs-serve.spec.ts       |  102 +-
 playground/hmr/tsconfig.json                  |    2 +-
 playground/html/__tests__/html.spec.ts        |   56 +-
 .../js-sourcemap/__tests__/build.spec.ts      |   16 +-
 .../js-sourcemap/__tests__/serve.spec.ts      |    8 +-
 playground/legacy/__tests__/legacy.spec.ts    |    4 +-
 .../legacy/__tests__/ssr/legacy-ssr.spec.ts   |    8 +-
 .../__tests__/ssr/{serve.js => serve.ts}      |   15 +-
 playground/lib/__tests__/lib.spec.ts          |   20 +-
 .../lib/__tests__/{serve.js => serve.ts}      |   28 +-
 .../__test__/optimize-missing-deps.spec.ts    |    8 +-
 .../__test__/serve.ts}                        |   15 +-
 playground/preload/__tests__/preload.spec.ts  |    4 +-
 .../{vite.config.js => vite.config.ts}        |    7 +-
 playground/react/__tests__/react.spec.ts      |   41 +-
 .../__tests__/resolve-config.spec.ts          |   10 +-
 .../__tests__/{serve.js => serve.ts}          |   15 +-
 .../ssr-deps/__tests__/{serve.js => serve.ts} |   15 +-
 .../ssr-html/__tests__/{serve.js => serve.ts} |   15 +-
 .../serve.js => ssr-pug/__tests__/serve.ts}   |   15 +-
 .../__tests__/{serve.js => serve.ts}          |   15 +-
 .../ssr-vue/__tests__/{serve.js => serve.ts}  |   15 +-
 playground/ssr-vue/__tests__/ssr-vue.spec.ts  |   30 +-
 .../__tests__/{serve.js => serve.ts}          |   15 +-
 playground/ssr-webworker/worker.js            |    8 +-
 .../__tests__/build.spec.ts                   |   16 +-
 .../__tests__/serve.spec.ts                   |   16 +-
 playground/testUtils.ts                       |   34 +-
 .../tsconfig-json-load-error.spec.ts          |   16 +-
 playground/tsconfig.json                      |    2 +-
 playground/vue-jsx/__tests__/vue-jsx.spec.ts  |    6 +-
 playground/vue-lib/__tests__/serve.js         |    7 -
 playground/vue-lib/__tests__/serve.ts         |    6 +
 .../vue-sourcemap/__tests__/build.spec.ts     |   16 +-
 .../vue-sourcemap/__tests__/serve.spec.ts     |   78 +-
 .../{vite.config.js => vite.config.ts}        |   10 +-
 playground/vue/__tests__/vue.spec.ts          |    8 +-
 .../worker/__tests__/es/es-worker.spec.ts     |    8 +-
 .../worker/__tests__/iife/worker.spec.ts      |    9 +-
 .../sourcemap-hidden-worker.spec.ts           |   19 +-
 .../sourcemap-inline-worker.spec.ts           |   19 +-
 .../sourcemap/sourcemap-worker.spec.ts        |   15 +-
 pnpm-lock.yaml                                | 1653 +----------------
 scripts/jestEnv.cjs                           |   48 -
 scripts/jestGlobalTeardown.cjs                |    9 -
 scripts/tsconfig.json                         |    2 +-
 ...stGlobalSetup.cjs => vitestGlobalSetup.ts} |   30 +-
 .../{jestPerTestSetup.ts => vitestSetup.ts}   |   82 +-
 vitest.config.e2e.ts                          |   21 +
 72 files changed, 714 insertions(+), 2323 deletions(-)
 delete mode 100644 jest.config.ts
 rename playground/cli-module/__tests__/{serve.js => serve.ts} (90%)
 rename playground/cli/__tests__/{serve.js => serve.ts} (91%)
 rename playground/legacy/__tests__/ssr/{serve.js => serve.ts} (72%)
 rename playground/lib/__tests__/{serve.js => serve.ts} (81%)
 rename playground/{ssr-pug/__tests__/serve.js => optimize-missing-deps/__test__/serve.ts} (64%)
 rename playground/preload/{vite.config.js => vite.config.ts} (62%)
 rename playground/resolve-config/__tests__/{serve.js => serve.ts} (71%)
 rename playground/ssr-deps/__tests__/{serve.js => serve.ts} (64%)
 rename playground/ssr-html/__tests__/{serve.js => serve.ts} (64%)
 rename playground/{optimize-missing-deps/__test__/serve.js => ssr-pug/__tests__/serve.ts} (63%)
 rename playground/ssr-react/__tests__/{serve.js => serve.ts} (77%)
 rename playground/ssr-vue/__tests__/{serve.js => serve.ts} (77%)
 rename playground/ssr-webworker/__tests__/{serve.js => serve.ts} (72%)
 delete mode 100644 playground/vue-lib/__tests__/serve.js
 create mode 100644 playground/vue-lib/__tests__/serve.ts
 rename playground/vue-sourcemap/{vite.config.js => vite.config.ts} (62%)
 delete mode 100644 scripts/jestEnv.cjs
 delete mode 100644 scripts/jestGlobalTeardown.cjs
 rename scripts/{jestGlobalSetup.cjs => vitestGlobalSetup.ts} (62%)
 rename scripts/{jestPerTestSetup.ts => vitestSetup.ts} (80%)
 create mode 100644 vitest.config.e2e.ts

diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index beab59a2df5ac9..63a8d282ba9b25 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -29,14 +29,7 @@ module.exports = defineConfig({
     'node/no-missing-import': [
       'error',
       {
-        allowModules: [
-          'types',
-          'estree',
-          'testUtils',
-          'less',
-          'sass',
-          'stylus'
-        ],
+        allowModules: ['types', 'estree', 'less', 'sass', 'stylus'],
         tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts']
       }
     ],
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b1c663db40e80f..ce695749544b39 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -72,10 +72,10 @@ jobs:
         run: pnpm run test-unit
 
       - name: Test serve
-        run: pnpm run test-serve -- --runInBand
+        run: pnpm run test-serve
 
       - name: Test build
-        run: pnpm run test-build -- --runInBand
+        run: pnpm run test-build
 
   lint:
     timeout-minutes: 10
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e620377c75408f..334d3cb8b79e8c 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -30,11 +30,11 @@ If you want to use break point and explore code execution you can use the ["Run
 
 5. The execution will stop and you'll use the [Debug toolbar](https://code.visualstudio.com/docs/editor/debugging#_debug-actions) to continue, step over, restart the process...
 
-### Debugging errors in Jest tests using Playwright (Chromium)
+### Debugging errors in Vitest tests using Playwright (Chromium)
 
-Some errors are masked and hidden away because of the layers of abstraction and sandboxed nature added by Jest, Playwright, and Chromium. In order to see what's actually going wrong and the contents of the devtools console in those instances, follow this setup:
+Some errors are masked and hidden away because of the layers of abstraction and sandboxed nature added by Vitest, Playwright, and Chromium. In order to see what's actually going wrong and the contents of the devtools console in those instances, follow this setup:
 
-1. Add a `debugger` statement to the `scripts/jestPerTestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits.
+1. Add a `debugger` statement to the `scripts/vitestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits.
 
 1. Run the tests with the `debug-serve` script command which will enable remote debugging: `pnpm run debug-serve -- --runInBand resolve`.
 
@@ -69,7 +69,7 @@ And re-run `pnpm install` to link the package.
 
 ### Integration Tests
 
-Each package under `playground/` contains a `__tests__` directory. The tests are run using [Jest](https://jestjs.io/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `jest.config.js` and `scripts/jest*` files.
+Each package under `playground/` contains a `__tests__` directory. The tests are run using [Vitest](https://vitest.dev/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `vitest.config.e2e.js` and `scripts/vitest*` files.
 
 Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). Also you may want to [set git `core.symlinks` to `true` to solve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242).
 
@@ -77,7 +77,7 @@ Each integration test can be run under either dev server mode or build mode.
 
 - `pnpm test` by default runs every integration test in both serve and build mode, and also unit tests.
 
-- `pnpm run test-serve` runs tests only under serve mode. This is just calling `jest` so you can pass any Jest flags to this command. Since Jest will attempt to run tests in parallel, if your machine has many cores this may cause flaky test failures with multiple Playwright instances running at the same time. You can force the tests to run in series with `pnpm run test-serve -- --runInBand`.
+- `pnpm run test-serve` runs tests only under serve mode.
 
 - `pnpm run test-build` runs tests only under build mode.
 
@@ -105,7 +105,7 @@ test('should work', async () => {
 
 Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `playground/testUtils.ts`.
 
-Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/9c6501d9c363eaa3c1e7708d531fb2a92b633db6/scripts/jestPerTestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build.
+Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/9c6501d9c363eaa3c1e7708d531fb2a92b633db6/scripts/vitestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build.
 
 ### Extending the Test Suite
 
diff --git a/jest.config.ts b/jest.config.ts
deleted file mode 100644
index 719d67f39b8bce..00000000000000
--- a/jest.config.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-// eslint-disable-next-line node/no-extraneous-import
-import type { Config } from '@jest/types'
-
-const config: Config.InitialOptions = {
-  preset: 'ts-jest',
-  testMatch: ['**/playground/**/*.spec.[jt]s?(x)'],
-  testTimeout: process.env.CI ? 50000 : 20000,
-  globalSetup: './scripts/jestGlobalSetup.cjs',
-  globalTeardown: './scripts/jestGlobalTeardown.cjs',
-  testEnvironment: './scripts/jestEnv.cjs',
-  setupFilesAfterEnv: ['./scripts/jestPerTestSetup.ts'],
-  watchPathIgnorePatterns: ['/playground-temp'],
-  modulePathIgnorePatterns: ['/playground-temp'],
-  moduleNameMapper: {
-    testUtils: '/playground/testUtils.ts'
-  },
-  globals: {
-    'ts-jest': {
-      tsconfig: './playground/tsconfig.json'
-    }
-  }
-}
-
-export default config
diff --git a/package.json b/package.json
index 1ba4ca2cec68dc..62a66770cb750a 100644
--- a/package.json
+++ b/package.json
@@ -17,11 +17,11 @@
     "format": "prettier --write .",
     "lint": "eslint packages/*/{src,types}/**",
     "test": "run-s test-unit test-serve test-build",
-    "test-serve": "jest",
-    "test-build": "cross-env VITE_TEST_BUILD=1 jest",
+    "test-serve": "vitest run -c vitest.config.e2e.ts",
+    "test-build": "cross-env VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts",
     "test-unit": "vitest run",
-    "debug-serve": "cross-env VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest",
-    "debug-build": "cross-env VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 node --inspect-brk ./node_modules/.bin/jest",
+    "debug-serve": "cross-env VITE_DEBUG_SERVE=1 vitest run -c vitest.config.e2e.ts",
+    "debug-build": "cross-env VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 vitest run -c vitest.config.e2e.ts",
     "docs": "vitepress dev docs",
     "build-docs": "vitepress build docs",
     "serve-docs": "vitepress serve docs",
@@ -36,8 +36,8 @@
   },
   "devDependencies": {
     "@microsoft/api-extractor": "^7.23.1",
+    "@types/babel__core": "^7.1.19",
     "@types/fs-extra": "^9.0.13",
-    "@types/jest": "^27.5.0",
     "@types/node": "^17.0.31",
     "@types/prompts": "^2.4.0",
     "@types/semver": "^7.3.9",
@@ -51,7 +51,7 @@
     "eslint-plugin-node": "^11.1.0",
     "execa": "^5.1.1",
     "fs-extra": "^10.1.0",
-    "jest": "^27.5.1",
+    "kill-port": "^1.6.1",
     "lint-staged": "^12.4.1",
     "minimist": "^1.2.6",
     "node-fetch": "^2.6.7",
@@ -65,12 +65,11 @@
     "semver": "^7.3.7",
     "simple-git-hooks": "^2.7.0",
     "sirv": "^2.0.2",
-    "ts-jest": "^27.1.4",
     "ts-node": "^10.7.0",
     "typescript": "^4.6.4",
     "vite": "workspace:*",
     "vitepress": "^0.22.4",
-    "vitest": "^0.10.5"
+    "vitest": "^0.12.4"
   },
   "simple-git-hooks": {
     "pre-commit": "pnpm exec lint-staged --concurrent false",
diff --git a/packages/vite/src/node/__tests__/plugins/css.spec.ts b/packages/vite/src/node/__tests__/plugins/css.spec.ts
index eeacaf482b0c31..70ddb640b13218 100644
--- a/packages/vite/src/node/__tests__/plugins/css.spec.ts
+++ b/packages/vite/src/node/__tests__/plugins/css.spec.ts
@@ -179,31 +179,29 @@ describe('hoist @ rules', () => {
 
   test('dont hoist @import and @charset in comments', async () => {
     const css = `
-      .foo{color:red;}
-      /*
-        @import "bla";
-      */
-      @charset "utf-8";
-      /*
-        @charset "utf-8";
-        @import "bar";
-      */
-      @import "baz";
-    `
+.foo{color:red;}
+/*
+  @import "bla";
+*/
+@charset "utf-8";
+/*
+  @charset "utf-8";
+  @import "bar";
+*/
+@import "baz";`
     const result = await hoistAtRules(css)
-    expect(result).toBe(
-      `@charset "utf-8";@import "baz";
+    expect(result).toMatchInlineSnapshot(`
+      "@charset \\"utf-8\\";@import \\"baz\\";
       .foo{color:red;}
       /*
-        @import "bla";
+        @import \\"bla\\";
       */
-      
+
       /*
-        @charset "utf-8";
-        @import "bar";
+        @charset \\"utf-8\\";
+        @import \\"bar\\";
       */
-      
-    `
-    )
+      "
+    `)
   })
 })
diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts
index 50ca05e17a748e..021fd8c25901b5 100644
--- a/packages/vite/src/node/server/index.ts
+++ b/packages/vite/src/node/server/index.ts
@@ -409,7 +409,7 @@ export async function createServer(
     try {
       await server.close()
     } finally {
-      process.exit(0)
+      process.exit()
     }
   }
 
diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts
index 9f75641c84e513..ba9589d8bbbf1f 100644
--- a/packages/vite/src/node/ssr/ssrModuleLoader.ts
+++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts
@@ -286,6 +286,7 @@ async function nodeImport(
       importer,
       // Non-external modules can import ESM-only modules, but only outside
       // of test runs, because we use Node `require` in Jest to avoid segfault.
+      // @ts-expect-error
       typeof jest === 'undefined'
         ? { ...resolveOptions, tryEsmOnly: true }
         : resolveOptions
diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts
index d84b474b87c33f..41b1073bb5b991 100644
--- a/packages/vite/src/node/utils.ts
+++ b/packages/vite/src/node/utils.ts
@@ -743,7 +743,9 @@ export const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm
 export const singlelineCommentsRE = /\/\/.*/g
 export const requestQuerySplitRE = /\?(?!.*[\/|\}])/
 
+// @ts-expect-error
 export const usingDynamicImport = typeof jest === 'undefined'
+
 /**
  * Dynamically import files. It will make sure it's not being compiled away by TS/Rollup.
  *
diff --git a/playground/assets/__tests__/assets.spec.ts b/playground/assets/__tests__/assets.spec.ts
index d9f1c8ed761773..96b4b4e1e434cf 100644
--- a/playground/assets/__tests__/assets.spec.ts
+++ b/playground/assets/__tests__/assets.spec.ts
@@ -175,11 +175,9 @@ describe('css url() references', () => {
     expect(bg).toMatch(assetMatch)
   })
 
-  if (isBuild) {
-    test('preserve postfix query/hash', () => {
-      expect(findAssetFile(/\.css$/, 'foo')).toMatch(`woff2?#iefix`)
-    })
-  }
+  test.runIf(isBuild)('preserve postfix query/hash', () => {
+    expect(findAssetFile(/\.css$/, 'foo')).toMatch(`woff2?#iefix`)
+  })
 })
 
 describe('image', () => {
@@ -254,17 +252,13 @@ describe('unicode url', () => {
   })
 })
 
-describe('encodeURI', () => {
-  if (isBuild) {
-    test('img src with encodeURI', async () => {
-      const img = await page.$('.encodeURI')
-      expect(
-        await (
-          await img.getAttribute('src')
-        ).startsWith('data:image/png;base64')
-      ).toBe(true)
-    })
-  }
+describe.runIf(isBuild)('encodeURI', () => {
+  test('img src with encodeURI', async () => {
+    const img = await page.$('.encodeURI')
+    expect(
+      await (await img.getAttribute('src')).startsWith('data:image/png;base64')
+    ).toBe(true)
+  })
 })
 
 test('new URL(..., import.meta.url)', async () => {
@@ -286,51 +280,43 @@ test('new URL(`non-existent`, import.meta.url)', async () => {
   )
 })
 
-if (isBuild) {
-  test('manifest', async () => {
-    const manifest = readManifest('foo')
-    const entry = manifest['index.html']
-
-    for (const file of listAssets('foo')) {
-      if (file.endsWith('.css')) {
-        expect(entry.css).toContain(`assets/${file}`)
-      } else if (!file.endsWith('.js')) {
-        expect(entry.assets).toContain(`assets/${file}`)
-      }
+test.runIf(isBuild)('manifest', async () => {
+  const manifest = readManifest('foo')
+  const entry = manifest['index.html']
+
+  for (const file of listAssets('foo')) {
+    if (file.endsWith('.css')) {
+      expect(entry.css).toContain(`assets/${file}`)
+    } else if (!file.endsWith('.js')) {
+      expect(entry.assets).toContain(`assets/${file}`)
     }
-  })
-}
+  }
+})
 
-describe('css and assets in css in build watch', () => {
-  if (isBuild) {
-    test('css will not be lost and css does not contain undefined', async () => {
-      editFile('index.html', (code) => code.replace('Assets', 'assets'), true)
-      await notifyRebuildComplete(watcher)
-      const cssFile = findAssetFile(/index\.\w+\.css$/, 'foo')
-      expect(cssFile).not.toBe('')
-      expect(cssFile).not.toMatch(/undefined/)
-    })
+describe.runIf(isBuild)('css and assets in css in build watch', () => {
+  test('css will not be lost and css does not contain undefined', async () => {
+    editFile('index.html', (code) => code.replace('Assets', 'assets'), true)
+    await notifyRebuildComplete(watcher)
+    const cssFile = findAssetFile(/index\.\w+\.css$/, 'foo')
+    expect(cssFile).not.toBe('')
+    expect(cssFile).not.toMatch(/undefined/)
+  })
 
-    test('import module.css', async () => {
-      expect(await getColor('#foo')).toBe('red')
-      editFile(
-        'css/foo.module.css',
-        (code) => code.replace('red', 'blue'),
-        true
-      )
-      await notifyRebuildComplete(watcher)
-      await page.reload()
-      expect(await getColor('#foo')).toBe('blue')
-    })
+  test('import module.css', async () => {
+    expect(await getColor('#foo')).toBe('red')
+    editFile('css/foo.module.css', (code) => code.replace('red', 'blue'), true)
+    await notifyRebuildComplete(watcher)
+    await page.reload()
+    expect(await getColor('#foo')).toBe('blue')
+  })
 
-    test('import with raw query', async () => {
-      expect(await page.textContent('.raw-query')).toBe('foo')
-      editFile('static/foo.txt', (code) => code.replace('foo', 'zoo'), true)
-      await notifyRebuildComplete(watcher)
-      await page.reload()
-      expect(await page.textContent('.raw-query')).toBe('zoo')
-    })
-  }
+  test('import with raw query', async () => {
+    expect(await page.textContent('.raw-query')).toBe('foo')
+    editFile('static/foo.txt', (code) => code.replace('foo', 'zoo'), true)
+    await notifyRebuildComplete(watcher)
+    await page.reload()
+    expect(await page.textContent('.raw-query')).toBe('zoo')
+  })
 })
 
 test('inline style test', async () => {
diff --git a/playground/backend-integration/__tests__/backend-integration.spec.ts b/playground/backend-integration/__tests__/backend-integration.spec.ts
index 7eebc9c27ff05a..4677700f6e8c12 100644
--- a/playground/backend-integration/__tests__/backend-integration.spec.ts
+++ b/playground/backend-integration/__tests__/backend-integration.spec.ts
@@ -2,6 +2,7 @@ import {
   editFile,
   getColor,
   isBuild,
+  isServe,
   readManifest,
   untilUpdated
 } from '../../testUtils'
@@ -24,42 +25,42 @@ describe('asset imports from js', () => {
   })
 })
 
-if (isBuild) {
+describe.runIf(isBuild)('build', () => {
   test('manifest', async () => {
     const manifest = readManifest('dev')
     const htmlEntry = manifest['index.html']
     expect(htmlEntry.css.length).toEqual(1)
     expect(htmlEntry.assets.length).toEqual(1)
   })
-} else {
+})
+
+describe.runIf(isServe)('serve', () => {
   test('No ReferenceError', async () => {
     browserErrors.forEach((error) => {
       expect(error.name).not.toBe('ReferenceError')
     })
   })
 
-  describe('CSS HMR', () => {
-    test('preserve the base in CSS HMR', async () => {
-      await untilUpdated(() => getColor('body'), 'black') // sanity check
-      editFile('frontend/entrypoints/global.css', (code) =>
-        code.replace('black', 'red')
-      )
-      await untilUpdated(() => getColor('body'), 'red') // successful HMR
+  test('preserve the base in CSS HMR', async () => {
+    await untilUpdated(() => getColor('body'), 'black') // sanity check
+    editFile('frontend/entrypoints/global.css', (code) =>
+      code.replace('black', 'red')
+    )
+    await untilUpdated(() => getColor('body'), 'red') // successful HMR
 
-      // Verify that the base (/dev/) was added during the css-update
-      const link = await page.$('link[rel="stylesheet"]')
-      expect(await link.getAttribute('href')).toContain('/dev/global.css?t=')
-    })
+    // Verify that the base (/dev/) was added during the css-update
+    const link = await page.$('link[rel="stylesheet"]')
+    expect(await link.getAttribute('href')).toContain('/dev/global.css?t=')
+  })
 
-    test('CSS dependencies are tracked for HMR', async () => {
-      const el = await page.$('h1')
-      browserLogs.length = 0
+  test('CSS dependencies are tracked for HMR', async () => {
+    const el = await page.$('h1')
+    browserLogs.length = 0
 
-      editFile('frontend/entrypoints/main.ts', (code) =>
-        code.replace('text-black', 'text-[rgb(204,0,0)]')
-      )
-      await untilUpdated(() => getColor(el), 'rgb(204, 0, 0)')
-      expect(browserLogs).toContain('[vite] css hot updated: /global.css')
-    })
+    editFile('frontend/entrypoints/main.ts', (code) =>
+      code.replace('text-black', 'text-[rgb(204,0,0)]')
+    )
+    await untilUpdated(() => getColor(el), 'rgb(204, 0, 0)')
+    expect(browserLogs).toContain('[vite] css hot updated: /global.css')
   })
-}
+})
diff --git a/playground/cli-module/__tests__/serve.js b/playground/cli-module/__tests__/serve.ts
similarity index 90%
rename from playground/cli-module/__tests__/serve.js
rename to playground/cli-module/__tests__/serve.ts
index cf873fd481830b..874c81715021d1 100644
--- a/playground/cli-module/__tests__/serve.js
+++ b/playground/cli-module/__tests__/serve.ts
@@ -1,21 +1,16 @@
-// @ts-check
-// this is automtically detected by scripts/jestPerTestSetup.ts and will replace
+// this is automatically detected by scripts/vitestSetup.ts and will replace
 // the default e2e test serve behavior
 
-const path = require('path')
-// eslint-disable-next-line node/no-restricted-require
-const execa = require('execa')
-const { workspaceRoot, ports } = require('../../testUtils')
+import path from 'path'
+import execa from 'execa'
+import { workspaceRoot, ports } from '../../testUtils'
+import kill from 'kill-port'
 
 const isWindows = process.platform === 'win32'
-const port = (exports.port = ports['cli-module'])
+export const port = ports['cli-module']
 const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js')
 
-/**
- * @param {string} root
- * @param {boolean} isProd
- */
-exports.serve = async function serve(root, isProd) {
+export async function serve(root: string, isProd: boolean) {
   // collect stdout and stderr streams from child processes here to avoid interfering with regular jest output
   const streams = {
     build: { out: [], err: [] },
@@ -60,6 +55,8 @@ exports.serve = async function serve(root, isProd) {
     }
   }
 
+  await kill(port)
+
   // run `vite --port x` or `vite preview --port x` to start server
   const viteServerArgs = ['--port', `${port}`, '--strict-port']
   if (isProd) {
@@ -113,7 +110,7 @@ exports.serve = async function serve(root, isProd) {
 // helper to validate that server was started on the correct port
 async function startedOnPort(serverProcess, port, timeout) {
   let checkPort
-  const startedPromise = new Promise((resolve, reject) => {
+  const startedPromise = new Promise((resolve, reject) => {
     checkPort = (data) => {
       const str = data.toString()
       // hack, console output may contain color code gibberish
diff --git a/playground/cli/__tests__/serve.js b/playground/cli/__tests__/serve.ts
similarity index 91%
rename from playground/cli/__tests__/serve.js
rename to playground/cli/__tests__/serve.ts
index 3ad375d9d1f543..913a4d5b565c73 100644
--- a/playground/cli/__tests__/serve.js
+++ b/playground/cli/__tests__/serve.ts
@@ -1,21 +1,16 @@
-// @ts-check
-// this is automtically detected by scripts/jestPerTestSetup.ts and will replace
+// this is automatically detected by scripts/vitestSetup.ts and will replace
 // the default e2e test serve behavior
 
-const path = require('path')
-// eslint-disable-next-line node/no-restricted-require
-const execa = require('execa')
-const { workspaceRoot, ports } = require('../../testUtils')
+import path from 'path'
+import execa from 'execa'
+import { workspaceRoot, ports } from '../../testUtils'
+import kill from 'kill-port'
 
 const isWindows = process.platform === 'win32'
 const port = (exports.port = ports.cli)
 const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js')
 
-/**
- * @param {string} root
- * @param {boolean} isProd
- */
-exports.serve = async function serve(root, isProd) {
+export async function serve(root: string, isProd: boolean) {
   // collect stdout and stderr streams from child processes here to avoid interfering with regular jest output
   const streams = {
     build: { out: [], err: [] },
@@ -60,6 +55,8 @@ exports.serve = async function serve(root, isProd) {
     }
   }
 
+  await kill(port)
+
   // run `vite --port x` or `vite preview --port x` to start server
   const viteServerArgs = ['--port', `${port}`, '--strict-port']
   if (isProd) {
@@ -113,7 +110,7 @@ exports.serve = async function serve(root, isProd) {
 // helper to validate that server was started on the correct port
 async function startedOnPort(serverProcess, port, timeout) {
   let checkPort
-  const startedPromise = new Promise((resolve, reject) => {
+  const startedPromise = new Promise((resolve, reject) => {
     checkPort = (data) => {
       const str = data.toString()
       // hack, console output may contain color code gibberish
diff --git a/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts b/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts
index 95fe97a1b953ba..dae8d5f4b4ca5e 100644
--- a/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts
+++ b/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts
@@ -5,7 +5,7 @@ test('should load both stylesheets', async () => {
   expect(await getColor('h2')).toBe('blue')
 })
 
-if (isBuild) {
+describe.runIf(isBuild)('build', () => {
   test('should remove empty chunk', async () => {
     expect(findAssetFile(/style.*\.js$/)).toBe('')
     expect(findAssetFile('main.*.js$')).toMatch(`/* empty css`)
@@ -17,4 +17,4 @@ if (isBuild) {
     expect(manifest['index.html'].css.length).toBe(2)
     expect(manifest['other.js'].css.length).toBe(1)
   })
-}
+})
diff --git a/playground/css-codesplit/__tests__/css-codesplit.spec.ts b/playground/css-codesplit/__tests__/css-codesplit.spec.ts
index 789adba23ae021..820222e9a964d2 100644
--- a/playground/css-codesplit/__tests__/css-codesplit.spec.ts
+++ b/playground/css-codesplit/__tests__/css-codesplit.spec.ts
@@ -20,7 +20,7 @@ test('should load dynamic import with module', async () => {
   expect(await getColor('.mod')).toBe('yellow')
 })
 
-if (isBuild) {
+describe.runIf(isBuild)('build', () => {
   test('should remove empty chunk', async () => {
     expect(findAssetFile(/style.*\.js$/)).toBe('')
     expect(findAssetFile('main.*.js$')).toMatch(`/* empty css`)
@@ -33,4 +33,4 @@ if (isBuild) {
     expect(manifest['index.html'].css.length).toBe(2)
     expect(manifest['other.js'].css.length).toBe(1)
   })
-}
+})
diff --git a/playground/css-sourcemap/__tests__/build.spec.ts b/playground/css-sourcemap/__tests__/build.spec.ts
index e36c1f52d2c1f8..50b8814aed9c4e 100644
--- a/playground/css-sourcemap/__tests__/build.spec.ts
+++ b/playground/css-sourcemap/__tests__/build.spec.ts
@@ -1,13 +1,7 @@
-import { isBuild } from 'testUtils'
+import { isBuild } from '../../testUtils'
 
-if (isBuild) {
-  test('should not output sourcemap warning (#4939)', () => {
-    serverLogs.forEach((log) => {
-      expect(log).not.toMatch('Sourcemap is likely to be incorrect')
-    })
+test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => {
+  serverLogs.forEach((log) => {
+    expect(log).not.toMatch('Sourcemap is likely to be incorrect')
   })
-} else {
-  test('this file only includes test for build', () => {
-    expect(true).toBe(true)
-  })
-}
+})
diff --git a/playground/css-sourcemap/__tests__/serve.spec.ts b/playground/css-sourcemap/__tests__/serve.spec.ts
index becd792e82293a..34a627b68df736 100644
--- a/playground/css-sourcemap/__tests__/serve.spec.ts
+++ b/playground/css-sourcemap/__tests__/serve.spec.ts
@@ -2,10 +2,10 @@ import { URL } from 'url'
 import {
   extractSourcemap,
   formatSourcemapForSnapshot,
-  isBuild
-} from 'testUtils'
+  isServe
+} from '../../testUtils'
 
-if (!isBuild) {
+describe.runIf(isServe)('serve', () => {
   const getStyleTagContentIncluding = async (content: string) => {
     const styles = await page.$$('style')
     for (const style of styles) {
@@ -43,13 +43,13 @@ if (!isBuild) {
     const css = await res.text()
     const map = extractSourcemap(css)
     expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
-      Object {
+      {
         "mappings": "AAAA;EACE,UAAU;AACZ;;ACAA;EACE,UAAU;AACZ",
-        "sources": Array [
+        "sources": [
           "/root/be-imported.css",
           "/root/linked-with-import.css",
         ],
-        "sourcesContent": Array [
+        "sourcesContent": [
           ".be-imported {
         color: red;
       }
@@ -70,12 +70,12 @@ if (!isBuild) {
     const css = await getStyleTagContentIncluding('.imported ')
     const map = extractSourcemap(css)
     expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
-      Object {
+      {
         "mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACX,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;",
-        "sources": Array [
+        "sources": [
           "/root/imported.css",
         ],
-        "sourcesContent": Array [
+        "sourcesContent": [
           ".imported {
         color: red;
       }
@@ -90,13 +90,13 @@ if (!isBuild) {
     const css = await getStyleTagContentIncluding('.imported-with-import ')
     const map = extractSourcemap(css)
     expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
-      Object {
+      {
         "mappings": "AAAA;EACE,UAAU;AACZ;;ACAA;EACE,UAAU;AACZ",
-        "sources": Array [
+        "sources": [
           "/root/be-imported.css",
           "/root/imported-with-import.css",
         ],
-        "sourcesContent": Array [
+        "sourcesContent": [
           ".be-imported {
         color: red;
       }
@@ -117,12 +117,12 @@ if (!isBuild) {
     const css = await getStyleTagContentIncluding('.imported-sass ')
     const map = extractSourcemap(css)
     expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
-      Object {
+      {
         "mappings": "AACE;EACE",
-        "sources": Array [
+        "sources": [
           "/root/imported.sass",
         ],
-        "sourcesContent": Array [
+        "sourcesContent": [
           ".imported
         &-sass
           color: red
@@ -137,12 +137,12 @@ if (!isBuild) {
     const css = await getStyleTagContentIncluding('._imported-sass-module_')
     const map = extractSourcemap(css)
     expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
-      Object {
+      {
         "mappings": "AACE;EACE",
-        "sources": Array [
+        "sources": [
           "/root/imported.module.sass",
         ],
-        "sourcesContent": Array [
+        "sourcesContent": [
           ".imported
         &-sass-module
           color: red
@@ -157,12 +157,12 @@ if (!isBuild) {
     const css = await getStyleTagContentIncluding('.imported-less ')
     const map = extractSourcemap(css)
     expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
-      Object {
+      {
         "mappings": "AACE;EACE",
-        "sources": Array [
+        "sources": [
           "/root/imported.less",
         ],
-        "sourcesContent": Array [
+        "sourcesContent": [
           ".imported {
         &-less {
           color: @color;
@@ -179,12 +179,12 @@ if (!isBuild) {
     const css = await getStyleTagContentIncluding('.imported-stylus ')
     const map = extractSourcemap(css)
     expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
-      Object {
+      {
         "mappings": "AACE;EACE,cAAM",
-        "sources": Array [
+        "sources": [
           "/root/imported.styl",
         ],
-        "sourcesContent": Array [
+        "sourcesContent": [
           ".imported
         &-stylus
           color blue-red-mixed
@@ -200,8 +200,4 @@ if (!isBuild) {
       expect(log).not.toMatch(/Sourcemap for .+ points to missing source files/)
     })
   })
-} else {
-  test('this file only includes test for serve', () => {
-    expect(true).toBe(true)
-  })
-}
+})
diff --git a/playground/css/__tests__/css.spec.ts b/playground/css/__tests__/css.spec.ts
index e666ca40517d57..3443597816f2d1 100644
--- a/playground/css/__tests__/css.spec.ts
+++ b/playground/css/__tests__/css.spec.ts
@@ -251,14 +251,12 @@ test('inline css modules', async () => {
   expect(css).toMatch(/\.inline-module__apply-color-inline___[\w-]{5}/)
 })
 
-if (isBuild) {
-  test('@charset hoist', async () => {
-    serverLogs.forEach((log) => {
-      // no warning from esbuild css minifier
-      expect(log).not.toMatch('"@charset" must be the first rule in the file')
-    })
+test.runIf(isBuild)('@charset hoist', async () => {
+  serverLogs.forEach((log) => {
+    // no warning from esbuild css minifier
+    expect(log).not.toMatch('"@charset" must be the first rule in the file')
   })
-}
+})
 
 test('@import dependency w/ style entry', async () => {
   expect(await getColor('.css-dep')).toBe('purple')
diff --git a/playground/data-uri/__tests__/data-uri.spec.ts b/playground/data-uri/__tests__/data-uri.spec.ts
index e1d488c931e7c1..bf9d595c813322 100644
--- a/playground/data-uri/__tests__/data-uri.spec.ts
+++ b/playground/data-uri/__tests__/data-uri.spec.ts
@@ -8,9 +8,7 @@ test('base64', async () => {
   expect(await page.textContent('.base64')).toBe('hi')
 })
 
-if (isBuild) {
-  test('should compile away the import for build', async () => {
-    const file = findAssetFile('index')
-    expect(file).not.toMatch('import')
-  })
-}
+test.runIf(isBuild)('should compile away the import for build', async () => {
+  const file = findAssetFile('index')
+  expect(file).not.toMatch('import')
+})
diff --git a/playground/define/__tests__/define.spec.ts b/playground/define/__tests__/define.spec.ts
index 3a4f34c5bbe7ff..a7a45dcea1b701 100644
--- a/playground/define/__tests__/define.spec.ts
+++ b/playground/define/__tests__/define.spec.ts
@@ -7,6 +7,7 @@ test('string', async () => {
   expect(await page.textContent('.string')).toBe(JSON.parse(defines.__STRING__))
   expect(await page.textContent('.number')).toBe(String(defines.__NUMBER__))
   expect(await page.textContent('.boolean')).toBe(String(defines.__BOOLEAN__))
+
   expect(await page.textContent('.object')).toBe(
     JSON.stringify(defines.__OBJ__, null, 2)
   )
diff --git a/playground/env-nested/__tests__/env-nested.spec.ts b/playground/env-nested/__tests__/env-nested.spec.ts
index 1ceebde7a044b7..ed107acb233e02 100644
--- a/playground/env-nested/__tests__/env-nested.spec.ts
+++ b/playground/env-nested/__tests__/env-nested.spec.ts
@@ -1,4 +1,4 @@
-import { isBuild } from 'testUtils'
+import { isBuild } from '../../testUtils'
 
 const mode = isBuild ? `production` : `development`
 
diff --git a/playground/env/__tests__/env.spec.ts b/playground/env/__tests__/env.spec.ts
index 907cebc8037ce9..cbc0aad524001c 100644
--- a/playground/env/__tests__/env.spec.ts
+++ b/playground/env/__tests__/env.spec.ts
@@ -1,4 +1,4 @@
-import { isBuild } from 'testUtils'
+import { isBuild } from '../../testUtils'
 
 const mode = isBuild ? `production` : `development`
 
diff --git a/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts b/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts
index 24f1237efedeec..04ce2e71b00cd8 100644
--- a/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts
+++ b/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts
@@ -6,8 +6,9 @@ import {
   isBuild
 } from '../../testUtils'
 
-if (!isBuild) {
-  test('should hmr when file is deleted and restored', async () => {
+test.runIf(isBuild)(
+  'should hmr when file is deleted and restored',
+  async () => {
     await untilUpdated(() => page.textContent('p'), 'Child state 1')
 
     editFile('Child.jsx', (code) =>
@@ -39,7 +40,7 @@ if (!isBuild) {
       (code) =>
         `import { useState } from 'react'
       import Child from './Child'
-      
+
       function App() {
         return (
           
@@ -47,15 +48,11 @@ if (!isBuild) {
) } - + export default App ` ) await untilUpdated(() => page.textContent('p'), 'Child state 1') - }) -} else { - test('dummy test to make jest happy', async () => { - // Your test suite must contain at least one test. - }) -} + } +) diff --git a/playground/fs-serve/__tests__/fs-serve.spec.ts b/playground/fs-serve/__tests__/fs-serve.spec.ts index eba1e441881710..75c3fc6edfee04 100644 --- a/playground/fs-serve/__tests__/fs-serve.spec.ts +++ b/playground/fs-serve/__tests__/fs-serve.spec.ts @@ -1,73 +1,67 @@ -import { isBuild } from '../../testUtils' +import { isServe } from '../../testUtils' const json = require('../safe.json') const stringified = JSON.stringify(json) -describe('main', () => { +describe.runIf(isServe)('main', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/jestPerTestSetup.ts + // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/src/') }) - if (!isBuild) { - test('default import', async () => { - expect(await page.textContent('.full')).toBe(stringified) - }) + test('default import', async () => { + expect(await page.textContent('.full')).toBe(stringified) + }) - test('named import', async () => { - expect(await page.textContent('.named')).toBe(json.msg) - }) + test('named import', async () => { + expect(await page.textContent('.named')).toBe(json.msg) + }) - test('safe fetch', async () => { - expect(await page.textContent('.safe-fetch')).toMatch('KEY=safe') - expect(await page.textContent('.safe-fetch-status')).toBe('200') - }) + test('safe fetch', async () => { + expect(await page.textContent('.safe-fetch')).toMatch('KEY=safe') + expect(await page.textContent('.safe-fetch-status')).toBe('200') + }) - test('safe fetch with special characters', async () => { - expect( - await page.textContent('.safe-fetch-subdir-special-characters') - ).toMatch('KEY=safe') - expect( - await page.textContent('.safe-fetch-subdir-special-characters-status') - ).toBe('200') - }) + test('safe fetch with special characters', async () => { + expect( + await page.textContent('.safe-fetch-subdir-special-characters') + ).toMatch('KEY=safe') + expect( + await page.textContent('.safe-fetch-subdir-special-characters-status') + ).toBe('200') + }) - test('unsafe fetch', async () => { - expect(await page.textContent('.unsafe-fetch')).toMatch('403 Restricted') - expect(await page.textContent('.unsafe-fetch-status')).toBe('403') - }) + test('unsafe fetch', async () => { + expect(await page.textContent('.unsafe-fetch')).toMatch('403 Restricted') + expect(await page.textContent('.unsafe-fetch-status')).toBe('403') + }) - test('safe fs fetch', async () => { - expect(await page.textContent('.safe-fs-fetch')).toBe(stringified) - expect(await page.textContent('.safe-fs-fetch-status')).toBe('200') - }) + test('safe fs fetch', async () => { + expect(await page.textContent('.safe-fs-fetch')).toBe(stringified) + expect(await page.textContent('.safe-fs-fetch-status')).toBe('200') + }) - test('safe fs fetch with special characters', async () => { - expect(await page.textContent('.safe-fs-fetch-special-characters')).toBe( - stringified - ) - expect(await page.textContent('.safe-fs-fetch-status')).toBe('200') - }) + test('safe fs fetch with special characters', async () => { + expect(await page.textContent('.safe-fs-fetch-special-characters')).toBe( + stringified + ) + expect(await page.textContent('.safe-fs-fetch-status')).toBe('200') + }) - test('unsafe fs fetch', async () => { - expect(await page.textContent('.unsafe-fs-fetch')).toBe('') - expect(await page.textContent('.unsafe-fs-fetch-status')).toBe('403') - }) + test('unsafe fs fetch', async () => { + expect(await page.textContent('.unsafe-fs-fetch')).toBe('') + expect(await page.textContent('.unsafe-fs-fetch-status')).toBe('403') + }) - test('nested entry', async () => { - expect(await page.textContent('.nested-entry')).toBe('foobar') - }) + test('nested entry', async () => { + expect(await page.textContent('.nested-entry')).toBe('foobar') + }) - test('nested entry', async () => { - expect(await page.textContent('.nested-entry')).toBe('foobar') - }) + test('nested entry', async () => { + expect(await page.textContent('.nested-entry')).toBe('foobar') + }) - test('denied', async () => { - expect(await page.textContent('.unsafe-dotenv')).toBe('404') - }) - } else { - test('dummy test to make jest happy', async () => { - // Your test suite must contain at least one test. - }) - } + test('denied', async () => { + expect(await page.textContent('.unsafe-dotenv')).toBe('404') + }) }) diff --git a/playground/hmr/tsconfig.json b/playground/hmr/tsconfig.json index 41b16fdc65ec8c..9da745ba51a3e9 100644 --- a/playground/hmr/tsconfig.json +++ b/playground/hmr/tsconfig.json @@ -10,6 +10,6 @@ "moduleResolution": "node", "baseUrl": ".", "jsx": "preserve", - "types": ["vite/client", "jest", "node"] + "types": ["vite/client", "node"] } } diff --git a/playground/html/__tests__/html.spec.ts b/playground/html/__tests__/html.spec.ts index 834db1f6126cad..3041247bc776d4 100644 --- a/playground/html/__tests__/html.spec.ts +++ b/playground/html/__tests__/html.spec.ts @@ -1,4 +1,4 @@ -import { getColor, isBuild, editFile } from '../../testUtils' +import { getColor, isBuild, editFile, isServe } from '../../testUtils' function testPage(isNested: boolean) { test('pre transform', async () => { @@ -79,7 +79,7 @@ describe('main', () => { describe('nested', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/jestPerTestSetup.ts + // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/nested/') }) @@ -88,17 +88,17 @@ describe('nested', () => { describe('nested w/ query', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/jestPerTestSetup.ts + // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/nested/index.html?v=1') }) testPage(true) }) -if (isBuild) { +describe.runIf(isBuild)('build', () => { describe('scriptAsync', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/jestPerTestSetup.ts + // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/scriptAsync.html') }) @@ -110,7 +110,7 @@ if (isBuild) { describe('scriptMixed', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/jestPerTestSetup.ts + // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/scriptMixed.html') }) @@ -124,7 +124,7 @@ if (isBuild) { // Ensure that the modulePreload polyfill is discarded in this case beforeAll(async () => { - // viteTestUrl is globally injected in scripts/jestPerTestSetup.ts + // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/zeroJS.html') }) @@ -164,11 +164,11 @@ if (isBuild) { ) }) }) -} +}) describe('noHead', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/jestPerTestSetup.ts + // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/noHead.html') }) @@ -183,7 +183,7 @@ describe('noHead', () => { describe('noBody', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/jestPerTestSetup.ts + // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/noBody.html') }) @@ -211,28 +211,26 @@ describe('unicode path', () => { }) }) -if (!isBuild) { - describe('invalid', () => { - test('should be 500 with overlay', async () => { - const response = await page.goto(viteTestUrl + '/invalid.html') - expect(response.status()).toBe(500) +describe.runIf(isServe)('invalid', () => { + test('should be 500 with overlay', async () => { + const response = await page.goto(viteTestUrl + '/invalid.html') + expect(response.status()).toBe(500) - const errorOverlay = await page.waitForSelector('vite-error-overlay') - expect(errorOverlay).toBeTruthy() + const errorOverlay = await page.waitForSelector('vite-error-overlay') + expect(errorOverlay).toBeTruthy() - const message = await errorOverlay.$$eval('.message-body', (m) => { - return m[0].innerHTML - }) - expect(message).toMatch(/^Unable to parse HTML/) + const message = await errorOverlay.$$eval('.message-body', (m) => { + return m[0].innerHTML }) + expect(message).toMatch(/^Unable to parse HTML/) + }) - test('should reload when fixed', async () => { - const response = await page.goto(viteTestUrl + '/invalid.html') - await editFile('invalid.html', (content) => { - return content.replace('
Good') - }) - const content = await page.waitForSelector('text=Good HTML') - expect(content).toBeTruthy() + test('should reload when fixed', async () => { + const response = await page.goto(viteTestUrl + '/invalid.html') + await editFile('invalid.html', (content) => { + return content.replace('
Good') }) + const content = await page.waitForSelector('text=Good HTML') + expect(content).toBeTruthy() }) -} +}) diff --git a/playground/js-sourcemap/__tests__/build.spec.ts b/playground/js-sourcemap/__tests__/build.spec.ts index e36c1f52d2c1f8..50b8814aed9c4e 100644 --- a/playground/js-sourcemap/__tests__/build.spec.ts +++ b/playground/js-sourcemap/__tests__/build.spec.ts @@ -1,13 +1,7 @@ -import { isBuild } from 'testUtils' +import { isBuild } from '../../testUtils' -if (isBuild) { - test('should not output sourcemap warning (#4939)', () => { - serverLogs.forEach((log) => { - expect(log).not.toMatch('Sourcemap is likely to be incorrect') - }) +test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => { + serverLogs.forEach((log) => { + expect(log).not.toMatch('Sourcemap is likely to be incorrect') }) -} else { - test('this file only includes test for build', () => { - expect(true).toBe(true) - }) -} +}) diff --git a/playground/js-sourcemap/__tests__/serve.spec.ts b/playground/js-sourcemap/__tests__/serve.spec.ts index a1ffdddc37ecd5..b3946461dde197 100644 --- a/playground/js-sourcemap/__tests__/serve.spec.ts +++ b/playground/js-sourcemap/__tests__/serve.spec.ts @@ -3,7 +3,7 @@ import { extractSourcemap, formatSourcemapForSnapshot, isBuild -} from 'testUtils' +} from '../../testUtils' if (!isBuild) { test('js', async () => { @@ -18,12 +18,12 @@ if (!isBuild) { const js = await res.text() const map = extractSourcemap(js) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": "AAAO,aAAM,MAAM;", - "sources": Array [ + "sources": [ "/root/bar.ts", ], - "sourcesContent": Array [ + "sourcesContent": [ "export const bar = 'bar' ", ], diff --git a/playground/legacy/__tests__/legacy.spec.ts b/playground/legacy/__tests__/legacy.spec.ts index 9fd3419337568d..c0eaa81fbc31d8 100644 --- a/playground/legacy/__tests__/legacy.spec.ts +++ b/playground/legacy/__tests__/legacy.spec.ts @@ -67,7 +67,7 @@ test('should load dynamic import with css', async () => { ) }) -if (isBuild) { +describe.runIf(isBuild)('build', () => { test('should generate correct manifest', async () => { const manifest = readManifest() expect(manifest['../../vite/legacy-polyfills']).toBeDefined() @@ -98,4 +98,4 @@ if (isBuild) { test('includes structuredClone polyfill which is supported after core-js v3', () => { expect(findAssetFile(/polyfills-legacy/)).toMatch('"structuredClone"') }) -} +}) diff --git a/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts b/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts index dad9b94d83509e..bc232e8af129c6 100644 --- a/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts +++ b/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts @@ -3,7 +3,7 @@ import { port } from './serve' const url = `http://localhost:${port}` -if (isBuild) { +describe.runIf(isBuild)('legacy-ssr', () => { test('should work', async () => { await page.goto(url) expect(await page.textContent('#app')).toMatch('Hello') @@ -13,8 +13,4 @@ if (isBuild) { // SSR build is always modern expect(await page.textContent('#env')).toMatch('false') }) -} else { - // this test doesn't support serve mode - // must contain at least one test - test('should work', () => void 0) -} +}) diff --git a/playground/legacy/__tests__/ssr/serve.js b/playground/legacy/__tests__/ssr/serve.ts similarity index 72% rename from playground/legacy/__tests__/ssr/serve.js rename to playground/legacy/__tests__/ssr/serve.ts index c7ef2ed3520e53..597320c9a58c0f 100644 --- a/playground/legacy/__tests__/ssr/serve.js +++ b/playground/legacy/__tests__/ssr/serve.ts @@ -1,16 +1,11 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const { ports } = require('../../../testUtils') +import path from 'path' +import { ports } from '../../../testUtils' -const port = (exports.port = ports['legacy/ssr']) +export const port = ports['legacy/ssr'] -/** - * @param {string} root - * @param {boolean} _isProd - */ -exports.serve = async function serve(root, _isProd) { +export async function serve(root: string, _isProd: boolean) { const { build } = require('vite') await build({ root, diff --git a/playground/lib/__tests__/lib.spec.ts b/playground/lib/__tests__/lib.spec.ts index cc5887c2777fcb..6d7ca7c5670ea0 100644 --- a/playground/lib/__tests__/lib.spec.ts +++ b/playground/lib/__tests__/lib.spec.ts @@ -1,8 +1,8 @@ -import { isBuild, findAssetFile, testDir } from 'testUtils' +import { isBuild, testDir, isServe } from '../../testUtils' import path from 'path' import fs from 'fs' -if (isBuild) { +describe.runIf(isBuild)('build', () => { test('es', async () => { expect(await page.textContent('.es')).toBe('It works') }) @@ -10,7 +10,7 @@ if (isBuild) { test('umd', async () => { expect(await page.textContent('.umd')).toBe('It works') const code = fs.readFileSync( - path.join(testDir, 'dist/my-lib-custom-filename.umd.js'), + path.join(testDir(), 'dist/my-lib-custom-filename.umd.js'), 'utf-8' ) // esbuild helpers are injected inside of the UMD wrapper @@ -20,7 +20,7 @@ if (isBuild) { test('iife', async () => { expect(await page.textContent('.iife')).toBe('It works') const code = fs.readFileSync( - path.join(testDir, 'dist/my-lib-custom-filename.iife.js'), + path.join(testDir(), 'dist/my-lib-custom-filename.iife.js'), 'utf-8' ) // esbuild helpers are injected inside of the IIFE wrapper @@ -30,7 +30,7 @@ if (isBuild) { test('Library mode does not include `preload`', async () => { expect(await page.textContent('.dynamic-import-message')).toBe('hello vite') const code = fs.readFileSync( - path.join(testDir, 'dist/lib/dynamic-import-message.js'), + path.join(testDir(), 'dist/lib/dynamic-import-message.js'), 'utf-8' ) expect(code).not.toMatch('__vitePreload') @@ -42,8 +42,8 @@ if (isBuild) { expect(log).not.toMatch('All "@import" rules must come first') }) }) -} else { - test('dev', async () => { - expect(await page.textContent('.demo')).toBe('It works') - }) -} +}) + +test.runIf(isServe)('dev', async () => { + expect(await page.textContent('.demo')).toBe('It works') +}) diff --git a/playground/lib/__tests__/serve.js b/playground/lib/__tests__/serve.ts similarity index 81% rename from playground/lib/__tests__/serve.js rename to playground/lib/__tests__/serve.ts index 2534545de5c221..3bde3d35a78dc1 100644 --- a/playground/lib/__tests__/serve.js +++ b/playground/lib/__tests__/serve.ts @@ -1,29 +1,23 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const http = require('http') -const sirv = require('sirv') -const { ports } = require('../../testUtils') +import path from 'path' +import http from 'http' +import sirv from 'sirv' +import { ports } from '../../testUtils' -const port = (exports.port = ports.lib) +export const port = ports.lib -global.serverLogs = [] - -/** - * @param {string} root - * @param {boolean} isBuildTest - */ -exports.serve = async function serve(root, isBuildTest) { - // build first +export async function serve(root, isBuildTest) { + // @ts-expect-error + global.serverLogs = [] setupConsoleWarnCollector() if (!isBuildTest) { const { createServer } = require('vite') process.env.VITE_INLINE = 'inline-serve' - let viteServer = await ( + const viteServer = await ( await createServer({ root: root, logLevel: 'silent', @@ -45,6 +39,7 @@ exports.serve = async function serve(root, isBuildTest) { // use resolved port/base from server const base = viteServer.config.base === '/' ? '' : viteServer.config.base const url = + // @ts-expect-error (global.viteTestUrl = `http://localhost:${viteServer.config.server.port}${base}`) await page.goto(url) @@ -97,6 +92,7 @@ exports.serve = async function serve(root, isBuildTest) { function setupConsoleWarnCollector() { const warn = console.warn console.warn = (...args) => { + // @ts-expect-error global.serverLogs.push(args.join(' ')) return warn.call(console, ...args) } diff --git a/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts b/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts index dd776daeceadbf..9f6934dd25ace8 100644 --- a/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts +++ b/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts @@ -1,10 +1,12 @@ import { port } from './serve' import fetch from 'node-fetch' import { untilUpdated } from '../../testUtils' +import { platform } from 'os' -const url = `http://localhost:${port}` +const url = `http://localhost:${port}/` -test('*', async () => { +// TODO: on macOS this test causing the process exists for some reason +test.skipIf(platform() === 'darwin')('optimize', async () => { await page.goto(url) // reload page to get optimized missing deps await page.reload() @@ -12,5 +14,5 @@ test('*', async () => { // raw http request const aboutHtml = await (await fetch(url)).text() - expect(aboutHtml).toMatch('Server') + expect(aboutHtml).toContain('Server') }) diff --git a/playground/ssr-pug/__tests__/serve.js b/playground/optimize-missing-deps/__test__/serve.ts similarity index 64% rename from playground/ssr-pug/__tests__/serve.js rename to playground/optimize-missing-deps/__test__/serve.ts index 392aa831ebb82d..3b60850905e389 100644 --- a/playground/ssr-pug/__tests__/serve.js +++ b/playground/optimize-missing-deps/__test__/serve.ts @@ -1,17 +1,12 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const { ports } = require('../../testUtils') +import path from 'path' +import { ports } from '../../testUtils' -const port = (exports.port = ports['ssr-pug']) +export const port = ports['optimize-missing-deps'] -/** - * @param {string} root - * @param {boolean} isProd - */ -exports.serve = async function serve(root, isProd) { +export async function serve(root: string, isProd: boolean) { const { createServer } = require(path.resolve(root, 'server.js')) const { app, vite } = await createServer(root, isProd) diff --git a/playground/preload/__tests__/preload.spec.ts b/playground/preload/__tests__/preload.spec.ts index 27a64930487797..b0ffb58a291bac 100644 --- a/playground/preload/__tests__/preload.spec.ts +++ b/playground/preload/__tests__/preload.spec.ts @@ -6,7 +6,7 @@ test('should have no 404s', () => { }) }) -if (isBuild) { +describe.runIf(isBuild)('build', () => { test('dynamic import', async () => { const appHtml = await page.content() expect(appHtml).toMatch('This is home page.') @@ -22,4 +22,4 @@ if (isBuild) { /link rel="stylesheet".*?href="\/assets\/Hello\.\w{8}\.css"/ ) }) -} +}) diff --git a/playground/preload/vite.config.js b/playground/preload/vite.config.ts similarity index 62% rename from playground/preload/vite.config.js rename to playground/preload/vite.config.ts index 90684f41829953..7fa1eb189818b3 100644 --- a/playground/preload/vite.config.js +++ b/playground/preload/vite.config.ts @@ -1,6 +1,7 @@ -const vuePlugin = require('@vitejs/plugin-vue') +import vuePlugin from '@vitejs/plugin-vue' +import { defineConfig } from 'vite' -module.exports = { +export default defineConfig({ plugins: [vuePlugin()], build: { minify: 'terser', @@ -13,4 +14,4 @@ module.exports = { } } } -} +}) diff --git a/playground/react/__tests__/react.spec.ts b/playground/react/__tests__/react.spec.ts index 46eb752924f801..4b39a304733318 100644 --- a/playground/react/__tests__/react.spec.ts +++ b/playground/react/__tests__/react.spec.ts @@ -1,4 +1,4 @@ -import { editFile, untilUpdated, isBuild } from '../../testUtils' +import { editFile, untilUpdated, isServe } from '../../testUtils' test('should render', async () => { expect(await page.textContent('h1')).toMatch('Hello Vite + React') @@ -17,23 +17,22 @@ test('should hmr', async () => { expect(await page.textContent('button')).toMatch('count is: 1') }) -test('should have annotated jsx with file location metadata', async () => { - // we're not annotating in prod, - // so we skip this test when isBuild is true - if (isBuild) return - - const meta = await page.evaluate(() => { - const button = document.querySelector('button') - const key = Object.keys(button).find( - (key) => key.indexOf('__reactFiber') === 0 - ) - return button[key]._debugSource - }) - // If the evaluate call doesn't crash, and the returned metadata has - // the expected fields, we're good. - expect(Object.keys(meta).sort()).toEqual([ - 'columnNumber', - 'fileName', - 'lineNumber' - ]) -}) +test.runIf(isServe)( + 'should have annotated jsx with file location metadata', + async () => { + const meta = await page.evaluate(() => { + const button = document.querySelector('button') + const key = Object.keys(button).find( + (key) => key.indexOf('__reactFiber') === 0 + ) + return button[key]._debugSource + }) + // If the evaluate call doesn't crash, and the returned metadata has + // the expected fields, we're good. + expect(Object.keys(meta).sort()).toEqual([ + 'columnNumber', + 'fileName', + 'lineNumber' + ]) + } +) diff --git a/playground/resolve-config/__tests__/resolve-config.spec.ts b/playground/resolve-config/__tests__/resolve-config.spec.ts index cde329afde2f50..bd45ad6c95012d 100644 --- a/playground/resolve-config/__tests__/resolve-config.spec.ts +++ b/playground/resolve-config/__tests__/resolve-config.spec.ts @@ -5,7 +5,7 @@ import { isBuild, testDir, workspaceRoot } from '../../testUtils' const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js') -const fromTestDir = (...p: string[]) => path.resolve(testDir, ...p) +const fromTestDir = (...p: string[]) => path.resolve(testDir(), ...p) const build = (configName: string) => { commandSync(`${viteBin} build`, { cwd: fromTestDir(configName) }) @@ -17,7 +17,7 @@ const getDistFile = (configName: string, extension: string) => { ) } -if (isBuild) { +describe.runIf(isBuild)('build', () => { it('loads vite.config.js', () => { build('js') expect(getDistFile('js', 'mjs')).toContain('console.log(true)') @@ -50,8 +50,4 @@ if (isBuild) { build('ts-module') expect(getDistFile('ts-module', 'js')).toContain('console.log(true)') }) -} else { - // this test doesn't support serve mode - // must contain at least one test - test('should work', () => void 0) -} +}) diff --git a/playground/resolve-config/__tests__/serve.js b/playground/resolve-config/__tests__/serve.ts similarity index 71% rename from playground/resolve-config/__tests__/serve.js rename to playground/resolve-config/__tests__/serve.ts index bd451d4cf6f6bc..4c1561264113e8 100644 --- a/playground/resolve-config/__tests__/serve.js +++ b/playground/resolve-config/__tests__/serve.ts @@ -1,19 +1,16 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const fs = require('fs-extra') -const { testDir } = require('../../testUtils') - -const fromTestDir = (/** @type{string[]} */ ...p) => path.resolve(testDir, ...p) +import path from 'path' +import fs from 'fs-extra' const configNames = ['js', 'cjs', 'mjs', 'ts'] -/** @param {string} root @param {boolean} isProd */ -exports.serve = async function serve(root, isProd) { +export async function serve(root: string, isProd: boolean) { if (!isProd) return + const fromTestDir = (...p: string[]) => path.resolve(root, '..', ...p) + // create separate directories for all config types: // ./{js,cjs,mjs,ts} and ./{js,cjs,mjs,ts}-module (with package#type) for (const configName of configNames) { diff --git a/playground/ssr-deps/__tests__/serve.js b/playground/ssr-deps/__tests__/serve.ts similarity index 64% rename from playground/ssr-deps/__tests__/serve.js rename to playground/ssr-deps/__tests__/serve.ts index 6c2584601c9331..92c73fc50a8629 100644 --- a/playground/ssr-deps/__tests__/serve.js +++ b/playground/ssr-deps/__tests__/serve.ts @@ -1,17 +1,12 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const { ports } = require('../../testUtils') +import path from 'path' +import { ports } from '../../testUtils' -const port = (exports.port = ports['ssr-deps']) +export const port = ports['ssr-deps'] -/** - * @param {string} root - * @param {boolean} isProd - */ -exports.serve = async function serve(root, isProd) { +export async function serve(root, isProd) { const { createServer } = require(path.resolve(root, 'server.js')) const { app, vite } = await createServer(root, isProd) diff --git a/playground/ssr-html/__tests__/serve.js b/playground/ssr-html/__tests__/serve.ts similarity index 64% rename from playground/ssr-html/__tests__/serve.js rename to playground/ssr-html/__tests__/serve.ts index d119397700cf75..804009e92e86d6 100644 --- a/playground/ssr-html/__tests__/serve.js +++ b/playground/ssr-html/__tests__/serve.ts @@ -1,17 +1,12 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const { ports } = require('../../testUtils') +import path from 'path' +import { ports } from '../../testUtils' -const port = (exports.port = ports['ssr-html']) +export const port = ports['ssr-html'] -/** - * @param {string} root - * @param {boolean} isProd - */ -exports.serve = async function serve(root, isProd) { +export async function serve(root, isProd) { const { createServer } = require(path.resolve(root, 'server.js')) const { app, vite } = await createServer(root, isProd) diff --git a/playground/optimize-missing-deps/__test__/serve.js b/playground/ssr-pug/__tests__/serve.ts similarity index 63% rename from playground/optimize-missing-deps/__test__/serve.js rename to playground/ssr-pug/__tests__/serve.ts index 89a6ce3593cd0e..2d687a5a685664 100644 --- a/playground/optimize-missing-deps/__test__/serve.js +++ b/playground/ssr-pug/__tests__/serve.ts @@ -1,17 +1,12 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const { ports } = require('../../testUtils') +import path from 'path' +import { ports } from '../../testUtils' -const port = (exports.port = ports['optimize-missing-deps']) +export const port = ports['ssr-pug'] -/** - * @param {string} root - * @param {boolean} isProd - */ -exports.serve = async function serve(root, isProd) { +export async function serve(root, isProd) { const { createServer } = require(path.resolve(root, 'server.js')) const { app, vite } = await createServer(root, isProd) diff --git a/playground/ssr-react/__tests__/serve.js b/playground/ssr-react/__tests__/serve.ts similarity index 77% rename from playground/ssr-react/__tests__/serve.js rename to playground/ssr-react/__tests__/serve.ts index 07476e0726e268..2f8479a7463bd7 100644 --- a/playground/ssr-react/__tests__/serve.js +++ b/playground/ssr-react/__tests__/serve.ts @@ -1,17 +1,12 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const { ports } = require('../../testUtils') +import path from 'path' +import { ports } from '../../testUtils' -const port = (exports.port = ports['ssr-react']) +export const port = ports['ssr-react'] -/** - * @param {string} root - * @param {boolean} isProd - */ -exports.serve = async function serve(root, isProd) { +export async function serve(root: string, isProd: boolean) { if (isProd) { // build first const { build } = require('vite') diff --git a/playground/ssr-vue/__tests__/serve.js b/playground/ssr-vue/__tests__/serve.ts similarity index 77% rename from playground/ssr-vue/__tests__/serve.js rename to playground/ssr-vue/__tests__/serve.ts index 5bcd5a4639877a..138729bfdaa01e 100644 --- a/playground/ssr-vue/__tests__/serve.js +++ b/playground/ssr-vue/__tests__/serve.ts @@ -1,17 +1,12 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const { ports } = require('../../testUtils') +import path from 'path' +import { ports } from '../../testUtils' -const port = (exports.port = ports['ssr-vue']) +export const port = ports['ssr-vue'] -/** - * @param {string} root - * @param {boolean} isProd - */ -exports.serve = async function serve(root, isProd) { +export async function serve(root, isProd) { if (isProd) { // build first const { build } = require('vite') diff --git a/playground/ssr-vue/__tests__/ssr-vue.spec.ts b/playground/ssr-vue/__tests__/ssr-vue.spec.ts index baa7b79dd74252..193c95b1f4a1c1 100644 --- a/playground/ssr-vue/__tests__/ssr-vue.spec.ts +++ b/playground/ssr-vue/__tests__/ssr-vue.spec.ts @@ -110,6 +110,7 @@ test('css', async () => { } else { // During dev, the CSS is loaded from async chunk and we may have to wait // when the test runs concurrently. + await page.waitForLoadState('networkidle') await untilUpdated(() => getColor('h1'), 'green') await untilUpdated(() => getColor('.jsx'), 'blue') } @@ -141,11 +142,13 @@ test('nested virtual module', async () => { test('hydration', async () => { expect(await page.textContent('button')).toMatch('0') await page.click('button') + await page.waitForLoadState('networkidle') expect(await page.textContent('button')).toMatch('1') }) test('hmr', async () => { editFile('src/pages/Home.vue', (code) => code.replace('Home', 'changed')) + await page.waitForLoadState('networkidle') await untilUpdated(() => page.textContent('h1'), 'changed') }) @@ -154,6 +157,7 @@ test('client navigation', async () => { await page.click('a[href="/about"]') await untilUpdated(() => page.textContent('h1'), 'About') editFile('src/pages/About.vue', (code) => code.replace('About', 'changed')) + await page.waitForLoadState('networkidle') await untilUpdated(() => page.textContent('h1'), 'changed') await page.click('a[href="/"]') await untilUpdated(() => page.textContent('a[href="/"]'), 'Home') @@ -164,19 +168,17 @@ test('import.meta.url', async () => { expect(await page.textContent('.protocol')).toEqual('file:') }) -test('dynamic css file should be preloaded', async () => { - if (isBuild) { - await page.goto(url) - const homeHtml = await (await fetch(url)).text() - const re = /link rel="modulepreload".*?href="\/assets\/(Home\.\w{8}\.js)"/ - const filename = re.exec(homeHtml)[1] - const manifest = require(resolve( - process.cwd(), - './playground-temp/ssr-vue/dist/client/ssr-manifest.json' - )) - const depFile = manifest[filename] - for (const file of depFile) { - expect(homeHtml).toMatch(file) - } +test.runIf(isBuild)('dynamic css file should be preloaded', async () => { + await page.goto(url) + const homeHtml = await (await fetch(url)).text() + const re = /link rel="modulepreload".*?href="\/assets\/(Home\.\w{8}\.js)"/ + const filename = re.exec(homeHtml)[1] + const manifest = require(resolve( + process.cwd(), + './playground-temp/ssr-vue/dist/client/ssr-manifest.json' + )) + const depFile = manifest[filename] + for (const file of depFile) { + expect(homeHtml).toMatch(file) } }) diff --git a/playground/ssr-webworker/__tests__/serve.js b/playground/ssr-webworker/__tests__/serve.ts similarity index 72% rename from playground/ssr-webworker/__tests__/serve.js rename to playground/ssr-webworker/__tests__/serve.ts index 38a957b0a333ea..382208b3b06d2e 100644 --- a/playground/ssr-webworker/__tests__/serve.js +++ b/playground/ssr-webworker/__tests__/serve.ts @@ -1,17 +1,12 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace +// this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -const path = require('path') -const { ports } = require('../../testUtils') +import path from 'path' +import { ports } from '../../testUtils' -const port = (exports.port = ports['ssr-webworker']) +export const port = ports['ssr-webworker'] -/** - * @param {string} root - * @param {boolean} isProd - */ -exports.serve = async function serve(root, isProd) { +export async function serve(root: string, isProd: boolean) { // we build first, regardless of whether it's prod/build mode // because Vite doesn't support the concept of a "webworker server" const { build } = require('vite') diff --git a/playground/ssr-webworker/worker.js b/playground/ssr-webworker/worker.js index 09725aaa9d71bb..e9a51e320c9899 100644 --- a/playground/ssr-webworker/worker.js +++ b/playground/ssr-webworker/worker.js @@ -2,11 +2,11 @@ const path = require('path') const { Miniflare } = require('miniflare') -const isDev = process.env.DEV +const isTest = !!process.env.TEST -async function createServer(root = process.cwd()) { +async function createServer() { const mf = new Miniflare({ - scriptPath: path.resolve(root, 'dist/worker/entry-worker.js') + scriptPath: path.resolve(__dirname, 'dist/worker/entry-worker.js') }) const app = mf.createServer() @@ -14,7 +14,7 @@ async function createServer(root = process.cwd()) { return { app } } -if (isDev) { +if (!isTest) { createServer().then(({ app }) => app.listen(3000, () => { console.log('http://localhost:3000') diff --git a/playground/tailwind-sourcemap/__tests__/build.spec.ts b/playground/tailwind-sourcemap/__tests__/build.spec.ts index e36c1f52d2c1f8..50b8814aed9c4e 100644 --- a/playground/tailwind-sourcemap/__tests__/build.spec.ts +++ b/playground/tailwind-sourcemap/__tests__/build.spec.ts @@ -1,13 +1,7 @@ -import { isBuild } from 'testUtils' +import { isBuild } from '../../testUtils' -if (isBuild) { - test('should not output sourcemap warning (#4939)', () => { - serverLogs.forEach((log) => { - expect(log).not.toMatch('Sourcemap is likely to be incorrect') - }) +test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => { + serverLogs.forEach((log) => { + expect(log).not.toMatch('Sourcemap is likely to be incorrect') }) -} else { - test('this file only includes test for build', () => { - expect(true).toBe(true) - }) -} +}) diff --git a/playground/tailwind-sourcemap/__tests__/serve.spec.ts b/playground/tailwind-sourcemap/__tests__/serve.spec.ts index d961f75e4536e5..8d4613190f02a2 100644 --- a/playground/tailwind-sourcemap/__tests__/serve.spec.ts +++ b/playground/tailwind-sourcemap/__tests__/serve.spec.ts @@ -1,13 +1,7 @@ -import { isBuild } from 'testUtils' +import { isBuild } from '../../testUtils' -if (!isBuild) { - test('should not output missing source file warning', () => { - serverLogs.forEach((log) => { - expect(log).not.toMatch(/Sourcemap for .+ points to missing source files/) - }) +test.runIf(isBuild)('should not output missing source file warning', () => { + serverLogs.forEach((log) => { + expect(log).not.toMatch(/Sourcemap for .+ points to missing source files/) }) -} else { - test('this file only includes test for serve', () => { - expect(true).toBe(true) - }) -} +}) diff --git a/playground/testUtils.ts b/playground/testUtils.ts index 7abf09eaada081..d423ba942923cb 100644 --- a/playground/testUtils.ts +++ b/playground/testUtils.ts @@ -1,6 +1,5 @@ // test utils used in e2e tests for playgrounds. -// this can be directly imported in any playground tests as 'testUtils', e.g. -// `import { getColor } from 'testUtils'` +// `import { getColor } from '../../testUtils'` import fs from 'fs' import path from 'path' @@ -9,6 +8,7 @@ import type { ElementHandle } from 'playwright-chromium' import type { Manifest } from 'vite' import { normalizePath } from 'vite' import { fromComment } from 'convert-source-map' +import { expect } from 'vitest' // make sure these ports are unique export const ports = { @@ -32,10 +32,13 @@ export function slash(p: string): string { } export const isBuild = !!process.env.VITE_TEST_BUILD +export const isServe = !isBuild -const testPath = expect.getState().testPath -const testName = slash(testPath).match(/playground\/([\w-]+)\//)?.[1] -export const testDir = path.resolve(__dirname, '../playground-temp', testName) +export const testDir = () => { + const testPath = expect.getState().testPath + const testName = slash(testPath).match(/playground\/([\w-]+)\//)?.[1] + return path.resolve(__dirname, '../playground-temp', testName) +} export const workspaceRoot = path.resolve(__dirname, '../') const hexToNameMap: Record = {} @@ -89,7 +92,7 @@ export async function getBgColor(el: string | ElementHandle): Promise { } export function readFile(filename: string): string { - return fs.readFileSync(path.resolve(testDir, filename), 'utf-8') + return fs.readFileSync(path.resolve(testDir(), filename), 'utf-8') } export function editFile( @@ -98,27 +101,27 @@ export function editFile( runInBuild: boolean = false ): void { if (isBuild && !runInBuild) return - filename = path.resolve(testDir, filename) + filename = path.resolve(testDir(), filename) const content = fs.readFileSync(filename, 'utf-8') const modified = replacer(content) fs.writeFileSync(filename, modified) } export function addFile(filename: string, content: string): void { - fs.writeFileSync(path.resolve(testDir, filename), content) + fs.writeFileSync(path.resolve(testDir(), filename), content) } export function removeFile(filename: string): void { - fs.unlinkSync(path.resolve(testDir, filename)) + fs.unlinkSync(path.resolve(testDir(), filename)) } export function listAssets(base = ''): string[] { - const assetsDir = path.join(testDir, 'dist', base, 'assets') + const assetsDir = path.join(testDir(), 'dist', base, 'assets') return fs.readdirSync(assetsDir) } export function findAssetFile(match: string | RegExp, base = ''): string { - const assetsDir = path.join(testDir, 'dist', base, 'assets') + const assetsDir = path.join(testDir(), 'dist', base, 'assets') const files = fs.readdirSync(assetsDir) const file = files.find((file) => { return file.match(match) @@ -128,7 +131,10 @@ export function findAssetFile(match: string | RegExp, base = ''): string { export function readManifest(base = ''): Manifest { return JSON.parse( - fs.readFileSync(path.join(testDir, 'dist', base, 'manifest.json'), 'utf-8') + fs.readFileSync( + path.join(testDir(), 'dist', base, 'manifest.json'), + 'utf-8' + ) ) } @@ -156,7 +162,7 @@ export async function untilUpdated( /** * Send the rebuild complete message in build watch */ -export { notifyRebuildComplete } from '../scripts/jestPerTestSetup' +export { notifyRebuildComplete } from '../scripts/vitestSetup' export const extractSourcemap = (content: string) => { const lines = content.trim().split('\n') @@ -164,7 +170,7 @@ export const extractSourcemap = (content: string) => { } export const formatSourcemapForSnapshot = (map: any) => { - const root = normalizePath(testDir) + const root = normalizePath(testDir()) const m = { ...map } delete m.file delete m.names diff --git a/playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts b/playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts index 699f658da6a255..30485918ea6e2d 100644 --- a/playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts +++ b/playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts @@ -1,6 +1,12 @@ -import { editFile, isBuild, readFile, untilUpdated } from '../../testUtils' +import { + editFile, + isBuild, + isServe, + readFile, + untilUpdated +} from '../../testUtils' -if (isBuild) { +describe.runIf(isBuild)('build', () => { test('should throw an error on build', () => { const buildError = beforeAllError expect(buildError).toBeTruthy() @@ -20,7 +26,9 @@ if (isBuild) { expect(err).toBeTruthy() expect(err.code).toBe('ENOENT') }) -} else { +}) + +describe.runIf(isServe)('server', () => { test('should log 500 error in browser for malformed tsconfig', () => { // don't test for actual complete message as this might be locale dependant. chrome does log 500 consistently though expect(browserLogs.find((x) => x.includes('500'))).toBeTruthy() @@ -47,4 +55,4 @@ if (isBuild) { return browserLogs.find((x) => x === 'tsconfig error fixed, file loaded') }, 'tsconfig error fixed, file loaded') }) -} +}) diff --git a/playground/tsconfig.json b/playground/tsconfig.json index d60edb9f78c801..06bea8c1328d7f 100644 --- a/playground/tsconfig.json +++ b/playground/tsconfig.json @@ -9,6 +9,6 @@ "moduleResolution": "node", "baseUrl": ".", "jsx": "preserve", - "types": ["vite/client", "jest", "node"] + "types": ["vite/client", "vitest/globals", "node"] } } diff --git a/playground/vue-jsx/__tests__/vue-jsx.spec.ts b/playground/vue-jsx/__tests__/vue-jsx.spec.ts index 275c918684119d..94c4eb147a0b84 100644 --- a/playground/vue-jsx/__tests__/vue-jsx.spec.ts +++ b/playground/vue-jsx/__tests__/vue-jsx.spec.ts @@ -1,4 +1,4 @@ -import { editFile, isBuild, untilUpdated } from 'testUtils' +import { editFile, isServe, untilUpdated } from '../../testUtils' test('should render', async () => { expect(await page.textContent('.named')).toMatch('0') @@ -29,7 +29,7 @@ test('should update', async () => { expect(await page.textContent('.jsx-with-query')).toMatch('7') }) -if (!isBuild) { +describe.runIf(isServe)('vue-jsx server', () => { test('hmr: named export', async () => { editFile('Comps.jsx', (code) => code.replace('named {count', 'named updated {count') @@ -113,4 +113,4 @@ if (!isBuild) { ) await untilUpdated(() => page.textContent('.setup-jsx'), '1000') }) -} +}) diff --git a/playground/vue-lib/__tests__/serve.js b/playground/vue-lib/__tests__/serve.js deleted file mode 100644 index 73f89eee44ea3e..00000000000000 --- a/playground/vue-lib/__tests__/serve.js +++ /dev/null @@ -1,7 +0,0 @@ -// @ts-check -// this is automtically detected by scripts/jestPerTestSetup.ts and will replace -// the default e2e test serve behavior - -exports.serve = async function serve() { - // do nothing, skip default behavior -} diff --git a/playground/vue-lib/__tests__/serve.ts b/playground/vue-lib/__tests__/serve.ts new file mode 100644 index 00000000000000..47c122339205eb --- /dev/null +++ b/playground/vue-lib/__tests__/serve.ts @@ -0,0 +1,6 @@ +// this is automatically detected by scripts/vitestSetup.ts and will replace +// the default e2e test serve behavior + +export async function serve() { + // do nothing, skip default behavior +} diff --git a/playground/vue-sourcemap/__tests__/build.spec.ts b/playground/vue-sourcemap/__tests__/build.spec.ts index e36c1f52d2c1f8..50b8814aed9c4e 100644 --- a/playground/vue-sourcemap/__tests__/build.spec.ts +++ b/playground/vue-sourcemap/__tests__/build.spec.ts @@ -1,13 +1,7 @@ -import { isBuild } from 'testUtils' +import { isBuild } from '../../testUtils' -if (isBuild) { - test('should not output sourcemap warning (#4939)', () => { - serverLogs.forEach((log) => { - expect(log).not.toMatch('Sourcemap is likely to be incorrect') - }) +test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => { + serverLogs.forEach((log) => { + expect(log).not.toMatch('Sourcemap is likely to be incorrect') }) -} else { - test('this file only includes test for build', () => { - expect(true).toBe(true) - }) -} +}) diff --git a/playground/vue-sourcemap/__tests__/serve.spec.ts b/playground/vue-sourcemap/__tests__/serve.spec.ts index 7dfa271deea322..09ba69c03abfa4 100644 --- a/playground/vue-sourcemap/__tests__/serve.spec.ts +++ b/playground/vue-sourcemap/__tests__/serve.spec.ts @@ -1,11 +1,11 @@ import { extractSourcemap, formatSourcemapForSnapshot, - isBuild -} from 'testUtils' + isServe +} from '../../testUtils' import { URL } from 'url' -if (!isBuild) { +describe.runIf(isServe)('serve:vue-sourcemap', () => { const getStyleTagContentIncluding = async (content: string) => { const styles = await page.$$('style') for (const style of styles) { @@ -22,12 +22,12 @@ if (!isBuild) { const js = await res.text() const map = extractSourcemap(js) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": "AAKA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;AAGP;AACd,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;wBARlB,oBAAiB,WAAd,MAAU", - "sources": Array [ + "sources": [ "/root/Js.vue", ], - "sourcesContent": Array [ + "sourcesContent": [ " @@ -51,12 +51,12 @@ if (!isBuild) { const js = await res.text() const map = extractSourcemap(js) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": ";AAKA,QAAQ,IAAI,WAAW;;;;AAIvB,YAAQ,IAAI,UAAU;;;;;;;;uBARpB,oBAAiB,WAAd,MAAU", - "sources": Array [ + "sources": [ "/root/Ts.vue", ], - "sourcesContent": Array [ + "sourcesContent": [ " @@ -79,15 +79,15 @@ if (!isBuild) { const css = await getStyleTagContentIncluding('.css ') const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": ";AAQA;EACE,UAAU;AACZ", - "sources": Array [ + "sources": [ "/root/Css.vue", ], - "sourcesContent": Array [ + "sourcesContent": [ " @@ -130,15 +130,15 @@ if (!isBuild) { const css = await getStyleTagContentIncluding('._css-module_') const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": ";AAcA;EACE,UAAU;AACZ", - "sources": Array [ + "sources": [ "/root/Css.vue", ], - "sourcesContent": Array [ + "sourcesContent": [ " @@ -181,15 +181,15 @@ if (!isBuild) { const css = await getStyleTagContentIncluding('.css-scoped[data-v-') const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": ";AAoBA;EACE,UAAU;AACZ", - "sources": Array [ + "sources": [ "/root/Css.vue", ], - "sourcesContent": Array [ + "sourcesContent": [ " @@ -232,12 +232,12 @@ if (!isBuild) { const css = await getStyleTagContentIncluding('.sass ') const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": "AAKA;EACE", - "sources": Array [ + "sources": [ "/root/Sass.vue", ], - "sourcesContent": Array [ + "sourcesContent": [ " @@ -257,13 +257,13 @@ if (!isBuild) { const css = await getStyleTagContentIncluding('.sass-with-import ') const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": "AAAA;EACE;;ACOF;EACE", - "sources": Array [ + "sources": [ "/root/sassWithImportImported.sass", "/root/SassWithImport.vue", ], - "sourcesContent": Array [ + "sourcesContent": [ ".sass-with-import-imported color: red ", @@ -289,12 +289,12 @@ if (!isBuild) { const css = await getStyleTagContentIncluding('.less ') const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": "AAKA;EACE", - "sources": Array [ + "sources": [ "/root/Less.vue", ], - "sourcesContent": Array [ + "sourcesContent": [ " @@ -315,12 +315,12 @@ if (!isBuild) { const css = await getStyleTagContentIncluding('.src-import[data-v-') const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": "AAAA;EACE,UAAU;AACZ", - "sources": Array [ + "sources": [ "/root/src-import/src-import.css", ], - "sourcesContent": Array [ + "sourcesContent": [ ".src-import { color: red; } @@ -335,13 +335,13 @@ if (!isBuild) { const css = await getStyleTagContentIncluding('.src-import-sass[data-v-') const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": "AAAA;EACE;;ACCF;EACE", - "sources": Array [ + "sources": [ "/root/src-import/src-import-imported.sass", "/root/src-import/src-import.sass", ], - "sourcesContent": Array [ + "sourcesContent": [ ".src-import-sass-imported color: red ", @@ -355,8 +355,4 @@ if (!isBuild) { } `) }) -} else { - test('this file only includes test for serve', () => { - expect(true).toBe(true) - }) -} +}) diff --git a/playground/vue-sourcemap/vite.config.js b/playground/vue-sourcemap/vite.config.ts similarity index 62% rename from playground/vue-sourcemap/vite.config.js rename to playground/vue-sourcemap/vite.config.ts index 2a48cad3cb00d4..dbfa81dbeb1144 100644 --- a/playground/vue-sourcemap/vite.config.js +++ b/playground/vue-sourcemap/vite.config.ts @@ -1,9 +1,7 @@ -const vuePlugin = require('@vitejs/plugin-vue') +import vuePlugin from '@vitejs/plugin-vue' +import { defineConfig } from 'vite' -/** - * @type {import('vite').UserConfig} - */ -module.exports = { +export default defineConfig({ css: { devSourcemap: true, preprocessorOptions: { @@ -16,4 +14,4 @@ module.exports = { build: { sourcemap: true } -} +}) diff --git a/playground/vue/__tests__/vue.spec.ts b/playground/vue/__tests__/vue.spec.ts index 0bce5d1e1a03f5..f790bd612bfa9e 100644 --- a/playground/vue/__tests__/vue.spec.ts +++ b/playground/vue/__tests__/vue.spec.ts @@ -1,4 +1,10 @@ -import { editFile, getBg, getColor, isBuild, untilUpdated } from 'testUtils' +import { + editFile, + getBg, + getColor, + isBuild, + untilUpdated +} from '../../testUtils' test('should render', async () => { expect(await page.textContent('h1')).toMatch('Vue SFCs') diff --git a/playground/worker/__tests__/es/es-worker.spec.ts b/playground/worker/__tests__/es/es-worker.spec.ts index 61215f931c77dc..b836b081357e2e 100644 --- a/playground/worker/__tests__/es/es-worker.spec.ts +++ b/playground/worker/__tests__/es/es-worker.spec.ts @@ -44,7 +44,7 @@ const waitSharedWorkerTick = ( } )(0) -test.concurrent.each([[true], [false]])('shared worker', async (doTick) => { +test.each([[true], [false]])('shared worker', async (doTick) => { if (doTick) { await page.click('.tick-shared') } @@ -59,10 +59,10 @@ test('worker emitted and import.meta.url in nested worker (serve)', async () => ) }) -if (isBuild) { - const assetsDir = path.resolve(testDir, 'dist/es/assets') +describe.runIf(isBuild)('build', () => { // assert correct files test('inlined code generation', async () => { + const assetsDir = path.resolve(testDir(), 'dist/es/assets') const files = fs.readdirSync(assetsDir) expect(files.length).toBe(26) const index = files.find((f) => f.includes('main-module')) @@ -92,7 +92,7 @@ if (isBuild) { '"type":"constructor"' ) }) -} +}) test('module worker', async () => { expect(await page.textContent('.shared-worker-import-meta-url')).toMatch( diff --git a/playground/worker/__tests__/iife/worker.spec.ts b/playground/worker/__tests__/iife/worker.spec.ts index f49666e4918a25..cfa7dfe2e4537b 100644 --- a/playground/worker/__tests__/iife/worker.spec.ts +++ b/playground/worker/__tests__/iife/worker.spec.ts @@ -2,6 +2,7 @@ import fs from 'fs' import path from 'path' import { untilUpdated, isBuild, testDir } from '../../../testUtils' import type { Page } from 'playwright-chromium' +import { test } from 'vitest' test('normal', async () => { await page.click('.ping') @@ -44,7 +45,7 @@ const waitSharedWorkerTick = ( } )(0) -test.concurrent.each([[true], [false]])('shared worker', async (doTick) => { +test.each([[true], [false]])('shared worker', async (doTick) => { if (doTick) { await page.click('.tick-shared') } @@ -59,10 +60,10 @@ test('worker emitted and import.meta.url in nested worker (serve)', async () => ) }) -if (isBuild) { - const assetsDir = path.resolve(testDir, 'dist/iife/assets') +describe.runIf(isBuild)('build', () => { // assert correct files test('inlined code generation', async () => { + const assetsDir = path.resolve(testDir(), 'dist/iife/assets') const files = fs.readdirSync(assetsDir) expect(files.length).toBe(13) const index = files.find((f) => f.includes('main-module')) @@ -92,7 +93,7 @@ if (isBuild) { '"type":"constructor"' ) }) -} +}) test('module worker', async () => { expect(await page.textContent('.shared-worker-import-meta-url')).toMatch( diff --git a/playground/worker/__tests__/sourcemap-hidden/sourcemap-hidden-worker.spec.ts b/playground/worker/__tests__/sourcemap-hidden/sourcemap-hidden-worker.spec.ts index e4cb3318ebd5f5..ce2c52b5c98840 100644 --- a/playground/worker/__tests__/sourcemap-hidden/sourcemap-hidden-worker.spec.ts +++ b/playground/worker/__tests__/sourcemap-hidden/sourcemap-hidden-worker.spec.ts @@ -1,12 +1,15 @@ import fs from 'fs' import path from 'path' -import { untilUpdated, isBuild, testDir } from '../../../testUtils' -import { Page } from 'playwright-chromium' +import { isBuild, testDir } from '../../../testUtils' -if (isBuild) { - const assetsDir = path.resolve(testDir, 'dist/iife-sourcemap-hidden/assets') +describe.runIf(isBuild)('build', () => { // assert correct files test('sourcemap generation for web workers', async () => { + const assetsDir = path.resolve( + testDir(), + 'dist/iife-sourcemap-hidden/assets' + ) + const files = fs.readdirSync(assetsDir) // should have 2 worker chunk expect(files.length).toBe(26) @@ -110,13 +113,7 @@ if (isBuild) { `new Worker("/iife-sourcemap-hidden/assets/sub-worker` ) }) -} else { - // Workaround so that testing serve does not emit - // "Your test suite must contain at least one test" - test('true', () => { - expect(true).toBe(true) - }) -} +}) function getSourceMapUrl(code: string): string { const regex = /\/\/[#@]\s(?:source(?:Mapping)?URL)=\s*(\S+)/g diff --git a/playground/worker/__tests__/sourcemap-inline/sourcemap-inline-worker.spec.ts b/playground/worker/__tests__/sourcemap-inline/sourcemap-inline-worker.spec.ts index ceda7dae1fec7c..0fe97386f178df 100644 --- a/playground/worker/__tests__/sourcemap-inline/sourcemap-inline-worker.spec.ts +++ b/playground/worker/__tests__/sourcemap-inline/sourcemap-inline-worker.spec.ts @@ -1,12 +1,15 @@ import fs from 'fs' import path from 'path' -import { untilUpdated, isBuild, testDir } from '../../../testUtils' -import { Page } from 'playwright-chromium' +import { isBuild, testDir } from '../../../testUtils' -if (isBuild) { - const assetsDir = path.resolve(testDir, 'dist/iife-sourcemap-inline/assets') +describe.runIf(isBuild)('build', () => { // assert correct files test('sourcemap generation for web workers', async () => { + const assetsDir = path.resolve( + testDir(), + 'dist/iife-sourcemap-inline/assets' + ) + const files = fs.readdirSync(assetsDir) // should have 2 worker chunk expect(files.length).toBe(13) @@ -93,13 +96,7 @@ if (isBuild) { `new Worker("/iife-sourcemap-inline/assets/sub-worker` ) }) -} else { - // Workaround so that testing serve does not emit - // "Your test suite must contain at least one test" - test('true', () => { - expect(true).toBe(true) - }) -} +}) function getSourceMapUrl(code: string): string { const regex = /\/\/[#@]\s(?:source(?:Mapping)?URL)=\s*(\S+)/g diff --git a/playground/worker/__tests__/sourcemap/sourcemap-worker.spec.ts b/playground/worker/__tests__/sourcemap/sourcemap-worker.spec.ts index 04cc079b4bc289..3b074f24990f4b 100644 --- a/playground/worker/__tests__/sourcemap/sourcemap-worker.spec.ts +++ b/playground/worker/__tests__/sourcemap/sourcemap-worker.spec.ts @@ -1,12 +1,11 @@ import fs from 'fs' import path from 'path' -import { untilUpdated, isBuild, testDir } from '../../../testUtils' -import { Page } from 'playwright-chromium' +import { isBuild, testDir } from '../../../testUtils' -if (isBuild) { - const assetsDir = path.resolve(testDir, 'dist/iife-sourcemap/assets') +describe.runIf(isBuild)('build', () => { // assert correct files test('sourcemap generation for web workers', async () => { + const assetsDir = path.resolve(testDir(), 'dist/iife-sourcemap/assets') const files = fs.readdirSync(assetsDir) // should have 2 worker chunk expect(files.length).toBe(26) @@ -112,13 +111,7 @@ if (isBuild) { `new Worker("/iife-sourcemap/assets/sub-worker` ) }) -} else { - // Workaround so that testing serve does not emit - // "Your test suite must contain at least one test" - test('true', () => { - expect(true).toBe(true) - }) -} +}) function getSourceMapUrl(code: string): string { const regex = /\/\/[#@]\s(?:source(?:Mapping)?URL)=\s*(\S+)/g diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1a06a82b104080..18dbe1e00545ac 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,8 +11,8 @@ importers: .: specifiers: '@microsoft/api-extractor': ^7.23.1 + '@types/babel__core': ^7.1.19 '@types/fs-extra': ^9.0.13 - '@types/jest': ^27.5.0 '@types/node': ^17.0.31 '@types/prompts': ^2.4.0 '@types/semver': ^7.3.9 @@ -26,7 +26,7 @@ importers: eslint-plugin-node: ^11.1.0 execa: ^5.1.1 fs-extra: ^10.1.0 - jest: ^27.5.1 + kill-port: ^1.6.1 lint-staged: ^12.4.1 minimist: ^1.2.6 node-fetch: ^2.6.7 @@ -40,16 +40,15 @@ importers: semver: ^7.3.7 simple-git-hooks: ^2.7.0 sirv: ^2.0.2 - ts-jest: ^27.1.4 ts-node: ^10.7.0 typescript: ^4.6.4 vite: workspace:* vitepress: ^0.22.4 - vitest: ^0.10.5 + vitest: ^0.12.4 devDependencies: '@microsoft/api-extractor': 7.23.1 + '@types/babel__core': 7.1.19 '@types/fs-extra': 9.0.13 - '@types/jest': 27.5.0 '@types/node': 17.0.31 '@types/prompts': 2.4.0 '@types/semver': 7.3.9 @@ -63,7 +62,7 @@ importers: eslint-plugin-node: 11.1.0_eslint@8.15.0 execa: 5.1.1 fs-extra: 10.1.0 - jest: 27.5.1_ts-node@10.7.0 + kill-port: 1.6.1 lint-staged: 12.4.1 minimist: 1.2.6 node-fetch: 2.6.7 @@ -77,12 +76,11 @@ importers: semver: 7.3.7 simple-git-hooks: 2.7.0 sirv: 2.0.2 - ts-jest: 27.1.4_edb1f862ecf73b6f0cc1f906c6266936 ts-node: 10.7.0_5f3e12794cebfbf3197131903b74d233 typescript: 4.6.4 vite: link:packages/vite vitepress: 0.22.4 - vitest: 0.10.5 + vitest: 0.12.4 packages/create-vite: specifiers: @@ -1108,6 +1106,7 @@ packages: /@babel/compat-data/7.17.10: resolution: {integrity: sha512-GZt/TCsG70Ms19gfZO1tM4CVnXsPgEPBCpJu+Qz3L0LUDsY5nZqFZglIoPC1kIYOtNBZlrnFT+klg12vFGZXrw==} engines: {node: '>=6.9.0'} + dev: false /@babel/core/7.17.10: resolution: {integrity: sha512-liKoppandF3ZcBnIYFjfSDHZLKdLHGJRkoWtG8zQyGJBQfIYobpnVGI5+pLBNtS6psFLDzyq8+h5HiVljW9PNA==} @@ -1130,6 +1129,7 @@ packages: semver: 6.3.0 transitivePeerDependencies: - supports-color + dev: false /@babel/generator/7.17.10: resolution: {integrity: sha512-46MJZZo9y3o4kmhBVc7zW7i8dtR1oIK/sdO5NcfcZRhTGYi+KKJRtHNgsU6c4VUcJmUNV/LQdebD/9Dlv4K+Tg==} @@ -1138,6 +1138,7 @@ packages: '@babel/types': 7.17.10 '@jridgewell/gen-mapping': 0.1.1 jsesc: 2.5.2 + dev: false /@babel/helper-annotate-as-pure/7.16.7: resolution: {integrity: sha512-s6t2w/IPQVTAET1HitoowRGXooX8mCgtuP5195wD/QJPV6wYjpujCGF7JuMODVX2ZAJOf1GT6DT9MHEZvLOFSw==} @@ -1157,6 +1158,7 @@ packages: '@babel/helper-validator-option': 7.16.7 browserslist: 4.20.3 semver: 6.3.0 + dev: false /@babel/helper-create-class-features-plugin/7.17.9_@babel+core@7.17.10: resolution: {integrity: sha512-kUjip3gruz6AJKOq5i3nC6CoCEEF/oHH3cp6tOZhB+IyyyPyW0g1Gfsxn3mkk6S08pIA2y8GQh609v9G/5sHVQ==} @@ -1181,6 +1183,7 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/types': 7.17.10 + dev: false /@babel/helper-function-name/7.17.9: resolution: {integrity: sha512-7cRisGlVtiVqZ0MW0/yFB4atgpGLWEHUVYnb448hZK4x+vih0YO5UoS11XIYtZYqHd0dIPMdUSv8q5K4LdMnIg==} @@ -1188,12 +1191,14 @@ packages: dependencies: '@babel/template': 7.16.7 '@babel/types': 7.17.10 + dev: false /@babel/helper-hoist-variables/7.16.7: resolution: {integrity: sha512-m04d/0Op34H5v7pbZw6pSKP7weA6lsMvfiIAMeIvkY/R4xQtBSMFEigu9QTZ2qB/9l22vsxtM8a+Q8CzD255fg==} engines: {node: '>=6.9.0'} dependencies: '@babel/types': 7.17.10 + dev: false /@babel/helper-member-expression-to-functions/7.17.7: resolution: {integrity: sha512-thxXgnQ8qQ11W2wVUObIqDL4p148VMxkt5T/qpN5k2fboRyzFGFmKsTGViquyM5QHKUy48OZoca8kw4ajaDPyw==} @@ -1222,6 +1227,7 @@ packages: '@babel/types': 7.17.10 transitivePeerDependencies: - supports-color + dev: false /@babel/helper-optimise-call-expression/7.16.7: resolution: {integrity: sha512-EtgBhg7rd/JcnpZFXpBy0ze1YRfdm7BnBX4uKMBd3ixa3RGAE002JZB66FJyNH7g0F38U05pXmA5P8cBh7z+1w==} @@ -1252,12 +1258,14 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/types': 7.17.10 + dev: false /@babel/helper-split-export-declaration/7.16.7: resolution: {integrity: sha512-xbWoy/PFoxSWazIToT9Sif+jJTlrMcndIsaOKvTA6u7QEo7ilkRZpjew18/W3c7nm8fXdUDXh02VXTbZ0pGDNw==} engines: {node: '>=6.9.0'} dependencies: '@babel/types': 7.17.10 + dev: false /@babel/helper-validator-identifier/7.16.7: resolution: {integrity: sha512-hsEnFemeiW4D08A5gUAZxLBTXpZ39P+a+DGDsHw1yxqyQ/jzFEnxf5uTEGp+3bzAbNOxU1paTgYS4ECU/IgfDw==} @@ -1266,6 +1274,7 @@ packages: /@babel/helper-validator-option/7.16.7: resolution: {integrity: sha512-TRtenOuRUVo9oIQGPC5G9DgK4743cdxvtOw0weQNpZXaS16SCBi5MNjZF8vba3ETURjZpTbVn7Vvcf2eAwFozQ==} engines: {node: '>=6.9.0'} + dev: false /@babel/helpers/7.17.9: resolution: {integrity: sha512-cPCt915ShDWUEzEp3+UNRktO2n6v49l5RSnG9M5pS24hA+2FAc5si+Pn1i4VVbQQ+jh+bIZhPFQOJOzbrOYY1Q==} @@ -1276,6 +1285,7 @@ packages: '@babel/types': 7.17.10 transitivePeerDependencies: - supports-color + dev: false /@babel/highlight/7.17.9: resolution: {integrity: sha512-J9PfEKCbFIv2X5bjTMiZu6Vf341N05QIY+d6FvVKynkG1S7G0j3I0QoRtWIrXhZ+/Nlb5Q0MzqL7TokEJ5BNHg==} @@ -1300,33 +1310,6 @@ packages: '@babel/plugin-syntax-pipeline-operator': 7.17.0 dev: true - /@babel/plugin-syntax-async-generators/7.8.4_@babel+core@7.17.10: - resolution: {integrity: sha512-tycmZxkGfZaxhMRbXlPXuVFpdWlXpir2W4AMhSJgRKzk/eDlIXOhb2LHWoLpDF7TEHylV5zNhykX6KAgHJmTNw==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - - /@babel/plugin-syntax-bigint/7.8.3_@babel+core@7.17.10: - resolution: {integrity: sha512-wnTnFlG+YxQm3vDxpGE57Pj0srRU4sHE/mDkt1qv2YJJSeUAec2ma4WLUnUPeKjyrfntVwe/N6dCXpU+zL3Npg==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - - /@babel/plugin-syntax-class-properties/7.12.13_@babel+core@7.17.10: - resolution: {integrity: sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.17.10: resolution: {integrity: sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==} peerDependencies: @@ -1334,15 +1317,7 @@ packages: dependencies: '@babel/core': 7.17.10 '@babel/helper-plugin-utils': 7.16.7 - - /@babel/plugin-syntax-json-strings/7.8.3_@babel+core@7.17.10: - resolution: {integrity: sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true + dev: false /@babel/plugin-syntax-jsx/7.16.7: resolution: {integrity: sha512-Esxmk7YjA8QysKeT3VhTXvF6y77f/a91SIs4pWb4H2eWGQkCKFgQaG6hdoEVZtGsrAcb2K5BW66XsOErD4WU3Q==} @@ -1362,60 +1337,6 @@ packages: '@babel/helper-plugin-utils': 7.16.7 dev: false - /@babel/plugin-syntax-logical-assignment-operators/7.10.4_@babel+core@7.17.10: - resolution: {integrity: sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - - /@babel/plugin-syntax-nullish-coalescing-operator/7.8.3_@babel+core@7.17.10: - resolution: {integrity: sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - - /@babel/plugin-syntax-numeric-separator/7.10.4_@babel+core@7.17.10: - resolution: {integrity: sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - - /@babel/plugin-syntax-object-rest-spread/7.8.3_@babel+core@7.17.10: - resolution: {integrity: sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - - /@babel/plugin-syntax-optional-catch-binding/7.8.3_@babel+core@7.17.10: - resolution: {integrity: sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - - /@babel/plugin-syntax-optional-chaining/7.8.3_@babel+core@7.17.10: - resolution: {integrity: sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - /@babel/plugin-syntax-pipeline-operator/7.17.0: resolution: {integrity: sha512-vNE+4pNAOk2Q0BkyTf+XMwZ53vMDJ7Ic/Z85sruaJfJJ+4O5k/61z2a4Xj3CSl9kKRlXOALbsxWca0vZz7ENbw==} engines: {node: '>=6.9.0'} @@ -1425,16 +1346,6 @@ packages: '@babel/helper-plugin-utils': 7.16.7 dev: true - /@babel/plugin-syntax-top-level-await/7.14.5_@babel+core@7.17.10: - resolution: {integrity: sha512-hx++upLv5U1rgYfwe1xBQUhRmU41NEvpUvrp8jkrSCdvGSnM5/qdRMtylJ6PG5OFkBaHkbTAKTnd3/YyESRHFw==} - engines: {node: '>=6.9.0'} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.17.10 - '@babel/helper-plugin-utils': 7.16.7 - dev: true - /@babel/plugin-syntax-typescript/7.17.10_@babel+core@7.17.10: resolution: {integrity: sha512-xJefea1DWXW09pW4Tm9bjwVlPDyYA2it3fWlmEjpYz6alPvTUjL0EOzNzI/FEOyI3r4/J7uVH5UqKgl1TQ5hqQ==} engines: {node: '>=6.9.0'} @@ -1443,6 +1354,7 @@ packages: dependencies: '@babel/core': 7.17.10 '@babel/helper-plugin-utils': 7.16.7 + dev: false /@babel/plugin-transform-react-jsx-development/7.16.7_@babel+core@7.17.10: resolution: {integrity: sha512-RMvQWvpla+xy6MlBpPlrKZCMRs2AGiHOGHY3xRwl0pEeim348dDyxeH4xBsMPbIMhujeq7ihE702eM2Ew0Wo+A==} @@ -1520,6 +1432,7 @@ packages: '@babel/code-frame': 7.16.7 '@babel/parser': 7.17.10 '@babel/types': 7.17.10 + dev: false /@babel/traverse/7.17.10: resolution: {integrity: sha512-VmbrTHQteIdUUQNTb+zE12SHS/xQVIShmBPhlNP12hD5poF2pbITW1Z4172d03HegaQWhLffdkRJYtAzp0AGcw==} @@ -1537,6 +1450,7 @@ packages: globals: 11.12.0 transitivePeerDependencies: - supports-color + dev: false /@babel/types/7.17.10: resolution: {integrity: sha512-9O26jG0mBYfGkUYCYZRnBwbVLd1UZOICEr2Em6InB6jVfsAv1GKgwXHmrSg+WFWDmeKTA6vyTZiN8tCSM5Oo3A==} @@ -1545,10 +1459,6 @@ packages: '@babel/helper-validator-identifier': 7.16.7 to-fast-properties: 2.0.0 - /@bcoe/v8-coverage/0.2.3: - resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} - dev: true - /@cloudflare/workers-types/2.2.2: resolution: {integrity: sha512-kaMn2rueJ0PL1TYVGknTCh0X0x0d9G+FNXAFep7/4uqecEZoQb/63o6rOmMuiqI09zLuHV6xhKRXinokV/MY9A==} dev: true @@ -1716,213 +1626,6 @@ packages: resolution: {integrity: sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==} dev: true - /@istanbuljs/load-nyc-config/1.1.0: - resolution: {integrity: sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==} - engines: {node: '>=8'} - dependencies: - camelcase: 5.3.1 - find-up: 4.1.0 - get-package-type: 0.1.0 - js-yaml: 3.14.1 - resolve-from: 5.0.0 - dev: true - - /@istanbuljs/schema/0.1.3: - resolution: {integrity: sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==} - engines: {node: '>=8'} - dev: true - - /@jest/console/27.5.1: - resolution: {integrity: sha512-kZ/tNpS3NXn0mlXXXPNuDZnb4c0oZ20r4K5eemM2k30ZC3G0T02nXUvyhf5YdbXWHPEJLc9qGLxEZ216MdL+Zg==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - chalk: 4.1.2 - jest-message-util: 27.5.1 - jest-util: 27.5.1 - slash: 3.0.0 - dev: true - - /@jest/core/27.5.1_ts-node@10.7.0: - resolution: {integrity: sha512-AK6/UTrvQD0Cd24NSqmIA6rKsu0tKIxfiCducZvqxYdmMisOYAsdItspT+fQDQYARPf8XgjAFZi0ogW2agH5nQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - peerDependencies: - node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 - peerDependenciesMeta: - node-notifier: - optional: true - dependencies: - '@jest/console': 27.5.1 - '@jest/reporters': 27.5.1 - '@jest/test-result': 27.5.1 - '@jest/transform': 27.5.1 - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - ansi-escapes: 4.3.2 - chalk: 4.1.2 - emittery: 0.8.1 - exit: 0.1.2 - graceful-fs: 4.2.10 - jest-changed-files: 27.5.1 - jest-config: 27.5.1_ts-node@10.7.0 - jest-haste-map: 27.5.1 - jest-message-util: 27.5.1 - jest-regex-util: 27.5.1 - jest-resolve: 27.5.1 - jest-resolve-dependencies: 27.5.1 - jest-runner: 27.5.1 - jest-runtime: 27.5.1 - jest-snapshot: 27.5.1 - jest-util: 27.5.1 - jest-validate: 27.5.1 - jest-watcher: 27.5.1 - micromatch: 4.0.5 - rimraf: 3.0.2 - slash: 3.0.0 - strip-ansi: 6.0.1 - transitivePeerDependencies: - - bufferutil - - canvas - - supports-color - - ts-node - - utf-8-validate - dev: true - - /@jest/environment/27.5.1: - resolution: {integrity: sha512-/WQjhPJe3/ghaol/4Bq480JKXV/Rfw8nQdN7f41fM8VDHLcxKXou6QyXAh3EFr9/bVG3x74z1NWDkP87EiY8gA==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/fake-timers': 27.5.1 - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - jest-mock: 27.5.1 - dev: true - - /@jest/fake-timers/27.5.1: - resolution: {integrity: sha512-/aPowoolwa07k7/oM3aASneNeBGCmGQsc3ugN4u6s4C/+s5M64MFo/+djTdiwcbQlRfFElGuDXWzaWj6QgKObQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/types': 27.5.1 - '@sinonjs/fake-timers': 8.1.0 - '@types/node': 17.0.31 - jest-message-util: 27.5.1 - jest-mock: 27.5.1 - jest-util: 27.5.1 - dev: true - - /@jest/globals/27.5.1: - resolution: {integrity: sha512-ZEJNB41OBQQgGzgyInAv0UUfDDj3upmHydjieSxFvTRuZElrx7tXg/uVQ5hYVEwiXs3+aMsAeEc9X7xiSKCm4Q==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/environment': 27.5.1 - '@jest/types': 27.5.1 - expect: 27.5.1 - dev: true - - /@jest/reporters/27.5.1: - resolution: {integrity: sha512-cPXh9hWIlVJMQkVk84aIvXuBB4uQQmFqZiacloFuGiP3ah1sbCxCosidXFDfqG8+6fO1oR2dTJTlsOy4VFmUfw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - peerDependencies: - node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 - peerDependenciesMeta: - node-notifier: - optional: true - dependencies: - '@bcoe/v8-coverage': 0.2.3 - '@jest/console': 27.5.1 - '@jest/test-result': 27.5.1 - '@jest/transform': 27.5.1 - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - chalk: 4.1.2 - collect-v8-coverage: 1.0.1 - exit: 0.1.2 - glob: 7.2.0 - graceful-fs: 4.2.10 - istanbul-lib-coverage: 3.2.0 - istanbul-lib-instrument: 5.2.0 - istanbul-lib-report: 3.0.0 - istanbul-lib-source-maps: 4.0.1 - istanbul-reports: 3.1.4 - jest-haste-map: 27.5.1 - jest-resolve: 27.5.1 - jest-util: 27.5.1 - jest-worker: 27.5.1 - slash: 3.0.0 - source-map: 0.6.1 - string-length: 4.0.2 - terminal-link: 2.1.1 - v8-to-istanbul: 8.1.1 - transitivePeerDependencies: - - supports-color - dev: true - - /@jest/source-map/27.5.1: - resolution: {integrity: sha512-y9NIHUYF3PJRlHk98NdC/N1gl88BL08aQQgu4k4ZopQkCw9t9cV8mtl3TV8b/YCB8XaVTFrmUTAJvjsntDireg==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - callsites: 3.1.0 - graceful-fs: 4.2.10 - source-map: 0.6.1 - dev: true - - /@jest/test-result/27.5.1: - resolution: {integrity: sha512-EW35l2RYFUcUQxFJz5Cv5MTOxlJIQs4I7gxzi2zVU7PJhOwfYq1MdC5nhSmYjX1gmMmLPvB3sIaC+BkcHRBfag==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/console': 27.5.1 - '@jest/types': 27.5.1 - '@types/istanbul-lib-coverage': 2.0.4 - collect-v8-coverage: 1.0.1 - dev: true - - /@jest/test-sequencer/27.5.1: - resolution: {integrity: sha512-LCheJF7WB2+9JuCS7VB/EmGIdQuhtqjRNI9A43idHv3E4KltCTsPsLxvdaubFHSYwY/fNjMWjl6vNRhDiN7vpQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/test-result': 27.5.1 - graceful-fs: 4.2.10 - jest-haste-map: 27.5.1 - jest-runtime: 27.5.1 - transitivePeerDependencies: - - supports-color - dev: true - - /@jest/transform/27.5.1: - resolution: {integrity: sha512-ipON6WtYgl/1329g5AIJVbUuEh0wZVbdpGwC99Jw4LwuoBNS95MVphU6zOeD9pDkon+LLbFL7lOQRapbB8SCHw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@babel/core': 7.17.10 - '@jest/types': 27.5.1 - babel-plugin-istanbul: 6.1.1 - chalk: 4.1.2 - convert-source-map: 1.8.0 - fast-json-stable-stringify: 2.1.0 - graceful-fs: 4.2.10 - jest-haste-map: 27.5.1 - jest-regex-util: 27.5.1 - jest-util: 27.5.1 - micromatch: 4.0.5 - pirates: 4.0.5 - slash: 3.0.0 - source-map: 0.6.1 - write-file-atomic: 3.0.3 - transitivePeerDependencies: - - supports-color - dev: true - - /@jest/types/27.5.1: - resolution: {integrity: sha512-Cx46iJ9QpwQTjIdq5VJu2QTMMs3QlEjI0x1QbBP5W1+nMzyc2XmimiRR/CbX9TO0cPTeUlxWMOu8mslYsJ8DEw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@types/istanbul-lib-coverage': 2.0.4 - '@types/istanbul-reports': 3.0.1 - '@types/node': 17.0.31 - '@types/yargs': 16.0.4 - chalk: 4.1.2 - dev: true - /@jridgewell/gen-mapping/0.1.1: resolution: {integrity: sha512-sQXCasFk+U8lWYEe66WxRDOE9PjVz4vSM51fTu3Hw+ClTpUSQb718772vH3pyS5pShp6lvQM7SxgIDXXXmOX7w==} engines: {node: '>=6.0.0'} @@ -2190,23 +1893,6 @@ packages: string-argv: 0.3.1 dev: true - /@sinonjs/commons/1.8.3: - resolution: {integrity: sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==} - dependencies: - type-detect: 4.0.8 - dev: true - - /@sinonjs/fake-timers/8.1.0: - resolution: {integrity: sha512-OAPJUAtgeINhh/TAlUID4QTs53Njm7xzddaVlEs/SXwgtiD1tW22zAB/W1wdqfrpmikgaWQ9Fw6Ws+hsiRm5Vg==} - dependencies: - '@sinonjs/commons': 1.8.3 - dev: true - - /@tootallnate/once/1.1.2: - resolution: {integrity: sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==} - engines: {node: '>= 6'} - dev: true - /@tsconfig/node10/1.0.8: resolution: {integrity: sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==} dev: true @@ -2310,39 +1996,10 @@ packages: '@types/node': 17.0.31 dev: true - /@types/graceful-fs/4.1.5: - resolution: {integrity: sha512-anKkLmZZ+xm4p8JWBf4hElkM4XR+EZeA2M9BAkkTldmcyDY4mbdIJnRghDJH3Ov5ooY7/UAoENtmdMSkaAd7Cw==} - dependencies: - '@types/node': 17.0.31 - dev: true - /@types/hash-sum/1.0.0: resolution: {integrity: sha512-FdLBT93h3kcZ586Aee66HPCVJ6qvxVjBlDWNmxSGSbCZe9hTsjRKdSsl4y1T+3zfujxo9auykQMnFsfyHWD7wg==} dev: true - /@types/istanbul-lib-coverage/2.0.4: - resolution: {integrity: sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==} - dev: true - - /@types/istanbul-lib-report/3.0.0: - resolution: {integrity: sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==} - dependencies: - '@types/istanbul-lib-coverage': 2.0.4 - dev: true - - /@types/istanbul-reports/3.0.1: - resolution: {integrity: sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==} - dependencies: - '@types/istanbul-lib-report': 3.0.0 - dev: true - - /@types/jest/27.5.0: - resolution: {integrity: sha512-9RBFx7r4k+msyj/arpfaa0WOOEcaAZNmN+j80KFbFCoSqCJGHTz7YMAMGQW9Xmqm5w6l5c25vbSjMwlikJi5+g==} - dependencies: - jest-matcher-utils: 27.5.1 - pretty-format: 27.5.1 - dev: true - /@types/json-schema/7.0.11: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} dev: true @@ -2388,10 +2045,6 @@ packages: /@types/parse-json/4.0.0: resolution: {integrity: sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==} - /@types/prettier/2.6.0: - resolution: {integrity: sha512-G/AdOadiZhnJp0jXCaBQU449W2h716OW/EoXeYkCytxKL06X1WCXB4DZpp8TpZ8eyIJVS1cw4lrlkkSYU21cDw==} - dev: true - /@types/prompts/2.4.0: resolution: {integrity: sha512-7th8Opn+0XlN0O6qzO7dXOPwL6rigq/EwRS2DntaTHwSw8cLaYKeAPt5dWEKHSL+ffVSUl1itTPUC06+FlsV4Q==} dev: true @@ -2420,10 +2073,6 @@ packages: resolution: {integrity: sha512-TgfOX+mGY/NyNxJLIbDWrO9DjGoVSW9+aB8H2yy1fy32jsvxijhmyJI9fDFgvz3YP4lvJaq9DzdR/M1bOgVc9g==} dev: true - /@types/stack-utils/2.0.1: - resolution: {integrity: sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==} - dev: true - /@types/stylus/0.48.37: resolution: {integrity: sha512-IkLnS/GzdDK3rgAmQwLr8LqPvUMa43SHlCnXqsfXNukwaIpiXBNgSHil3ro8aemhF4k4ZiMoa4URE7mwBHPJnQ==} dependencies: @@ -2436,16 +2085,6 @@ packages: '@types/node': 17.0.31 dev: true - /@types/yargs-parser/21.0.0: - resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} - dev: true - - /@types/yargs/16.0.4: - resolution: {integrity: sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==} - dependencies: - '@types/yargs-parser': 21.0.0 - dev: true - /@types/yauzl/2.10.0: resolution: {integrity: sha512-Cn6WYCm0tXv8p6k+A8PvbDG763EDpBoTzHdA+Q/MF6H3sapGjCm9NzoaJncJS9tUKSuCoDs9XHxYYsQDgxR6kw==} requiresBuild: true @@ -2691,10 +2330,6 @@ packages: through: 2.3.8 dev: true - /abab/2.0.6: - resolution: {integrity: sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==} - dev: true - /abbrev/1.1.1: resolution: {integrity: sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==} dev: false @@ -2707,13 +2342,6 @@ packages: negotiator: 0.6.3 dev: true - /acorn-globals/6.0.0: - resolution: {integrity: sha512-ZQl7LOWaF5ePqqcX4hLuv/bLXYQNfNWw2c0/yX/TsPRKamzHcTGQnlCjHT3TsmkOUVEPS3crCxiPfdzE/Trlhg==} - dependencies: - acorn: 7.4.1 - acorn-walk: 7.2.0 - dev: true - /acorn-jsx/5.3.2_acorn@8.7.1: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: @@ -2733,6 +2361,7 @@ packages: /acorn-walk/7.2.0: resolution: {integrity: sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==} engines: {node: '>=0.4.0'} + dev: false /acorn-walk/8.2.0: resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} @@ -2826,11 +2455,6 @@ packages: dependencies: color-convert: 2.0.1 - /ansi-styles/5.2.0: - resolution: {integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==} - engines: {node: '>=10'} - dev: true - /ansi-styles/6.1.0: resolution: {integrity: sha512-VbqNsoz55SYGczauuup0MFUyXNQviSpFTj1RQtFzmQLk18qbVSpTFFGMT293rmDaQuKCT6InmbuEyUne4mTuxQ==} engines: {node: '>=12'} @@ -2920,10 +2544,6 @@ packages: engines: {node: '>=8'} dev: true - /asynckit/0.4.0: - resolution: {integrity: sha1-x57Zf380y48robyXkLzDZkdLS3k=} - dev: true - /atob/2.1.2: resolution: {integrity: sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==} engines: {node: '>= 4.5.0'} @@ -2953,89 +2573,16 @@ packages: - debug dev: false - /babel-jest/27.5.1_@babel+core@7.17.10: - resolution: {integrity: sha512-cdQ5dXjGRd0IBRATiQ4mZGlGlRE8kJpjPOixdNRdT+m3UcNqmYWN6rK6nvtXYfY3D76cb8s/O1Ss8ea24PIwcg==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - peerDependencies: - '@babel/core': ^7.8.0 + /babel-plugin-macros/2.8.0: + resolution: {integrity: sha512-SEP5kJpfGYqYKpBrj5XU3ahw5p5GOHJ0U5ssOSQ/WBVdwkD2Dzlce95exQTs3jOVWPPKLBN2rlEWkCK7dSmLvg==} dependencies: - '@babel/core': 7.17.10 - '@jest/transform': 27.5.1 - '@jest/types': 27.5.1 - '@types/babel__core': 7.1.19 - babel-plugin-istanbul: 6.1.1 - babel-preset-jest: 27.5.1_@babel+core@7.17.10 - chalk: 4.1.2 - graceful-fs: 4.2.10 - slash: 3.0.0 - transitivePeerDependencies: - - supports-color - dev: true + '@babel/runtime': 7.17.9 + cosmiconfig: 6.0.0 + resolve: 1.22.0 - /babel-plugin-istanbul/6.1.1: - resolution: {integrity: sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==} - engines: {node: '>=8'} - dependencies: - '@babel/helper-plugin-utils': 7.16.7 - '@istanbuljs/load-nyc-config': 1.1.0 - '@istanbuljs/schema': 0.1.3 - istanbul-lib-instrument: 5.2.0 - test-exclude: 6.0.0 - transitivePeerDependencies: - - supports-color - dev: true - - /babel-plugin-jest-hoist/27.5.1: - resolution: {integrity: sha512-50wCwD5EMNW4aRpOwtqzyZHIewTYNxLA4nhB+09d8BIssfNfzBRhkBIHiaPv1Si226TQSvp8gxAJm2iY2qs2hQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@babel/template': 7.16.7 - '@babel/types': 7.17.10 - '@types/babel__core': 7.1.19 - '@types/babel__traverse': 7.17.1 - dev: true - - /babel-plugin-macros/2.8.0: - resolution: {integrity: sha512-SEP5kJpfGYqYKpBrj5XU3ahw5p5GOHJ0U5ssOSQ/WBVdwkD2Dzlce95exQTs3jOVWPPKLBN2rlEWkCK7dSmLvg==} - dependencies: - '@babel/runtime': 7.17.9 - cosmiconfig: 6.0.0 - resolve: 1.22.0 - - /babel-preset-current-node-syntax/1.0.1_@babel+core@7.17.10: - resolution: {integrity: sha512-M7LQ0bxarkxQoN+vz5aJPsLBn77n8QgTFmo8WK0/44auK2xlCXrYcUxHFxgU7qW5Yzw/CjmLRK2uJzaCd7LvqQ==} - peerDependencies: - '@babel/core': ^7.0.0 - dependencies: - '@babel/core': 7.17.10 - '@babel/plugin-syntax-async-generators': 7.8.4_@babel+core@7.17.10 - '@babel/plugin-syntax-bigint': 7.8.3_@babel+core@7.17.10 - '@babel/plugin-syntax-class-properties': 7.12.13_@babel+core@7.17.10 - '@babel/plugin-syntax-import-meta': 7.10.4_@babel+core@7.17.10 - '@babel/plugin-syntax-json-strings': 7.8.3_@babel+core@7.17.10 - '@babel/plugin-syntax-logical-assignment-operators': 7.10.4_@babel+core@7.17.10 - '@babel/plugin-syntax-nullish-coalescing-operator': 7.8.3_@babel+core@7.17.10 - '@babel/plugin-syntax-numeric-separator': 7.10.4_@babel+core@7.17.10 - '@babel/plugin-syntax-object-rest-spread': 7.8.3_@babel+core@7.17.10 - '@babel/plugin-syntax-optional-catch-binding': 7.8.3_@babel+core@7.17.10 - '@babel/plugin-syntax-optional-chaining': 7.8.3_@babel+core@7.17.10 - '@babel/plugin-syntax-top-level-await': 7.14.5_@babel+core@7.17.10 - dev: true - - /babel-preset-jest/27.5.1_@babel+core@7.17.10: - resolution: {integrity: sha512-Nptf2FzlPCWYuJg41HBqXVT8ym6bXOevuCTbhxlUpjwtysGaIWFvDEjp4y+G7fl13FgOdjs7P/DmErqH7da0Ag==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - peerDependencies: - '@babel/core': ^7.0.0 - dependencies: - '@babel/core': 7.17.10 - babel-plugin-jest-hoist: 27.5.1 - babel-preset-current-node-syntax: 1.0.1_@babel+core@7.17.10 - dev: true - - /babel-walk/3.0.0-canary-5: - resolution: {integrity: sha512-GAwkz0AihzY5bkwIY5QDR+LvsRQgB/B+1foMPvi0FZPMl5fjD7ICiznUiBdLYMH1QYe6vqu4gWYytZOccLouFw==} - engines: {node: '>= 10.0.0'} + /babel-walk/3.0.0-canary-5: + resolution: {integrity: sha512-GAwkz0AihzY5bkwIY5QDR+LvsRQgB/B+1foMPvi0FZPMl5fjD7ICiznUiBdLYMH1QYe6vqu4gWYytZOccLouFw==} + engines: {node: '>= 10.0.0'} dependencies: '@babel/types': 7.17.10 dev: true @@ -3098,10 +2645,6 @@ packages: dependencies: fill-range: 7.0.1 - /browser-process-hrtime/1.0.0: - resolution: {integrity: sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==} - dev: true - /browserslist/4.20.3: resolution: {integrity: sha512-NBhymBQl1zM0Y5dQT/O+xiLP9/rzOIQdKM/eMJBAq7yBgaB6krIYLGejrwVYnSHZdqjscB1SPuAjHwxjvN6Wdg==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -3112,19 +2655,7 @@ packages: escalade: 3.1.1 node-releases: 2.0.4 picocolors: 1.0.0 - - /bs-logger/0.2.6: - resolution: {integrity: sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==} - engines: {node: '>= 6'} - dependencies: - fast-json-stable-stringify: 2.1.0 - dev: true - - /bser/2.1.1: - resolution: {integrity: sha512-gQxTNE/GAfIIrmHLUE3oJyp5FO6HRBfhjnw4/wMmA63ZGDJnWBmgY/lyQBpnDUkGmAhbSe39tx2d/iTOAfglwQ==} - dependencies: - node-int64: 0.4.0 - dev: true + dev: false /buffer-crc32/0.2.13: resolution: {integrity: sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=} @@ -3193,9 +2724,11 @@ packages: /camelcase/6.3.0: resolution: {integrity: sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==} engines: {node: '>=10'} + dev: false /caniuse-lite/1.0.30001338: resolution: {integrity: sha512-1gLHWyfVoRDsHieO+CaeYe7jSo/MT7D7lhaXUiwwbuR5BwQxORs0f1tAwUSQr3YbxRXJvxHM/PA5FfPQRnsPeQ==} + dev: false /chai/4.3.6: resolution: {integrity: sha512-bbcp3YfHCUzMOvKqsztczerVgBKSsEijCySNlHHbX3VG1nskvqjz5Rfso1gGwD6w6oOV3eI60pKuMOV5MV7p3Q==} @@ -3225,11 +2758,6 @@ packages: ansi-styles: 4.3.0 supports-color: 7.2.0 - /char-regex/1.0.2: - resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==} - engines: {node: '>=10'} - dev: true - /character-parser/2.2.0: resolution: {integrity: sha1-x84o821LzZdE5f/CxfzeHHMmH8A=} dependencies: @@ -3259,14 +2787,6 @@ packages: engines: {node: '>=10'} dev: false - /ci-info/3.3.0: - resolution: {integrity: sha512-riT/3vI5YpVH6/qomlDnJow6TBee2PBKSEpx3O32EGPYbWGIRsIlGRms3Sm74wYE1JMo8RnO04Hb12+v1J5ICw==} - dev: true - - /cjs-module-lexer/1.2.2: - resolution: {integrity: sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==} - dev: true - /cjstoesm/1.1.4_typescript@4.6.4: resolution: {integrity: sha512-cixLJwK2HS8R8J1jJcYwlrLxWUbdNms5EmVQuvP3O0CGvHNv2WVd2gnqTP/tbTEYzbgWiSYQBZDoAakqsSl94Q==} engines: {node: '>=10.0.0'} @@ -3335,15 +2855,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /co/4.6.0: - resolution: {integrity: sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=} - engines: {iojs: '>= 1.0.0', node: '>= 0.12.0'} - dev: true - - /collect-v8-coverage/1.0.1: - resolution: {integrity: sha512-iBPtljfCNcTKNAto0KEtDfZ3qzjJvqE3aTGZsbhjSBlorqpXJlaWWtPO35D+ZImoC3KWejX64o+yPGxhWSTzfg==} - dev: true - /color-convert/1.9.3: resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} dependencies: @@ -3395,13 +2906,6 @@ packages: engines: {node: '>=0.1.90'} dev: true - /combined-stream/1.0.8: - resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} - engines: {node: '>= 0.8'} - dependencies: - delayed-stream: 1.0.0 - dev: true - /commander/2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} dev: true @@ -3786,21 +3290,6 @@ packages: engines: {node: '>=4'} hasBin: true - /cssom/0.3.8: - resolution: {integrity: sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==} - dev: true - - /cssom/0.4.4: - resolution: {integrity: sha512-p3pvU7r1MyyqbTk+WbNJIgJjG2VmTIaB10rI93LzVPrmDJKkzKYMtxxyAvQXR/NS6otuzveI7+7BBq3SjBS2mw==} - dev: true - - /cssstyle/2.3.0: - resolution: {integrity: sha512-AZL67abkUzIuvcHqk7c09cezpGNcxUxU4Ioi/05xHk4DQeTkWmGYftIE6ctU6AEt+Gn4n1lDStOtj7FKycP71A==} - engines: {node: '>=8'} - dependencies: - cssom: 0.3.8 - dev: true - /csstype/2.6.20: resolution: {integrity: sha512-/WwNkdXfckNgw6S5R125rrW8ez139lBHWouiBvX8dfMFtcn6V81REDqnH7+CRpRipfYlyU1CmOnOxrmGcFOjeA==} @@ -3819,15 +3308,6 @@ packages: engines: {node: '>=8'} dev: true - /data-urls/2.0.0: - resolution: {integrity: sha512-X5eWTSXO/BJmpdIKCRuKUgSCgAN0OwliVK3yPKbwIWU1Tdw5BRajxlzMidvh+gwko9AfQ9zIj52pzF91Q3YAvQ==} - engines: {node: '>=10'} - dependencies: - abab: 2.0.6 - whatwg-mimetype: 2.3.0 - whatwg-url: 8.7.0 - dev: true - /dateformat/3.0.3: resolution: {integrity: sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==} dev: true @@ -3900,19 +3380,11 @@ packages: engines: {node: '>=0.10.0'} dev: true - /decimal.js/10.3.1: - resolution: {integrity: sha512-V0pfhfr8suzyPGOx3nmq4aHqabehUZn6Ch9kyFpV79TGDTWFmHqUqXdabR7QHqxzrYolF4+tVmJhUG4OURg5dQ==} - dev: true - /decode-uri-component/0.2.0: resolution: {integrity: sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=} engines: {node: '>=0.10'} dev: true - /dedent/0.7.0: - resolution: {integrity: sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw=} - dev: true - /deep-eql/3.0.1: resolution: {integrity: sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==} engines: {node: '>=0.12'} @@ -3946,11 +3418,6 @@ packages: resolution: {integrity: sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=} dev: false - /delayed-stream/1.0.0: - resolution: {integrity: sha1-3zrhmayt+31ECqrgsp4icrJOxhk=} - engines: {node: '>=0.4.0'} - dev: true - /delegate/3.2.0: resolution: {integrity: sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==} dev: false @@ -3979,11 +3446,6 @@ packages: engines: {node: '>=8'} dev: false - /detect-newline/3.1.0: - resolution: {integrity: sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==} - engines: {node: '>=8'} - dev: true - /detective/5.2.0: resolution: {integrity: sha512-6SsIx+nUUbuK0EthKjv0zrdnajCCXVYGmbYYiYjFVpzcjwEs/JMDZ8tPRG29J/HhN56t3GJp2cGSWDRjjot8Pg==} engines: {node: '>=0.8.0'} @@ -4005,11 +3467,6 @@ packages: resolution: {integrity: sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==} dev: false - /diff-sequences/27.5.1: - resolution: {integrity: sha512-k1gCAXAsNgLwEL+Y8Wvl+M6oEFj5bgazfZULpS5CneoPPXRaCCW7dm+q21Ky2VEE5X+VeRDBVg1Pcvvsr4TtNQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dev: true - /diff/4.0.2: resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} engines: {node: '>=0.3.1'} @@ -4037,13 +3494,6 @@ packages: resolution: {integrity: sha1-6oCxBqh1OHdOijpKWv4pPeSJ4Kk=} dev: true - /domexception/2.0.1: - resolution: {integrity: sha512-yxJ2mFy/sibVQlu5qHjOkf9J3K6zgmCxgJ94u2EdvDOV09H+32LtRswEcUsmUWN72pVLOEnTSRaIVVzVQgS0dg==} - engines: {node: '>=8'} - dependencies: - webidl-conversions: 5.0.0 - dev: true - /dot-prop/5.3.0: resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==} engines: {node: '>=8'} @@ -4075,11 +3525,7 @@ packages: /electron-to-chromium/1.4.137: resolution: {integrity: sha512-0Rcpald12O11BUogJagX3HsCN3FE83DSqWjgXoHo5a72KUKMSfI39XBgJpgNNxS9fuGzytaFjE06kZkiVFy2qA==} - - /emittery/0.8.1: - resolution: {integrity: sha512-uDfvUjVrfGJJhymx/kz6prltenw1u7WrCg1oa94zYY8xxVpLLUu045LAT0dhDZdXG58/EpPL/5kA180fQ/qudg==} - engines: {node: '>=10'} - dev: true + dev: false /emoji-regex/8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -4391,19 +3837,6 @@ packages: resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==} engines: {node: '>=10'} - /escodegen/2.0.0: - resolution: {integrity: sha512-mmHKys/C8BFUGI+MAWNcSYoORYLMdPzjrknd2Vc+bUsjN5bXcr8EhrNB+UTqfL1y3I9c4fw2ihgtMPQLBRiQxw==} - engines: {node: '>=6.0'} - hasBin: true - dependencies: - esprima: 4.0.1 - estraverse: 5.3.0 - esutils: 2.0.3 - optionator: 0.8.3 - optionalDependencies: - source-map: 0.6.1 - dev: true - /eslint-define-config/1.4.0: resolution: {integrity: sha512-DJGEdzX4fkdkhPSzPgOpBbBjhT+b9DcgbAgxfrEUcipVWlSuesQJriKffHz1JF5mhKFm7PGoiZz4D2nb4GslNA==} engines: {node: '>= 14.6.0', npm: '>= 6.0.0', pnpm: '>= 6.32.9'} @@ -4536,12 +3969,6 @@ packages: eslint-visitor-keys: 3.3.0 dev: true - /esprima/4.0.1: - resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==} - engines: {node: '>=4'} - hasBin: true - dev: true - /esquery/1.4.0: resolution: {integrity: sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==} engines: {node: '>=0.10'} @@ -4607,21 +4034,6 @@ packages: strip-final-newline: 2.0.0 dev: true - /exit/0.1.2: - resolution: {integrity: sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=} - engines: {node: '>= 0.8.0'} - dev: true - - /expect/27.5.1: - resolution: {integrity: sha512-E1q5hSUG2AmYQwQJ041nvgpkODHQvB+RKlB4IYdru6uJsyFTRyZAP463M+1lINorwbqAmUggi6+WwkD8lCS/Dw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/types': 27.5.1 - jest-get-type: 27.5.1 - jest-matcher-utils: 27.5.1 - jest-message-util: 27.5.1 - dev: true - /express/4.18.1: resolution: {integrity: sha512-zZBcOX9TfehHQhtupq57OF8lFZ3UZi08Y97dwFCkD8p9d/d2Y3M+ykKcwaMDEL+4qyUolgBDX6AblpR3fL212Q==} engines: {node: '>= 0.10.0'} @@ -4706,12 +4118,6 @@ packages: dependencies: reusify: 1.0.4 - /fb-watchman/2.0.1: - resolution: {integrity: sha512-DkPJKQeY6kKwmuMretBhr7G6Vodr7bFwDYTXIkfG1gjvNpaxBTQV3PbXg6bR1c1UP4jPOX0jHUbbHANL9vRjVg==} - dependencies: - bser: 2.1.1 - dev: true - /fd-slicer/1.1.0: resolution: {integrity: sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=} dependencies: @@ -4796,15 +4202,6 @@ packages: debug: optional: true - /form-data/3.0.1: - resolution: {integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==} - engines: {node: '>= 6'} - dependencies: - asynckit: 0.4.0 - combined-stream: 1.0.8 - mime-types: 2.1.35 - dev: true - /formdata-node/2.5.0: resolution: {integrity: sha512-JFSNLq34u2Tqc6F034x5aaK3ksIfrDBMPie8b4KYx2/pVDLxWFXDly52dsvHjZ+A0LGHTZb/w4HBZVdgN74RTw==} engines: {node: '>= 10.17'} @@ -4905,6 +4302,7 @@ packages: /gensync/1.0.0-beta.2: resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==} engines: {node: '>=6.9.0'} + dev: false /get-caller-file/2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} @@ -4923,11 +4321,6 @@ packages: has-symbols: 1.0.3 dev: true - /get-package-type/0.1.0: - resolution: {integrity: sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==} - engines: {node: '>=8.0.0'} - dev: true - /get-pkg-repo/4.2.1: resolution: {integrity: sha512-2+QbHjFRfGB74v/pYWjd5OhU3TDIC2Gv/YKUTk/tCvAz0pkn/Mz6P3uByuBimLOcPvN2jYdScl3xGFSrx0jEcA==} engines: {node: '>=6.9.0'} @@ -4959,6 +4352,10 @@ packages: get-intrinsic: 1.1.1 dev: true + /get-them-args/1.3.2: + resolution: {integrity: sha1-dKILqKSr7OWuGZrQPyvMaP38m6U=} + dev: true + /git-raw-commits/2.0.11: resolution: {integrity: sha512-VnctFhw+xfj8Va1xtfEqCUD2XDrbAPSJx+hSrE5K7fGdjZruW7XV+QOrN7LF/RJyvspRiD2I0asWsxFp0ya26A==} engines: {node: '>=10'} @@ -5019,6 +4416,7 @@ packages: /globals/11.12.0: resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==} engines: {node: '>=4'} + dev: false /globals/13.14.0: resolution: {integrity: sha512-ERO68sOYwm5UuLvSJTY7w7NP2c8S4UcXs3X1GBX8cwOr+ShOcDBbCY5mH4zxz0jsYCdJ8ve8Mv9n2YGJMB1aeg==} @@ -5154,17 +4552,6 @@ packages: resolution: {integrity: sha1-wc56MWjIxmFAM6S194d/OyJfnDg=} dev: false - /html-encoding-sniffer/2.0.1: - resolution: {integrity: sha512-D5JbOMBIR/TVZkubHT+OyT2705QvogUW4IBn6nHd756OwieSF9aDYFj4dv6HHEVGYbHaLETa3WggZYWWMyy3ZQ==} - engines: {node: '>=10'} - dependencies: - whatwg-encoding: 1.0.5 - dev: true - - /html-escaper/2.0.2: - resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} - dev: true - /html-rewriter-wasm/0.3.2: resolution: {integrity: sha512-b+pOh+bs00uRVNIZoTgGBREjUKN47pchTNwkxKuP4ecQTFcOA6KJIW+jjvjjXrkSRURZsideLxFKqX7hnxdegQ==} dev: true @@ -5189,17 +4576,6 @@ packages: toidentifier: 1.0.1 dev: true - /http-proxy-agent/4.0.1: - resolution: {integrity: sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==} - engines: {node: '>= 6'} - dependencies: - '@tootallnate/once': 1.1.2 - agent-base: 6.0.2 - debug: 4.3.4 - transitivePeerDependencies: - - supports-color - dev: true - /http-proxy/1.18.1_debug@4.3.4: resolution: {integrity: sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==} engines: {node: '>=8.0.0'} @@ -5229,6 +4605,7 @@ packages: debug: 4.3.4 transitivePeerDependencies: - supports-color + dev: false /human-signals/2.1.0: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} @@ -5284,15 +4661,6 @@ packages: engines: {node: '>=8'} dev: true - /import-local/3.1.0: - resolution: {integrity: sha512-ASB07uLtnDs1o6EHjKpX34BKYDSqnFerfTOJL2HvMqF70LnxpjkzDB8J44oT9pu4AMPkQwf8jl6szgvNd2tRIg==} - engines: {node: '>=8'} - hasBin: true - dependencies: - pkg-dir: 4.2.0 - resolve-cwd: 3.0.0 - dev: true - /imurmurhash/0.1.4: resolution: {integrity: sha1-khi5srkoojixPcT7a21XbyMUU+o=} engines: {node: '>=0.8.19'} @@ -5434,11 +4802,6 @@ packages: engines: {node: '>=12'} dev: true - /is-generator-fn/2.1.0: - resolution: {integrity: sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ==} - engines: {node: '>=6'} - dev: true - /is-glob/4.0.3: resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} engines: {node: '>=0.10.0'} @@ -5475,10 +4838,6 @@ packages: engines: {node: '>=0.10.0'} dev: true - /is-potential-custom-element-name/1.0.1: - resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==} - dev: true - /is-promise/2.2.2: resolution: {integrity: sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==} dev: true @@ -5503,576 +4862,59 @@ packages: call-bind: 1.0.2 dev: true - /is-stream/2.0.1: - resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} - engines: {node: '>=8'} - dev: true - - /is-string/1.0.7: - resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} - engines: {node: '>= 0.4'} - dependencies: - has-tostringtag: 1.0.0 - dev: true - - /is-symbol/1.0.4: - resolution: {integrity: sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==} - engines: {node: '>= 0.4'} - dependencies: - has-symbols: 1.0.3 - dev: true - - /is-text-path/1.0.1: - resolution: {integrity: sha1-Thqg+1G/vLPpJogAE5cgLBd1tm4=} - engines: {node: '>=0.10.0'} - dependencies: - text-extensions: 1.9.0 - dev: true - - /is-typedarray/1.0.0: - resolution: {integrity: sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=} - dev: true - - /is-weakref/1.0.2: - resolution: {integrity: sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==} - dependencies: - call-bind: 1.0.2 - dev: true - - /is-what/3.14.1: - resolution: {integrity: sha512-sNxgpk9793nzSs7bA6JQJGeIuRBQhAaNGG77kzYQgMkrID+lS6SlK07K5LaptscDlSaIgH+GPFzf+d75FVxozA==} - dev: true - - /is-wsl/2.2.0: - resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==} - engines: {node: '>=8'} - dependencies: - is-docker: 2.2.1 - dev: true - - /isarray/0.0.1: - resolution: {integrity: sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=} - dev: false - - /isarray/1.0.0: - resolution: {integrity: sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=} - dev: true - - /isexe/2.0.0: - resolution: {integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=} - dev: true - - /istanbul-lib-coverage/3.2.0: - resolution: {integrity: sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==} - engines: {node: '>=8'} - dev: true - - /istanbul-lib-instrument/5.2.0: - resolution: {integrity: sha512-6Lthe1hqXHBNsqvgDzGO6l03XNeu3CrG4RqQ1KM9+l5+jNGpEJfIELx1NS3SEHmJQA8np/u+E4EPRKRiu6m19A==} - engines: {node: '>=8'} - dependencies: - '@babel/core': 7.17.10 - '@babel/parser': 7.17.10 - '@istanbuljs/schema': 0.1.3 - istanbul-lib-coverage: 3.2.0 - semver: 6.3.0 - transitivePeerDependencies: - - supports-color - dev: true - - /istanbul-lib-report/3.0.0: - resolution: {integrity: sha512-wcdi+uAKzfiGT2abPpKZ0hSU1rGQjUQnLvtY5MpQ7QCTahD3VODhcu4wcfY1YtkGaDD5yuydOLINXsfbus9ROw==} - engines: {node: '>=8'} - dependencies: - istanbul-lib-coverage: 3.2.0 - make-dir: 3.1.0 - supports-color: 7.2.0 - dev: true - - /istanbul-lib-source-maps/4.0.1: - resolution: {integrity: sha512-n3s8EwkdFIJCG3BPKBYvskgXGoy88ARzvegkitk60NxRdwltLOTaH7CUiMRXvwYorl0Q712iEjcWB+fK/MrWVw==} - engines: {node: '>=10'} - dependencies: - debug: 4.3.4 - istanbul-lib-coverage: 3.2.0 - source-map: 0.6.1 - transitivePeerDependencies: - - supports-color - dev: true - - /istanbul-reports/3.1.4: - resolution: {integrity: sha512-r1/DshN4KSE7xWEknZLLLLDn5CJybV3nw01VTkp6D5jzLuELlcbudfj/eSQFvrKsJuTVCGnePO7ho82Nw9zzfw==} - engines: {node: '>=8'} - dependencies: - html-escaper: 2.0.2 - istanbul-lib-report: 3.0.0 - dev: true - - /jest-changed-files/27.5.1: - resolution: {integrity: sha512-buBLMiByfWGCoMsLLzGUUSpAmIAGnbR2KJoMN10ziLhOLvP4e0SlypHnAel8iqQXTrcbmfEY9sSqae5sgUsTvw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/types': 27.5.1 - execa: 5.1.1 - throat: 6.0.1 - dev: true - - /jest-circus/27.5.1: - resolution: {integrity: sha512-D95R7x5UtlMA5iBYsOHFFbMD/GVA4R/Kdq15f7xYWUfWHBto9NYRsOvnSauTgdF+ogCpJ4tyKOXhUifxS65gdw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/environment': 27.5.1 - '@jest/test-result': 27.5.1 - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - chalk: 4.1.2 - co: 4.6.0 - dedent: 0.7.0 - expect: 27.5.1 - is-generator-fn: 2.1.0 - jest-each: 27.5.1 - jest-matcher-utils: 27.5.1 - jest-message-util: 27.5.1 - jest-runtime: 27.5.1 - jest-snapshot: 27.5.1 - jest-util: 27.5.1 - pretty-format: 27.5.1 - slash: 3.0.0 - stack-utils: 2.0.5 - throat: 6.0.1 - transitivePeerDependencies: - - supports-color - dev: true - - /jest-cli/27.5.1_ts-node@10.7.0: - resolution: {integrity: sha512-Hc6HOOwYq4/74/c62dEE3r5elx8wjYqxY0r0G/nFrLDPMFRu6RA/u8qINOIkvhxG7mMQ5EJsOGfRpI8L6eFUVw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - hasBin: true - peerDependencies: - node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 - peerDependenciesMeta: - node-notifier: - optional: true - dependencies: - '@jest/core': 27.5.1_ts-node@10.7.0 - '@jest/test-result': 27.5.1 - '@jest/types': 27.5.1 - chalk: 4.1.2 - exit: 0.1.2 - graceful-fs: 4.2.10 - import-local: 3.1.0 - jest-config: 27.5.1_ts-node@10.7.0 - jest-util: 27.5.1 - jest-validate: 27.5.1 - prompts: 2.4.2 - yargs: 16.2.0 - transitivePeerDependencies: - - bufferutil - - canvas - - supports-color - - ts-node - - utf-8-validate - dev: true - - /jest-config/27.5.1_ts-node@10.7.0: - resolution: {integrity: sha512-5sAsjm6tGdsVbW9ahcChPAFCk4IlkQUknH5AvKjuLTSlcO/wCZKyFdn7Rg0EkC+OGgWODEy2hDpWB1PgzH0JNA==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - peerDependencies: - ts-node: '>=9.0.0' - peerDependenciesMeta: - ts-node: - optional: true - dependencies: - '@babel/core': 7.17.10 - '@jest/test-sequencer': 27.5.1 - '@jest/types': 27.5.1 - babel-jest: 27.5.1_@babel+core@7.17.10 - chalk: 4.1.2 - ci-info: 3.3.0 - deepmerge: 4.2.2 - glob: 7.2.0 - graceful-fs: 4.2.10 - jest-circus: 27.5.1 - jest-environment-jsdom: 27.5.1 - jest-environment-node: 27.5.1 - jest-get-type: 27.5.1 - jest-jasmine2: 27.5.1 - jest-regex-util: 27.5.1 - jest-resolve: 27.5.1 - jest-runner: 27.5.1 - jest-util: 27.5.1 - jest-validate: 27.5.1 - micromatch: 4.0.5 - parse-json: 5.2.0 - pretty-format: 27.5.1 - slash: 3.0.0 - strip-json-comments: 3.1.1 - ts-node: 10.7.0_5f3e12794cebfbf3197131903b74d233 - transitivePeerDependencies: - - bufferutil - - canvas - - supports-color - - utf-8-validate - dev: true - - /jest-diff/27.5.1: - resolution: {integrity: sha512-m0NvkX55LDt9T4mctTEgnZk3fmEg3NRYutvMPWM/0iPnkFj2wIeF45O1718cMSOFO1vINkqmxqD8vE37uTEbqw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - chalk: 4.1.2 - diff-sequences: 27.5.1 - jest-get-type: 27.5.1 - pretty-format: 27.5.1 - dev: true - - /jest-docblock/27.5.1: - resolution: {integrity: sha512-rl7hlABeTsRYxKiUfpHrQrG4e2obOiTQWfMEH3PxPjOtdsfLQO4ReWSZaQ7DETm4xu07rl4q/h4zcKXyU0/OzQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - detect-newline: 3.1.0 - dev: true - - /jest-each/27.5.1: - resolution: {integrity: sha512-1Ff6p+FbhT/bXQnEouYy00bkNSY7OUpfIcmdl8vZ31A1UUaurOLPA8a8BbJOF2RDUElwJhmeaV7LnagI+5UwNQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/types': 27.5.1 - chalk: 4.1.2 - jest-get-type: 27.5.1 - jest-util: 27.5.1 - pretty-format: 27.5.1 - dev: true - - /jest-environment-jsdom/27.5.1: - resolution: {integrity: sha512-TFBvkTC1Hnnnrka/fUb56atfDtJ9VMZ94JkjTbggl1PEpwrYtUBKMezB3inLmWqQsXYLcMwNoDQwoBTAvFfsfw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/environment': 27.5.1 - '@jest/fake-timers': 27.5.1 - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - jest-mock: 27.5.1 - jest-util: 27.5.1 - jsdom: 16.7.0 - transitivePeerDependencies: - - bufferutil - - canvas - - supports-color - - utf-8-validate - dev: true - - /jest-environment-node/27.5.1: - resolution: {integrity: sha512-Jt4ZUnxdOsTGwSRAfKEnE6BcwsSPNOijjwifq5sDFSA2kesnXTvNqKHYgM0hDq3549Uf/KzdXNYn4wMZJPlFLw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/environment': 27.5.1 - '@jest/fake-timers': 27.5.1 - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - jest-mock: 27.5.1 - jest-util: 27.5.1 - dev: true - - /jest-get-type/27.5.1: - resolution: {integrity: sha512-2KY95ksYSaK7DMBWQn6dQz3kqAf3BB64y2udeG+hv4KfSOb9qwcYQstTJc1KCbsix+wLZWZYN8t7nwX3GOBLRw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dev: true - - /jest-haste-map/27.5.1: - resolution: {integrity: sha512-7GgkZ4Fw4NFbMSDSpZwXeBiIbx+t/46nJ2QitkOjvwPYyZmqttu2TDSimMHP1EkPOi4xUZAN1doE5Vd25H4Jng==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/types': 27.5.1 - '@types/graceful-fs': 4.1.5 - '@types/node': 17.0.31 - anymatch: 3.1.2 - fb-watchman: 2.0.1 - graceful-fs: 4.2.10 - jest-regex-util: 27.5.1 - jest-serializer: 27.5.1 - jest-util: 27.5.1 - jest-worker: 27.5.1 - micromatch: 4.0.5 - walker: 1.0.8 - optionalDependencies: - fsevents: 2.3.2 - dev: true - - /jest-jasmine2/27.5.1: - resolution: {integrity: sha512-jtq7VVyG8SqAorDpApwiJJImd0V2wv1xzdheGHRGyuT7gZm6gG47QEskOlzsN1PG/6WNaCo5pmwMHDf3AkG2pQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/environment': 27.5.1 - '@jest/source-map': 27.5.1 - '@jest/test-result': 27.5.1 - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - chalk: 4.1.2 - co: 4.6.0 - expect: 27.5.1 - is-generator-fn: 2.1.0 - jest-each: 27.5.1 - jest-matcher-utils: 27.5.1 - jest-message-util: 27.5.1 - jest-runtime: 27.5.1 - jest-snapshot: 27.5.1 - jest-util: 27.5.1 - pretty-format: 27.5.1 - throat: 6.0.1 - transitivePeerDependencies: - - supports-color - dev: true - - /jest-leak-detector/27.5.1: - resolution: {integrity: sha512-POXfWAMvfU6WMUXftV4HolnJfnPOGEu10fscNCA76KBpRRhcMN2c8d3iT2pxQS3HLbA+5X4sOUPzYO2NUyIlHQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - jest-get-type: 27.5.1 - pretty-format: 27.5.1 - dev: true - - /jest-matcher-utils/27.5.1: - resolution: {integrity: sha512-z2uTx/T6LBaCoNWNFWwChLBKYxTMcGBRjAt+2SbP929/Fflb9aa5LGma654Rz8z9HLxsrUaYzxE9T/EFIL/PAw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - chalk: 4.1.2 - jest-diff: 27.5.1 - jest-get-type: 27.5.1 - pretty-format: 27.5.1 - dev: true - - /jest-message-util/27.5.1: - resolution: {integrity: sha512-rMyFe1+jnyAAf+NHwTclDz0eAaLkVDdKVHHBFWsBWHnnh5YeJMNWWsv7AbFYXfK3oTqvL7VTWkhNLu1jX24D+g==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@babel/code-frame': 7.16.7 - '@jest/types': 27.5.1 - '@types/stack-utils': 2.0.1 - chalk: 4.1.2 - graceful-fs: 4.2.10 - micromatch: 4.0.5 - pretty-format: 27.5.1 - slash: 3.0.0 - stack-utils: 2.0.5 - dev: true - - /jest-mock/27.5.1: - resolution: {integrity: sha512-K4jKbY1d4ENhbrG2zuPWaQBvDly+iZ2yAW+T1fATN78hc0sInwn7wZB8XtlNnvHug5RMwV897Xm4LqmPM4e2Og==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - dev: true - - /jest-pnp-resolver/1.2.2_jest-resolve@27.5.1: - resolution: {integrity: sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w==} - engines: {node: '>=6'} - peerDependencies: - jest-resolve: '*' - peerDependenciesMeta: - jest-resolve: - optional: true - dependencies: - jest-resolve: 27.5.1 - dev: true - - /jest-regex-util/27.5.1: - resolution: {integrity: sha512-4bfKq2zie+x16okqDXjXn9ql2B0dScQu+vcwe4TvFVhkVyuWLqpZrZtXxLLWoXYgn0E87I6r6GRYHF7wFZBUvg==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dev: true - - /jest-resolve-dependencies/27.5.1: - resolution: {integrity: sha512-QQOOdY4PE39iawDn5rzbIePNigfe5B9Z91GDD1ae/xNDlu9kaat8QQ5EKnNmVWPV54hUdxCVwwj6YMgR2O7IOg==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/types': 27.5.1 - jest-regex-util: 27.5.1 - jest-snapshot: 27.5.1 - transitivePeerDependencies: - - supports-color - dev: true - - /jest-resolve/27.5.1: - resolution: {integrity: sha512-FFDy8/9E6CV83IMbDpcjOhumAQPDyETnU2KZ1O98DwTnz8AOBsW/Xv3GySr1mOZdItLR+zDZ7I/UdTFbgSOVCw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/types': 27.5.1 - chalk: 4.1.2 - graceful-fs: 4.2.10 - jest-haste-map: 27.5.1 - jest-pnp-resolver: 1.2.2_jest-resolve@27.5.1 - jest-util: 27.5.1 - jest-validate: 27.5.1 - resolve: 1.22.0 - resolve.exports: 1.1.0 - slash: 3.0.0 - dev: true - - /jest-runner/27.5.1: - resolution: {integrity: sha512-g4NPsM4mFCOwFKXO4p/H/kWGdJp9V8kURY2lX8Me2drgXqG7rrZAx5kv+5H7wtt/cdFIjhqYx1HrlqWHaOvDaQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/console': 27.5.1 - '@jest/environment': 27.5.1 - '@jest/test-result': 27.5.1 - '@jest/transform': 27.5.1 - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - chalk: 4.1.2 - emittery: 0.8.1 - graceful-fs: 4.2.10 - jest-docblock: 27.5.1 - jest-environment-jsdom: 27.5.1 - jest-environment-node: 27.5.1 - jest-haste-map: 27.5.1 - jest-leak-detector: 27.5.1 - jest-message-util: 27.5.1 - jest-resolve: 27.5.1 - jest-runtime: 27.5.1 - jest-util: 27.5.1 - jest-worker: 27.5.1 - source-map-support: 0.5.21 - throat: 6.0.1 - transitivePeerDependencies: - - bufferutil - - canvas - - supports-color - - utf-8-validate - dev: true - - /jest-runtime/27.5.1: - resolution: {integrity: sha512-o7gxw3Gf+H2IGt8fv0RiyE1+r83FJBRruoA+FXrlHw6xEyBsU8ugA6IPfTdVyA0w8HClpbK+DGJxH59UrNMx8A==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/environment': 27.5.1 - '@jest/fake-timers': 27.5.1 - '@jest/globals': 27.5.1 - '@jest/source-map': 27.5.1 - '@jest/test-result': 27.5.1 - '@jest/transform': 27.5.1 - '@jest/types': 27.5.1 - chalk: 4.1.2 - cjs-module-lexer: 1.2.2 - collect-v8-coverage: 1.0.1 - execa: 5.1.1 - glob: 7.2.0 - graceful-fs: 4.2.10 - jest-haste-map: 27.5.1 - jest-message-util: 27.5.1 - jest-mock: 27.5.1 - jest-regex-util: 27.5.1 - jest-resolve: 27.5.1 - jest-snapshot: 27.5.1 - jest-util: 27.5.1 - slash: 3.0.0 - strip-bom: 4.0.0 - transitivePeerDependencies: - - supports-color + /is-stream/2.0.1: + resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} + engines: {node: '>=8'} dev: true - /jest-serializer/27.5.1: - resolution: {integrity: sha512-jZCyo6iIxO1aqUxpuBlwTDMkzOAJS4a3eYz3YzgxxVQFwLeSA7Jfq5cbqCY+JLvTDrWirgusI/0KwxKMgrdf7w==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} + /is-string/1.0.7: + resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} + engines: {node: '>= 0.4'} dependencies: - '@types/node': 17.0.31 - graceful-fs: 4.2.10 + has-tostringtag: 1.0.0 dev: true - /jest-snapshot/27.5.1: - resolution: {integrity: sha512-yYykXI5a0I31xX67mgeLw1DZ0bJB+gpq5IpSuCAoyDi0+BhgU/RIrL+RTzDmkNTchvDFWKP8lp+w/42Z3us5sA==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} + /is-symbol/1.0.4: + resolution: {integrity: sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==} + engines: {node: '>= 0.4'} dependencies: - '@babel/core': 7.17.10 - '@babel/generator': 7.17.10 - '@babel/plugin-syntax-typescript': 7.17.10_@babel+core@7.17.10 - '@babel/traverse': 7.17.10 - '@babel/types': 7.17.10 - '@jest/transform': 27.5.1 - '@jest/types': 27.5.1 - '@types/babel__traverse': 7.17.1 - '@types/prettier': 2.6.0 - babel-preset-current-node-syntax: 1.0.1_@babel+core@7.17.10 - chalk: 4.1.2 - expect: 27.5.1 - graceful-fs: 4.2.10 - jest-diff: 27.5.1 - jest-get-type: 27.5.1 - jest-haste-map: 27.5.1 - jest-matcher-utils: 27.5.1 - jest-message-util: 27.5.1 - jest-util: 27.5.1 - natural-compare: 1.4.0 - pretty-format: 27.5.1 - semver: 7.3.7 - transitivePeerDependencies: - - supports-color + has-symbols: 1.0.3 dev: true - /jest-util/27.5.1: - resolution: {integrity: sha512-Kv2o/8jNvX1MQ0KGtw480E/w4fBCDOnH6+6DmeKi6LZUIlKA5kwY0YNdlzaWTiVgxqAqik11QyxDOKk543aKXw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} + /is-text-path/1.0.1: + resolution: {integrity: sha1-Thqg+1G/vLPpJogAE5cgLBd1tm4=} + engines: {node: '>=0.10.0'} dependencies: - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - chalk: 4.1.2 - ci-info: 3.3.0 - graceful-fs: 4.2.10 - picomatch: 2.3.1 + text-extensions: 1.9.0 dev: true - /jest-validate/27.5.1: - resolution: {integrity: sha512-thkNli0LYTmOI1tDB3FI1S1RTp/Bqyd9pTarJwL87OIBFuqEb5Apv5EaApEudYg4g86e3CT6kM0RowkhtEnCBQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} + /is-weakref/1.0.2: + resolution: {integrity: sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==} dependencies: - '@jest/types': 27.5.1 - camelcase: 6.3.0 - chalk: 4.1.2 - jest-get-type: 27.5.1 - leven: 3.1.0 - pretty-format: 27.5.1 + call-bind: 1.0.2 dev: true - /jest-watcher/27.5.1: - resolution: {integrity: sha512-z676SuD6Z8o8qbmEGhoEUFOM1+jfEiL3DXHK/xgEiG2EyNYfFG60jluWcupY6dATjfEsKQuibReS1djInQnoVw==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - '@jest/test-result': 27.5.1 - '@jest/types': 27.5.1 - '@types/node': 17.0.31 - ansi-escapes: 4.3.2 - chalk: 4.1.2 - jest-util: 27.5.1 - string-length: 4.0.2 + /is-what/3.14.1: + resolution: {integrity: sha512-sNxgpk9793nzSs7bA6JQJGeIuRBQhAaNGG77kzYQgMkrID+lS6SlK07K5LaptscDlSaIgH+GPFzf+d75FVxozA==} dev: true - /jest-worker/27.5.1: - resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==} - engines: {node: '>= 10.13.0'} + /is-wsl/2.2.0: + resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==} + engines: {node: '>=8'} dependencies: - '@types/node': 17.0.31 - merge-stream: 2.0.0 - supports-color: 8.1.1 + is-docker: 2.2.1 dev: true - /jest/27.5.1_ts-node@10.7.0: - resolution: {integrity: sha512-Yn0mADZB89zTtjkPJEXwrac3LHudkQMR+Paqa8uxJHCBr9agxztUifWCyiYrjhMPBoUVBjyny0I7XH6ozDr7QQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - hasBin: true - peerDependencies: - node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0 - peerDependenciesMeta: - node-notifier: - optional: true - dependencies: - '@jest/core': 27.5.1_ts-node@10.7.0 - import-local: 3.1.0 - jest-cli: 27.5.1_ts-node@10.7.0 - transitivePeerDependencies: - - bufferutil - - canvas - - supports-color - - ts-node - - utf-8-validate + /isarray/0.0.1: + resolution: {integrity: sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=} + dev: false + + /isarray/1.0.0: + resolution: {integrity: sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=} + dev: true + + /isexe/2.0.0: + resolution: {integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=} dev: true /jju/1.4.0: @@ -6090,14 +4932,6 @@ packages: /js-tokens/4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} - /js-yaml/3.14.1: - resolution: {integrity: sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==} - hasBin: true - dependencies: - argparse: 1.0.10 - esprima: 4.0.1 - dev: true - /js-yaml/4.1.0: resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} hasBin: true @@ -6105,52 +4939,11 @@ packages: argparse: 2.0.1 dev: true - /jsdom/16.7.0: - resolution: {integrity: sha512-u9Smc2G1USStM+s/x1ru5Sxrl6mPYCbByG1U/hUmqaVsm4tbNyS7CicOSRyuGQYZhTu0h84qkZZQ/I+dzizSVw==} - engines: {node: '>=10'} - peerDependencies: - canvas: ^2.5.0 - peerDependenciesMeta: - canvas: - optional: true - dependencies: - abab: 2.0.6 - acorn: 8.7.1 - acorn-globals: 6.0.0 - cssom: 0.4.4 - cssstyle: 2.3.0 - data-urls: 2.0.0 - decimal.js: 10.3.1 - domexception: 2.0.1 - escodegen: 2.0.0 - form-data: 3.0.1 - html-encoding-sniffer: 2.0.1 - http-proxy-agent: 4.0.1 - https-proxy-agent: 5.0.1 - is-potential-custom-element-name: 1.0.1 - nwsapi: 2.2.0 - parse5: 6.0.1 - saxes: 5.0.1 - symbol-tree: 3.2.4 - tough-cookie: 4.0.0 - w3c-hr-time: 1.0.2 - w3c-xmlserializer: 2.0.0 - webidl-conversions: 6.1.0 - whatwg-encoding: 1.0.5 - whatwg-mimetype: 2.3.0 - whatwg-url: 8.7.0 - ws: 7.5.7 - xml-name-validator: 3.0.0 - transitivePeerDependencies: - - bufferutil - - supports-color - - utf-8-validate - dev: true - /jsesc/2.5.2: resolution: {integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==} engines: {node: '>=4'} hasBin: true + dev: false /json-parse-better-errors/1.0.2: resolution: {integrity: sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==} @@ -6201,6 +4994,14 @@ packages: promise: 7.3.1 dev: true + /kill-port/1.6.1: + resolution: {integrity: sha512-un0Y55cOM7JKGaLnGja28T38tDDop0AQ8N0KlAdyh+B1nmMoX8AnNmqPNZbS3mUMgiST51DCVqmbFT1gNJpVNw==} + hasBin: true + dependencies: + get-them-args: 1.3.2 + shell-exec: 1.0.2 + dev: true + /kind-of/6.0.3: resolution: {integrity: sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==} engines: {node: '>=0.10.0'} @@ -6250,19 +5051,6 @@ packages: source-map: 0.6.1 dev: true - /leven/3.1.0: - resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} - engines: {node: '>=6'} - dev: true - - /levn/0.3.0: - resolution: {integrity: sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=} - engines: {node: '>= 0.8.0'} - dependencies: - prelude-ls: 1.1.2 - type-check: 0.3.2 - dev: true - /levn/0.4.1: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} @@ -6392,10 +5180,6 @@ packages: resolution: {integrity: sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc=} dev: true - /lodash.memoize/4.1.2: - resolution: {integrity: sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=} - dev: true - /lodash.merge/4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} dev: true @@ -6466,17 +5250,12 @@ packages: engines: {node: '>=8'} dependencies: semver: 6.3.0 + dev: false /make-error/1.3.6: resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} dev: true - /makeerror/1.0.12: - resolution: {integrity: sha512-JmqCvUhmt43madlpFzG4BQzG2Z3m6tvQDNKdClZnO3VbIudJYmxsT0FNJMeiB2+JTSlTQTSbU8QdesVmwJcmLg==} - dependencies: - tmpl: 1.0.5 - dev: true - /map-obj/1.0.1: resolution: {integrity: sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=} engines: {node: '>=0.10.0'} @@ -6784,12 +5563,9 @@ packages: engines: {node: '>= 6.13.0'} dev: true - /node-int64/0.4.0: - resolution: {integrity: sha1-h6kGXNs1XTGC2PlM4RGIuCXGijs=} - dev: true - /node-releases/2.0.4: resolution: {integrity: sha512-gbMzqQtTtDz/00jQzZ21PQzdI9PyLYqUSvD0p3naOhX4odFji0ZxYdnVwPTxmSwkmxhcFImpozceidSG+AgoPQ==} + dev: false /nopt/5.0.0: resolution: {integrity: sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==} @@ -6863,10 +5639,6 @@ packages: set-blocking: 2.0.0 dev: false - /nwsapi/2.2.0: - resolution: {integrity: sha512-h2AatdwYH+JHiZpv7pt/gSX1XoRGb7L/qSIeuqA6GwYoF9w1vP1cw42TO0aI2pNyshRK5893hNSl+1//vHK7hQ==} - dev: true - /object-assign/4.1.1: resolution: {integrity: sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=} engines: {node: '>=0.10.0'} @@ -6950,18 +5722,6 @@ packages: hasBin: true dev: true - /optionator/0.8.3: - resolution: {integrity: sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==} - engines: {node: '>= 0.8.0'} - dependencies: - deep-is: 0.1.4 - fast-levenshtein: 2.0.6 - levn: 0.3.0 - prelude-ls: 1.1.2 - type-check: 0.3.2 - word-wrap: 1.2.3 - dev: true - /optionator/0.9.1: resolution: {integrity: sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==} engines: {node: '>= 0.8.0'} @@ -7057,10 +5817,6 @@ packages: engines: {node: '>= 0.10'} dev: true - /parse5/6.0.1: - resolution: {integrity: sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==} - dev: true - /parseurl/1.3.3: resolution: {integrity: sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==} engines: {node: '>= 0.8'} @@ -7168,11 +5924,6 @@ packages: dev: true optional: true - /pirates/4.0.5: - resolution: {integrity: sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==} - engines: {node: '>= 6'} - dev: true - /pixelmatch/5.2.1: resolution: {integrity: sha512-WjcAdYSnKrrdDdqTcVEY7aB7UhhwjYQKYhHiBXdJef0MOaQeYpUdQ+iVyBLa5YBKS8MPVPPMX7rpOByISLpeEQ==} hasBin: true @@ -7180,13 +5931,6 @@ packages: pngjs: 4.0.1 dev: true - /pkg-dir/4.2.0: - resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==} - engines: {node: '>=8'} - dependencies: - find-up: 4.1.0 - dev: true - /playwright-chromium/1.21.1: resolution: {integrity: sha512-bbqFFpcTs+3amiofja/KvTmZ+FZnMNEOuGkRyJk2p6DV9EbgRYVrlzzgLtMnX2DwaX3ZZ23MukGuQ+bVKOdsnw==} engines: {node: '>=12'} @@ -7404,11 +6148,6 @@ packages: resolution: {integrity: sha512-GLjn0I3r6ka+NvxJUppsVFqb4V0qDTEHT/QxHlidPuClGaxF/4AI2Qti4a0cv3XMh5n1+D3hLScW10LRIm5msQ==} dev: true - /prelude-ls/1.1.2: - resolution: {integrity: sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=} - engines: {node: '>= 0.8.0'} - dev: true - /prelude-ls/1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} @@ -7420,15 +6159,6 @@ packages: hasBin: true dev: true - /pretty-format/27.5.1: - resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - dependencies: - ansi-regex: 5.0.1 - ansi-styles: 5.2.0 - react-is: 17.0.2 - dev: true - /pretty-hrtime/1.0.3: resolution: {integrity: sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=} engines: {node: '>= 0.8'} @@ -7494,10 +6224,6 @@ packages: dev: true optional: true - /psl/1.8.0: - resolution: {integrity: sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==} - dev: true - /pug-attrs/3.0.0: resolution: {integrity: sha512-azINV9dUtzPMFQktvTXciNAfAuVh/L/JCl0vtPCwvOA21uZrC08K/UnmrL+SXGEVc1FwzjW62+xw5S/uaLj6cA==} dependencies: @@ -7687,10 +6413,6 @@ packages: resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==} dev: false - /react-is/17.0.2: - resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==} - dev: true - /react-refresh/0.13.0: resolution: {integrity: sha512-XP8A9BT0CpRBD+NYLLeIhld/RqG9+gktUjW1FkE+Vm7OCinbG1SshcK5tb9ls4kzvjZr9mOQc7HYgBngEyPAXg==} engines: {node: '>=0.10.0'} @@ -7877,22 +6599,10 @@ packages: resolution: {integrity: sha1-AKCUD5jNUBrqqsMWQR2a3FKzGrE=} dev: true - /resolve-cwd/3.0.0: - resolution: {integrity: sha512-OrZaX2Mb+rJCpH/6CpSqt9xFVpN++x01XnN2ie9g6P5/3xelLAkXWVADpdz1IHD/KFfEXyE6V0U01OQ3UO2rEg==} - engines: {node: '>=8'} - dependencies: - resolve-from: 5.0.0 - dev: true - /resolve-from/4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'} - /resolve-from/5.0.0: - resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} - engines: {node: '>=8'} - dev: true - /resolve-pathname/3.0.0: resolution: {integrity: sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==} dev: false @@ -8024,13 +6734,6 @@ packages: resolution: {integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==} dev: true - /saxes/5.0.1: - resolution: {integrity: sha512-5LBh1Tls8c9xgGjw3QrMwETmTMVk0oFgvrFSvWx62llR2hcEInrKNZ2GZCCuuy2lvWrdl5jhbpeqc5hRYKFOcw==} - engines: {node: '>=10'} - dependencies: - xmlchars: 2.2.0 - dev: true - /scheduler/0.20.2: resolution: {integrity: sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==} dependencies: @@ -8130,6 +6833,10 @@ packages: engines: {node: '>=8'} dev: true + /shell-exec/1.0.2: + resolution: {integrity: sha512-jyVd+kU2X+mWKMmGhx4fpWbPsjvD53k9ivqetutVW/BQ+WIZoDoP4d8vUMGezV6saZsiNoW2f9GIhg9Dondohg==} + dev: true + /shell-quote/1.7.3: resolution: {integrity: sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==} dev: true @@ -8374,14 +7081,6 @@ packages: resolution: {integrity: sha1-6Kr8CsGFW0Zmkp7X3RJ1311sgRs=} dev: true - /string-length/4.0.2: - resolution: {integrity: sha512-+l6rNN5fYHNhZZy41RXsYptCjA2Igmq4EG7kZAYFQI1E1VTXarr6ZPXBg6eq7Y6eK4FEhY6AJlyuFIb/v/S0VQ==} - engines: {node: '>=10'} - dependencies: - char-regex: 1.0.2 - strip-ansi: 6.0.1 - dev: true - /string-width/4.2.3: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} @@ -8453,11 +7152,6 @@ packages: engines: {node: '>=4'} dev: true - /strip-bom/4.0.0: - resolution: {integrity: sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w==} - engines: {node: '>=8'} - dev: true - /strip-final-newline/2.0.0: resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} engines: {node: '>=6'} @@ -8510,26 +7204,11 @@ packages: dependencies: has-flag: 4.0.0 - /supports-color/8.1.1: - resolution: {integrity: sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==} - engines: {node: '>=10'} - dependencies: - has-flag: 4.0.0 - dev: true - /supports-color/9.2.2: resolution: {integrity: sha512-XC6g/Kgux+rJXmwokjm9ECpD6k/smUoS5LKlUCcsYr4IY3rW0XyAympon2RmxGrlnZURMpg5T18gWDP9CsHXFA==} engines: {node: '>=12'} dev: true - /supports-hyperlinks/2.2.0: - resolution: {integrity: sha512-6sXEzV5+I5j8Bmq9/vUphGRM/RJNT9SCURJLjwfOg51heRtguGWDzcaBlgAzKhQa0EVNpPEKzQuBwZ8S8WaCeQ==} - engines: {node: '>=8'} - dependencies: - has-flag: 4.0.0 - supports-color: 7.2.0 - dev: true - /supports-preserve-symlinks-flag/1.0.0: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} engines: {node: '>= 0.4'} @@ -8538,10 +7217,6 @@ packages: resolution: {integrity: sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q=} dev: false - /symbol-tree/3.2.4: - resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==} - dev: true - /systemjs/6.12.1: resolution: {integrity: sha512-hqTN6kW+pN6/qro6G9OZ7ceDQOcYno020zBQKpZQLsJhYTDMCMNfXi/Y8duF5iW+4WWZr42ry0MMkcRGpbwG2A==} dev: false @@ -8690,14 +7365,6 @@ packages: uuid: 3.4.0 dev: true - /terminal-link/2.1.1: - resolution: {integrity: sha512-un0FmiRUQNr5PJqy9kP7c40F5BOfpGlYTrxonDChEZB7pzZxRNp/bt+ymiy9/npwXya9KH99nJ/GXFIiUkYGFQ==} - engines: {node: '>=8'} - dependencies: - ansi-escapes: 4.3.2 - supports-hyperlinks: 2.2.0 - dev: true - /terser/5.13.1: resolution: {integrity: sha512-hn4WKOfwnwbYfe48NgrQjqNOH9jzLqRcIfbYytOXCOv46LBfWr9bDS17MQqOi+BWGD0sJK3Sj5NC/gJjiojaoA==} engines: {node: '>=10'} @@ -8709,15 +7376,6 @@ packages: source-map-support: 0.5.21 dev: true - /test-exclude/6.0.0: - resolution: {integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==} - engines: {node: '>=8'} - dependencies: - '@istanbuljs/schema': 0.1.3 - glob: 7.2.0 - minimatch: 3.1.2 - dev: true - /text-extensions/1.9.0: resolution: {integrity: sha512-wiBrwC1EhBelW12Zy26JeOUkQ5mRu+5o8rpsJk5+2t+Y5vE7e842qtZDQ2g1NpX/29HdyFeJ4nSIhI47ENSxlQ==} engines: {node: '>=0.10'} @@ -8727,10 +7385,6 @@ packages: resolution: {integrity: sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=} dev: true - /throat/6.0.1: - resolution: {integrity: sha512-8hmiGIJMDlwjg7dlJ4yKGLK8EsYqKgPWbG3b4wjJddKNwc7N7Dpn08Df4szr/sZdMVeOstrdYSsqzX6BYbcB+w==} - dev: true - /through/2.3.8: resolution: {integrity: sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=} dev: true @@ -8781,10 +7435,6 @@ packages: rimraf: 3.0.2 dev: false - /tmpl/1.0.5: - resolution: {integrity: sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==} - dev: true - /to-fast-properties/2.0.0: resolution: {integrity: sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=} engines: {node: '>=4'} @@ -8809,15 +7459,6 @@ packages: engines: {node: '>=6'} dev: true - /tough-cookie/4.0.0: - resolution: {integrity: sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg==} - engines: {node: '>=6'} - dependencies: - psl: 1.8.0 - punycode: 2.1.1 - universalify: 0.1.2 - dev: true - /tr46/0.0.3: resolution: {integrity: sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=} @@ -8845,41 +7486,6 @@ packages: utf8-byte-length: 1.0.4 dev: true - /ts-jest/27.1.4_edb1f862ecf73b6f0cc1f906c6266936: - resolution: {integrity: sha512-qjkZlVPWVctAezwsOD1OPzbZ+k7zA5z3oxII4dGdZo5ggX/PL7kvwTM0pXTr10fAtbiVpJaL3bWd502zAhpgSQ==} - engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} - hasBin: true - peerDependencies: - '@babel/core': '>=7.0.0-beta.0 <8' - '@types/jest': ^27.0.0 - babel-jest: '>=27.0.0 <28' - esbuild: '*' - jest: ^27.0.0 - typescript: '>=3.8 <5.0' - peerDependenciesMeta: - '@babel/core': - optional: true - '@types/jest': - optional: true - babel-jest: - optional: true - esbuild: - optional: true - dependencies: - '@types/jest': 27.5.0 - bs-logger: 0.2.6 - esbuild: 0.14.38 - fast-json-stable-stringify: 2.1.0 - jest: 27.5.1_ts-node@10.7.0 - jest-util: 27.5.1 - json5: 2.2.1 - lodash.memoize: 4.1.2 - make-error: 1.3.6 - semver: 7.3.7 - typescript: 4.6.4 - yargs-parser: 20.2.9 - dev: true - /ts-node/10.7.0_5f3e12794cebfbf3197131903b74d233: resolution: {integrity: sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==} hasBin: true @@ -8942,13 +7548,6 @@ packages: typescript: 4.6.4 dev: true - /type-check/0.3.2: - resolution: {integrity: sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=} - engines: {node: '>= 0.8.0'} - dependencies: - prelude-ls: 1.1.2 - dev: true - /type-check/0.4.0: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} engines: {node: '>= 0.8.0'} @@ -9002,12 +7601,6 @@ packages: resolution: {integrity: sha512-eiDBDOmkih5pMbo9OqsqPRGMljLodLcwd5XD5JbtNB0o89xZAwynY9EdCDsJU7LtcVCClu9DvM7/0Ep1hYX3EQ==} dev: false - /typedarray-to-buffer/3.1.5: - resolution: {integrity: sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==} - dependencies: - is-typedarray: 1.0.0 - dev: true - /typescript/4.6.4: resolution: {integrity: sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==} engines: {node: '>=4.2.0'} @@ -9106,15 +7699,6 @@ packages: resolution: {integrity: sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==} dev: true - /v8-to-istanbul/8.1.1: - resolution: {integrity: sha512-FGtKtv3xIpR6BYhvgH8MI/y78oT7d8Au3ww4QIxymrCtZEh5b8gCw2siywE+puhEmuWKDtmfrvF5UlB298ut3w==} - engines: {node: '>=10.12.0'} - dependencies: - '@types/istanbul-lib-coverage': 2.0.4 - convert-source-map: 1.8.0 - source-map: 0.7.3 - dev: true - /validate-npm-package-license/3.0.4: resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==} dependencies: @@ -9154,8 +7738,8 @@ packages: - react-dom dev: true - /vitest/0.10.5: - resolution: {integrity: sha512-4qXdNbHwAd9YcsztJoVMWUQGcMATVlY9Xd95I3KQ2JJwDLTL97f/jgfGRotqptvNxdlmme5TBY0Gv+l6+JSYvA==} + /vitest/0.12.4: + resolution: {integrity: sha512-EDxdhlAt6vcu6y4VouAI60z78iCAVFnfBL4VlSQVQnGmOk5altOtIKvp3xfZ+cfo4iVHgqq1QNyf5qOFiL4leg==} engines: {node: '>=v14.16.0'} hasBin: true peerDependencies: @@ -9214,25 +7798,6 @@ packages: vue: 3.2.33 dev: false - /w3c-hr-time/1.0.2: - resolution: {integrity: sha512-z8P5DvDNjKDoFIHK7q8r8lackT6l+jo/Ye3HOle7l9nICP9lf1Ci25fy9vHd0JOWewkIFzXIEig3TdKT7JQ5fQ==} - dependencies: - browser-process-hrtime: 1.0.0 - dev: true - - /w3c-xmlserializer/2.0.0: - resolution: {integrity: sha512-4tzD0mF8iSiMiNs30BiLO3EpfGLZUT2MSX/G+o7ZywDzliWQ3OPtTZ0PTC3B3ca1UAf4cJMHB+2Bf56EriJuRA==} - engines: {node: '>=10'} - dependencies: - xml-name-validator: 3.0.0 - dev: true - - /walker/1.0.8: - resolution: {integrity: sha512-ts/8E8l5b7kY0vlWLewOkDXMmPdLcVV4GmOQLyxuSswIJsweeFZtAsMF7k1Nszz+TYBQrlYRmzOnr398y1JemQ==} - dependencies: - makeerror: 1.0.12 - dev: true - /web-streams-polyfill/3.2.1: resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==} engines: {node: '>= 8'} @@ -9255,26 +7820,11 @@ packages: resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==} dev: true - /webidl-conversions/5.0.0: - resolution: {integrity: sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==} - engines: {node: '>=8'} - dev: true - /webidl-conversions/6.1.0: resolution: {integrity: sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==} engines: {node: '>=10.4'} dev: true - /whatwg-encoding/1.0.5: - resolution: {integrity: sha512-b5lim54JOPN9HtzvK9HFXvBma/rnfFeqsic0hSpjtDbVxR3dJKLc+KB4V6GgiGOvl7CY/KNh8rxSo9DKQrnUEw==} - dependencies: - iconv-lite: 0.4.24 - dev: true - - /whatwg-mimetype/2.3.0: - resolution: {integrity: sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==} - dev: true - /whatwg-url/5.0.0: resolution: {integrity: sha1-lmRU6HZUYuN2RNNib2dCzotwll0=} dependencies: @@ -9369,15 +7919,6 @@ packages: /wrappy/1.0.2: resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=} - /write-file-atomic/3.0.3: - resolution: {integrity: sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q==} - dependencies: - imurmurhash: 0.1.4 - is-typedarray: 1.0.0 - signal-exit: 3.0.7 - typedarray-to-buffer: 3.1.5 - dev: true - /ws/7.5.7: resolution: {integrity: sha512-KMvVuFzpKBuiIXW3E4u3mySRO2/mCHSyZDJQM5NQ9Q9KHWHWh0NHgfbRMLLrceUK5qAL4ytALJbpRMjixFZh8A==} engines: {node: '>=8.3.0'} @@ -9417,14 +7958,6 @@ packages: optional: true dev: true - /xml-name-validator/3.0.0: - resolution: {integrity: sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==} - dev: true - - /xmlchars/2.2.0: - resolution: {integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==} - dev: true - /xtend/4.0.2: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} diff --git a/scripts/jestEnv.cjs b/scripts/jestEnv.cjs deleted file mode 100644 index a053faef1a69a5..00000000000000 --- a/scripts/jestEnv.cjs +++ /dev/null @@ -1,48 +0,0 @@ -const os = require('os') -const fs = require('fs') -const path = require('path') -const NodeEnvironment = require('jest-environment-node') -const { chromium } = require('playwright-chromium') - -const DIR = path.join(os.tmpdir(), 'jest_playwright_global_setup') - -module.exports = class PlaywrightEnvironment extends NodeEnvironment { - constructor(config, context) { - super(config) - this.testPath = context.testPath - } - - async setup() { - await super.setup() - const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf-8') - if (!wsEndpoint) { - throw new Error('wsEndpoint not found') - } - - // skip browser setup for non-playground tests - if (!this.testPath.includes('playground')) { - return - } - - const browser = (this.browser = await chromium.connect({ - wsEndpoint - })) - this.global.page = await browser.newPage() - - const console = this.global.console - const warn = console.warn - console.warn = (msg, ...args) => { - // suppress @vue/reactivity-transform warning - if (msg.includes('@vue/reactivity-transform')) return - if (msg.includes('Generated an empty chunk')) return - warn.call(console, msg, ...args) - } - } - - async teardown() { - if (this.browser) { - await this.browser.close() - } - await super.teardown() - } -} diff --git a/scripts/jestGlobalTeardown.cjs b/scripts/jestGlobalTeardown.cjs deleted file mode 100644 index 786b7b95724fa3..00000000000000 --- a/scripts/jestGlobalTeardown.cjs +++ /dev/null @@ -1,9 +0,0 @@ -const fs = require('fs-extra') -const path = require('path') - -module.exports = async () => { - await global.__BROWSER_SERVER__.close() - if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) { - fs.removeSync(path.resolve(__dirname, '../playground-temp')) - } -} diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 5c70fcc7f15823..bb673b6c8e21fb 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -8,6 +8,6 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "types": ["node", "jest"] + "types": ["node", "vitest/globals"] } } diff --git a/scripts/jestGlobalSetup.cjs b/scripts/vitestGlobalSetup.ts similarity index 62% rename from scripts/jestGlobalSetup.cjs rename to scripts/vitestGlobalSetup.ts index b4098ba3f6f2c1..8a0b7ffad6c6b2 100644 --- a/scripts/jestGlobalSetup.cjs +++ b/scripts/vitestGlobalSetup.ts @@ -1,26 +1,27 @@ -// @ts-check -const os = require('os') -const fs = require('fs-extra') -const path = require('path') -const { chromium } = require('playwright-chromium') +import os from 'os' +import fs from 'fs-extra' +import path from 'path' +import type { BrowserServer } from 'playwright-chromium' +import { chromium } from 'playwright-chromium' -const DIR = path.join(os.tmpdir(), 'jest_playwright_global_setup') +const DIR = path.join(os.tmpdir(), 'vitest_playwright_global_setup') -module.exports = async () => { - const browserServer = await chromium.launchServer({ +let browserServer: BrowserServer | undefined + +export async function setup() { + browserServer = await chromium.launchServer({ headless: !process.env.VITE_DEBUG_SERVE, args: process.env.CI ? ['--no-sandbox', '--disable-setuid-sandbox'] : undefined }) - global.__BROWSER_SERVER__ = browserServer - await fs.mkdirp(DIR) await fs.writeFile(path.join(DIR, 'wsEndpoint'), browserServer.wsEndpoint()) const tempDir = path.resolve(__dirname, '../playground-temp') - await fs.remove(tempDir) + await fs.ensureDir(tempDir) + await fs.emptyDir(tempDir) await fs .copy(path.resolve(__dirname, '../playground'), tempDir, { dereference: false, @@ -39,3 +40,10 @@ module.exports = async () => { } }) } + +export async function teardown() { + browserServer?.close() + if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) { + fs.removeSync(path.resolve(__dirname, '../playground-temp')) + } +} diff --git a/scripts/jestPerTestSetup.ts b/scripts/vitestSetup.ts similarity index 80% rename from scripts/jestPerTestSetup.ts rename to scripts/vitestSetup.ts index 8160a04d9df4a9..4275d9d80864a5 100644 --- a/scripts/jestPerTestSetup.ts +++ b/scripts/vitestSetup.ts @@ -2,6 +2,9 @@ import fs from 'fs-extra' import * as http from 'http' import { resolve, dirname } from 'path' import sirv from 'sirv' +import os from 'os' +import path from 'path' +import { chromium } from 'playwright-chromium' import type { ViteDevServer, InlineConfig, @@ -12,6 +15,8 @@ import type { import { createServer, build, mergeConfig } from 'vite' import type { Page, ConsoleMessage } from 'playwright-chromium' import type { RollupError, RollupWatcher, RollupWatcherEvent } from 'rollup' +import type { File } from 'vitest' +import { beforeAll } from 'vitest' const isBuildTest = !!process.env.VITE_TEST_BUILD @@ -26,7 +31,7 @@ declare global { const browserLogs: string[] const browserErrors: Error[] const serverLogs: string[] - const viteTestUrl: string | undefined + let viteTestUrl: string | undefined const watcher: RollupWatcher | undefined let beforeAllError: Error | null // error caught in beforeAll, useful if you want to test error scenarios on build } @@ -63,32 +68,60 @@ const onPageError = (error: Error) => { errors.push(error) } -beforeAll(async () => { - const page = global.page - if (!page) { +const DIR = path.join(os.tmpdir(), 'vitest_playwright_global_setup') + +beforeAll(async (s) => { + const suite = s as File + const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf-8') + if (!wsEndpoint) { + throw new Error('wsEndpoint not found') + } + + // skip browser setup for non-playground tests + if (!suite.filepath.includes('playground')) { return } + + const browser = await chromium.connect(wsEndpoint) + const page = await browser.newPage() + // @ts-expect-error + globalThis.page = page + + const globalConsole = globalThis.console + const warn = globalConsole.warn + globalConsole.warn = (msg, ...args) => { + // suppress @vue/reactivity-transform warning + if (msg.includes('@vue/reactivity-transform')) return + if (msg.includes('Generated an empty chunk')) return + warn.call(globalConsole, msg, ...args) + } + try { page.on('console', onConsole) page.on('pageerror', onPageError) - const testPath = expect.getState().testPath + const testPath = suite.filepath! const testName = slash(testPath).match(/playground\/([\w-]+)\//)?.[1] // if this is a test placed under playground/xxx/__tests__ // start a vite server in that directory. if (testName) { - const playgroundRoot = resolve(__dirname, '../playground') tempDir = resolve(__dirname, '../playground-temp/', testName) // when `root` dir is present, use it as vite's root const testCustomRoot = resolve(tempDir, 'root') rootDir = fs.existsSync(testCustomRoot) ? testCustomRoot : tempDir - const testCustomServe = resolve(dirname(testPath), 'serve.js') - if (fs.existsSync(testCustomServe)) { + const testCustomServe = [ + resolve(dirname(testPath), 'serve.ts'), + resolve(dirname(testPath), 'serve.cjs'), + resolve(dirname(testPath), 'serve.js') + ].find((i) => fs.existsSync(i)) + if (testCustomServe) { // test has custom server configuration. - const { serve, preServe } = require(testCustomServe) + const mod = await import(testCustomServe) + const serve = mod.serve || mod.default?.serve + const preServe = mod.preServe || mod.default?.preServe if (preServe) { await preServe(rootDir, isBuildTest) } @@ -167,29 +200,30 @@ beforeAll(async () => { } } } catch (e: any) { - // jest doesn't exit if our setup has error here - // https://github.com/facebook/jest/issues/2713 - setBeforeAllError(e) - // Closing the page since an error in the setup, for example a runtime error // when building the playground should skip further tests. // If the page remains open, a command like `await page.click(...)` produces // a timeout with an exception that hides the real error in the console. await page.close() + + beforeAllError = e } -}, 30000) -afterAll(async () => { - global.page?.off('console', onConsole) - global.serverLogs = [] - await global.page?.close() - await server?.close() - global.watcher?.close() - const beforeAllErr = getBeforeAllError() - if (beforeAllErr) { - throw beforeAllErr + return async () => { + page?.off('console', onConsole) + global.serverLogs = [] + await page?.close() + await server?.close() + global.watcher?.close() + const beforeAllErr = getBeforeAllError() + if (browser) { + await browser.close() + } + if (beforeAllErr) { + throw beforeAllErr + } } -}) +}, 30000) function startStaticServer(config?: InlineConfig): Promise { if (!config) { diff --git a/vitest.config.e2e.ts b/vitest.config.e2e.ts new file mode 100644 index 00000000000000..a23378c97465b3 --- /dev/null +++ b/vitest.config.e2e.ts @@ -0,0 +1,21 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + include: ['./playground/**/*.spec.[tj]s'], + setupFiles: ['./scripts/vitestSetup.ts'], + globalSetup: ['./scripts/vitestGlobalSetup.ts'], + testTimeout: process.env.CI ? 50000 : 20000, + globals: true, + reporters: 'dot', + onConsoleLog(log) { + if (log.match(/experimental|jit engine|emitted file|tailwind/i)) + return false + }, + maxThreads: process.env.CI ? 1 : undefined, + minThreads: process.env.CI ? 1 : undefined + }, + esbuild: { + target: 'node14' + } +}) From b993c5f940b0cb69f34bff4c4b4cd6e546575ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 11 May 2022 15:53:46 +0900 Subject: [PATCH 101/114] perf(lib): reduce backtrack when injecting esbuild helpers (#8110) --- packages/vite/src/node/plugins/esbuild.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index bc4a1f780a54d5..6fdf74ee05c4ad 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -27,9 +27,9 @@ import { searchForWorkspaceRoot } from '..' const debug = createDebugger('vite:esbuild') const INJECT_HELPERS_IIFE_RE = - /(.*)(var [^\s]+=function\(.*\){"use strict";)(.*)/ + /(.*)(var [^\s]+=function\([^)]*?\){"use strict";)(.*)/ const INJECT_HELPERS_UMD_RE = - /(.*)(\(function\(.*\){.+amd.+function\(.*\){"use strict";)(.*)/ + /(.*)(\(function\([^)]*?\){.+amd.+function\([^)]*?\){"use strict";)(.*)/ let server: ViteDevServer From 6d84baafc184808a266875793a765b69423c0d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 11 May 2022 16:06:53 +0900 Subject: [PATCH 102/114] test: fix flaky lib test (#8108) Co-authored-by: Anthony Fu --- playground/lib/__tests__/lib.spec.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/playground/lib/__tests__/lib.spec.ts b/playground/lib/__tests__/lib.spec.ts index 6d7ca7c5670ea0..ab3314ffe3a546 100644 --- a/playground/lib/__tests__/lib.spec.ts +++ b/playground/lib/__tests__/lib.spec.ts @@ -1,4 +1,4 @@ -import { isBuild, testDir, isServe } from '../../testUtils' +import { isBuild, isServe, testDir, untilUpdated } from '../../testUtils' import path from 'path' import fs from 'fs' @@ -28,7 +28,10 @@ describe.runIf(isBuild)('build', () => { }) test('Library mode does not include `preload`', async () => { - expect(await page.textContent('.dynamic-import-message')).toBe('hello vite') + await untilUpdated( + () => page.textContent('.dynamic-import-message'), + 'hello vite' + ) const code = fs.readFileSync( path.join(testDir(), 'dist/lib/dynamic-import-message.js'), 'utf-8' From 54a941a1ad4089502ccda063a917623a87b6d6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 11 May 2022 16:37:16 +0900 Subject: [PATCH 103/114] fix: add direct query to html-proxy css (fixes #8091) (#8094) --- packages/vite/src/node/plugins/css.ts | 65 +++++++++---------- .../src/node/server/middlewares/indexHtml.ts | 2 +- .../css-sourcemap/__tests__/serve.spec.ts | 18 ++++- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 1e1bcef686ea42..8c2575c970d359 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -223,7 +223,8 @@ export function cssPlugin(config: ResolvedConfig): Plugin { const thisModule = moduleGraph.getModuleById(id) if (thisModule) { // CSS modules cannot self-accept since it exports values - const isSelfAccepting = !modules && !inlineRE.test(id) + const isSelfAccepting = + !modules && !inlineRE.test(id) && !htmlProxyRE.test(id) if (deps) { // record deps in the module graph so edits to @import css can trigger // main import to hot update @@ -301,7 +302,6 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { return } - const isHTMLProxy = htmlProxyRE.test(id) const inlined = inlineRE.test(id) const modules = cssModulesCache.get(config)!.get(id) @@ -314,43 +314,41 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { dataToEsm(modules, { namedExports: true, preferConst: true }) if (config.command === 'serve') { - if (isDirectCSSRequest(id)) { - return css - } else { - // server only - if (options?.ssr) { - return modulesCode || `export default ${JSON.stringify(css)}` - } - if (inlined) { - return `export default ${JSON.stringify(css)}` - } - - let cssContent = css + const getContentWithSourcemap = async (content: string) => { if (config.css?.devSourcemap) { const sourcemap = this.getCombinedSourcemap() await injectSourcesContent(sourcemap, cleanUrl(id), config.logger) - cssContent = getCodeWithSourcemap('css', css, sourcemap) - } - - if (isHTMLProxy) { - return cssContent + return getCodeWithSourcemap('css', content, sourcemap) } + return content + } - return [ - `import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${JSON.stringify( - path.posix.join(config.base, CLIENT_PUBLIC_PATH) - )}`, - `const __vite__id = ${JSON.stringify(id)}`, - `const __vite__css = ${JSON.stringify(cssContent)}`, - `__vite__updateStyle(__vite__id, __vite__css)`, - // css modules exports change on edit so it can't self accept - `${ - modulesCode || - `import.meta.hot.accept()\nexport default __vite__css` - }`, - `import.meta.hot.prune(() => __vite__removeStyle(__vite__id))` - ].join('\n') + if (isDirectCSSRequest(id)) { + return await getContentWithSourcemap(css) + } + // server only + if (options?.ssr) { + return modulesCode || `export default ${JSON.stringify(css)}` } + if (inlined) { + return `export default ${JSON.stringify(css)}` + } + + const cssContent = await getContentWithSourcemap(css) + return [ + `import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${JSON.stringify( + path.posix.join(config.base, CLIENT_PUBLIC_PATH) + )}`, + `const __vite__id = ${JSON.stringify(id)}`, + `const __vite__css = ${JSON.stringify(cssContent)}`, + `__vite__updateStyle(__vite__id, __vite__css)`, + // css modules exports change on edit so it can't self accept + `${ + modulesCode || + `import.meta.hot.accept()\nexport default __vite__css` + }`, + `import.meta.hot.prune(() => __vite__removeStyle(__vite__id))` + ].join('\n') } // build CSS handling ---------------------------------------------------- @@ -359,6 +357,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // cache css compile result to map // and then use the cache replace inline-style-flag when `generateBundle` in vite:build-html plugin const inlineCSS = inlineCSSRE.test(id) + const isHTMLProxy = htmlProxyRE.test(id) const query = parseRequest(id) if (inlineCSS && isHTMLProxy) { addToHTMLProxyTransformResult( diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 955ee6b708f54d..7b43ac0c67d428 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -217,7 +217,7 @@ const devHtmlHook: IndexHtmlTransformHook = async ( await Promise.all( styleUrl.map(async ({ start, end, code }, index) => { - const url = `${proxyModulePath}?html-proxy&index=${index}.css` + const url = `${proxyModulePath}?html-proxy&direct&index=${index}.css` // ensure module in graph after successful load const mod = await moduleGraph.ensureEntryFromUrl(url, false) diff --git a/playground/css-sourcemap/__tests__/serve.spec.ts b/playground/css-sourcemap/__tests__/serve.spec.ts index 34a627b68df736..2791300056074c 100644 --- a/playground/css-sourcemap/__tests__/serve.spec.ts +++ b/playground/css-sourcemap/__tests__/serve.spec.ts @@ -27,8 +27,22 @@ describe.runIf(isServe)('serve', () => { } ) const css = await res.text() - const lines = css.split('\n') - expect(lines[lines.length - 1].includes('/*')).toBe(false) // expect no sourcemap + const map = extractSourcemap(css) + expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` + Object { + "mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACT,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;", + "sources": Array [ + "/root/linked.css", + ], + "sourcesContent": Array [ + ".linked { + color: red; + } + ", + ], + "version": 3, + } + `) }) test('linked css with import', async () => { From edf6fe0381e11e4f1f4f9dba85c340d2421a87bf Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 11 May 2022 15:57:50 +0800 Subject: [PATCH 104/114] chore: update snapshot --- playground/css-sourcemap/__tests__/serve.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/playground/css-sourcemap/__tests__/serve.spec.ts b/playground/css-sourcemap/__tests__/serve.spec.ts index 2791300056074c..d42f93e84d4007 100644 --- a/playground/css-sourcemap/__tests__/serve.spec.ts +++ b/playground/css-sourcemap/__tests__/serve.spec.ts @@ -29,12 +29,12 @@ describe.runIf(isServe)('serve', () => { const css = await res.text() const map = extractSourcemap(css) expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - Object { + { "mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACT,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;", - "sources": Array [ + "sources": [ "/root/linked.css", ], - "sourcesContent": Array [ + "sourcesContent": [ ".linked { color: red; } From 43a58ddcd6fcf7bdaea6db6463bac2a6932cd248 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 11 May 2022 16:44:14 +0800 Subject: [PATCH 105/114] chore(lint): sort for imports (#8113) --- .eslintrc.cjs | 13 +++ package.json | 10 +- packages/plugin-react/src/fast-refresh.ts | 2 +- .../jsx-runtime/babel-import-to-require.ts | 2 +- .../src/jsx-runtime/babel-restore-jsx.spec.ts | 4 +- .../src/jsx-runtime/restore-jsx.spec.ts | 4 +- packages/plugin-vue/src/handleHotUpdate.ts | 2 +- packages/plugin-vue/src/main.ts | 16 +-- packages/plugin-vue/src/script.ts | 2 +- packages/plugin-vue/src/style.ts | 2 +- packages/plugin-vue/src/template.ts | 6 +- .../vite/src/node/__tests__/asset.spec.ts | 2 +- .../vite/src/node/__tests__/build.spec.ts | 4 +- .../vite/src/node/__tests__/config.spec.ts | 4 +- packages/vite/src/node/__tests__/dev.spec.ts | 2 +- .../src/node/__tests__/plugins/css.spec.ts | 6 +- .../src/node/__tests__/plugins/define.spec.ts | 2 +- .../plugins/dynamicImportVar/parse.test.ts | 2 +- .../src/node/__tests__/plugins/import.spec.ts | 2 +- packages/vite/src/node/__tests__/scan.spec.ts | 4 +- .../vite/src/node/__tests__/utils.spec.ts | 2 +- packages/vite/src/node/build.ts | 30 ++--- packages/vite/src/node/cli.ts | 2 +- packages/vite/src/node/config.ts | 32 +++--- packages/vite/src/node/http.ts | 6 +- packages/vite/src/node/logger.ts | 4 +- .../src/node/optimizer/esbuildDepPlugin.ts | 8 +- packages/vite/src/node/optimizer/index.ts | 16 +-- .../src/node/optimizer/registerMissing.ts | 20 ++-- packages/vite/src/node/optimizer/scan.ts | 26 ++--- packages/vite/src/node/plugin.ts | 6 +- packages/vite/src/node/plugins/asset.ts | 6 +- .../src/node/plugins/assetImportMetaUrl.ts | 8 +- .../vite/src/node/plugins/clientInjections.ts | 2 +- packages/vite/src/node/plugins/css.ts | 55 +++++----- packages/vite/src/node/plugins/dataUri.ts | 2 +- .../src/node/plugins/dynamicImportVars.ts | 6 +- packages/vite/src/node/plugins/esbuild.ts | 18 +-- packages/vite/src/node/plugins/html.ts | 30 ++--- .../vite/src/node/plugins/importAnalysis.ts | 60 +++++----- .../src/node/plugins/importAnalysisBuild.ts | 8 +- .../vite/src/node/plugins/importMetaGlob.ts | 4 +- packages/vite/src/node/plugins/index.ts | 2 +- .../vite/src/node/plugins/optimizedDeps.ts | 2 +- packages/vite/src/node/plugins/reporter.ts | 2 +- packages/vite/src/node/plugins/resolve.ts | 36 +++--- .../vite/src/node/plugins/splitVendorChunk.ts | 8 +- packages/vite/src/node/plugins/terser.ts | 2 +- packages/vite/src/node/plugins/worker.ts | 8 +- .../src/node/plugins/workerImportMetaUrl.ts | 12 +- packages/vite/src/node/preview.ts | 14 +-- .../server/__tests__/pluginContainer.spec.ts | 2 +- .../node/server/__tests__/search-root.spec.ts | 4 +- packages/vite/src/node/server/hmr.ts | 10 +- packages/vite/src/node/server/index.ts | 48 ++++---- .../vite/src/node/server/middlewares/base.ts | 2 +- .../vite/src/node/server/middlewares/error.ts | 4 +- .../src/node/server/middlewares/indexHtml.ts | 8 +- .../vite/src/node/server/middlewares/proxy.ts | 4 +- .../node/server/middlewares/spaFallback.ts | 2 +- .../src/node/server/middlewares/static.ts | 8 +- .../src/node/server/middlewares/transform.ts | 14 +-- packages/vite/src/node/server/moduleGraph.ts | 4 +- packages/vite/src/node/server/openBrowser.ts | 2 +- .../vite/src/node/server/pluginContainer.ts | 22 ++-- packages/vite/src/node/server/sourcemap.ts | 2 +- .../vite/src/node/server/transformRequest.ts | 12 +- packages/vite/src/node/server/ws.ts | 4 +- .../node/ssr/__tests__/ssrExternal.spec.ts | 2 +- .../ssr/__tests__/ssrModuleLoader.spec.ts | 2 +- .../node/ssr/__tests__/ssrTransform.spec.ts | 2 +- packages/vite/src/node/ssr/ssrExternal.ts | 2 +- .../vite/src/node/ssr/ssrManifestPlugin.ts | 2 +- packages/vite/src/node/ssr/ssrModuleLoader.ts | 16 +-- packages/vite/src/node/ssr/ssrTransform.ts | 12 +- packages/vite/src/node/utils.ts | 28 ++--- packages/vite/types/shims.d.ts | 2 +- packages/vite/types/ws.d.ts | 4 +- .../worker/__tests__/es/es-worker.spec.ts | 2 +- .../worker/__tests__/iife/worker.spec.ts | 2 +- pnpm-lock.yaml | 103 +++++++++++++++++- 81 files changed, 488 insertions(+), 371 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 63a8d282ba9b25..e75311e00ed7a2 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -8,6 +8,7 @@ module.exports = defineConfig({ 'plugin:node/recommended', 'plugin:@typescript-eslint/recommended' ], + plugins: ['import'], parser: '@typescript-eslint/parser', parserOptions: { sourceType: 'module', @@ -86,6 +87,18 @@ module.exports = defineConfig({ '@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports' } + ], + + 'import/order': 'error', + 'sort-imports': [ + 'error', + { + ignoreCase: false, + ignoreDeclarationSort: true, + ignoreMemberSort: false, + memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], + allowSeparatedGroups: false + } ] }, overrides: [ diff --git a/package.json b/package.json index 62a66770cb750a..9904f281fbc4f1 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "scripts": { "preinstall": "npx only-allow pnpm", "format": "prettier --write .", - "lint": "eslint packages/*/{src,types}/**", + "lint": "eslint packages/*/{src,types}/** playground/**/__tests__/**/*.*", "test": "run-s test-unit test-serve test-build", "test-serve": "vitest run -c vitest.config.e2e.ts", "test-build": "cross-env VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts", @@ -48,6 +48,7 @@ "esbuild": "^0.14.38", "eslint": "^8.15.0", "eslint-define-config": "^1.4.0", + "eslint-plugin-import": "^2.26.0", "eslint-plugin-node": "^11.1.0", "execa": "^5.1.1", "fs-extra": "^10.1.0", @@ -80,10 +81,13 @@ "prettier --write --ignore-unknown" ], "packages/*/{src,types}/**/*.ts": [ - "eslint --ext .ts" + "eslint --fix" ], "packages/**/*.d.ts": [ - "eslint --ext .ts" + "eslint --fix" + ], + "playground/**/__tests__/**/*.ts": [ + "eslint --fix" ] }, "packageManager": "pnpm@6.32.11", diff --git a/packages/plugin-react/src/fast-refresh.ts b/packages/plugin-react/src/fast-refresh.ts index 4672e26f6264e3..6bff7d94fa023b 100644 --- a/packages/plugin-react/src/fast-refresh.ts +++ b/packages/plugin-react/src/fast-refresh.ts @@ -1,6 +1,6 @@ -import type { types as t } from '@babel/core' import fs from 'fs' import path from 'path' +import type { types as t } from '@babel/core' export const runtimePublicPath = '/@react-refresh' diff --git a/packages/plugin-react/src/jsx-runtime/babel-import-to-require.ts b/packages/plugin-react/src/jsx-runtime/babel-import-to-require.ts index dc7129862fd976..01e4cc4c37d478 100644 --- a/packages/plugin-react/src/jsx-runtime/babel-import-to-require.ts +++ b/packages/plugin-react/src/jsx-runtime/babel-import-to-require.ts @@ -1,5 +1,5 @@ import type * as babelCore from '@babel/core' -import type { types as t, Visitor } from '@babel/core' +import type { Visitor, types as t } from '@babel/core' /** * Replace this: diff --git a/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts b/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts index 391007f68c1329..b37ef698e5f215 100644 --- a/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts +++ b/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts @@ -1,6 +1,6 @@ -import babelRestoreJSX from './babel-restore-jsx' import * as babel from '@babel/core' -import { describe, it, expect } from 'vitest' +import { describe, expect, it } from 'vitest' +import babelRestoreJSX from './babel-restore-jsx' function jsx(code: string) { return babel.transform(code, { diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts index 4f6a34ee60d915..fcad0f78c3373b 100644 --- a/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts +++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts @@ -1,6 +1,6 @@ -import { restoreJSX } from './restore-jsx' import * as babel from '@babel/core' -import { describe, it, expect } from 'vitest' +import { describe, expect, it } from 'vitest' +import { restoreJSX } from './restore-jsx' async function jsx(sourceCode: string) { const [ast] = await restoreJSX(babel, sourceCode, 'test.js') diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 7c2a7ef7ee2f1f..fbf7d2c1f5d490 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -1,12 +1,12 @@ import _debug from 'debug' import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc' +import type { HmrContext, ModuleNode } from 'vite' import { createDescriptor, getDescriptor, setPrevDescriptor } from './utils/descriptorCache' import { getResolvedScript, setResolvedScript } from './script' -import type { ModuleNode, HmrContext } from 'vite' import type { ResolvedOptions } from '.' const debug = _debug('vite:hmr') diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index ccc700f184d0e4..8fa01e494f58e2 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -1,21 +1,21 @@ import path from 'path' import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc' -import type { ResolvedOptions } from '.' +import type { PluginContext, SourceMap, TransformPluginContext } from 'rollup' +import { normalizePath } from '@rollup/pluginutils' +import type { RawSourceMap } from 'source-map' +import { SourceMapConsumer, SourceMapGenerator } from 'source-map' +import { transformWithEsbuild } from 'vite' import { createDescriptor, getPrevDescriptor, setSrcDescriptor } from './utils/descriptorCache' -import type { PluginContext, SourceMap, TransformPluginContext } from 'rollup' -import { normalizePath } from '@rollup/pluginutils' -import { resolveScript, isUseInlineTemplate } from './script' +import { isUseInlineTemplate, resolveScript } from './script' import { transformTemplateInMain } from './template' -import { isOnlyTemplateChanged, isEqualBlock } from './handleHotUpdate' -import type { RawSourceMap } from 'source-map' -import { SourceMapConsumer, SourceMapGenerator } from 'source-map' +import { isEqualBlock, isOnlyTemplateChanged } from './handleHotUpdate' import { createRollupError } from './utils/error' -import { transformWithEsbuild } from 'vite' import { EXPORT_HELPER_ID } from './helper' +import type { ResolvedOptions } from '.' // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export async function transformMain( diff --git a/packages/plugin-vue/src/script.ts b/packages/plugin-vue/src/script.ts index 93610dcf7f6a36..f5d488c22c279a 100644 --- a/packages/plugin-vue/src/script.ts +++ b/packages/plugin-vue/src/script.ts @@ -1,6 +1,6 @@ import type { SFCDescriptor, SFCScriptBlock } from 'vue/compiler-sfc' -import type { ResolvedOptions } from '.' import { resolveTemplateCompilerOptions } from './template' +import type { ResolvedOptions } from '.' // ssr and non ssr builds would output different script content const clientCache = new WeakMap() diff --git a/packages/plugin-vue/src/style.ts b/packages/plugin-vue/src/style.ts index cab75791bd54ec..aa124de17b8894 100644 --- a/packages/plugin-vue/src/style.ts +++ b/packages/plugin-vue/src/style.ts @@ -1,8 +1,8 @@ import type { SFCDescriptor } from 'vue/compiler-sfc' import type { ExistingRawSourceMap, TransformPluginContext } from 'rollup' -import type { ResolvedOptions } from '.' import type { RawSourceMap } from 'source-map' import { formatPostcssSourceMap } from 'vite' +import type { ResolvedOptions } from '.' // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export async function transformStyle( diff --git a/packages/plugin-vue/src/template.ts b/packages/plugin-vue/src/template.ts index c7eed9015d6339..c44da9e67228b0 100644 --- a/packages/plugin-vue/src/template.ts +++ b/packages/plugin-vue/src/template.ts @@ -1,15 +1,15 @@ import path from 'path' import slash from 'slash' import type { + CompilerOptions, SFCDescriptor, SFCTemplateCompileOptions, - SFCTemplateCompileResults, - CompilerOptions + SFCTemplateCompileResults } from 'vue/compiler-sfc' import type { PluginContext, TransformPluginContext } from 'rollup' -import type { ResolvedOptions } from '.' import { getResolvedScript } from './script' import { createRollupError } from './utils/error' +import type { ResolvedOptions } from '.' // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export async function transformTemplateAsModule( diff --git a/packages/vite/src/node/__tests__/asset.spec.ts b/packages/vite/src/node/__tests__/asset.spec.ts index 8727aa6485eb26..a756cb12652739 100644 --- a/packages/vite/src/node/__tests__/asset.spec.ts +++ b/packages/vite/src/node/__tests__/asset.spec.ts @@ -1,4 +1,4 @@ -import { describe, test, expect } from 'vitest' +import { describe, expect, test } from 'vitest' import { assetFileNamesToFileName, getAssetHash } from '../plugins/asset' describe('getAssetHash', () => { diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index b49847f1d955a4..3b34851203e149 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -1,7 +1,7 @@ +import { resolve } from 'path' +import { describe, expect, test } from 'vitest' import type { LibraryFormats, LibraryOptions } from '../build' import { resolveLibFilename } from '../build' -import { resolve } from 'path' -import { describe, test, expect } from 'vitest' type FormatsToFileNames = [LibraryFormats, string][] const baseLibOptions: LibraryOptions = { diff --git a/packages/vite/src/node/__tests__/config.spec.ts b/packages/vite/src/node/__tests__/config.spec.ts index 83995ab28adcbd..4eaeae2822a1e3 100644 --- a/packages/vite/src/node/__tests__/config.spec.ts +++ b/packages/vite/src/node/__tests__/config.spec.ts @@ -1,7 +1,7 @@ +import { describe, expect, test } from 'vitest' import type { InlineConfig } from '..' -import type { UserConfigExport, UserConfig } from '../config' +import type { UserConfig, UserConfigExport } from '../config' import { mergeConfig, resolveConfig, resolveEnvPrefix } from '../config' -import { describe, test, expect } from 'vitest' describe('mergeConfig', () => { test('handles configs with different alias schemas', () => { diff --git a/packages/vite/src/node/__tests__/dev.spec.ts b/packages/vite/src/node/__tests__/dev.spec.ts index cdb0fc123f4b4f..3b3b3d14553da4 100644 --- a/packages/vite/src/node/__tests__/dev.spec.ts +++ b/packages/vite/src/node/__tests__/dev.spec.ts @@ -1,5 +1,5 @@ +import { describe, expect, test } from 'vitest' import { resolveConfig } from '..' -import { describe, test, expect } from 'vitest' describe('resolveBuildOptions in dev', () => { test('build.rollupOptions should not have input in lib', async () => { diff --git a/packages/vite/src/node/__tests__/plugins/css.spec.ts b/packages/vite/src/node/__tests__/plugins/css.spec.ts index 70ddb640b13218..e6b919a0094aa6 100644 --- a/packages/vite/src/node/__tests__/plugins/css.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/css.spec.ts @@ -1,8 +1,8 @@ -import { cssUrlRE, cssPlugin, hoistAtRules } from '../../plugins/css' -import { resolveConfig } from '../../config' import fs from 'fs' import path from 'path' -import { describe, vi, test, expect } from 'vitest' +import { describe, expect, test, vi } from 'vitest' +import { resolveConfig } from '../../config' +import { cssPlugin, cssUrlRE, hoistAtRules } from '../../plugins/css' describe('search css url function', () => { test('some spaces before it', () => { diff --git a/packages/vite/src/node/__tests__/plugins/define.spec.ts b/packages/vite/src/node/__tests__/plugins/define.spec.ts index b9acc81cb790d5..932560a749f24d 100644 --- a/packages/vite/src/node/__tests__/plugins/define.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/define.spec.ts @@ -1,4 +1,4 @@ -import { describe, test, expect } from 'vitest' +import { describe, expect, test } from 'vitest' import { definePlugin } from '../../plugins/define' import { resolveConfig } from '../../config' diff --git a/packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.test.ts b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.test.ts index ef1dcb2238a5b0..a0017d50ae6cd2 100644 --- a/packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.test.ts +++ b/packages/vite/src/node/__tests__/plugins/dynamicImportVar/parse.test.ts @@ -1,6 +1,6 @@ +import { resolve } from 'path' import { describe, expect, it } from 'vitest' import { transformDynamicImport } from '../../../plugins/dynamicImportVars' -import { resolve } from 'path' async function run(input: string) { const { glob, rawPattern } = await transformDynamicImport( diff --git a/packages/vite/src/node/__tests__/plugins/import.spec.ts b/packages/vite/src/node/__tests__/plugins/import.spec.ts index e232702d57d354..661f35902ab580 100644 --- a/packages/vite/src/node/__tests__/plugins/import.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/import.spec.ts @@ -1,4 +1,4 @@ -import { describe, test, expect } from 'vitest' +import { describe, expect, test } from 'vitest' import { transformCjsImport } from '../../plugins/importAnalysis' describe('transformCjsImport', () => { diff --git a/packages/vite/src/node/__tests__/scan.spec.ts b/packages/vite/src/node/__tests__/scan.spec.ts index 8d5a275fca0292..0f9475562365d5 100644 --- a/packages/vite/src/node/__tests__/scan.spec.ts +++ b/packages/vite/src/node/__tests__/scan.spec.ts @@ -1,6 +1,6 @@ -import { scriptRE, commentRE, importsRE } from '../optimizer/scan' +import { describe, expect, test } from 'vitest' +import { commentRE, importsRE, scriptRE } from '../optimizer/scan' import { multilineCommentsRE, singlelineCommentsRE } from '../utils' -import { describe, test, expect } from 'vitest' describe('optimizer-scan:script-test', () => { const scriptContent = `import { defineComponent } from 'vue' diff --git a/packages/vite/src/node/__tests__/utils.spec.ts b/packages/vite/src/node/__tests__/utils.spec.ts index 29fd53f3c9a32e..56b5db32c2caf4 100644 --- a/packages/vite/src/node/__tests__/utils.spec.ts +++ b/packages/vite/src/node/__tests__/utils.spec.ts @@ -1,10 +1,10 @@ +import { describe, expect, test } from 'vitest' import { getPotentialTsSrcPaths, injectQuery, isWindows, resolveHostname } from '../utils' -import { describe, test, expect } from 'vitest' describe('injectQuery', () => { if (isWindows) { diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index cc254521b8d2aa..73db49c1c2b7ae 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -1,40 +1,40 @@ import fs from 'fs' import path from 'path' import colors from 'picocolors' -import type { InlineConfig, ResolvedConfig } from './config' -import { resolveConfig } from './config' import type { + ExternalOption, + ModuleFormat, + OutputOptions, Plugin, RollupBuild, + RollupError, RollupOptions, - RollupWarning, - WarningHandler, - OutputOptions, RollupOutput, - ExternalOption, - WatcherOptions, + RollupWarning, RollupWatcher, - RollupError, - ModuleFormat + WarningHandler, + WatcherOptions } from 'rollup' import type Rollup from 'rollup' +import type { Terser } from 'types/terser' +import commonjsPlugin from '@rollup/plugin-commonjs' +import type { RollupCommonJSOptions } from 'types/commonjs' +import type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars' +import type { TransformOptions } from 'esbuild' +import type { InlineConfig, ResolvedConfig } from './config' +import { resolveConfig } from './config' import { buildReporterPlugin } from './plugins/reporter' import { buildEsbuildPlugin } from './plugins/esbuild' import { terserPlugin } from './plugins/terser' -import type { Terser } from 'types/terser' import { copyDir, emptyDir, lookupFile, normalizePath } from './utils' import { manifestPlugin } from './plugins/manifest' -import commonjsPlugin from '@rollup/plugin-commonjs' -import type { RollupCommonJSOptions } from 'types/commonjs' -import type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars' import type { Logger } from './logger' -import type { TransformOptions } from 'esbuild' import { dataURIPlugin } from './plugins/dataUri' import { buildImportAnalysisPlugin } from './plugins/importAnalysisBuild' import { resolveSSRExternal, shouldExternalizeForSSR } from './ssr/ssrExternal' import { ssrManifestPlugin } from './ssr/ssrManifestPlugin' import type { DepOptimizationMetadata } from './optimizer' -import { getDepsCacheDir, findKnownImports } from './optimizer' +import { findKnownImports, getDepsCacheDir } from './optimizer' import { assetImportMetaUrlPlugin } from './plugins/assetImportMetaUrl' import { loadFallbackPlugin } from './plugins/loadFallback' import type { PackageData } from './packages' diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index 89412a825e9fc1..9ee807f505e016 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -1,6 +1,6 @@ +import { performance } from 'perf_hooks' import { cac } from 'cac' import colors from 'picocolors' -import { performance } from 'perf_hooks' import type { BuildOptions } from './build' import type { ServerOptions } from './server' import type { LogLevel } from './logger' diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index e7fcaefeb2a799..138514579f3ee0 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -1,45 +1,45 @@ import fs from 'fs' import path from 'path' +import { parse as parseUrl, pathToFileURL } from 'url' +import { performance } from 'perf_hooks' +import colors from 'picocolors' +import dotenv from 'dotenv' +import dotenvExpand from 'dotenv-expand' +import type { Alias, AliasOptions } from 'types/alias' +import { createFilter } from '@rollup/pluginutils' +import aliasPlugin from '@rollup/plugin-alias' +import { build } from 'esbuild' +import type { RollupOptions } from 'rollup' import type { Plugin } from './plugin' import type { BuildOptions } from './build' import { resolveBuildOptions } from './build' import type { ResolvedServerOptions, ServerOptions } from './server' import { resolveServerOptions } from './server' -import type { ResolvedPreviewOptions, PreviewOptions } from './preview' +import type { PreviewOptions, ResolvedPreviewOptions } from './preview' import { resolvePreviewOptions } from './preview' import type { CSSOptions } from './plugins/css' import { arraify, createDebugger, + dynamicImport, isExternalUrl, isObject, lookupFile, - normalizePath, - dynamicImport + normalizePath } from './utils' import { resolvePlugins } from './plugins' -import colors from 'picocolors' import type { ESBuildOptions } from './plugins/esbuild' -import dotenv from 'dotenv' -import dotenvExpand from 'dotenv-expand' -import type { Alias, AliasOptions } from 'types/alias' -import { CLIENT_ENTRY, ENV_ENTRY, DEFAULT_ASSETS_RE } from './constants' +import { CLIENT_ENTRY, DEFAULT_ASSETS_RE, ENV_ENTRY } from './constants' import type { InternalResolveOptions, ResolveOptions } from './plugins/resolve' import { resolvePlugin } from './plugins/resolve' -import type { Logger, LogLevel } from './logger' +import type { LogLevel, Logger } from './logger' import { createLogger } from './logger' import type { DepOptimizationOptions } from './optimizer' -import { createFilter } from '@rollup/pluginutils' -import type { ResolvedBuildOptions } from '.' -import { parse as parseUrl, pathToFileURL } from 'url' import type { JsonOptions } from './plugins/json' import type { PluginContainer } from './server/pluginContainer' import { createPluginContainer } from './server/pluginContainer' -import aliasPlugin from '@rollup/plugin-alias' -import { build } from 'esbuild' -import { performance } from 'perf_hooks' import type { PackageCache } from './packages' -import type { RollupOptions } from 'rollup' +import type { ResolvedBuildOptions } from '.' const debug = createDebugger('vite:config') diff --git a/packages/vite/src/node/http.ts b/packages/vite/src/node/http.ts index 18140b031937a9..1aa924282483b8 100644 --- a/packages/vite/src/node/http.ts +++ b/packages/vite/src/node/http.ts @@ -1,13 +1,13 @@ import fs, { promises as fsp } from 'fs' import path from 'path' import type { - OutgoingHttpHeaders as HttpServerHeaders, - Server as HttpServer + Server as HttpServer, + OutgoingHttpHeaders as HttpServerHeaders } from 'http' import type { ServerOptions as HttpsServerOptions } from 'https' +import type { Connect } from 'types/connect' import { isObject } from './utils' import type { ProxyOptions } from './server/middlewares/proxy' -import type { Connect } from 'types/connect' import type { Logger } from './logger' export interface CommonServerOptions { diff --git a/packages/vite/src/node/logger.ts b/packages/vite/src/node/logger.ts index 4f5784aeb527ff..c0f316ffed2698 100644 --- a/packages/vite/src/node/logger.ts +++ b/packages/vite/src/node/logger.ts @@ -1,14 +1,14 @@ /* eslint no-console: 0 */ -import colors from 'picocolors' import type { AddressInfo, Server } from 'net' import os from 'os' import readline from 'readline' +import colors from 'picocolors' import type { RollupError } from 'rollup' -import type { ResolvedConfig } from '.' import type { CommonServerOptions } from './http' import type { Hostname } from './utils' import { resolveHostname } from './utils' +import type { ResolvedConfig } from '.' export type LogType = 'error' | 'warn' | 'info' export type LogLevel = LogType | 'silent' diff --git a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts index 4303be0ec876e7..9fcc649ef394e3 100644 --- a/packages/vite/src/node/optimizer/esbuildDepPlugin.ts +++ b/packages/vite/src/node/optimizer/esbuildDepPlugin.ts @@ -1,13 +1,13 @@ import path from 'path' -import type { Plugin, ImportKind } from 'esbuild' +import type { ImportKind, Plugin } from 'esbuild' import { KNOWN_ASSET_TYPES } from '../constants' import type { ResolvedConfig } from '..' import { - isRunningWithYarnPnp, flattenId, - normalizePath, isExternalUrl, - moduleListContains + isRunningWithYarnPnp, + moduleListContains, + normalizePath } from '../utils' import { browserExternalId } from '../plugins/resolve' import type { ExportsData } from '.' diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 33419e0d186487..53bffb13e604d0 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1,27 +1,27 @@ import fs from 'fs' import path from 'path' +import { createHash } from 'crypto' +import { performance } from 'perf_hooks' import _debug from 'debug' import colors from 'picocolors' -import { createHash } from 'crypto' import type { BuildOptions as EsbuildBuildOptions } from 'esbuild' import { build } from 'esbuild' +import { init, parse } from 'es-module-lexer' import type { ResolvedConfig } from '../config' import { createDebugger, emptyDir, - lookupFile, - normalizePath, - writeFile, flattenId, + lookupFile, normalizeId, + normalizePath, removeDirSync, - renameDir + renameDir, + writeFile } from '../utils' +import { transformWithEsbuild } from '../plugins/esbuild' import { esbuildDepPlugin } from './esbuildDepPlugin' -import { init, parse } from 'es-module-lexer' import { scanImports } from './scan' -import { transformWithEsbuild } from '../plugins/esbuild' -import { performance } from 'perf_hooks' export const debuggerViteDeps = createDebugger('vite:deps') const debug = debuggerViteDeps diff --git a/packages/vite/src/node/optimizer/registerMissing.ts b/packages/vite/src/node/optimizer/registerMissing.ts index 53cd7e981b1b61..1efb9e02261ae7 100644 --- a/packages/vite/src/node/optimizer/registerMissing.ts +++ b/packages/vite/src/node/optimizer/registerMissing.ts @@ -1,24 +1,24 @@ import colors from 'picocolors' import _debug from 'debug' +import type { ViteDevServer } from '..' import { - runOptimizeDeps, - getOptimizedDepPath, - getHash, - depsFromOptimizedDepInfo, - newDepOptimizationProcessing, - loadCachedDepOptimizationMetadata, - createOptimizedDepsMetadata, addOptimizedDepInfo, - discoverProjectDependencies, + createOptimizedDepsMetadata, + debuggerViteDeps as debug, + depsFromOptimizedDepInfo, depsLogString, - debuggerViteDeps as debug + discoverProjectDependencies, + getHash, + getOptimizedDepPath, + loadCachedDepOptimizationMetadata, + newDepOptimizationProcessing, + runOptimizeDeps } from '.' import type { DepOptimizationProcessing, OptimizedDepInfo, OptimizedDeps } from '.' -import type { ViteDevServer } from '..' const isDebugEnabled = _debug('vite:deps').enabled diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 8dfac45c4e6612..157c8d28db1083 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -1,32 +1,32 @@ import fs from 'fs' import path from 'path' +import { performance } from 'perf_hooks' import glob from 'fast-glob' -import type { ResolvedConfig } from '..' -import type { Loader, Plugin, OnLoadResult } from 'esbuild' +import type { Loader, OnLoadResult, Plugin } from 'esbuild' import { build } from 'esbuild' +import colors from 'picocolors' +import type { ResolvedConfig } from '..' import { - KNOWN_ASSET_TYPES, JS_TYPES_RE, - SPECIAL_QUERY_RE, - OPTIMIZABLE_ENTRY_RE + KNOWN_ASSET_TYPES, + OPTIMIZABLE_ENTRY_RE, + SPECIAL_QUERY_RE } from '../constants' import { + cleanUrl, createDebugger, - normalizePath, + dataUrlRE, + externalRE, isObject, - cleanUrl, moduleListContains, - externalRE, - dataUrlRE, multilineCommentsRE, + normalizePath, singlelineCommentsRE, - virtualModuleRE, - virtualModulePrefix + virtualModulePrefix, + virtualModuleRE } from '../utils' import type { PluginContainer } from '../server/pluginContainer' import { createPluginContainer } from '../server/pluginContainer' -import { performance } from 'perf_hooks' -import colors from 'picocolors' import { transformGlobImport } from '../plugins/importMetaGlob' const debug = createDebugger('vite:deps') diff --git a/packages/vite/src/node/plugin.ts b/packages/vite/src/node/plugin.ts index 3bfe789a299987..adf647d6d5500f 100644 --- a/packages/vite/src/node/plugin.ts +++ b/packages/vite/src/node/plugin.ts @@ -1,19 +1,19 @@ -import type { UserConfig } from './config' import type { CustomPluginOptions, LoadResult, - Plugin as RollupPlugin, PluginContext, ResolveIdResult, + Plugin as RollupPlugin, TransformPluginContext, TransformResult } from 'rollup' +import type { UserConfig } from './config' import type { ServerHook } from './server' import type { IndexHtmlTransform } from './plugins/html' import type { ModuleNode } from './server/moduleGraph' -import type { ConfigEnv, ResolvedConfig } from './' import type { HmrContext } from './server/hmr' import type { PreviewServerHook } from './preview' +import type { ConfigEnv, ResolvedConfig } from './' /** * Vite plugins extends the Rollup plugin interface with a few extra diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index f2eed2bc28bc5a..db62325509f308 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -1,14 +1,14 @@ import path from 'path' import { parse as parseUrl } from 'url' import fs, { promises as fsp } from 'fs' +import { createHash } from 'crypto' import * as mrmime from 'mrmime' +import type { OutputOptions, PluginContext } from 'rollup' +import MagicString from 'magic-string' import type { Plugin } from '../plugin' import type { ResolvedConfig } from '../config' import { cleanUrl } from '../utils' import { FS_PREFIX } from '../constants' -import type { OutputOptions, PluginContext } from 'rollup' -import MagicString from 'magic-string' -import { createHash } from 'crypto' import { normalizePath } from '../utils' export const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g diff --git a/packages/vite/src/node/plugins/assetImportMetaUrl.ts b/packages/vite/src/node/plugins/assetImportMetaUrl.ts index 73932bfb29a411..2bff4f5e7b682e 100644 --- a/packages/vite/src/node/plugins/assetImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/assetImportMetaUrl.ts @@ -1,9 +1,9 @@ -import type { Plugin } from '../plugin' -import MagicString from 'magic-string' import path from 'path' -import { fileToUrl } from './asset' -import type { ResolvedConfig } from '../config' +import MagicString from 'magic-string' import { stripLiteral } from 'strip-literal' +import type { Plugin } from '../plugin' +import type { ResolvedConfig } from '../config' +import { fileToUrl } from './asset' /** * Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL diff --git a/packages/vite/src/node/plugins/clientInjections.ts b/packages/vite/src/node/plugins/clientInjections.ts index 1c9a0d393327c7..eb5c7183c2ac59 100644 --- a/packages/vite/src/node/plugins/clientInjections.ts +++ b/packages/vite/src/node/plugins/clientInjections.ts @@ -2,7 +2,7 @@ import path from 'path' import type { Plugin } from '../plugin' import type { ResolvedConfig } from '../config' import { CLIENT_ENTRY, ENV_ENTRY } from '../constants' -import { normalizePath, isObject } from '../utils' +import { isObject, normalizePath } from '../utils' // ids in transform are normalized to unix style const normalizedClientEntry = normalizePath(CLIENT_ENTRY) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 8c2575c970d359..bee3e37d4cbe38 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -1,21 +1,6 @@ import fs from 'fs' import path from 'path' import glob from 'fast-glob' -import { - // createDebugger, - isExternalUrl, - asyncReplace, - cleanUrl, - generateCodeFrame, - isDataUrl, - isObject, - normalizePath, - processSrcSet, - parseRequest, - combineSourcemaps -} from '../utils' -import type { Plugin } from '../plugin' -import type { ResolvedConfig } from '../config' import postcssrc from 'postcss-load-config' import type { ExistingRawSourceMap, @@ -27,15 +12,6 @@ import type { } from 'rollup' import { dataToEsm } from '@rollup/pluginutils' import colors from 'picocolors' -import { CLIENT_PUBLIC_PATH, SPECIAL_QUERY_RE } from '../constants' -import type { ResolveFn, ViteDevServer } from '../' -import { - getAssetFilename, - assetUrlRE, - fileToUrl, - checkPublicFile, - getAssetHash -} from './asset' import MagicString from 'magic-string' import type * as PostCSS from 'postcss' import type Sass from 'sass' @@ -44,12 +20,35 @@ import type Sass from 'sass' import type Stylus from 'stylus' // eslint-disable-line node/no-extraneous-import import type Less from 'less' import type { Alias } from 'types/alias' -import type { ModuleNode } from '../server/moduleGraph' -import { transform, formatMessages } from 'esbuild' -import { addToHTMLProxyTransformResult } from './html' -import { injectSourcesContent, getCodeWithSourcemap } from '../server/sourcemap' +import { formatMessages, transform } from 'esbuild' import type { RawSourceMap } from '@ampproject/remapping' +import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap' +import type { ModuleNode } from '../server/moduleGraph' +import type { ResolveFn, ViteDevServer } from '../' +import { CLIENT_PUBLIC_PATH, SPECIAL_QUERY_RE } from '../constants' +import type { ResolvedConfig } from '../config' +import type { Plugin } from '../plugin' +import { + asyncReplace, + cleanUrl, + combineSourcemaps, + generateCodeFrame, + isDataUrl, + isExternalUrl, + isObject, + normalizePath, + parseRequest, + processSrcSet +} from '../utils' import { emptyCssComments } from '../utils' +import { addToHTMLProxyTransformResult } from './html' +import { + assetUrlRE, + checkPublicFile, + fileToUrl, + getAssetFilename, + getAssetHash +} from './asset' // const debug = createDebugger('vite:css') diff --git a/packages/vite/src/node/plugins/dataUri.ts b/packages/vite/src/node/plugins/dataUri.ts index 5f5f40146097df..84999d586c4f34 100644 --- a/packages/vite/src/node/plugins/dataUri.ts +++ b/packages/vite/src/node/plugins/dataUri.ts @@ -1,8 +1,8 @@ // This is based on @rollup/plugin-data-uri // MIT Licensed https://github.com/rollup/plugins/blob/master/LICENSE // ref https://github.com/vitejs/vite/issues/1428#issuecomment-757033808 -import type { Plugin } from '../plugin' import { URL } from 'url' +import type { Plugin } from '../plugin' const dataUriRE = /^([^/]+\/[^;,]+)(;base64)?,([\s\S]*)$/ diff --git a/packages/vite/src/node/plugins/dynamicImportVars.ts b/packages/vite/src/node/plugins/dynamicImportVars.ts index c33590cf0343f4..7559d637ce648e 100644 --- a/packages/vite/src/node/plugins/dynamicImportVars.ts +++ b/packages/vite/src/node/plugins/dynamicImportVars.ts @@ -2,12 +2,12 @@ import { posix } from 'path' import MagicString from 'magic-string' import { init, parse as parseImports } from 'es-module-lexer' import type { ImportSpecifier } from 'es-module-lexer' -import type { Plugin } from '../plugin' -import type { ResolvedConfig } from '../config' -import { normalizePath, parseRequest, requestQuerySplitRE } from '../utils' import { parse as parseJS } from 'acorn' import { createFilter } from '@rollup/pluginutils' import { dynamicImportToGlob } from '@rollup/plugin-dynamic-import-vars' +import type { Plugin } from '../plugin' +import type { ResolvedConfig } from '../config' +import { normalizePath, parseRequest, requestQuerySplitRE } from '../utils' export const dynamicImportHelperId = '/@vite/dynamic-import-helper' diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 6fdf74ee05c4ad..5250f4baf7687b 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -1,13 +1,19 @@ import path from 'path' import colors from 'picocolors' -import type { Plugin } from '../plugin' import type { - Message, Loader, + Message, TransformOptions, TransformResult } from 'esbuild' import { transform } from 'esbuild' +import type { RawSourceMap } from '@ampproject/remapping' +import type { SourceMap } from 'rollup' +import { createFilter } from '@rollup/pluginutils' +import type { TSConfckParseOptions, TSConfckParseResult } from 'tsconfck' +import { TSConfckParseError, findAll, parse } from 'tsconfck' +import { combineSourcemaps } from '../utils' +import type { ResolvedConfig, ViteDevServer } from '..' import { cleanUrl, createDebugger, @@ -15,13 +21,7 @@ import { generateCodeFrame, toUpperCaseDriveLetter } from '../utils' -import type { RawSourceMap } from '@ampproject/remapping' -import type { SourceMap } from 'rollup' -import type { ResolvedConfig, ViteDevServer } from '..' -import { createFilter } from '@rollup/pluginutils' -import { combineSourcemaps } from '../utils' -import type { TSConfckParseOptions, TSConfckParseResult } from 'tsconfck' -import { parse, findAll, TSConfckParseError } from 'tsconfck' +import type { Plugin } from '../plugin' import { searchForWorkspaceRoot } from '..' const debug = createDebugger('vite:esbuild') diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index 2f1e3af34babb4..ea178287f672a1 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -1,6 +1,4 @@ import path from 'path' -import type { Plugin } from '../plugin' -import type { ViteDevServer } from '../server' import type { OutputAsset, OutputBundle, @@ -8,6 +6,18 @@ import type { RollupError, SourceMapInput } from 'rollup' +import MagicString from 'magic-string' +import type { + AttributeNode, + CompilerError, + ElementNode, + NodeTransform, + TextNode +} from '@vue/compiler-dom' +import { NodeTypes } from '@vue/compiler-dom' +import { stripLiteral } from 'strip-literal' +import type { Plugin } from '../plugin' +import type { ViteDevServer } from '../server' import { cleanUrl, generateCodeFrame, @@ -18,25 +28,15 @@ import { slash } from '../utils' import type { ResolvedConfig } from '../config' -import MagicString from 'magic-string' import { - checkPublicFile, assetUrlRE, - urlToBuiltUrl, + checkPublicFile, getAssetFilename, - getAssetHash + getAssetHash, + urlToBuiltUrl } from './asset' import { isCSSRequest } from './css' import { modulePreloadPolyfillId } from './modulePreloadPolyfill' -import type { - AttributeNode, - NodeTransform, - ElementNode, - CompilerError, - TextNode -} from '@vue/compiler-dom' -import { NodeTypes } from '@vue/compiler-dom' -import { stripLiteral } from 'strip-literal' interface ScriptAssetsUrl { start: number diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index f12426aa923cfe..d33235805aa5ee 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -1,56 +1,56 @@ import fs from 'fs' import path from 'path' -import type { Plugin } from '../plugin' -import type { ResolvedConfig } from '../config' +import { performance } from 'perf_hooks' import colors from 'picocolors' import MagicString from 'magic-string' import type { ImportSpecifier } from 'es-module-lexer' import { init, parse as parseImports } from 'es-module-lexer' -import { isCSSRequest, isDirectCSSRequest } from './css' +import { parse as parseJS } from 'acorn' +import type { Node } from 'estree' +import { makeLegalIdentifier } from '@rollup/pluginutils' +import type { ViteDevServer } from '..' +import { + CLIENT_DIR, + CLIENT_PUBLIC_PATH, + DEP_VERSION_RE, + FS_PREFIX, + NULL_BYTE_PLACEHOLDER, + VALID_ID_PREFIX +} from '../constants' +import { + debugHmr, + handlePrunedModules, + lexAcceptedHmrDeps +} from '../server/hmr' import { - isBuiltin, cleanUrl, createDebugger, + fsPathFromUrl, generateCodeFrame, injectQuery, + isBuiltin, isDataUrl, isExternalUrl, isJSRequest, - prettifyUrl, - timeFrom, + moduleListContains, normalizePath, + prettifyUrl, removeImportQuery, - unwrapId, - moduleListContains, - fsPathFromUrl + timeFrom, + unwrapId } from '../utils' -import { - debugHmr, - handlePrunedModules, - lexAcceptedHmrDeps -} from '../server/hmr' -import { - FS_PREFIX, - CLIENT_DIR, - CLIENT_PUBLIC_PATH, - DEP_VERSION_RE, - VALID_ID_PREFIX, - NULL_BYTE_PLACEHOLDER -} from '../constants' -import { ERR_OUTDATED_OPTIMIZED_DEP } from './optimizedDeps' -import type { ViteDevServer } from '..' -import { checkPublicFile } from './asset' -import { parse as parseJS } from 'acorn' -import type { Node } from 'estree' -import { makeLegalIdentifier } from '@rollup/pluginutils' +import type { ResolvedConfig } from '../config' +import type { Plugin } from '../plugin' import { shouldExternalizeForSSR } from '../ssr/ssrExternal' -import { performance } from 'perf_hooks' import { transformRequest } from '../server/transformRequest' import { - isOptimizedDepFile, getDepsCacheDir, + isOptimizedDepFile, optimizedDepNeedsInterop } from '../optimizer' +import { checkPublicFile } from './asset' +import { ERR_OUTDATED_OPTIMIZED_DEP } from './optimizedDeps' +import { isCSSRequest, isDirectCSSRequest } from './css' const isDebug = !!process.env.DEBUG const debug = createDebugger('vite:import-analysis') diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 5b7d738c2da264..36696986a4aacf 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -1,14 +1,14 @@ import path from 'path' -import type { ResolvedConfig } from '../config' -import type { Plugin } from '../plugin' import MagicString from 'magic-string' import type { ImportSpecifier } from 'es-module-lexer' import { init, parse as parseImports } from 'es-module-lexer' import type { OutputChunk, SourceMap } from 'rollup' -import { isCSSRequest, removedPureCssFilesCache } from './css' -import { bareImportRE, combineSourcemaps } from '../utils' import type { RawSourceMap } from '@ampproject/remapping' +import { bareImportRE, combineSourcemaps } from '../utils' +import type { Plugin } from '../plugin' +import type { ResolvedConfig } from '../config' import { genSourceMapUrl } from '../server/sourcemap' +import { isCSSRequest, removedPureCssFilesCache } from './css' /** * A flag for injected helpers. This flag will be set to `false` if the output diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 140eb6ca6d1273..3282014d2ffca3 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -6,13 +6,13 @@ import { parseExpressionAt } from 'acorn' import MagicString from 'magic-string' import fg from 'fast-glob' import { stringifyQuery } from 'ufo' +import type { GeneralImportGlobOptions } from 'types/importGlob' import type { Plugin } from '../plugin' import type { ViteDevServer } from '../server' import type { ModuleNode } from '../server/moduleGraph' import type { ResolvedConfig } from '../config' -import { isCSSRequest } from './css' -import type { GeneralImportGlobOptions } from 'types/importGlob' import { normalizePath, slash } from '../utils' +import { isCSSRequest } from './css' export interface ParsedImportGlob { match: RegExpMatchArray diff --git a/packages/vite/src/node/plugins/index.ts b/packages/vite/src/node/plugins/index.ts index 3fd283b07b4e47..b4a298bc334d41 100644 --- a/packages/vite/src/node/plugins/index.ts +++ b/packages/vite/src/node/plugins/index.ts @@ -1,6 +1,6 @@ +import aliasPlugin from '@rollup/plugin-alias' import type { ResolvedConfig } from '../config' import type { Plugin } from '../plugin' -import aliasPlugin from '@rollup/plugin-alias' import { jsonPlugin } from './json' import { resolvePlugin } from './resolve' import { optimizedDepsPlugin } from './optimizedDeps' diff --git a/packages/vite/src/node/plugins/optimizedDeps.ts b/packages/vite/src/node/plugins/optimizedDeps.ts index adab1bd9756251..8d4e98b865bf28 100644 --- a/packages/vite/src/node/plugins/optimizedDeps.ts +++ b/packages/vite/src/node/plugins/optimizedDeps.ts @@ -1,6 +1,6 @@ import { promises as fs } from 'fs' -import type { Plugin } from '../plugin' import colors from 'picocolors' +import type { Plugin } from '../plugin' import { DEP_VERSION_RE } from '../constants' import { cleanUrl, createDebugger } from '../utils' import { isOptimizedDepFile, optimizedDepInfoFromFile } from '../optimizer' diff --git a/packages/vite/src/node/plugins/reporter.ts b/packages/vite/src/node/plugins/reporter.ts index 808e8040cba9f7..da6da4b8a349e3 100644 --- a/packages/vite/src/node/plugins/reporter.ts +++ b/packages/vite/src/node/plugins/reporter.ts @@ -1,7 +1,7 @@ import path from 'path' -import colors from 'picocolors' import { gzip } from 'zlib' import { promisify } from 'util' +import colors from 'picocolors' import type { Plugin } from 'rollup' import type { ResolvedConfig } from '../config' import { normalizePath } from '../utils' diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 98a2cd8a9f776e..e50cd68ace76b0 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -1,34 +1,36 @@ import fs from 'fs' import path from 'path' -import type { Plugin } from '../plugin' import colors from 'picocolors' +import type { PartialResolvedId } from 'rollup' +import { resolve as _resolveExports } from 'resolve.exports' +import type { Plugin } from '../plugin' import { - FS_PREFIX, - SPECIAL_QUERY_RE, DEFAULT_EXTENSIONS, DEFAULT_MAIN_FIELDS, + DEP_VERSION_RE, + FS_PREFIX, OPTIMIZABLE_ENTRY_RE, - DEP_VERSION_RE + SPECIAL_QUERY_RE } from '../constants' import { - isBuiltin, bareImportRE, + cleanUrl, createDebugger, + ensureVolumeInPath, + fsPathFromId, + getPotentialTsSrcPaths, injectQuery, + isBuiltin, + isDataUrl, isExternalUrl, + isFileReadable, isObject, + isPossibleTsOutput, + isTsRequest, + nestedResolveFrom, normalizePath, - fsPathFromId, - ensureVolumeInPath, resolveFrom, - isDataUrl, - cleanUrl, - slash, - nestedResolveFrom, - isFileReadable, - isTsRequest, - isPossibleTsOutput, - getPotentialTsSrcPaths + slash } from '../utils' import { createIsOptimizedDepUrl, @@ -37,9 +39,7 @@ import { optimizedDepInfoFromId } from '../optimizer' import type { OptimizedDepInfo } from '../optimizer' -import type { ViteDevServer, SSROptions } from '..' -import type { PartialResolvedId } from 'rollup' -import { resolve as _resolveExports } from 'resolve.exports' +import type { SSROptions, ViteDevServer } from '..' import type { PackageCache, PackageData } from '../packages' import { loadPackageData, resolvePackageData } from '../packages' diff --git a/packages/vite/src/node/plugins/splitVendorChunk.ts b/packages/vite/src/node/plugins/splitVendorChunk.ts index 3f7c16067a5f8e..7aa389da8377e2 100644 --- a/packages/vite/src/node/plugins/splitVendorChunk.ts +++ b/packages/vite/src/node/plugins/splitVendorChunk.ts @@ -1,11 +1,11 @@ -import type { UserConfig } from '../../node' -import type { Plugin } from '../plugin' import type { - OutputOptions, GetManualChunk, GetManualChunkApi, - GetModuleInfo + GetModuleInfo, + OutputOptions } from 'rollup' +import type { UserConfig } from '../../node' +import type { Plugin } from '../plugin' import { isCSSRequest } from './css' // Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7 diff --git a/packages/vite/src/node/plugins/terser.ts b/packages/vite/src/node/plugins/terser.ts index 29f4d5c172ce67..5ec3e86b57f96d 100644 --- a/packages/vite/src/node/plugins/terser.ts +++ b/packages/vite/src/node/plugins/terser.ts @@ -1,6 +1,6 @@ -import type { Plugin } from '../plugin' import { Worker } from 'okie' import type { Terser } from 'types/terser' +import type { Plugin } from '../plugin' import type { ResolvedConfig } from '..' export function terserPlugin(config: ResolvedConfig): Plugin { diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts index f0850242de9a90..b5b33e27bc860b 100644 --- a/packages/vite/src/node/plugins/worker.ts +++ b/packages/vite/src/node/plugins/worker.ts @@ -1,12 +1,12 @@ +import path from 'path' +import type Rollup from 'rollup' +import type { EmittedFile, TransformPluginContext } from 'rollup' import type { ResolvedConfig } from '../config' import type { Plugin } from '../plugin' -import { fileToUrl, getAssetHash } from './asset' import { cleanUrl, injectQuery, parseRequest } from '../utils' -import type Rollup from 'rollup' import { ENV_PUBLIC_PATH } from '../constants' -import path from 'path' import { onRollupWarning } from '../build' -import type { TransformPluginContext, EmittedFile } from 'rollup' +import { fileToUrl, getAssetHash } from './asset' interface WorkerCache { // save worker bundle emitted files avoid overwrites the same file. diff --git a/packages/vite/src/node/plugins/workerImportMetaUrl.ts b/packages/vite/src/node/plugins/workerImportMetaUrl.ts index bfd8c22dcad372..48d38dd0a1359e 100644 --- a/packages/vite/src/node/plugins/workerImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/workerImportMetaUrl.ts @@ -1,16 +1,16 @@ +import path from 'path' import JSON5 from 'json5' +import MagicString from 'magic-string' +import type { RollupError } from 'rollup' +import { stripLiteral } from 'strip-literal' import type { ResolvedConfig } from '../config' import type { Plugin } from '../plugin' -import { fileToUrl } from './asset' import { cleanUrl, injectQuery } from '../utils' -import path from 'path' -import { workerFileToUrl } from './worker' import { parseRequest } from '../utils' import { ENV_ENTRY, ENV_PUBLIC_PATH } from '../constants' -import MagicString from 'magic-string' import type { ViteDevServer } from '..' -import type { RollupError } from 'rollup' -import { stripLiteral } from 'strip-literal' +import { workerFileToUrl } from './worker' +import { fileToUrl } from './asset' type WorkerType = 'classic' | 'module' | 'ignore' const ignoreFlagRE = /\/\*\s*@vite-ignore\s*\*\// diff --git a/packages/vite/src/node/preview.ts b/packages/vite/src/node/preview.ts index e48f2e6231933f..33825200bc1823 100644 --- a/packages/vite/src/node/preview.ts +++ b/packages/vite/src/node/preview.ts @@ -1,20 +1,20 @@ import path from 'path' +import type { Server } from 'http' +import type * as http from 'http' import sirv from 'sirv' import connect from 'connect' -import compression from './server/middlewares/compression' -import type { Server } from 'http' -import type { InlineConfig, ResolvedConfig } from '.' -import { resolveConfig } from '.' import type { Connect } from 'types/connect' +import corsMiddleware from 'cors' import type { ResolvedServerOptions } from './server' import type { CommonServerOptions } from './http' -import { resolveHttpsConfig, resolveHttpServer, httpServerStart } from './http' +import { httpServerStart, resolveHttpServer, resolveHttpsConfig } from './http' import { openBrowser } from './server/openBrowser' -import corsMiddleware from 'cors' +import compression from './server/middlewares/compression' import { proxyMiddleware } from './server/middlewares/proxy' import { resolveHostname } from './utils' import { printCommonServerUrls } from './logger' -import type * as http from 'http' +import { resolveConfig } from '.' +import type { InlineConfig, ResolvedConfig } from '.' export interface PreviewOptions extends CommonServerOptions {} diff --git a/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts b/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts index ab0555ae7982e9..c6f81e9107ef0b 100644 --- a/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts +++ b/packages/vite/src/node/server/__tests__/pluginContainer.spec.ts @@ -1,10 +1,10 @@ +import { beforeEach, describe, expect, it } from 'vitest' import type { UserConfig } from '../../config' import { resolveConfig } from '../../config' import type { Plugin } from '../../plugin' import { ModuleGraph } from '../moduleGraph' import type { PluginContainer } from '../pluginContainer' import { createPluginContainer } from '../pluginContainer' -import { describe, it, expect, beforeEach } from 'vitest' let resolveId: (id: string) => any let moduleGraph: ModuleGraph diff --git a/packages/vite/src/node/server/__tests__/search-root.spec.ts b/packages/vite/src/node/server/__tests__/search-root.spec.ts index ff9366e8791534..066b64917a8b92 100644 --- a/packages/vite/src/node/server/__tests__/search-root.spec.ts +++ b/packages/vite/src/node/server/__tests__/search-root.spec.ts @@ -1,6 +1,6 @@ -import { searchForWorkspaceRoot } from '../searchRoot' import { resolve } from 'path' -import { describe, test, expect } from 'vitest' +import { describe, expect, test } from 'vitest' +import { searchForWorkspaceRoot } from '../searchRoot' describe('searchForWorkspaceRoot', () => { test('lerna', () => { diff --git a/packages/vite/src/node/server/hmr.ts b/packages/vite/src/node/server/hmr.ts index da2ba9f99bd753..23ed627a79f3e6 100644 --- a/packages/vite/src/node/server/hmr.ts +++ b/packages/vite/src/node/server/hmr.ts @@ -1,15 +1,15 @@ import fs from 'fs' import path from 'path' +import type { Server } from 'http' import colors from 'picocolors' -import type { ViteDevServer } from '..' -import { createDebugger, normalizePath, unique } from '../utils' -import type { ModuleNode } from './moduleGraph' import type { Update } from 'types/hmrPayload' -import { CLIENT_DIR } from '../constants' import type { RollupError } from 'rollup' -import type { Server } from 'http' +import { CLIENT_DIR } from '../constants' +import { createDebugger, normalizePath, unique } from '../utils' +import type { ViteDevServer } from '..' import { isCSSRequest } from '../plugins/css' import { getAffectedGlobModules } from '../plugins/importMetaGlob' +import type { ModuleNode } from './moduleGraph' export const debugHmr = createDebugger('vite:hmr') diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 021fd8c25901b5..aaf0533337c700 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -2,18 +2,37 @@ import fs from 'fs' import path from 'path' import type * as net from 'net' import type * as http from 'http' +import type { AddressInfo } from 'net' +import { performance } from 'perf_hooks' import connect from 'connect' import corsMiddleware from 'cors' import colors from 'picocolors' -import type { AddressInfo } from 'net' import chokidar from 'chokidar' +import type { FSWatcher, WatchOptions } from 'types/chokidar' +import type { Connect } from 'types/connect' +import launchEditorMiddleware from 'launch-editor-middleware' +import type { SourceMap } from 'rollup' import type { CommonServerOptions } from '../http' -import { resolveHttpsConfig, resolveHttpServer, httpServerStart } from '../http' +import { httpServerStart, resolveHttpServer, resolveHttpsConfig } from '../http' import type { InlineConfig, ResolvedConfig } from '../config' import { mergeConfig, resolveConfig } from '../config' +import { isParentDirectory, normalizePath } from '../utils' +import { ssrLoadModule } from '../ssr/ssrModuleLoader' +import { resolveSSRExternal } from '../ssr/ssrExternal' +import { + rebindErrorStacktrace, + ssrRewriteStacktrace +} from '../ssr/ssrStacktrace' +import { ssrTransform } from '../ssr/ssrTransform' +import { createOptimizedDeps } from '../optimizer/registerMissing' +import type { OptimizedDeps } from '../optimizer' +import { resolveHostname } from '../utils' +import { CLIENT_DIR } from '../constants' +import type { Logger } from '../logger' +import { printCommonServerUrls } from '../logger' +import { invalidatePackageData } from '../packages' import type { PluginContainer } from './pluginContainer' import { createPluginContainer } from './pluginContainer' -import type { FSWatcher, WatchOptions } from 'types/chokidar' import type { WebSocketServer } from './ws' import { createWebSocketServer } from './ws' import { baseMiddleware } from './middlewares/base' @@ -25,38 +44,19 @@ import { indexHtmlMiddleware } from './middlewares/indexHtml' import { - serveRawFsMiddleware, servePublicMiddleware, + serveRawFsMiddleware, serveStaticMiddleware } from './middlewares/static' import { timeMiddleware } from './middlewares/time' import { ModuleGraph } from './moduleGraph' -import type { Connect } from 'types/connect' -import { isParentDirectory, normalizePath } from '../utils' import { errorMiddleware, prepareError } from './middlewares/error' import type { HmrOptions } from './hmr' -import { handleHMRUpdate, handleFileAddUnlink } from './hmr' +import { handleFileAddUnlink, handleHMRUpdate } from './hmr' import { openBrowser } from './openBrowser' -import launchEditorMiddleware from 'launch-editor-middleware' import type { TransformOptions, TransformResult } from './transformRequest' import { transformRequest } from './transformRequest' -import { ssrLoadModule } from '../ssr/ssrModuleLoader' -import { resolveSSRExternal } from '../ssr/ssrExternal' -import { - rebindErrorStacktrace, - ssrRewriteStacktrace -} from '../ssr/ssrStacktrace' -import { ssrTransform } from '../ssr/ssrTransform' -import { createOptimizedDeps } from '../optimizer/registerMissing' -import type { OptimizedDeps } from '../optimizer' -import { resolveHostname } from '../utils' import { searchForWorkspaceRoot } from './searchRoot' -import { CLIENT_DIR } from '../constants' -import type { Logger } from '../logger' -import { printCommonServerUrls } from '../logger' -import { performance } from 'perf_hooks' -import { invalidatePackageData } from '../packages' -import type { SourceMap } from 'rollup' export { searchForWorkspaceRoot } from './searchRoot' diff --git a/packages/vite/src/node/server/middlewares/base.ts b/packages/vite/src/node/server/middlewares/base.ts index b72f0fd7949f0b..7aa93f3faeae1e 100644 --- a/packages/vite/src/node/server/middlewares/base.ts +++ b/packages/vite/src/node/server/middlewares/base.ts @@ -1,6 +1,6 @@ import { parse as parseUrl } from 'url' -import type { ViteDevServer } from '..' import type { Connect } from 'types/connect' +import type { ViteDevServer } from '..' // this middleware is only active when (config.base !== '/') diff --git a/packages/vite/src/node/server/middlewares/error.ts b/packages/vite/src/node/server/middlewares/error.ts index 62f86313690f0e..c43901a5b0a265 100644 --- a/packages/vite/src/node/server/middlewares/error.ts +++ b/packages/vite/src/node/server/middlewares/error.ts @@ -1,10 +1,10 @@ import colors from 'picocolors' import type { RollupError } from 'rollup' -import type { ViteDevServer } from '../..' import type { Connect } from 'types/connect' -import { pad } from '../../utils' import strip from 'strip-ansi' import type { ErrorPayload } from 'types/hmrPayload' +import { pad } from '../../utils' +import type { ViteDevServer } from '../..' export function prepareError(err: Error | RollupError): ErrorPayload['err'] { // only copy the information we need and avoid serializing unnecessary diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 7b43ac0c67d428..80afe7f79a3535 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -19,15 +19,15 @@ import { send } from '../send' import { CLIENT_PUBLIC_PATH, FS_PREFIX, - VALID_ID_PREFIX, - NULL_BYTE_PLACEHOLDER + NULL_BYTE_PLACEHOLDER, + VALID_ID_PREFIX } from '../../constants' import { cleanUrl, + ensureWatchedFile, fsPathFromId, - normalizePath, injectQuery, - ensureWatchedFile + normalizePath } from '../../utils' import type { ModuleGraph } from '../moduleGraph' diff --git a/packages/vite/src/node/server/middlewares/proxy.ts b/packages/vite/src/node/server/middlewares/proxy.ts index 97de98a8331a7a..5c447435911ecd 100644 --- a/packages/vite/src/node/server/middlewares/proxy.ts +++ b/packages/vite/src/node/server/middlewares/proxy.ts @@ -1,10 +1,10 @@ import type * as http from 'http' -import { createDebugger, isObject } from '../../utils' import httpProxy from 'http-proxy' -import { HMR_HEADER } from '../ws' import type { Connect } from 'types/connect' import type { HttpProxy } from 'types/http-proxy' import colors from 'picocolors' +import { HMR_HEADER } from '../ws' +import { createDebugger, isObject } from '../../utils' import type { CommonServerOptions, ResolvedConfig } from '../..' const debug = createDebugger('vite:proxy') diff --git a/packages/vite/src/node/server/middlewares/spaFallback.ts b/packages/vite/src/node/server/middlewares/spaFallback.ts index 1aade764d6993a..450d188651b6e8 100644 --- a/packages/vite/src/node/server/middlewares/spaFallback.ts +++ b/packages/vite/src/node/server/middlewares/spaFallback.ts @@ -1,6 +1,6 @@ import fs from 'fs' -import history from 'connect-history-api-fallback' import path from 'path' +import history from 'connect-history-api-fallback' import type { Connect } from 'types/connect' import { createDebugger } from '../../utils' diff --git a/packages/vite/src/node/server/middlewares/static.ts b/packages/vite/src/node/server/middlewares/static.ts index 5fb4f7fad2e055..f2508032ddb565 100644 --- a/packages/vite/src/node/server/middlewares/static.ts +++ b/packages/vite/src/node/server/middlewares/static.ts @@ -3,20 +3,20 @@ import type { ServerResponse } from 'http' import type { Options } from 'sirv' import sirv from 'sirv' import type { Connect } from 'types/connect' +import { isMatch } from 'micromatch' import type { ViteDevServer } from '../..' import { FS_PREFIX } from '../../constants' import { cleanUrl, fsPathFromId, fsPathFromUrl, + isFileReadable, isImportRequest, isInternalRequest, + isParentDirectory, isWindows, - slash, - isFileReadable, - isParentDirectory + slash } from '../../utils' -import { isMatch } from 'micromatch' const sirvOptions: Options = { dev: true, diff --git a/packages/vite/src/node/server/middlewares/transform.ts b/packages/vite/src/node/server/middlewares/transform.ts index f5ae0e97b065bd..89022bf93bb4b2 100644 --- a/packages/vite/src/node/server/middlewares/transform.ts +++ b/packages/vite/src/node/server/middlewares/transform.ts @@ -1,10 +1,13 @@ import { promises as fs } from 'fs' import path from 'path' -import type { ViteDevServer } from '..' import type { Connect } from 'types/connect' +import colors from 'picocolors' +import type { ViteDevServer } from '..' import { cleanUrl, createDebugger, + ensureVolumeInPath, + fsPathFromId, injectQuery, isImportRequest, isJSRequest, @@ -12,18 +15,15 @@ import { prettifyUrl, removeImportQuery, removeTimestampQuery, - unwrapId, - fsPathFromId, - ensureVolumeInPath + unwrapId } from '../../utils' import { send } from '../send' import { transformRequest } from '../transformRequest' import { isHTMLProxy } from '../../plugins/html' -import colors from 'picocolors' import { DEP_VERSION_RE, - NULL_BYTE_PLACEHOLDER, - FS_PREFIX + FS_PREFIX, + NULL_BYTE_PLACEHOLDER } from '../../constants' import { isCSSRequest, diff --git a/packages/vite/src/node/server/moduleGraph.ts b/packages/vite/src/node/server/moduleGraph.ts index 1d7ae407f110c5..5730f4be324744 100644 --- a/packages/vite/src/node/server/moduleGraph.ts +++ b/packages/vite/src/node/server/moduleGraph.ts @@ -1,6 +1,6 @@ import { extname } from 'path' -import type { ModuleInfo, PartialResolvedId } from 'rollup' import { parse as parseUrl } from 'url' +import type { ModuleInfo, PartialResolvedId } from 'rollup' import { isDirectCSSRequest } from '../plugins/css' import { isHTMLRequest } from '../plugins/html' import { @@ -10,8 +10,8 @@ import { removeTimestampQuery } from '../utils' import { FS_PREFIX } from '../constants' -import type { TransformResult } from './transformRequest' import { canSkipImportAnalysis } from '../plugins/importAnalysis' +import type { TransformResult } from './transformRequest' export class ModuleNode { /** diff --git a/packages/vite/src/node/server/openBrowser.ts b/packages/vite/src/node/server/openBrowser.ts index 5eeb7554e606bb..bacb4006ea08ea 100644 --- a/packages/vite/src/node/server/openBrowser.ts +++ b/packages/vite/src/node/server/openBrowser.ts @@ -9,10 +9,10 @@ */ import path from 'path' +import { execSync } from 'child_process' import open from 'open' import spawn from 'cross-spawn' import colors from 'picocolors' -import { execSync } from 'child_process' import type { Logger } from '../logger' // https://github.com/sindresorhus/open#app diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 5efc2670c0f81a..4016f6a0b71741 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -30,48 +30,48 @@ SOFTWARE. */ import fs from 'fs' -import { resolve, join } from 'path' -import type { Plugin } from '../plugin' +import { join, resolve } from 'path' +import { performance } from 'perf_hooks' import type { + EmittedFile, InputOptions, + LoadResult, MinimalPluginContext, - OutputOptions, ModuleInfo, NormalizedInputOptions, + OutputOptions, PartialResolvedId, ResolvedId, + RollupError, PluginContext as RollupPluginContext, - LoadResult, SourceDescription, - EmittedFile, SourceMap, - RollupError, TransformResult } from 'rollup' import * as acorn from 'acorn' import type { RawSourceMap } from '@ampproject/remapping' import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping' -import { cleanUrl, combineSourcemaps } from '../utils' import MagicString from 'magic-string' import type { FSWatcher } from 'chokidar' +import colors from 'picocolors' +import type * as postcss from 'postcss' +import type { Plugin } from '../plugin' +import { cleanUrl, combineSourcemaps } from '../utils' import { createDebugger, ensureWatchedFile, generateCodeFrame, - isObject, isExternalUrl, + isObject, normalizePath, numberToPos, prettifyUrl, timeFrom } from '../utils' import { FS_PREFIX } from '../constants' -import colors from 'picocolors' import type { ResolvedConfig } from '../config' import { buildErrorMessage } from './middlewares/error' import type { ModuleGraph } from './moduleGraph' -import { performance } from 'perf_hooks' -import type * as postcss from 'postcss' export interface PluginContainerOptions { cwd?: string diff --git a/packages/vite/src/node/server/sourcemap.ts b/packages/vite/src/node/server/sourcemap.ts index 88cbafc344c739..97ee26668d741c 100644 --- a/packages/vite/src/node/server/sourcemap.ts +++ b/packages/vite/src/node/server/sourcemap.ts @@ -1,8 +1,8 @@ import path from 'path' import { promises as fs } from 'fs' +import type { SourceMap } from 'rollup' import type { Logger } from '../logger' import { createDebugger } from '../utils' -import type { SourceMap } from 'rollup' const isDebug = !!process.env.DEBUG const debug = createDebugger('vite:sourcemap', { diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index f877925f491479..5402bb21093d59 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -1,24 +1,24 @@ import { promises as fs } from 'fs' import path from 'path' +import { performance } from 'perf_hooks' import getEtag from 'etag' import * as convertSourceMap from 'convert-source-map' import type { SourceDescription, SourceMap } from 'rollup' -import type { ViteDevServer } from '..' import colors from 'picocolors' +import type { ViteDevServer } from '..' import { - createDebugger, cleanUrl, + createDebugger, + ensureWatchedFile, + isObject, prettifyUrl, removeTimestampQuery, - timeFrom, - ensureWatchedFile, - isObject + timeFrom } from '../utils' import { checkPublicFile } from '../plugins/asset' import { ssrTransform } from '../ssr/ssrTransform' import { injectSourcesContent } from './sourcemap' import { isFileServingAllowed } from './middlewares/static' -import { performance } from 'perf_hooks' const debugLoad = createDebugger('vite:load') const debugTransform = createDebugger('vite:transform') diff --git a/packages/vite/src/node/server/ws.ts b/packages/vite/src/node/server/ws.ts index 17187ca6e282ac..af6b20b0434241 100644 --- a/packages/vite/src/node/server/ws.ts +++ b/packages/vite/src/node/server/ws.ts @@ -1,8 +1,9 @@ -import colors from 'picocolors' import type { Server } from 'http' import { STATUS_CODES } from 'http' import type { ServerOptions as HttpsServerOptions } from 'https' import { createServer as createHttpsServer } from 'https' +import type { Socket } from 'net' +import colors from 'picocolors' import type { ServerOptions, WebSocket as WebSocketRaw } from 'ws' import { WebSocketServer as WebSocketServerRaw } from 'ws' import type { WebSocket as WebSocketTypes } from 'types/ws' @@ -10,7 +11,6 @@ import type { CustomPayload, ErrorPayload, HMRPayload } from 'types/hmrPayload' import type { InferCustomEventPayload } from 'types/customEvent' import type { ResolvedConfig } from '..' import { isObject } from '../utils' -import type { Socket } from 'net' export const HMR_HEADER = 'vite-hmr' diff --git a/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts index 5fb51093405250..579ba997da5272 100644 --- a/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts +++ b/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts @@ -1,5 +1,5 @@ +import { expect, test } from 'vitest' import { stripNesting } from '../ssrExternal' -import { test, expect } from 'vitest' test('stripNesting', async () => { expect(stripNesting(['c', 'p1>c1', 'p2 > c2'])).toEqual(['c', 'c1', 'c2']) diff --git a/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts index 93a04734840d31..4b494524d45c72 100644 --- a/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts +++ b/packages/vite/src/node/ssr/__tests__/ssrModuleLoader.spec.ts @@ -1,6 +1,6 @@ import { resolve } from 'path' +import { expect, test, vi } from 'vitest' import { createServer } from '../../index' -import { test, vi, expect } from 'vitest' const badjs = resolve(__dirname, './fixtures/ssrModuleLoader-bad.js') const THROW_MESSAGE = 'it is an expected error' diff --git a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts index 9c1fdea5939793..f759a51e60ff58 100644 --- a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts +++ b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts @@ -1,7 +1,7 @@ +import { expect, test } from 'vitest' import { transformWithEsbuild } from '../../plugins/esbuild' import { traverseHtml } from '../../plugins/html' import { ssrTransform } from '../ssrTransform' -import { test, expect } from 'vitest' test('default import', async () => { expect( diff --git a/packages/vite/src/node/ssr/ssrExternal.ts b/packages/vite/src/node/ssr/ssrExternal.ts index 800a2307dabae6..24a12cb7386ff3 100644 --- a/packages/vite/src/node/ssr/ssrExternal.ts +++ b/packages/vite/src/node/ssr/ssrExternal.ts @@ -1,5 +1,6 @@ import fs from 'fs' import path from 'path' +import { createFilter } from '@rollup/pluginutils' import type { InternalResolveOptions } from '../plugins/resolve' import { tryNodeResolve } from '../plugins/resolve' import { @@ -10,7 +11,6 @@ import { resolveFrom } from '../utils' import type { Logger, ResolvedConfig } from '..' -import { createFilter } from '@rollup/pluginutils' const debug = createDebugger('vite:ssr-external') diff --git a/packages/vite/src/node/ssr/ssrManifestPlugin.ts b/packages/vite/src/node/ssr/ssrManifestPlugin.ts index 69184150bb97b7..993fae1632ed5d 100644 --- a/packages/vite/src/node/ssr/ssrManifestPlugin.ts +++ b/packages/vite/src/node/ssr/ssrManifestPlugin.ts @@ -1,4 +1,4 @@ -import { relative, basename, join, dirname } from 'path' +import { basename, dirname, join, relative } from 'path' import { parse as parseImports } from 'es-module-lexer' import type { ImportSpecifier } from 'es-module-lexer' import type { OutputChunk } from 'rollup' diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index ba9589d8bbbf1f..c552d5431881eb 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -8,19 +8,19 @@ import { unwrapId, usingDynamicImport } from '../utils' -import { rebindErrorStacktrace, ssrRewriteStacktrace } from './ssrStacktrace' -import { - ssrExportAllKey, - ssrModuleExportsKey, - ssrImportKey, - ssrImportMetaKey, - ssrDynamicImportKey -} from './ssrTransform' import { transformRequest } from '../server/transformRequest' import type { InternalResolveOptions } from '../plugins/resolve' import { tryNodeResolve } from '../plugins/resolve' import { hookNodeResolve } from '../plugins/ssrRequireHook' import { NULL_BYTE_PLACEHOLDER } from '../constants' +import { + ssrDynamicImportKey, + ssrExportAllKey, + ssrImportKey, + ssrImportMetaKey, + ssrModuleExportsKey +} from './ssrTransform' +import { rebindErrorStacktrace, ssrRewriteStacktrace } from './ssrStacktrace' interface SSRContext { global: typeof globalThis diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts index 4eeb34ad7e102c..d7dc610cb82f47 100644 --- a/packages/vite/src/node/ssr/ssrTransform.ts +++ b/packages/vite/src/node/ssr/ssrTransform.ts @@ -1,19 +1,19 @@ import MagicString from 'magic-string' import type { SourceMap } from 'rollup' -import type { TransformResult } from '../server/transformRequest' -import { parser } from '../server/pluginContainer' import type { + Function as FunctionNode, Identifier, - Node as _Node, + Pattern, Property, - Function as FunctionNode, - Pattern + Node as _Node } from 'estree' import { extract_names as extractNames } from 'periscopic' import { walk as eswalk } from 'estree-walker' +import type { RawSourceMap } from '@ampproject/remapping' +import type { TransformResult } from '../server/transformRequest' +import { parser } from '../server/pluginContainer' import { combineSourcemaps } from '../utils' import { isJSONRequest } from '../plugins/json' -import type { RawSourceMap } from '@ampproject/remapping' type Node = _Node & { start: number diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 41b1073bb5b991..1e9e23c483d1ef 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -1,25 +1,25 @@ -import debug from 'debug' -import colors from 'picocolors' import fs from 'fs' import os from 'os' import path from 'path' import { promisify } from 'util' -import { pathToFileURL, URL } from 'url' -import { - FS_PREFIX, - DEFAULT_EXTENSIONS, - VALID_ID_PREFIX, - CLIENT_PUBLIC_PATH, - ENV_PUBLIC_PATH, - CLIENT_ENTRY -} from './constants' -import resolve from 'resolve' +import { URL, pathToFileURL } from 'url' import { builtinModules } from 'module' +import { performance } from 'perf_hooks' +import { URLSearchParams } from 'url' +import resolve from 'resolve' import type { FSWatcher } from 'chokidar' import remapping from '@ampproject/remapping' import type { DecodedSourceMap, RawSourceMap } from '@ampproject/remapping' -import { performance } from 'perf_hooks' -import { URLSearchParams } from 'url' +import colors from 'picocolors' +import debug from 'debug' +import { + CLIENT_ENTRY, + CLIENT_PUBLIC_PATH, + DEFAULT_EXTENSIONS, + ENV_PUBLIC_PATH, + FS_PREFIX, + VALID_ID_PREFIX +} from './constants' export function slash(p: string): string { return p.replace(/\\/g, '/') diff --git a/packages/vite/types/shims.d.ts b/packages/vite/types/shims.d.ts index 587b3344e6ce39..d90f0bf42c7057 100644 --- a/packages/vite/types/shims.d.ts +++ b/packages/vite/types/shims.d.ts @@ -28,7 +28,7 @@ declare module 'launch-editor-middleware' { } declare module 'postcss-load-config' { - import type { ProcessOptions, Plugin } from 'postcss' + import type { Plugin, ProcessOptions } from 'postcss' function load( inline: any, root: string diff --git a/packages/vite/types/ws.d.ts b/packages/vite/types/ws.d.ts index 29732ebf3e0d8a..a7620ad5470a1d 100644 --- a/packages/vite/types/ws.d.ts +++ b/packages/vite/types/ws.d.ts @@ -20,9 +20,9 @@ import type { Agent, ClientRequest, ClientRequestArgs, + Server as HTTPServer, IncomingMessage, - OutgoingHttpHeaders, - Server as HTTPServer + OutgoingHttpHeaders } from 'http' import type { Server as HTTPSServer } from 'https' import type { Duplex, DuplexOptions } from 'stream' diff --git a/playground/worker/__tests__/es/es-worker.spec.ts b/playground/worker/__tests__/es/es-worker.spec.ts index b836b081357e2e..4096aa4ec995e7 100644 --- a/playground/worker/__tests__/es/es-worker.spec.ts +++ b/playground/worker/__tests__/es/es-worker.spec.ts @@ -1,7 +1,7 @@ import fs from 'fs' import path from 'path' -import { untilUpdated, isBuild, testDir } from '../../../testUtils' import type { Page } from 'playwright-chromium' +import { isBuild, testDir, untilUpdated } from '../../../testUtils' test('normal', async () => { await page.click('.ping') diff --git a/playground/worker/__tests__/iife/worker.spec.ts b/playground/worker/__tests__/iife/worker.spec.ts index cfa7dfe2e4537b..37cc8675dc357b 100644 --- a/playground/worker/__tests__/iife/worker.spec.ts +++ b/playground/worker/__tests__/iife/worker.spec.ts @@ -1,8 +1,8 @@ import fs from 'fs' import path from 'path' -import { untilUpdated, isBuild, testDir } from '../../../testUtils' import type { Page } from 'playwright-chromium' import { test } from 'vitest' +import { isBuild, testDir, untilUpdated } from '../../../testUtils' test('normal', async () => { await page.click('.ping') diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 18dbe1e00545ac..2777cf17d91d04 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,7 @@ importers: esbuild: ^0.14.38 eslint: ^8.15.0 eslint-define-config: ^1.4.0 + eslint-plugin-import: ^2.26.0 eslint-plugin-node: ^11.1.0 execa: ^5.1.1 fs-extra: ^10.1.0 @@ -59,6 +60,7 @@ importers: esbuild: 0.14.38 eslint: 8.15.0 eslint-define-config: 1.4.0 + eslint-plugin-import: 2.26.0_eslint@8.15.0 eslint-plugin-node: 11.1.0_eslint@8.15.0 execa: 5.1.1 fs-extra: 10.1.0 @@ -2004,6 +2006,10 @@ packages: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} dev: true + /@types/json5/0.0.29: + resolution: {integrity: sha1-7ihweulOEdK4J7y+UnC86n8+ce4=} + dev: true + /@types/less/3.0.3: resolution: {integrity: sha512-1YXyYH83h6We1djyoUEqTlVyQtCfJAFXELSKW2ZRtjHD4hQ82CC4lvrv5D0l0FLcKBaiPbXyi3MpMsI9ZRgKsw==} dev: true @@ -2510,11 +2516,32 @@ packages: resolution: {integrity: sha1-nlKHYrSpBmrRY6aWKjZEGOlibs4=} dev: true + /array-includes/3.1.5: + resolution: {integrity: sha512-iSDYZMMyTPkiFasVqfuAQnWAYcvO/SeBSCGKePoEthjp4LEMTe4uLc7b025o4jAZpHhihh8xPo99TNWUWWkGDQ==} + engines: {node: '>= 0.4'} + dependencies: + call-bind: 1.0.2 + define-properties: 1.1.4 + es-abstract: 1.20.0 + get-intrinsic: 1.1.1 + is-string: 1.0.7 + dev: true + /array-union/2.1.0: resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} engines: {node: '>=8'} dev: true + /array.prototype.flat/1.3.0: + resolution: {integrity: sha512-12IUEkHsAhA4DY5s0FPgNXIdc8VRSqD9Zp78a5au9abH/SOBrsp082JOWFNTjkMozh8mqcdiKuaLGhPeYztxSw==} + engines: {node: '>= 0.4'} + dependencies: + call-bind: 1.0.2 + define-properties: 1.1.4 + es-abstract: 1.20.0 + es-shim-unscopables: 1.0.0 + dev: true + /arrify/1.0.1: resolution: {integrity: sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=} engines: {node: '>=0.10.0'} @@ -3329,7 +3356,6 @@ packages: dependencies: ms: 2.1.3 dev: true - optional: true /debug/4.3.3: resolution: {integrity: sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==} @@ -3483,6 +3509,13 @@ packages: resolution: {integrity: sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==} dev: false + /doctrine/2.1.0: + resolution: {integrity: sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==} + engines: {node: '>=0.10.0'} + dependencies: + esutils: 2.0.3 + dev: true + /doctrine/3.0.0: resolution: {integrity: sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==} engines: {node: '>=6.0.0'} @@ -3597,6 +3630,12 @@ packages: resolution: {integrity: sha512-+7IwY/kiGAacQfY+YBhKMvEmyAJnw5grTUgjG85Pe7vcUI/6b7pZjZG8nQ7+48YhzEAEqrEgD2dCz/JIK+AYvw==} dev: true + /es-shim-unscopables/1.0.0: + resolution: {integrity: sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==} + dependencies: + has: 1.0.3 + dev: true + /es-to-primitive/1.2.1: resolution: {integrity: sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==} engines: {node: '>= 0.4'} @@ -3842,6 +3881,21 @@ packages: engines: {node: '>= 14.6.0', npm: '>= 6.0.0', pnpm: '>= 6.32.9'} dev: true + /eslint-import-resolver-node/0.3.6: + resolution: {integrity: sha512-0En0w03NRVMn9Uiyn8YRPDKvWjxCWkslUEhGNTdGx15RvPJYQ+lbOlqrlNI2vEAs4pDYK4f/HN2TbDmk5TP0iw==} + dependencies: + debug: 3.2.7 + resolve: 1.22.0 + dev: true + + /eslint-module-utils/2.7.3: + resolution: {integrity: sha512-088JEC7O3lDZM9xGe0RerkOMd0EjFl+Yvd1jPWIkMT5u3H9+HC34mWWPnqPrN13gieT9pBOO+Qt07Nb/6TresQ==} + engines: {node: '>=4'} + dependencies: + debug: 3.2.7 + find-up: 2.1.0 + dev: true + /eslint-plugin-es/3.0.1_eslint@8.15.0: resolution: {integrity: sha512-GUmAsJaN4Fc7Gbtl8uOBlayo2DqhwWvEzykMHSCZHU3XdJ+NSzzZcVhXh3VxX5icqQ+oQdIEawXX8xkR3mIFmQ==} engines: {node: '>=8.10.0'} @@ -3853,6 +3907,28 @@ packages: regexpp: 3.2.0 dev: true + /eslint-plugin-import/2.26.0_eslint@8.15.0: + resolution: {integrity: sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==} + engines: {node: '>=4'} + peerDependencies: + eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 + dependencies: + array-includes: 3.1.5 + array.prototype.flat: 1.3.0 + debug: 2.6.9 + doctrine: 2.1.0 + eslint: 8.15.0 + eslint-import-resolver-node: 0.3.6 + eslint-module-utils: 2.7.3 + has: 1.0.3 + is-core-module: 2.9.0 + is-glob: 4.0.3 + minimatch: 3.1.2 + object.values: 1.1.5 + resolve: 1.22.0 + tsconfig-paths: 3.14.1 + dev: true + /eslint-plugin-node/11.1.0_eslint@8.15.0: resolution: {integrity: sha512-oUwtPJ1W0SKD0Tr+wqu92c5xuCeQqB3hSCHasn/ZgjFdA9iDGNkNf2Zi9ztY7X+hNuMib23LNGRm6+uN+KLE3g==} engines: {node: '>=8.10.0'} @@ -4964,6 +5040,13 @@ packages: resolution: {integrity: sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=} dev: true + /json5/1.0.1: + resolution: {integrity: sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==} + hasBin: true + dependencies: + minimist: 1.2.6 + dev: true + /json5/2.2.1: resolution: {integrity: sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==} engines: {node: '>=6'} @@ -5672,6 +5755,15 @@ packages: object-keys: 1.1.1 dev: true + /object.values/1.1.5: + resolution: {integrity: sha512-QUZRW0ilQ3PnPpbNtgdNV1PDbEqLIiSFB3l+EnGtBQ/8SUTLj1PZwtQHABZtLgwpJZTSZhuGLOGk57Drx2IvYg==} + engines: {node: '>= 0.4'} + dependencies: + call-bind: 1.0.2 + define-properties: 1.1.4 + es-abstract: 1.20.0 + dev: true + /okie/1.0.1: resolution: {integrity: sha512-JQh5TdSYhzXSuKN3zzX8Rw9Q/Tec1fm0jwP/k9+cBDk6tyLjlARVu936MLY//2NZp76UGHH+5gXPzRejU1bTjQ==} engines: {node: '>=12.0.0'} @@ -7530,6 +7622,15 @@ packages: typescript: 4.6.4 dev: true + /tsconfig-paths/3.14.1: + resolution: {integrity: sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==} + dependencies: + '@types/json5': 0.0.29 + json5: 1.0.1 + minimist: 1.2.6 + strip-bom: 3.0.0 + dev: true + /tslib/1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} dev: true From d2874827f7ed6b1d4ccd49dfefdeec9cefc837ba Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 11 May 2022 17:03:19 +0800 Subject: [PATCH 106/114] test: improve dx for tests (#8112) --- .eslintrc.cjs | 3 +- .prettierignore | 1 + CONTRIBUTING.md | 6 +- package.json | 2 +- playground/alias/__tests__/alias.spec.ts | 3 +- playground/assets/__tests__/assets.spec.ts | 14 ++- .../__tests__/backend-integration.spec.ts | 5 +- .../cli-module/__tests__/cli-module.spec.ts | 1 + playground/cli-module/__tests__/serve.ts | 9 +- playground/cli/__tests__/cli.spec.ts | 1 + playground/cli/__tests__/serve.ts | 11 +- .../__tests__/css-codesplit.spec.ts | 2 +- .../__tests__/css-codesplit.spec.ts | 2 +- .../css-sourcemap/__tests__/build.spec.ts | 2 +- .../css-sourcemap/__tests__/serve.spec.ts | 6 +- playground/css/__tests__/css.spec.ts | 7 +- .../postcss-plugins-different-dir.spec.ts | 4 +- playground/css/postcss-caching/css.spec.ts | 2 +- .../data-uri/__tests__/data-uri.spec.ts | 2 +- playground/define/__tests__/define.spec.ts | 5 +- .../__tests__/dynamic-import.spec.ts | 2 +- .../env-nested/__tests__/env-nested.spec.ts | 2 +- playground/env/__tests__/env.spec.ts | 2 +- .../extensions/__tests__/extensions.spec.ts | 2 + .../__tests__/file-delete-restore.spec.ts | 9 +- .../fs-serve/__tests__/fs-serve.spec.ts | 3 +- .../glob-import/__tests__/glob-import.spec.ts | 3 +- playground/hmr/__tests__/hmr.spec.ts | 10 +- playground/hmr/tsconfig.json | 3 +- playground/html/__tests__/html.spec.ts | 10 +- .../js-sourcemap/__tests__/build.spec.ts | 2 +- .../js-sourcemap/__tests__/serve.spec.ts | 6 +- playground/json/__tests__/json.spec.ts | 4 +- playground/legacy/__tests__/legacy.spec.ts | 9 +- .../legacy/__tests__/ssr/legacy-ssr.spec.ts | 2 +- playground/legacy/__tests__/ssr/serve.ts | 2 +- playground/lib/__tests__/lib.spec.ts | 9 +- playground/lib/__tests__/serve.ts | 14 +-- .../__tests__/multiple-entrypoints.spec.ts | 2 +- .../nested-deps/__tests__/nested-deps.spec.ts | 2 + .../__tests__/optimize-deps.spec.ts | 2 +- .../__test__/optimize-missing-deps.spec.ts | 2 +- .../optimize-missing-deps/__test__/serve.ts | 2 +- playground/preload/__tests__/preload.spec.ts | 2 +- .../__tests__/preserve-symlinks.spec.ts | 2 + .../react-emotion/__tests__/react.spec.ts | 2 +- playground/react/__tests__/react.spec.ts | 2 +- .../__tests__/resolve-config.spec.ts | 7 +- playground/resolve/__tests__/resolve.spec.ts | 2 +- playground/ssr-deps/__tests__/serve.ts | 2 +- .../ssr-deps/__tests__/ssr-deps.spec.ts | 1 + playground/ssr-html/__tests__/serve.ts | 2 +- .../ssr-html/__tests__/ssr-html.spec.ts | 3 +- playground/ssr-pug/__tests__/serve.ts | 2 +- playground/ssr-pug/__tests__/ssr-pug.spec.ts | 3 +- playground/ssr-react/__tests__/serve.ts | 2 +- .../ssr-react/__tests__/ssr-react.spec.ts | 4 +- playground/ssr-vue/__tests__/serve.ts | 2 +- playground/ssr-vue/__tests__/ssr-vue.spec.ts | 13 +- playground/ssr-webworker/__tests__/serve.ts | 2 +- .../__tests__/ssr-webworker.spec.ts | 1 + .../__tests__/build.spec.ts | 2 +- .../__tests__/serve.spec.ts | 2 +- playground/tailwind/__test__/tailwind.spec.ts | 9 +- playground/{testUtils.ts => test-utils.ts} | 31 +++-- .../tsconfig-json-load-error.spec.ts | 8 +- .../__tests__/tsconfig-json.spec.ts | 1 + playground/tsconfig.json | 6 +- playground/vue-jsx/__tests__/vue-jsx.spec.ts | 2 +- playground/vue-lib/__tests__/vue-lib.spec.ts | 2 +- playground/vue-lib/src-consumer/index.ts | 2 +- .../vue-sourcemap/__tests__/build.spec.ts | 2 +- .../vue-sourcemap/__tests__/serve.spec.ts | 7 +- playground/vue/__tests__/vue.spec.ts | 5 +- playground/wasm/__tests__/wasm.spec.ts | 2 +- .../worker/__tests__/es/es-worker.spec.ts | 2 +- .../worker/__tests__/iife/worker.spec.ts | 2 +- .../sourcemap-hidden-worker.spec.ts | 2 +- .../sourcemap-inline-worker.spec.ts | 2 +- .../sourcemap/sourcemap-worker.spec.ts | 2 +- scripts/patchEsbuildDist.ts | 2 +- scripts/patchFileDeps.ts | 2 +- scripts/releaseUtils.ts | 4 +- scripts/verifyCommit.ts | 2 +- scripts/vitestGlobalSetup.ts | 2 +- scripts/vitestSetup.ts | 113 +++++++----------- vitest.config.e2e.ts | 6 + 87 files changed, 259 insertions(+), 209 deletions(-) rename playground/{testUtils.ts => test-utils.ts} (93%) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index e75311e00ed7a2..1c80ee1df739c8 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -118,7 +118,8 @@ module.exports = defineConfig({ files: ['playground/**'], rules: { 'node/no-extraneous-import': 'off', - 'node/no-extraneous-require': 'off' + 'node/no-extraneous-require': 'off', + 'node/no-missing-import': 'off' } }, { diff --git a/.prettierignore b/.prettierignore index ad4762a457c436..a2c1f98cf5cc02 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,6 +4,7 @@ packages/vite/temp/ packages/plugin-react/dist/ packages/plugin-vue/dist/ packages/*/CHANGELOG.md +playground-temp/ LICENSE.md .prettierignore pnpm-lock.yaml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 334d3cb8b79e8c..a6b0b84a83b5a3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -95,15 +95,17 @@ Other than tests under `playground/` for integration tests, packages might conta ### Test Env and Helpers -Inside playground tests, a global `page` object is automatically available, which is a Playwright [`Page`](https://playwright.dev/docs/api/class-page) instance that has already navigated to the served page of the current playground. So writing a test is as simple as: +Inside playground tests, you can import the `page` object from `~utils`, which is a Playwright [`Page`](https://playwright.dev/docs/api/class-page) instance that has already navigated to the served page of the current playground. So writing a test is as simple as: ```js +import { page } from '~utils' + test('should work', async () => { expect(await page.textContent('.foo')).toMatch('foo') }) ``` -Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `playground/testUtils.ts`. +Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are also available in the utils. Source code is located at `playground/test-utils.ts`. Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/9c6501d9c363eaa3c1e7708d531fb2a92b633db6/scripts/vitestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build. diff --git a/package.json b/package.json index 9904f281fbc4f1..8fffa3f6e045f6 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "scripts": { "preinstall": "npx only-allow pnpm", "format": "prettier --write .", - "lint": "eslint packages/*/{src,types}/** playground/**/__tests__/**/*.*", + "lint": "eslint packages/*/{src,types}/** playground/**/__tests__/** scripts/**", "test": "run-s test-unit test-serve test-build", "test-serve": "vitest run -c vitest.config.e2e.ts", "test-build": "cross-env VITE_TEST_BUILD=1 vitest run -c vitest.config.e2e.ts", diff --git a/playground/alias/__tests__/alias.spec.ts b/playground/alias/__tests__/alias.spec.ts index 835dd37521bc77..cef34c07c51004 100644 --- a/playground/alias/__tests__/alias.spec.ts +++ b/playground/alias/__tests__/alias.spec.ts @@ -1,4 +1,5 @@ -import { editFile, getColor, untilUpdated } from '../../testUtils' +import { expect, test } from 'vitest' +import { editFile, getColor, page, untilUpdated } from '~utils' test('fs', async () => { expect(await page.textContent('.fs')).toMatch('[success] alias to fs path') diff --git a/playground/assets/__tests__/assets.spec.ts b/playground/assets/__tests__/assets.spec.ts index 96b4b4e1e434cf..f31b52e6ac9ea2 100644 --- a/playground/assets/__tests__/assets.spec.ts +++ b/playground/assets/__tests__/assets.spec.ts @@ -1,15 +1,19 @@ +import { describe, expect, test } from 'vitest' import { + browserLogs, + editFile, findAssetFile, getBg, getColor, isBuild, listAssets, - readManifest, - readFile, - editFile, notifyRebuildComplete, - untilUpdated -} from '../../testUtils' + page, + readFile, + readManifest, + untilUpdated, + watcher +} from '~utils' const assetMatch = isBuild ? /\/foo\/assets\/asset\.\w{8}\.png/ diff --git a/playground/backend-integration/__tests__/backend-integration.spec.ts b/playground/backend-integration/__tests__/backend-integration.spec.ts index 4677700f6e8c12..e8059c7d20f13c 100644 --- a/playground/backend-integration/__tests__/backend-integration.spec.ts +++ b/playground/backend-integration/__tests__/backend-integration.spec.ts @@ -1,11 +1,14 @@ import { + browserErrors, + browserLogs, editFile, getColor, isBuild, isServe, + page, readManifest, untilUpdated -} from '../../testUtils' +} from '~utils' const outerAssetMatch = isBuild ? /\/dev\/assets\/logo\.\w{8}\.png/ diff --git a/playground/cli-module/__tests__/cli-module.spec.ts b/playground/cli-module/__tests__/cli-module.spec.ts index e761343298910b..a443a66c9810dc 100644 --- a/playground/cli-module/__tests__/cli-module.spec.ts +++ b/playground/cli-module/__tests__/cli-module.spec.ts @@ -1,4 +1,5 @@ import { port } from './serve' +import { page } from '~utils' test('cli should work in "type":"module" package', async () => { // this test uses a custom serve implementation, so regular helpers for browserLogs and goto don't work diff --git a/playground/cli-module/__tests__/serve.ts b/playground/cli-module/__tests__/serve.ts index 874c81715021d1..6d5ad2d512089a 100644 --- a/playground/cli-module/__tests__/serve.ts +++ b/playground/cli-module/__tests__/serve.ts @@ -1,14 +1,11 @@ // this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -import path from 'path' import execa from 'execa' -import { workspaceRoot, ports } from '../../testUtils' import kill from 'kill-port' +import { isWindows, ports, viteBinPath } from '~utils' -const isWindows = process.platform === 'win32' export const port = ports['cli-module'] -const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js') export async function serve(root: string, isProd: boolean) { // collect stdout and stderr streams from child processes here to avoid interfering with regular jest output @@ -39,7 +36,7 @@ export async function serve(root: string, isProd: boolean) { // only run `vite build` when needed if (isProd) { - const buildCommand = `${viteBin} build` + const buildCommand = `${viteBinPath} build` try { const buildProcess = execa.command(buildCommand, { cwd: root, @@ -62,7 +59,7 @@ export async function serve(root: string, isProd: boolean) { if (isProd) { viteServerArgs.unshift('preview') } - const serverCommand = `${viteBin} ${viteServerArgs.join(' ')}` + const serverCommand = `${viteBinPath} ${viteServerArgs.join(' ')}` const serverProcess = execa.command(serverCommand, { cwd: root, stdio: 'pipe' diff --git a/playground/cli/__tests__/cli.spec.ts b/playground/cli/__tests__/cli.spec.ts index 3b735faef95ddf..676d076a1aaeed 100644 --- a/playground/cli/__tests__/cli.spec.ts +++ b/playground/cli/__tests__/cli.spec.ts @@ -1,4 +1,5 @@ import { port } from './serve' +import { page } from '~utils' test('cli should work', async () => { // this test uses a custom serve implementation, so regular helpers for browserLogs and goto don't work diff --git a/playground/cli/__tests__/serve.ts b/playground/cli/__tests__/serve.ts index 913a4d5b565c73..8c5717f4031e4a 100644 --- a/playground/cli/__tests__/serve.ts +++ b/playground/cli/__tests__/serve.ts @@ -1,14 +1,11 @@ // this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior -import path from 'path' import execa from 'execa' -import { workspaceRoot, ports } from '../../testUtils' import kill from 'kill-port' +import { isWindows, ports, viteBinPath } from '~utils' -const isWindows = process.platform === 'win32' -const port = (exports.port = ports.cli) -const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js') +export const port = ports.cli export async function serve(root: string, isProd: boolean) { // collect stdout and stderr streams from child processes here to avoid interfering with regular jest output @@ -39,7 +36,7 @@ export async function serve(root: string, isProd: boolean) { // only run `vite build` when needed if (isProd) { - const buildCommand = `${viteBin} build` + const buildCommand = `${viteBinPath} build` try { const buildProcess = execa.command(buildCommand, { cwd: root, @@ -62,7 +59,7 @@ export async function serve(root: string, isProd: boolean) { if (isProd) { viteServerArgs.unshift('preview') } - const serverCommand = `${viteBin} ${viteServerArgs.join(' ')}` + const serverCommand = `${viteBinPath} ${viteServerArgs.join(' ')}` const serverProcess = execa.command(serverCommand, { cwd: root, stdio: 'pipe' diff --git a/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts b/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts index dae8d5f4b4ca5e..dc51f0a2e473c1 100644 --- a/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts +++ b/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts @@ -1,4 +1,4 @@ -import { findAssetFile, getColor, isBuild, readManifest } from '../../testUtils' +import { findAssetFile, getColor, isBuild, readManifest } from '~utils' test('should load both stylesheets', async () => { expect(await getColor('h1')).toBe('red') diff --git a/playground/css-codesplit/__tests__/css-codesplit.spec.ts b/playground/css-codesplit/__tests__/css-codesplit.spec.ts index 820222e9a964d2..f00dfed1d92453 100644 --- a/playground/css-codesplit/__tests__/css-codesplit.spec.ts +++ b/playground/css-codesplit/__tests__/css-codesplit.spec.ts @@ -1,4 +1,4 @@ -import { findAssetFile, getColor, isBuild, readManifest } from '../../testUtils' +import { findAssetFile, getColor, isBuild, page, readManifest } from '~utils' test('should load all stylesheets', async () => { expect(await getColor('h1')).toBe('red') diff --git a/playground/css-sourcemap/__tests__/build.spec.ts b/playground/css-sourcemap/__tests__/build.spec.ts index 50b8814aed9c4e..b30284731a76d9 100644 --- a/playground/css-sourcemap/__tests__/build.spec.ts +++ b/playground/css-sourcemap/__tests__/build.spec.ts @@ -1,4 +1,4 @@ -import { isBuild } from '../../testUtils' +import { isBuild, serverLogs } from '~utils' test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => { serverLogs.forEach((log) => { diff --git a/playground/css-sourcemap/__tests__/serve.spec.ts b/playground/css-sourcemap/__tests__/serve.spec.ts index d42f93e84d4007..730866d86ef03b 100644 --- a/playground/css-sourcemap/__tests__/serve.spec.ts +++ b/playground/css-sourcemap/__tests__/serve.spec.ts @@ -2,8 +2,10 @@ import { URL } from 'url' import { extractSourcemap, formatSourcemapForSnapshot, - isServe -} from '../../testUtils' + isServe, + page, + serverLogs +} from '~utils' describe.runIf(isServe)('serve', () => { const getStyleTagContentIncluding = async (content: string) => { diff --git a/playground/css/__tests__/css.spec.ts b/playground/css/__tests__/css.spec.ts index 3443597816f2d1..5341522900ddb1 100644 --- a/playground/css/__tests__/css.spec.ts +++ b/playground/css/__tests__/css.spec.ts @@ -1,15 +1,14 @@ -import fs from 'fs' -import path from 'path' import { editFile, findAssetFile, getBg, getColor, isBuild, + page, removeFile, - testDir, + serverLogs, untilUpdated -} from '../../testUtils' +} from '~utils' // note: tests should retrieve the element at the beginning of test and reuse it // in later assertions to ensure CSS HMR doesn't reload the page diff --git a/playground/css/__tests__/postcss-plugins-different-dir.spec.ts b/playground/css/__tests__/postcss-plugins-different-dir.spec.ts index 8bedc26ee354c8..55a6d8fe8dd130 100644 --- a/playground/css/__tests__/postcss-plugins-different-dir.spec.ts +++ b/playground/css/__tests__/postcss-plugins-different-dir.spec.ts @@ -1,6 +1,6 @@ -import { getColor, getBgColor, ports } from '../../testUtils' -import { createServer } from 'vite' import path from 'path' +import { createServer } from 'vite' +import { getBgColor, getColor, page, ports } from '~utils' // Regression test for https://github.com/vitejs/vite/issues/4000 test('postcss plugins in different dir', async () => { diff --git a/playground/css/postcss-caching/css.spec.ts b/playground/css/postcss-caching/css.spec.ts index e8ba73154b6bc8..bbffdb618280e4 100644 --- a/playground/css/postcss-caching/css.spec.ts +++ b/playground/css/postcss-caching/css.spec.ts @@ -1,4 +1,4 @@ -import { getColor, ports } from '../../testUtils' +import { getColor, page, ports } from '~utils' import { createServer } from 'vite' import path from 'path' diff --git a/playground/data-uri/__tests__/data-uri.spec.ts b/playground/data-uri/__tests__/data-uri.spec.ts index bf9d595c813322..4b7f3d6e1e471b 100644 --- a/playground/data-uri/__tests__/data-uri.spec.ts +++ b/playground/data-uri/__tests__/data-uri.spec.ts @@ -1,4 +1,4 @@ -import { isBuild, findAssetFile } from '../../testUtils' +import { findAssetFile, isBuild, page } from '~utils' test('plain', async () => { expect(await page.textContent('.plain')).toBe('hi') diff --git a/playground/define/__tests__/define.spec.ts b/playground/define/__tests__/define.spec.ts index a7a45dcea1b701..b2eb571734cc54 100644 --- a/playground/define/__tests__/define.spec.ts +++ b/playground/define/__tests__/define.spec.ts @@ -1,5 +1,8 @@ +import viteConfig from '../vite.config' +import { page } from '~utils' + test('string', async () => { - const defines = require('../vite.config.js').define + const defines = viteConfig.define expect(await page.textContent('.exp')).toBe( String(typeof eval(defines.__EXP__)) diff --git a/playground/dynamic-import/__tests__/dynamic-import.spec.ts b/playground/dynamic-import/__tests__/dynamic-import.spec.ts index 95101a039e50f8..5c434bac47527b 100644 --- a/playground/dynamic-import/__tests__/dynamic-import.spec.ts +++ b/playground/dynamic-import/__tests__/dynamic-import.spec.ts @@ -1,4 +1,4 @@ -import { getColor, isBuild, untilUpdated } from '../../testUtils' +import { getColor, page, serverLogs, untilUpdated } from '~utils' test('should load literal dynamic import', async () => { await page.click('.baz') diff --git a/playground/env-nested/__tests__/env-nested.spec.ts b/playground/env-nested/__tests__/env-nested.spec.ts index ed107acb233e02..2ae9ab64023896 100644 --- a/playground/env-nested/__tests__/env-nested.spec.ts +++ b/playground/env-nested/__tests__/env-nested.spec.ts @@ -1,4 +1,4 @@ -import { isBuild } from '../../testUtils' +import { isBuild, page } from '~utils' const mode = isBuild ? `production` : `development` diff --git a/playground/env/__tests__/env.spec.ts b/playground/env/__tests__/env.spec.ts index cbc0aad524001c..373e051a22a66e 100644 --- a/playground/env/__tests__/env.spec.ts +++ b/playground/env/__tests__/env.spec.ts @@ -1,4 +1,4 @@ -import { isBuild } from '../../testUtils' +import { isBuild, page } from '~utils' const mode = isBuild ? `production` : `development` diff --git a/playground/extensions/__tests__/extensions.spec.ts b/playground/extensions/__tests__/extensions.spec.ts index 718cb40e790537..eb497a280e711a 100644 --- a/playground/extensions/__tests__/extensions.spec.ts +++ b/playground/extensions/__tests__/extensions.spec.ts @@ -1,3 +1,5 @@ +import { browserLogs, page } from '~utils' + test('should have no 404s', () => { browserLogs.forEach((msg) => { expect(msg).not.toMatch('404') diff --git a/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts b/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts index 04ce2e71b00cd8..a54f4b8da8e77e 100644 --- a/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts +++ b/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts @@ -1,10 +1,11 @@ import { + addFile, editFile, - untilUpdated, + isBuild, + page, removeFile, - addFile, - isBuild -} from '../../testUtils' + untilUpdated +} from '~utils' test.runIf(isBuild)( 'should hmr when file is deleted and restored', diff --git a/playground/fs-serve/__tests__/fs-serve.spec.ts b/playground/fs-serve/__tests__/fs-serve.spec.ts index 75c3fc6edfee04..6a21a35404ebb7 100644 --- a/playground/fs-serve/__tests__/fs-serve.spec.ts +++ b/playground/fs-serve/__tests__/fs-serve.spec.ts @@ -1,11 +1,10 @@ -import { isServe } from '../../testUtils' +import { isServe, page, viteTestUrl } from '~utils' const json = require('../safe.json') const stringified = JSON.stringify(json) describe.runIf(isServe)('main', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/src/') }) diff --git a/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts index 8cc5c61d172236..70f7ec252280a9 100644 --- a/playground/glob-import/__tests__/glob-import.spec.ts +++ b/playground/glob-import/__tests__/glob-import.spec.ts @@ -2,9 +2,10 @@ import { addFile, editFile, isBuild, + page, removeFile, untilUpdated -} from '../../testUtils' +} from '~utils' const filteredResult = { './alias.js': { diff --git a/playground/hmr/__tests__/hmr.spec.ts b/playground/hmr/__tests__/hmr.spec.ts index 34612ee1e7d3d5..d06fee31f110ea 100644 --- a/playground/hmr/__tests__/hmr.spec.ts +++ b/playground/hmr/__tests__/hmr.spec.ts @@ -1,4 +1,12 @@ -import { isBuild, editFile, untilUpdated, getBg } from '../../testUtils' +import { + browserLogs, + editFile, + getBg, + isBuild, + page, + untilUpdated, + viteTestUrl +} from '~utils' test('should render', async () => { expect(await page.textContent('.app')).toBe('1') diff --git a/playground/hmr/tsconfig.json b/playground/hmr/tsconfig.json index 9da745ba51a3e9..e920e674091b5e 100644 --- a/playground/hmr/tsconfig.json +++ b/playground/hmr/tsconfig.json @@ -1,6 +1,7 @@ { + "extends": "../tsconfig.json", "include": ["."], - "exclude": ["**/dist/**"], + "exclude": ["**/dist/**", "**/__tests__/**"], "compilerOptions": { "target": "es2019", "module": "esnext", diff --git a/playground/html/__tests__/html.spec.ts b/playground/html/__tests__/html.spec.ts index 3041247bc776d4..3e7c3d0166f75a 100644 --- a/playground/html/__tests__/html.spec.ts +++ b/playground/html/__tests__/html.spec.ts @@ -1,4 +1,5 @@ -import { getColor, isBuild, editFile, isServe } from '../../testUtils' +import { beforeAll, describe, expect, test } from 'vitest' +import { editFile, getColor, isBuild, isServe, page, viteTestUrl } from '~utils' function testPage(isNested: boolean) { test('pre transform', async () => { @@ -79,7 +80,6 @@ describe('main', () => { describe('nested', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/nested/') }) @@ -88,7 +88,6 @@ describe('nested', () => { describe('nested w/ query', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/nested/index.html?v=1') }) @@ -98,7 +97,6 @@ describe('nested w/ query', () => { describe.runIf(isBuild)('build', () => { describe('scriptAsync', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/scriptAsync.html') }) @@ -110,7 +108,6 @@ describe.runIf(isBuild)('build', () => { describe('scriptMixed', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/scriptMixed.html') }) @@ -124,7 +121,6 @@ describe.runIf(isBuild)('build', () => { // Ensure that the modulePreload polyfill is discarded in this case beforeAll(async () => { - // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/zeroJS.html') }) @@ -168,7 +164,6 @@ describe.runIf(isBuild)('build', () => { describe('noHead', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/noHead.html') }) @@ -183,7 +178,6 @@ describe('noHead', () => { describe('noBody', () => { beforeAll(async () => { - // viteTestUrl is globally injected in scripts/vitestSetup.ts await page.goto(viteTestUrl + '/noBody.html') }) diff --git a/playground/js-sourcemap/__tests__/build.spec.ts b/playground/js-sourcemap/__tests__/build.spec.ts index 50b8814aed9c4e..b30284731a76d9 100644 --- a/playground/js-sourcemap/__tests__/build.spec.ts +++ b/playground/js-sourcemap/__tests__/build.spec.ts @@ -1,4 +1,4 @@ -import { isBuild } from '../../testUtils' +import { isBuild, serverLogs } from '~utils' test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => { serverLogs.forEach((log) => { diff --git a/playground/js-sourcemap/__tests__/serve.spec.ts b/playground/js-sourcemap/__tests__/serve.spec.ts index b3946461dde197..8f36f5f6f832f1 100644 --- a/playground/js-sourcemap/__tests__/serve.spec.ts +++ b/playground/js-sourcemap/__tests__/serve.spec.ts @@ -2,8 +2,10 @@ import { URL } from 'url' import { extractSourcemap, formatSourcemapForSnapshot, - isBuild -} from '../../testUtils' + isBuild, + page, + serverLogs +} from '~utils' if (!isBuild) { test('js', async () => { diff --git a/playground/json/__tests__/json.spec.ts b/playground/json/__tests__/json.spec.ts index 2897ee22332e44..8c64d619361bfb 100644 --- a/playground/json/__tests__/json.spec.ts +++ b/playground/json/__tests__/json.spec.ts @@ -1,7 +1,7 @@ -import { isBuild } from '../../testUtils' +import { isBuild, page } from '~utils' -const json = require('../test.json') const deepJson = require('vue/package.json') +const json = require('../test.json') const stringified = JSON.stringify(json) const deepStringified = JSON.stringify(deepJson) diff --git a/playground/legacy/__tests__/legacy.spec.ts b/playground/legacy/__tests__/legacy.spec.ts index c0eaa81fbc31d8..b21f42afcbd7ed 100644 --- a/playground/legacy/__tests__/legacy.spec.ts +++ b/playground/legacy/__tests__/legacy.spec.ts @@ -1,11 +1,12 @@ import { - listAssets, findAssetFile, + getColor, isBuild, + listAssets, + page, readManifest, - untilUpdated, - getColor -} from '../../testUtils' + untilUpdated +} from '~utils' test('should work', async () => { expect(await page.textContent('#app')).toMatch('Hello') diff --git a/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts b/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts index bc232e8af129c6..b5cfe82cd93910 100644 --- a/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts +++ b/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts @@ -1,5 +1,5 @@ -import { isBuild } from '../../../testUtils' import { port } from './serve' +import { isBuild, page } from '~utils' const url = `http://localhost:${port}` diff --git a/playground/legacy/__tests__/ssr/serve.ts b/playground/legacy/__tests__/ssr/serve.ts index 597320c9a58c0f..930f11f3bb8dfb 100644 --- a/playground/legacy/__tests__/ssr/serve.ts +++ b/playground/legacy/__tests__/ssr/serve.ts @@ -1,7 +1,7 @@ // this is automatically detected by scripts/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' -import { ports } from '../../../testUtils' +import { ports } from '~utils' export const port = ports['legacy/ssr'] diff --git a/playground/lib/__tests__/lib.spec.ts b/playground/lib/__tests__/lib.spec.ts index ab3314ffe3a546..de1af1519624d1 100644 --- a/playground/lib/__tests__/lib.spec.ts +++ b/playground/lib/__tests__/lib.spec.ts @@ -1,6 +1,13 @@ -import { isBuild, isServe, testDir, untilUpdated } from '../../testUtils' import path from 'path' import fs from 'fs' +import { + isBuild, + isServe, + page, + serverLogs, + testDir, + untilUpdated +} from '~utils' describe.runIf(isBuild)('build', () => { test('es', async () => { diff --git a/playground/lib/__tests__/serve.ts b/playground/lib/__tests__/serve.ts index 3bde3d35a78dc1..c536ad231bc3a5 100644 --- a/playground/lib/__tests__/serve.ts +++ b/playground/lib/__tests__/serve.ts @@ -4,14 +4,11 @@ import path from 'path' import http from 'http' import sirv from 'sirv' -import { ports } from '../../testUtils' +import { page, ports, serverLogs, setViteUrl, viteTestUrl } from '~utils' export const port = ports.lib export async function serve(root, isBuildTest) { - // @ts-expect-error - global.serverLogs = [] - setupConsoleWarnCollector() if (!isBuildTest) { @@ -38,10 +35,8 @@ export async function serve(root, isBuildTest) { ).listen() // use resolved port/base from server const base = viteServer.config.base === '/' ? '' : viteServer.config.base - const url = - // @ts-expect-error - (global.viteTestUrl = `http://localhost:${viteServer.config.server.port}${base}`) - await page.goto(url) + setViteUrl(`http://localhost:${viteServer.config.server.port}${base}`) + await page.goto(viteTestUrl) return viteServer } else { @@ -92,8 +87,7 @@ export async function serve(root, isBuildTest) { function setupConsoleWarnCollector() { const warn = console.warn console.warn = (...args) => { - // @ts-expect-error - global.serverLogs.push(args.join(' ')) + serverLogs.push(args.join(' ')) return warn.call(console, ...args) } } diff --git a/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts b/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts index 56c0b46c8a3e6f..e61c2187556f08 100644 --- a/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts +++ b/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts @@ -1,4 +1,4 @@ -import { getColor, untilUpdated } from '../../testUtils' +import { getColor, page, untilUpdated } from '~utils' test('should have css applied on second dynamic import', async () => { await untilUpdated(() => page.textContent('.content'), 'Initial', true) diff --git a/playground/nested-deps/__tests__/nested-deps.spec.ts b/playground/nested-deps/__tests__/nested-deps.spec.ts index 2ef0e191da7b50..e4adb68792d116 100644 --- a/playground/nested-deps/__tests__/nested-deps.spec.ts +++ b/playground/nested-deps/__tests__/nested-deps.spec.ts @@ -1,3 +1,5 @@ +import { page } from '~utils' + test('handle nested package', async () => { expect(await page.textContent('.a')).toBe('A@2.0.0') expect(await page.textContent('.b')).toBe('B@1.0.0') diff --git a/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/playground/optimize-deps/__tests__/optimize-deps.spec.ts index e832408370969a..898d75f6bf9f0d 100644 --- a/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -1,4 +1,4 @@ -import { getColor, isBuild } from '../../testUtils' +import { getColor, isBuild, page } from '~utils' test('default + named imports from cjs dep (react)', async () => { expect(await page.textContent('.cjs button')).toBe('count is 0') diff --git a/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts b/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts index 9f6934dd25ace8..d6e2403761268a 100644 --- a/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts +++ b/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts @@ -1,6 +1,6 @@ import { port } from './serve' import fetch from 'node-fetch' -import { untilUpdated } from '../../testUtils' +import { page, untilUpdated } from '~utils' import { platform } from 'os' const url = `http://localhost:${port}/` diff --git a/playground/optimize-missing-deps/__test__/serve.ts b/playground/optimize-missing-deps/__test__/serve.ts index 3b60850905e389..81c58b296837e1 100644 --- a/playground/optimize-missing-deps/__test__/serve.ts +++ b/playground/optimize-missing-deps/__test__/serve.ts @@ -2,7 +2,7 @@ // the default e2e test serve behavior import path from 'path' -import { ports } from '../../testUtils' +import { ports } from '~utils' export const port = ports['optimize-missing-deps'] diff --git a/playground/preload/__tests__/preload.spec.ts b/playground/preload/__tests__/preload.spec.ts index b0ffb58a291bac..cb1d3557499946 100644 --- a/playground/preload/__tests__/preload.spec.ts +++ b/playground/preload/__tests__/preload.spec.ts @@ -1,4 +1,4 @@ -import { isBuild } from '../../testUtils' +import { browserLogs, isBuild, page, viteTestUrl } from '~utils' test('should have no 404s', () => { browserLogs.forEach((msg) => { diff --git a/playground/preserve-symlinks/__tests__/preserve-symlinks.spec.ts b/playground/preserve-symlinks/__tests__/preserve-symlinks.spec.ts index 7e0b546d7dbdbb..c33069fbc48cc9 100644 --- a/playground/preserve-symlinks/__tests__/preserve-symlinks.spec.ts +++ b/playground/preserve-symlinks/__tests__/preserve-symlinks.spec.ts @@ -1,3 +1,5 @@ +import { browserLogs, page } from '~utils' + test('should have no 404s', () => { browserLogs.forEach((msg) => { expect(msg).not.toMatch('404') diff --git a/playground/react-emotion/__tests__/react.spec.ts b/playground/react-emotion/__tests__/react.spec.ts index 49a66b9e103374..86b572be1ff403 100644 --- a/playground/react-emotion/__tests__/react.spec.ts +++ b/playground/react-emotion/__tests__/react.spec.ts @@ -1,4 +1,4 @@ -import { editFile, untilUpdated } from '../../testUtils' +import { editFile, page, untilUpdated } from '~utils' test('should render', async () => { expect(await page.textContent('h1')).toMatch( diff --git a/playground/react/__tests__/react.spec.ts b/playground/react/__tests__/react.spec.ts index 4b39a304733318..8381992d59df3d 100644 --- a/playground/react/__tests__/react.spec.ts +++ b/playground/react/__tests__/react.spec.ts @@ -1,4 +1,4 @@ -import { editFile, untilUpdated, isServe } from '../../testUtils' +import { editFile, isServe, page, untilUpdated } from '~utils' test('should render', async () => { expect(await page.textContent('h1')).toMatch('Hello Vite + React') diff --git a/playground/resolve-config/__tests__/resolve-config.spec.ts b/playground/resolve-config/__tests__/resolve-config.spec.ts index bd45ad6c95012d..9b3588cafcc47d 100644 --- a/playground/resolve-config/__tests__/resolve-config.spec.ts +++ b/playground/resolve-config/__tests__/resolve-config.spec.ts @@ -1,15 +1,14 @@ import fs from 'fs' import path from 'path' import { commandSync } from 'execa' -import { isBuild, testDir, workspaceRoot } from '../../testUtils' - -const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js') +import { isBuild, testDir, viteBinPath } from '~utils' const fromTestDir = (...p: string[]) => path.resolve(testDir(), ...p) const build = (configName: string) => { - commandSync(`${viteBin} build`, { cwd: fromTestDir(configName) }) + commandSync(`${viteBinPath} build`, { cwd: fromTestDir(configName) }) } + const getDistFile = (configName: string, extension: string) => { return fs.readFileSync( fromTestDir(`${configName}/dist/index.es.${extension}`), diff --git a/playground/resolve/__tests__/resolve.spec.ts b/playground/resolve/__tests__/resolve.spec.ts index 2deb2fab7f8d40..79ab9dce6409c3 100644 --- a/playground/resolve/__tests__/resolve.spec.ts +++ b/playground/resolve/__tests__/resolve.spec.ts @@ -1,4 +1,4 @@ -import { isBuild } from '../../testUtils' +import { isBuild, page } from '~utils' test('bom import', async () => { expect(await page.textContent('.utf8-bom')).toMatch('[success]') diff --git a/playground/ssr-deps/__tests__/serve.ts b/playground/ssr-deps/__tests__/serve.ts index 92c73fc50a8629..1d5ef5f3039c4e 100644 --- a/playground/ssr-deps/__tests__/serve.ts +++ b/playground/ssr-deps/__tests__/serve.ts @@ -2,7 +2,7 @@ // the default e2e test serve behavior import path from 'path' -import { ports } from '../../testUtils' +import { ports } from '~utils' export const port = ports['ssr-deps'] diff --git a/playground/ssr-deps/__tests__/ssr-deps.spec.ts b/playground/ssr-deps/__tests__/ssr-deps.spec.ts index 8a201c9eb87455..75903a1c39c943 100644 --- a/playground/ssr-deps/__tests__/ssr-deps.spec.ts +++ b/playground/ssr-deps/__tests__/ssr-deps.spec.ts @@ -1,4 +1,5 @@ import { port } from './serve' +import { page } from '~utils' const url = `http://localhost:${port}` diff --git a/playground/ssr-html/__tests__/serve.ts b/playground/ssr-html/__tests__/serve.ts index 804009e92e86d6..c46d8f5a0574fd 100644 --- a/playground/ssr-html/__tests__/serve.ts +++ b/playground/ssr-html/__tests__/serve.ts @@ -2,7 +2,7 @@ // the default e2e test serve behavior import path from 'path' -import { ports } from '../../testUtils' +import { ports } from '~utils' export const port = ports['ssr-html'] diff --git a/playground/ssr-html/__tests__/ssr-html.spec.ts b/playground/ssr-html/__tests__/ssr-html.spec.ts index e34b8a91fc3421..bcf66c8f5ad128 100644 --- a/playground/ssr-html/__tests__/ssr-html.spec.ts +++ b/playground/ssr-html/__tests__/ssr-html.spec.ts @@ -1,5 +1,6 @@ -import { port } from './serve' import fetch from 'node-fetch' +import { port } from './serve' +import { page } from '~utils' const url = `http://localhost:${port}` diff --git a/playground/ssr-pug/__tests__/serve.ts b/playground/ssr-pug/__tests__/serve.ts index 2d687a5a685664..094dc20ab7e121 100644 --- a/playground/ssr-pug/__tests__/serve.ts +++ b/playground/ssr-pug/__tests__/serve.ts @@ -2,7 +2,7 @@ // the default e2e test serve behavior import path from 'path' -import { ports } from '../../testUtils' +import { ports } from '~utils' export const port = ports['ssr-pug'] diff --git a/playground/ssr-pug/__tests__/ssr-pug.spec.ts b/playground/ssr-pug/__tests__/ssr-pug.spec.ts index e34b8a91fc3421..bcf66c8f5ad128 100644 --- a/playground/ssr-pug/__tests__/ssr-pug.spec.ts +++ b/playground/ssr-pug/__tests__/ssr-pug.spec.ts @@ -1,5 +1,6 @@ -import { port } from './serve' import fetch from 'node-fetch' +import { port } from './serve' +import { page } from '~utils' const url = `http://localhost:${port}` diff --git a/playground/ssr-react/__tests__/serve.ts b/playground/ssr-react/__tests__/serve.ts index 2f8479a7463bd7..033d3565b89279 100644 --- a/playground/ssr-react/__tests__/serve.ts +++ b/playground/ssr-react/__tests__/serve.ts @@ -2,7 +2,7 @@ // the default e2e test serve behavior import path from 'path' -import { ports } from '../../testUtils' +import { ports } from '~utils' export const port = ports['ssr-react'] diff --git a/playground/ssr-react/__tests__/ssr-react.spec.ts b/playground/ssr-react/__tests__/ssr-react.spec.ts index 2235d4ae4d0edf..e560d0311b0caf 100644 --- a/playground/ssr-react/__tests__/ssr-react.spec.ts +++ b/playground/ssr-react/__tests__/ssr-react.spec.ts @@ -1,6 +1,6 @@ -import { editFile, untilUpdated } from '../../testUtils' -import { port } from './serve' import fetch from 'node-fetch' +import { port } from './serve' +import { browserLogs, editFile, page, untilUpdated } from '~utils' const url = `http://localhost:${port}` diff --git a/playground/ssr-vue/__tests__/serve.ts b/playground/ssr-vue/__tests__/serve.ts index 138729bfdaa01e..fd126c5482312d 100644 --- a/playground/ssr-vue/__tests__/serve.ts +++ b/playground/ssr-vue/__tests__/serve.ts @@ -2,7 +2,7 @@ // the default e2e test serve behavior import path from 'path' -import { ports } from '../../testUtils' +import { ports } from '~utils' export const port = ports['ssr-vue'] diff --git a/playground/ssr-vue/__tests__/ssr-vue.spec.ts b/playground/ssr-vue/__tests__/ssr-vue.spec.ts index 193c95b1f4a1c1..c58cea4cd13e59 100644 --- a/playground/ssr-vue/__tests__/ssr-vue.spec.ts +++ b/playground/ssr-vue/__tests__/ssr-vue.spec.ts @@ -1,7 +1,14 @@ -import { editFile, getColor, isBuild, untilUpdated } from '../../testUtils' -import { port } from './serve' -import fetch from 'node-fetch' import { resolve } from 'path' +import fetch from 'node-fetch' +import { port } from './serve' +import { + browserLogs, + editFile, + getColor, + isBuild, + page, + untilUpdated +} from '~utils' const url = `http://localhost:${port}` diff --git a/playground/ssr-webworker/__tests__/serve.ts b/playground/ssr-webworker/__tests__/serve.ts index 382208b3b06d2e..97d16cd3a97e3b 100644 --- a/playground/ssr-webworker/__tests__/serve.ts +++ b/playground/ssr-webworker/__tests__/serve.ts @@ -2,7 +2,7 @@ // the default e2e test serve behavior import path from 'path' -import { ports } from '../../testUtils' +import { ports } from '~utils' export const port = ports['ssr-webworker'] diff --git a/playground/ssr-webworker/__tests__/ssr-webworker.spec.ts b/playground/ssr-webworker/__tests__/ssr-webworker.spec.ts index 30d2bb93e495b1..7a5c1bdad2880e 100644 --- a/playground/ssr-webworker/__tests__/ssr-webworker.spec.ts +++ b/playground/ssr-webworker/__tests__/ssr-webworker.spec.ts @@ -1,4 +1,5 @@ import { port } from './serve' +import { page } from '~utils' const url = `http://localhost:${port}` diff --git a/playground/tailwind-sourcemap/__tests__/build.spec.ts b/playground/tailwind-sourcemap/__tests__/build.spec.ts index 50b8814aed9c4e..b30284731a76d9 100644 --- a/playground/tailwind-sourcemap/__tests__/build.spec.ts +++ b/playground/tailwind-sourcemap/__tests__/build.spec.ts @@ -1,4 +1,4 @@ -import { isBuild } from '../../testUtils' +import { isBuild, serverLogs } from '~utils' test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => { serverLogs.forEach((log) => { diff --git a/playground/tailwind-sourcemap/__tests__/serve.spec.ts b/playground/tailwind-sourcemap/__tests__/serve.spec.ts index 8d4613190f02a2..62e46cc7781482 100644 --- a/playground/tailwind-sourcemap/__tests__/serve.spec.ts +++ b/playground/tailwind-sourcemap/__tests__/serve.spec.ts @@ -1,4 +1,4 @@ -import { isBuild } from '../../testUtils' +import { isBuild, serverLogs } from '~utils' test.runIf(isBuild)('should not output missing source file warning', () => { serverLogs.forEach((log) => { diff --git a/playground/tailwind/__test__/tailwind.spec.ts b/playground/tailwind/__test__/tailwind.spec.ts index 47f6b7ccf49037..ee596a17999a6e 100644 --- a/playground/tailwind/__test__/tailwind.spec.ts +++ b/playground/tailwind/__test__/tailwind.spec.ts @@ -1,4 +1,11 @@ -import { isBuild, editFile, untilUpdated, getColor } from '../../testUtils' +import { + isBuild, + editFile, + untilUpdated, + getColor, + browserLogs, + page +} from '~utils' test('should render', async () => { expect(await page.textContent('#pagetitle')).toBe('|Page title|') diff --git a/playground/testUtils.ts b/playground/test-utils.ts similarity index 93% rename from playground/testUtils.ts rename to playground/test-utils.ts index d423ba942923cb..00bfced5cb1006 100644 --- a/playground/testUtils.ts +++ b/playground/test-utils.ts @@ -1,5 +1,5 @@ // test utils used in e2e tests for playgrounds. -// `import { getColor } from '../../testUtils'` +// `import { getColor } from '~utils'` import fs from 'fs' import path from 'path' @@ -9,6 +9,26 @@ import type { Manifest } from 'vite' import { normalizePath } from 'vite' import { fromComment } from 'convert-source-map' import { expect } from 'vitest' +import { page } from '../scripts/vitestSetup' + +// TODO: explicitly import APIs and remove this +import 'vitest/globals' + +export * from '../scripts/vitestSetup' + +export const workspaceRoot = path.resolve(__dirname, '../') + +export const isBuild = !!process.env.VITE_TEST_BUILD +export const isServe = !isBuild + +export const isWindows = process.platform === 'win32' +export const viteBinPath = path.join( + workspaceRoot, + 'packages', + 'vite', + 'bin', + 'vite.js' +) // make sure these ports are unique export const ports = { @@ -31,15 +51,11 @@ export function slash(p: string): string { return p.replace(/\\/g, '/') } -export const isBuild = !!process.env.VITE_TEST_BUILD -export const isServe = !isBuild - export const testDir = () => { const testPath = expect.getState().testPath const testName = slash(testPath).match(/playground\/([\w-]+)\//)?.[1] return path.resolve(__dirname, '../playground-temp', testName) } -export const workspaceRoot = path.resolve(__dirname, '../') const hexToNameMap: Record = {} Object.keys(colors).forEach((color) => { @@ -159,11 +175,6 @@ export async function untilUpdated( } } -/** - * Send the rebuild complete message in build watch - */ -export { notifyRebuildComplete } from '../scripts/vitestSetup' - export const extractSourcemap = (content: string) => { const lines = content.trim().split('\n') return fromComment(lines[lines.length - 1]).toObject() diff --git a/playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts b/playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts index 30485918ea6e2d..52a02683b79c00 100644 --- a/playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts +++ b/playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts @@ -1,10 +1,14 @@ import { + beforeAllError, + browserLogs, + clearBeforeAllError, editFile, isBuild, isServe, + page, readFile, untilUpdated -} from '../../testUtils' +} from '~utils' describe.runIf(isBuild)('build', () => { test('should throw an error on build', () => { @@ -13,7 +17,7 @@ describe.runIf(isBuild)('build', () => { expect(buildError.message).toMatch( /^parsing .* failed: SyntaxError: Unexpected token } in JSON at position \d+$/ ) - beforeAllError = null // got expected error, null it here so testsuite does not fail from rethrow in afterAll + clearBeforeAllError() // got expected error, null it here so testsuite does not fail from rethrow in afterAll }) test('should not output files to dist', () => { diff --git a/playground/tsconfig-json/__tests__/tsconfig-json.spec.ts b/playground/tsconfig-json/__tests__/tsconfig-json.spec.ts index 0cd6af909f045b..aec0c42b3a3a77 100644 --- a/playground/tsconfig-json/__tests__/tsconfig-json.spec.ts +++ b/playground/tsconfig-json/__tests__/tsconfig-json.spec.ts @@ -1,6 +1,7 @@ import path from 'path' import fs from 'fs' import { transformWithEsbuild } from 'vite' +import { browserLogs } from '~utils' test('should respected each `tsconfig.json`s compilerOptions', () => { // main side effect should be called (because of `"importsNotUsedAsValues": "preserve"`) diff --git a/playground/tsconfig.json b/playground/tsconfig.json index 06bea8c1328d7f..55ffe0cc6b1ba2 100644 --- a/playground/tsconfig.json +++ b/playground/tsconfig.json @@ -7,8 +7,12 @@ "allowJs": true, "esModuleInterop": true, "moduleResolution": "node", + "resolveJsonModule": true, "baseUrl": ".", "jsx": "preserve", - "types": ["vite/client", "vitest/globals", "node"] + "types": ["vite/client", "vitest/globals", "node"], + "paths": { + "~utils": ["./test-utils.ts"] + } } } diff --git a/playground/vue-jsx/__tests__/vue-jsx.spec.ts b/playground/vue-jsx/__tests__/vue-jsx.spec.ts index 94c4eb147a0b84..2e6858dacce3c4 100644 --- a/playground/vue-jsx/__tests__/vue-jsx.spec.ts +++ b/playground/vue-jsx/__tests__/vue-jsx.spec.ts @@ -1,4 +1,4 @@ -import { editFile, isServe, untilUpdated } from '../../testUtils' +import { editFile, isServe, page, untilUpdated } from '~utils' test('should render', async () => { expect(await page.textContent('.named')).toMatch('0') diff --git a/playground/vue-lib/__tests__/vue-lib.spec.ts b/playground/vue-lib/__tests__/vue-lib.spec.ts index 0504160f17d2f0..5766b0c0c5643a 100644 --- a/playground/vue-lib/__tests__/vue-lib.spec.ts +++ b/playground/vue-lib/__tests__/vue-lib.spec.ts @@ -1,5 +1,5 @@ -import { build } from 'vite' import path from 'path' +import { build } from 'vite' import type { OutputChunk, RollupOutput } from 'rollup' describe('vue component library', () => { diff --git a/playground/vue-lib/src-consumer/index.ts b/playground/vue-lib/src-consumer/index.ts index ac0f65e2a3ed9d..ee20f81d75a7ca 100644 --- a/playground/vue-lib/src-consumer/index.ts +++ b/playground/vue-lib/src-consumer/index.ts @@ -1,5 +1,5 @@ -// @ts-ignore /* eslint-disable node/no-missing-import */ +// @ts-ignore import { CompA } from '../dist/lib/my-vue-lib.es' import '../dist/lib/style.css' import { createApp } from 'vue' diff --git a/playground/vue-sourcemap/__tests__/build.spec.ts b/playground/vue-sourcemap/__tests__/build.spec.ts index 50b8814aed9c4e..b30284731a76d9 100644 --- a/playground/vue-sourcemap/__tests__/build.spec.ts +++ b/playground/vue-sourcemap/__tests__/build.spec.ts @@ -1,4 +1,4 @@ -import { isBuild } from '../../testUtils' +import { isBuild, serverLogs } from '~utils' test.runIf(isBuild)('should not output sourcemap warning (#4939)', () => { serverLogs.forEach((log) => { diff --git a/playground/vue-sourcemap/__tests__/serve.spec.ts b/playground/vue-sourcemap/__tests__/serve.spec.ts index 09ba69c03abfa4..278b04bef1e6f5 100644 --- a/playground/vue-sourcemap/__tests__/serve.spec.ts +++ b/playground/vue-sourcemap/__tests__/serve.spec.ts @@ -1,9 +1,10 @@ +import { URL } from 'url' import { extractSourcemap, formatSourcemapForSnapshot, - isServe -} from '../../testUtils' -import { URL } from 'url' + isServe, + page +} from '~utils' describe.runIf(isServe)('serve:vue-sourcemap', () => { const getStyleTagContentIncluding = async (content: string) => { diff --git a/playground/vue/__tests__/vue.spec.ts b/playground/vue/__tests__/vue.spec.ts index f790bd612bfa9e..3b6e2cc15555b1 100644 --- a/playground/vue/__tests__/vue.spec.ts +++ b/playground/vue/__tests__/vue.spec.ts @@ -1,10 +1,13 @@ import { + browserLogs, editFile, getBg, getColor, isBuild, + page, + serverLogs, untilUpdated -} from '../../testUtils' +} from '~utils' test('should render', async () => { expect(await page.textContent('h1')).toMatch('Vue SFCs') diff --git a/playground/wasm/__tests__/wasm.spec.ts b/playground/wasm/__tests__/wasm.spec.ts index 112617212251fa..9a23378ecbf8dc 100644 --- a/playground/wasm/__tests__/wasm.spec.ts +++ b/playground/wasm/__tests__/wasm.spec.ts @@ -1,4 +1,4 @@ -import { untilUpdated } from '../../testUtils' +import { page, untilUpdated } from '~utils' test('should work when inlined', async () => { await page.click('.inline-wasm .run') diff --git a/playground/worker/__tests__/es/es-worker.spec.ts b/playground/worker/__tests__/es/es-worker.spec.ts index 4096aa4ec995e7..6d8cdaf9767d11 100644 --- a/playground/worker/__tests__/es/es-worker.spec.ts +++ b/playground/worker/__tests__/es/es-worker.spec.ts @@ -1,7 +1,7 @@ import fs from 'fs' import path from 'path' import type { Page } from 'playwright-chromium' -import { isBuild, testDir, untilUpdated } from '../../../testUtils' +import { isBuild, page, testDir, untilUpdated } from '~utils' test('normal', async () => { await page.click('.ping') diff --git a/playground/worker/__tests__/iife/worker.spec.ts b/playground/worker/__tests__/iife/worker.spec.ts index 37cc8675dc357b..0842d42e3562cc 100644 --- a/playground/worker/__tests__/iife/worker.spec.ts +++ b/playground/worker/__tests__/iife/worker.spec.ts @@ -2,7 +2,7 @@ import fs from 'fs' import path from 'path' import type { Page } from 'playwright-chromium' import { test } from 'vitest' -import { isBuild, testDir, untilUpdated } from '../../../testUtils' +import { isBuild, page, testDir, untilUpdated } from '~utils' test('normal', async () => { await page.click('.ping') diff --git a/playground/worker/__tests__/sourcemap-hidden/sourcemap-hidden-worker.spec.ts b/playground/worker/__tests__/sourcemap-hidden/sourcemap-hidden-worker.spec.ts index ce2c52b5c98840..3b1f153ef1f19a 100644 --- a/playground/worker/__tests__/sourcemap-hidden/sourcemap-hidden-worker.spec.ts +++ b/playground/worker/__tests__/sourcemap-hidden/sourcemap-hidden-worker.spec.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import { isBuild, testDir } from '../../../testUtils' +import { isBuild, testDir } from '~utils' describe.runIf(isBuild)('build', () => { // assert correct files diff --git a/playground/worker/__tests__/sourcemap-inline/sourcemap-inline-worker.spec.ts b/playground/worker/__tests__/sourcemap-inline/sourcemap-inline-worker.spec.ts index 0fe97386f178df..eaf62b25dde214 100644 --- a/playground/worker/__tests__/sourcemap-inline/sourcemap-inline-worker.spec.ts +++ b/playground/worker/__tests__/sourcemap-inline/sourcemap-inline-worker.spec.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import { isBuild, testDir } from '../../../testUtils' +import { isBuild, testDir } from '~utils' describe.runIf(isBuild)('build', () => { // assert correct files diff --git a/playground/worker/__tests__/sourcemap/sourcemap-worker.spec.ts b/playground/worker/__tests__/sourcemap/sourcemap-worker.spec.ts index 3b074f24990f4b..10dcfcb5fba048 100644 --- a/playground/worker/__tests__/sourcemap/sourcemap-worker.spec.ts +++ b/playground/worker/__tests__/sourcemap/sourcemap-worker.spec.ts @@ -1,6 +1,6 @@ import fs from 'fs' import path from 'path' -import { isBuild, testDir } from '../../../testUtils' +import { isBuild, testDir } from '~utils' describe.runIf(isBuild)('build', () => { // assert correct files diff --git a/scripts/patchEsbuildDist.ts b/scripts/patchEsbuildDist.ts index 70ef846af1bcbb..6ad2803c741346 100644 --- a/scripts/patchEsbuildDist.ts +++ b/scripts/patchEsbuildDist.ts @@ -3,8 +3,8 @@ // and plugin-react. For the moment, we can remove the extra exports code added in 0.14.4 to // continue using it. -import { bold, red } from 'picocolors' import { readFileSync, writeFileSync } from 'fs' +import { bold, red } from 'picocolors' const indexPath = process.argv[2] const varName = process.argv[3] diff --git a/scripts/patchFileDeps.ts b/scripts/patchFileDeps.ts index 0e90bbe8adece2..e5d15baecc7029 100644 --- a/scripts/patchFileDeps.ts +++ b/scripts/patchFileDeps.ts @@ -3,8 +3,8 @@ // This script is called from postinstall hooks in playground packages that // uses the file: protocol, and copies the file: deps into node_modules. -import { copySync, removeSync } from 'fs-extra' import { join, resolve } from 'path' +import { copySync, removeSync } from 'fs-extra' const root = process.cwd() const pkg = require(join(root, 'package.json')) diff --git a/scripts/releaseUtils.ts b/scripts/releaseUtils.ts index b444835db7b6d0..9fff2679b868b0 100644 --- a/scripts/releaseUtils.ts +++ b/scripts/releaseUtils.ts @@ -1,11 +1,11 @@ /** * modified from https://github.com/vuejs/core/blob/master/scripts/release.js */ +import { existsSync, readFileSync, readdirSync, writeFileSync } from 'fs' +import path from 'path' import colors from 'picocolors' import type { Options as ExecaOptions } from 'execa' import execa from 'execa' -import { readFileSync, writeFileSync, existsSync, readdirSync } from 'fs' -import path from 'path' import type { ReleaseType } from 'semver' import semver from 'semver' diff --git a/scripts/verifyCommit.ts b/scripts/verifyCommit.ts index e433e3aa1aa3e5..226b514437d555 100644 --- a/scripts/verifyCommit.ts +++ b/scripts/verifyCommit.ts @@ -1,7 +1,7 @@ // Invoked on the commit-msg git hook by simple-git-hooks. -import colors from 'picocolors' import { readFileSync } from 'fs' +import colors from 'picocolors' // get $1 from commit-msg script const msgPath = process.argv[2] diff --git a/scripts/vitestGlobalSetup.ts b/scripts/vitestGlobalSetup.ts index 8a0b7ffad6c6b2..52b49d01f38fda 100644 --- a/scripts/vitestGlobalSetup.ts +++ b/scripts/vitestGlobalSetup.ts @@ -1,6 +1,6 @@ import os from 'os' -import fs from 'fs-extra' import path from 'path' +import fs from 'fs-extra' import type { BrowserServer } from 'playwright-chromium' import { chromium } from 'playwright-chromium' diff --git a/scripts/vitestSetup.ts b/scripts/vitestSetup.ts index 4275d9d80864a5..84cc8107952ecb 100644 --- a/scripts/vitestSetup.ts +++ b/scripts/vitestSetup.ts @@ -1,71 +1,53 @@ -import fs from 'fs-extra' import * as http from 'http' -import { resolve, dirname } from 'path' -import sirv from 'sirv' +import { dirname, resolve } from 'path' import os from 'os' import path from 'path' +import sirv from 'sirv' +import fs from 'fs-extra' import { chromium } from 'playwright-chromium' import type { - ViteDevServer, InlineConfig, + Logger, PluginOption, ResolvedConfig, - Logger + ViteDevServer } from 'vite' -import { createServer, build, mergeConfig } from 'vite' -import type { Page, ConsoleMessage } from 'playwright-chromium' +import { build, createServer, mergeConfig } from 'vite' +import type { Browser, ConsoleMessage, Page } from 'playwright-chromium' import type { RollupError, RollupWatcher, RollupWatcherEvent } from 'rollup' import type { File } from 'vitest' import { beforeAll } from 'vitest' const isBuildTest = !!process.env.VITE_TEST_BUILD -export function slash(p: string): string { - return p.replace(/\\/g, '/') -} - -// injected by the test env -declare global { - const page: Page | undefined - - const browserLogs: string[] - const browserErrors: Error[] - const serverLogs: string[] - let viteTestUrl: string | undefined - const watcher: RollupWatcher | undefined - let beforeAllError: Error | null // error caught in beforeAll, useful if you want to test error scenarios on build -} - -declare const global: { - page?: Page - - browserLogs: string[] - browserErrors: Error[] - serverLogs: string[] - viteTestUrl?: string - watcher?: RollupWatcher - beforeAllError: Error | null -} - let server: ViteDevServer | http.Server let tempDir: string let rootDir: string -const setBeforeAllError = (err: Error | null) => { - global.beforeAllError = err +export const serverLogs: string[] = [] +export const browserLogs: string[] = [] +export const browserErrors: Error[] = [] + +/** + * Error caught in beforeAll, useful if you want to test error scenarios on build + */ +export let beforeAllError: Error | null = null + +export let page: Page = undefined! +export let browser: Browser = undefined! +export let viteTestUrl: string = '' +export let watcher: RollupWatcher | undefined = undefined + +export function clearBeforeAllError() { + beforeAllError = null } -const getBeforeAllError = () => global.beforeAllError -//init with null so old errors don't carry over -setBeforeAllError(null) -const logs: string[] = (global.browserLogs = []) -const onConsole = (msg: ConsoleMessage) => { - logs.push(msg.text()) +export function setViteUrl(url: string) { + viteTestUrl = url } -const errors: Error[] = (global.browserErrors = []) -const onPageError = (error: Error) => { - errors.push(error) +export function slash(p: string): string { + return p.replace(/\\/g, '/') } const DIR = path.join(os.tmpdir(), 'vitest_playwright_global_setup') @@ -82,10 +64,8 @@ beforeAll(async (s) => { return } - const browser = await chromium.connect(wsEndpoint) - const page = await browser.newPage() - // @ts-expect-error - globalThis.page = page + browser = await chromium.connect(wsEndpoint) + page = await browser.newPage() const globalConsole = globalThis.console const warn = globalConsole.warn @@ -97,8 +77,12 @@ beforeAll(async (s) => { } try { - page.on('console', onConsole) - page.on('pageerror', onPageError) + page.on('console', (msg) => { + browserLogs.push(msg.text()) + }) + page.on('pageerror', (error) => { + browserErrors.push(error) + }) const testPath = suite.filepath! const testName = slash(testPath).match(/playground\/([\w-]+)\//)?.[1] @@ -138,8 +122,6 @@ beforeAll(async (s) => { config = require(testCustomConfig) } - const serverLogs: string[] = [] - const options: InlineConfig = { root: rootDir, logLevel: 'silent', @@ -165,8 +147,6 @@ beforeAll(async (s) => { setupConsoleWarnCollector(serverLogs) - global.serverLogs = serverLogs - if (!isBuildTest) { process.env.VITE_INLINE = 'inline-serve' server = await ( @@ -174,9 +154,8 @@ beforeAll(async (s) => { ).listen() // use resolved port/base from server const base = server.config.base === '/' ? '' : server.config.base - const url = - (global.viteTestUrl = `http://localhost:${server.config.server.port}${base}`) - await page.goto(url) + viteTestUrl = `http://localhost:${server.config.server.port}${base}` + await page.goto(viteTestUrl) } else { process.env.VITE_INLINE = 'inline-build' // determine build watch @@ -192,11 +171,11 @@ beforeAll(async (s) => { const isWatch = !!resolvedConfig!.build.watch // in build watch,call startStaticServer after the build is complete if (isWatch) { - global.watcher = rollupOutput as RollupWatcher - await notifyRebuildComplete(global.watcher) + watcher = rollupOutput as RollupWatcher + await notifyRebuildComplete(watcher) } - const url = (global.viteTestUrl = await startStaticServer(config)) - await page.goto(url) + viteTestUrl = await startStaticServer(config) + await page.goto(viteTestUrl) } } } catch (e: any) { @@ -210,17 +189,15 @@ beforeAll(async (s) => { } return async () => { - page?.off('console', onConsole) - global.serverLogs = [] + serverLogs.length = 0 await page?.close() await server?.close() - global.watcher?.close() - const beforeAllErr = getBeforeAllError() + watcher?.close() if (browser) { await browser.close() } - if (beforeAllErr) { - throw beforeAllErr + if (beforeAllError) { + throw beforeAllError } } }, 30000) diff --git a/vitest.config.e2e.ts b/vitest.config.e2e.ts index a23378c97465b3..241910ff7382c3 100644 --- a/vitest.config.e2e.ts +++ b/vitest.config.e2e.ts @@ -1,6 +1,12 @@ +import { resolve } from 'path' import { defineConfig } from 'vitest/config' export default defineConfig({ + resolve: { + alias: { + '~utils': resolve(__dirname, './playground/test-utils') + } + }, test: { include: ['./playground/**/*.spec.[tj]s'], setupFiles: ['./scripts/vitestSetup.ts'], From b99cdc8fc51d43e4d92df6e5be1ef6146e05a7c7 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 11 May 2022 17:20:50 +0800 Subject: [PATCH 107/114] chore: fix test --- playground/test-utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/playground/test-utils.ts b/playground/test-utils.ts index 00bfced5cb1006..60a159f701fa1f 100644 --- a/playground/test-utils.ts +++ b/playground/test-utils.ts @@ -1,6 +1,9 @@ // test utils used in e2e tests for playgrounds. // `import { getColor } from '~utils'` +// TODO: explicitly import APIs and remove this +/// + import fs from 'fs' import path from 'path' import colors from 'css-color-names' @@ -11,9 +14,6 @@ import { fromComment } from 'convert-source-map' import { expect } from 'vitest' import { page } from '../scripts/vitestSetup' -// TODO: explicitly import APIs and remove this -import 'vitest/globals' - export * from '../scripts/vitestSetup' export const workspaceRoot = path.resolve(__dirname, '../') From 79ef186b40c98d1988576e21610fe78e1aa3a93c Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 11 May 2022 18:09:52 +0800 Subject: [PATCH 108/114] chore: enable typecheck for tests and scripts (#8114) --- .eslintrc.cjs | 3 ++- .github/workflows/ci.yml | 4 ++++ CONTRIBUTING.md | 8 ++++---- package.json | 1 + playground/cli-module/__tests__/serve.ts | 2 +- playground/cli/__tests__/serve.ts | 2 +- playground/html/__tests__/html.spec.ts | 2 +- playground/legacy/__tests__/ssr/serve.ts | 2 +- playground/lib/__tests__/serve.ts | 2 +- playground/optimize-missing-deps/__test__/serve.ts | 2 +- playground/react-emotion/__tests__/react.spec.ts | 2 +- playground/resolve-config/__tests__/serve.ts | 2 +- playground/ssr-deps/__tests__/serve.ts | 2 +- playground/ssr-html/__tests__/serve.ts | 2 +- playground/ssr-pug/__tests__/serve.ts | 2 +- playground/ssr-react/__tests__/serve.ts | 2 +- playground/ssr-react/server.js | 1 + playground/ssr-vue/__tests__/serve.ts | 2 +- playground/ssr-vue/server.js | 1 + playground/ssr-webworker/__tests__/serve.ts | 2 +- playground/test-utils.ts | 5 +++-- playground/tsconfig.json | 7 +++++-- {scripts => playground}/vitestGlobalSetup.ts | 0 {scripts => playground}/vitestSetup.ts | 2 +- playground/vue-lib/__tests__/serve.ts | 2 +- playground/worker/my-shared-worker.ts | 5 ++++- playground/worker/my-worker.ts | 2 +- scripts/tsconfig.json | 7 ++++--- vitest.config.e2e.ts | 4 ++-- 29 files changed, 48 insertions(+), 32 deletions(-) rename {scripts => playground}/vitestGlobalSetup.ts (100%) rename {scripts => playground}/vitestSetup.ts (99%) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 1c80ee1df739c8..9f6bf0deb86303 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -119,7 +119,8 @@ module.exports = defineConfig({ rules: { 'node/no-extraneous-import': 'off', 'node/no-extraneous-require': 'off', - 'node/no-missing-import': 'off' + 'node/no-missing-import': 'off', + 'node/no-missing-require': 'off' } }, { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce695749544b39..6260aa327e7c86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,9 +102,13 @@ jobs: run: | pnpm run ci-build-vite pnpm run build-plugin-vue + pnpm run build-plugin-react - name: Lint run: pnpm run lint - name: Check formatting run: pnpm prettier --check . + + - name: Typecheck + run: pnpm run typecheck diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a6b0b84a83b5a3..daa79cc1222c80 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,7 +34,7 @@ If you want to use break point and explore code execution you can use the ["Run Some errors are masked and hidden away because of the layers of abstraction and sandboxed nature added by Vitest, Playwright, and Chromium. In order to see what's actually going wrong and the contents of the devtools console in those instances, follow this setup: -1. Add a `debugger` statement to the `scripts/vitestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits. +1. Add a `debugger` statement to the `playground/vitestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits. 1. Run the tests with the `debug-serve` script command which will enable remote debugging: `pnpm run debug-serve -- --runInBand resolve`. @@ -69,7 +69,7 @@ And re-run `pnpm install` to link the package. ### Integration Tests -Each package under `playground/` contains a `__tests__` directory. The tests are run using [Vitest](https://vitest.dev/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `vitest.config.e2e.js` and `scripts/vitest*` files. +Each package under `playground/` contains a `__tests__` directory. The tests are run using [Vitest](https://vitest.dev/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `vitest.config.e2e.js` and `playground/vitest*` files. Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). Also you may want to [set git `core.symlinks` to `true` to solve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242). @@ -107,11 +107,11 @@ test('should work', async () => { Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are also available in the utils. Source code is located at `playground/test-utils.ts`. -Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/9c6501d9c363eaa3c1e7708d531fb2a92b633db6/scripts/vitestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build. +Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/main/playground/vitestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build. ### Extending the Test Suite -To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/playground/assets/index.html#L121): +To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/main/playground/assets/index.html#L121): ```html

?raw import

diff --git a/package.json b/package.json index 8fffa3f6e045f6..ef29b398dde809 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "serve-docs": "vitepress serve docs", "release": "ts-node scripts/release.ts", "ci-publish": "ts-node scripts/publishCI.ts", + "typecheck": "tsc -p scripts --noEmit && tsc -p playground --noEmit", "build": "run-s build-vite build-plugin-vue build-plugin-react", "build-vite": "cd packages/vite && npm run build", "build-plugin-vue": "cd packages/plugin-vue && npm run build", diff --git a/playground/cli-module/__tests__/serve.ts b/playground/cli-module/__tests__/serve.ts index 6d5ad2d512089a..e4a011b2258c58 100644 --- a/playground/cli-module/__tests__/serve.ts +++ b/playground/cli-module/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import execa from 'execa' diff --git a/playground/cli/__tests__/serve.ts b/playground/cli/__tests__/serve.ts index 8c5717f4031e4a..9515b74af6a217 100644 --- a/playground/cli/__tests__/serve.ts +++ b/playground/cli/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import execa from 'execa' diff --git a/playground/html/__tests__/html.spec.ts b/playground/html/__tests__/html.spec.ts index 3e7c3d0166f75a..44372b324d5771 100644 --- a/playground/html/__tests__/html.spec.ts +++ b/playground/html/__tests__/html.spec.ts @@ -220,7 +220,7 @@ describe.runIf(isServe)('invalid', () => { }) test('should reload when fixed', async () => { - const response = await page.goto(viteTestUrl + '/invalid.html') + await page.goto(viteTestUrl + '/invalid.html') await editFile('invalid.html', (content) => { return content.replace('
Good') }) diff --git a/playground/legacy/__tests__/ssr/serve.ts b/playground/legacy/__tests__/ssr/serve.ts index 930f11f3bb8dfb..ec16b39e550965 100644 --- a/playground/legacy/__tests__/ssr/serve.ts +++ b/playground/legacy/__tests__/ssr/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' import { ports } from '~utils' diff --git a/playground/lib/__tests__/serve.ts b/playground/lib/__tests__/serve.ts index c536ad231bc3a5..a03bb185875b20 100644 --- a/playground/lib/__tests__/serve.ts +++ b/playground/lib/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' diff --git a/playground/optimize-missing-deps/__test__/serve.ts b/playground/optimize-missing-deps/__test__/serve.ts index 81c58b296837e1..7ceddad85dd19e 100644 --- a/playground/optimize-missing-deps/__test__/serve.ts +++ b/playground/optimize-missing-deps/__test__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' diff --git a/playground/react-emotion/__tests__/react.spec.ts b/playground/react-emotion/__tests__/react.spec.ts index 86b572be1ff403..ceb594ee259e1c 100644 --- a/playground/react-emotion/__tests__/react.spec.ts +++ b/playground/react-emotion/__tests__/react.spec.ts @@ -28,7 +28,7 @@ test('should update button style', async () => { }) } - const styles = await page.evaluate(() => { + await page.evaluate(() => { return document.querySelector('button').style }) diff --git a/playground/resolve-config/__tests__/serve.ts b/playground/resolve-config/__tests__/serve.ts index 4c1561264113e8..97d68d8f7fb54f 100644 --- a/playground/resolve-config/__tests__/serve.ts +++ b/playground/resolve-config/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' diff --git a/playground/ssr-deps/__tests__/serve.ts b/playground/ssr-deps/__tests__/serve.ts index 1d5ef5f3039c4e..4856ec936194e9 100644 --- a/playground/ssr-deps/__tests__/serve.ts +++ b/playground/ssr-deps/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' diff --git a/playground/ssr-html/__tests__/serve.ts b/playground/ssr-html/__tests__/serve.ts index c46d8f5a0574fd..9d1af30e706310 100644 --- a/playground/ssr-html/__tests__/serve.ts +++ b/playground/ssr-html/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' diff --git a/playground/ssr-pug/__tests__/serve.ts b/playground/ssr-pug/__tests__/serve.ts index 094dc20ab7e121..05d037d085c3b5 100644 --- a/playground/ssr-pug/__tests__/serve.ts +++ b/playground/ssr-pug/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' diff --git a/playground/ssr-react/__tests__/serve.ts b/playground/ssr-react/__tests__/serve.ts index 033d3565b89279..d6261ea9f55125 100644 --- a/playground/ssr-react/__tests__/serve.ts +++ b/playground/ssr-react/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' diff --git a/playground/ssr-react/server.js b/playground/ssr-react/server.js index 1876439c18fa88..bac272a95a2900 100644 --- a/playground/ssr-react/server.js +++ b/playground/ssr-react/server.js @@ -60,6 +60,7 @@ async function createServer( render = (await vite.ssrLoadModule('/src/entry-server.jsx')).render } else { template = indexProd + // @ts-ignore render = require('./dist/server/entry-server.js').render } diff --git a/playground/ssr-vue/__tests__/serve.ts b/playground/ssr-vue/__tests__/serve.ts index fd126c5482312d..1842659ec2019f 100644 --- a/playground/ssr-vue/__tests__/serve.ts +++ b/playground/ssr-vue/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' diff --git a/playground/ssr-vue/server.js b/playground/ssr-vue/server.js index 642f274647294f..c98d2984f82e5c 100644 --- a/playground/ssr-vue/server.js +++ b/playground/ssr-vue/server.js @@ -63,6 +63,7 @@ async function createServer( render = (await vite.ssrLoadModule('/src/entry-server.js')).render } else { template = indexProd + // @ts-ignore render = require('./dist/server/entry-server.js').render } diff --git a/playground/ssr-webworker/__tests__/serve.ts b/playground/ssr-webworker/__tests__/serve.ts index 97d16cd3a97e3b..4c4f1e3216e98f 100644 --- a/playground/ssr-webworker/__tests__/serve.ts +++ b/playground/ssr-webworker/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior import path from 'path' diff --git a/playground/test-utils.ts b/playground/test-utils.ts index 60a159f701fa1f..47bab08b698336 100644 --- a/playground/test-utils.ts +++ b/playground/test-utils.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/triple-slash-reference */ // test utils used in e2e tests for playgrounds. // `import { getColor } from '~utils'` @@ -12,9 +13,9 @@ import type { Manifest } from 'vite' import { normalizePath } from 'vite' import { fromComment } from 'convert-source-map' import { expect } from 'vitest' -import { page } from '../scripts/vitestSetup' +import { page } from './vitestSetup' -export * from '../scripts/vitestSetup' +export * from './vitestSetup' export const workspaceRoot = path.resolve(__dirname, '../') diff --git a/playground/tsconfig.json b/playground/tsconfig.json index 55ffe0cc6b1ba2..ada2a60bff6cff 100644 --- a/playground/tsconfig.json +++ b/playground/tsconfig.json @@ -3,12 +3,15 @@ "exclude": ["**/dist/**"], "compilerOptions": { "target": "es2019", + "module": "esnext", "outDir": "dist", + "baseUrl": ".", "allowJs": true, "esModuleInterop": true, - "moduleResolution": "node", "resolveJsonModule": true, - "baseUrl": ".", + "moduleResolution": "node", + "skipLibCheck": true, + "noUnusedLocals": true, "jsx": "preserve", "types": ["vite/client", "vitest/globals", "node"], "paths": { diff --git a/scripts/vitestGlobalSetup.ts b/playground/vitestGlobalSetup.ts similarity index 100% rename from scripts/vitestGlobalSetup.ts rename to playground/vitestGlobalSetup.ts diff --git a/scripts/vitestSetup.ts b/playground/vitestSetup.ts similarity index 99% rename from scripts/vitestSetup.ts rename to playground/vitestSetup.ts index 84cc8107952ecb..15c1192b7c7159 100644 --- a/scripts/vitestSetup.ts +++ b/playground/vitestSetup.ts @@ -13,7 +13,7 @@ import type { ViteDevServer } from 'vite' import { build, createServer, mergeConfig } from 'vite' -import type { Browser, ConsoleMessage, Page } from 'playwright-chromium' +import type { Browser, Page } from 'playwright-chromium' import type { RollupError, RollupWatcher, RollupWatcherEvent } from 'rollup' import type { File } from 'vitest' import { beforeAll } from 'vitest' diff --git a/playground/vue-lib/__tests__/serve.ts b/playground/vue-lib/__tests__/serve.ts index 47c122339205eb..70d30af178f50e 100644 --- a/playground/vue-lib/__tests__/serve.ts +++ b/playground/vue-lib/__tests__/serve.ts @@ -1,4 +1,4 @@ -// this is automatically detected by scripts/vitestSetup.ts and will replace +// this is automatically detected by playground/vitestSetup.ts and will replace // the default e2e test serve behavior export async function serve() { diff --git a/playground/worker/my-shared-worker.ts b/playground/worker/my-shared-worker.ts index caab5257394266..8d2099a7636459 100644 --- a/playground/worker/my-shared-worker.ts +++ b/playground/worker/my-shared-worker.ts @@ -1,6 +1,7 @@ let count = 0 const ports = new Set() +// @ts-expect-error onconnect = (event) => { const port = event.ports[0] ports.add(port) @@ -8,7 +9,7 @@ onconnect = (event) => { port.onmessage = (message) => { if (message.data === 'tick') { count++ - ports.forEach((p) => { + ports.forEach((p: any) => { p.postMessage(count) }) } @@ -17,3 +18,5 @@ onconnect = (event) => { // for sourcemap console.log('my-shared-worker.js') + +export {} diff --git a/playground/worker/my-worker.ts b/playground/worker/my-worker.ts index 553754f4901030..cfaaeeb4b788d3 100644 --- a/playground/worker/my-worker.ts +++ b/playground/worker/my-worker.ts @@ -1,4 +1,4 @@ -import { msg, mode } from './modules/workerImport' +import { mode, msg } from './modules/workerImport' import { bundleWithPlugin } from './modules/test-plugin' self.onmessage = (e) => { diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index bb673b6c8e21fb..92cbe98fb03740 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -1,13 +1,14 @@ { "$schema": "https://json.schemastore.org/tsconfig", + "include": ["."], "compilerOptions": { "module": "commonjs", - "moduleResolution": "node", "target": "es2019", + "moduleResolution": "node", "strict": true, "esModuleInterop": true, "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "types": ["node", "vitest/globals"] + "noUnusedLocals": true, + "forceConsistentCasingInFileNames": true } } diff --git a/vitest.config.e2e.ts b/vitest.config.e2e.ts index 241910ff7382c3..05388353994f61 100644 --- a/vitest.config.e2e.ts +++ b/vitest.config.e2e.ts @@ -9,8 +9,8 @@ export default defineConfig({ }, test: { include: ['./playground/**/*.spec.[tj]s'], - setupFiles: ['./scripts/vitestSetup.ts'], - globalSetup: ['./scripts/vitestGlobalSetup.ts'], + setupFiles: ['./playground/vitestSetup.ts'], + globalSetup: ['./playground/vitestGlobalSetup.ts'], testTimeout: process.env.CI ? 50000 : 20000, globals: true, reporters: 'dot', From 4c54800d6be6611399be01cf830ed0f743e47d11 Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 11 May 2022 18:37:29 +0800 Subject: [PATCH 109/114] fix(vue): same src file request same key (#8059) --- packages/plugin-vue/src/main.ts | 43 ++++++++++++++----- .../plugin-vue/src/utils/descriptorCache.ts | 21 ++++++--- packages/plugin-vue/src/utils/query.ts | 4 ++ playground/vue/src-import/css.module.css | 7 +++ playground/vue/src-import/script.ts | 6 ++- .../vue/src-import/srcImportModuleStyle.vue | 4 ++ .../vue/src-import/srcImportModuleStyle2.vue | 4 ++ playground/vue/src-import/template.html | 2 + 8 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 playground/vue/src-import/css.module.css create mode 100644 playground/vue/src-import/srcImportModuleStyle.vue create mode 100644 playground/vue/src-import/srcImportModuleStyle2.vue diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index 8fa01e494f58e2..6df6901a2bab40 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -227,6 +227,7 @@ async function genTemplateCode( ssr: boolean ) { const template = descriptor.template! + const hasScoped = descriptor.styles.some((style) => style.scoped) // If the template is not using pre-processor AND is not using external src, // compile and inline it directly in the main module. When served in vite this @@ -241,12 +242,22 @@ async function genTemplateCode( ) } else { if (template.src) { - await linkSrcToDescriptor(template.src, descriptor, pluginContext) + await linkSrcToDescriptor( + template.src, + descriptor, + pluginContext, + hasScoped + ) } const src = template.src || descriptor.filename - const srcQuery = template.src ? `&src=${descriptor.id}` : `` + const srcQuery = template.src + ? hasScoped + ? `&src=${descriptor.id}` + : '&src=true' + : '' + const scopedQuery = hasScoped ? `&scoped=true` : `` const attrsQuery = attrsToQuery(template.attrs, 'js', true) - const query = `?vue&type=template${srcQuery}${attrsQuery}` + const query = `?vue&type=template${srcQuery}${scopedQuery}${attrsQuery}` const request = JSON.stringify(src + query) const renderFnName = ssr ? 'ssrRender' : 'render' return { @@ -284,12 +295,12 @@ async function genScriptCode( map = script.map } else { if (script.src) { - await linkSrcToDescriptor(script.src, descriptor, pluginContext) + await linkSrcToDescriptor(script.src, descriptor, pluginContext, false) } const src = script.src || descriptor.filename const langFallback = (script.src && path.extname(src).slice(1)) || 'js' const attrsQuery = attrsToQuery(script.attrs, langFallback) - const srcQuery = script.src ? `&src=${descriptor.id}` : `` + const srcQuery = script.src ? `&src=true` : `` const query = `?vue&type=script${srcQuery}${attrsQuery}` const request = JSON.stringify(src + query) scriptCode = @@ -314,13 +325,22 @@ async function genStyleCode( for (let i = 0; i < descriptor.styles.length; i++) { const style = descriptor.styles[i] if (style.src) { - await linkSrcToDescriptor(style.src, descriptor, pluginContext) + await linkSrcToDescriptor( + style.src, + descriptor, + pluginContext, + style.scoped + ) } const src = style.src || descriptor.filename // do not include module in default query, since we use it to indicate // that the module needs to export the modules json const attrsQuery = attrsToQuery(style.attrs, 'css') - const srcQuery = style.src ? `&src=${descriptor.id}` : `` + const srcQuery = style.src + ? style.scoped + ? `&src=${descriptor.id}` + : '&src=true' + : '' const directQuery = asCustomElement ? `&inline` : `` const query = `?vue&type=style&index=${i}${srcQuery}${directQuery}` const styleRequest = src + query + attrsQuery @@ -390,11 +410,11 @@ async function genCustomBlockCode( for (let index = 0; index < descriptor.customBlocks.length; index++) { const block = descriptor.customBlocks[index] if (block.src) { - await linkSrcToDescriptor(block.src, descriptor, pluginContext) + await linkSrcToDescriptor(block.src, descriptor, pluginContext, false) } const src = block.src || descriptor.filename const attrsQuery = attrsToQuery(block.attrs, block.type) - const srcQuery = block.src ? `&src` : `` + const srcQuery = block.src ? `&src=true` : `` const query = `?vue&type=${block.type}&index=${index}${srcQuery}${attrsQuery}` const request = JSON.stringify(src + query) code += `import block${index} from ${request}\n` @@ -411,13 +431,14 @@ async function genCustomBlockCode( async function linkSrcToDescriptor( src: string, descriptor: SFCDescriptor, - pluginContext: PluginContext + pluginContext: PluginContext, + scoped?: boolean ) { const srcFile = (await pluginContext.resolve(src, descriptor.filename))?.id || src // #1812 if the src points to a dep file, the resolved id may contain a // version query. - setSrcDescriptor(srcFile.replace(/\?.*$/, ''), descriptor) + setSrcDescriptor(srcFile.replace(/\?.*$/, ''), descriptor, scoped) } // these are built-in query parameters so should be ignored diff --git a/packages/plugin-vue/src/utils/descriptorCache.ts b/packages/plugin-vue/src/utils/descriptorCache.ts index c0b77e72d3e613..5143a6131d5ddc 100644 --- a/packages/plugin-vue/src/utils/descriptorCache.ts +++ b/packages/plugin-vue/src/utils/descriptorCache.ts @@ -69,11 +69,22 @@ export function getSrcDescriptor( filename: string, query: VueQuery ): SFCDescriptor { - return cache.get(`${filename}?src=${query.src}`)! + if (query.scoped) { + return cache.get(`${filename}?src=${query.src}`)! + } + return cache.get(filename)! } -export function setSrcDescriptor(filename: string, entry: SFCDescriptor): void { - // if multiple Vue files use the same src file, they will be overwritten - // should use other key - cache.set(`${filename}?src=${entry.id}`, entry) +export function setSrcDescriptor( + filename: string, + entry: SFCDescriptor, + scoped?: boolean +): void { + if (scoped) { + // if multiple Vue files use the same src file, they will be overwritten + // should use other key + cache.set(`${filename}?src=${entry.id}`, entry) + return + } + cache.set(filename, entry) } diff --git a/packages/plugin-vue/src/utils/query.ts b/packages/plugin-vue/src/utils/query.ts index 060b5f28987bfa..f579067e52f8d8 100644 --- a/packages/plugin-vue/src/utils/query.ts +++ b/packages/plugin-vue/src/utils/query.ts @@ -5,6 +5,7 @@ export interface VueQuery { index?: number lang?: string raw?: boolean + scoped?: boolean } export function parseVueRequest(id: string): { @@ -22,6 +23,9 @@ export function parseVueRequest(id: string): { if (query.raw != null) { query.raw = true } + if (query.scoped != null) { + query.scoped = true + } return { filename, query diff --git a/playground/vue/src-import/css.module.css b/playground/vue/src-import/css.module.css new file mode 100644 index 00000000000000..09b5c09fb637e2 --- /dev/null +++ b/playground/vue/src-import/css.module.css @@ -0,0 +1,7 @@ +.one { + background: yellow; +} + +.two { + border: solid 1px red; +} diff --git a/playground/vue/src-import/script.ts b/playground/vue/src-import/script.ts index 54e6e35db41f46..d20c098a7af289 100644 --- a/playground/vue/src-import/script.ts +++ b/playground/vue/src-import/script.ts @@ -1,11 +1,15 @@ import { defineComponent } from 'vue' import SrcImportStyle from './srcImportStyle.vue' import SrcImportStyle2 from './srcImportStyle2.vue' +import SrcImportModuleStyle from './srcImportModuleStyle.vue' +import SrcImportModuleStyle2 from './srcImportModuleStyle2.vue' export default defineComponent({ components: { SrcImportStyle, - SrcImportStyle2 + SrcImportStyle2, + SrcImportModuleStyle, + SrcImportModuleStyle2 }, setup() { return { diff --git a/playground/vue/src-import/srcImportModuleStyle.vue b/playground/vue/src-import/srcImportModuleStyle.vue new file mode 100644 index 00000000000000..f1e85abb6d2b12 --- /dev/null +++ b/playground/vue/src-import/srcImportModuleStyle.vue @@ -0,0 +1,4 @@ + +