Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions e2e/docs/.vuepress/components/OnContentUpdated.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ watch(routePath, () => {

const callback: ContentUpdatedCallback = (reason) => {
switch (reason) {
case 'mounted':
case 'mounted': {
mounted.value = routePath.value
mountedCount.value++
break
case 'updated':
}
case 'updated': {
updatedCount.value++
break
case 'beforeUnmount':
}
case 'beforeUnmount': {
beforeUnmount.value = routePath.value
break
}
default:
}
}
Expand Down
2 changes: 2 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default vuepress(
typescript: {
overrides: {
'@typescript-eslint/no-useless-default-assignment': 'off', // TODO: crash
// we may need to mark some sync function as async
'@typescript-eslint/require-await': 'off',
},
},
javascript: {
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-vite/src/build/renderPagePreloadLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const renderPagePreloadLinks = ({
}

return `<link rel="preload" href="${app.options.base}${item}"${
type !== '' ? ` as="${type}"` : ''
type === '' ? '' : ` as="${type}"`
}>`
})
.join('')
Expand Down
8 changes: 4 additions & 4 deletions packages/bundler-vite/src/plugins/vuepressConfigPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ const resolveAlias = async ({
Object.assign(alias, aliasObject)
})

return [
...Object.keys(alias)
return (
Object.keys(alias)
// sort alias by length in descending order to ensure longer alias is handled first
.sort((a, b) => b.length - a.length)
.map((item) => ({
find: item,
replacement: alias[item],
})),
]
}))
)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/build/createClientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const createClientConfig = async (
styles: {
idHint: 'styles',
// necessary to ensure async chunks are also extracted
test: (m: Module) => m.type.includes('css/mini-extract'),
test: (module: Module) => module.type.includes('css/mini-extract'),
chunks: 'all',
enforce: true,
reuseExistingChunk: true,
Expand Down
18 changes: 10 additions & 8 deletions packages/bundler-webpack/src/build/createClientPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ export const createClientPlugin = (

// get asset modules
const assetModules = modules.filter(
(m): m is Required<Pick<StatsModule, 'assets'>> & StatsModule =>
Boolean(m.assets?.length),
(
module,
): module is Required<Pick<StatsModule, 'assets'>> & StatsModule =>
Boolean(module.assets?.length),
)

// get modules for client manifest
Expand All @@ -57,25 +59,25 @@ export const createClientPlugin = (
const fileToIndex = (file: number | string): number =>
allFiles.indexOf(file.toString())

modules.forEach((m) => {
modules.forEach((module) => {
// ignore modules duplicated in multiple chunks
if (m.chunks?.length !== 1) {
if (module.chunks?.length !== 1) {
return
}

const cid = m.chunks[0]
const chunk = chunks.find((c) => c.id === cid)
const cid = module.chunks[0]
const chunk = chunks.find(({ id }) => id === cid)

if (!chunk?.files) {
return
}

// remove appended hash of module identifier
// which is the request string of the module
const request = m.identifier?.replace(/\|\w+$/, '')
const request = module.identifier?.replace(/\|\w+$/, '')

// get chunk files index
const files = [...chunk.files.map(fileToIndex)]
const files = chunk.files.map(fileToIndex)

// find all asset modules associated with the same chunk
assetModules.forEach((item) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const renderPagePrefetchLinks = ({

// async files excluding files used by current page should be prefetch
const prefetchFilesMeta = asyncFilesMeta.filter(
({ file }) => !pageClientFilesMeta.some((f) => f.file === file),
({ file }) => !pageClientFilesMeta.some((meta) => meta.file === file),
)

return prefetchFilesMeta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const renderPagePreloadLinks = ({
}

return `<link rel="preload" href="${app.options.base}${file}"${
type !== '' ? ` as="${type}"` : ''
type === '' ? '' : ` as="${type}"`
}${type === 'font' ? ` type="font/${extension}" crossorigin` : ''}>`
})
.join('')
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/dev/watchPageFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { App, Page } from '@vuepress/core'
import { colors, logger, path, picomatch } from '@vuepress/utils'
import type { FSWatcher } from 'chokidar'
import chokidar from 'chokidar'
import { watch } from 'chokidar'
import { handlePageAdd } from './handlePageAdd.js'
import { handlePageChange } from './handlePageChange.js'
import { handlePageUnlink } from './handlePageUnlink.js'
Expand All @@ -13,7 +13,7 @@ import { createPageDepsHelper } from './pageDepsHelper.js'
*/
export const watchPageFiles = (app: App): FSWatcher[] => {
// watch page deps
const depsWatcher = chokidar.watch([], {
const depsWatcher = watch([], {
ignoreInitial: true,
})
const depsHelper = createPageDepsHelper()
Expand Down Expand Up @@ -56,7 +56,7 @@ export const watchPageFiles = (app: App): FSWatcher[] => {
const cacheDir = app.dir.cache()
const ignoreMatcher = picomatch(ignorePatterns, { cwd: sourceDir })
const pageMatcher = picomatch(pagePatterns, { cwd: sourceDir })
const pagesWatcher = chokidar.watch('.', {
const pagesWatcher = watch('.', {
cwd: sourceDir,
ignored: (filepath, stats) => {
// This is important so that folders like node_modules will be ignored immediately without traversing their children
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/dev/watchUserConfigFile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import process from 'node:process'
import { colors, logger } from '@vuepress/utils'
import type { FSWatcher } from 'chokidar'
import chokidar from 'chokidar'
import { watch } from 'chokidar'

export const watchUserConfigFile = ({
userConfigPath,
Expand All @@ -14,7 +14,7 @@ export const watchUserConfigFile = ({
}): FSWatcher[] => {
const cwd = process.cwd()

const configWatcher = chokidar.watch(userConfigPath, {
const configWatcher = watch(userConfigPath, {
cwd,
ignoreInitial: true,
})
Expand All @@ -23,7 +23,7 @@ export const watchUserConfigFile = ({
void restart()
})

const depsWatcher = chokidar.watch(userConfigDependencies, {
const depsWatcher = watch(userConfigDependencies, {
cwd,
ignoreInitial: true,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/components/Content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const Content = defineComponent({
if (!props.path) return pageComponent.value
const route = resolveRoute(props.path)
return defineAsyncComponent(async () =>
route.loader().then((m) => m.default),
route.loader().then((module) => module.default),
)
})

Expand Down
6 changes: 4 additions & 2 deletions packages/client/src/components/RouteLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const RouteLink = defineComponent({
const path = computed(() =>
props.to.startsWith('#') || props.to.startsWith('?')
? props.to
: `${__VUEPRESS_BASE__}${resolveRouteFullPath(props.to, route.path).substring(1)}`,
: `${__VUEPRESS_BASE__}${resolveRouteFullPath(props.to, route.path).slice(1)}`,
)

return () =>
Expand All @@ -103,7 +103,9 @@ export const RouteLink = defineComponent({
href: path.value,
onClick: (event: MouseEvent = {} as MouseEvent) => {
if (guardEvent(event)) {
void router.push(props.to).catch()
void router.push(props.to).catch(() => {
// ignore error here
})
}
},
},
Expand Down
3 changes: 1 addition & 2 deletions packages/client/src/setupGlobalComputed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export const setupGlobalComputed = (
default: oldPageChunk.default,
_pageData: newPageData,
}
routes.value[newPageData.path].loader = async () =>
Promise.resolve(newPageChunk)
routes.value[newPageData.path].loader = async () => newPageChunk
if (
newPageData.path ===
router.currentRoute.value.meta._pageChunk?._pageData.path
Expand Down
8 changes: 5 additions & 3 deletions packages/client/src/setupUpdateHead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const queryHeadElement = ([
document.querySelectorAll<HTMLElement>(selector),
)
const matchedHeadElement = headElements.find(
(item) => item.innerText === content,
(item) => item.textContent === content,
)
return matchedHeadElement ?? null
}
Expand Down Expand Up @@ -66,7 +66,7 @@ export const createHeadElement = ([

// set content
if (isString(content)) {
headElement.appendChild(document.createTextNode(content))
headElement.append(document.createTextNode(content))
}

return headElement
Expand Down Expand Up @@ -145,7 +145,9 @@ export const setupUpdateHead = (): void => {
}
})
// append the rest new elements to head
newHeadElements.forEach((el) => document.head.appendChild(el))
newHeadElements.forEach((el) => {
document.head.append(el)
})
// update managed head elements
managedHeadElements = [
// filter out empty deleted items
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/app/resolveAppWriteTemp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ export const resolveAppWriteTemp = (dir: AppDir): AppWriteTemp => {

item.hash = contentHash

if (!item.current) {
item.current = (async () => {
await fs.outputFile(filePath, content)
// if there is a next writing promise, chain it with the current one
item.current = item.next?.()
return item.current
})()
} else {
if (item.current) {
// if there is a current writing promise, save the next writing promise
item.next = async () => {
await fs.outputFile(filePath, content)
item.next = undefined
item.current = undefined
}
} else {
item.current = (async () => {
await fs.outputFile(filePath, content)
// if there is a next writing promise, chain it with the current one
item.current = item.next?.()
return item.current
})()
}
await item.current
return filePath
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/page/resolvePageContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const resolvePageContent = async ({
try {
const content = await fs.readFile(filePath, 'utf-8')
return content
} catch (e) {
log(e instanceof Error ? e.message : e)
} catch (err) {
log(err instanceof Error ? err.message : err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/pluginApi/createHookQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export const createHookQueue = <T extends HooksName>(name: T): HookQueue<T> => {
if (result !== undefined) {
results.push(result)
}
} catch (e) {
} catch (err) {
logger.error(
`error in hook ${colors.magenta(name)} from ${colors.magenta(
item.pluginName,
)}`,
)
throw e
throw err
}
}

Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/pluginApi/createPluginApiRegisterHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export const createPluginApiRegisterHooks =
plugins.forEach(
({
name: pluginName,
multiple,

alias,
define,
clientConfigFile,
Expand Down
6 changes: 0 additions & 6 deletions packages/core/src/types/app/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export interface AppConfigCommon extends Partial<SiteData> {
* Source directory of the markdown files.
*
* Vuepress will load markdown files from this directory.
*
* @required
*/
source: string

Expand Down Expand Up @@ -84,15 +82,11 @@ export interface AppConfigCommon extends Partial<SiteData> {

/**
* Vuepress bundler
*
* @required
*/
bundler: Bundler

/**
* Vuepress theme
*
* @required
*/
theme: Theme

Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/types/pluginApi/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export interface Hook<
Exposed,
Normalized = Exposed,
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- `any` type is required to infer the result type correctly
Result = Normalized extends (...args: any) => infer U
? U extends Promise<infer V>
? V
: U
Result = Normalized extends (...args: any) => infer Return
? Return extends Promise<infer Value>
? Value
: Return
: never,
> {
exposed: Exposed
Expand Down Expand Up @@ -85,21 +85,21 @@ export type HooksName = keyof Hooks
* Exposed hooks API that can be accessed by a plugin
*/
export type HooksExposed = {
[K in HooksName]: Hooks[K]['exposed']
[Key in HooksName]: Hooks[Key]['exposed']
}

/**
* Normalized hooks
*/
export type HooksNormalized = {
[K in HooksName]: Hooks[K]['normalized']
[Key in HooksName]: Hooks[Key]['normalized']
}

/**
* Result of hooks
*/
export type HooksResult = {
[K in HooksName]: Hooks[K]['result']
[Key in HooksName]: Hooks[Key]['result']
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/pluginApi/pluginApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface PluginApi {
* All available hooks
*/
hooks: {
[K in HooksName]: HookQueue<K>
[Key in HooksName]: HookQueue<Key>
}

/**
Expand Down
Loading
Loading