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
1 change: 1 addition & 0 deletions .github/workflows/security-supply-chain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
trustPolicyExclude:
- 'detect-port@1.6.1'
- 'semver@6.3.1'
- 'webpack-dev-middleware@7.4.6'
YAML

sfw pnpm install || sfw pnpm install || sfw pnpm install
Expand Down
34 changes: 23 additions & 11 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# Agent Development Guide
# AGENTS.md

A file for [guiding AI coding agents](https://agents.md/).
## Docusaurus

## Project Overview
Overview:

Docusaurus is a modern static site generator framework focused on documentation websites. It's built with React and supports MDX, i18n, versioning, and extensive plugin architecture.
- Modern static site generator framework - SPA
- Focus on documentation sites
- Built with React
- Supports MDX, i18n, versioning
- Extensive plugin architecture
- Uses itself to build its own sites & dogfood

The project is a monorepo managed by Lerna and uses pnpm workspaces.
Monorepo based on:

Docusaurus uses itself to build its own website, which serves as both documentation and a way to dogfood the framework.
- Lerna
- pnpm workspaces

### Monorepo Structure
### Monorepo

- `packages/` - Core Docusaurus packages and plugins, published to npm
- `docusaurus/` - Main CLI and core functionality
Expand All @@ -21,7 +27,13 @@ Docusaurus uses itself to build its own website, which serves as both documentat
- `docusaurus-types/` - TypeScript definitions
- `create-docusaurus/` - Site initialization CLI tool

Monorepo packages depend on each other. Use `pnpm lerna list --toposort` to know in which order to build them, and `pnpm --filter <package-name> build` to build one in particular. Using `pnpm build:packages` builds them all in the correct order, but is slower.
Packages depend on each other.

Use:

- `pnpm lerna list --toposort` to know in which order to build them
- `pnpm --filter <package-name> build` to build one in particular
- `pnpm build:packages` to build them all in the correct order

### Website structure

Expand All @@ -43,7 +55,7 @@ The main CLI commands available
- `pnpm watch` - Incremental build of monorepo packages with file watchers
- `pnpm format` - Format code with oxfmt
- `pnpm lint` - Run linting (ESLint + Stylelint + spell check)
- `pnpm test` - Run all tests using Jest
- `pnpm test` - Run all tests using Vitest
- `pnpm clear` - Clean all build artifacts and caches
- `pnpm --filter <package-name> build` - Build an individual monorepo package

Expand All @@ -57,13 +69,13 @@ The main CLI commands available

### Testing

- `pnpm test` - Run all Jest tests
- `pnpm test` - Run all Vitest tests
- `pnpm test <path/to/test.file.ts>` - Run single test file
- `pnpm --filter <package-name> test` - Run tests in a specific package:

When a test is failing, run only that test file until it passes. Make sure to run all tests at the end to ensure there's no unexpected failure in other places.

Update Jest failing snapshots with the `-u` option. Do not blindly update snapshots, and make sure they capture the correct behavior.
Update Vitest failing snapshots with the `-u` option. Do not blindly update snapshots, and make sure they capture the correct behavior.

### Linting & Formatting

Expand Down
3 changes: 3 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CLAUDE.md

@AGENTS.md
7 changes: 7 additions & 0 deletions packages/docusaurus-bundler/src/importFaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export async function importRspack(): Promise<FasterModule['rspack']> {
return faster.rspack;
}

export async function importRspackDevServer(): Promise<
FasterModule['rspackDevServer']
> {
const faster = await ensureFaster();
return faster.rspackDevServer;
}

export async function importSwcLoader(): Promise<string> {
const faster = await ensureFaster();
return faster.swcLoader;
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-bundler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export {
} from './minifyHtml';
export {createJsLoaderFactory} from './loaders/jsLoader';
export {createStyleLoadersFactory} from './loaders/styleLoader';
export {importRspackDevServer} from './importFaster';
3 changes: 2 additions & 1 deletion packages/docusaurus-faster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"license": "MIT",
"dependencies": {
"@docusaurus/types": "3.10.1",
"@rspack/core": "^2.2.0",
"@rspack/core": "^2.2.2",
"@rspack/dev-server": "^2.2.1",
"@swc/core": "^1.15.40",
"@swc/html": "^1.15.40",
"browserslist": "^4.28.2",
Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus-faster/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import {rspack as Rspack} from '@rspack/core';
import {RspackDevServer} from '@rspack/dev-server';
import * as lightningcss from 'lightningcss';
import browserslist from 'browserslist';
import semver from 'semver';
Expand Down Expand Up @@ -39,7 +40,9 @@ export const getSwcLoaderOptions = ({
};
};

export const rspack: typeof Rspack = Rspack;
export const rspack = Rspack;

export const rspackDevServer = RspackDevServer;

type SwcHtmlMinifier = (typeof import('@swc/html'))['minify'];

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"update-notifier": "^6.0.2",
"webpack": "^5.106.2",
"webpack-bundle-analyzer": "^5.3.0",
"webpack-dev-server": "^5.2.3",
"webpack-dev-server": "^6.0.0",
"webpack-merge": "^6.0.1"
},
"devDependencies": {
Expand Down
47 changes: 39 additions & 8 deletions packages/docusaurus/src/commands/start/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@

import path from 'path';
import merge from 'webpack-merge';
import {formatStatsErrorMessage, printStatsWarnings} from '@docusaurus/bundler';
import {
formatStatsErrorMessage,
importRspackDevServer,
printStatsWarnings,
} from '@docusaurus/bundler';
import logger from '@docusaurus/logger';
// eslint-disable-next-line import/default
import WebpackDevServer from 'webpack-dev-server';
import WebpackDevServer, {
type Configuration as DevServerConfig,
} from 'webpack-dev-server';
import evalSourceMapMiddleware from '../utils/legacy/evalSourceMapMiddleware';
import {createPollingOptions} from './watcher';
import getHttpsConfig from '../../webpack/utils/getHttpsConfig';
Expand All @@ -20,7 +25,11 @@ import {
} from '../../webpack/configure';
import {createStartClientConfig} from '../../webpack/client';
import type {StartCLIOptions} from './start';
import type {ConfigureWebpackUtils, Props} from '@docusaurus/types';
import type {
ConfigureWebpackUtils,
CurrentBundler,
Props,
} from '@docusaurus/types';
import type {Compiler} from 'webpack';
import type {OpenUrlContext} from './utils';

Expand Down Expand Up @@ -55,7 +64,7 @@ async function createDevServerConfig({
props: Props;
host: string;
port: number;
}): Promise<WebpackDevServer.Configuration> {
}): Promise<DevServerConfig> {
const {baseUrl, siteDir, siteConfig} = props;

const pollingOptions = createPollingOptions(cliOptions);
Expand Down Expand Up @@ -175,17 +184,39 @@ export async function createWebpackDevServer({
const compiler = props.currentBundler.instance(config);
registerWebpackE2ETestHook(compiler);

const defaultDevServerConfig = await createDevServerConfig({
const defaultDevServerConfig: DevServerConfig = await createDevServerConfig({
cliOptions,
props,
host: openUrlContext.host,
port: openUrlContext.port,
});

// Allow plugin authors to customize/override devServer config
const devServerConfig: WebpackDevServer.Configuration = merge(
const devServerConfig: DevServerConfig = merge(
[defaultDevServerConfig, config.devServer].filter(Boolean),
);

return new WebpackDevServer(devServerConfig, compiler);
return createDevServer({
devServerConfig,
compiler,
currentBundler: props.currentBundler,
});
}

async function createDevServer({
devServerConfig,
compiler,
currentBundler,
}: {
devServerConfig: DevServerConfig;
compiler: Compiler;
currentBundler: CurrentBundler;
}): Promise<WebpackDevServer> {
if (currentBundler.name === 'webpack') {
return new WebpackDevServer(devServerConfig, compiler);
} else {
const RspackDevServer = await importRspackDevServer();
// @ts-expect-error: different types
return new RspackDevServer(devServerConfig, compiler);
}
}
Loading
Loading