Skip to content

Commit

Permalink
chore(infra/test): migrate to vitest workspace (#1827)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter authored Feb 8, 2025
1 parent 920ca42 commit 7bb9f96
Show file tree
Hide file tree
Showing 49 changed files with 83 additions and 234 deletions.
1 change: 0 additions & 1 deletion e2e/fixtures/modern-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"],
"demo": ["./src"]
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"preview:website": "cd packages/document && npm run preview",
"test": "pnpm test:unit && pnpm test:e2e",
"test:e2e": "playwright test",
"test:unit": "cross-env NX_DAEMON=false NX_REJECT_UNKNOWN_LOCAL_CACHE=0 nx run-many -t test --exclude @rspress-fixture/*",
"test:unit": "vitest run",
"update:modern": "npx taze minor --include /modern-js/ -w -r -l",
"update:rsbuild": "npx taze minor --include /rsbuild/ -w -r -l"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"scripts": {
"build": "rslib build",
"dev": "rslib build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run"
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"@rsbuild/core": "1.2.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/config/loadConfigFile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'node:fs';
import path from 'node:path';
import { DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS } from '@/constants';
import type { UserConfig } from '@rspress/core';
import { logger } from '@rspress/shared/logger';
import { DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS } from '../constants';

const findConfig = (basePath: string): string | undefined => {
return DEFAULT_EXTENSIONS.map(ext => basePath + ext).find(fs.existsSync);
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"module": "ESNext",
"target": "ESNext",
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"]
},
"isolatedModules": true
},
"include": [
Expand Down
6 changes: 2 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
"scripts": {
"build": "modern build",
"dev": "modern build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run --passWithNoTests"
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"@mdx-js/loader": "2.3.0",
Expand Down Expand Up @@ -109,8 +108,7 @@
"remark-rehype": "^10.1.0",
"rimraf": "^3.0.2",
"tailwindcss": "^3.4.17",
"typescript": "^5.5.3",
"vitest": "2.1.9"
"typescript": "^5.5.3"
},
"engines": {
"node": ">=14.17.6"
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/node/build.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import fs from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { pathToFileURL } from 'node:url';
import type { Route } from '@/node/route/RouteService';
import { routeService } from '@/node/route/init';
import {
type PageData,
type SSGConfig,
Expand All @@ -25,6 +23,8 @@ import {
TEMP_DIR,
} from './constants';
import { initRsbuild } from './initRsbuild';
import type { Route } from './route/RouteService';
import { routeService } from './route/init';
import { writeSearchIndex } from './searchIndex';
import { checkLanguageParity } from './utils/checkLanguageParity';
import { renderConfigHead, renderFrontmatterHead } from './utils/renderHead';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/node/mdx/remarkPlugins/builtin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path';
import { getASTNodeImport } from '@/node/utils/getASTNodeImport';
import type { Root } from 'mdast';
import type { MdxjsEsm } from 'mdast-util-mdxjs-esm';
import type { Plugin } from 'unified';
import { getASTNodeImport } from '../../utils';

/**
* A remark plugin to import all builtin components.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/node/mdx/remarkPlugins/checkDeadLink.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'node:path';
import type { RouteService } from '@/node/route/RouteService';
import { normalizePath } from '@/node/utils';
import { cleanUrl, isProduction } from '@rspress/shared';
import { logger } from '@rspress/shared/logger';
import type { Plugin } from 'unified';
import { visit } from 'unist-util-visit';
import type { RouteService } from '../../route/RouteService';
import { normalizePath } from '../../utils';

export interface DeadLinkCheckOptions {
root: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/node/mdx/remarkPlugins/normalizeLink.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'node:path';
import { getASTNodeImport } from '@/node/utils/getASTNodeImport';
import { isExternalUrl, normalizeHref, parseUrl, slash } from '@rspress/shared';
import type { Root } from 'mdast';
import type { MdxjsEsm } from 'mdast-util-mdxjs-esm';
import type { Plugin } from 'unified';
import { visit } from 'unist-util-visit';
import { getASTNodeImport } from '../../utils';

interface LinkNode {
type: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { importStatementRegex } from '@/node/constants';
import type { RouteService } from '@/node/route/RouteService';
import { flattenMdxContent } from '@/node/utils';
import { applyReplaceRules } from '@/node/utils/applyReplaceRules';
import { compile } from '@rspress/mdx-rs';
import {
type Header,
Expand All @@ -13,6 +9,10 @@ import {
} from '@rspress/shared';
import { loadFrontMatter } from '@rspress/shared/node-utils';
import { htmlToText } from 'html-to-text';
import { importStatementRegex } from '../../constants';
import type { RouteService } from '../../route/RouteService';
import { flattenMdxContent } from '../../utils';
import { applyReplaceRules } from '../../utils/applyReplaceRules';

export function applyReplaceRulesToNestedObject(
obj: Record<string, any>,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/node/runtimeModule/siteData/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { TEMP_DIR, isProduction } from '@/node/constants';
import { createHash } from '@/node/utils';
import { SEARCH_INDEX_NAME, type SiteData } from '@rspress/shared';
import { groupBy } from 'lodash-es';
import { type FactoryContext, RuntimeModuleID } from '..';
import { TEMP_DIR, isProduction } from '../../constants';
import { createHash } from '../../utils';
import { extractPageData } from './extractPageData';
import { handleHighlightLanguages } from './highlightLanguages';
import { normalizeThemeConfig } from './normalizeThemeConfig';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { logger } from '@rspress/shared/logger';
import { fs, vol } from 'memfs';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { checkLanguageParity } from '../src/node/utils/checkLanguageParity';
import { checkLanguageParity } from './checkLanguageParity';

vi.mock('node:fs/promises');
vi.mock('node:fs/promises', () => {
return { default: fs.promises };
});
vi.mock('@rspress/shared/logger', () => ({
logger: {
info: vi.fn(),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/node/utils/checkLanguageParity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function collectModuleFiles(
if (!fileLangMap[baseName]) fileLangMap[baseName] = new Set();
fileLangMap[baseName].add(lang);
}
} catch {
} catch (e) {
throw new Error(
`Failed to access directory: ${normalizePath(langModuleDir)}`,
);
Expand Down
7 changes: 1 addition & 6 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
"composite": true,
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"],
"@theme": ["./theme-default"],
"@/theme-default/*": ["./theme-default/*"]
}
"skipLibCheck": true
},
"include": ["src"],
"references": [
Expand Down
3 changes: 0 additions & 3 deletions packages/create-rspress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"module": "ESNext",
"target": "ESNext",
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"]
},
"isolatedModules": true
},
"include": ["src"],
Expand Down
2 changes: 0 additions & 2 deletions packages/document/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"paths": {
"i18n": ["./i18n.json"],
"@theme": ["./theme"],
"@/assets/*": ["./docs/public/*"],
"@/components/*": ["./theme/components/*"],
"@zh/*": ["./docs/zh/*"],
"@en/*": ["./docs/en/*"]
},
Expand Down
3 changes: 1 addition & 2 deletions packages/modern-plugin-rspress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"@types/react": "^18.3.18",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5.5.3",
"vitest": "2.1.9"
"typescript": "^5.5.3"
},
"publishConfig": {
"access": "public",
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-api-docgen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"scripts": {
"build": "rslib build",
"dev": "rslib build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run --passWithNoTests"
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"@rspress/shared": "workspace:*",
Expand Down
5 changes: 1 addition & 4 deletions packages/plugin-api-docgen/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
"rootDir": "src",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
"skipLibCheck": true
},
"references": [
{
Expand Down
6 changes: 2 additions & 4 deletions packages/plugin-auto-nav-sidebar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"scripts": {
"build": "rslib build",
"dev": "rslib build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run --passWithNoTests"
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"@rspress/shared": "workspace:*"
Expand All @@ -40,8 +39,7 @@
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"react": "^18.3.1",
"typescript": "^5.5.3",
"vitest": "2.1.9"
"typescript": "^5.5.3"
},
"engines": {
"node": ">=14.17.6"
Expand Down
5 changes: 1 addition & 4 deletions packages/plugin-auto-nav-sidebar/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
"rootDir": ".",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
"skipLibCheck": true
},
"references": [
{
Expand Down
6 changes: 2 additions & 4 deletions packages/plugin-client-redirects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"scripts": {
"build": "rslib build",
"dev": "rslib build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run --passWithNoTests"
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"@rspress/shared": "workspace:*"
Expand All @@ -40,8 +39,7 @@
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"react": "^18.3.1",
"typescript": "^5.5.3",
"vitest": "2.1.9"
"typescript": "^5.5.3"
},
"peerDependencies": {
"@rspress/runtime": "workspace:^1.41.1"
Expand Down
5 changes: 1 addition & 4 deletions packages/plugin-client-redirects/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"rootDir": ".",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
"skipLibCheck": true
},
"references": [
{
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-container-syntax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"scripts": {
"build": "rslib build",
"dev": "rslib build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run --passWithNoTests"
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"@rspress/shared": "workspace:*"
Expand Down
5 changes: 1 addition & 4 deletions packages/plugin-container-syntax/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"rootDir": "src",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
"skipLibCheck": true
},
"references": [
{
Expand Down
6 changes: 2 additions & 4 deletions packages/plugin-last-updated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"scripts": {
"build": "rslib build",
"dev": "rslib build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run --passWithNoTests"
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"@rspress/shared": "workspace:*"
Expand All @@ -41,8 +40,7 @@
"@types/react-dom": "^18.3.5",
"execa": "8.0.1",
"react": "^18.3.1",
"typescript": "^5.5.3",
"vitest": "2.1.9"
"typescript": "^5.5.3"
},
"engines": {
"node": ">=14.17.6"
Expand Down
5 changes: 1 addition & 4 deletions packages/plugin-last-updated/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
"rootDir": "src",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
"skipLibCheck": true
},
"references": [
{
Expand Down
6 changes: 2 additions & 4 deletions packages/plugin-medium-zoom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"scripts": {
"build": "rslib build",
"dev": "rslib build -w",
"reset": "rimraf ./**/node_modules",
"test": "vitest run --passWithNoTests"
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
"medium-zoom": "1.1.0"
Expand All @@ -41,8 +40,7 @@
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"react": "^18.3.1",
"typescript": "^5.5.3",
"vitest": "2.1.9"
"typescript": "^5.5.3"
},
"peerDependencies": {
"@rspress/runtime": "workspace:^1.41.1"
Expand Down
5 changes: 1 addition & 4 deletions packages/plugin-medium-zoom/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
"rootDir": "src",
"lib": ["ESNext", "DOM"],
"esModuleInterop": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./*"]
}
"skipLibCheck": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
Expand Down
Loading

0 comments on commit 7bb9f96

Please sign in to comment.