Skip to content

Commit 932d722

Browse files
authored
feat!: rebuild isModuleAvailable and getModulePath with import.meta.resolve (#295)
1 parent 4b380ba commit 932d722

File tree

66 files changed

+183
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+183
-213
lines changed

commitlint.config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { readdirSync, statSync } from 'node:fs'
2-
import { dirname, join } from 'node:path'
3-
import { fileURLToPath } from 'node:url'
2+
import { join } from 'node:path'
3+
import { getDirname } from 'vuepress/utils'
44

5-
const __dirname = dirname(fileURLToPath(import.meta.url))
5+
const __dirname = getDirname(import.meta.url)
66

77
const getSubDirectories = (dir: string): string[] =>
88
readdirSync(dir).filter((item) => statSync(join(dir, item)).isDirectory())

docs/.vuepress/config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import process from 'node:process'
22
import { viteBundler } from '@vuepress/bundler-vite'
33
import { webpackBundler } from '@vuepress/bundler-webpack'
4-
import { getRealPath } from '@vuepress/helper'
4+
import { getModulePath } from '@vuepress/helper'
55
import { cachePlugin } from '@vuepress/plugin-cache'
66
import { catalogPlugin } from '@vuepress/plugin-catalog'
77
import { commentPlugin } from '@vuepress/plugin-comment'
@@ -21,7 +21,7 @@ import { getDirname, path } from 'vuepress/utils'
2121
import { head } from './configs/index.js'
2222
import theme from './theme.js'
2323

24-
const __dirname = getDirname(import.meta.url)
24+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
2525

2626
const IS_PROD = process.env.NODE_ENV === 'production'
2727

@@ -60,7 +60,7 @@ export default defineUserConfig({
6060
const realPath = importPath.replace(
6161
packageName,
6262
path.dirname(
63-
getRealPath(`${packageName}/package.json`, import.meta.url),
63+
getModulePath(`${packageName}/package.json`, import.meta),
6464
),
6565
)
6666

docs/plugins/tools/register-components.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default {
4343
```ts
4444
import { getDirname, path } from 'vuepress/utils'
4545

46-
const __dirname = getDirname(import.meta.url)
46+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
4747

4848
export default {
4949
plugins: [
@@ -73,7 +73,7 @@ export default {
7373
```ts
7474
import { getDirname, path } from 'vuepress/utils'
7575

76-
const __dirname = getDirname(import.meta.url)
76+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
7777

7878
export default {
7979
plugins: [

docs/themes/default/extending.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import { defaultTheme } from '@vuepress/theme-default'
7272
import { defineUserConfig } from 'vuepress'
7373
import { getDirname, path } from 'vuepress/utils'
7474

75-
const __dirname = getDirname(import.meta.url)
75+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
7676

7777
export default defineUserConfig({
7878
theme: defaultTheme(),
@@ -101,7 +101,7 @@ import { defaultTheme } from '@vuepress/theme-default'
101101
import type { Theme } from 'vuepress/core'
102102
import { getDirname, path } from 'vuepress/utils'
103103

104-
const __dirname = getDirname(import.meta.url)
104+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
105105

106106
export const childTheme = (options: DefaultThemeOptions): Theme => ({
107107
name: 'vuepress-theme-child',

docs/zh/plugins/tools/register-components.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default {
4343
```ts
4444
import { getDirname, path } from 'vuepress/utils'
4545

46-
const __dirname = getDirname(import.meta.url)
46+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
4747

4848
export default {
4949
plugins: [
@@ -73,7 +73,7 @@ export default {
7373
```ts
7474
import { getDirname, path } from 'vuepress/utils'
7575

76-
const __dirname = getDirname(import.meta.url)
76+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
7777

7878
export default {
7979
plugins: [

docs/zh/themes/default/extending.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import { defaultTheme } from '@vuepress/theme-default'
7272
import { defineUserConfig } from 'vuepress'
7373
import { getDirname, path } from 'vuepress/utils'
7474

75-
const __dirname = getDirname(import.meta.url)
75+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
7676

7777
export default defineUserConfig({
7878
theme: defaultTheme(),
@@ -101,7 +101,7 @@ import { defaultTheme } from '@vuepress/theme-default'
101101
import type { Theme } from 'vuepress/core'
102102
import { getDirname, path } from 'vuepress/utils'
103103

104-
const __dirname = getDirname(import.meta.url)
104+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
105105

106106
export const childTheme = (options: DefaultThemeOptions): Theme => ({
107107
name: 'vuepress-theme-child',

e2e/docs/.vuepress/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { defaultTheme } from '@vuepress/theme-default'
1515
import { defineUserConfig } from 'vuepress/cli'
1616
import { getDirname, path } from 'vuepress/utils'
1717

18-
const __dirname = getDirname(import.meta.url)
18+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
1919

2020
const E2E_BASE = (process.env.E2E_BASE ?? '/') as '/' | `/${string}/`
2121
const E2E_BUNDLER = process.env.E2E_BUNDLER ?? 'vite'

plugins/analytics/plugin-baidu-analytics/src/node/baiduAnalyticsPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Plugin, PluginObject } from 'vuepress/core'
33
import { colors, getDirname, path } from 'vuepress/utils'
44
import type { BaiduAnalyticsPluginOptions } from './options.js'
55

6-
const __dirname = getDirname(import.meta.url)
6+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
77

88
const PLUGIN_NAME = '@vuepress/plugin-baidu-analytics'
99

plugins/analytics/plugin-google-analytics/src/node/googleAnalyticsPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Plugin, PluginObject } from 'vuepress/core'
22
import { getDirname, logger, path } from 'vuepress/utils'
33
import type { GoogleAnalyticsPluginOptions } from '../shared/index.js'
44

5-
const __dirname = getDirname(import.meta.url)
5+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
66

77
export const googleAnalyticsPlugin =
88
(options: GoogleAnalyticsPluginOptions): Plugin =>

plugins/analytics/plugin-umami-analytics/src/node/umamiAnalyticsPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Plugin, PluginObject } from 'vuepress/core'
33
import { colors, getDirname, path } from 'vuepress/utils'
44
import type { UmamiOptions } from '../shared/index.js'
55

6-
const __dirname = getDirname(import.meta.url)
6+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
77

88
const PLUGIN_NAME = '@vuepress/plugin-umami-analytics'
99

plugins/blog/plugin-comment/src/node/commentPlugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
addViteOptimizeDepsInclude,
55
addViteSsrExternal,
66
addViteSsrNoExternal,
7-
getInstalledStatus,
87
getLocaleConfig,
8+
isModuleAvailable,
99
} from '@vuepress/helper'
1010
import type { PluginFunction } from 'vuepress/core'
1111
import { getAlias, getProviderPackage } from './getProvider.js'
@@ -21,7 +21,7 @@ export const commentPlugin =
2121

2222
const pkg = getProviderPackage(options.provider)
2323

24-
if (pkg && !getInstalledStatus(pkg, import.meta.url)) {
24+
if (pkg && !isModuleAvailable(pkg, import.meta)) {
2525
logger.error(
2626
`Package ${pkg} is not installed, please install it manually!`,
2727
)

plugins/blog/plugin-comment/src/node/getProvider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getRealPath } from '@vuepress/helper'
1+
import { getModulePath } from '@vuepress/helper'
22
import type { CommentPluginOptions } from './options.js'
33
import { CLIENT_FOLDER, PLUGIN_NAME, logger } from './utils.js'
44

@@ -11,7 +11,7 @@ export const getServiceComponent = (provider = 'None'): string => {
1111

1212
if (provider !== 'None') logger.error(`Invalid provider: ${provider}`)
1313

14-
return getRealPath('@vuepress/helper/noopModule', import.meta.url)
14+
return getModulePath('@vuepress/helper/noopModule', import.meta)
1515
}
1616

1717
export const getPageviewChunk = (provider = 'None'): string =>

plugins/blog/plugin-comment/src/node/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Logger, ensureEndingSlash } from '@vuepress/helper'
22
import { getDirname, path } from 'vuepress/utils'
33

4-
const __dirname = getDirname(import.meta.url)
4+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
55

66
export const CLIENT_FOLDER = ensureEndingSlash(
77
path.resolve(__dirname, '../client'),

plugins/blog/plugin-feed/src/node/getTemplates.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { FeedConfig } from '../typings/index.js'
55
import { getFeedFilenames } from './getFeedFilenames.js'
66
import type { ResolvedFeedOptionsMap } from './getFeedOptions.js'
77

8-
const __dirname = getDirname(import.meta.url)
8+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
99

1010
const TEMPLATE_FOLDER = ensureEndingSlash(
1111
path.resolve(__dirname, '../../templates'),

plugins/development/plugin-active-header-links/src/node/activeHeaderLinksPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Plugin } from 'vuepress/core'
22
import { getDirname, path } from 'vuepress/utils'
33

4-
const __dirname = getDirname(import.meta.url)
4+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
55

66
/**
77
* Options for @vuepress/plugin-active-header-links

plugins/development/plugin-rtl/src/node/rtlPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface RTLPluginOptions {
2121
}
2222
}
2323

24-
const __dirname = getDirname(import.meta.url)
24+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
2525

2626
export const rtlPlugin = (options: RTLPluginOptions = {}): PluginObject => ({
2727
name: '@vuepress/plugin-rtl',

plugins/development/plugin-sass-palette/src/node/sassPalettePlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from './prepare/index.js'
1414
import { EMPTY_FILE, PLUGIN_NAME, getIdPrefix, logger } from './utils.js'
1515

16-
const __dirname = getDirname(import.meta.url)
16+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
1717

1818
export const sassPalettePlugin =
1919
(options: SassPalettePluginOptions): PluginFunction =>

plugins/development/plugin-sass-palette/src/node/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Logger } from '@vuepress/helper'
22
import { fs, getDirname, path } from 'vuepress/utils'
33

4-
const __dirname = getDirname(import.meta.url)
4+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
55

66
export const EMPTY_FILE = path.resolve(__dirname, '../../styles/empty.scss')
77

plugins/development/plugin-theme-data/src/node/themeDataPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getDirname, path } from 'vuepress/utils'
33
import type { ThemeData } from '../shared/index.js'
44
import { prepareThemeData } from './prepareThemeData.js'
55

6-
const __dirname = getDirname(import.meta.url)
6+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
77

88
/**
99
* Options of @vuepress/plugin-theme-data

plugins/development/plugin-toc/src/node/tocPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Plugin } from 'vuepress/core'
22
import { getDirname, path } from 'vuepress/utils'
33
import type { TocPropsOptions } from '../shared/index.js'
44

5-
const __dirname = getDirname(import.meta.url)
5+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
66

77
/**
88
* Options for @vuepress/plugin-toc

plugins/features/plugin-back-to-top/src/node/backToTopPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { backToTopLocales } from './locales.js'
55
import { PLUGIN_NAME } from './logger.js'
66
import type { BackToTopPluginOptions } from './options.js'
77

8-
const __dirname = getDirname(import.meta.url)
8+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
99

1010
export const backToTopPlugin =
1111
(options: BackToTopPluginOptions = {}): Plugin =>

plugins/features/plugin-catalog/src/node/catalogPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { catalogLocales as defaultLocales } from './locales.js'
66
import { PLUGIN_NAME, logger } from './logger.js'
77
import type { CatalogPluginOptions } from './options.js'
88

9-
const __dirname = getDirname(import.meta.url)
9+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
1010

1111
export const catalogPlugin =
1212
(options: CatalogPluginOptions = {}): PluginFunction =>

plugins/features/plugin-copy-code/src/node/copyCodePlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { copyCodeLocales } from './locales.js'
1010
import { PLUGIN_NAME, logger } from './logger.js'
1111
import type { CopyCodePluginOptions } from './options.js'
1212

13-
const __dirname = getDirname(import.meta.url)
13+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
1414

1515
export const copyCodePlugin =
1616
(options: CopyCodePluginOptions = {}): PluginFunction =>

plugins/features/plugin-copyright/src/node/copyrightPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const PLUGIN_NAME = '@vuepress/plugin-copyright'
1212

1313
export const logger = new Logger(PLUGIN_NAME)
1414

15-
const __dirname = getDirname(import.meta.url)
15+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
1616

1717
export const copyrightPlugin =
1818
(options: CopyrightPluginOptions = {}): PluginFunction =>

plugins/features/plugin-medium-zoom/src/node/mediumZoomPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ZoomOptions } from 'medium-zoom'
22
import type { Plugin } from 'vuepress/core'
33
import { getDirname, path } from 'vuepress/utils'
44

5-
const __dirname = getDirname(import.meta.url)
5+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
66

77
/**
88
* Options for @vuepress/plugin-medium-zoom

plugins/features/plugin-notice/src/node/noticePlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getNoticeOptions } from './getNoticeOptions.js'
44
import { PLUGIN_NAME } from './logger.js'
55
import type { NoticePluginOptions } from './options.js'
66

7-
const __dirname = getDirname(import.meta.url)
7+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
88

99
export const noticePlugin =
1010
(options: NoticePluginOptions): Plugin =>

plugins/features/plugin-nprogress/src/node/nprogressPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Plugin } from 'vuepress/core'
22
import { getDirname, path } from 'vuepress/utils'
33

4-
const __dirname = getDirname(import.meta.url)
4+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
55

66
export const nprogressPlugin = (): Plugin => ({
77
name: '@vuepress/plugin-nprogress',

plugins/features/plugin-photo-swipe/src/node/photoSwipePlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { photoSwipeLocales } from './locales.js'
1111
import { PLUGIN_NAME, logger } from './logger.js'
1212
import type { PhotoSwipePluginOptions } from './options.js'
1313

14-
const __dirname = getDirname(import.meta.url)
14+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
1515

1616
export const photoSwipePlugin =
1717
(options: PhotoSwipePluginOptions = {}): PluginFunction =>

plugins/features/plugin-watermark/src/node/watermarkPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getDirname, path } from 'vuepress/utils'
44
import { PLUGIN_NAME, logger } from './logger.js'
55
import type { WatermarkPluginOptions } from './options.js'
66

7-
const __dirname = getDirname(import.meta.url)
7+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
88

99
export const watermarkPlugin =
1010
({ enabled = true, ...options }: WatermarkPluginOptions = {}): Plugin =>

plugins/markdown/plugin-append-date/src/node/checkGitPlugin.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import { createRequire } from 'node:module'
21
import type { App } from 'vuepress/core'
32
import { colors } from 'vuepress/utils'
43
import { logger } from './logger.js'
54

6-
const require = createRequire(import.meta.url)
7-
85
const GIT_PLUGIN_NAME = '@vuepress/plugin-git'
96

107
export const isGitPluginEnabled = (app: App): boolean => {
118
if (
129
app.pluginApi.plugins.every((plugin) => plugin.name !== GIT_PLUGIN_NAME)
1310
) {
1411
try {
15-
require.resolve(GIT_PLUGIN_NAME)
12+
import.meta.resolve(GIT_PLUGIN_NAME)
1613

1714
logger.info(`${colors.magenta(GIT_PLUGIN_NAME)} is not enabled.`)
1815

plugins/markdown/plugin-markdown-ext/src/node/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Logger, ensureEndingSlash } from '@vuepress/helper'
22
import { getDirname, path } from 'vuepress/utils'
33

4-
const __dirname = getDirname(import.meta.url)
4+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
55

66
export const PLUGIN_NAME = '@vuepress/plugin-markdown-ext'
77

plugins/markdown/plugin-markdown-hint/src/node/markdownHintPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { MarkdownHintPluginOptions } from './options.js'
99

1010
const PLUGIN_NAME = '@vuepress/plugin-markdown-hint'
1111

12-
const __dirname = getDirname(import.meta.url)
12+
const __dirname = import.meta.dirname || getDirname(import.meta.url)
1313

1414
export const markdownHintPlugin = (
1515
options: MarkdownHintPluginOptions,

plugins/markdown/plugin-markdown-image/src/node/prepare/prepareClientConfigFile.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getRealPath } from '@vuepress/helper'
1+
import { getModulePath } from '@vuepress/helper'
22
import type { App } from 'vuepress'
33
import type { MarkdownImagePluginOptions } from '../options.js'
44
import { PLUGIN_NAME } from '../utils.js'
@@ -11,13 +11,13 @@ export const prepareClientConfigFile = async (
1111

1212
if (figure) {
1313
content += `\
14-
import "${getRealPath(`${PLUGIN_NAME}/figure.css`, import.meta.url)}"
14+
import "${getModulePath(`${PLUGIN_NAME}/figure.css`, import.meta)}"
1515
`
1616
}
1717

1818
if (mark) {
1919
content += `\
20-
import "${getRealPath(`${PLUGIN_NAME}/mark.css`, import.meta.url)}"
20+
import "${getModulePath(`${PLUGIN_NAME}/mark.css`, import.meta)}"
2121
`
2222
}
2323

0 commit comments

Comments
 (0)