diff --git a/packages/github-actions-grafana-jump/package.json b/packages/github-actions-grafana-jump/package.json index b8d3a9b..5381507 100644 --- a/packages/github-actions-grafana-jump/package.json +++ b/packages/github-actions-grafana-jump/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "@types/greasemonkey": "~4.0.7", - "typescript": "~5.8.3" + "typescript": "~6.0.3" } } diff --git a/packages/github-actions-grafana-jump/tsconfig.json b/packages/github-actions-grafana-jump/tsconfig.json index b813d42..7dc0f4f 100644 --- a/packages/github-actions-grafana-jump/tsconfig.json +++ b/packages/github-actions-grafana-jump/tsconfig.json @@ -2,7 +2,13 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "./dist", - "rootDir": "./src" + "rootDir": "./src", + // This is the only package that references ambient globals from + // @types/node (the `module` test-export guard) and @types/greasemonkey + // (`GM`). Under moduleResolution: bundler, tsc does not auto-include + // these from node_modules/@types the way it does under "node"/"node10" - + // list them explicitly rather than relying on that auto-discovery. + "types": ["node", "greasemonkey"] }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"] diff --git a/packages/graphite-to-github-button/src/index.ts b/packages/graphite-to-github-button/src/index.ts new file mode 100644 index 0000000..cdcdbff --- /dev/null +++ b/packages/graphite-to-github-button/src/index.ts @@ -0,0 +1,67 @@ +// ==UserScript== +// @name Graphite => GitHub button +// @description Add a button to go from app.graphite.dev to github.com +// @match https://app.graphite.dev/* +// @version 0.3.3 +// @run-at document-start +// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== +// @grant none +// @license MIT +// @namespace https://app.graphite.dev +// @downloadURL https://update.greasyfork.org/scripts/509841/Graphite%20%3D%3E%20GitHub%20button.user.js +// @updateURL https://update.greasyfork.org/scripts/509841/Graphite%20%3D%3E%20GitHub%20button.meta.js +// ==/UserScript== + +const PATH_REGEX = /^\/github\/pr\/([^\/]+)\/([^\/]+)\/([^\/]+).*$/; +const SELECTOR = + '[class^="PullRequestTitleBar_container_"] > div:nth-child(1) > div:nth-child(2)'; + +const addButton = (toolbar: HTMLElement) => { + const match = window.location.pathname.match(PATH_REGEX); + if (!match) return; + + const [_, org, repo, pr] = match; + const gitHubLink = `https://github.com/${org}/${repo}/pull/${pr}`; + + if (document.getElementById("gitHubLink") != null) { + return; + } + + const anchorEl = document.createElement("a"); + anchorEl.setAttribute("id", "gitHubLink"); + anchorEl.setAttribute("href", gitHubLink); + anchorEl.setAttribute("target", "_blank"); + anchorEl.setAttribute( + "style", + "background: #f0f0f333; padding: 6px; border-radius: 4px; flex-shrink: 0;" + ); + anchorEl.appendChild(document.createTextNode("GitHub ↗️")); + + toolbar.appendChild(anchorEl); +}; + +const toolbarObserver = new MutationObserver((_, observer) => { + const toolbar = document.querySelector(SELECTOR) as HTMLElement; + if (toolbar) { + observer.disconnect(); + addButton(toolbar); + } +}); + +let lastPathname: string | undefined; +const routeChangeObserver = new MutationObserver(() => { + const { pathname } = window.location; + + if (pathname !== lastPathname) { + lastPathname = pathname; + + if (pathname.match(PATH_REGEX)) { + toolbarObserver.observe(document.body, { + childList: true, + subtree: true, + }); + } + } +}); + +routeChangeObserver.observe(document.body, { childList: true, subtree: true }); diff --git a/tsconfig.base.json b/tsconfig.base.json index 1173bc3..37e27ab 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -3,7 +3,11 @@ "target": "ES2020", "module": "ESNext", "lib": ["ES2020", "DOM"], - "moduleResolution": "node", + // "node" (an alias for the legacy "node10" strategy) is deprecated as of + // TypeScript 6.0 and will stop functioning in 7.0 (TS5107). "bundler" is + // the modern pairing for `module: ESNext`; no package in this repo does + // external module imports, so this has no effect on compiled output. + "moduleResolution": "bundler", "strict": true, "esModuleInterop": true, "skipLibCheck": true, diff --git a/yarn.lock b/yarn.lock index b0e4be6..e7cab71 100644 --- a/yarn.lock +++ b/yarn.lock @@ -410,7 +410,7 @@ __metadata: resolution: "@nsheaps/gm-github-actions-grafana-jump@workspace:packages/github-actions-grafana-jump" dependencies: "@types/greasemonkey": "npm:~4.0.7" - typescript: "npm:~5.8.3" + typescript: "npm:~6.0.3" languageName: unknown linkType: soft