(binaries: Record<string, string>)
| 547 | // --------------------------------------------------------------------------- |
| 548 | |
| 549 | const buildWrapperPackage = async (binaries: Record<string, string>) => { |
| 550 | const meta = await readMetadata(); |
| 551 | const wrapperDir = join(distDir, meta.name); |
| 552 | const binDir = join(wrapperDir, "bin"); |
| 553 | |
| 554 | await mkdir(binDir, { recursive: true }); |
| 555 | |
| 556 | // Node.js launcher — resolves the platform binary via require.resolve |
| 557 | // against optionalDependencies and execs it. No postinstall: the binary |
| 558 | // ships as an os/cpu-filtered optional dep, the launcher resolves it at |
| 559 | // runtime. This works whether or not the package manager runs postinstalls |
| 560 | // (bun blocks them by default). |
| 561 | await writeFile(join(binDir, "executor"), NODE_SHIM); |
| 562 | await chmod(join(binDir, "executor"), 0o755); |
| 563 | |
| 564 | await writeFile( |
| 565 | join(wrapperDir, "package.json"), |
| 566 | JSON.stringify( |
| 567 | { |
| 568 | name: meta.name, |
| 569 | version: meta.version, |
| 570 | description: meta.description, |
| 571 | keywords: meta.keywords, |
| 572 | homepage: meta.homepage, |
| 573 | bugs: meta.bugs, |
| 574 | repository: meta.repository, |
| 575 | license: meta.license, |
| 576 | bin: { executor: "bin/executor" }, |
| 577 | // Per-platform compiled binaries published as platform-tagged |
| 578 | // versions of `executor` itself, referenced via npm:alias specs: |
| 579 | // "executor-linux-x64": "npm:executor@1.4.14-linux-x64" |
| 580 | // npm/bun fetch only the variant matching the current os/cpu (set |
| 581 | // on each variant's package.json); everything else is a no-op. |
| 582 | // The local alias name on the left is what the launcher passes to |
| 583 | // require.resolve at runtime — npm puts the variant at |
| 584 | // `node_modules/executor-<plat>-<arch>/` so resolution just works. |
| 585 | optionalDependencies: binaries, |
| 586 | engines: { |
| 587 | node: ">=20", |
| 588 | }, |
| 589 | }, |
| 590 | null, |
| 591 | 2, |
| 592 | ) + "\n", |
| 593 | ); |
| 594 | |
| 595 | const readmePath = join(repoRoot, "README.md"); |
| 596 | if (existsSync(readmePath)) { |
| 597 | await cp(readmePath, join(wrapperDir, "README.md")); |
| 598 | } |
| 599 | |
| 600 | console.log(`\nWrapper package: ${wrapperDir}`); |
| 601 | console.log(` ${meta.name}@${meta.version}`); |
| 602 | console.log(` optionalDependencies: ${Object.keys(binaries).join(", ")}`); |
| 603 | }; |
| 604 | |
| 605 | // --------------------------------------------------------------------------- |
| 606 | // Preview wrapper — a slim npm package for pkg.pr.new previews that fetches |
no test coverage detected