* Test that a package can be packed without errors
(packageName, packageDir)
| 164 | * Test that a package can be packed without errors |
| 165 | */ |
| 166 | function testPackagePack(packageName, packageDir) { |
| 167 | log(`Testing pnpm pack for ${packageName}...`); |
| 168 | |
| 169 | // A scoped name (`@decap/cli`) would put a path separator in the prefix. |
| 170 | const packDir = mkdtempSync(join(tmpdir(), `decap-pack-${packageName.replace(/[@/]/g, '_')}-`)); |
| 171 | |
| 172 | try { |
| 173 | const result = spawnSync('pnpm', ['pack', '--json', '--pack-destination', packDir], { |
| 174 | cwd: packageDir, |
| 175 | encoding: 'utf8', |
| 176 | stdio: 'pipe', |
| 177 | shell: true, |
| 178 | }); |
| 179 | |
| 180 | if (result.status !== 0) { |
| 181 | error(`pnpm pack failed for ${packageName}`); |
| 182 | error(result.stderr || result.stdout); |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | const packOutput = JSON.parse(result.stdout); |
| 187 | const tarballPath = Array.isArray(packOutput) ? packOutput[0].filename : packOutput.filename; |
| 188 | const packedPackageJson = JSON.parse(readFileFromTarball(tarballPath, 'package/package.json')); |
| 189 | const publishProtocolDependencies = findPublishProtocolDependencies(packedPackageJson); |
| 190 | if (publishProtocolDependencies.length > 0) { |
| 191 | error(`pnpm pack left unresolved pnpm protocols in ${packageName}:`); |
| 192 | for (const dependency of publishProtocolDependencies) { |
| 193 | error(` ${dependency}`); |
| 194 | } |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | log(` pnpm pack OK for ${packageName}`); |
| 199 | return true; |
| 200 | } finally { |
| 201 | rmSync(packDir, { recursive: true, force: true }); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Test that a package doesn't have browser-incompatible code |
no test coverage detected