Skip to content
Merged
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
11 changes: 11 additions & 0 deletions .changeset/fix-esm-dirname.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'rspress-plugin-google-analytics': patch
'rspress-plugin-back-to-top': patch
'rspress-plugin-file-tree': patch
'rspress-plugin-live2d': patch
'rspress-plugin-mermaid': patch
'rspress-plugin-reading-time': patch
'rspress-plugin-vercel-analytics': patch
---

fix: replace `__dirname` with ESM-compatible `import.meta.url` to fix `ReferenceError: __dirname is not defined` when loading plugins as ESM
4 changes: 4 additions & 0 deletions packages/rspress-plugin-back-to-top/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { PresetConfigMutator } from 'rspress-plugin-devkit';

import type { RspressPlugin } from '@rspress/core';
import type { Back2TopProps } from './components/Back2Top';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export const componentsPath = path.join(__dirname, './components');

export interface RspressPluginBack2TopOptions extends Back2TopProps {}
Expand Down
4 changes: 4 additions & 0 deletions packages/rspress-plugin-file-tree/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { RemarkCodeBlockToGlobalComponentPluginFactory } from 'rspress-plugin-devkit';

import { parseTreeContent } from './components/tree-parser/tree-parser';

import type { RspressPlugin } from '@rspress/core';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

interface RspressPluginFileTreeOptions {
initialExpandDepth?: number;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/rspress-plugin-google-analytics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { ensureArray, type MaybeArray } from 'rspress-plugin-devkit';

import type { RspressPlugin } from '@rspress/core';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

interface RspressPluginSiteMapOptions {
id: MaybeArray<string>;
Expand Down
4 changes: 4 additions & 0 deletions packages/rspress-plugin-live2d/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import type { RspressPlugin } from '@rspress/core';
import type { Live2DWidgetProps } from './typings';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export interface RspressPluginLive2dOptions extends Live2DWidgetProps {}

export default function rspressPluginLive2d(
Expand Down
4 changes: 4 additions & 0 deletions packages/rspress-plugin-mermaid/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import {
PresetConfigMutator,
Expand All @@ -9,6 +10,9 @@ import type { RspressPlugin } from '@rspress/core';
import type { MermaidConfig } from 'mermaid';
import type { MermaidRendererProps } from './typings';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

interface RspressPluginMermaidOptions {
mermaidConfig?: MermaidConfig;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/rspress-plugin-reading-time/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import readingTime, { type ReadTimeResults } from 'reading-time';

Expand All @@ -10,6 +11,9 @@ import {

import type { RspressPlugin } from '@rspress/core';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export interface RspressPluginReadingTimeOptions extends WithDefaultLocale {
getReadingTime?: (content: string) => ReadTimeResults;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/rspress-plugin-vercel-analytics/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import type { RspressPlugin } from '@rspress/core';
import type { VercelAnalyticsProps } from './typings';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

interface RspressPluginVercelAnalyticsOptions extends VercelAnalyticsProps {}

export default function rspressPluginVercelAnalytics(
Expand Down