From ad5157764df33062ed753dce2a8a65597adac785 Mon Sep 17 00:00:00 2001 From: Kevin Heis Date: Mon, 18 Aug 2025 15:48:33 -0700 Subject: [PATCH] Remove remaining .js in package.json scripts (#57114) --- package.json | 20 ++++++------- src/codeql-cli/scripts/{sync.js => sync.ts} | 4 +-- .../{lint-content.js => lint-content.ts} | 5 ++-- .../{lint-report.js => lint-report.ts} | 29 ++++++++++--------- .../tests/{lint-files.js => lint-files.ts} | 1 + .../{move-content.js => move-content.ts} | 3 +- src/graphql/scripts/{sync.js => sync.ts} | 1 + src/rest/{docs.js => docs.ts} | 8 +++-- ...y-fixture-data.js => copy-fixture-data.ts} | 6 ++-- 9 files changed, 42 insertions(+), 35 deletions(-) rename src/codeql-cli/scripts/{sync.js => sync.ts} (96%) rename src/content-linter/scripts/{lint-content.js => lint-content.ts} (99%) rename src/content-linter/scripts/{lint-report.js => lint-report.ts} (85%) rename src/content-linter/tests/{lint-files.js => lint-files.ts} (99%) rename src/content-render/scripts/{move-content.js => move-content.ts} (99%) rename src/graphql/scripts/{sync.js => sync.ts} (99%) rename src/rest/{docs.js => docs.ts} (93%) rename src/tests/scripts/{copy-fixture-data.js => copy-fixture-data.ts} (95%) diff --git a/package.json b/package.json index e65bd8b958..4ef3a13984 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "clone-translations": "./src/languages/scripts/clone-translations.sh", "cmp-files": "tsx src/workflows/cmp-files.ts", "content-changes-table-comment": "tsx src/workflows/content-changes-table-comment.ts", - "copy-fixture-data": "tsx src/tests/scripts/copy-fixture-data.js", + "copy-fixture-data": "tsx src/tests/scripts/copy-fixture-data.ts", "count-translation-corruptions": "tsx src/languages/scripts/count-translation-corruptions.ts", "create-enterprise-issue": "tsx src/ghes-releases/scripts/create-enterprise-issue.ts", "debug": "cross-env NODE_ENV=development ENABLED_LANGUAGES=en nodemon --inspect src/frame/server.ts", @@ -58,16 +58,16 @@ "index-test-fixtures": "./src/search/scripts/index-test-fixtures.sh", "labeler": "tsx .github/actions/labeler/labeler.ts", "lint": "eslint '**/*.{js,mjs,ts,tsx}'", - "lint-content": "tsx src/content-linter/scripts/lint-content.js", - "lint-translation": "vitest src/content-linter/tests/lint-files.js", + "lint-content": "tsx src/content-linter/scripts/lint-content.ts", + "lint-translation": "vitest src/content-linter/tests/lint-files.ts", "liquid-markdown-tables": "tsx src/tools/scripts/liquid-markdown-tables/index.ts", "generate-article-api-docs": "tsx src/article-api/scripts/generate-api-docs.ts", "generate-code-scanning-query-list": "tsx src/code-scanning/scripts/generate-code-scanning-query-list.ts", "generate-content-linter-docs": "tsx src/content-linter/scripts/generate-docs.ts", - "move-content": "tsx src/content-render/scripts/move-content.js", - "openapi-docs": "tsx src/rest/docs.js", + "move-content": "tsx src/content-render/scripts/move-content.ts", + "openapi-docs": "tsx src/rest/docs.ts", "playwright-test": "playwright test --config src/fixtures/playwright.config.ts --project=\"Google Chrome\"", - "lint-report": "tsx src/content-linter/scripts/lint-report.js", + "lint-report": "tsx src/content-linter/scripts/lint-report.ts", "postinstall": "cp package-lock.json .installed.package-lock.json && echo \"Updated .installed.package-lock.json\" # see husky/post-checkout and husky/post-merge", "precompute-pageinfo": "tsx src/article-api/scripts/precompute-pageinfo.ts", "prepare": "husky src/workflows/husky", @@ -75,7 +75,7 @@ "prettier-check": "prettier -c \"**/*.{ts,tsx,js,mjs,scss,yml,yaml}\"", "prevent-pushes-to-main": "tsx src/workflows/prevent-pushes-to-main.ts", "purge-fastly-edge-cache": "tsx src/workflows/purge-fastly-edge-cache.ts", - "purge-fastly-edge-cache-per-language": "tsx src/languages/scripts/purge-fastly-edge-cache-per-language.js", + "purge-fastly-edge-cache-per-language": "tsx src/languages/scripts/purge-fastly-edge-cache-per-language.ts", "readability-report": "tsx src/workflows/experimental/readability-report.ts", "ready-for-docs-review": "tsx src/workflows/ready-for-docs-review.ts", "release-banner": "tsx src/ghes-releases/scripts/release-banner.ts", @@ -83,15 +83,15 @@ "reusables": "tsx src/content-render/scripts/reusables-cli.ts", "rendered-content-link-checker": "tsx src/links/scripts/rendered-content-link-checker.ts", "rendered-content-link-checker-cli": "tsx src/links/scripts/rendered-content-link-checker-cli.ts", - "rest-dev": "tsx src/rest/scripts/update-files.js", + "rest-dev": "tsx src/rest/scripts/update-files.ts", "show-action-deps": "echo 'Action Dependencies:' && rg '^[\\s|-]*(uses:.*)$' .github -I -N --no-heading -r '$1$2' | sort | uniq | cut -c 7-", "start": "cross-env NODE_ENV=development ENABLED_LANGUAGES=en nodemon src/frame/server.ts", "start-all-languages": "cross-env NODE_ENV=development tsx src/frame/server.ts", "start-for-playwright": "cross-env ROOT=src/fixtures/fixtures TRANSLATIONS_FIXTURE_ROOT=src/fixtures/fixtures/translations ENABLED_LANGUAGES=en,ja NODE_ENV=test tsx src/frame/server.ts", "symlink-from-local-repo": "tsx src/early-access/scripts/symlink-from-local-repo.ts", "sync-audit-log": "tsx src/audit-logs/scripts/sync.ts", - "sync-codeql-cli": "tsx src/codeql-cli/scripts/sync.js", - "sync-graphql": "tsx src/graphql/scripts/sync.js", + "sync-codeql-cli": "tsx src/codeql-cli/scripts/sync.ts", + "sync-graphql": "tsx src/graphql/scripts/sync.ts", "sync-rest": "tsx src/rest/scripts/update-files.ts", "sync-secret-scanning": "tsx src/secret-scanning/scripts/sync.ts", "sync-webhooks": "npx tsx src/rest/scripts/update-files.ts -o webhooks", diff --git a/src/codeql-cli/scripts/sync.js b/src/codeql-cli/scripts/sync.ts similarity index 96% rename from src/codeql-cli/scripts/sync.js rename to src/codeql-cli/scripts/sync.ts index 93ed6a4d62..407b96e056 100755 --- a/src/codeql-cli/scripts/sync.js +++ b/src/codeql-cli/scripts/sync.ts @@ -29,7 +29,7 @@ async function main() { includeBasePath: true, globs: ['**/*.md'], }) - const cliMarkdownContents = {} + const cliMarkdownContents: Record = {} for (const file of markdownFiles) { const sourceContent = await readFile(file, 'utf8') @@ -83,7 +83,7 @@ async function setupEnvironment() { // copy the raw rst files to the temp directory and convert them // to Markdownusing pandoc -async function rstToMarkdown(sourceDirectory) { +async function rstToMarkdown(sourceDirectory: string) { const sourceFiles = walk(sourceDirectory, { includeBasePath: true, globs: ['**/*.rst'], diff --git a/src/content-linter/scripts/lint-content.js b/src/content-linter/scripts/lint-content.ts similarity index 99% rename from src/content-linter/scripts/lint-content.js rename to src/content-linter/scripts/lint-content.ts index 679a126875..2d0f18ca86 100755 --- a/src/content-linter/scripts/lint-content.js +++ b/src/content-linter/scripts/lint-content.ts @@ -1,3 +1,4 @@ +// @ts-nocheck import fs from 'fs' import path from 'path' import { execSync } from 'child_process' @@ -258,7 +259,7 @@ async function main() { } const fixableFiles = Object.entries(formattedResults) - .filter(([_, results]) => results.some((result) => result.fixable)) + .filter(([, results]) => results.some((result) => result.fixable)) .map(([file]) => file) if (fixableFiles.length) { console.log('') // Just for some whitespace before the next message @@ -692,7 +693,7 @@ function isOptionsValid() { for (const path of paths) { try { fs.statSync(path) - } catch (err) { + } catch { if ('paths'.includes(path)) { console.log('error: did you mean --paths') } else { diff --git a/src/content-linter/scripts/lint-report.js b/src/content-linter/scripts/lint-report.ts similarity index 85% rename from src/content-linter/scripts/lint-report.js rename to src/content-linter/scripts/lint-report.ts index 306db8bec2..ce61c9dd95 100644 --- a/src/content-linter/scripts/lint-report.js +++ b/src/content-linter/scripts/lint-report.ts @@ -10,20 +10,21 @@ import { reportingConfig } from '@/content-linter/style/github-docs' // GitHub issue body size limit is ~65k characters, so we'll use 60k as a safe limit const MAX_ISSUE_BODY_SIZE = 60000 +interface LintFlaw { + severity: string + ruleNames: string[] +} + /** * Determines if a lint result should be included in the automated report - * @param {Object} flaw - The lint result object - * @param {string} flaw.severity - 'error' or 'warning' - * @param {string[]} flaw.ruleNames - Array of rule names for this flaw - * @returns {boolean} - True if this flaw should be included in the report */ -function shouldIncludeInReport(flaw) { +function shouldIncludeInReport(flaw: LintFlaw): boolean { if (!flaw.ruleNames || !Array.isArray(flaw.ruleNames)) { return false } // Check if any rule name is in the exclude list - const hasExcludedRule = flaw.ruleNames.some((ruleName) => + const hasExcludedRule = flaw.ruleNames.some((ruleName: string) => reportingConfig.excludeRules.includes(ruleName), ) if (hasExcludedRule) { @@ -36,7 +37,7 @@ function shouldIncludeInReport(flaw) { } // Check if any rule name is in the include list - const hasIncludedRule = flaw.ruleNames.some((ruleName) => + const hasIncludedRule = flaw.ruleNames.some((ruleName: string) => reportingConfig.includeRules.includes(ruleName), ) if (hasIncludedRule) { @@ -88,9 +89,9 @@ async function main() { const parsedResults = JSON.parse(lintResults) // Filter results based on reporting configuration - const filteredResults = {} + const filteredResults: Record = {} for (const [file, flaws] of Object.entries(parsedResults)) { - const filteredFlaws = flaws.filter(shouldIncludeInReport) + const filteredFlaws = (flaws as LintFlaw[]).filter(shouldIncludeInReport) // Only include files that have remaining flaws after filtering if (filteredFlaws.length > 0) { @@ -127,8 +128,8 @@ async function main() { octokit, reportTitle: `Content linting issues requiring attention`, reportBody, - reportRepository: REPORT_REPOSITORY, - reportLabel: REPORT_LABEL, + reportRepository: REPORT_REPOSITORY!, + reportLabel: REPORT_LABEL!, } await createReportIssue(reportProps) @@ -137,9 +138,9 @@ async function main() { core, octokit, newReport: await createReportIssue(reportProps), - reportRepository: REPORT_REPOSITORY, - reportAuthor: REPORT_AUTHOR, - reportLabel: REPORT_LABEL, + reportRepository: REPORT_REPOSITORY!, + reportAuthor: REPORT_AUTHOR!, + reportLabel: REPORT_LABEL!, } await linkReports(linkProps) diff --git a/src/content-linter/tests/lint-files.js b/src/content-linter/tests/lint-files.ts similarity index 99% rename from src/content-linter/tests/lint-files.js rename to src/content-linter/tests/lint-files.ts index 6d517e7f00..e2e62f5252 100755 --- a/src/content-linter/tests/lint-files.js +++ b/src/content-linter/tests/lint-files.ts @@ -1,3 +1,4 @@ +// @ts-nocheck import { fileURLToPath } from 'url' import path from 'path' import yaml from 'js-yaml' diff --git a/src/content-render/scripts/move-content.js b/src/content-render/scripts/move-content.ts similarity index 99% rename from src/content-render/scripts/move-content.js rename to src/content-render/scripts/move-content.ts index bd63c9944f..094bd2d300 100755 --- a/src/content-render/scripts/move-content.js +++ b/src/content-render/scripts/move-content.ts @@ -1,3 +1,4 @@ +// @ts-nocheck // [start-readme] // // Use this script to help you move or rename a single file or a folder. The script will move or rename the file or folder for you, update relevant `children` in the index.md file(s), and add a `redirect_from` to frontmatter in the renamed file(s). Note: You will still need to manually update the `title` if necessary. @@ -507,7 +508,7 @@ function editFiles(files, updateParent, opts) { // Add contentType frontmatter to moved files if (files.length > 0) { - const filePaths = files.map(([oldPath, newPath, oldHref, newHref]) => newPath) + const filePaths = files.map(([, newPath]) => newPath) try { const cmd = ['run', 'add-content-type', '--', '--paths', ...filePaths] const result = execFileSync('npm', cmd, { cwd: process.cwd(), encoding: 'utf8' }) diff --git a/src/graphql/scripts/sync.js b/src/graphql/scripts/sync.ts similarity index 99% rename from src/graphql/scripts/sync.js rename to src/graphql/scripts/sync.ts index 6b37b28fd9..11af291817 100755 --- a/src/graphql/scripts/sync.js +++ b/src/graphql/scripts/sync.ts @@ -1,3 +1,4 @@ +// @ts-nocheck import fs from 'fs/promises' import { appendFileSync } from 'fs' import path from 'path' diff --git a/src/rest/docs.js b/src/rest/docs.ts similarity index 93% rename from src/rest/docs.js rename to src/rest/docs.ts index b67023c8cb..86cf35d0d7 100755 --- a/src/rest/docs.js +++ b/src/rest/docs.ts @@ -3,11 +3,13 @@ import { readFile } from 'fs/promises' import { allVersions } from '@/versions/lib/all-versions' // Translate the docs versioning nomenclature back to the OpenAPI names -const invertedVersionMapping = JSON.parse(await readFile('src/rest/lib/config.json')).versionMapping -const versionMapping = {} +const invertedVersionMapping = JSON.parse( + await readFile('src/rest/lib/config.json', 'utf8'), +).versionMapping +const versionMapping: Record = {} Object.assign( versionMapping, - ...Object.entries(invertedVersionMapping).map(([a, b]) => ({ [b]: a })), + ...Object.entries(invertedVersionMapping).map(([a, b]) => ({ [b as string]: a })), ) const openApiVersions = Object.values(allVersions) .map((version) => version.openApiVersionName) diff --git a/src/tests/scripts/copy-fixture-data.js b/src/tests/scripts/copy-fixture-data.ts similarity index 95% rename from src/tests/scripts/copy-fixture-data.js rename to src/tests/scripts/copy-fixture-data.ts index 6cb23e4052..9aa07582da 100755 --- a/src/tests/scripts/copy-fixture-data.js +++ b/src/tests/scripts/copy-fixture-data.ts @@ -37,7 +37,7 @@ program main(program.opts()) -async function main(opts) { +async function main(opts: { check?: boolean; dryRun?: boolean; verbose?: boolean }) { let errors = 0 for (const file of MANDATORY_FILES) { const source = fs.readFileSync(file, 'utf-8') @@ -54,7 +54,7 @@ async function main(opts) { } else if (opts.verbose) { console.log(`The file ${chalk.green(destination)} is up-to-date 🥰`) } - } catch (error) { + } catch (error: any) { if (error.code === 'ENOENT') { console.warn(`The file ${chalk.red(destination)} does not exist`) errors++ @@ -71,7 +71,7 @@ async function main(opts) { } continue } - } catch (error) { + } catch (error: any) { if (error.code !== 'ENOENT') throw error } if (!opts.dryRun) {