MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / buildWrapperPackage

Function buildWrapperPackage

apps/cli/src/build.ts:598–652  ·  view source on GitHub ↗
(binaries: Record<string, string>)

Source from the content-addressed store, hash-verified

596// ---------------------------------------------------------------------------
597
598const buildWrapperPackage = async (binaries: Record<string, string>) => {
599 const meta = await readMetadata();
600 const wrapperDir = join(distDir, meta.name);
601 const binDir = join(wrapperDir, "bin");
602
603 await mkdir(binDir, { recursive: true });
604
605 // Node.js launcher — resolves the platform binary via require.resolve
606 // against optionalDependencies and execs it. No postinstall: the binary
607 // ships as an os/cpu-filtered optional dep, the launcher resolves it at
608 // runtime. This works whether or not the package manager runs postinstalls
609 // (bun blocks them by default).
610 await writeFile(join(binDir, "executor"), NODE_SHIM);
611 await chmod(join(binDir, "executor"), 0o755);
612
613 await writeFile(
614 join(wrapperDir, "package.json"),
615 JSON.stringify(
616 {
617 name: meta.name,
618 version: meta.version,
619 description: meta.description,
620 keywords: meta.keywords,
621 homepage: meta.homepage,
622 bugs: meta.bugs,
623 repository: meta.repository,
624 license: meta.license,
625 bin: { executor: "bin/executor" },
626 // Per-platform compiled binaries published as platform-tagged
627 // versions of `executor` itself, referenced via npm:alias specs:
628 // "executor-linux-x64": "npm:executor@1.4.14-linux-x64"
629 // npm/bun fetch only the variant matching the current os/cpu (set
630 // on each variant's package.json); everything else is a no-op.
631 // The local alias name on the left is what the launcher passes to
632 // require.resolve at runtime — npm puts the variant at
633 // `node_modules/executor-<plat>-<arch>/` so resolution just works.
634 optionalDependencies: binaries,
635 engines: {
636 node: ">=20",
637 },
638 },
639 null,
640 2,
641 ) + "\n",
642 );
643
644 const readmePath = join(repoRoot, "README.md");
645 if (existsSync(readmePath)) {
646 await cp(readmePath, join(wrapperDir, "README.md"));
647 }
648
649 console.log(`\nWrapper package: ${wrapperDir}`);
650 console.log(` ${meta.name}@${meta.version}`);
651 console.log(` optionalDependencies: ${Object.keys(binaries).join(", ")}`);
652};
653
654// ---------------------------------------------------------------------------
655// Preview wrapper — a slim npm package for pkg.pr.new previews that fetches

Callers 1

build.tsFile · 0.85

Calls 2

readMetadataFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected