Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
74 changes: 74 additions & 0 deletions admin/scripts/lintRepoName.js
Original file line number Diff line number Diff line change
@@ -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<string[]>} "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();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading