Skip to content

Commit 324386d

Browse files
authored
fix(cli/eject): fix the component path not right (#2896)
1 parent 6b80077 commit 324386d

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

packages/core/src/node/PluginDriver.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export class PluginDriver {
112112
}
113113

114114
private async normalizeConfig() {
115+
this.#config.root ??= 'docs';
115116
this.#config.ssg ??= true;
116117
this.#config.llms ??= false;
117118
this.#config.base = addTrailingSlash(

packages/core/src/node/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const PACKAGE_ROOT = path.dirname(
3333
require.resolve('@rspress/core/package.json'),
3434
);
3535
export const DEFAULT_THEME = path.join(PACKAGE_ROOT, 'dist/theme');
36+
export const EJECTED_THEME = path.join(PACKAGE_ROOT, 'dist/eject-theme');
3637
export const TEMPLATE_PATH = path.join(PACKAGE_ROOT, 'index.html');
3738

3839
export const CSR_CLIENT_ENTRY = path.join(

packages/core/src/node/eject.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import fs from 'node:fs/promises';
22
import path from 'node:path';
3-
import { fileURLToPath } from 'node:url';
43
import { logger } from '@rspress/shared/logger';
54
import picocolors from 'picocolors';
6-
7-
const __filename = fileURLToPath(import.meta.url);
8-
const __dirname = path.dirname(__filename);
5+
import { EJECTED_THEME } from './constants';
96

107
// For testing purposes, allow overriding the theme path
118
let _themeComponentsPathOverride: string | undefined;
@@ -23,7 +20,7 @@ function getThemeComponentsPath(): string {
2320
if (_themeComponentsPathOverride) {
2421
return _themeComponentsPathOverride;
2522
}
26-
return path.join(__dirname, 'eject-theme/components');
23+
return path.join(EJECTED_THEME, 'components');
2724
}
2825

2926
/**

packages/core/src/node/initRsbuild.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createRequire } from 'node:module';
22
import path from 'node:path';
3+
import { cwd } from 'node:process';
34
import { fileURLToPath } from 'node:url';
45
import type {
56
RsbuildConfig,
@@ -89,7 +90,9 @@ async function createInternalBuildConfig(
8990
routeService: RouteService,
9091
pluginDriver: PluginDriver,
9192
): Promise<RsbuildConfig> {
92-
const CUSTOM_THEME_DIR = config.themeDir!;
93+
const CUSTOM_THEME_DIR = path.isAbsolute(config.themeDir!)
94+
? config.themeDir!
95+
: path.join(cwd(), config.themeDir!);
9396
const outDir = config?.outDir ?? OUTPUT_DIR;
9497

9598
const base = config?.base ?? '';
@@ -363,7 +366,7 @@ async function createInternalBuildConfig(
363366
chain.resolve.extensions.prepend('.md').prepend('.mdx').prepend('.mjs');
364367

365368
chain.module
366-
.rule('css-virtual-module')
369+
.rule('rspress-css-virtual-module')
367370
.test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/)
368371
.merge({ sideEffects: true });
369372

@@ -499,8 +502,7 @@ export async function initRsbuild(
499502
enableSSG: boolean,
500503
extraRsbuildConfig?: RsbuildConfig,
501504
): Promise<RsbuildInstance> {
502-
const cwd = process.cwd();
503-
const userDocRoot = path.resolve(rootDir || config?.root || cwd);
505+
const userDocRoot = path.resolve(rootDir || config.root!);
504506

505507
hintBuilderPluginsBreakingChange(config);
506508

0 commit comments

Comments
 (0)