Skip to content

Commit 35a6091

Browse files
jrolfsclaude
andcommitted
fix(fork): link published packages to the fork repo
Published packages weren't appearing in the fork's Packages view because their repository.url still pointed at upstream (pascalorg/editor) — the source is kept identical to upstream and the scope-rewrite only touches @pascal-app/ tokens. GitHub Packages couldn't associate them with the fork, so they landed unlinked under the account. Rewrite repository.url in the packed artifact to ${GITHUB_REPOSITORY} (the publishing fork) so GitHub links the package to this repo. Source stays untouched; works for any fork/scope since it reads the repo from CI. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7d7027d commit 35a6091

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

scripts/publish-fork.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const TARGET_PREFIX = `${SCOPE}/${NAME_PREFIX}`; // e.g. "@jrolfs/pascal-"
3030
const REGISTRY = "https://npm.pkg.github.com";
3131
const DRY_RUN = process.argv.includes("--dry-run");
3232
const IN_CI = process.env.GITHUB_ACTIONS === "true";
33+
// "owner/repo" of the publishing fork in CI; used to link packages to this repo.
34+
const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY;
3335

3436
// Files whose contents may reference the scope. Note extname("x.d.ts") === ".ts".
3537
const TEXT_EXT = new Set([
@@ -51,6 +53,21 @@ const rewriteScope = (dir: string): void => {
5153
}
5254
};
5355

56+
/**
57+
* Point the packed package's repository.url at the publishing fork so GitHub
58+
* Packages links the package to this repo. The source field still points at
59+
* upstream (pascalorg/editor); only the published artifact is changed.
60+
*/
61+
const relinkRepository = (packageDir: string, repo: string): void => {
62+
const manifestPath = join(packageDir, "package.json");
63+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
64+
if (!manifest.repository) return;
65+
const url = `https://github.com/${repo}.git`;
66+
manifest.repository =
67+
typeof manifest.repository === "string" ? url : { ...manifest.repository, url };
68+
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
69+
};
70+
5471
const newTags: string[] = [];
5572

5673
for (const dir of readdirSync("packages")) {
@@ -80,6 +97,7 @@ for (const dir of readdirSync("packages")) {
8097

8198
const packed = join(work, "package");
8299
rewriteScope(packed);
100+
if (GITHUB_REPOSITORY) relinkRepository(packed, GITHUB_REPOSITORY);
83101

84102
if (DRY_RUN) {
85103
console.log(`→ [dry-run] ${tag}`);

0 commit comments

Comments
 (0)