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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)