Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Aug 16, 2024
1 parent bae6b36 commit ddea4de
Show file tree
Hide file tree
Showing 25 changed files with 75 additions and 83 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export default vuepress(
},
vue: {
overrides: {
'vue/multi-word-component-names': 'off',
'no-useless-assignment': 'off', // TODO: false positive in vue sfc
},
},
},
{
files: ['**/tests/**'],
rules: {
'import/no-unresolved': 'off',
'no-console': 'off',
'prefer-template': 'off',
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"bumpp": "^9.5.1",
"conventional-changelog-cli": "^5.0.0",
"eslint": "^9.9.0",
"eslint-config-vuepress": "^5.1.0",
"eslint-config-vuepress": "^5.1.2",
"husky": "^9.1.4",
"lint-staged": "^15.2.9",
"prettier": "^3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/build/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface FileMeta {
/**
* Client file meta type, mainly used for <preload as="type">
*/
export type FileMetaType = 'script' | 'style' | 'image' | 'font' | ''
export type FileMetaType = '' | 'font' | 'image' | 'script' | 'style'

/**
* A "module request" to "client files meta" key-value map
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/createBaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const createBaseConfig = async ({
/**
* module
*/
handleModule({ app, options, config, isBuild, isServer })
handleModule({ options, config, isBuild, isServer })

/**
* plugins
Expand Down
16 changes: 9 additions & 7 deletions packages/bundler-webpack/src/config/handleEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export const handleEntry = ({
config: Config
}): void => {
// set client app as entry point
config
.entry('app')
.add(
app.dir.client(
fs.readJsonSync(app.dir.client('package.json')).exports['./app'],
),
)
config.entry('app').add(
app.dir.client(
(
fs.readJsonSync(app.dir.client('package.json')) as {
exports: { './app': string }
}
).exports['./app'],
),
)
}
9 changes: 3 additions & 6 deletions packages/bundler-webpack/src/config/handleModule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { App } from '@vuepress/core'
import type Config from 'webpack-5-chain'
import type { WebpackBundlerOptions } from '../types.js'
import { handleModuleAssets } from './handleModuleAssets.js'
Expand All @@ -12,13 +11,11 @@ import { handleModuleVue } from './handleModuleVue.js'
* Set webpack module
*/
export const handleModule = ({
app,
options,
config,
isBuild,
isServer,
}: {
app: App
options: WebpackBundlerOptions
config: Config
isBuild: boolean
Expand All @@ -30,19 +27,19 @@ export const handleModule = ({
)

// vue files
handleModuleVue({ app, options, config, isServer })
handleModuleVue({ options, config, isServer })

// pug files, for templates
handleModulePug({ config })

// images & media & fonts
handleModuleAssets({ app, config })
handleModuleAssets({ config })

// js files
handleModuleJs({ options, config, isBuild, isServer })

// ts files
handleModuleTs({ app, config })
handleModuleTs({ config })

// styles files
handleModuleStyles({ options, config, isBuild, isServer })
Expand Down
9 changes: 1 addition & 8 deletions packages/bundler-webpack/src/config/handleModuleAssets.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import type { App } from '@vuepress/core'
import type Config from 'webpack-5-chain'

/**
* Set webpack config to handle assets files
*/
export const handleModuleAssets = ({
app,
config,
}: {
app: App
config: Config
}): void => {
export const handleModuleAssets = ({ config }: { config: Config }): void => {
// images
config.module
.rule('images')
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-webpack/src/config/handleModuleJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const handleModuleJs = ({
return false
}
// don't transpile node_modules
return /node_modules/.test(filePath)
return filePath.includes('node_modules')
})
.end()
// use esbuild-loader
Expand Down
17 changes: 6 additions & 11 deletions packages/bundler-webpack/src/config/handleModuleStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import autoprefixer from 'autoprefixer'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import type Config from 'webpack-5-chain'
import type {
LessLoaderOptions,
SassLoaderOptions,
StylePreprocessorLoaderOptions,
StylusLoaderOptions,
WebpackBundlerOptions,
} from '../types.js'

Expand All @@ -26,9 +23,7 @@ export const handleModuleStyles = ({
isBuild: boolean
isServer: boolean
}): void => {
const handleStyle = <
T extends StylePreprocessorLoaderOptions = StylePreprocessorLoaderOptions,
>({
const handleStyle = ({
lang,
test,
loaderName,
Expand All @@ -37,7 +32,7 @@ export const handleModuleStyles = ({
lang: string
test: RegExp
loaderName?: string
loaderOptions?: T
loaderOptions?: StylePreprocessorLoaderOptions
}): void => {
const rule = config.module.rule(lang).test(test)

Expand Down Expand Up @@ -94,28 +89,28 @@ export const handleModuleStyles = ({
test: /\.p(ost)?css$/,
})

handleStyle<SassLoaderOptions>({
handleStyle({
lang: 'scss',
test: /\.scss$/,
loaderName: 'sass-loader',
loaderOptions: options.scss,
})

handleStyle<SassLoaderOptions>({
handleStyle({
lang: 'sass',
test: /\.sass$/,
loaderName: 'sass-loader',
loaderOptions: options.sass,
})

handleStyle<LessLoaderOptions>({
handleStyle({
lang: 'less',
test: /\.less$/,
loaderName: 'less-loader',
loaderOptions: options.less,
})

handleStyle<StylusLoaderOptions>({
handleStyle({
lang: 'stylus',
test: /\.styl(us)?$/,
loaderName: 'stylus-loader',
Expand Down
9 changes: 1 addition & 8 deletions packages/bundler-webpack/src/config/handleModuleTs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createRequire } from 'node:module'
import type { App } from '@vuepress/core'
import type Config from 'webpack-5-chain'
import { resolveEsbuildJsxOptions } from './resolveEsbuildJsxOptions.js'

Expand All @@ -8,13 +7,7 @@ const require = createRequire(import.meta.url)
/**
* Set webpack module to handle ts files
*/
export const handleModuleTs = ({
app,
config,
}: {
app: App
config: Config
}): void => {
export const handleModuleTs = ({ config }: { config: Config }): void => {
config.module
.rule('ts')
.test(/\.tsx?/)
Expand Down
5 changes: 1 addition & 4 deletions packages/bundler-webpack/src/config/handleModuleVue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createRequire } from 'node:module'
import type { App } from '@vuepress/core'
import { VueLoaderPlugin } from 'vue-loader'
import type { VueLoaderOptions } from 'vue-loader'
import { VueLoaderPlugin } from 'vue-loader'
import type Config from 'webpack-5-chain'
import type { WebpackBundlerOptions } from '../types.js'

Expand All @@ -11,12 +10,10 @@ const require = createRequire(import.meta.url)
* Set webpack module to handle vue files
*/
export const handleModuleVue = ({
app,
options,
config,
isServer,
}: {
app: App
options: WebpackBundlerOptions
config: Config
isServer: boolean
Expand Down
10 changes: 7 additions & 3 deletions packages/bundler-webpack/src/config/handleOtherOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ export const handleOtherOptions = ({
isServer,
'version': app.version,
// dependencies
'esbuild-loader': require('esbuild-loader/package.json').version,
'vue-loader': require('vue-loader/package.json').version,
'webpack': require('webpack/package.json').version,
'esbuild-loader': (
require('esbuild-loader/package.json') as { version: string }
).version,
'vue-loader': (require('vue-loader/package.json') as { version: string })
.version,
'webpack': (require('webpack/package.json') as { version: string })
.version,
}),
})
}
8 changes: 4 additions & 4 deletions packages/bundler-webpack/src/config/handleResolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export const handleResolve = async ({
const aliasResult = await app.pluginApi.hooks.alias.process(app, isServer)

// set aliases
aliasResult.forEach((aliasObject) =>
aliasResult.forEach((aliasObject) => {
Object.entries(aliasObject).forEach(([key, value]) => {
config.resolve.alias.set(key, value)
}),
)
config.resolve.alias.set(key, value as string)
})
})
}
4 changes: 2 additions & 2 deletions packages/bundler-webpack/src/webpackBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export const webpackBundler = (
options: WebpackBundlerOptions = {},
): Bundler => ({
name: '@vuepress/bundler-webpack',
dev: (app) => dev(options, app),
build: (app) => build(options, app),
dev: async (app) => dev(options, app),
build: async (app) => build(options, app),
})
8 changes: 5 additions & 3 deletions packages/cli/src/commands/dev/watchPageFiles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-misused-promises */
import type { App, Page } from '@vuepress/core'
import { colors, logger } from '@vuepress/utils'
import chokidar from 'chokidar'
import type { FSWatcher } from 'chokidar'
import chokidar from 'chokidar'
import { handlePageAdd } from './handlePageAdd.js'
import { handlePageChange } from './handlePageChange.js'
import { handlePageUnlink } from './handlePageUnlink.js'
Expand All @@ -27,7 +28,6 @@ export const watchPageFiles = (app: App): FSWatcher[] => {
}
const depsListener = async (dep: string): Promise<void> => {
const pagePaths = depsHelper.get(dep)
if (!pagePaths) return
for (const filePathRelative of pagePaths) {
logger.info(
`dependency of page ${colors.magenta(filePathRelative)} is modified`,
Expand All @@ -38,7 +38,9 @@ export const watchPageFiles = (app: App): FSWatcher[] => {
depsWatcher.on('add', depsListener)
depsWatcher.on('change', depsListener)
depsWatcher.on('unlink', depsListener)
app.pages.forEach((page) => addDeps(page))
app.pages.forEach((page) => {
addDeps(page)
})

// watch page files
const pagesWatcher = chokidar.watch(app.options.pagePatterns, {
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import type { AppConfig, PluginObject } from '@vuepress/core'
*
* It will be transformed to `AppConfig` by cli
*/
export type UserConfig = Partial<AppConfig> &
// user config can be used as a plugin
Omit<PluginObject, 'name' | 'multiple'>
export type UserConfig = Omit<PluginObject, 'multiple' | 'name'> &
Partial<AppConfig>
1 change: 1 addition & 0 deletions packages/client/src/components/RouteLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const guardEvent = (event: MouseEvent): boolean | void => {
// don't redirect when preventDefault called
if (event.defaultPrevented) return
// don't redirect on right click
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (event.button !== undefined && event.button !== 0) return
// don't redirect if `target="_blank"`
if (event.currentTarget) {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/composables/clientDataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export const usePageComponent = (): PageComponentRef =>
useClientData().pageComponent

export const usePageData = <
T extends Record<any, any> = Record<never, never>,
T extends Record<string, unknown> = Record<string, unknown>,
>(): PageDataRef<T> => useClientData().pageData as PageDataRef<T>

export const usePageFrontmatter = <
T extends Record<any, any> = Record<string, unknown>,
T extends Record<string, unknown> = Record<string, unknown>,
>(): PageFrontmatterRef<T> =>
useClientData().pageFrontmatter as PageFrontmatterRef<T>

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/composables/updateHead.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject } from 'vue'
import type { InjectionKey } from 'vue'
import { inject } from 'vue'

/**
* A util function to force update `<head>` of current page
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/internal/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
redirects as redirectsRaw,
routes as routesRaw,
} from '@internal/routes'
import { shallowRef } from 'vue'
import type { Ref } from 'vue'
import { shallowRef } from 'vue'
import type { Redirects, Routes } from '../types/index.js'

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const resolvers = reactive({
const layoutName = isString(pageData.frontmatter.layout)
? pageData.frontmatter.layout
: LAYOUT_NAME_DEFAULT
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- unsafe indexed access
if (!layouts[layoutName]) {
throw new Error(`[vuepress] Cannot resolve layout: ${layoutName}`)
}
Expand Down Expand Up @@ -113,8 +114,9 @@ export const resolvers = reactive({
head: [
// when merging head, the locales head should be placed before root head
// to get higher priority
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- unsafe indexed access
...(locales[routeLocale]?.head ?? []),
...(siteData.head ?? []),
...siteData.head,
],
}),
})
Loading

0 comments on commit ddea4de

Please sign in to comment.