WIP: address PR #475 review feedback
このコミットが含まれているのは:
@@ -1,9 +1,10 @@
|
||||
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import path from 'node:path'
|
||||
import { createServer } from 'vite'
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { generateHelpAssets } from './help-assets'
|
||||
import { generateHelpAssets, helpAssets } from './help-assets'
|
||||
|
||||
import type { ArticleMeta, HelpChange, HelpSearchEntry, HelpTitleIndex } from '@/lib/help'
|
||||
|
||||
@@ -109,4 +110,22 @@ describe ('Build-time Help assets', () => {
|
||||
it ('rejects an empty Help checkout', async () => {
|
||||
await expect (generateHelpAssets (root)).rejects.toThrow ('No Help articles found')
|
||||
})
|
||||
|
||||
it ('defers missing Help errors until a Help module is requested', async () => {
|
||||
const server = await createServer ({
|
||||
configFile: false,
|
||||
root,
|
||||
plugins: [helpAssets ()],
|
||||
server: { middlewareMode: true, watch: null } })
|
||||
try
|
||||
{
|
||||
await server.pluginContainer.buildStart ({})
|
||||
await expect (server.pluginContainer.load ('\0virtual:help/articles'))
|
||||
.rejects.toThrow ('ENOENT')
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.close ()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -159,10 +159,9 @@ export const helpAssets = (): Plugin => {
|
||||
configResolved (config) {
|
||||
state.root = path.resolve (config.root, 'help')
|
||||
},
|
||||
async buildStart () {
|
||||
state.data = generateHelpAssets (state.root)
|
||||
const generated = await data ()
|
||||
generated.files.forEach (file => this.addWatchFile (file))
|
||||
buildStart () {
|
||||
state.data = undefined
|
||||
this.addWatchFile (state.root)
|
||||
},
|
||||
resolveId (id) {
|
||||
return id.startsWith (prefix) ? `\0${ id }` : null
|
||||
@@ -170,7 +169,9 @@ export const helpAssets = (): Plugin => {
|
||||
async load (id) {
|
||||
if (!(id.startsWith (`\0${ prefix }`)))
|
||||
return null
|
||||
const source = (await data ()).modules.get (id.slice (1))
|
||||
const generated = await data ()
|
||||
generated.files.forEach (file => this.addWatchFile (file))
|
||||
const source = generated.modules.get (id.slice (1))
|
||||
if (source == null)
|
||||
throw new Error (`Unknown Help asset: ${ id.slice (1) }`)
|
||||
return source
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする