This file provides context and strict guidelines for autonomous coding agents (like Cursor, Copilot, or OpenCode) operating within this repository (rsbuild-plugin-tailwindcss).
(Note: No other .cursorrules or Copilot instruction files exist in this repository. This file serves as the single source of truth for agent behavior.)
- Package Manager:
pnpm(strictly use this; do not use npm or yarn). - Core Frameworks: Rsbuild plugin integrating Tailwind CSS v4, PostCSS, and Rslib.
- Language: TypeScript (ES2023 target, ESM format).
- Linter & Formatter: Biome.
- Testing: Playwright (
@playwright/test).
Ensure you run pnpm install first to install dependencies before executing any tasks.
- Build the plugin:
pnpm build(runs Rslib to build the project into thedist/folder). - Watch/Dev mode:
pnpm dev(rebuilds the plugin automatically on changes).
- Check code:
pnpm lint(runsbiome check .). - Fix and format code:
pnpm lint:write(runsbiome check . --write). - Note: Always run
pnpm lint:writebefore concluding a task to ensure code styling matches the repo's Biome configuration.
- Run all tests:
pnpm test(uses Playwright with--workers 1). - Run a single test file:
pnpm test test/basic/index.test.ts - Run a specific test case within a file:
pnpm test test/basic/index.test.ts -g "preflight base styles are applied"
- Note: Tests involve spinning up a temporary Rsbuild server and checking computed styles via a headless browser.
- ES Modules (ESM): The codebase strictly uses ESM. Use
import/exportsyntax. - Local Imports: Always append the
.jsextension for local relative imports (e.g.,import { compile } from './compiler.js';). - Node Built-ins: Use the
node:prefix for all Node.js core modules (e.g.,import fs from 'node:fs';,import path from 'node:path';). - Type Imports: Use
import type { ... }exclusively for importing TypeScript interfaces and types to avoid runtime overhead. - Biome Formatting: Biome is configured to automatically organize imports. Let
pnpm lint:writehandle import sorting rather than doing it manually.
- Use spaces for indentation.
- Use single quotes for strings (in JavaScript/TypeScript).
- Do not spend time manually aligning or perfectly formatting code; rely on
pnpm lint:writeto format the code automatically after making changes.
- Strict mode is enabled (
"strict": true). - Interfaces vs Types: Prefer
interfaceovertypefor defining options, configurations, and object structures. - JSDoc: Document public APIs, exported interfaces, and complex options using standard JSDoc comments (
/** ... */). Seesrc/index.tsfor examples. - Type Safety: Avoid
any. Useunknownor specific generics if type information is complex or unknown at compile time.
- Variables, functions, and properties:
camelCase. - Interfaces, Types, and Classes:
PascalCase. - Internal/Virtual file names and global constants:
UPPER_SNAKE_CASE(e.g.,VIRTUAL_UTILITIES_ID). - Boolean variables or methods: Prefix with
is,has, orshould.
- Throw clear, descriptive errors when configurations are missing or invalid, ensuring the user understands what went wrong.
- For asynchronous file system operations, utilize async/await with
try/catchwhere the error might bubble up or where specific recovery/fallback behavior is required. - If a build step fails inside the plugin, let Rsbuild/Rspack handle the error gracefully; provide relevant context if possible.
- Location: Tests are located in the
test/directory, broken down by feature or scenario folders (e.g.,test/theme/,test/basic/). - Framework:
Playwrightis used as the primary test runner for integration and E2E testing. - Standard Test Flow:
- Initialize Rsbuild with the target directory and the Tailwind plugin:
const rsbuild = await createRsbuild({ cwd: __dirname, rsbuildConfig: { plugins: [pluginTailwindCSS()] } });
- Build the app:
await rsbuild.build(); - Preview it:
const { server, urls } = await rsbuild.preview(); - Navigate to the URL:
await page.goto(urls[0]); - Assert against computed styles rather than raw CSS strings:
await expect(page.locator('#test')).toHaveCSS('display', 'flex');
- Clean up: Always close the server in the test execution (e.g.,
await server.close();).
- Initialize Rsbuild with the target directory and the Tailwind plugin:
- Do not break existing workflows: Run tests (
pnpm test) and linting (pnpm lint) locally to verify your changes before concluding your task or committing. - Minimize file modifications: Only change files that are strictly required to fulfill the user's objective. Do not preemptively rewrite or refactor unrelated parts of the codebase.
- Respect established patterns: Look at existing files like
src/index.tsandsrc/compiler.tsto mimic the codebase's tone, architecture, and complexity. - Use appropriate tools: Utilize
read,glob, andgrepto build context before making code modifications. When creating or editing files, always ensure you provide absolute paths. - No implicit assumptions: Verify dependencies and module existence before importing them. If adding a new feature, follow the test-driven approach evident in the
test/directory.