Merge branch 'main' into chore/deps-replace-micromatch-with-picomatch

pull/4505/head
Divyansh Singh 8 months ago committed by GitHub
commit 362ab67204
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,3 +1,9 @@
## [1.6.2](https://github.com/vuejs/vitepress/compare/v1.6.1...v1.6.2) (2025-01-22)
### Bug Fixes
- fix static content removal for lean chunks due to Vue 3.5 changes ([#4508](https://github.com/vuejs/vitepress/issues/4508)) ([8214cae](https://github.com/vuejs/vitepress/commit/8214cae21bb16842d8870d5867e974146c51fd61))
## [1.6.1](https://github.com/vuejs/vitepress/compare/v1.6.0...v1.6.1) (2025-01-20) ## [1.6.1](https://github.com/vuejs/vitepress/compare/v1.6.0...v1.6.1) (2025-01-20)
### Bug Fixes ### Bug Fixes

@ -43,8 +43,7 @@ describe('static data file support in vite 3', () => {
`) `)
}) })
// TODO: make it `.runIf(!process.env.VITE_TEST_BUILD)` -- it currently works, but is skipped to avoid vite's ecosystem-ci from failing (https://github.com/vitejs/vite/pull/16471#issuecomment-2308437187) test.runIf(!process.env.VITE_TEST_BUILD)('hmr works', async () => {
test.skip('hmr works', async () => {
const a = fileURLToPath(new URL('./data/a.json', import.meta.url)) const a = fileURLToPath(new URL('./data/a.json', import.meta.url))
const b = fileURLToPath(new URL('./data/b.json', import.meta.url)) const b = fileURLToPath(new URL('./data/b.json', import.meta.url))

@ -1,6 +1,6 @@
{ {
"name": "vitepress", "name": "vitepress",
"version": "1.6.1", "version": "1.6.2",
"description": "Vite & Vue powered static site generator", "description": "Vite & Vue powered static site generator",
"keywords": [ "keywords": [
"vite", "vite",
@ -95,12 +95,12 @@
"*": "prettier --write --ignore-unknown" "*": "prettier --write --ignore-unknown"
}, },
"dependencies": { "dependencies": {
"@docsearch/css": "^3.8.2", "@docsearch/css": "^3.8.3",
"@docsearch/js": "^3.8.2", "@docsearch/js": "^3.8.3",
"@iconify-json/simple-icons": "^1.2.20", "@iconify-json/simple-icons": "^1.2.21",
"@shikijs/core": "^2.0.0", "@shikijs/core": "^2.1.0",
"@shikijs/transformers": "^2.0.0", "@shikijs/transformers": "^2.1.0",
"@shikijs/types": "^2.0.0", "@shikijs/types": "^2.1.0",
"@types/markdown-it": "^14.1.2", "@types/markdown-it": "^14.1.2",
"@vitejs/plugin-vue": "^5.2.1", "@vitejs/plugin-vue": "^5.2.1",
"@vue/devtools-api": "^7.7.0", "@vue/devtools-api": "^7.7.0",
@ -110,8 +110,8 @@
"focus-trap": "^7.6.4", "focus-trap": "^7.6.4",
"mark.js": "8.11.1", "mark.js": "8.11.1",
"minisearch": "^7.1.1", "minisearch": "^7.1.1",
"shiki": "^2.0.0", "shiki": "^2.1.0",
"vite": "^5.4.12", "vite": "^6.0.11",
"vue": "^3.5.13" "vue": "^3.5.13"
}, },
"devDependencies": { "devDependencies": {
@ -186,7 +186,7 @@
"synckit": "^0.9.2", "synckit": "^0.9.2",
"tinyglobby": "^0.2.10", "tinyglobby": "^0.2.10",
"typescript": "^5.7.3", "typescript": "^5.7.3",
"vitest": "^3.0.2", "vitest": "^3.0.3",
"vue-tsc": "^2.2.0", "vue-tsc": "^2.2.0",
"wait-on": "^8.0.2" "wait-on": "^8.0.2"
}, },

File diff suppressed because it is too large Load Diff

@ -119,21 +119,14 @@ function newApp(): App {
function newRouter(): Router { function newRouter(): Router {
let isInitialPageLoad = inBrowser let isInitialPageLoad = inBrowser
let initialPath: string
return createRouter((path) => { return createRouter((path) => {
let pageFilePath = pathToFile(path) let pageFilePath = pathToFile(path)
let pageModule = null let pageModule = null
if (pageFilePath) { if (pageFilePath) {
// use lean build if this is the initial page load
if (isInitialPageLoad) { if (isInitialPageLoad) {
initialPath = pageFilePath
}
// use lean build if this is the initial page load or navigating back
// to the initial loaded path (the static vnodes already adopted the
// static content on that load so no need to re-fetch the page)
if (isInitialPageLoad || initialPath === pageFilePath) {
pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js') pageFilePath = pageFilePath.replace(/\.js$/, '.lean.js')
} }

@ -38,8 +38,7 @@ declare module 'vite' {
const themeRE = /\/\.vitepress\/theme\/index\.(m|c)?(j|t)s$/ const themeRE = /\/\.vitepress\/theme\/index\.(m|c)?(j|t)s$/
const hashRE = /\.([-\w]+)\.js$/ const hashRE = /\.([-\w]+)\.js$/
const staticInjectMarkerRE = const staticInjectMarkerRE = /\bcreateStaticVNode\((?:(".*")|('.*')), (\d+)\)/g
/\b(const _hoisted_\d+ = \/\*(?:#|@)__PURE__\*\/\s*createStaticVNode)\("(.*)", (\d+)\)/g
const staticStripRE = /['"`]__VP_STATIC_START__[^]*?__VP_STATIC_END__['"`]/g const staticStripRE = /['"`]__VP_STATIC_START__[^]*?__VP_STATIC_END__['"`]/g
const staticRestoreRE = /__VP_STATIC_(START|END)__/g const staticRestoreRE = /__VP_STATIC_(START|END)__/g
@ -325,10 +324,11 @@ export async function createVitePressPlugin(
// Using a regexp relies on specific output from Vue compiler core, // Using a regexp relies on specific output from Vue compiler core,
// which is a reasonable trade-off considering the massive perf win over // which is a reasonable trade-off considering the massive perf win over
// a full AST parse. // a full AST parse.
code = code.replace( code = code.replace(staticInjectMarkerRE, (_, str1, str2, flag) => {
staticInjectMarkerRE, const str = str1 || str2
'$1("__VP_STATIC_START__$2__VP_STATIC_END__", $3)' const quote = str[0]
) return `createStaticVNode(${quote}__VP_STATIC_START__${str.slice(1, -1)}__VP_STATIC_END__${quote}, ${flag})`
})
return code return code
} }
return null return null

@ -2,6 +2,7 @@ import { isMatch } from 'picomatch'
import path, { dirname, resolve } from 'node:path' import path, { dirname, resolve } from 'node:path'
import { glob } from 'tinyglobby' import { glob } from 'tinyglobby'
import { import {
type EnvironmentModuleNode,
type Plugin, type Plugin,
type ViteDevServer, type ViteDevServer,
loadConfigFromFile, loadConfigFromFile,
@ -122,44 +123,25 @@ export const staticDataPlugin: Plugin = {
} }
}, },
transform(_code, id) { hotUpdate(ctx) {
if (server && loaderMatch.test(id) && '_importGlobMap' in server) {
// register this module as a glob importer
const { watch } = idToLoaderModulesMap[id]!
if (watch) {
;(server as any)._importGlobMap.set(
id,
[Array.isArray(watch) ? watch : [watch]].map((globs) => {
const affirmed: string[] = []
const negated: string[] = []
for (const glob of globs) {
;(glob[0] === '!' ? negated : affirmed).push(glob)
}
return { affirmed, negated }
})
)
}
}
return null
},
handleHotUpdate(ctx) {
const file = ctx.file const file = ctx.file
const modules: EnvironmentModuleNode[] = []
// dependency of data loader changed // dependency of data loader changed
// (note the dep array includes the loader file itself) // (note the dep array includes the loader file itself)
if (file in depToLoaderModuleIdMap) { if (file in depToLoaderModuleIdMap) {
const id = depToLoaderModuleIdMap[file]! const id = depToLoaderModuleIdMap[file]!
delete idToLoaderModulesMap[id] delete idToLoaderModulesMap[id]
ctx.modules.push(server.moduleGraph.getModuleById(id)!) modules.push(this.environment.moduleGraph.getModuleById(id)!)
} }
for (const id in idToLoaderModulesMap) { for (const id in idToLoaderModulesMap) {
const { watch } = idToLoaderModulesMap[id]! const { watch } = idToLoaderModulesMap[id]!
if (watch && isMatch(file, watch)) { if (watch && isMatch(file, watch)) {
ctx.modules.push(server.moduleGraph.getModuleById(id)!) modules.push(this.environment.moduleGraph.getModuleById(id)!)
} }
} }
return modules.length > 0 ? [...ctx.modules, ...modules] : undefined
} }
} }

Loading…
Cancel
Save