feat: switch to vite 5 and bump deps (#3200)

BREAKING CHANGE: VitePress now runs on Vite 5. Please refer https://vitejs.dev/guide/migration for breaking changes and migration guide if you're relying on some Vite-specific things.
pull/3217/head
Divyansh Singh 8 months ago committed by GitHub
parent 2d96200a21
commit d2238eedb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,2 +1,2 @@
shell-emulator=true
resolution-mode=highest
auto-install-peers=false

@ -4,8 +4,8 @@ exports[`render correct content > main content 1`] = `
[
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \\"de Finibus Bonorum et Malorum\\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \\"Lorem ipsum dolor sit amet..\\", comes from a line in section 1.10.32.",
"The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from \\"de Finibus Bonorum et Malorum\\" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.",
"The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.",
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).",
"There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.",
]

@ -7,34 +7,34 @@ describe('static data file support in vite 3', () => {
expect(await page.textContent('pre#basic')).toMatchInlineSnapshot(`
"[
{
\\"foo\\": true
"foo": true
},
{
\\"bar\\": true
"bar": true
}
]"
`)
expect(await page.textContent('pre#content')).toMatchInlineSnapshot(`
"[
{
\\"src\\": \\"---\\\\ntitle: bar\\\\n---\\\\n\\\\nHello\\\\n\\\\n---\\\\n\\\\nworld\\\\n\\",
\\"html\\": \\"<p>Hello</p>\\\\n<hr>\\\\n<p>world</p>\\\\n\\",
\\"frontmatter\\": {
\\"title\\": \\"bar\\"
"src": "---\\ntitle: bar\\n---\\n\\nHello\\n\\n---\\n\\nworld\\n",
"html": "<p>Hello</p>\\n<hr>\\n<p>world</p>\\n",
"frontmatter": {
"title": "bar"
},
\\"excerpt\\": \\"<p>Hello</p>\\\\n\\",
\\"url\\": \\"/data-loading/content/bar.html\\",
\\"transformed\\": true
"excerpt": "<p>Hello</p>\\n",
"url": "/data-loading/content/bar.html",
"transformed": true
},
{
\\"src\\": \\"---\\\\ntitle: foo\\\\n---\\\\n\\\\nHello\\\\n\\\\n---\\\\n\\\\nworld\\\\n\\",
\\"html\\": \\"<p>Hello</p>\\\\n<hr>\\\\n<p>world</p>\\\\n\\",
\\"frontmatter\\": {
\\"title\\": \\"foo\\"
"src": "---\\ntitle: foo\\n---\\n\\nHello\\n\\n---\\n\\nworld\\n",
"html": "<p>Hello</p>\\n<hr>\\n<p>world</p>\\n",
"frontmatter": {
"title": "foo"
},
\\"excerpt\\": \\"<p>Hello</p>\\\\n\\",
\\"url\\": \\"/data-loading/content/foo.html\\",
\\"transformed\\": true
"excerpt": "<p>Hello</p>\\n",
"url": "/data-loading/content/foo.html",
"transformed": true
}
]"
`)

@ -1,10 +1,13 @@
import fs from 'fs-extra'
import getPort from 'get-port'
import { nanoid } from 'nanoid'
import path from 'path'
import { chromium } from 'playwright-chromium'
import { fileURLToPath, URL } from 'url'
import { createServer, scaffold, ScaffoldThemeType } from 'vitepress'
const root = fileURLToPath(new URL('./.temp', import.meta.url))
const tempDir = fileURLToPath(new URL('./.temp', import.meta.url))
const getTempRoot = () => path.join(tempDir, nanoid())
const browser = await chromium.launch({
headless: !process.env.DEBUG,
@ -30,9 +33,11 @@ const variations = themes.flatMap((theme) =>
afterAll(async () => {
await page.close()
await browser.close()
await fs.remove(tempDir)
})
test.each(variations)('init %s', async (_, { theme, useTs }) => {
const root = getTempRoot()
await fs.remove(root)
scaffold({ root, theme, useTs, injectNpmScripts: false })
@ -62,7 +67,6 @@ test.each(variations)('init %s', async (_, { theme, useTs }) => {
// teardown
} finally {
await fs.remove(root)
await server.close()
}
})

@ -50,7 +50,7 @@ describe('node/markdown/plugins/snippet', () => {
)
).toMatchInlineSnapshot(`
"fn main() {
println!(\\"Hello\\");
println!("Hello");
}"
`)
})

@ -3,7 +3,7 @@
"version": "1.0.0-rc.25",
"description": "Vite & Vue powered static site generator",
"type": "module",
"packageManager": "pnpm@8.9.2",
"packageManager": "pnpm@8.10.5",
"main": "dist/node/index.js",
"types": "types/index.d.ts",
"exports": {
@ -92,17 +92,17 @@
"dependencies": {
"@docsearch/css": "^3.5.2",
"@docsearch/js": "^3.5.2",
"@types/markdown-it": "^13.0.4",
"@vitejs/plugin-vue": "4.3.1",
"@types/markdown-it": "^13.0.6",
"@vitejs/plugin-vue": "^4.5.0",
"@vue/devtools-api": "^6.5.1",
"@vueuse/core": "^10.5.0",
"@vueuse/integrations": "^10.5.0",
"@vueuse/core": "^10.6.1",
"@vueuse/integrations": "^10.6.1",
"focus-trap": "^7.5.4",
"mark.js": "8.11.1",
"minisearch": "^6.1.0",
"minisearch": "^6.2.0",
"shiki": "^0.14.5",
"vite": "^4.5.0",
"vue": "^3.3.6"
"vite": "^5.0.0",
"vue": "^3.3.8"
},
"peerDependencies": {
"markdown-it-mathjax3": "^4.3.2",
@ -129,23 +129,23 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.4",
"@types/compression": "^1.7.4",
"@types/cross-spawn": "^6.0.4",
"@types/debug": "^4.1.10",
"@types/escape-html": "^1.0.3",
"@types/fs-extra": "^11.0.3",
"@types/lodash.template": "^4.5.2",
"@types/mark.js": "^8.11.10",
"@types/markdown-it-attrs": "^4.1.2",
"@types/markdown-it-container": "^2.0.8",
"@types/markdown-it-emoji": "^2.0.3",
"@types/micromatch": "^4.0.4",
"@types/minimist": "^1.2.4",
"@types/node": "^20.8.7",
"@types/postcss-prefix-selector": "^1.16.2",
"@types/prompts": "^2.4.7",
"@vue/shared": "^3.3.6",
"@rollup/plugin-replace": "^5.0.5",
"@types/compression": "^1.7.5",
"@types/cross-spawn": "^6.0.5",
"@types/debug": "^4.1.12",
"@types/escape-html": "^1.0.4",
"@types/fs-extra": "^11.0.4",
"@types/lodash.template": "^4.5.3",
"@types/mark.js": "^8.11.11",
"@types/markdown-it-attrs": "^4.1.3",
"@types/markdown-it-container": "^2.0.9",
"@types/markdown-it-emoji": "^2.0.4",
"@types/micromatch": "^4.0.5",
"@types/minimist": "^1.2.5",
"@types/node": "^20.9.0",
"@types/postcss-prefix-selector": "^1.16.3",
"@types/prompts": "^2.4.8",
"@vue/shared": "^3.3.8",
"chokidar": "^3.5.3",
"compression": "^1.7.4",
"conventional-changelog-cli": "^4.1.0",
@ -154,13 +154,13 @@
"esbuild": "^0.19.5",
"escape-html": "^1.0.3",
"execa": "^8.0.1",
"fast-glob": "^3.3.1",
"fast-glob": "^3.3.2",
"fs-extra": "^11.1.1",
"get-port": "^7.0.0",
"gray-matter": "^4.0.3",
"lint-staged": "^15.0.2",
"lint-staged": "^15.1.0",
"lodash.template": "^4.5.0",
"lru-cache": "^10.0.1",
"lru-cache": "^10.0.2",
"markdown-it": "^13.0.2",
"markdown-it-anchor": "^8.6.7",
"markdown-it-attrs": "^4.1.6",
@ -169,20 +169,20 @@
"markdown-it-mathjax3": "^4.3.2",
"micromatch": "^4.0.5",
"minimist": "^1.2.8",
"nanoid": "^5.0.2",
"nanoid": "^5.0.3",
"npm-run-all": "^4.1.5",
"ora": "^7.0.1",
"path-to-regexp": "^6.2.1",
"picocolors": "^1.0.0",
"pkg-dir": "^7.0.0",
"pkg-dir": "^8.0.0",
"playwright-chromium": "^1.39.0",
"polka": "1.0.0-next.22",
"polka": "1.0.0-next.23",
"postcss-prefix-selector": "^1.16.0",
"prettier": "^3.0.3",
"prettier": "^3.1.0",
"prompts": "^2.4.2",
"punycode": "^2.3.0",
"punycode": "^2.3.1",
"rimraf": "^5.0.5",
"rollup": "^4.1.4",
"rollup": "^4.4.1",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.0",
"semver": "^7.5.4",
@ -192,9 +192,9 @@
"sitemap": "^7.1.1",
"supports-color": "^9.4.0",
"typescript": "^5.2.2",
"vitest": "^0.34.6",
"vue-tsc": "^1.8.19",
"wait-on": "^7.0.1"
"vitest": "^1.0.0-beta.4",
"vue-tsc": "^1.8.22",
"wait-on": "^7.2.0"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
@ -207,6 +207,13 @@
"pnpm": {
"overrides": {
"ora>string-width": "^5"
},
"peerDependencyRules": {
"ignoreMissing": [
"@algolia/client-search",
"search-insights",
"postcss"
]
}
}
}

File diff suppressed because it is too large Load Diff

@ -74,13 +74,13 @@ export function initData(route: Route): VitePressData {
appearance === 'force-dark'
? ref(true)
: appearance
? useDark({
storageKey: APPEARANCE_KEY,
initialValue: () =>
typeof appearance === 'string' ? appearance : 'auto',
...(typeof appearance === 'object' ? appearance : {})
})
: ref(false)
? useDark({
storageKey: APPEARANCE_KEY,
initialValue: () =>
typeof appearance === 'string' ? appearance : 'auto',
...(typeof appearance === 'object' ? appearance : {})
})
: ref(false)
return {
site,

@ -18,7 +18,6 @@ defineEmits<{
const { theme, frontmatter } = useData()
const { hasSidebar } = useSidebar()
// @ts-ignore
const { y } = useWindowScroll()
const headers = shallowRef<MenuItem[]>([])

@ -20,7 +20,6 @@ defineEmits<{
(e: 'toggle-screen'): void
}>()
// @ts-ignore
const { y } = useWindowScroll()
const { hasSidebar } = useSidebar()
const { frontmatter } = useData()

@ -73,8 +73,8 @@ export function resolveHeaders(
typeof levelsRange === 'number'
? [levelsRange, levelsRange]
: levelsRange === 'deep'
? [2, 6]
: levelsRange
? [2, 6]
: levelsRange
headers = headers.filter((h) => h.level >= high && h.level <= low)

@ -30,8 +30,8 @@ export function usePrevNext() {
(typeof frontmatter.value.prev === 'string'
? frontmatter.value.prev
: typeof frontmatter.value.prev === 'object'
? frontmatter.value.prev.text
: undefined) ??
? frontmatter.value.prev.text
: undefined) ??
candidates[index - 1]?.docFooterText ??
candidates[index - 1]?.text,
link:
@ -46,8 +46,8 @@ export function usePrevNext() {
(typeof frontmatter.value.next === 'string'
? frontmatter.value.next
: typeof frontmatter.value.next === 'object'
? frontmatter.value.next.text
: undefined) ??
? frontmatter.value.next.text
: undefined) ??
candidates[index + 1]?.docFooterText ??
candidates[index + 1]?.text,
link:

@ -104,8 +104,8 @@ export function hasActiveLink(
return isActive(path, items.link)
? true
: items.items
? hasActiveLink(path, items.items)
: false
? hasActiveLink(path, items.items)
: false
}
function addBase(items: SidebarItem[], _base?: string): SidebarItem[] {

@ -77,8 +77,8 @@ export async function bundle(
? 'esbuild'
: false
: typeof options.minify === 'boolean'
? options.minify
: !process.env.DEBUG,
? options.minify
: !process.env.DEBUG,
outDir: ssr ? config.tempDir : config.outDir,
cssCodeSplit: false,
rollupOptions: {

@ -73,16 +73,16 @@ export async function renderPage(
config.mpa || (!hasCustom404 && page === '404.md')
? []
: result && appChunk
? [
...new Set([
// resolve imports for index.js + page.md.js and inject script tags
// for them as well so we fetch everything as early as possible
// without having to wait for entry chunks to parse
...resolvePageImports(config, page, result, appChunk),
pageClientJsFileName
])
]
: []
? [
...new Set([
// resolve imports for index.js + page.md.js and inject script tags
// for them as well so we fetch everything as early as possible
// without having to wait for entry chunks to parse
...resolvePageImports(config, page, result, appChunk),
pageClientJsFileName
])
]
: []
let prefetchLinks: string[] = []

@ -252,8 +252,8 @@ function resolveSiteDataHead(userConfig?: UserConfig): HeadConfig[] {
typeof userConfig?.appearance === 'string'
? userConfig?.appearance
: typeof userConfig?.appearance === 'object'
? userConfig.appearance.initialValue ?? 'auto'
: 'auto'
? userConfig.appearance.initialValue ?? 'auto'
: 'auto'
head.push([
'script',

@ -43,7 +43,6 @@ export async function createMarkdownToVueRenderFn(
srcDir: string,
options: MarkdownOptions = {},
pages: string[],
userDefines: Record<string, any> | undefined,
isBuild = false,
base = '/',
includeLastUpdatedData = false,
@ -57,7 +56,6 @@ export async function createMarkdownToVueRenderFn(
siteConfig?.logger
)
pages = pages.map((p) => slash(p.replace(/\.md$/, '')))
const replaceRegex = genReplaceRegexp(userDefines, isBuild)
return async (
src: string,
@ -200,14 +198,9 @@ export async function createMarkdownToVueRenderFn(
const vueSrc = [
...injectPageDataCode(
sfcBlocks?.scripts.map((item) => item.content) ?? [],
pageData,
replaceRegex
pageData
),
`<template><div>${replaceConstants(
html,
replaceRegex,
vueTemplateBreaker
)}</div></template>`,
`<template><div>${html}</div></template>`,
...(sfcBlocks?.styles.map((item) => item.content) ?? []),
...(sfcBlocks?.customBlocks.map((item) => item.content) ?? [])
].join('\n')
@ -233,46 +226,10 @@ const scriptSetupRE = /<\s*script[^>]*\bsetup\b[^>]*/
const scriptClientRE = /<\s*script[^>]*\bclient\b[^>]*/
const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/
const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/
const jsStringBreaker = '\u200b'
const vueTemplateBreaker = '<wbr>'
function genReplaceRegexp(
userDefines: Record<string, any> = {},
isBuild: boolean
): RegExp {
// `process.env` need to be handled in both dev and build
// @see https://github.com/vitejs/vite/blob/cad27ee8c00bbd5aeeb2be9bfb3eb164c1b77885/packages/vite/src/node/plugins/clientInjections.ts#L57-L64
const replacements = ['process.env']
if (isBuild) {
replacements.push('import.meta', ...Object.keys(userDefines))
}
return new RegExp(
`\\b(${replacements
.map((key) => key.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&'))
.join('|')})`,
'g'
)
}
/**
* To avoid env variables being replaced by vite:
* - insert `'\u200b'` char into those strings inside js string (page data)
* - insert `<wbr>` tag into those strings inside html string (vue template)
*
* @see https://vitejs.dev/guide/env-and-mode.html#production-replacement
*/
function replaceConstants(str: string, replaceRegex: RegExp, breaker: string) {
return str.replace(replaceRegex, (_) => `${_[0]}${breaker}${_.slice(1)}`)
}
function injectPageDataCode(
tags: string[],
data: PageData,
replaceRegex: RegExp
) {
const dataJson = JSON.stringify(data)
function injectPageDataCode(tags: string[], data: PageData) {
const code = `\nexport const __pageData = JSON.parse(${JSON.stringify(
replaceConstants(dataJson, replaceRegex, jsStringBreaker)
JSON.stringify(data)
)})`
const existingScriptIndex = tags.findIndex((tag) => {

@ -133,7 +133,6 @@ export async function createVitePressPlugin(
srcDir,
markdown,
pages,
config.define,
config.command === 'build',
config.base,
lastUpdated,
@ -328,14 +327,11 @@ export async function createVitePressPlugin(
generateBundle(_options, bundle) {
if (ssr) {
// @ts-ignore will be removed in vite 5
if (config.ssr?.format !== 'cjs') {
this.emitFile({
type: 'asset',
fileName: 'package.json',
source: '{ "private": true, "type": "module" }'
})
}
this.emitFile({
type: 'asset',
fileName: 'package.json',
source: '{ "private": true, "type": "module" }'
})
} else {
// client build:
// for each .md entry chunk, adjust its name to its correct path.

Loading…
Cancel
Save