diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e31d3d496dc4..fa7eddd725de 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -56,6 +56,8 @@ jobs: run: pnpm lint:syncpack - name: Catalogs run: pnpm lint:catalogs + - name: Repository name + run: pnpm lint:repo-name - name: Check deduped pnpm-lock.yaml run: pnpm lint:deps - name: Knip diff --git a/AGENTS.md b/AGENTS.md index 2ef332569fa5..527aa55288df 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -99,6 +99,7 @@ Update Vitest failing snapshots with the `-u` option. Do not blindly update snap - `pnpm lint:spelling:sort` - Sort `project-words.txt`, the words CSpell accepts - `pnpm lint:syncpack` - Syncpack to check that dependencies use the pnpm catalogs - `pnpm lint:catalogs` - Check the content of the pnpm catalogs +- `pnpm lint:repo-name` - Check that files use the current `meta/docusaurus` GitHub repository name - `pnpm lint:knip` - Knip to find unused files, exports and dependencies (config in `knip.config.ts`) - `pnpm lint:knip:production` - Knip to find the exports and dependencies of published packages that only tests use - `pnpm lint:knip:public-api` - Knip to warn about the public API exports that the monorepo doesn't use, not part of `pnpm lint` diff --git a/admin/scripts/lintRepoName.js b/admin/scripts/lintRepoName.js new file mode 100644 index 000000000000..1ac42d95ee78 --- /dev/null +++ b/admin/scripts/lintRepoName.js @@ -0,0 +1,74 @@ +#!/usr/bin/env node +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// Checks that the repository files use the current GitHub repository name. +// See https://github.com/meta/docusaurus/pull/12818 + +import path from 'node:path'; +import {execa} from 'execa'; +import {logger} from '@docusaurus/logger'; + +const RootDir = path.resolve(import.meta.dirname, '../..'); + +const FormerNamePattern = String.raw`facebook(/|%2F)docusaurus|facebook\.github\.io/docusaurus`; + +const IgnoredPathspecs = [ + // History + 'CHANGELOG.md', + 'CHANGELOG-v2.md', + 'website/blog', + 'website/versioned_docs', + // Generated from the init templates at release time + 'examples', + // Placeholder data + '**/__tests__/**', + '**/*.test.*', +]; + +async function main() { + const matches = await findFormerNameMatches(); + + if (matches.length > 0) { + logger.error( + `Found references to the former repository name, use meta/docusaurus instead:\n${matches.join('\n')}`, + ); + process.exit(1); + } + logger.success('No reference to the former repository name found'); +} + +/** @returns {Promise} "path:line:content" lines */ +async function findFormerNameMatches() { + const excludedPathspecs = IgnoredPathspecs.map((pathspec) => `:!${pathspec}`); + const result = await execa( + 'git', + [ + 'grep', + '--line-number', + // Skip binary files + '-I', + '--extended-regexp', + FormerNamePattern, + '--', + '.', + ...excludedPathspecs, + ], + {cwd: RootDir, reject: false}, + ); + + // git grep exits with 1 when nothing matches + if (result.exitCode === 1) { + return []; + } + if (result.exitCode !== 0) { + throw new Error(`git grep failed:\n${result.stderr}`); + } + return result.stdout.split('\n'); +} + +await main(); diff --git a/package.json b/package.json index f10acbc750b2..d9c6429b9afa 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "format": "oxfmt .", "format:website:build": "format-gitignored-files --config=.oxfmtrc.website.build.json \"website/build/**/*.{html,css,json}\"", "format:diff": "oxfmt --list-different .", - "lint": "pnpm lint:js && pnpm lint:style && pnpm lint:spelling && pnpm lint:syncpack && pnpm lint:catalogs && pnpm lint:deps && pnpm lint:knip && pnpm lint:knip:production && pnpm format:diff", + "lint": "pnpm lint:js && pnpm lint:style && pnpm lint:spelling && pnpm lint:syncpack && pnpm lint:catalogs && pnpm lint:repo-name && pnpm lint:deps && pnpm lint:knip && pnpm lint:knip:production && pnpm format:diff", "lint:js": "eslint --cache --report-unused-disable-directives \"**/*.{js,jsx,ts,tsx,mjs}\"", "lint:js:fix": "pnpm lint:js --fix", "lint:spelling": "cspell \"**\" --no-progress --show-context --show-suggestions", @@ -62,6 +62,7 @@ "lint:style:fix": "pnpm lint:style --fix", "lint:syncpack": "syncpack lint", "lint:catalogs": "node admin/scripts/lintCatalogs.js", + "lint:repo-name": "node admin/scripts/lintRepoName.js", "lint:syncpack:fix": "syncpack fix", "lint:deps": "pnpm dedupe --check", "lint:deps:fix": "pnpm dedupe",