* Test that the package.json has required fields
(packageName)
| 228 | * Test that the package.json has required fields |
| 229 | */ |
| 230 | function testPackageJson(packageName) { |
| 231 | const packageDir = join(ROOT_DIR, 'packages', packageName); |
| 232 | const pkgJsonPath = join(packageDir, 'package.json'); |
| 233 | |
| 234 | log(`Checking package.json for ${packageName}...`); |
| 235 | |
| 236 | const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8')); |
| 237 | const issues = []; |
| 238 | |
| 239 | // Check required fields |
| 240 | const requiredFields = ['name', 'version', 'main', 'files']; |
| 241 | for (const field of requiredFields) { |
| 242 | if (!pkgJson[field]) { |
| 243 | issues.push(`Missing required field: ${field}`); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // Check that main entry exists |
| 248 | if (pkgJson.main) { |
| 249 | const mainPath = join(packageDir, pkgJson.main); |
| 250 | if (!existsSync(mainPath)) { |
| 251 | issues.push(`Main entry does not exist: ${pkgJson.main}`); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // Check that module entry exists if specified |
| 256 | if (pkgJson.module) { |
| 257 | const modulePath = join(packageDir, pkgJson.module); |
| 258 | if (!existsSync(modulePath)) { |
| 259 | issues.push(`Module entry does not exist: ${pkgJson.module}`); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | if (issues.length > 0) { |
| 264 | error(`package.json issues in ${packageName}:`); |
| 265 | for (const issue of issues) { |
| 266 | error(` ${issue}`); |
| 267 | } |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | log(` package.json OK for ${packageName}`); |
| 272 | return true; |
| 273 | } |
| 274 | |
| 275 | async function main() { |
| 276 | log('Starting pnpm package integrity tests...'); |