fix(nx-dev): fix internal link checker (#19606)
This commit is contained in:
parent
8249ace5a2
commit
0e1962237b
@ -18,6 +18,12 @@
|
|||||||
],
|
],
|
||||||
"parallel": false
|
"parallel": false
|
||||||
},
|
},
|
||||||
|
"inputs": [
|
||||||
|
"production",
|
||||||
|
"^production",
|
||||||
|
"{workspaceRoot}/scripts/tsconfig.scripts.json",
|
||||||
|
"{workspaceRoot}/scripts/documentation/internal-link-checker.ts"
|
||||||
|
],
|
||||||
"outputs": ["{workspaceRoot}/dist/nx-dev/nx-dev"]
|
"outputs": ["{workspaceRoot}/dist/nx-dev/nx-dev"]
|
||||||
},
|
},
|
||||||
"sitemap": {
|
"sitemap": {
|
||||||
|
|||||||
@ -83,38 +83,6 @@ function readSiteMapLinks(filePath: string): string[] {
|
|||||||
return sitemap.urlset.url.map((obj) => obj.loc);
|
return sitemap.urlset.url.map((obj) => obj.loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This function checks if a link is for a private package.
|
|
||||||
* When link is for a private package, it is not included in the sitemap.
|
|
||||||
* However, some shared docs might be written for this private package during development.
|
|
||||||
* @param link e.g. /nx-api/vite/generators/configuration
|
|
||||||
* @returns true if the link is for a private package or NODE_ENV is not development, false otherwise.
|
|
||||||
*/
|
|
||||||
function checkLinkIsForPrivatePackage(link: string) {
|
|
||||||
// skip this check in dev mode
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const pathSegments = link.split('/').filter(Boolean);
|
|
||||||
if (pathSegments[0] === 'nx-api') {
|
|
||||||
// TODO(v17): Remove this once vue is public or once this logic is fixed
|
|
||||||
if (pathSegments[1] === 'vue') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const packageJsonPath = join(
|
|
||||||
workspaceRoot,
|
|
||||||
'packages',
|
|
||||||
pathSegments[1],
|
|
||||||
'package.json'
|
|
||||||
);
|
|
||||||
if (existsSync(packageJsonPath)) {
|
|
||||||
return readJSONSync(packageJsonPath).private ?? false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
const documentLinks = extractAllLinks(join(workspaceRoot, 'docs'));
|
const documentLinks = extractAllLinks(join(workspaceRoot, 'docs'));
|
||||||
const sitemapLinks = readSiteMapIndex(
|
const sitemapLinks = readSiteMapIndex(
|
||||||
@ -124,11 +92,7 @@ const sitemapLinks = readSiteMapIndex(
|
|||||||
const errors: Array<{ file: string; link: string }> = [];
|
const errors: Array<{ file: string; link: string }> = [];
|
||||||
for (let file in documentLinks) {
|
for (let file in documentLinks) {
|
||||||
for (let link of documentLinks[file]) {
|
for (let link of documentLinks[file]) {
|
||||||
// TODO(@isaacplmann): This ignores errors which are links TO private packages. It allows links FROM public packages (public docs) TO private packages (404 links)
|
if (!sitemapLinks.includes(['https://nx.dev', link].join(''))) {
|
||||||
if (
|
|
||||||
!sitemapLinks.includes(['https://nx.dev', link].join('')) &&
|
|
||||||
!checkLinkIsForPrivatePackage(link)
|
|
||||||
) {
|
|
||||||
errors.push({ file, link });
|
errors.push({ file, link });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user