Skip to content

Commit

Permalink
Update dependencies (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored May 31, 2024
1 parent 0bb2aad commit d4941d8
Show file tree
Hide file tree
Showing 7 changed files with 2,834 additions and 3,079 deletions.
37 changes: 15 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
env: {}

# FILE GENERATED WITH: npx ghat fregante/ghatemplates/node
# SOURCE: https://github.com/fregante/ghatemplates

name: CI

on:
Expand All @@ -13,30 +8,28 @@ jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install
run: npm ci || npm install
- name: XO
run: npx xo
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: package.json
- run: npm ci
- run: npx xo

Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install
run: npm ci || npm install
- name: build
run: npm run build --if-present
- name: Test
run: npm run test:unit
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: package.json
- run: npm ci
- run: npm run test:unit

Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install
run: npm ci || npm install
- name: build
run: npm run build
- uses: actions/checkout@v4
- run: npm ci
- run: npm run build
- name: Ensure that test URLs aren't included in the built file
run: '! grep http distribution/index.js'
1 change: 1 addition & 0 deletions collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export const testableUrls = new Map<string, string[]>();

export function addTests(test: string, urls: string[]): void {
// eslint-disable-next-line n/prefer-global/process -- Better not import `process` to avoid bundling its polyfills by mistake
if (process.env.NODE_ENV !== 'bundling') {
testableUrls.set(test, urls);
}
Expand Down
5 changes: 5 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Broaden types because testing against `"undefined"` is fine for our regexes
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- Module augmentation
interface RegExp {
test(s: string | undefined): boolean;
}
38 changes: 19 additions & 19 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import reservedNames from 'github-reserved-names/reserved-names.json' assert {type: 'json'};
import reservedNames from 'github-reserved-names/reserved-names.json' with {type: 'json'};
import {addTests} from './collector.js';

const $ = <E extends Element>(selector: string) => document.querySelector<E>(selector);
Expand Down Expand Up @@ -130,7 +130,7 @@ addTests('isGlobalSearchResults', [
'https://github.com/search?q=refined-github&ref=opensearch',
]);

export const isIssue = (url: URL | HTMLAnchorElement | Location = location): boolean => /^issues\/\d+/.test(getRepo(url)?.path!) && document.title !== 'GitHub · Where software is built'; // The title check excludes deleted issues
export const isIssue = (url: URL | HTMLAnchorElement | Location = location): boolean => /^issues\/\d+/.test(getRepo(url)?.path) && document.title !== 'GitHub · Where software is built'; // The title check excludes deleted issues
addTests('isIssue', [
'https://github.com/sindresorhus/refined-github/issues/146',
]);
Expand All @@ -150,7 +150,7 @@ addTests('isLabelList', [
'https://github.com/sindresorhus/refined-github/labels/',
]);

export const isMilestone = (url: URL | HTMLAnchorElement | Location = location): boolean => /^milestone\/\d+/.test(getRepo(url)?.path!);
export const isMilestone = (url: URL | HTMLAnchorElement | Location = location): boolean => /^milestone\/\d+/.test(getRepo(url)?.path);
addTests('isMilestone', [
'https://github.com/kubernetes/kubernetes/milestone/56',
]);
Expand Down Expand Up @@ -201,7 +201,7 @@ export const isOwnUserProfile = (): boolean => getCleanPathname() === getUsernam
// If there's a Report Abuse link, we're not part of the org
export const isOwnOrganizationProfile = (): boolean => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]');

export const isProject = (url: URL | HTMLAnchorElement | Location = location): boolean => /^projects\/\d+/.test(getRepo(url)?.path!);
export const isProject = (url: URL | HTMLAnchorElement | Location = location): boolean => /^projects\/\d+/.test(getRepo(url)?.path);
addTests('isProject', [
'https://github.com/sindresorhus/refined-github/projects/3',
]);
Expand All @@ -211,7 +211,7 @@ addTests('isProjects', [
'https://github.com/sindresorhus/refined-github/projects',
]);

export const isDiscussion = (url: URL | HTMLAnchorElement | Location = location): boolean => /^discussions\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path!);
export const isDiscussion = (url: URL | HTMLAnchorElement | Location = location): boolean => /^discussions\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path);
addTests('isDiscussion', [
'https://github.com/tophf/mpiv/discussions/50',
'https://github.com/orgs/community/discussions/11202',
Expand All @@ -229,14 +229,14 @@ addTests('isDiscussionList', [
'https://github.com/orgs/community/discussions',
]);

export const isPR = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+/.test(getRepo(url)?.path!) && !isPRConflicts(url);
export const isPR = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+/.test(getRepo(url)?.path) && !isPRConflicts(url);
addTests('isPR', [
'isPRFiles',
'isPRCommitList',
'https://github.com/sindresorhus/refined-github/pull/148',
]);

export const isPRConflicts = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/conflicts/.test(getRepo(url)?.path!);
export const isPRConflicts = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/conflicts/.test(getRepo(url)?.path);
addTests('isPRConflicts', [
'https://github.com/sindresorhus/refined-github/pull/148/conflicts',
]);
Expand All @@ -252,7 +252,7 @@ addTests('isPRList', [
'https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed',
]);

export const isPRCommit = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/commits\/[\da-f]{5,40}$/.test(getRepo(url)?.path!);
export const isPRCommit = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/commits\/[\da-f]{5,40}$/.test(getRepo(url)?.path);
addTests('isPRCommit', [
'https://github.com/sindresorhus/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85',
'https://github.com/sindresorhus/refined-github/pull/148/commits/00196',
Expand All @@ -261,17 +261,17 @@ addTests('isPRCommit', [
export const isPRCommit404 = (): boolean => isPRCommit() && document.title.startsWith('Commit range not found · Pull Request');
export const isPRFile404 = (): boolean => isPRFiles() && document.title.startsWith('Commit range not found · Pull Request');

export const isPRConversation = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+$/.test(getRepo(url)?.path!);
export const isPRConversation = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+$/.test(getRepo(url)?.path);
addTests('isPRConversation', [
'https://github.com/sindresorhus/refined-github/pull/148',
]);

export const isPRCommitList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/commits$/.test(getRepo(url)?.path!);
export const isPRCommitList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/commits$/.test(getRepo(url)?.path);
addTests('isPRCommitList', [
'https://github.com/sindresorhus/refined-github/pull/148/commits',
]);

export const isPRFiles = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/files/.test(getRepo(url)?.path!) || isPRCommit(url);
export const isPRFiles = (url: URL | HTMLAnchorElement | Location = location): boolean => /^pull\/\d+\/files/.test(getRepo(url)?.path) || isPRCommit(url);
addTests('isPRFiles', [
'isPRCommit', // File contents but lacks "Viewed" checkbox, has commit information
'https://github.com/sindresorhus/refined-github/pull/148/files',
Expand Down Expand Up @@ -378,7 +378,7 @@ export const isArchivedRepo = (): boolean => Boolean(isRepo() && $('main > .flas

export const isBlank = (): boolean => exists('main .blankslate:not([hidden] .blankslate)');

export const isRepoTaxonomyIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(getRepo(url)?.path!);
export const isRepoTaxonomyIssueOrPRList = (url: URL | HTMLAnchorElement | Location = location): boolean => /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(getRepo(url)?.path);
addTests('isRepoTaxonomyIssueOrPRList', [
'https://github.com/sindresorhus/refined-github/labels/bug',
'https://github.com/sindresorhus/refined-github/labels/implemented%20by%20github',
Expand All @@ -402,7 +402,7 @@ addTests('isRepoPRList', [

export const isRepoIssueList = (url: URL | HTMLAnchorElement | Location = location): boolean =>
// `issues/fregante` is a list but `issues/1`, `issues/new`, `issues/new/choose`, `issues/templates/edit` aren’t
/^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test(getRepo(url)?.path!);
/^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test(getRepo(url)?.path);
addTests('isRepoIssueList', [
'http://github.com/sindresorhus/ava/issues',
'https://github.com/sindresorhus/refined-github/issues',
Expand Down Expand Up @@ -513,7 +513,7 @@ addTests('isRepoWiki', [
'https://github.com/brookhong/Surfingkeys/wiki/Color-Themes/_compare/8ebb46b1a12d16fc1af442b7df0ca13ca3bb34dc...80e51eeabe69b15a3f23880ecc36f800b71e6c6d',
]);

export const isSingleCommit = (url: URL | HTMLAnchorElement | Location = location): boolean => /^commit\/[\da-f]{5,40}$/.test(getRepo(url)?.path!);
export const isSingleCommit = (url: URL | HTMLAnchorElement | Location = location): boolean => /^commit\/[\da-f]{5,40}$/.test(getRepo(url)?.path);
addTests('isSingleCommit', [
'https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f',
'https://github.com/sindresorhus/refined-github/commit/5b614',
Expand Down Expand Up @@ -549,14 +549,14 @@ addTests('isRepoNetworkGraph', [

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

export const isSingleGist = (url: URL | HTMLAnchorElement | Location = location): boolean => /^[^/]+\/[\da-f]{20,32}(\/[\da-f]{40})?$/.test(getCleanGistPathname(url)!);
export const isSingleGist = (url: URL | HTMLAnchorElement | Location = location): boolean => /^[^/]+\/[\da-f]{20,32}(\/[\da-f]{40})?$/.test(getCleanGistPathname(url));
addTests('isSingleGist', [
'https://gist.github.com/fregante/2205329b71218fa2c1d3',
'https://gist.github.com/fregante/2205329b71218fa2c1d3/d1ebf7d9cfaba4d4596d2ea9174e202479a5f9ad',
'https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064',
]);

export const isGistRevision = (url: URL | HTMLAnchorElement | Location = location): boolean => /^[^/]+\/[\da-f]{20,32}\/revisions$/.test(getCleanGistPathname(url)!);
export const isGistRevision = (url: URL | HTMLAnchorElement | Location = location): boolean => /^[^/]+\/[\da-f]{20,32}\/revisions$/.test(getCleanGistPathname(url));
addTests('isGistRevision', [
'https://gist.github.com/kidonng/0d16c7f17045f486751fad1b602204a0/revisions',
]);
Expand Down Expand Up @@ -713,7 +713,7 @@ addTests('isActionJobRun', [
'https://github.com/refined-github/github-url-detection/runs/1224552520?check_suite_focus=true',
]);

export const isActionRun = (url: URL | HTMLAnchorElement | Location = location): boolean => /^(actions\/)?runs/.test(getRepo(url)?.path!);
export const isActionRun = (url: URL | HTMLAnchorElement | Location = location): boolean => /^(actions\/)?runs/.test(getRepo(url)?.path);
addTests('isActionRun', [
'https://github.com/sindresorhus/refined-github/runs/639481849',
'https://github.com/refined-github/github-url-detection/runs/1224552520?check_suite_focus=true',
Expand All @@ -725,7 +725,7 @@ addTests('isNewAction', [
'https://github.com/sindresorhus/refined-github/actions/new',
]);

export const isRepositoryActions = (url: URL | HTMLAnchorElement | Location = location): boolean => /^actions(\/workflows\/.+\.ya?ml)?$/.test(getRepo(url)?.path!);
export const isRepositoryActions = (url: URL | HTMLAnchorElement | Location = location): boolean => /^actions(\/workflows\/.+\.ya?ml)?$/.test(getRepo(url)?.path);
addTests('isRepositoryActions', [
'https://github.com/refined-github/github-url-detection/actions',
'https://github.com/refined-github/github-url-detection/actions/workflows/demo.yml',
Expand All @@ -749,7 +749,7 @@ addTests('isNewRepoTemplate', [
]);

/** Get the logged-in user’s username */
const getUsername = (): string | undefined => $('meta[name="user-login"]')?.getAttribute('content')!;
const getUsername = (): string | undefined => $('meta[name="user-login"]')?.getAttribute('content') ?? undefined;

/** Drop all duplicate slashes */
const getCleanPathname = (url: URL | HTMLAnchorElement | Location = location): string => url.pathname.replaceAll(/\/+/g, '/').slice(1, url.pathname.endsWith('/') ? -1 : undefined);
Expand Down
Loading

0 comments on commit d4941d8

Please sign in to comment.