| 280 | * Fails hard on any mismatch — reusing stale artifacts must never be a |
| 281 | * silent fallback. */ |
| 282 | const locateBuiltArtifacts = async (version: string): Promise<string> => { |
| 283 | const wrapperPkgPath = join(wrapperDir, "package.json"); |
| 284 | if (!existsSync(wrapperPkgPath)) { |
| 285 | throw new Error(`No built wrapper package at ${wrapperPkgPath}; run without --skip-build.`); |
| 286 | } |
| 287 | |
| 288 | const wrapperPkg = (await Bun.file(wrapperPkgPath).json()) as { |
| 289 | version?: string; |
| 290 | optionalDependencies?: Record<string, string>; |
| 291 | }; |
| 292 | if (wrapperPkg.version !== version) { |
| 293 | throw new Error( |
| 294 | `Built wrapper version ${wrapperPkg.version} does not match ${version}; run without --skip-build.`, |
| 295 | ); |
| 296 | } |
| 297 | |
| 298 | const expectedArchive = join(releaseDir, `executor-${version}.tgz`); |
| 299 | if (!existsSync(expectedArchive)) { |
| 300 | throw new Error(`Missing packed wrapper ${expectedArchive}; run without --skip-build.`); |
| 301 | } |
| 302 | |
| 303 | // The wrapper's optionalDependencies are the source of truth for which |
| 304 | // platform variants this release ships. `build.ts publish` globs the |
| 305 | // dist/executor-*/ directories and publishes whatever it finds, so a |
| 306 | // missing dir would ship a wrapper referencing a variant that never |
| 307 | // reached npm, and an extra stale dir (say a leftover beta variant) |
| 308 | // would be published alongside. Require the exact set, each at the exact |
| 309 | // aliased version, each with its release archive present. |
| 310 | const optional = wrapperPkg.optionalDependencies ?? {}; |
| 311 | const expectedVariants = Object.keys(optional).sort(); |
| 312 | if (expectedVariants.length === 0) { |
| 313 | throw new Error(`Built wrapper has no optionalDependencies; run without --skip-build.`); |
| 314 | } |
| 315 | |
| 316 | const variantDirs = [...new Bun.Glob("executor-*/package.json").scanSync({ cwd: distDir })] |
| 317 | .map((entry) => dirname(entry)) |
| 318 | .sort(); |
| 319 | if (variantDirs.join(",") !== expectedVariants.join(",")) { |
| 320 | throw new Error( |
| 321 | `Platform variant dirs [${variantDirs.join(", ")}] do not match the wrapper's ` + |
| 322 | `optionalDependencies [${expectedVariants.join(", ")}]; run without --skip-build.`, |
| 323 | ); |
| 324 | } |
| 325 | |
| 326 | for (const name of expectedVariants) { |
| 327 | const spec = optional[name]!; |
| 328 | const aliasPrefix = "npm:executor@"; |
| 329 | if (!spec.startsWith(aliasPrefix)) { |
| 330 | throw new Error(`Unexpected optionalDependency spec for ${name}: ${spec}`); |
| 331 | } |
| 332 | const aliasVersion = spec.slice(aliasPrefix.length); |
| 333 | |
| 334 | const variantPkg = (await Bun.file(join(distDir, name, "package.json")).json()) as { |
| 335 | version?: string; |
| 336 | }; |
| 337 | if (variantPkg.version !== aliasVersion) { |
| 338 | throw new Error( |
| 339 | `${name} version ${variantPkg.version} does not match the wrapper's ` + |