|
| 1 | +# Monorepo Migration Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document explains the migration from a single package (`@objectstack/spec`) to a monorepo structure with multiple packages. |
| 6 | + |
| 7 | +## New Structure |
| 8 | + |
| 9 | +The repository is now organized as a pnpm workspace with the following packages: |
| 10 | + |
| 11 | +### 📦 Packages |
| 12 | + |
| 13 | +``` |
| 14 | +packages/ |
| 15 | +├── constants/ # @objectstack/spec-constants |
| 16 | +├── meta/ # @objectstack/spec-meta |
| 17 | +├── plugin/ # @objectstack/spec-plugin |
| 18 | +├── schemas/ # @objectstack/spec-schemas |
| 19 | +└── spec/ # @objectstack/spec (main package) |
| 20 | +``` |
| 21 | + |
| 22 | +### Package Descriptions |
| 23 | + |
| 24 | +1. **@objectstack/spec-meta** - Metamodel Type Definitions |
| 25 | + - Contains: `ObjectEntity`, `ObjectField`, `ObjectView`, `FieldType` |
| 26 | + - Also includes: Example entities and views |
| 27 | + - Dependencies: None |
| 28 | + |
| 29 | +2. **@objectstack/spec-plugin** - Plugin Runtime Interfaces |
| 30 | + - Contains: `ObjectStackPlugin`, `PluginContext`, `PluginLogger`, etc. |
| 31 | + - Dependencies: None |
| 32 | + |
| 33 | +3. **@objectstack/spec-schemas** - Zod Validation Schemas |
| 34 | + - Contains: `ManifestSchema`, `MenuItemSchema` |
| 35 | + - Dependencies: `zod` |
| 36 | + |
| 37 | +4. **@objectstack/spec-constants** - Convention Constants |
| 38 | + - Contains: `PKG_CONVENTIONS` |
| 39 | + - Dependencies: None |
| 40 | + |
| 41 | +5. **@objectstack/spec** - Main Package (Aggregator) |
| 42 | + - Re-exports all sub-packages for backward compatibility |
| 43 | + - Dependencies: All other packages (workspace:*) |
| 44 | + |
| 45 | +## Migration Benefits |
| 46 | + |
| 47 | +### 1. **Smaller Bundle Sizes** |
| 48 | +Users can now install only the packages they need: |
| 49 | +```bash |
| 50 | +# Instead of installing the entire spec |
| 51 | +pnpm install @objectstack/spec |
| 52 | + |
| 53 | +# Install only what you need |
| 54 | +pnpm install @objectstack/spec-meta |
| 55 | +``` |
| 56 | + |
| 57 | +### 2. **Better Organization** |
| 58 | +Each package has a clear responsibility and can evolve independently. |
| 59 | + |
| 60 | +### 3. **Backward Compatibility** |
| 61 | +The main `@objectstack/spec` package maintains full backward compatibility by re-exporting all sub-packages. |
| 62 | + |
| 63 | +### 4. **Independent Versioning** |
| 64 | +Each package can be versioned independently (though currently linked via changesets). |
| 65 | + |
| 66 | +## Usage |
| 67 | + |
| 68 | +### For Existing Users (No Breaking Changes) |
| 69 | + |
| 70 | +```typescript |
| 71 | +// This still works exactly as before |
| 72 | +import { |
| 73 | + ObjectEntity, |
| 74 | + ManifestSchema, |
| 75 | + PKG_CONVENTIONS |
| 76 | +} from '@objectstack/spec'; |
| 77 | +``` |
| 78 | + |
| 79 | +### For New Users (Optimized Imports) |
| 80 | + |
| 81 | +```typescript |
| 82 | +// Import only what you need for smaller bundles |
| 83 | +import { ObjectEntity } from '@objectstack/spec-meta'; |
| 84 | +import { ManifestSchema } from '@objectstack/spec-schemas'; |
| 85 | +import { PKG_CONVENTIONS } from '@objectstack/spec-constants'; |
| 86 | +``` |
| 87 | + |
| 88 | +## Development |
| 89 | + |
| 90 | +### Building |
| 91 | + |
| 92 | +```bash |
| 93 | +# Build all packages |
| 94 | +pnpm run build |
| 95 | + |
| 96 | +# Build a specific package |
| 97 | +cd packages/meta && pnpm run build |
| 98 | +``` |
| 99 | + |
| 100 | +### Development Mode |
| 101 | + |
| 102 | +```bash |
| 103 | +# Watch all packages |
| 104 | +pnpm run dev |
| 105 | + |
| 106 | +# Watch a specific package |
| 107 | +cd packages/meta && pnpm run dev |
| 108 | +``` |
| 109 | + |
| 110 | +### Adding a New Package |
| 111 | + |
| 112 | +1. Create a new directory in `packages/` |
| 113 | +2. Create `package.json`, `tsconfig.json`, and `README.md` |
| 114 | +3. Add the package to `.changeset/config.json` linked array |
| 115 | +4. Add dependencies in `packages/spec/package.json` if needed |
| 116 | + |
| 117 | +## Publishing |
| 118 | + |
| 119 | +The monorepo uses Changesets for version management and publishing: |
| 120 | + |
| 121 | +```bash |
| 122 | +# Create a changeset |
| 123 | +pnpm changeset |
| 124 | + |
| 125 | +# Version packages |
| 126 | +pnpm run version |
| 127 | + |
| 128 | +# Publish packages |
| 129 | +pnpm run release |
| 130 | +``` |
| 131 | + |
| 132 | +## CI/CD |
| 133 | + |
| 134 | +The existing GitHub Actions workflows have been updated to work with the monorepo: |
| 135 | +- **CI**: Builds all packages |
| 136 | +- **Release**: Publishes all packages with changesets |
| 137 | + |
| 138 | +## File Structure |
| 139 | + |
| 140 | +``` |
| 141 | +. |
| 142 | +├── packages/ |
| 143 | +│ ├── constants/ |
| 144 | +│ │ ├── src/ |
| 145 | +│ │ ├── package.json |
| 146 | +│ │ ├── tsconfig.json |
| 147 | +│ │ └── README.md |
| 148 | +│ ├── meta/ |
| 149 | +│ ├── plugin/ |
| 150 | +│ ├── schemas/ |
| 151 | +│ └── spec/ |
| 152 | +├── content/ # Documentation and AI guides |
| 153 | +├── .changeset/ # Changeset configuration |
| 154 | +├── pnpm-workspace.yaml # Workspace configuration |
| 155 | +├── package.json # Root package.json |
| 156 | +├── tsconfig.json # Base TypeScript configuration |
| 157 | +└── README.md # Main README |
| 158 | +``` |
| 159 | + |
| 160 | +## Technical Details |
| 161 | + |
| 162 | +### Workspace Configuration |
| 163 | + |
| 164 | +- **Package Manager**: pnpm (v10.28.0) |
| 165 | +- **Workspace Protocol**: `workspace:*` for internal dependencies |
| 166 | +- **Build Tool**: TypeScript Compiler (tsc) |
| 167 | +- **Version Management**: Changesets |
| 168 | + |
| 169 | +### TypeScript Configuration |
| 170 | + |
| 171 | +- Each package extends the root `tsconfig.json` |
| 172 | +- All packages compile to `dist/` directory |
| 173 | +- Declaration maps are generated for better IDE support |
| 174 | + |
| 175 | +### Publishing Configuration |
| 176 | + |
| 177 | +- All packages are published to npm with `public` access |
| 178 | +- Each package includes only `dist/` and `README.md` files |
| 179 | +- Workspace dependencies are replaced with actual versions during publish |
| 180 | + |
| 181 | +## Migration Checklist |
| 182 | + |
| 183 | +- [x] Created monorepo structure |
| 184 | +- [x] Split code into logical packages |
| 185 | +- [x] Updated all imports and exports |
| 186 | +- [x] Configured pnpm workspace |
| 187 | +- [x] Updated build scripts |
| 188 | +- [x] Added package READMEs |
| 189 | +- [x] Updated root README |
| 190 | +- [x] Configured changesets for monorepo |
| 191 | +- [x] Verified backward compatibility |
| 192 | +- [x] Tested all builds |
| 193 | +- [x] Updated CI/CD workflows |
| 194 | + |
| 195 | +## Support |
| 196 | + |
| 197 | +For issues or questions about the monorepo structure, please: |
| 198 | +1. Check this migration guide |
| 199 | +2. Review individual package READMEs |
| 200 | +3. Open an issue on GitHub |
0 commit comments