@mulmoclaude/core 7.8.1 → 7.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -588,8 +588,14 @@ function parseGithub(rest) {
|
|
|
588
588
|
const ownerRepo = hash === -1 ? rest : rest.slice(0, hash);
|
|
589
589
|
const tag = hash === -1 ? null : rest.slice(hash + 1);
|
|
590
590
|
const [owner = "", repo = "", ...extra] = ownerRepo.split("/");
|
|
591
|
-
if (extra.length > 0
|
|
592
|
-
|
|
591
|
+
if (extra.length > 0) return refuse$1(`not a GitHub owner/repo: ${JSON.stringify(ownerRepo)}`);
|
|
592
|
+
return githubSource(owner, repo, tag, ownerRepo);
|
|
593
|
+
}
|
|
594
|
+
/** Owner, repo and tag already split apart, checked as one GitHub source. `shown` is how the owner/repo
|
|
595
|
+
* was written, for the error. */
|
|
596
|
+
function githubSource(owner, repo, tag, shown) {
|
|
597
|
+
if (!GITHUB_OWNER.test(owner)) return refuse$1(`not a GitHub owner/repo: ${JSON.stringify(shown)}`);
|
|
598
|
+
if (!GITHUB_REPO.test(repo) || repo === "." || repo === "..") return refuse$1(`not a GitHub owner/repo: ${JSON.stringify(shown)}`);
|
|
593
599
|
if (tag !== null && !isGithubTag(tag)) return refuse$1(`not a release tag: ${JSON.stringify(tag)}`);
|
|
594
600
|
return {
|
|
595
601
|
ok: true,
|
|
@@ -614,12 +620,50 @@ function parseFile(rest) {
|
|
|
614
620
|
}
|
|
615
621
|
};
|
|
616
622
|
}
|
|
623
|
+
var GITHUB_HOSTS = /* @__PURE__ */ new Set(["github.com", "www.github.com"]);
|
|
624
|
+
var URL_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*:\/\//;
|
|
625
|
+
var GIT_SUFFIX = /\.git$/;
|
|
626
|
+
var GITHUB_URL_SHAPES = "https://github.com/<owner>/<repo>, …/releases/latest or …/releases/tag/<tag>";
|
|
627
|
+
var AUTHORITY_WITH_USERINFO = /^[A-Za-z][A-Za-z0-9+.-]*:\/\/[^/?#\\]*@/;
|
|
628
|
+
var refuseUrl = (input) => refuse$1(`not a GitHub repository or release URL (${GITHUB_URL_SHAPES}): ${JSON.stringify(input)}`);
|
|
629
|
+
/** The tag a release path names: none for the repository itself or `releases/latest`, else `releases/tag/<tag>`.
|
|
630
|
+
* `undefined` when the path is something else (a branch, a file, an issue). */
|
|
631
|
+
function releaseTagOf(rest) {
|
|
632
|
+
if (rest.length === 0) return null;
|
|
633
|
+
if (rest.length === 2 && rest[0] === "releases" && rest[1] === "latest") return null;
|
|
634
|
+
if (rest.length >= 3 && rest[0] === "releases" && rest[1] === "tag") return rest.slice(2).join("/");
|
|
635
|
+
}
|
|
636
|
+
/** A URL path's segments, percent-decoded; `null` when one does not decode. Only the leading `/` and one
|
|
637
|
+
* trailing `/` are dropped: an empty segment anywhere else is kept, so a tag written `x//y` is refused as
|
|
638
|
+
* `github:` refuses it rather than read as `x/y`. */
|
|
639
|
+
function decodedSegments(pathname) {
|
|
640
|
+
const segments = pathname.split("/").slice(1);
|
|
641
|
+
const withoutTrailing = segments.at(-1) === "" ? segments.slice(0, -1) : segments;
|
|
642
|
+
try {
|
|
643
|
+
return withoutTrailing.map((segment) => decodeURIComponent(segment));
|
|
644
|
+
} catch {
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function parseGithubUrl(input) {
|
|
649
|
+
const url = URL.canParse(input) ? new URL(input) : null;
|
|
650
|
+
if (url === null || url.protocol !== "https:" || !GITHUB_HOSTS.has(url.hostname)) return refuseUrl(input);
|
|
651
|
+
if (url.port !== "" || AUTHORITY_WITH_USERINFO.test(input)) return refuseUrl(input);
|
|
652
|
+
const segments = decodedSegments(url.pathname);
|
|
653
|
+
if (segments === null) return refuseUrl(input);
|
|
654
|
+
const [owner = "", repo = "", ...rest] = segments;
|
|
655
|
+
const tag = releaseTagOf(rest);
|
|
656
|
+
if (tag === void 0 || owner === "" || repo === "") return refuseUrl(input);
|
|
657
|
+
const bareRepo = repo.replace(GIT_SUFFIX, "");
|
|
658
|
+
return githubSource(owner, bareRepo, tag, `${owner}/${bareRepo}`);
|
|
659
|
+
}
|
|
617
660
|
function parseInstallSource(input) {
|
|
618
661
|
if (typeof input !== "string") return refuse$1("an install source is a string");
|
|
619
662
|
const trimmed = input.trim();
|
|
620
663
|
if (trimmed === "") return refuse$1("an install source is empty");
|
|
621
664
|
if (trimmed.startsWith(GITHUB_PREFIX)) return parseGithub(trimmed.slice(7));
|
|
622
665
|
if (trimmed.startsWith(FILE_PREFIX)) return parseFile(trimmed.slice(5));
|
|
666
|
+
if (URL_SCHEME.test(trimmed)) return parseGithubUrl(trimmed);
|
|
623
667
|
return parseNpm(trimmed);
|
|
624
668
|
}
|
|
625
669
|
/** The ledger's `source` field for what was actually installed: the resolved version or tag. */
|