diff --git a/eslint.config.js b/eslint.config.js index 115d6c4386..19dd6bb34c 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -32,9 +32,10 @@ export default vuepress( }, }, { - files: ['**/*.spec.ts'], + files: ['**/tests/**'], rules: { 'no-console': 'off', + 'prefer-template': 'off', }, }, ) diff --git a/packages/core/src/app/createBaseApp.ts b/packages/core/src/app/createBaseApp.ts index b596ac2031..3e91a42eff 100644 --- a/packages/core/src/app/createBaseApp.ts +++ b/packages/core/src/app/createBaseApp.ts @@ -36,8 +36,8 @@ export const createBaseApp = (config: AppConfig, isBuild = false): App => { // methods use: (plugin: Plugin) => appUse(app, plugin), - init: () => appInit(app), - prepare: () => appPrepare(app), + init: async () => appInit(app), + prepare: async () => appPrepare(app), } as App // setup theme and plugins diff --git a/packages/core/src/app/resolveAppDir.ts b/packages/core/src/app/resolveAppDir.ts index 675c30ee5e..5e78b9d344 100644 --- a/packages/core/src/app/resolveAppDir.ts +++ b/packages/core/src/app/resolveAppDir.ts @@ -7,9 +7,10 @@ const require = createRequire(import.meta.url) /** * Create directory util function */ -export const createAppDirFunction = (baseDir: string): AppDirFunction => { - return (...args: string[]): string => path.resolve(baseDir, ...args) -} +export const createAppDirFunction = + (baseDir: string): AppDirFunction => + (...args) => + path.resolve(baseDir, ...args) /** * Resolve directory utils for vuepress app diff --git a/packages/core/src/app/resolveAppMarkdown.ts b/packages/core/src/app/resolveAppMarkdown.ts index 0875dceaf6..84ce7d0a1a 100644 --- a/packages/core/src/app/resolveAppMarkdown.ts +++ b/packages/core/src/app/resolveAppMarkdown.ts @@ -1,5 +1,5 @@ -import { createMarkdown } from '@vuepress/markdown' import type { Markdown } from '@vuepress/markdown' +import { createMarkdown } from '@vuepress/markdown' import type { App } from '../types/index.js' /** diff --git a/packages/core/src/app/resolveAppPages.ts b/packages/core/src/app/resolveAppPages.ts index 2f721fa7fd..1f7d083dc0 100644 --- a/packages/core/src/app/resolveAppPages.ts +++ b/packages/core/src/app/resolveAppPages.ts @@ -18,7 +18,7 @@ export const resolveAppPages = async (app: App): Promise => { // create pages from files const pages = await Promise.all( - pageFilePaths.map((filePath) => createPage(app, { filePath })), + pageFilePaths.map(async (filePath) => createPage(app, { filePath })), ) // find the 404 page diff --git a/packages/core/src/page/resolvePageHtmlInfo.ts b/packages/core/src/page/resolvePageHtmlInfo.ts index 58d1c63b4b..677921ed04 100644 --- a/packages/core/src/page/resolvePageHtmlInfo.ts +++ b/packages/core/src/page/resolvePageHtmlInfo.ts @@ -20,10 +20,10 @@ export const resolvePageHtmlInfo = ({ // /foo/ -> foo/index.html const htmlFilePathRelative = removeLeadingSlash( path.endsWith('/') - ? path + 'index.html' + ? `${path}index.html` : path.endsWith('.html') ? path - : path + '.html', + : `${path}.html`, ) const htmlFilePath = app.dir.dest(htmlFilePathRelative) diff --git a/packages/core/src/page/resolvePagePermalink.ts b/packages/core/src/page/resolvePagePermalink.ts index 6a549085f2..15a421dec1 100644 --- a/packages/core/src/page/resolvePagePermalink.ts +++ b/packages/core/src/page/resolvePagePermalink.ts @@ -45,9 +45,9 @@ export const resolvePagePermalink = ({ const link = path.join( pathLocale, permalinkPattern - .replace(/:year/, year!) - .replace(/:month/, month!) - .replace(/:day/, day!) + .replace(/:year/, year) + .replace(/:month/, month) + .replace(/:day/, day) .replace(/:slug/, slug) .replace(/:raw/, pathInferred?.replace(/^\//, '') ?? ''), ) diff --git a/packages/core/src/types/app/options.ts b/packages/core/src/types/app/options.ts index 93271fd4bf..4cbcabbc37 100644 --- a/packages/core/src/types/app/options.ts +++ b/packages/core/src/types/app/options.ts @@ -67,7 +67,7 @@ export interface AppConfigBuild { * * @default true */ - shouldPreload?: ((file: string, type: string) => boolean) | boolean + shouldPreload?: boolean | ((file: string, type: string) => boolean) /** * Determine what resource files should be prefetched. Use boolean value to @@ -75,7 +75,7 @@ export interface AppConfigBuild { * * @default true */ - shouldPrefetch?: ((file: string, type: string) => boolean) | boolean + shouldPrefetch?: boolean | ((file: string, type: string) => boolean) /** * Specify the path of the HTML template to be used for build @@ -95,7 +95,7 @@ export interface AppConfigBuild { /** * Vuepress app config */ -export type AppConfig = AppConfigCommon & AppConfigDev & AppConfigBuild +export type AppConfig = AppConfigBuild & AppConfigCommon & AppConfigDev /** * Vuepress app options diff --git a/packages/markdown/src/plugins/emojiPlugin.ts b/packages/markdown/src/plugins/emojiPlugin.ts index 5defb59291..edae7522e0 100644 --- a/packages/markdown/src/plugins/emojiPlugin.ts +++ b/packages/markdown/src/plugins/emojiPlugin.ts @@ -1,5 +1,5 @@ -import { full as emojiPlugin } from 'markdown-it-emoji' import type { Options } from 'markdown-it-emoji' +import { full as emojiPlugin } from 'markdown-it-emoji' export type EmojiPluginOptions = Options export { emojiPlugin } diff --git a/packages/markdown/src/types.ts b/packages/markdown/src/types.ts index 274baabe08..5bb7cc76fc 100644 --- a/packages/markdown/src/types.ts +++ b/packages/markdown/src/types.ts @@ -20,19 +20,19 @@ export type Markdown = MarkdownIt export type { MarkdownSfcBlocks } export interface MarkdownOptions extends Options { - anchor?: false | AnchorPluginOptions - assets?: false | AssetsPluginOptions + anchor?: AnchorPluginOptions | false + assets?: AssetsPluginOptions | false component?: false - emoji?: false | EmojiPluginOptions - frontmatter?: false | FrontmatterPluginOptions - headers?: false | HeadersPluginOptions + emoji?: EmojiPluginOptions | false + frontmatter?: FrontmatterPluginOptions | false + headers?: HeadersPluginOptions | false title?: false - importCode?: false | ImportCodePluginOptions - links?: false | LinksPluginOptions - sfc?: false | SfcPluginOptions + importCode?: ImportCodePluginOptions | false + links?: LinksPluginOptions | false + sfc?: SfcPluginOptions | false slugify?: MarkdownSlugifyFunction - toc?: false | TocPluginOptions - vPre?: false | VPrePluginOptions + toc?: TocPluginOptions | false + vPre?: VPrePluginOptions | false /** * @deprecated This feature has been removed. Please use `@vuepress/plugin-prismjs` or `@vuepress/plugin-shiki` instead. */ diff --git a/packages/markdown/tests/plugins/linksPlugin.spec.ts b/packages/markdown/tests/plugins/linksPlugin.spec.ts index 19b1318c59..b74996ac9d 100644 --- a/packages/markdown/tests/plugins/linksPlugin.spec.ts +++ b/packages/markdown/tests/plugins/linksPlugin.spec.ts @@ -1,7 +1,7 @@ import MarkdownIt from 'markdown-it' import { describe, expect, it } from 'vitest' -import { linksPlugin } from '../../src/index.js' import type { MarkdownEnv } from '../../src/index.js' +import { linksPlugin } from '../../src/index.js' describe('@vuepress/markdown > plugins > linksPlugin', () => { describe('external links', () => { diff --git a/packages/markdown/tests/plugins/vPrePlugin.spec.ts b/packages/markdown/tests/plugins/vPrePlugin.spec.ts index 1bda5aaf05..128a163cf5 100644 --- a/packages/markdown/tests/plugins/vPrePlugin.spec.ts +++ b/packages/markdown/tests/plugins/vPrePlugin.spec.ts @@ -2,14 +2,14 @@ import MarkdownIt from 'markdown-it' import { describe, expect, it, vi } from 'vitest' import { vPrePlugin } from '../../src/index.js' -const codeFence = '```' +const CODE_FENCE = '```' describe('@vuepress/markdown > plugins > vPrePlugin', () => { describe('plugin options', () => { const source = `\ -${codeFence}js +${CODE_FENCE}js const a = 1 -${codeFence} +${CODE_FENCE} \`inline\` ` @@ -40,33 +40,33 @@ ${codeFence} describe(':v-pre / :no-v-pre', () => { const source = `\ -${codeFence}js:v-pre +${CODE_FENCE}js:v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js:no-v-pre +${CODE_FENCE}js:no-v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js{1,2}:v-pre +${CODE_FENCE}js{1,2}:v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js{1,2}:no-v-pre +${CODE_FENCE}js{1,2}:no-v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js:other-syntax:v-pre +${CODE_FENCE}js:other-syntax:v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js:other-syntax:no-v-pre +${CODE_FENCE}js:other-syntax:no-v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js +${CODE_FENCE}js const a = 1 -${codeFence} +${CODE_FENCE} ` it('should work if `block` is enabled by default', () => { const md = MarkdownIt().use(vPrePlugin) @@ -83,33 +83,33 @@ ${codeFence} describe('syntax highlighting', () => { const source = `\ -${codeFence}js:v-pre +${CODE_FENCE}js:v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js:no-v-pre +${CODE_FENCE}js:no-v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js{1,2}:v-pre +${CODE_FENCE}js{1,2}:v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js{1,2}:no-v-pre +${CODE_FENCE}js{1,2}:no-v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js:other-syntax:v-pre +${CODE_FENCE}js:other-syntax:v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js:other-syntax:no-v-pre +${CODE_FENCE}js:other-syntax:no-v-pre const a = 1 -${codeFence} +${CODE_FENCE} -${codeFence}js +${CODE_FENCE}js const a = 1 -${codeFence} +${CODE_FENCE} ` it('should work highlighted code is wrapped with `
`', () => {
       const highlight = vi.fn(
diff --git a/packages/shared/src/types/head.ts b/packages/shared/src/types/head.ts
index 44024a9956..4cbf019a3b 100644
--- a/packages/shared/src/types/head.ts
+++ b/packages/shared/src/types/head.ts
@@ -10,17 +10,17 @@ export type HeadConfig =
  *
  * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head
  */
-export type HeadTag = HeadTagNonEmpty | HeadTagEmpty
+export type HeadTag = HeadTagEmpty | HeadTagNonEmpty
 
 /**
  * Non-empty tags in ``
  */
 export type HeadTagNonEmpty =
-  | 'title'
-  | 'style'
-  | 'script'
   | 'noscript'
+  | 'script'
+  | 'style'
   | 'template'
+  | 'title'
 
 /**
  * Empty tags in ``
@@ -30,4 +30,4 @@ export type HeadTagEmpty = 'base' | 'link' | 'meta' | 'script'
 /**
  * Attributes to be set for tags in ``
  */
-export type HeadAttrsConfig = Record
+export type HeadAttrsConfig = Record
diff --git a/packages/shared/tests/dedupeHead.spec.ts b/packages/shared/tests/dedupeHead.spec.ts
index a73fae6b26..659cb1df16 100644
--- a/packages/shared/tests/dedupeHead.spec.ts
+++ b/packages/shared/tests/dedupeHead.spec.ts
@@ -1,6 +1,6 @@
 import { expect, it } from 'vitest'
-import { dedupeHead } from '../src/index.js'
 import type { HeadConfig } from '../src/index.js'
+import { dedupeHead } from '../src/index.js'
 
 it('should dedupe head correctly', () => {
   const head: HeadConfig[] = [