Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Rollup build with Vite #129

Merged
merged 3 commits into from
Jul 23, 2022
Merged

Replace Rollup build with Vite #129

merged 3 commits into from
Jul 23, 2022

Conversation

fregante
Copy link
Member

@fregante fregante commented Jul 23, 2022

Since #128 dropped Parcel for Vite, I thought I'd also use Vite for the main build.

This also lets us simplify the build/minification further by using Rollup’s own dead code eliminator and disable the minification entirely.

Too bad Vitest isn't as fast as AVA in this case:

@netlify
Copy link

netlify bot commented Jul 23, 2022

Deploy Preview for preview-for-github-url-detection ready!

Name Link
🔨 Latest commit e3c8ade
🔍 Latest deploy log https://app.netlify.com/sites/preview-for-github-url-detection/deploys/62dbb9474709ba0008004cd9
😎 Deploy Preview https://deploy-preview-129--preview-for-github-url-detection.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@fregante fregante changed the title Meta: Replace Rollup build with Vite Replace Rollup build with Vite Jul 23, 2022
@fregante fregante marked this pull request as ready for review July 23, 2022 08:41
@fregante
Copy link
Member Author

For reference, here are the built files:

Before

var reservedNames = [ "400", "401", "402", "403", "404", "405", "406", "407", "408", "409", "410", "411", "412", "413", "414", "415", "416", "417", "418", "419", "420", "421", "422", "423", "424", "425", "426", "427", "428", "429", "430", "431", "500", "501", "502", "503", "504", "505", "506", "507", "508", "509", "510", "511", "about", "access", "account", "admin", "advisories", "anonymous", "any", "api", "apps", "attributes", "auth", "billing", "blob", "blog", "bounty", "branches", "business", "businesses", "c", "cache", "case-studies", "categories", "central", "certification", "changelog", "cla", "cloud", "codereview", "collection", "collections", "comments", "commit", "commits", "community", "companies", "compare", "contact", "contributing", "cookbook", "coupons", "customer-stories", "customer", "customers", "dashboard", "dashboards", "design", "develop", "developer", "diff", "discover", "discussions", "docs", "downloads", "downtime", "editor", "editors", "edu", "enterprise", "events", "explore", "featured", "features", "files", "fixtures", "forked", "garage", "ghost", "gist", "gists", "graphs", "guide", "guides", "help", "help-wanted", "home", "hooks", "hosting", "hovercards", "identity", "images", "inbox", "individual", "info", "integration", "interfaces", "introduction", "invalid-email-address", "investors", "issues", "jobs", "join", "journal", "journals", "lab", "labs", "languages", "launch", "layouts", "learn", "legal", "library", "linux", "listings", "lists", "login", "logos", "logout", "mac", "maintenance", "malware", "man", "marketplace", "mention", "mentioned", "mentioning", "mentions", "migrating", "milestones", "mine", "mirrors", "mobile", "navigation", "network", "new", "news", "none", "nonprofit", "nonprofits", "notices", "notifications", "oauth", "offer", "open-source", "organisations", "organizations", "orgs", "pages", "partners", "payments", "personal", "plans", "plugins", "popular", "popularity", "posts", "press", "pricing", "professional", "projects", "pulls", "raw", "readme", "recommendations", "redeem", "releases", "render", "reply", "repositories", "resources", "restore", "revert", "save-net-neutrality", "saved", "scraping", "search", "security", "services", "sessions", "settings", "shareholders", "shop", "showcases", "signin", "signup", "site", "spam", "sponsors", "ssh", "staff", "starred", "stars", "static", "status", "statuses", "storage", "store", "stories", "styleguide", "subscriptions", "suggest", "suggestion", "suggestions", "support", "suspended", "talks", "teach", "teacher", "teachers", "teaching", "team", "teams", "ten", "terms", "timeline", "topic", "topics", "tos", "tour", "train", "training", "translations", "tree", "trending", "updates", "username", "users", "visualization", "w", "watching", "wiki", "windows", "works-with", "www0", "www1", "www2", "www3", "www4", "www5", "www6", "www7", "www8", "www9" ];

const $ = selector => document.querySelector(selector);

const exists = selector => Boolean($(selector));

const is404 = () => document.title.startsWith("Page not found · GitHub");

const is500 = () => "Server Error · GitHub" === document.title || "Unicorn! · GitHub" === document.title || "504 Gateway Time-out" === document.title;

const isPasswordConfirmation = () => "Confirm password" === document.title || "Confirm access" === document.title;

const isBlame = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("blame/"));
};

const isCommit = (url = location) => isSingleCommit(url) || isPRCommit(url);

const isCommitList = (url = location) => isRepoCommitList(url) || isPRCommitList(url);

const isRepoCommitList = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("commits"));
};

const isCompare = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("compare"));
};

const isCompareWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).split("/").slice(3, 5).includes("_compare");

const isDashboard = (url = location) => !isGist(url) && /^$|^(orgs\/[^/]+\/)?dashboard(\/|$)/.test(getCleanPathname(url));

const isEnterprise = (url = location) => "github.com" !== url.hostname && "gist.github.com" !== url.hostname;

const isGist = (url = location) => url.hostname.startsWith("gist.") || "gist" === url.pathname.split("/", 2)[1];

const isGlobalConversationList = (url = location) => [ "issues", "pulls" ].includes(url.pathname.split("/", 2)[1]);

const isGlobalSearchResults = (url = location) => "/search" === url.pathname && null !== new URLSearchParams(url.search).get("q");

const isIssue = (url = location) => {
    var _a;
    return /^issues\/\d+/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path) && "GitHub · Where software is built" !== document.title;
};

const isConversationList = (url = location) => isGlobalConversationList(url) || isRepoConversationList(url) || isMilestone(url);

const isConversation = (url = location) => isIssue(url) || isPRConversation(url);

const isLabelList = (url = location) => {
    var _a;
    return "labels" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isMilestone = (url = location) => {
    var _a;
    return /^milestone\/\d+/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isMilestoneList = (url = location) => {
    var _a;
    return "milestones" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isNewFile = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("new"));
};

const isNewIssue = (url = location) => {
    var _a;
    return "issues/new" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isNewRelease = (url = location) => {
    var _a;
    return "releases/new" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isNewWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_new");

const isNotifications = (url = location) => "notifications" === getCleanPathname(url);

const isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]');

const isOrganizationRepo = () => {
    var _a;
    return Boolean(null === (_a = document.querySelector("[data-owner-scoped-search-url]")) || void 0 === _a ? void 0 : _a.dataset.ownerScopedSearchUrl.startsWith("/org"));
};

const isOrganizationDiscussion = (url = location) => /^orgs\/[^/]+\/teams\/[^/]+($|\/discussions)/.test(getCleanPathname(url));

const isOwnUserProfile = () => getCleanPathname() === getUsername();

const isOwnOrganizationProfile = () => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]');

const isProject = (url = location) => {
    var _a;
    return /^projects\/\d+/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isProjects = (url = location) => {
    var _a;
    return "projects" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isDiscussion = (url = location) => {
    var _a;
    return /^discussions\/\d+/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isDiscussionList = (url = location) => {
    var _a;
    return "discussions" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isPR = (url = location) => {
    var _a;
    return /^pull\/\d+/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path) && !isPRConflicts(url);
};

const isPRConflicts = (url = location) => {
    var _a;
    return /^pull\/\d+\/conflicts/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isPRList = (url = location) => {
    var _a;
    return "/pulls" === url.pathname || "pulls" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isPRCommit = (url = location) => {
    var _a;
    return /^pull\/\d+\/commits\/[\da-f]{5,40}$/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit range not found · Pull Request");

const isPRFile404 = () => isPRFiles() && document.title.startsWith("Commit range not found · Pull Request");

const isPRConversation = (url = location) => {
    var _a;
    return /^pull\/\d+$/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isPRCommitList = (url = location) => {
    var _a;
    return /^pull\/\d+\/commits$/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isPRFiles = (url = location) => {
    var _a;
    return /^pull\/\d+\/files/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isQuickPR = (url = location) => isCompare(url) && /[?&]quick_pull=1(&|$)/.test(url.search);

const isDraftPR = () => exists('#partial-discussion-header [title="Status: Draft"]');

const isOpenPR = () => exists('#partial-discussion-header [title="Status: Open"], #partial-discussion-header [title="Status: Draft"]');

const isMergedPR = () => exists('#partial-discussion-header [title="Status: Merged"]');

const isClosedConversation = () => exists('#partial-discussion-header :is([title="Status: Closed"], [title="Status: Merged"], [title="Status: Closed as not planned"])');

const isClosedPR = isClosedConversation;

const isReleases = (url = location) => {
    var _a;
    return "releases" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isTags = (url = location) => {
    var _a;
    return "tags" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isSingleTag = (url = location) => {
    var _a;
    return /^(releases\/tag)/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isReleasesOrTags = (url = location) => isReleases(url) || isTags(url) || isSingleTag(url);

const isDeletingFile = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("delete"));
};

const isEditingFile = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("edit"));
};

const hasFileEditor = (url = location) => isEditingFile(url) || isNewFile(url) || isDeletingFile(url);

const isEditingRelease = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("releases/edit"));
};

const hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url);

const isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit");

const hasWikiPageEditor = (url = location) => isEditingWikiPage(url) || isNewWikiPage(url);

const isRepo = (url = location) => /^[^/]+\/[^/]+/.test(getCleanPathname(url)) && !reservedNames.includes(url.pathname.split("/", 2)[1]) && !isDashboard(url) && !isGist(url) && !isRepoSearch(url) && !isNewRepoTemplate(url);

const isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');

const isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]');

const isArchivedRepo = () => Boolean(isRepo() && $("#repository-container-header .Label").textContent.endsWith("archive"));

const isBlank = () => exists("main .blankslate");

const isRepoTaxonomyConversationList = (url = location) => {
    var _a;
    return /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isRepoConversationList = (url = location) => isRepoPRList(url) || isRepoIssueList(url) || isRepoTaxonomyConversationList(url);

const isRepoPRList = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("pulls"));
};

const isRepoIssueList = (url = location) => {
    var _a;
    return /^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isRepoHome = (url = location) => {
    var _a;
    return "" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isRepoRoot = url => {
    const repository = getRepo(null != url ? url : location);
    return !!repository && (!repository.path || (url ? /^tree\/[^/]+$/.test(repository.path) : repository.path.startsWith("tree/") && document.title.startsWith(repository.nameWithOwner) && !document.title.endsWith(repository.nameWithOwner)));
};

const isRepoSearch = (url = location) => "search" === url.pathname.split("/")[3];

const isRepoSettings = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("settings"));
};

const isRepoMainSettings = (url = location) => {
    var _a;
    return "settings" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isRepliesSettings = (url = location) => url.pathname.startsWith("/settings/replies");

const isUserSettings = (url = location) => url.pathname.startsWith("/settings/");

const isRepoTree = (url = location) => {
    var _a;
    return isRepoRoot(url) || Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("tree/"));
};

const isRepoWiki = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("wiki"));
};

const isSingleCommit = (url = location) => {
    var _a;
    return /^commit\/[\da-f]{5,40}$/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isSingleFile = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("blob/"));
};

const isFileFinder = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("find/"));
};

const isRepoForksList = (url = location) => {
    var _a;
    return "network/members" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isRepoNetworkGraph = (url = location) => {
    var _a;
    return "network" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isForkedRepo = () => exists('meta[name="octolytics-dimension-repository_is_fork"][content="true"]');

const isSingleGist = (url = location) => isGist(url) && /^\/(gist\/)?[^/]+\/[\da-f]{32}$/.test(url.pathname);

const isGistRevision = (url = location) => isGist(url) && /^\/(gist\/)?[^/]+\/[\da-f]{32}\/revisions$/.test(url.pathname);

const isTrending = (url = location) => "/trending" === url.pathname || url.pathname.startsWith("/trending/");

const isBranches = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("branches"));
};

const isProfile = (url = location) => {
    const pathname = getCleanPathname(url);
    return pathname.length > 0 && !pathname.includes("/") && !pathname.includes(".") && !reservedNames.includes(pathname);
};

const isUserProfile = () => isProfile() && !isOrganizationProfile();

const isPrivateUserProfile = () => isUserProfile() && !exists(".user-following-container");

const isUserProfileMainTab = () => isUserProfile() && !new URLSearchParams(location.search).has("tab");

const isUserProfileRepoTab = (url = location) => isProfile(url) && "repositories" === new URLSearchParams(url.search).get("tab");

const isUserProfileStarsTab = (url = location) => isProfile(url) && "stars" === new URLSearchParams(url.search).get("tab");

const isUserProfileFollowersTab = (url = location) => isProfile(url) && "followers" === new URLSearchParams(url.search).get("tab");

const isUserProfileFollowingTab = (url = location) => isProfile(url) && "following" === new URLSearchParams(url.search).get("tab");

const hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isOrganizationDiscussion(url) || isSingleGist(url);

const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url);

const hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isRepoSearch(url) || isGlobalSearchResults(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isCompareWikiPage(url) || isBlame(url);

const hasFiles = (url = location) => isCommit(url) || isCompare(url) || isPRFiles(url);

const isMarketplaceAction = (url = location) => url.pathname.startsWith("/marketplace/actions/");

const isActionJobRun = (url = location) => {
    var _a;
    return Boolean(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path.startsWith("runs/"));
};

const isActionRun = (url = location) => {
    var _a;
    return /^(actions\/)?runs/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isNewAction = (url = location) => {
    var _a;
    return "actions/new" === (null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isRepositoryActions = (url = location) => {
    var _a;
    return /^actions(\/workflows\/.+\.ya?ml)?$/.test(null === (_a = getRepo(url)) || void 0 === _a ? void 0 : _a.path);
};

const isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');

const canUserEditOrganization = isUserTheOrganizationOwner;

const canUserEditRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');

const isNewRepo = (url = location) => "/new" === url.pathname || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url));

const isNewRepoTemplate = (url = location) => Boolean("generate" === url.pathname.split("/")[3]);

const getUsername = () => {
    var _a;
    return null === (_a = document.querySelector('meta[name="user-login"]')) || void 0 === _a ? void 0 : _a.getAttribute("content");
};

const getCleanPathname = (url = location) => url.pathname.replace(/\/+/g, "/").slice(1, url.pathname.endsWith("/") ? -1 : void 0);

const getRepo = url => {
    if (!url) {
        const canonical = document.querySelector('[property="og:url"]');
        if (canonical) {
            const canonicalUrl = new URL(canonical.content, location.origin);
            getCleanPathname(canonicalUrl).toLowerCase() === getCleanPathname(location).toLowerCase() && (url = canonicalUrl);
        }
    }
    "string" == typeof url && (url = new URL(url, location.origin));
    if (!isRepo(url)) return;
    const [owner, name, ...path] = getCleanPathname(url).split("/");
    return {
        owner: owner,
        name: name,
        nameWithOwner: owner + "/" + name,
        path: path.join("/")
    };
};

const utils = {
    getUsername: getUsername,
    getCleanPathname: getCleanPathname,
    getRepositoryInfo: getRepo
};

export { canUserEditOrganization, canUserEditRepo, hasCode, hasComments, hasFileEditor, hasFiles, hasReleaseEditor, hasRichTextEditor, hasWikiPageEditor, is404, is500, isActionJobRun, isActionRun, isArchivedRepo, isBlame, isBlank, isBranches, isClosedConversation, isClosedPR, isCommit, isCommitList, isCompare, isCompareWikiPage, isConversation, isConversationList, isDashboard, isDeletingFile, isDiscussion, isDiscussionList, isDraftPR, isEditingFile, isEditingRelease, isEditingWikiPage, isEmptyRepo, isEmptyRepoRoot, isEnterprise, isFileFinder, isForkedRepo, isGist, isGistRevision, isGlobalConversationList, isGlobalSearchResults, isIssue, isLabelList, isMarketplaceAction, isMergedPR, isMilestone, isMilestoneList, isNewAction, isNewFile, isNewIssue, isNewRelease, isNewRepo, isNewRepoTemplate, isNewWikiPage, isNotifications, isOpenPR, isOrganizationDiscussion, isOrganizationProfile, isOrganizationRepo, isOwnOrganizationProfile, isOwnUserProfile, isPR, isPRCommit, isPRCommit404, isPRCommitList, isPRConflicts, isPRConversation, isPRFile404, isPRFiles, isPRList, isPasswordConfirmation, isPrivateUserProfile, isProfile, isProject, isProjects, isQuickPR, isReleases, isReleasesOrTags, isRepliesSettings, isRepo, isRepoCommitList, isRepoConversationList, isRepoForksList, isRepoHome, isRepoIssueList, isRepoMainSettings, isRepoNetworkGraph, isRepoPRList, isRepoRoot, isRepoSearch, isRepoSettings, isRepoTaxonomyConversationList, isRepoTree, isRepoWiki, isRepositoryActions, isSingleCommit, isSingleFile, isSingleGist, isSingleTag, isTags, isTrending, isUserProfile, isUserProfileFollowersTab, isUserProfileFollowingTab, isUserProfileMainTab, isUserProfileRepoTab, isUserProfileStarsTab, isUserSettings, isUserTheOrganizationOwner, utils };

After

const reservedNames = [
  "400",
  "401",
  "402",
  "403",
  "404",
  "405",
  "406",
  "407",
  "408",
  "409",
  "410",
  "411",
  "412",
  "413",
  "414",
  "415",
  "416",
  "417",
  "418",
  "419",
  "420",
  "421",
  "422",
  "423",
  "424",
  "425",
  "426",
  "427",
  "428",
  "429",
  "430",
  "431",
  "500",
  "501",
  "502",
  "503",
  "504",
  "505",
  "506",
  "507",
  "508",
  "509",
  "510",
  "511",
  "about",
  "access",
  "account",
  "admin",
  "advisories",
  "anonymous",
  "any",
  "api",
  "apps",
  "attributes",
  "auth",
  "billing",
  "blob",
  "blog",
  "bounty",
  "branches",
  "business",
  "businesses",
  "c",
  "cache",
  "case-studies",
  "categories",
  "central",
  "certification",
  "changelog",
  "cla",
  "cloud",
  "codereview",
  "collection",
  "collections",
  "comments",
  "commit",
  "commits",
  "community",
  "companies",
  "compare",
  "contact",
  "contributing",
  "cookbook",
  "coupons",
  "customer-stories",
  "customer",
  "customers",
  "dashboard",
  "dashboards",
  "design",
  "develop",
  "developer",
  "diff",
  "discover",
  "discussions",
  "docs",
  "downloads",
  "downtime",
  "editor",
  "editors",
  "edu",
  "enterprise",
  "events",
  "explore",
  "featured",
  "features",
  "files",
  "fixtures",
  "forked",
  "garage",
  "ghost",
  "gist",
  "gists",
  "graphs",
  "guide",
  "guides",
  "help",
  "help-wanted",
  "home",
  "hooks",
  "hosting",
  "hovercards",
  "identity",
  "images",
  "inbox",
  "individual",
  "info",
  "integration",
  "interfaces",
  "introduction",
  "invalid-email-address",
  "investors",
  "issues",
  "jobs",
  "join",
  "journal",
  "journals",
  "lab",
  "labs",
  "languages",
  "launch",
  "layouts",
  "learn",
  "legal",
  "library",
  "linux",
  "listings",
  "lists",
  "login",
  "logos",
  "logout",
  "mac",
  "maintenance",
  "malware",
  "man",
  "marketplace",
  "mention",
  "mentioned",
  "mentioning",
  "mentions",
  "migrating",
  "milestones",
  "mine",
  "mirrors",
  "mobile",
  "navigation",
  "network",
  "new",
  "news",
  "none",
  "nonprofit",
  "nonprofits",
  "notices",
  "notifications",
  "oauth",
  "offer",
  "open-source",
  "organisations",
  "organizations",
  "orgs",
  "pages",
  "partners",
  "payments",
  "personal",
  "plans",
  "plugins",
  "popular",
  "popularity",
  "posts",
  "press",
  "pricing",
  "professional",
  "projects",
  "pulls",
  "raw",
  "readme",
  "recommendations",
  "redeem",
  "releases",
  "render",
  "reply",
  "repositories",
  "resources",
  "restore",
  "revert",
  "save-net-neutrality",
  "saved",
  "scraping",
  "search",
  "security",
  "services",
  "sessions",
  "settings",
  "shareholders",
  "shop",
  "showcases",
  "signin",
  "signup",
  "site",
  "spam",
  "sponsors",
  "ssh",
  "staff",
  "starred",
  "stars",
  "static",
  "status",
  "statuses",
  "storage",
  "store",
  "stories",
  "styleguide",
  "subscriptions",
  "suggest",
  "suggestion",
  "suggestions",
  "support",
  "suspended",
  "talks",
  "teach",
  "teacher",
  "teachers",
  "teaching",
  "team",
  "teams",
  "ten",
  "terms",
  "timeline",
  "topic",
  "topics",
  "tos",
  "tour",
  "train",
  "training",
  "translations",
  "tree",
  "trending",
  "updates",
  "username",
  "users",
  "visualization",
  "w",
  "watching",
  "wiki",
  "windows",
  "works-with",
  "www0",
  "www1",
  "www2",
  "www3",
  "www4",
  "www5",
  "www6",
  "www7",
  "www8",
  "www9"
];
const $ = (selector) => document.querySelector(selector);
const exists = (selector) => Boolean($(selector));
const is404 = () => document.title.startsWith("Page not found \xB7 GitHub");
const is500 = () => document.title === "Server Error \xB7 GitHub" || document.title === "Unicorn! \xB7 GitHub" || document.title === "504 Gateway Time-out";
const isPasswordConfirmation = () => document.title === "Confirm password" || document.title === "Confirm access";
const isBlame = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("blame/"));
};
const isCommit = (url = location) => isSingleCommit(url) || isPRCommit(url);
const isCommitList = (url = location) => isRepoCommitList(url) || isPRCommitList(url);
const isRepoCommitList = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("commits"));
};
const isCompare = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("compare"));
};
const isCompareWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).split("/").slice(3, 5).includes("_compare");
const isDashboard = (url = location) => !isGist(url) && /^$|^(orgs\/[^/]+\/)?dashboard(\/|$)/.test(getCleanPathname(url));
const isEnterprise = (url = location) => url.hostname !== "github.com" && url.hostname !== "gist.github.com";
const isGist = (url = location) => url.hostname.startsWith("gist.") || url.pathname.split("/", 2)[1] === "gist";
const isGlobalConversationList = (url = location) => ["issues", "pulls"].includes(url.pathname.split("/", 2)[1]);
const isGlobalSearchResults = (url = location) => url.pathname === "/search" && new URLSearchParams(url.search).get("q") !== null;
const isIssue = (url = location) => {
  var _a;
  return /^issues\/\d+/.test((_a = getRepo(url)) == null ? void 0 : _a.path) && document.title !== "GitHub \xB7 Where software is built";
};
const isConversationList = (url = location) => isGlobalConversationList(url) || isRepoConversationList(url) || isMilestone(url);
const isConversation = (url = location) => isIssue(url) || isPRConversation(url);
const isLabelList = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "labels";
};
const isMilestone = (url = location) => {
  var _a;
  return /^milestone\/\d+/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isMilestoneList = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "milestones";
};
const isNewFile = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("new"));
};
const isNewIssue = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "issues/new";
};
const isNewRelease = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "releases/new";
};
const isNewWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_new");
const isNotifications = (url = location) => getCleanPathname(url) === "notifications";
const isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]');
const isOrganizationRepo = () => {
  var _a;
  return Boolean((_a = document.querySelector("[data-owner-scoped-search-url]")) == null ? void 0 : _a.dataset["ownerScopedSearchUrl"].startsWith("/org"));
};
const isOrganizationDiscussion = (url = location) => /^orgs\/[^/]+\/teams\/[^/]+($|\/discussions)/.test(getCleanPathname(url));
const isOwnUserProfile = () => getCleanPathname() === getUsername();
const isOwnOrganizationProfile = () => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]');
const isProject = (url = location) => {
  var _a;
  return /^projects\/\d+/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isProjects = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "projects";
};
const isDiscussion = (url = location) => {
  var _a;
  return /^discussions\/\d+/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isDiscussionList = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "discussions";
};
const isPR = (url = location) => {
  var _a;
  return /^pull\/\d+/.test((_a = getRepo(url)) == null ? void 0 : _a.path) && !isPRConflicts(url);
};
const isPRConflicts = (url = location) => {
  var _a;
  return /^pull\/\d+\/conflicts/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isPRList = (url = location) => {
  var _a;
  return url.pathname === "/pulls" || ((_a = getRepo(url)) == null ? void 0 : _a.path) === "pulls";
};
const isPRCommit = (url = location) => {
  var _a;
  return /^pull\/\d+\/commits\/[\da-f]{5,40}$/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit range not found \xB7 Pull Request");
const isPRFile404 = () => isPRFiles() && document.title.startsWith("Commit range not found \xB7 Pull Request");
const isPRConversation = (url = location) => {
  var _a;
  return /^pull\/\d+$/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isPRCommitList = (url = location) => {
  var _a;
  return /^pull\/\d+\/commits$/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isPRFiles = (url = location) => {
  var _a;
  return /^pull\/\d+\/files/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isQuickPR = (url = location) => isCompare(url) && /[?&]quick_pull=1(&|$)/.test(url.search);
const isDraftPR = () => exists('#partial-discussion-header [title="Status: Draft"]');
const isOpenPR = () => exists('#partial-discussion-header [title="Status: Open"], #partial-discussion-header [title="Status: Draft"]');
const isMergedPR = () => exists('#partial-discussion-header [title="Status: Merged"]');
const isClosedConversation = () => exists('#partial-discussion-header :is([title="Status: Closed"], [title="Status: Merged"], [title="Status: Closed as not planned"])');
const isClosedPR = isClosedConversation;
const isReleases = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "releases";
};
const isTags = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "tags";
};
const isSingleTag = (url = location) => {
  var _a;
  return /^(releases\/tag)/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isReleasesOrTags = (url = location) => isReleases(url) || isTags(url) || isSingleTag(url);
const isDeletingFile = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("delete"));
};
const isEditingFile = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("edit"));
};
const hasFileEditor = (url = location) => isEditingFile(url) || isNewFile(url) || isDeletingFile(url);
const isEditingRelease = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("releases/edit"));
};
const hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url);
const isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit");
const hasWikiPageEditor = (url = location) => isEditingWikiPage(url) || isNewWikiPage(url);
const isRepo = (url = location) => /^[^/]+\/[^/]+/.test(getCleanPathname(url)) && !reservedNames.includes(url.pathname.split("/", 2)[1]) && !isDashboard(url) && !isGist(url) && !isRepoSearch(url) && !isNewRepoTemplate(url);
const isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]');
const isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]');
const isArchivedRepo = () => Boolean(isRepo() && $("#repository-container-header .Label").textContent.endsWith("archive"));
const isBlank = () => exists("main .blankslate");
const isRepoTaxonomyConversationList = (url = location) => {
  var _a;
  return /^labels\/.+|^milestones\/\d+(?!\/edit)/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isRepoConversationList = (url = location) => isRepoPRList(url) || isRepoIssueList(url) || isRepoTaxonomyConversationList(url);
const isRepoPRList = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("pulls"));
};
const isRepoIssueList = (url = location) => {
  var _a;
  return /^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isRepoHome = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "";
};
const isRepoRoot = (url) => {
  const repository = getRepo(url != null ? url : location);
  if (!repository) {
    return false;
  }
  if (!repository.path) {
    return true;
  }
  if (url) {
    return /^tree\/[^/]+$/.test(repository.path);
  }
  return repository.path.startsWith("tree/") && document.title.startsWith(repository.nameWithOwner) && !document.title.endsWith(repository.nameWithOwner);
};
const isRepoSearch = (url = location) => url.pathname.split("/")[3] === "search";
const isRepoSettings = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("settings"));
};
const isRepoMainSettings = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "settings";
};
const isRepliesSettings = (url = location) => url.pathname.startsWith("/settings/replies");
const isUserSettings = (url = location) => url.pathname.startsWith("/settings/");
const isRepoTree = (url = location) => {
  var _a;
  return isRepoRoot(url) || Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("tree/"));
};
const isRepoWiki = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("wiki"));
};
const isSingleCommit = (url = location) => {
  var _a;
  return /^commit\/[\da-f]{5,40}$/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isSingleFile = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("blob/"));
};
const isFileFinder = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("find/"));
};
const isRepoForksList = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "network/members";
};
const isRepoNetworkGraph = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "network";
};
const isForkedRepo = () => exists('meta[name="octolytics-dimension-repository_is_fork"][content="true"]');
const isSingleGist = (url = location) => isGist(url) && /^\/(gist\/)?[^/]+\/[\da-f]{32}$/.test(url.pathname);
const isGistRevision = (url = location) => isGist(url) && /^\/(gist\/)?[^/]+\/[\da-f]{32}\/revisions$/.test(url.pathname);
const isTrending = (url = location) => url.pathname === "/trending" || url.pathname.startsWith("/trending/");
const isBranches = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("branches"));
};
const isProfile = (url = location) => {
  const pathname = getCleanPathname(url);
  return pathname.length > 0 && !pathname.includes("/") && !pathname.includes(".") && !reservedNames.includes(pathname);
};
const isUserProfile = () => isProfile() && !isOrganizationProfile();
const isPrivateUserProfile = () => isUserProfile() && !exists(".user-following-container");
const isUserProfileMainTab = () => isUserProfile() && !new URLSearchParams(location.search).has("tab");
const isUserProfileRepoTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "repositories";
const isUserProfileStarsTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "stars";
const isUserProfileFollowersTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "followers";
const isUserProfileFollowingTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "following";
const hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isOrganizationDiscussion(url) || isSingleGist(url);
const hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url);
const hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isRepoSearch(url) || isGlobalSearchResults(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isCompareWikiPage(url) || isBlame(url);
const hasFiles = (url = location) => isCommit(url) || isCompare(url) || isPRFiles(url);
const isMarketplaceAction = (url = location) => url.pathname.startsWith("/marketplace/actions/");
const isActionJobRun = (url = location) => {
  var _a;
  return Boolean((_a = getRepo(url)) == null ? void 0 : _a.path.startsWith("runs/"));
};
const isActionRun = (url = location) => {
  var _a;
  return /^(actions\/)?runs/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isNewAction = (url = location) => {
  var _a;
  return ((_a = getRepo(url)) == null ? void 0 : _a.path) === "actions/new";
};
const isRepositoryActions = (url = location) => {
  var _a;
  return /^actions(\/workflows\/.+\.ya?ml)?$/.test((_a = getRepo(url)) == null ? void 0 : _a.path);
};
const isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]');
const canUserEditOrganization = isUserTheOrganizationOwner;
const canUserEditRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]');
const isNewRepo = (url = location) => url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url));
const isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate");
const getUsername = () => {
  var _a;
  return (_a = document.querySelector('meta[name="user-login"]')) == null ? void 0 : _a.getAttribute("content");
};
const getCleanPathname = (url = location) => url.pathname.replace(/\/+/g, "/").slice(1, url.pathname.endsWith("/") ? -1 : void 0);
const getRepo = (url) => {
  if (!url) {
    const canonical = document.querySelector('[property="og:url"]');
    if (canonical) {
      const canonicalUrl = new URL(canonical.content, location.origin);
      if (getCleanPathname(canonicalUrl).toLowerCase() === getCleanPathname(location).toLowerCase()) {
        url = canonicalUrl;
      }
    }
  }
  if (typeof url === "string") {
    url = new URL(url, location.origin);
  }
  if (!isRepo(url)) {
    return;
  }
  const [owner, name, ...path] = getCleanPathname(url).split("/");
  return {
    owner,
    name,
    nameWithOwner: owner + "/" + name,
    path: path.join("/")
  };
};
const utils = {
  getUsername,
  getCleanPathname,
  getRepositoryInfo: getRepo
};
export {
  canUserEditOrganization,
  canUserEditRepo,
  hasCode,
  hasComments,
  hasFileEditor,
  hasFiles,
  hasReleaseEditor,
  hasRichTextEditor,
  hasWikiPageEditor,
  is404,
  is500,
  isActionJobRun,
  isActionRun,
  isArchivedRepo,
  isBlame,
  isBlank,
  isBranches,
  isClosedConversation,
  isClosedPR,
  isCommit,
  isCommitList,
  isCompare,
  isCompareWikiPage,
  isConversation,
  isConversationList,
  isDashboard,
  isDeletingFile,
  isDiscussion,
  isDiscussionList,
  isDraftPR,
  isEditingFile,
  isEditingRelease,
  isEditingWikiPage,
  isEmptyRepo,
  isEmptyRepoRoot,
  isEnterprise,
  isFileFinder,
  isForkedRepo,
  isGist,
  isGistRevision,
  isGlobalConversationList,
  isGlobalSearchResults,
  isIssue,
  isLabelList,
  isMarketplaceAction,
  isMergedPR,
  isMilestone,
  isMilestoneList,
  isNewAction,
  isNewFile,
  isNewIssue,
  isNewRelease,
  isNewRepo,
  isNewRepoTemplate,
  isNewWikiPage,
  isNotifications,
  isOpenPR,
  isOrganizationDiscussion,
  isOrganizationProfile,
  isOrganizationRepo,
  isOwnOrganizationProfile,
  isOwnUserProfile,
  isPR,
  isPRCommit,
  isPRCommit404,
  isPRCommitList,
  isPRConflicts,
  isPRConversation,
  isPRFile404,
  isPRFiles,
  isPRList,
  isPasswordConfirmation,
  isPrivateUserProfile,
  isProfile,
  isProject,
  isProjects,
  isQuickPR,
  isReleases,
  isReleasesOrTags,
  isRepliesSettings,
  isRepo,
  isRepoCommitList,
  isRepoConversationList,
  isRepoForksList,
  isRepoHome,
  isRepoIssueList,
  isRepoMainSettings,
  isRepoNetworkGraph,
  isRepoPRList,
  isRepoRoot,
  isRepoSearch,
  isRepoSettings,
  isRepoTaxonomyConversationList,
  isRepoTree,
  isRepoWiki,
  isRepositoryActions,
  isSingleCommit,
  isSingleFile,
  isSingleGist,
  isSingleTag,
  isTags,
  isTrending,
  isUserProfile,
  isUserProfileFollowersTab,
  isUserProfileFollowingTab,
  isUserProfileMainTab,
  isUserProfileRepoTab,
  isUserProfileStarsTab,
  isUserSettings,
  isUserTheOrganizationOwner,
  utils
};

@fregante
Copy link
Member Author

fregante commented Jul 23, 2022

One thing I tried to do was to turn on ES2021 output in order to get the native ?. but Vite refuses to follows the build.target option and tsconfig’s compilerOptions.target 😰

"browserslist": [
"last 2 versions",
"not IE <= 11"
],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was probably due to this. It works now, but I'll send it as a separate PR

@fregante fregante merged commit 1d9e93f into main Jul 23, 2022
@fregante fregante deleted the next branch July 23, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant