Skip to content

Commit b9e865b

Browse files
authored
chore(infra): implement click to reference by tsconfig.reference (#1790)
1 parent 658d1f2 commit b9e865b

File tree

22 files changed

+167
-50
lines changed

22 files changed

+167
-50
lines changed

packages/cli/src/update.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { spawn } from 'node:child_process';
22
import fs from 'node:fs/promises';
33
import path from 'node:path';
4-
import { pathExists } from '@rspress/shared/fs-extra';
4+
import fse from '@rspress/shared/fs-extra';
55
import { logger } from '@rspress/shared/logger';
66

77
type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';
@@ -16,7 +16,7 @@ const lockfileMap: Record<string, PackageManager> = {
1616
async function getPackageManager(rootPath: string) {
1717
let packageManager: PackageManager = 'npm';
1818
for (const file of Object.keys(lockfileMap)) {
19-
if (await pathExists(path.join(rootPath, file))) {
19+
if (await fse.pathExists(path.join(rootPath, file))) {
2020
packageManager = lockfileMap[file];
2121
break;
2222
}

packages/cli/tsconfig.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717
"runtime.ts",
1818
"theme.ts"
1919
],
20-
"exclude": ["**/node_modules"]
20+
"exclude": ["**/node_modules"],
21+
"references": [
22+
{
23+
"path": "../core"
24+
},
25+
{
26+
"path": "../shared"
27+
}
28+
]
2129
}

packages/core/src/node/runtimeModule/siteData/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export async function siteDataVMPlugin(context: FactoryContext) {
107107
pages.map(async pageData => pluginDriver.extendPageData(pageData)),
108108
);
109109

110-
const siteData: SiteData = {
110+
const siteData: Omit<SiteData, 'root'> = {
111111
title: userConfig?.title || '',
112112
description: userConfig?.description || '',
113113
icon: userConfig?.icon || '',

packages/core/src/node/utils/flattenMdxContent.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ export async function flattenMdxContent(
9191
let result = content;
9292

9393
try {
94-
ast = processor.parse(content) as Root;
94+
ast = processor.parse(content) as unknown as Root;
9595
} catch (e) {
9696
// Fallback: if mdx parse failed, just return the content
9797
return { flattenContent: content, deps };
9898
}
9999

100100
const importNodes = ast.children
101101
.filter(node => node.type === ('mdxjsEsm' as any))
102-
.flatMap(node => (node.data?.estree as ESTree)?.body || [])
102+
.flatMap(node => ((node.data as any)?.estree as ESTree)?.body || [])
103103
.filter(node => node.type === 'ImportDeclaration');
104104
for (const importNode of importNodes) {
105105
// import Comp from './a';

packages/core/tsconfig.json

+28-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
54
"strict": false,
5+
"declaration": true,
6+
"noEmit": false,
7+
"declarationDir": "dist",
68
"module": "ESNext",
79
"target": "ESNext",
810
"jsx": "react-jsx",
911
"baseUrl": "src",
10-
"rootDir": ".",
12+
"rootDir": "src",
13+
"composite": true,
1114
"lib": ["ESNext", "DOM"],
1215
"esModuleInterop": true,
1316
"skipLibCheck": true,
@@ -17,11 +20,29 @@
1720
"@/theme-default/*": ["./theme-default/*"]
1821
}
1922
},
20-
"include": [
21-
"src",
22-
"vitest.config.ts",
23-
"./modern.config.ts",
24-
"./tailwind.config.ts"
23+
"include": ["src"],
24+
"references": [
25+
{
26+
"path": "../plugin-auto-nav-sidebar"
27+
},
28+
{
29+
"path": "../plugin-last-updated"
30+
},
31+
{
32+
"path": "../plugin-container-syntax"
33+
},
34+
{
35+
"path": "../plugin-medium-zoom"
36+
},
37+
{
38+
"path": "../shared"
39+
},
40+
{
41+
"path": "../theme-default"
42+
},
43+
{
44+
"path": "../runtime"
45+
}
2546
],
2647
"exclude": ["runtime.ts", "theme.ts", "node_modules"]
2748
}

packages/modern-plugin-rspress/tests/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"jsx": "preserve",
66
"baseUrl": "./",
77
"outDir": "./out",
8-
"emitDeclarationOnly": true,
8+
"noEmit": false,
99
"isolatedModules": true,
1010
"paths": {},
1111
"types": ["node", "jest"]
+14-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
4+
"declaration": true,
5+
"noEmit": false,
6+
"outDir": "dist",
57
"jsx": "preserve",
68
"baseUrl": "./"
79
},
10+
"references": [
11+
{
12+
"path": "../core"
13+
},
14+
{
15+
"path": "../plugin-api-docgen"
16+
},
17+
{
18+
"path": "../plugin-preview"
19+
}
20+
],
821
"include": ["src", "static", "rslib.config.ts"]
922
}
+12-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
4+
"composite": true,
5+
"declaration": true,
6+
"noEmit": false,
57
"module": "ESNext",
68
"target": "ESNext",
79
"jsx": "react-jsx",
810
"baseUrl": "src",
9-
"rootDir": ".",
11+
"rootDir": "src",
1012
"lib": ["ESNext", "DOM"],
1113
"esModuleInterop": true,
1214
"skipLibCheck": true,
13-
"noEmit": true,
1415
"paths": {
1516
"@/*": ["./*"]
1617
}
1718
},
18-
"include": [
19-
"src",
20-
"vitest.config.ts",
21-
"index.d.ts",
22-
"mdx-meta-loader.cjs",
23-
"static/"
19+
"references": [
20+
{
21+
"path": "../core"
22+
},
23+
{
24+
"path": "../shared"
25+
}
2426
],
27+
"include": ["src"],
2528
"exclude": ["runtime.d.ts", "theme.d.ts", "node_modules", "dist"]
2629
}

packages/plugin-auto-nav-sidebar/tsconfig.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
4+
"declaration": true,
5+
"noEmit": false,
6+
"composite": true,
7+
"outDir": "dist",
8+
"noImplicitAny": false,
59
"module": "ESNext",
610
"target": "ESNext",
711
"jsx": "react-jsx",
@@ -14,6 +18,11 @@
1418
"@/*": ["./*"]
1519
}
1620
},
21+
"references": [
22+
{
23+
"path": "../shared"
24+
}
25+
],
1726
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
1827
"exclude": ["node_modules", "dist"]
1928
}

packages/plugin-client-redirects/tsconfig.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
4+
"composite": true,
5+
"declaration": true,
56
"module": "ESNext",
67
"target": "ESNext",
78
"jsx": "react-jsx",
@@ -14,6 +15,11 @@
1415
"@/*": ["./*"]
1516
}
1617
},
18+
"references": [
19+
{
20+
"path": "../shared"
21+
}
22+
],
1723
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
1824
"exclude": ["node_modules", "dist"]
1925
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
4+
"composite": true,
5+
"declaration": true,
56
"module": "ESNext",
67
"target": "ESNext",
78
"jsx": "react-jsx",
89
"baseUrl": "src",
9-
"rootDir": ".",
10+
"rootDir": "src",
1011
"lib": ["ESNext", "DOM"],
1112
"esModuleInterop": true,
1213
"skipLibCheck": true,
1314
"paths": {
1415
"@/*": ["./*"]
1516
}
1617
},
17-
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
18+
"references": [
19+
{
20+
"path": "../shared"
21+
}
22+
],
23+
"include": ["src"],
1824
"exclude": ["node_modules", "dist"]
1925
}
+10-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
4+
"declaration": true,
5+
"composite": true,
56
"module": "ESNext",
67
"target": "ESNext",
78
"jsx": "react-jsx",
9+
"outDir": "dist",
810
"baseUrl": "src",
9-
"rootDir": ".",
11+
"rootDir": "src",
1012
"lib": ["ESNext", "DOM"],
1113
"esModuleInterop": true,
1214
"skipLibCheck": true,
1315
"paths": {
1416
"@/*": ["./*"]
1517
}
1618
},
17-
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
19+
"references": [
20+
{
21+
"path": "../shared"
22+
}
23+
],
24+
"include": ["src"],
1825
"exclude": ["node_modules", "dist"]
1926
}
+6-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
4+
"declaration": true,
5+
"noEmit": false,
6+
"outDir": "dist",
7+
"composite": true,
58
"module": "ESNext",
69
"target": "ESNext",
710
"jsx": "react-jsx",
811
"baseUrl": "src",
9-
"rootDir": ".",
12+
"rootDir": "src",
1013
"lib": ["ESNext", "DOM"],
1114
"esModuleInterop": true,
1215
"skipLibCheck": true,
1316
"paths": {
1417
"@/*": ["./*"]
1518
}
1619
},
17-
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
20+
"include": ["src"],
1821
"exclude": ["node_modules", "dist"]
1922
}
+6-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
4+
"declaration": true,
5+
"composite": true,
6+
"noEmit": false,
7+
"outDir": "dist",
58
"module": "ESNext",
69
"target": "ESNext",
710
"jsx": "react-jsx",
811
"baseUrl": "src",
9-
"rootDir": ".",
12+
"rootDir": "src",
1013
"lib": ["ESNext", "DOM"],
1114
"esModuleInterop": true,
1215
"skipLibCheck": true,
1316
"paths": {
1417
"@/*": ["./*"]
1518
}
1619
},
17-
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
20+
"include": ["src"],
1821
"exclude": ["node_modules", "dist"]
1922
}

packages/plugin-preview/tsconfig.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"extends": "@modern-js/tsconfig/base",
33
"compilerOptions": {
4-
"declaration": false,
4+
"composite": true,
5+
"noEmit": false,
6+
"declaration": true,
7+
"declarationDir": "dist",
58
"module": "ESNext",
69
"target": "ESNext",
710
"jsx": "react-jsx",
@@ -10,7 +13,6 @@
1013
"lib": ["ESNext", "DOM"],
1114
"esModuleInterop": true,
1215
"skipLibCheck": true,
13-
"noEmit": true,
1416
"paths": {
1517
"@/*": ["./*"]
1618
}
@@ -23,5 +25,13 @@
2325
"static/",
2426
"rslib.config.ts"
2527
],
28+
"references": [
29+
{
30+
"path": "../shared"
31+
},
32+
{
33+
"path": "../theme-default"
34+
}
35+
],
2636
"exclude": ["runtime.d.ts", "theme.d.ts", "node_modules", "dist"]
2737
}

packages/plugin-rss/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"include": ["src"],
1212
"references": [
1313
{ "path": "./tsconfig.runtime.json" },
14-
{ "path": "./tsconfig.tools.json" }
14+
{ "path": "./tsconfig.tools.json" },
15+
{ "path": "../runtime" }
1516
]
1617
}

0 commit comments

Comments
 (0)