Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vitejs/vite-plugin-vue
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f00bcb4d2a0caf013013b0b8b54655daa1fce7ff
Choose a base ref
...
head repository: vitejs/vite-plugin-vue
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 76ffd55cf5a846d60ba3ec4bad3dd7237a0887ae
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Aug 17, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    haoqunjiang Haoqun Jiang
    Copy the full SHA
    ca5c634 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    haoqunjiang Haoqun Jiang
    Copy the full SHA
    0c28448 View commit details
  3. release: plugin-vue@4.3.1

    haoqunjiang committed Aug 17, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    haoqunjiang Haoqun Jiang
    Copy the full SHA
    76ffd55 View commit details
11 changes: 11 additions & 0 deletions packages/plugin-vue-jsx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## <small>3.0.2 (2023-08-17)</small>

* chore: bump vite ([ffe74e5](https://github.com/vitejs/vite-plugin-vue/commit/ffe74e5))
* chore: remove unused function parameter (#56) ([28bb84b](https://github.com/vitejs/vite-plugin-vue/commit/28bb84b)), closes [#56](https://github.com/vitejs/vite-plugin-vue/issues/56)
* fix(build): ensure correct typing for node esm (#179) ([8a19ee4](https://github.com/vitejs/vite-plugin-vue/commit/8a19ee4)), closes [#179](https://github.com/vitejs/vite-plugin-vue/issues/179)
* fix(deps): update all non-major dependencies (#163) ([3c8193d](https://github.com/vitejs/vite-plugin-vue/commit/3c8193d)), closes [#163](https://github.com/vitejs/vite-plugin-vue/issues/163)
* fix(deps): update all non-major dependencies (#205) ([e014680](https://github.com/vitejs/vite-plugin-vue/commit/e014680)), closes [#205](https://github.com/vitejs/vite-plugin-vue/issues/205)
* fix(deps): update all non-major dependencies (#82) ([b274436](https://github.com/vitejs/vite-plugin-vue/commit/b274436)), closes [#82](https://github.com/vitejs/vite-plugin-vue/issues/82)



## <small>3.0.1 (2023-03-16)</small>

* fix(deps): update all non-major dependencies (#50) ([8f4a5dc](https://github.com/vitejs/vite-plugin-vue/commit/8f4a5dc)), closes [#50](https://github.com/vitejs/vite-plugin-vue/issues/50)
2 changes: 1 addition & 1 deletion packages/plugin-vue-jsx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vitejs/plugin-vue-jsx",
"version": "3.0.1",
"version": "3.0.2",
"license": "MIT",
"author": "Evan You",
"files": [
6 changes: 6 additions & 0 deletions packages/plugin-vue/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## <small>4.3.1 (2023-08-17)</small>

* fix: revert "fix(plugin-vue): distinguish HMR and transform descriptor (#227)" ([0c28448](https://github.com/vitejs/vite-plugin-vue/commit/0c28448)), closes [#227](https://github.com/vitejs/vite-plugin-vue/issues/227)



## 4.3.0 (2023-08-17)

* docs: add example for transforming custom blocks (#221) ([a6e013e](https://github.com/vitejs/vite-plugin-vue/commit/a6e013e)), closes [#221](https://github.com/vitejs/vite-plugin-vue/issues/221)
2 changes: 1 addition & 1 deletion packages/plugin-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vitejs/plugin-vue",
"version": "4.3.0",
"version": "4.3.1",
"license": "MIT",
"author": "Evan You",
"files": [
11 changes: 5 additions & 6 deletions packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import { isCSSRequest } from 'vite'
import {
createDescriptor,
getDescriptor,
invalidateDescriptor,
setPrevDescriptor,
} from './utils/descriptorCache'
import {
getResolvedScript,
@@ -26,14 +26,16 @@ export async function handleHotUpdate(
{ file, modules, read }: HmrContext,
options: ResolvedOptions,
): Promise<ModuleNode[] | void> {
const prevDescriptor = getDescriptor(file, options, false, true)
const prevDescriptor = getDescriptor(file, options, false)
if (!prevDescriptor) {
// file hasn't been requested yet (e.g. async component)
return
}

setPrevDescriptor(file, prevDescriptor)

const content = await read()
const { descriptor } = createDescriptor(file, content, options, true)
const { descriptor } = createDescriptor(file, content, options)

let needRerender = false
const affectedModules = new Set<ModuleNode | undefined>()
@@ -148,9 +150,6 @@ export async function handleHotUpdate(
updateType.push(`style`)
}
if (updateType.length) {
// invalidate the descriptor cache so that the next transform will
// re-analyze the file and pick up the changes.
invalidateDescriptor(file)
debug(`[vue:update(${updateType.join('&')})] ${file}`)
}
return [...affectedModules].filter(Boolean) as ModuleNode[]
5 changes: 1 addition & 4 deletions packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import { addMapping, fromMap, toEncodedMap } from '@jridgewell/gen-mapping'
import { normalizePath, transformWithEsbuild } from 'vite'
import {
createDescriptor,
getDescriptor,
getPrevDescriptor,
setSrcDescriptor,
} from './utils/descriptorCache'
@@ -36,12 +35,10 @@ export async function transformMain(
) {
const { devServer, isProduction, devToolsEnabled } = options

// prev descriptor is only set and used for hmr
const prevDescriptor = getPrevDescriptor(filename)
const { descriptor, errors } = createDescriptor(filename, code, options)

// set descriptor for HMR if it's not set yet
getDescriptor(filename, options, true, true)

if (errors.length) {
errors.forEach((error) =>
pluginContext.error(createRollupError(filename, error)),
24 changes: 9 additions & 15 deletions packages/plugin-vue/src/utils/descriptorCache.ts
Original file line number Diff line number Diff line change
@@ -12,14 +12,12 @@ export interface SFCParseResult {
}

export const cache = new Map<string, SFCDescriptor>()
export const hmrCache = new Map<string, SFCDescriptor>()
const prevCache = new Map<string, SFCDescriptor | undefined>()

export function createDescriptor(
filename: string,
source: string,
{ root, isProduction, sourceMap, compiler }: ResolvedOptions,
hmr = false,
): SFCParseResult {
const { descriptor, errors } = compiler.parse(source, {
filename,
@@ -30,39 +28,35 @@ export function createDescriptor(
// project (relative to root) and on different systems.
const normalizedPath = slash(path.normalize(path.relative(root, filename)))
descriptor.id = getHash(normalizedPath + (isProduction ? source : ''))
;(hmr ? hmrCache : cache).set(filename, descriptor)

cache.set(filename, descriptor)
return { descriptor, errors }
}

export function getPrevDescriptor(filename: string): SFCDescriptor | undefined {
return prevCache.get(filename)
}

export function invalidateDescriptor(filename: string, hmr = false): void {
const _cache = hmr ? hmrCache : cache
const prev = _cache.get(filename)
_cache.delete(filename)
if (prev) {
prevCache.set(filename, prev)
}
export function setPrevDescriptor(
filename: string,
entry: SFCDescriptor,
): void {
prevCache.set(filename, entry)
}

export function getDescriptor(
filename: string,
options: ResolvedOptions,
createIfNotFound = true,
hmr = false,
): SFCDescriptor | undefined {
const _cache = hmr ? hmrCache : cache
if (_cache.has(filename)) {
return _cache.get(filename)!
if (cache.has(filename)) {
return cache.get(filename)!
}
if (createIfNotFound) {
const { descriptor, errors } = createDescriptor(
filename,
fs.readFileSync(filename, 'utf-8'),
options,
hmr,
)
if (errors.length) {
throw errors[0]