Skip to content

bug: Repeated builds will result in incorrect cache #3363

@rxliuli

Description

@rxliuli

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

  1. git clone https://github.com/rxliuli/vitepress-error-demo
  2. pnpm i
  3. pnpm 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions