|
| 1 | +# CLAUDE.md - Repository Context |
| 2 | + |
| 3 | +This document provides essential information about the `packages-private` repository to help AI assistants understand the codebase structure, conventions, and development practices. |
| 4 | + |
| 5 | +## Repository Overview |
| 6 | + |
| 7 | +This is a **TypeScript monorepo** managed with **pnpm workspaces** and **Turbo**. It contains various utility packages, tools, and libraries created by Patrick Kerschbaum (@pkerschbaum). |
| 8 | + |
| 9 | +### Key Technologies |
| 10 | + |
| 11 | +- **Language**: TypeScript |
| 12 | +- **Package Manager**: pnpm |
| 13 | +- **Build System**: Turbo (via custom `superturbo` wrapper) |
| 14 | +- **Node Version**: Specified in `.nvmrc` |
| 15 | +- **Module Systems**: Both CommonJS and ESM packages |
| 16 | + |
| 17 | +### Repository Structure |
| 18 | + |
| 19 | +```txt |
| 20 | +packages-private/ |
| 21 | +├── packages/ # Main packages (published to npm) |
| 22 | +├── platform/ # Internal platform utilities |
| 23 | +│ ├── config-eslint/ |
| 24 | +│ ├── config-typescript/ |
| 25 | +│ └── superturbo/ |
| 26 | +├── test/ # Test packages |
| 27 | +├── patches/ # pnpm patches for dependencies |
| 28 | +└── turbo.json # Turbo configuration |
| 29 | +``` |
| 30 | + |
| 31 | +## Development Setup |
| 32 | + |
| 33 | +### Prerequisites |
| 34 | + |
| 35 | +1. Install Node.js using nvm: `nvm install` |
| 36 | +2. Enable pnpm via corepack: `corepack enable` |
| 37 | +3. Install native toolchain for Node.js modules: Run the installation instructions "A C/C++ compiler tool chain for your platform" of [microsoft/vscode/wiki/How-to-Contribute#prerequisites](https://github.com/microsoft/vscode/wiki/How-to-Contribute#prerequisites) |
| 38 | + |
| 39 | +### Common Commands |
| 40 | + |
| 41 | +```bash |
| 42 | +pnpm install # Install all dependencies |
| 43 | +pnpm run build # Build all packages |
| 44 | +pnpm run lint # Run ESLint across all packages |
| 45 | +pnpm run lint:fix # Fix linting issues |
| 46 | +pnpm run format # Format with Prettier |
| 47 | +pnpm run nuke # Clean all build artifacts and node_modules |
| 48 | +``` |
| 49 | + |
| 50 | +## Coding Conventions |
| 51 | + |
| 52 | +### TypeScript Configuration |
| 53 | + |
| 54 | +- **Base config**: `platform/config-typescript/tsconfig.json` |
| 55 | +- **Strict mode**: Enabled with additional strict checks |
| 56 | +- **Module resolution**: Node16 |
| 57 | +- **Path aliases**: Use `#pkg/*` for internal imports (transformed to relative paths during build) |
| 58 | +- **Custom transformer**: `typescript-transform-paths` for path alias support |
| 59 | + |
| 60 | +### Code Style |
| 61 | + |
| 62 | +- **Formatting**: Prettier with single quotes, trailing commas, 100-char line width |
| 63 | +- **Linting**: ESLint with TypeScript support, all errors shown as warnings |
| 64 | +- **Import ordering**: External → workspace → internal, alphabetically sorted |
| 65 | +- **No default exports**: Use named exports only |
| 66 | +- **No relative imports**: Use `#pkg/*` aliases instead (except for assets) |
| 67 | + |
| 68 | +### Package Structure |
| 69 | + |
| 70 | +Each package typically follows this structure: |
| 71 | + |
| 72 | +```txt |
| 73 | +package-name/ |
| 74 | +├── src/ # Source files |
| 75 | +├── dist/ # Build output (gitignored) |
| 76 | +├── package.json # Package manifest |
| 77 | +├── tsconfig.project.json # TypeScript config |
| 78 | +└── turbo.json # Turbo config (if needed) |
| 79 | +``` |
| 80 | + |
| 81 | +### Package Configuration |
| 82 | + |
| 83 | +- **Exports**: Use `exports` field in package.json |
| 84 | +- **Types**: TypeScript declarations generated with source maps |
| 85 | +- **Scripts**: |
| 86 | + - `build`: Compile TypeScript |
| 87 | + - `dev`: Watch mode compilation |
| 88 | + - `lint`: Run ESLint |
| 89 | + - `nuke`: Clean artifacts |
| 90 | + |
| 91 | +## Important Patterns |
| 92 | + |
| 93 | +### Path Aliases |
| 94 | + |
| 95 | +All internal imports use `#pkg/*` aliases which map to `./src/*`. These are transformed to relative paths during compilation using `typescript-transform-paths`. |
| 96 | + |
| 97 | +### Monorepo References |
| 98 | + |
| 99 | +The root `tsconfig.json` contains references to all packages for TypeScript project references support. |
| 100 | + |
| 101 | +### Build System |
| 102 | + |
| 103 | +- Uses Turbo for orchestrating builds across packages |
| 104 | +- Custom `superturbo` wrapper in `platform/superturbo/` |
| 105 | +- Build outputs go to `dist/` directories |
| 106 | + |
| 107 | +### Testing |
| 108 | + |
| 109 | +- Test packages in `test/` directory |
| 110 | +- Package consumption tests ensure packages work correctly when installed |
| 111 | + |
| 112 | +### Publishing |
| 113 | + |
| 114 | +- Packages under `packages/` are published to npm |
| 115 | +- Uses Changesets for version management |
| 116 | +- Public packages use `@pkerschbaum/` scope |
| 117 | + |
| 118 | +## Special Considerations |
| 119 | + |
| 120 | +### TypeScript Patching |
| 121 | + |
| 122 | +The repository uses a patched version of TypeScript to support custom transformers. We use the custom transformer (plugin) [`typescript-transform-paths`](https://github.com/LeDDGroup/typescript-transform-paths) in our TypeScript codebase. This enables authoring TypeScript sources with path aliases but during TypeScript compilation, they are replaced by relative paths. That avoids all sorts of difficulties supporting path aliases in Node.js, Next.js, etc. |
| 123 | + |
| 124 | +Such custom transformers (plugins) are not supported by TypeScript out-of-the-box, so we apply [`ts-patch`](https://github.com/nonara/ts-patch) to the `typescript` package. To better incorporate with pnpm (<https://github.com/pnpm/pnpm/issues/6111>) we create a pnpm patch via `ts-patch`, using [`@pkerschbaum/pkg-management`](https://www.npmjs.com/package/@pkerschbaum/pkg-management). |
| 125 | + |
| 126 | +When updating TypeScript to a new version, this procedure is required: |
| 127 | + |
| 128 | +1. Remove current patch: |
| 129 | + |
| 130 | + ```bash |
| 131 | + pnpm patch-remove [email protected] # <-- look this up in package.json#pnpm.patchedDependencies |
| 132 | + ``` |
| 133 | + |
| 134 | +2. Update `typescript` everywhere: |
| 135 | + |
| 136 | + ```bash |
| 137 | + pnpm -r update [email protected] # <-- new version here |
| 138 | + ``` |
| 139 | + |
| 140 | +3. Run: |
| 141 | + |
| 142 | + ```bash |
| 143 | + pnpm --package= "@pkerschbaum/[email protected]" dlx create-pnpm-patch-via-ts-patch \ |
| 144 | + --typescript-version=5.6.3 \ # <-- new version of `typescript` here |
| 145 | + --ts-patch-version=3.3.0 # <-- latest version of `ts-patch` here |
| 146 | + ``` |
| 147 | + |
| 148 | +In the future, when all tools (like Node.js, Next.js builds, Playwright, ...) support ["subpath imports"](https://nodejs.org/api/packages.html#subpath-imports) correctly, we can configure `#pkg/*` imports via subpath imports and remove that "patching" approach altogether. |
| 149 | + |
| 150 | +### Git Hooks |
| 151 | + |
| 152 | +- Husky is configured for git hooks |
| 153 | +- Pre-commit hooks run linting and formatting checks |
| 154 | + |
| 155 | +### CI/CD |
| 156 | + |
| 157 | +- GitHub Actions workflows handle testing and publishing |
| 158 | +- Changesets manage versioning and changelogs |
0 commit comments