From 9acb8391574350389e60b6639db29e042dfc9a67 Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 25 Sep 2022 20:39:09 +0800 Subject: [PATCH 01/10] docs: fix invalid jsdoc comments (#10241) --- packages/vite/src/node/config.ts | 4 ++-- packages/vite/src/node/plugin.ts | 2 +- packages/vite/src/node/plugins/importAnalysis.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index 806f0f8275de4f..09c6e00adf9d6e 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -126,7 +126,7 @@ export interface UserConfig { /** * Directory to serve as plain static assets. Files in this directory are * served and copied to build dist dir as-is without transform. The value - * can be either an absolute file system path or a path relative to . + * can be either an absolute file system path or a path relative to project root. * * Set to `false` or an empty string to disable copied static assets to build dist dir. * @default 'public' @@ -137,7 +137,7 @@ export interface UserConfig { * deps or some other cache files that generated by vite, which can improve * the performance. You can use `--force` flag or manually delete the directory * to regenerate the cache files. The value can be either an absolute file - * system path or a path relative to . + * system path or a path relative to project root. * Default to `.vite` when no `package.json` is detected. * @default 'node_modules/.vite' */ diff --git a/packages/vite/src/node/plugin.ts b/packages/vite/src/node/plugin.ts index 8cc78df892d7df..b01cf6bda13be8 100644 --- a/packages/vite/src/node/plugin.ts +++ b/packages/vite/src/node/plugin.ts @@ -108,7 +108,7 @@ export interface Plugin extends RollupPlugin { * - bundle?: rollup.OutputBundle (only present during build) * * It can either return a transformed string, or a list of html tag - * descriptors that will be injected into the or . + * descriptors that will be injected into the `` or ``. * * By default the transform is applied **after** vite's internal html * transform. If you need to apply the transform before vite, use an object: diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 86bad0b75ac001..9656ed25aeae0f 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -147,7 +147,7 @@ function extractImportedBindings( * ``` * * - CSS imports are appended with `.js` since both the js module and the actual - * css (referenced via ) may go through the transform pipeline: + * css (referenced via ``) may go through the transform pipeline: * * ```js * import './style.css' From e4c1c6d506069e55eedfb81f8c607ffb3e74bda0 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sun, 25 Sep 2022 21:46:49 +0800 Subject: [PATCH 02/10] fix(css): missing css in lib mode (#10185) --- packages/vite/src/node/plugins/css.ts | 2 +- playground/vue-lib/__tests__/vue-lib.spec.ts | 11 +++++++++++ playground/vue-lib/package.json | 1 + playground/vue-lib/src-lib-css/index.css | 3 +++ playground/vue-lib/src-lib-css/index.ts | 3 +++ playground/vue-lib/vite.config.lib-css.ts | 16 ++++++++++++++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 playground/vue-lib/src-lib-css/index.css create mode 100644 playground/vue-lib/src-lib-css/index.ts create mode 100644 playground/vue-lib/vite.config.lib-css.ts diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index bcc5359d17ca93..1f26f80d1e6d74 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -563,7 +563,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // the legacy build should avoid inserting entry CSS modules here, they // will be collected into `chunk.viteMetadata.importedCss` and injected // later by the `'vite:build-html'` plugin into the `index.html` - if (chunk.isEntry) { + if (chunk.isEntry && !config.build.lib) { return null } chunkCSS = await finalizeCss(chunkCSS, true, config) diff --git a/playground/vue-lib/__tests__/vue-lib.spec.ts b/playground/vue-lib/__tests__/vue-lib.spec.ts index 64f318656ca10e..50b554d63f9f76 100644 --- a/playground/vue-lib/__tests__/vue-lib.spec.ts +++ b/playground/vue-lib/__tests__/vue-lib.spec.ts @@ -22,4 +22,15 @@ describe('vue component library', () => { expect(code).toContain('styleA') // styleA is used by CompA expect(code).not.toContain('styleB') // styleB is not used }) + + test('should inject css when cssCodeSplit = true', async () => { + // Build lib + const { output } = ( + await build({ + logLevel: 'silent', + configFile: path.resolve(__dirname, '../vite.config.lib-css.ts') + }) + )[0] + expect(output[0].code).toContain('.card{padding:4rem}') + }) }) diff --git a/playground/vue-lib/package.json b/playground/vue-lib/package.json index d59f3d626160d4..d28ab18295c799 100644 --- a/playground/vue-lib/package.json +++ b/playground/vue-lib/package.json @@ -5,6 +5,7 @@ "scripts": { "dev-consumer": "vite --config ./vite.config.consumer.ts", "build-lib": "vite build --config ./vite.config.lib.ts", + "build-lib-css": "vite build --config ./vite.config.lib-css.ts", "build-consumer": "vite build --config ./vite.config.consumer.ts" }, "dependencies": { diff --git a/playground/vue-lib/src-lib-css/index.css b/playground/vue-lib/src-lib-css/index.css new file mode 100644 index 00000000000000..135f4787b30766 --- /dev/null +++ b/playground/vue-lib/src-lib-css/index.css @@ -0,0 +1,3 @@ +.card { + padding: 4rem; +} diff --git a/playground/vue-lib/src-lib-css/index.ts b/playground/vue-lib/src-lib-css/index.ts new file mode 100644 index 00000000000000..0da52ebb0b6115 --- /dev/null +++ b/playground/vue-lib/src-lib-css/index.ts @@ -0,0 +1,3 @@ +import './index.css' + +export function setup() {} diff --git a/playground/vue-lib/vite.config.lib-css.ts b/playground/vue-lib/vite.config.lib-css.ts new file mode 100644 index 00000000000000..e20ec925e05b0e --- /dev/null +++ b/playground/vue-lib/vite.config.lib-css.ts @@ -0,0 +1,16 @@ +import path from 'node:path' +import { defineConfig } from 'vite' + +export default defineConfig({ + root: __dirname, + build: { + outDir: 'dist/lib', + cssCodeSplit: true, + lib: { + entry: path.resolve(__dirname, 'src-lib-css/index.ts'), + name: 'index', + formats: ['umd'], + fileName: 'index.js' + } + } +}) From fb6d8cb8233d813a612a98f174db454237598c66 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Mon, 26 Sep 2022 15:15:45 +0800 Subject: [PATCH 03/10] test: skip favicon log in debug serve (#10248) --- playground/vitestSetup.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/playground/vitestSetup.ts b/playground/vitestSetup.ts index 9cfcbed855e6dd..cf476a87100c20 100644 --- a/playground/vitestSetup.ts +++ b/playground/vitestSetup.ts @@ -122,6 +122,14 @@ beforeAll(async (s) => { try { page.on('console', (msg) => { + // ignore favicon request in headed browser + if ( + process.env.VITE_DEBUG_SERVE && + msg.text().includes('Failed to load resource:') && + msg.location().url.includes('favicon.ico') + ) { + return + } browserLogs.push(msg.text()) }) page.on('pageerror', (error) => { From ed40a65772f660c1252d56d578adeb6ae3daf326 Mon Sep 17 00:00:00 2001 From: yoho Date: Mon, 26 Sep 2022 17:56:08 +0800 Subject: [PATCH 04/10] chore: update type init (#10251) --- packages/vite/src/node/plugins/importAnalysis.ts | 4 ++-- packages/vite/src/node/plugins/importAnalysisBuild.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 9656ed25aeae0f..3559a8d5fdbc34 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -187,8 +187,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { const start = performance.now() await init - let imports: readonly ImportSpecifier[] = [] - let exports: readonly ExportSpecifier[] = [] + let imports!: readonly ImportSpecifier[] + let exports!: readonly ExportSpecifier[] source = stripBomTag(source) try { ;[imports, exports] = parseImports(source) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 689cd0646cac6b..849b71c4cdcd64 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -439,7 +439,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { // dynamic import to constant json may get inlined. if (chunk.type === 'chunk' && chunk.code.indexOf(preloadMarker) > -1) { const code = chunk.code - let imports: ImportSpecifier[] = [] + let imports!: ImportSpecifier[] try { imports = parseImports(code)[0].filter((i) => i.d > -1) } catch (e: any) { From 1bac86ab33f10531f8103f547780e915cdbf7c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Mon, 26 Sep 2022 19:30:18 +0900 Subject: [PATCH 05/10] refactor(vue-jsx): remove `@babel/plugin-syntax-import-meta` (#10233) --- packages/plugin-vue-jsx/package.json | 1 - packages/plugin-vue-jsx/src/index.ts | 4 +--- pnpm-lock.yaml | 16 ---------------- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 7c61ff0fab5a27..68567ec2abb5bc 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -36,7 +36,6 @@ "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-vue-jsx#readme", "dependencies": { "@babel/core": "^7.19.1", - "@babel/plugin-syntax-import-meta": "^7.10.4", "@babel/plugin-transform-typescript": "^7.19.1", "@vue/babel-plugin-jsx": "^1.1.1" }, diff --git a/packages/plugin-vue-jsx/src/index.ts b/packages/plugin-vue-jsx/src/index.ts index e5454980ed4d8e..cb2888728a45b5 100644 --- a/packages/plugin-vue-jsx/src/index.ts +++ b/packages/plugin-vue-jsx/src/index.ts @@ -3,8 +3,6 @@ import path from 'node:path' import type { types } from '@babel/core' import * as babel from '@babel/core' import jsx from '@vue/babel-plugin-jsx' -// @ts-expect-error missing type -import importMeta from '@babel/plugin-syntax-import-meta' import { createFilter, normalizePath } from 'vite' import type { ComponentOptions } from 'vue' import type { Plugin } from 'vite' @@ -83,7 +81,7 @@ function vueJsxPlugin(options: Options = {}): Plugin { // use id for script blocks in Vue SFCs (e.g. `App.vue?vue&type=script&lang.jsx`) // use filepath for plain jsx files (e.g. App.jsx) if (filter(id) || filter(filepath)) { - const plugins = [importMeta, [jsx, babelPluginOptions], ...babelPlugins] + const plugins = [[jsx, babelPluginOptions], ...babelPlugins] if (id.endsWith('.tsx') || filepath.endsWith('.tsx')) { plugins.push([ // @ts-ignore missing type diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3eeeda1cd37e39..1b568ad3bf898b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -199,13 +199,11 @@ importers: packages/plugin-vue-jsx: specifiers: '@babel/core': ^7.19.1 - '@babel/plugin-syntax-import-meta': ^7.10.4 '@babel/plugin-transform-typescript': ^7.19.1 '@vue/babel-plugin-jsx': ^1.1.1 vite: workspace:* dependencies: '@babel/core': 7.19.1 - '@babel/plugin-syntax-import-meta': 7.10.4_@babel+core@7.19.1 '@babel/plugin-transform-typescript': 7.19.1_@babel+core@7.19.1 '@vue/babel-plugin-jsx': 1.1.1_@babel+core@7.19.1 devDependencies: @@ -1526,11 +1524,6 @@ packages: '@babel/types': 7.19.0 dev: false - /@babel/helper-plugin-utils/7.16.7: - resolution: {integrity: sha512-Qg3Nk7ZxpgMrsox6HreY1ZNKdBq7K72tDSliA6dCl5f007jR4ne8iD5UzuNnCJH2xBf2BEEVGr+/OL6Gdp7RxA==} - engines: {node: '>=6.9.0'} - dev: false - /@babel/helper-plugin-utils/7.18.6: resolution: {integrity: sha512-gvZnm1YAAxh13eJdkb9EWHBnF3eAub3XTLCZEehHT2kWxiKVRL64+ae5Y6Ivne0mVHmMYKT+xWgZO+gQhuLUBg==} engines: {node: '>=6.9.0'} @@ -1617,15 +1610,6 @@ packages: '@babel/plugin-syntax-pipeline-operator': 7.18.6 dev: true - /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.19.1: - resolution: {integrity: sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==} - peerDependencies: - '@babel/core': ^7.0.0-0 - dependencies: - '@babel/core': 7.19.1 - '@babel/helper-plugin-utils': 7.16.7 - dev: false - /@babel/plugin-syntax-jsx/7.16.7_@babel+core@7.19.1: resolution: {integrity: sha512-Esxmk7YjA8QysKeT3VhTXvF6y77f/a91SIs4pWb4H2eWGQkCKFgQaG6hdoEVZtGsrAcb2K5BW66XsOErD4WU3Q==} engines: {node: '>=6.9.0'} From 81d4d04c37b805843ea83075d1c0819c31726c4e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 16:25:12 +0200 Subject: [PATCH 06/10] fix(deps): update all non-major dependencies (#10246) --- package.json | 4 +- packages/plugin-legacy/package.json | 2 +- pnpm-lock.yaml | 96 ++++++++++++++--------------- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/package.json b/package.json index f951c5b3a72a3d..7fea462b78be4c 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "@typescript-eslint/parser": "^5.38.0", "conventional-changelog-cli": "^2.2.2", "esbuild": "^0.14.47", - "eslint": "^8.23.1", + "eslint": "^8.24.0", "eslint-define-config": "^1.7.0", "eslint-plugin-import": "^2.26.0", "eslint-plugin-node": "^11.1.0", @@ -88,7 +88,7 @@ "typescript": "^4.6.4", "unbuild": "^0.8.11", "vite": "workspace:*", - "vitepress": "^1.0.0-alpha.15", + "vitepress": "^1.0.0-alpha.16", "vitest": "^0.23.4", "vue": "^3.2.39" }, diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index 5e6ffa9074d38e..0d307c520e37a5 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -36,7 +36,7 @@ "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme", "dependencies": { "@babel/standalone": "^7.19.2", - "core-js": "^3.25.2", + "core-js": "^3.25.3", "magic-string": "^0.26.4", "regenerator-runtime": "^0.13.9", "systemjs": "^6.12.6" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1b568ad3bf898b..ab25134fb26652 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,7 +36,7 @@ importers: '@typescript-eslint/parser': ^5.38.0 conventional-changelog-cli: ^2.2.2 esbuild: ^0.14.47 - eslint: ^8.23.1 + eslint: ^8.24.0 eslint-define-config: ^1.7.0 eslint-plugin-import: ^2.26.0 eslint-plugin-node: ^11.1.0 @@ -62,7 +62,7 @@ importers: typescript: ^4.6.4 unbuild: ^0.8.11 vite: workspace:* - vitepress: ^1.0.0-alpha.15 + vitepress: ^1.0.0-alpha.16 vitest: ^0.23.4 vue: ^3.2.39 devDependencies: @@ -88,14 +88,14 @@ importers: '@types/semver': 7.3.12 '@types/stylus': 0.48.38 '@types/ws': 8.5.3 - '@typescript-eslint/eslint-plugin': 5.38.0_2x3pnxumot2lspjryjtmmusp2e - '@typescript-eslint/parser': 5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje + '@typescript-eslint/eslint-plugin': 5.38.0_rwai6flfqy4pzaqznlsnhxvs6q + '@typescript-eslint/parser': 5.38.0_4at4lsfnhb3djm6qjts2gmiglm conventional-changelog-cli: 2.2.2 esbuild: 0.14.47 - eslint: 8.23.1 + eslint: 8.24.0 eslint-define-config: 1.7.0 - eslint-plugin-import: 2.26.0_cxqatnnjiq7ozd2bkspxnuicdq - eslint-plugin-node: 11.1.0_eslint@8.23.1 + eslint-plugin-import: 2.26.0_2azyxy5wfmd73v3pbt5rvmgcsm + eslint-plugin-node: 11.1.0_eslint@8.24.0 execa: 6.1.0 fast-glob: 3.2.12 fs-extra: 10.1.0 @@ -118,7 +118,7 @@ importers: typescript: 4.6.4 unbuild: 0.8.11 vite: link:packages/vite - vitepress: 1.0.0-alpha.15 + vitepress: 1.0.0-alpha.16 vitest: 0.23.4 vue: 3.2.39 @@ -138,7 +138,7 @@ importers: specifiers: '@babel/core': ^7.19.1 '@babel/standalone': ^7.19.2 - core-js: ^3.25.2 + core-js: ^3.25.3 magic-string: ^0.26.4 picocolors: ^1.0.0 regenerator-runtime: ^0.13.9 @@ -146,7 +146,7 @@ importers: vite: workspace:* dependencies: '@babel/standalone': 7.19.2 - core-js: 3.25.2 + core-js: 3.25.3 magic-string: 0.26.4 regenerator-runtime: 0.13.9 systemjs: 6.12.6 @@ -1975,8 +1975,8 @@ packages: - supports-color dev: true - /@humanwhocodes/config-array/0.10.4: - resolution: {integrity: sha512-mXAIHxZT3Vcpg83opl1wGlVZ9xydbfZO3r5YfRSH6Gpp2J/PfdBP0wbDa2sO6/qRbcalpoevVyW6A/fI6LfeMw==} + /@humanwhocodes/config-array/0.10.5: + resolution: {integrity: sha512-XVVDtp+dVvRxMoxSiSfasYaG02VEe1qH5cKgMQJWhol6HwzbcqoCMJi8dAGoYAO57jhUyhI6cWuRiTcRaDaYug==} engines: {node: '>=10.10.0'} dependencies: '@humanwhocodes/object-schema': 1.2.1 @@ -2599,7 +2599,7 @@ packages: '@types/node': 17.0.42 dev: true - /@typescript-eslint/eslint-plugin/5.38.0_2x3pnxumot2lspjryjtmmusp2e: + /@typescript-eslint/eslint-plugin/5.38.0_rwai6flfqy4pzaqznlsnhxvs6q: resolution: {integrity: sha512-GgHi/GNuUbTOeoJiEANi0oI6fF3gBQc3bGFYj40nnAPCbhrtEDf2rjBmefFadweBmO1Du1YovHeDP2h5JLhtTQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -2610,12 +2610,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje + '@typescript-eslint/parser': 5.38.0_4at4lsfnhb3djm6qjts2gmiglm '@typescript-eslint/scope-manager': 5.38.0 - '@typescript-eslint/type-utils': 5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje - '@typescript-eslint/utils': 5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje + '@typescript-eslint/type-utils': 5.38.0_4at4lsfnhb3djm6qjts2gmiglm + '@typescript-eslint/utils': 5.38.0_4at4lsfnhb3djm6qjts2gmiglm debug: 4.3.4 - eslint: 8.23.1 + eslint: 8.24.0 ignore: 5.2.0 regexpp: 3.2.0 semver: 7.3.7 @@ -2625,7 +2625,7 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje: + /@typescript-eslint/parser/5.38.0_4at4lsfnhb3djm6qjts2gmiglm: resolution: {integrity: sha512-/F63giJGLDr0ms1Cr8utDAxP2SPiglaD6V+pCOcG35P2jCqdfR7uuEhz1GIC3oy4hkUF8xA1XSXmd9hOh/a5EA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -2639,7 +2639,7 @@ packages: '@typescript-eslint/types': 5.38.0 '@typescript-eslint/typescript-estree': 5.38.0_typescript@4.6.4 debug: 4.3.4 - eslint: 8.23.1 + eslint: 8.24.0 typescript: 4.6.4 transitivePeerDependencies: - supports-color @@ -2653,7 +2653,7 @@ packages: '@typescript-eslint/visitor-keys': 5.38.0 dev: true - /@typescript-eslint/type-utils/5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje: + /@typescript-eslint/type-utils/5.38.0_4at4lsfnhb3djm6qjts2gmiglm: resolution: {integrity: sha512-iZq5USgybUcj/lfnbuelJ0j3K9dbs1I3RICAJY9NZZpDgBYXmuUlYQGzftpQA9wC8cKgtS6DASTvF3HrXwwozA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -2664,9 +2664,9 @@ packages: optional: true dependencies: '@typescript-eslint/typescript-estree': 5.38.0_typescript@4.6.4 - '@typescript-eslint/utils': 5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje + '@typescript-eslint/utils': 5.38.0_4at4lsfnhb3djm6qjts2gmiglm debug: 4.3.4 - eslint: 8.23.1 + eslint: 8.24.0 tsutils: 3.21.0_typescript@4.6.4 typescript: 4.6.4 transitivePeerDependencies: @@ -2699,7 +2699,7 @@ packages: - supports-color dev: true - /@typescript-eslint/utils/5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje: + /@typescript-eslint/utils/5.38.0_4at4lsfnhb3djm6qjts2gmiglm: resolution: {integrity: sha512-6sdeYaBgk9Fh7N2unEXGz+D+som2QCQGPAf1SxrkEr+Z32gMreQ0rparXTNGRRfYUWk/JzbGdcM8NSSd6oqnTA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -2709,9 +2709,9 @@ packages: '@typescript-eslint/scope-manager': 5.38.0 '@typescript-eslint/types': 5.38.0 '@typescript-eslint/typescript-estree': 5.38.0_typescript@4.6.4 - eslint: 8.23.1 + eslint: 8.24.0 eslint-scope: 5.1.1 - eslint-utils: 3.0.0_eslint@8.23.1 + eslint-utils: 3.0.0_eslint@8.24.0 transitivePeerDependencies: - supports-color - typescript @@ -3748,8 +3748,8 @@ packages: is-what: 3.14.1 dev: true - /core-js/3.25.2: - resolution: {integrity: sha512-YB4IAT1bjEfxTJ1XYy11hJAKskO+qmhuDBM8/guIfMz4JvdsAQAqvyb97zXX7JgSrfPLG5mRGFWJwJD39ruq2A==} + /core-js/3.25.3: + resolution: {integrity: sha512-y1hvKXmPHvm5B7w4ln1S4uc9eV/O5+iFExSRUimnvIph11uaizFR8LFMdONN8hG3P2pipUfX4Y/fR8rAEtcHcQ==} requiresBuild: true dev: false @@ -4805,7 +4805,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje + '@typescript-eslint/parser': 5.38.0_4at4lsfnhb3djm6qjts2gmiglm debug: 3.2.7 eslint-import-resolver-node: 0.3.6 find-up: 2.1.0 @@ -4813,18 +4813,18 @@ packages: - supports-color dev: true - /eslint-plugin-es/3.0.1_eslint@8.23.1: + /eslint-plugin-es/3.0.1_eslint@8.24.0: resolution: {integrity: sha512-GUmAsJaN4Fc7Gbtl8uOBlayo2DqhwWvEzykMHSCZHU3XdJ+NSzzZcVhXh3VxX5icqQ+oQdIEawXX8xkR3mIFmQ==} engines: {node: '>=8.10.0'} peerDependencies: eslint: '>=4.19.1' dependencies: - eslint: 8.23.1 + eslint: 8.24.0 eslint-utils: 2.1.0 regexpp: 3.2.0 dev: true - /eslint-plugin-import/2.26.0_cxqatnnjiq7ozd2bkspxnuicdq: + /eslint-plugin-import/2.26.0_2azyxy5wfmd73v3pbt5rvmgcsm: resolution: {integrity: sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==} engines: {node: '>=4'} peerDependencies: @@ -4834,12 +4834,12 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 5.38.0_3pgpbtxx6aaanl2g7t7xjqhlje + '@typescript-eslint/parser': 5.38.0_4at4lsfnhb3djm6qjts2gmiglm array-includes: 3.1.5 array.prototype.flat: 1.3.0 debug: 2.6.9 doctrine: 2.1.0 - eslint: 8.23.1 + eslint: 8.24.0 eslint-import-resolver-node: 0.3.6 eslint-module-utils: 2.7.3_wksnzkbqgr3q3djac7fn35kbeq has: 1.0.3 @@ -4855,14 +4855,14 @@ packages: - supports-color dev: true - /eslint-plugin-node/11.1.0_eslint@8.23.1: + /eslint-plugin-node/11.1.0_eslint@8.24.0: resolution: {integrity: sha512-oUwtPJ1W0SKD0Tr+wqu92c5xuCeQqB3hSCHasn/ZgjFdA9iDGNkNf2Zi9ztY7X+hNuMib23LNGRm6+uN+KLE3g==} engines: {node: '>=8.10.0'} peerDependencies: eslint: '>=5.16.0' dependencies: - eslint: 8.23.1 - eslint-plugin-es: 3.0.1_eslint@8.23.1 + eslint: 8.24.0 + eslint-plugin-es: 3.0.1_eslint@8.24.0 eslint-utils: 2.1.0 ignore: 5.2.0 minimatch: 3.1.2 @@ -4893,13 +4893,13 @@ packages: eslint-visitor-keys: 1.3.0 dev: true - /eslint-utils/3.0.0_eslint@8.23.1: + /eslint-utils/3.0.0_eslint@8.24.0: resolution: {integrity: sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==} engines: {node: ^10.0.0 || ^12.0.0 || >= 14.0.0} peerDependencies: eslint: '>=5' dependencies: - eslint: 8.23.1 + eslint: 8.24.0 eslint-visitor-keys: 2.1.0 dev: true @@ -4918,13 +4918,13 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /eslint/8.23.1: - resolution: {integrity: sha512-w7C1IXCc6fNqjpuYd0yPlcTKKmHlHHktRkzmBPZ+7cvNBQuiNjx0xaMTjAJGCafJhQkrFJooREv0CtrVzmHwqg==} + /eslint/8.24.0: + resolution: {integrity: sha512-dWFaPhGhTAiPcCgm3f6LI2MBWbogMnTJzFBbhXVRQDJPkr9pGZvVjlVfXd+vyDcWPA2Ic9L2AXPIQM0+vk/cSQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} hasBin: true dependencies: '@eslint/eslintrc': 1.3.2 - '@humanwhocodes/config-array': 0.10.4 + '@humanwhocodes/config-array': 0.10.5 '@humanwhocodes/gitignore-to-minimatch': 1.0.2 '@humanwhocodes/module-importer': 1.0.1 ajv: 6.12.6 @@ -4934,7 +4934,7 @@ packages: doctrine: 3.0.0 escape-string-regexp: 4.0.0 eslint-scope: 7.1.1 - eslint-utils: 3.0.0_eslint@8.23.1 + eslint-utils: 3.0.0_eslint@8.24.0 eslint-visitor-keys: 3.3.0 espree: 9.4.0 esquery: 1.4.0 @@ -5171,7 +5171,7 @@ packages: resolution: {integrity: sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==} /find-up/2.1.0: - resolution: {integrity: sha1-RdG35QbHF93UgndaK3eSCjwMV6c=} + resolution: {integrity: sha512-NWzkk0jSJtTt08+FBFMvXoeZnOJD+jTtsRmBYbAIzJdX6l7dLgR7CTubCM5/eDdPUBvLCeVasP1brfVR/9/EZQ==} engines: {node: '>=4'} dependencies: locate-path: 2.0.0 @@ -6161,7 +6161,7 @@ packages: dev: true /locate-path/2.0.0: - resolution: {integrity: sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=} + resolution: {integrity: sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==} engines: {node: '>=4'} dependencies: p-locate: 2.0.0 @@ -6817,7 +6817,7 @@ packages: dev: true /p-locate/2.0.0: - resolution: {integrity: sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=} + resolution: {integrity: sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==} engines: {node: '>=4'} dependencies: p-limit: 1.3.0 @@ -6904,7 +6904,7 @@ packages: dev: true /path-exists/3.0.0: - resolution: {integrity: sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=} + resolution: {integrity: sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==} engines: {node: '>=4'} dev: true @@ -8717,8 +8717,8 @@ packages: engines: {node: '>= 0.8'} dev: true - /vitepress/1.0.0-alpha.15: - resolution: {integrity: sha512-+pHJQCpnv0wVgLRyonisrj7Y77PVhbns2nTLxV9GkH3T+RTY/W2JmRatzBg5WciMaPyO8Ms6F3YElO5PULVv3w==} + /vitepress/1.0.0-alpha.16: + resolution: {integrity: sha512-IXW3jA2Y9BsoYlpVuVcAy2XEu1wuoq2xmPvSDPVFrh8HV+oVpuvbPUCHqG6smEcu86xw3g4JjreqAwPlpPn6gw==} hasBin: true dependencies: '@docsearch/css': 3.2.1 From 78f74c99d2edcdb26c692d5741790942902c5bea Mon Sep 17 00:00:00 2001 From: yoho Date: Wed, 28 Sep 2022 20:56:00 +0800 Subject: [PATCH 07/10] fix: isFromTsImporter flag in worker virtual model (#10273) --- packages/vite/src/node/plugins/resolve.ts | 8 ++++++-- packages/vite/src/node/plugins/worker.ts | 8 ++++++++ playground/worker/__tests__/es/es-worker.spec.ts | 2 +- .../worker/modules/{workerImport.js => workerImport.ts} | 0 playground/worker/my-worker.ts | 2 +- playground/worker/url-shared-worker.js | 2 +- playground/worker/worker/main-module.js | 4 ++-- 7 files changed, 19 insertions(+), 7 deletions(-) rename playground/worker/modules/{workerImport.js => workerImport.ts} (100%) diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index b44bdb337b2525..b9476e501ff447 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -44,6 +44,7 @@ import type { DepsOptimizer } from '../optimizer' import type { SSROptions } from '..' import type { PackageCache, PackageData } from '../packages' import { loadPackageData, resolvePackageData } from '../packages' +import { isWorkerRequest } from './worker' const normalizedClientEntry = normalizePath(CLIENT_ENTRY) const normalizedEnvEntry = normalizePath(ENV_ENTRY) @@ -144,13 +145,16 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin { } if (importer) { + const _importer = isWorkerRequest(importer) + ? splitFileAndPostfix(importer).file + : importer if ( - isTsRequest(importer) || + isTsRequest(_importer) || resolveOpts.custom?.depScan?.loader?.startsWith('ts') ) { options.isFromTsImporter = true } else { - const moduleLang = this.getModuleInfo(importer)?.meta?.vite?.lang + const moduleLang = this.getModuleInfo(_importer)?.meta?.vite?.lang options.isFromTsImporter = moduleLang && isTsRequest(`.${moduleLang}`) } } diff --git a/packages/vite/src/node/plugins/worker.ts b/packages/vite/src/node/plugins/worker.ts index 0113f7b01ad13a..b645d178f6f645 100644 --- a/packages/vite/src/node/plugins/worker.ts +++ b/packages/vite/src/node/plugins/worker.ts @@ -32,6 +32,14 @@ export type WorkerType = 'classic' | 'module' | 'ignore' export const WORKER_FILE_ID = 'worker_file' const workerCache = new WeakMap() +export function isWorkerRequest(id: string): boolean { + const query = parseRequest(id) + if (query && query[WORKER_FILE_ID] != null) { + return true + } + return false +} + function saveEmitWorkerAsset( config: ResolvedConfig, asset: EmittedAsset diff --git a/playground/worker/__tests__/es/es-worker.spec.ts b/playground/worker/__tests__/es/es-worker.spec.ts index eb8b9f650c236f..b3c49375cc1e47 100644 --- a/playground/worker/__tests__/es/es-worker.spec.ts +++ b/playground/worker/__tests__/es/es-worker.spec.ts @@ -57,7 +57,7 @@ describe.runIf(isBuild)('build', () => { test('inlined code generation', async () => { const assetsDir = path.resolve(testDir, 'dist/es/assets') const files = fs.readdirSync(assetsDir) - expect(files.length).toBe(28) + expect(files.length).toBe(27) const index = files.find((f) => f.includes('main-module')) const content = fs.readFileSync(path.resolve(assetsDir, index), 'utf-8') const worker = files.find((f) => f.includes('my-worker')) diff --git a/playground/worker/modules/workerImport.js b/playground/worker/modules/workerImport.ts similarity index 100% rename from playground/worker/modules/workerImport.js rename to playground/worker/modules/workerImport.ts diff --git a/playground/worker/my-worker.ts b/playground/worker/my-worker.ts index f31f081e64d15a..c2da7ffad3fd26 100644 --- a/playground/worker/my-worker.ts +++ b/playground/worker/my-worker.ts @@ -1,5 +1,5 @@ import { msg as msgFromDep } from 'dep-to-optimize' -import { mode, msg } from './modules/workerImport' +import { mode, msg } from './modules/workerImport.js' import { bundleWithPlugin } from './modules/test-plugin' import viteSvg from './vite.svg' diff --git a/playground/worker/url-shared-worker.js b/playground/worker/url-shared-worker.js index 9ef32c58f6c64b..6dc55b4ccaee2d 100644 --- a/playground/worker/url-shared-worker.js +++ b/playground/worker/url-shared-worker.js @@ -1,4 +1,4 @@ -import constant from './modules/module0' +import constant from './modules/module0.js' self.onconnect = (event) => { const port = event.ports[0] diff --git a/playground/worker/worker/main-module.js b/playground/worker/worker/main-module.js index adf1bea60b1a6b..21c1dcadb853a9 100644 --- a/playground/worker/worker/main-module.js +++ b/playground/worker/worker/main-module.js @@ -1,5 +1,5 @@ -import myWorker from '../my-worker?worker' -import InlineWorker from '../my-worker?worker&inline' +import myWorker from '../my-worker.ts?worker' +import InlineWorker from '../my-worker.ts?worker&inline' import mySharedWorker from '../my-shared-worker?sharedworker&name=shared' import TSOutputWorker from '../possible-ts-output-worker?worker' import NestedWorker from '../worker-nested-worker?worker' From fe4dc8d3fae2eb6344b9b48794d01ad25c46a321 Mon Sep 17 00:00:00 2001 From: Manu MA Date: Wed, 28 Sep 2022 17:29:28 +0200 Subject: [PATCH 08/10] feat: customize ErrorOverlay (#10234) --- packages/vite/src/client/overlay.ts | 42 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/vite/src/client/overlay.ts b/packages/vite/src/client/overlay.ts index e094f5664a5bb6..562b87432a17f8 100644 --- a/packages/vite/src/client/overlay.ts +++ b/packages/vite/src/client/overlay.ts @@ -9,6 +9,17 @@ const template = /*html*/ ` left: 0; width: 100%; height: 100%; + + --monospace: 'SFMono-Regular', Consolas, + 'Liberation Mono', Menlo, Courier, monospace; + --red: #ff5555; + --yellow: #e2aa53; + --purple: #cfa4ff; + --cyan: #2dd9da; + --dim: #c9c9c9; + + --window-background: #181818; + --window-color: #d8d8d8; } .backdrop { @@ -21,24 +32,17 @@ const template = /*html*/ ` overflow-y: scroll; margin: 0; background: rgba(0, 0, 0, 0.66); - --monospace: 'SFMono-Regular', Consolas, - 'Liberation Mono', Menlo, Courier, monospace; - --red: #ff5555; - --yellow: #e2aa53; - --purple: #cfa4ff; - --cyan: #2dd9da; - --dim: #c9c9c9; } .window { font-family: var(--monospace); line-height: 1.5; width: 800px; - color: #d8d8d8; + color: var(--window-color); margin: 30px auto; padding: 25px 40px; position: relative; - background: #181818; + background: var(--window-background); border-radius: 6px 6px 8px 8px; box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22); overflow: hidden; @@ -108,13 +112,13 @@ code { cursor: pointer; } -
-
-
-

-    

-    

-    
+
+
+
+

+    

+    

+    
Click outside or fix the code to dismiss.
You can also disable this overlay by setting server.hmr.overlay to false in vite.config.js. @@ -132,7 +136,7 @@ const { HTMLElement = class {} as typeof globalThis.HTMLElement } = globalThis export class ErrorOverlay extends HTMLElement { root: ShadowRoot - constructor(err: ErrorPayload['err']) { + constructor(err: ErrorPayload['err'], links = true) { super() this.root = this.attachShadow({ mode: 'open' }) this.root.innerHTML = template @@ -149,7 +153,7 @@ export class ErrorOverlay extends HTMLElement { const [file] = (err.loc?.file || err.id || 'unknown file').split(`?`) if (err.loc) { - this.text('.file', `${file}:${err.loc.line}:${err.loc.column}`, true) + this.text('.file', `${file}:${err.loc.line}:${err.loc.column}`, links) } else if (err.id) { this.text('.file', file) } @@ -157,7 +161,7 @@ export class ErrorOverlay extends HTMLElement { if (hasFrame) { this.text('.frame', err.frame!.trim()) } - this.text('.stack', err.stack, true) + this.text('.stack', err.stack, links) this.root.querySelector('.window')!.addEventListener('click', (e) => { e.stopPropagation() From fb8ab1641feb597f5ba51f8e6e043d2ce3980e08 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Wed, 28 Sep 2022 17:11:42 -0400 Subject: [PATCH 09/10] feat: support import.meta.hot.invalidate (#10244) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alec Larson <1925840+aleclarson@users.noreply.github.com> Co-authored-by: 翠 / green --- docs/guide/api-hmr.md | 14 +++++++++++++- packages/vite/src/client-types.d.ts | 3 ++- packages/vite/src/client/client.ts | 6 +++--- packages/vite/src/node/index.ts | 6 +++++- packages/vite/src/node/server/index.ts | 16 +++++++++++++++- packages/vite/src/types/customEvent.d.ts | 5 +++++ packages/vite/types/customEvent.d.ts | 6 +++++- playground/hmr/__tests__/hmr.spec.ts | 24 ++++++++++++++++++++++-- playground/hmr/hmr.ts | 5 +++++ playground/hmr/index.html | 1 + playground/hmr/invalidation/child.js | 9 +++++++++ playground/hmr/invalidation/parent.js | 9 +++++++++ 12 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 playground/hmr/invalidation/child.js create mode 100644 playground/hmr/invalidation/parent.js diff --git a/docs/guide/api-hmr.md b/docs/guide/api-hmr.md index 3b416169f5231a..12a859370d2e11 100644 --- a/docs/guide/api-hmr.md +++ b/docs/guide/api-hmr.md @@ -125,7 +125,18 @@ Calling `import.meta.hot.decline()` indicates this module is not hot-updatable, ## `hot.invalidate()` -For now, calling `import.meta.hot.invalidate()` simply reloads the page. +A self-accepting module may realize during runtime that it can't handle a HMR update, and so the update needs to be forcefully propagated to importers. By calling `import.meta.hot.invalidate()`, the HMR server will invalidate the importers of the caller, as if the caller wasn't self-accepting. + +Note that you should always call `import.meta.hot.accept` even if you plan to call `invalidate` immediately afterwards, or else the HMR client won't listen for future changes to the self-accepting module. To communicate your intent clearly, we recommend calling `invalidate` within the `accept` callback like so: + + ```ts + import.meta.hot.accept(module => { + // You may use the new module instance to decide whether to invalidate. + if (cannotHandleUpdate(module)) { + import.meta.hot.invalidate() + } + }) + ``` ## `hot.on(event, cb)` @@ -136,6 +147,7 @@ The following HMR events are dispatched by Vite automatically: - `'vite:beforeUpdate'` when an update is about to be applied (e.g. a module will be replaced) - `'vite:beforeFullReload'` when a full reload is about to occur - `'vite:beforePrune'` when modules that are no longer needed are about to be pruned +- `'vite:invalidate'` when a module is invalidated with `import.meta.hot.invalidate()` - `'vite:error'` when an error occurs (e.g. syntax error) Custom HMR events can also be sent from plugins. See [handleHotUpdate](./api-plugin#handlehotupdate) for more details. diff --git a/packages/vite/src/client-types.d.ts b/packages/vite/src/client-types.d.ts index 270a1ac29f2d8b..cca320bc5d4e1b 100644 --- a/packages/vite/src/client-types.d.ts +++ b/packages/vite/src/client-types.d.ts @@ -1,6 +1,7 @@ export type { CustomEventMap, - InferCustomEventPayload + InferCustomEventPayload, + InvalidatePayload } from './types/customEvent' export type { HMRPayload, diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index 83465d794358e2..3f974e77d9b52b 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -546,10 +546,10 @@ export function createHotContext(ownerPath: string): ViteHotContext { // eslint-disable-next-line @typescript-eslint/no-empty-function decline() {}, + // tell the server to re-perform hmr propagation from this module as root invalidate() { - // TODO should tell the server to re-perform hmr propagation - // from this module as root - location.reload() + notifyListeners('vite:invalidate', { path: ownerPath }) + this.send('vite:invalidate', { path: ownerPath }) }, // custom events diff --git a/packages/vite/src/node/index.ts b/packages/vite/src/node/index.ts index 2bc81f001d6947..0e246615bfa5f3 100644 --- a/packages/vite/src/node/index.ts +++ b/packages/vite/src/node/index.ts @@ -102,7 +102,11 @@ export type { PrunePayload, ErrorPayload } from 'types/hmrPayload' -export type { CustomEventMap, InferCustomEventPayload } from 'types/customEvent' +export type { + CustomEventMap, + InferCustomEventPayload, + InvalidatePayload +} from 'types/customEvent' // [deprecated: use vite/client/types instead] export type { ImportGlobFunction, diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 57a6a01e1fea12..77b91a4dfd6dba 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -13,6 +13,7 @@ import launchEditorMiddleware from 'launch-editor-middleware' import type { SourceMap } from 'rollup' import picomatch from 'picomatch' import type { Matcher } from 'picomatch' +import type { InvalidatePayload } from 'types/customEvent' import type { CommonServerOptions } from '../http' import { httpServerStart, @@ -67,7 +68,12 @@ import { timeMiddleware } from './middlewares/time' import { ModuleGraph } from './moduleGraph' import { errorMiddleware, prepareError } from './middlewares/error' import type { HmrOptions } from './hmr' -import { handleFileAddUnlink, handleHMRUpdate } from './hmr' +import { + getShortName, + handleFileAddUnlink, + handleHMRUpdate, + updateModules +} from './hmr' import { openBrowser } from './openBrowser' import type { TransformOptions, TransformResult } from './transformRequest' import { transformRequest } from './transformRequest' @@ -489,6 +495,14 @@ export async function createServer( handleFileAddUnlink(normalizePath(file), server) }) + ws.on('vite:invalidate', async ({ path }: InvalidatePayload) => { + const mod = moduleGraph.urlToModuleMap.get(path) + if (mod && mod.isSelfAccepting && mod.lastHMRTimestamp > 0) { + const file = getShortName(mod.file!, config.root) + updateModules(file, [...mod.importers], mod.lastHMRTimestamp, server) + } + }) + if (!middlewareMode && httpServer) { httpServer.once('listening', () => { // update actual port since this may be different from initial value diff --git a/packages/vite/src/types/customEvent.d.ts b/packages/vite/src/types/customEvent.d.ts index af4db5d14fbe97..839e17dd729eda 100644 --- a/packages/vite/src/types/customEvent.d.ts +++ b/packages/vite/src/types/customEvent.d.ts @@ -10,6 +10,11 @@ export interface CustomEventMap { 'vite:beforePrune': PrunePayload 'vite:beforeFullReload': FullReloadPayload 'vite:error': ErrorPayload + 'vite:invalidate': InvalidatePayload +} + +export interface InvalidatePayload { + path: string } export type InferCustomEventPayload = diff --git a/packages/vite/types/customEvent.d.ts b/packages/vite/types/customEvent.d.ts index 09fd7dc36ea481..d5bdbde98984fb 100644 --- a/packages/vite/types/customEvent.d.ts +++ b/packages/vite/types/customEvent.d.ts @@ -1 +1,5 @@ -export type { CustomEventMap, InferCustomEventPayload } from '../client/types' +export type { + CustomEventMap, + InferCustomEventPayload, + InvalidatePayload +} from '../client/types' diff --git a/playground/hmr/__tests__/hmr.spec.ts b/playground/hmr/__tests__/hmr.spec.ts index ef8def29a389a5..70d5a1b9ace52e 100644 --- a/playground/hmr/__tests__/hmr.spec.ts +++ b/playground/hmr/__tests__/hmr.spec.ts @@ -18,14 +18,14 @@ test('should render', async () => { if (!isBuild) { test('should connect', async () => { - expect(browserLogs.length).toBe(2) + expect(browserLogs.length).toBe(3) expect(browserLogs.some((msg) => msg.match('connected'))).toBe(true) browserLogs.length = 0 }) test('self accept', async () => { const el = await page.$('.app') - + browserLogs.length = 0 editFile('hmr.ts', (code) => code.replace('const foo = 1', 'const foo = 2')) await untilUpdated(() => el.textContent(), '2') @@ -91,6 +91,7 @@ if (!isBuild) { test('nested dep propagation', async () => { const el = await page.$('.nested') + browserLogs.length = 0 editFile('hmrNestedDep.js', (code) => code.replace('const foo = 1', 'const foo = 2') @@ -127,6 +128,25 @@ if (!isBuild) { browserLogs.length = 0 }) + test('invalidate', async () => { + browserLogs.length = 0 + const el = await page.$('.invalidation') + + editFile('invalidation/child.js', (code) => + code.replace('child', 'child updated') + ) + await untilUpdated(() => el.textContent(), 'child updated') + expect(browserLogs).toMatchObject([ + '>>> vite:beforeUpdate -- update', + '>>> vite:invalidate -- /invalidation/child.js', + '[vite] hot updated: /invalidation/child.js', + '>>> vite:beforeUpdate -- update', + '(invalidation) parent is executing', + '[vite] hot updated: /invalidation/parent.js' + ]) + browserLogs.length = 0 + }) + test('plugin hmr handler + custom event', async () => { const el = await page.$('.custom') editFile('customFile.js', (code) => code.replace('custom', 'edited')) diff --git a/playground/hmr/hmr.ts b/playground/hmr/hmr.ts index dc3c22eac9d56e..473dff9fdbfb88 100644 --- a/playground/hmr/hmr.ts +++ b/playground/hmr/hmr.ts @@ -2,6 +2,7 @@ import { virtual } from 'virtual:file' import { foo as depFoo, nestedFoo } from './hmrDep' import './importing-updated' +import './invalidation/parent' export const foo = 1 text('.app', foo) @@ -88,6 +89,10 @@ if (import.meta.hot) { console.log(`>>> vite:error -- ${event.type}`) }) + import.meta.hot.on('vite:invalidate', ({ path }) => { + console.log(`>>> vite:invalidate -- ${path}`) + }) + import.meta.hot.on('custom:foo', ({ msg }) => { text('.custom', msg) }) diff --git a/playground/hmr/index.html b/playground/hmr/index.html index 28f08014036ade..b8d6065a9fd5e2 100644 --- a/playground/hmr/index.html +++ b/playground/hmr/index.html @@ -20,6 +20,7 @@
+
diff --git a/playground/hmr/invalidation/child.js b/playground/hmr/invalidation/child.js new file mode 100644 index 00000000000000..b424e2f83c3233 --- /dev/null +++ b/playground/hmr/invalidation/child.js @@ -0,0 +1,9 @@ +if (import.meta.hot) { + // Need to accept, to register a callback for HMR + import.meta.hot.accept(() => { + // Trigger HMR in importers + import.meta.hot.invalidate() + }) +} + +export const value = 'child' diff --git a/playground/hmr/invalidation/parent.js b/playground/hmr/invalidation/parent.js new file mode 100644 index 00000000000000..0b10298fff1aa4 --- /dev/null +++ b/playground/hmr/invalidation/parent.js @@ -0,0 +1,9 @@ +import { value } from './child' + +if (import.meta.hot) { + import.meta.hot.accept() +} + +console.log('(invalidation) parent is executing') + +document.querySelector('.invalidation').innerHTML = value From 931d69b4d3cfebe641b93867191a7d411593f554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Thu, 29 Sep 2022 17:56:25 +0200 Subject: [PATCH 10/10] feat(optimizer): Support bun lockfile format (#10288) --- packages/vite/src/node/optimizer/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index eb9b51aa472e59..94447b9403393b 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1042,7 +1042,12 @@ function isSingleDefaultExport(exports: readonly string[]) { return exports.length === 1 && exports[0] === 'default' } -const lockfileFormats = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml'] +const lockfileFormats = [ + 'package-lock.json', + 'yarn.lock', + 'pnpm-lock.yaml', + 'bun.lockb' +] export function getDepHash(config: ResolvedConfig, ssr: boolean): string { let content = lookupFile(config.root, lockfileFormats) || ''