( request: BuildDownloadRequest, )
| 201 | }; |
| 202 | |
| 203 | const buildDownloadArtifacts = async ( |
| 204 | request: BuildDownloadRequest, |
| 205 | ): Promise<number> => { |
| 206 | const { id } = request.metadata; |
| 207 | const [staticPackage, variablePackage] = await Promise.all([ |
| 208 | request.staticVersion |
| 209 | ? readPackageArchive(id, request.staticVersion, false) |
| 210 | : undefined, |
| 211 | request.variableVersion |
| 212 | ? readPackageArchive(id, request.variableVersion, true) |
| 213 | : undefined, |
| 214 | ]); |
| 215 | const packageWithLicense = staticPackage ?? variablePackage; |
| 216 | if (!packageWithLicense) { |
| 217 | throw new Error(`No package versions provided for ${id}`); |
| 218 | } |
| 219 | const license = getPackageFile(packageWithLicense, 'LICENSE'); |
| 220 | const staticArtifacts = |
| 221 | request.staticVersion && staticPackage |
| 222 | ? await buildStaticArtifacts( |
| 223 | { id, version: request.staticVersion }, |
| 224 | staticPackage, |
| 225 | ) |
| 226 | : []; |
| 227 | const variableArtifacts = |
| 228 | request.variableVersion && variablePackage |
| 229 | ? buildVariableArtifacts( |
| 230 | { id, version: request.variableVersion }, |
| 231 | variablePackage, |
| 232 | ) |
| 233 | : []; |
| 234 | if (request.staticVersion && staticArtifacts.length === 0) { |
| 235 | throw new Error( |
| 236 | `No static artifacts published for ${id}@${request.staticVersion}`, |
| 237 | ); |
| 238 | } |
| 239 | if (request.variableVersion && variableArtifacts.length === 0) { |
| 240 | throw new Error( |
| 241 | `No variable artifacts published for ${id}@${request.variableVersion}`, |
| 242 | ); |
| 243 | } |
| 244 | |
| 245 | const artifacts = [...staticArtifacts, ...variableArtifacts]; |
| 246 | const archive = zipSync( |
| 247 | Object.fromEntries([ |
| 248 | ...staticArtifacts.map((artifact) => [ |
| 249 | `static/${id}-${artifact.filename}`, |
| 250 | artifact.extension === 'ttf' |
| 251 | ? artifact.bytes |
| 252 | : [artifact.bytes, { level: 0 }], |
| 253 | ]), |
| 254 | ...variableArtifacts.map((artifact) => [ |
| 255 | `variable/${id}-${artifact.filename}`, |
| 256 | [artifact.bytes, { level: 0 }], |
| 257 | ]), |
| 258 | ['LICENSE', license], |
| 259 | ]), |
| 260 | ); |
no test coverage detected