diff --git a/package.json b/package.json index fb7472d24027a..fface07eb45c0 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,6 @@ "@spotlightjs/spotlight": "^2.0.0-alpha.1", "@tailwindcss/forms": "^0.5.7", "@tailwindcss/typography": "^0.5.10", - "@types/cli-progress": "^3.11.6", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", diff --git a/scripts/lint-404s/main.ts b/scripts/lint-404s/main.ts index 457ee1c4e2c4f..af3bddc2ff74a 100644 --- a/scripts/lint-404s/main.ts +++ b/scripts/lint-404s/main.ts @@ -4,8 +4,6 @@ import {readFileSync} from 'fs'; import path, {dirname} from 'path'; import {fileURLToPath} from 'url'; -import cliProgress from 'cli-progress'; - const baseURL = 'http://localhost:3000/'; type Link = {href: string; innerText: string}; @@ -14,6 +12,8 @@ const trimSlashes = (s: string) => s.replace(/(^\/|\/$)/g, ''); // @ts-ignore const ignoreListFile = path.join(dirname(import.meta.url), './ignore-list.txt'); +const showProgress = process.argv.includes('--progress'); + // Paths to skip const ignoreList: string[] = readFileSync(fileURLToPath(ignoreListFile), 'utf8') .split('\n') @@ -88,12 +88,9 @@ async function main() { return false; } - const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic); - progressBar.start(slugs.length, 0); - - for (let i = 0; i < slugs.length; i++) { - const slug = slugs[i]; + for (const slug of slugs) { const pageUrl = new URL(slug, baseURL); + const now = performance.now(); const html = await fetchWithFollow(pageUrl.href).then(r => r.text()); const linkRegex = /]*href="([^"]*)"[^>]*>([^<]*)<\/a>/g; @@ -116,7 +113,12 @@ async function main() { all404s.push({slug, page404s}); } - progressBar.increment(); + if (showProgress) { + console.log( + page404s.length ? '❌' : '✅', + `in ${(performance.now() - now).toFixed(1).padStart(4, '0')} ms | ${slug}` + ); + } } if (all404s.length === 0) { @@ -143,22 +145,8 @@ async function main() { return true; } const now = performance.now(); - -const humanReadableMs = (ms: number) => { - const oneSecond = 1000; - const oneMinute = oneSecond * 60; - if (ms < oneSecond) { - return `${ms.toFixed(1)} ms`; - } - if (ms < oneMinute) { - return `${(ms / 1000).toFixed(1)} s`; - } - // show minutes and seconds - return `${Math.floor(ms / oneMinute)} m ${((ms % oneMinute) / 1000).toFixed(1)} s`; -}; - main().then(has404s => { - console.log(`\n Done in ${humanReadableMs(performance.now() - now)}`); + console.log(`\n Done in ${(performance.now() - now).toFixed(1)} ms`); process.exit(has404s ? 1 : 0); }); diff --git a/yarn.lock b/yarn.lock index 678b7b9badfa4..ba3e621719def 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2815,13 +2815,6 @@ resolved "https://registry.yarnpkg.com/@types/caseless/-/caseless-0.12.5.tgz#db9468cb1b1b5a925b8f34822f1669df0c5472f5" integrity sha512-hWtVTC2q7hc7xZ/RLbxapMvDMgUnDvKvMOpKal4DrMyfGBUfB1oKaZlIRr6mJL+If3bAP6sV/QneGzF6tJjZDg== -"@types/cli-progress@^3.11.6": - version "3.11.6" - resolved "https://registry.yarnpkg.com/@types/cli-progress/-/cli-progress-3.11.6.tgz#94b334ebe4190f710e51c1bf9b4fedb681fa9e45" - integrity sha512-cE3+jb9WRlu+uOSAugewNpITJDt1VF8dHOopPO4IABFc3SXYL5WE/+PTz/FCdZRRfIujiWW3n3aMbv1eIGVRWA== - dependencies: - "@types/node" "*" - "@types/connect@*": version "3.4.38" resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.38.tgz#5ba7f3bc4fbbdeaff8dded952e5ff2cc53f8d858"