Skip to content

Commit

Permalink
chore(infra): implement click to reference by tsconfig.reference (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter authored Jan 28, 2025
1 parent 658d1f2 commit b9e865b
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 50 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/update.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { spawn } from 'node:child_process';
import fs from 'node:fs/promises';
import path from 'node:path';
import { pathExists } from '@rspress/shared/fs-extra';
import fse from '@rspress/shared/fs-extra';
import { logger } from '@rspress/shared/logger';

type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun';
Expand All @@ -16,7 +16,7 @@ const lockfileMap: Record<string, PackageManager> = {
async function getPackageManager(rootPath: string) {
let packageManager: PackageManager = 'npm';
for (const file of Object.keys(lockfileMap)) {
if (await pathExists(path.join(rootPath, file))) {
if (await fse.pathExists(path.join(rootPath, file))) {
packageManager = lockfileMap[file];
break;
}
Expand Down
10 changes: 9 additions & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@
"runtime.ts",
"theme.ts"
],
"exclude": ["**/node_modules"]
"exclude": ["**/node_modules"],
"references": [
{
"path": "../core"
},
{
"path": "../shared"
}
]
}
2 changes: 1 addition & 1 deletion packages/core/src/node/runtimeModule/siteData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function siteDataVMPlugin(context: FactoryContext) {
pages.map(async pageData => pluginDriver.extendPageData(pageData)),
);

const siteData: SiteData = {
const siteData: Omit<SiteData, 'root'> = {
title: userConfig?.title || '',
description: userConfig?.description || '',
icon: userConfig?.icon || '',
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/node/utils/flattenMdxContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ export async function flattenMdxContent(
let result = content;

try {
ast = processor.parse(content) as Root;
ast = processor.parse(content) as unknown as Root;
} catch (e) {
// Fallback: if mdx parse failed, just return the content
return { flattenContent: content, deps };
}

const importNodes = ast.children
.filter(node => node.type === ('mdxjsEsm' as any))
.flatMap(node => (node.data?.estree as ESTree)?.body || [])
.flatMap(node => ((node.data as any)?.estree as ESTree)?.body || [])
.filter(node => node.type === 'ImportDeclaration');
for (const importNode of importNodes) {
// import Comp from './a';
Expand Down
35 changes: 28 additions & 7 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"strict": false,
"declaration": true,
"noEmit": false,
"declarationDir": "dist",
"module": "ESNext",
"target": "ESNext",
"jsx": "react-jsx",
"baseUrl": "src",
"rootDir": ".",
"rootDir": "src",
"composite": true,
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
Expand All @@ -17,11 +20,29 @@
"@/theme-default/*": ["./theme-default/*"]
}
},
"include": [
"src",
"vitest.config.ts",
"./modern.config.ts",
"./tailwind.config.ts"
"include": ["src"],
"references": [
{
"path": "../plugin-auto-nav-sidebar"
},
{
"path": "../plugin-last-updated"
},
{
"path": "../plugin-container-syntax"
},
{
"path": "../plugin-medium-zoom"
},
{
"path": "../shared"
},
{
"path": "../theme-default"
},
{
"path": "../runtime"
}
],
"exclude": ["runtime.ts", "theme.ts", "node_modules"]
}
2 changes: 1 addition & 1 deletion packages/modern-plugin-rspress/tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"jsx": "preserve",
"baseUrl": "./",
"outDir": "./out",
"emitDeclarationOnly": true,
"noEmit": false,
"isolatedModules": true,
"paths": {},
"types": ["node", "jest"]
Expand Down
15 changes: 14 additions & 1 deletion packages/modern-plugin-rspress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"declaration": true,
"noEmit": false,
"outDir": "dist",
"jsx": "preserve",
"baseUrl": "./"
},
"references": [
{
"path": "../core"
},
{
"path": "../plugin-api-docgen"
},
{
"path": "../plugin-preview"
}
],
"include": ["src", "static", "rslib.config.ts"]
}
21 changes: 12 additions & 9 deletions packages/plugin-api-docgen/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"composite": true,
"declaration": true,
"noEmit": false,
"module": "ESNext",
"target": "ESNext",
"jsx": "react-jsx",
"baseUrl": "src",
"rootDir": ".",
"rootDir": "src",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"noEmit": true,
"paths": {
"@/*": ["./*"]
}
},
"include": [
"src",
"vitest.config.ts",
"index.d.ts",
"mdx-meta-loader.cjs",
"static/"
"references": [
{
"path": "../core"
},
{
"path": "../shared"
}
],
"include": ["src"],
"exclude": ["runtime.d.ts", "theme.d.ts", "node_modules", "dist"]
}
11 changes: 10 additions & 1 deletion packages/plugin-auto-nav-sidebar/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"declaration": true,
"noEmit": false,
"composite": true,
"outDir": "dist",
"noImplicitAny": false,
"module": "ESNext",
"target": "ESNext",
"jsx": "react-jsx",
Expand All @@ -14,6 +18,11 @@
"@/*": ["./*"]
}
},
"references": [
{
"path": "../shared"
}
],
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
"exclude": ["node_modules", "dist"]
}
8 changes: 7 additions & 1 deletion packages/plugin-client-redirects/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"composite": true,
"declaration": true,
"module": "ESNext",
"target": "ESNext",
"jsx": "react-jsx",
Expand All @@ -14,6 +15,11 @@
"@/*": ["./*"]
}
},
"references": [
{
"path": "../shared"
}
],
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
"exclude": ["node_modules", "dist"]
}
12 changes: 9 additions & 3 deletions packages/plugin-container-syntax/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"composite": true,
"declaration": true,
"module": "ESNext",
"target": "ESNext",
"jsx": "react-jsx",
"baseUrl": "src",
"rootDir": ".",
"rootDir": "src",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
},
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
"references": [
{
"path": "../shared"
}
],
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
13 changes: 10 additions & 3 deletions packages/plugin-last-updated/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"declaration": true,
"composite": true,
"module": "ESNext",
"target": "ESNext",
"jsx": "react-jsx",
"outDir": "dist",
"baseUrl": "src",
"rootDir": ".",
"rootDir": "src",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
},
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
"references": [
{
"path": "../shared"
}
],
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
9 changes: 6 additions & 3 deletions packages/plugin-medium-zoom/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"declaration": true,
"noEmit": false,
"outDir": "dist",
"composite": true,
"module": "ESNext",
"target": "ESNext",
"jsx": "react-jsx",
"baseUrl": "src",
"rootDir": ".",
"rootDir": "src",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
},
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
9 changes: 6 additions & 3 deletions packages/plugin-playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"declaration": true,
"composite": true,
"noEmit": false,
"outDir": "dist",
"module": "ESNext",
"target": "ESNext",
"jsx": "react-jsx",
"baseUrl": "src",
"rootDir": ".",
"rootDir": "src",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
},
"include": ["src", "vitest.config.ts", "index.d.ts", "rslib.config.ts"],
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
14 changes: 12 additions & 2 deletions packages/plugin-preview/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"composite": true,
"noEmit": false,
"declaration": true,
"declarationDir": "dist",
"module": "ESNext",
"target": "ESNext",
"jsx": "react-jsx",
Expand All @@ -10,7 +13,6 @@
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"noEmit": true,
"paths": {
"@/*": ["./*"]
}
Expand All @@ -23,5 +25,13 @@
"static/",
"rslib.config.ts"
],
"references": [
{
"path": "../shared"
},
{
"path": "../theme-default"
}
],
"exclude": ["runtime.d.ts", "theme.d.ts", "node_modules", "dist"]
}
3 changes: 2 additions & 1 deletion packages/plugin-rss/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"include": ["src"],
"references": [
{ "path": "./tsconfig.runtime.json" },
{ "path": "./tsconfig.tools.json" }
{ "path": "./tsconfig.tools.json" },
{ "path": "../runtime" }
]
}
Loading

0 comments on commit b9e865b

Please sign in to comment.