* Test that the package.json has required fields
(packageName)
| 131 | * Test that the package.json has required fields |
| 132 | */ |
| 133 | function testPackageJson(packageName) { |
| 134 | const packageDir = join(ROOT_DIR, 'packages', packageName); |
| 135 | const pkgJsonPath = join(packageDir, 'package.json'); |
| 136 | |
| 137 | log(`Checking package.json for ${packageName}...`); |
| 138 | |
| 139 | const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8')); |
| 140 | const issues = []; |
| 141 | |
| 142 | // Check required fields |
| 143 | const requiredFields = ['name', 'version', 'main', 'files']; |
| 144 | for (const field of requiredFields) { |
| 145 | if (!pkgJson[field]) { |
| 146 | issues.push(`Missing required field: ${field}`); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Check that main entry exists |
| 151 | if (pkgJson.main) { |
| 152 | const mainPath = join(packageDir, pkgJson.main); |
| 153 | if (!existsSync(mainPath)) { |
| 154 | issues.push(`Main entry does not exist: ${pkgJson.main}`); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // Check that module entry exists if specified |
| 159 | if (pkgJson.module) { |
| 160 | const modulePath = join(packageDir, pkgJson.module); |
| 161 | if (!existsSync(modulePath)) { |
| 162 | issues.push(`Module entry does not exist: ${pkgJson.module}`); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if (issues.length > 0) { |
| 167 | error(`package.json issues in ${packageName}:`); |
| 168 | for (const issue of issues) { |
| 169 | error(` ${issue}`); |
| 170 | } |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | log(` package.json OK for ${packageName}`); |
| 175 | return true; |
| 176 | } |
| 177 | |
| 178 | async function main() { |
| 179 | log('Starting npm package integrity tests...'); |