Merge branch 'main' into feat/3783

pull/3795/head
Timothy Lau 1 year ago committed by GitHub
commit 930dbc7558
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,3 +1,9 @@
## [1.3.4](https://github.com/vuejs/vitepress/compare/v1.3.3...v1.3.4) (2024-08-24)
### Bug Fixes
- check if `_importGlobMap` (vite internal) exists before using it ([612d66f](https://github.com/vuejs/vitepress/commit/612d66fbb5162d9905cfb10919ca1761ce8c4680))
## [1.3.3](https://github.com/vuejs/vitepress/compare/v1.3.2...v1.3.3) (2024-08-17) ## [1.3.3](https://github.com/vuejs/vitepress/compare/v1.3.2...v1.3.3) (2024-08-17)
### Miscellaneous ### Miscellaneous

@ -7,14 +7,10 @@ export declare const data: Data
export default defineLoader({ export default defineLoader({
watch: ['./data/*'], watch: ['./data/*'],
async load(files: string[]): Promise<Data> { async load(files: string[]): Promise<Data> {
const foo = fs.readFileSync( const data: Data = []
files.find((f) => f.endsWith('foo.json'))!, for (const file of files.sort().filter((file) => file.endsWith('.json'))) {
'utf-8' data.push(JSON.parse(fs.readFileSync(file, 'utf-8')))
) }
const bar = fs.readFileSync( return data
files.find((f) => f.endsWith('bar.json'))!,
'utf-8'
)
return [JSON.parse(foo), JSON.parse(bar)]
} }
}) })

@ -1,3 +1,6 @@
import fs from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
describe('static data file support in vite 3', () => { describe('static data file support in vite 3', () => {
beforeAll(async () => { beforeAll(async () => {
await goto('/data-loading/data') await goto('/data-loading/data')
@ -7,10 +10,10 @@ describe('static data file support in vite 3', () => {
expect(await page.textContent('pre#basic')).toMatchInlineSnapshot(` expect(await page.textContent('pre#basic')).toMatchInlineSnapshot(`
"[ "[
{ {
"foo": true "a": true
}, },
{ {
"bar": true "b": true
} }
]" ]"
`) `)
@ -39,4 +42,68 @@ 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.skip('hmr works', async () => {
const a = fileURLToPath(new URL('./data/a.json', import.meta.url))
const b = fileURLToPath(new URL('./data/b.json', import.meta.url))
try {
await fs.writeFile(a, JSON.stringify({ a: false }, null, 2) + '\n')
await page.waitForFunction(
() =>
document.querySelector('pre#basic')?.textContent ===
JSON.stringify([{ a: false }, { b: true }], null, 2),
undefined,
{ timeout: 3000 }
)
} finally {
await fs.writeFile(a, JSON.stringify({ a: true }, null, 2) + '\n')
}
let err = true
try {
await fs.unlink(b)
await page.waitForFunction(
() =>
document.querySelector('pre#basic')?.textContent ===
JSON.stringify([{ a: true }], null, 2),
undefined,
{ timeout: 3000 }
)
err = false
} finally {
if (err) {
await fs.writeFile(b, JSON.stringify({ b: true }, null, 2) + '\n')
}
}
try {
await fs.writeFile(b, JSON.stringify({ b: false }, null, 2) + '\n')
await page.waitForFunction(
() =>
document.querySelector('pre#basic')?.textContent ===
JSON.stringify([{ a: true }, { b: false }], null, 2),
undefined,
{ timeout: 3000 }
)
} finally {
await fs.writeFile(b, JSON.stringify({ b: true }, null, 2) + '\n')
}
})
/*
MODIFY a.json with { a: false }
this should trigger a hmr update and the content should be updated to [{ a: false }, { b: true }]
reset a.json
DELETE b.json
this should trigger a hmr update and the content should be updated to [{ a: true }]
reset b.json if failed
CREATE b.json with { b: false }
this should trigger a hmr update and the content should be updated to [{ a: true }, { b: false }]
reset b.json
*/
}) })

@ -1,6 +1,6 @@
{ {
"name": "vitepress", "name": "vitepress",
"version": "1.3.3", "version": "1.3.4",
"description": "Vite & Vue powered static site generator", "description": "Vite & Vue powered static site generator",
"keywords": [ "keywords": [
"vite", "vite",

@ -121,7 +121,7 @@ export const staticDataPlugin: Plugin = {
}, },
transform(_code, id) { transform(_code, id) {
if (server && loaderMatch.test(id)) { if (server && loaderMatch.test(id) && '_importGlobMap' in server) {
// register this module as a glob importer // register this module as a glob importer
const { watch } = idToLoaderModulesMap[id]! const { watch } = idToLoaderModulesMap[id]!
if (watch) { if (watch) {

@ -28,7 +28,7 @@
* custom containers. * custom containers.
* *
* - `default`: The color used purely for subtle indication without any * - `default`: The color used purely for subtle indication without any
* special meanings attched to it such as bg color for menu hover state. * special meanings attached to it such as bg color for menu hover state.
* *
* - `brand`: Used for primary brand colors, such as link text, button with * - `brand`: Used for primary brand colors, such as link text, button with
* brand theme, etc. * brand theme, etc.

Loading…
Cancel
Save