-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Labels
Description
Describe the bug
I'm using vitepress's nodejs api, but one problem is that if I call build twice, the second time there will be the wrong cache, causing the built index.html to still be the old result from the first time.
import { mkdir, readFile, writeFile } from 'fs/promises'
import path from 'path'
import { build } from 'vitepress'
import { it, expect } from 'vitest'
const tempPath = path.resolve(__dirname, '.temp')
it('should build', async () => {
await mkdir(tempPath, { recursive: true })
await writeFile(path.resolve(tempPath, 'index.md'), '# test 1')
await build(tempPath, {
outDir: path.resolve(tempPath, 'dist'),
})
expect(
await readFile(path.resolve(tempPath, 'dist/index.html'), 'utf-8'),
).include('test 1')
await writeFile(path.resolve(tempPath, 'index.md'), '# test 2')
await build(tempPath, {
outDir: path.resolve(tempPath, 'dist'),
})
expect(
await readFile(path.resolve(tempPath, 'dist/index.html'), 'utf-8'),
).include('test 2') // AssertionError: expected '<!DOCTYPE html>\n<html lang="en-US" d…' to include 'test 2'
})Reproduction
git clone https://github.com/rxliuli/vitepress-error-demopnpm ipnpm vitest
Expected behavior
The cache should be cleared during the second build
System Info
System:
OS: macOS 13.3
CPU: (12) arm64 Apple M2 Max
Memory: 10.56 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.2.3 - /usr/local/bin/npm
pnpm: 8.12.1 - /usr/local/bin/pnpm
Watchman: 2023.08.14.00 - /opt/homebrew/bin/watchman
Browsers:
Brave Browser: 115.1.56.11
Chrome: 120.0.6099.109
Safari: 16.4
npmPackages:
vitepress: 1.0.0-rc.32 => 1.0.0-rc.32
Additional context
No response
Validations
- Check if you're on the latest VitePress version.
- Follow our Code of Conduct
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.