@mintlify/link-rot 3.0.1603 → 3.0.1605

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/graph.d.ts CHANGED
@@ -24,6 +24,7 @@ export declare class MdxPath {
24
24
  relativeDir: string;
25
25
  filename: string;
26
26
  wrapper?: Wrapper | undefined;
27
+ line?: number | undefined;
27
28
  path: ParsedPath | URL;
28
29
  pathType: PathType;
29
30
  anchorLink?: string;
@@ -34,7 +35,7 @@ export declare class MdxPath {
34
35
  * Generate all the computed fields in an MdxPath
35
36
  */
36
37
  private constructParsedPath;
37
- constructor(originalPath: string, relativeDir?: string, filename?: string, wrapper?: Wrapper | undefined);
38
+ constructor(originalPath: string, relativeDir?: string, filename?: string, wrapper?: Wrapper | undefined, line?: number | undefined);
38
39
  toString(): string;
39
40
  getResolvedFiles(fileIndex: FileIndex, baseDir: string): string[];
40
41
  resolvesTo(node: Node, fileIndex: FileIndex, baseDir: string): boolean;
@@ -56,7 +57,7 @@ export declare class Node {
56
57
  constructor(label: string, paths?: MdxPath[]);
57
58
  toString(): string;
58
59
  equals(other: Node): boolean;
59
- addPath(originalPath: string, wrapper?: Wrapper): void;
60
+ addPath(originalPath: string, wrapper?: Wrapper, line?: number): void;
60
61
  addOutgoingEdge(edge: Edge): void;
61
62
  getChildNodes(depth?: number): Node[];
62
63
  }
@@ -108,6 +109,8 @@ export declare class Graph {
108
109
  getBrokenInternalLinks(options?: {
109
110
  checkAnchors?: boolean;
110
111
  }): MdxPath[];
112
+ getLinksTo(target: MdxPath): MdxPath[];
113
+ private getPageRoute;
111
114
  private getPageCandidates;
112
115
  private isPageRoute;
113
116
  private resolvesToValidPath;
package/dist/graph.js CHANGED
@@ -3,7 +3,7 @@ import { getFileListWithDirectories } from '@mintlify/prebuild';
3
3
  import { existsSync } from 'fs';
4
4
  import { parse, join, resolve, dirname, basename } from 'path';
5
5
  import { sep as WINDOWS_SEPARATOR } from 'path/win32';
6
- import { getLinkPaths, normalizePath, removeSelectors } from './prebuild.js';
6
+ import { getLinkPaths, isValidPage, normalizePath, removeFileExtension, removeSelectors, } from './prebuild.js';
7
7
  export var PathType;
8
8
  (function (PathType) {
9
9
  PathType["INTERNAL"] = "internal";
@@ -91,11 +91,12 @@ export class MdxPath {
91
91
  const queryParams = urlPath.searchParams;
92
92
  return { path, pathType, anchorLink, queryParams };
93
93
  }
94
- constructor(originalPath, relativeDir = '', filename = '', wrapper) {
94
+ constructor(originalPath, relativeDir = '', filename = '', wrapper, line) {
95
95
  this.originalPath = originalPath;
96
96
  this.relativeDir = relativeDir;
97
97
  this.filename = filename;
98
98
  this.wrapper = wrapper;
99
+ this.line = line;
99
100
  this.pagePaths = [];
100
101
  this.relativeDir = normalizePath(relativeDir);
101
102
  const { path, pathType, anchorLink, queryParams } = this.constructParsedPath();
@@ -185,8 +186,8 @@ export class Node {
185
186
  equals(other) {
186
187
  return this.label === other.label;
187
188
  }
188
- addPath(originalPath, wrapper) {
189
- const path = new MdxPath(originalPath, this.relativeDir, this.filename, wrapper);
189
+ addPath(originalPath, wrapper, line) {
190
+ const path = new MdxPath(originalPath, this.relativeDir, this.filename, wrapper, line);
190
191
  this.paths.push(path);
191
192
  }
192
193
  addOutgoingEdge(edge) {
@@ -458,6 +459,23 @@ export class Graph {
458
459
  (path.pagePaths.length === 0 ||
459
460
  path.pagePaths.some((pagePath) => brokenLinks.has(pagePath))));
460
461
  }
462
+ getLinksTo(target) {
463
+ const targetPage = this.getPageRoute(target.toString());
464
+ const pointsAtTarget = (path) => path.pathType === PathType.INTERNAL &&
465
+ !path.originalPath.startsWith('#') &&
466
+ this.getPageRoute(path.toString()) === targetPage &&
467
+ (!target.anchorLink || path.anchorLink === target.anchorLink);
468
+ return Object.values(this.nodes)
469
+ .flatMap((node) => node.paths)
470
+ .filter((path) => pointsAtTarget(path) || path.pagePaths.some(pointsAtTarget));
471
+ }
472
+ getPageRoute(normalized) {
473
+ var _a;
474
+ const file = (_a = [...this.getPageCandidates(normalized), normalized].find((label) => this.nodes[label])) !== null && _a !== void 0 ? _a : normalized;
475
+ const parsed = parse(file);
476
+ const route = isValidPage(parsed) ? removeFileExtension(parsed) : file;
477
+ return basename(route) === 'index' ? dirname(route) : route;
478
+ }
461
479
  getPageCandidates(normalized) {
462
480
  // normalizePath('/') yields '.' — resolve lookups against node labels (which use
463
481
  // path.join, so `join('.', 'index.mdx') === 'index.mdx'`) rather than naive
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { buildGraph, decorateGraphNodeFromPageContent, getBrokenInternalLinks, } from './static-checking/getBrokenInternalLinks.js';
2
- export { Node, PathType } from './graph.js';
2
+ export { MdxPath, Node, PathType } from './graph.js';
3
3
  export { getBrokenExternalLinks } from './static-checking/getBrokenExternalLinks.js';
4
4
  export type { ExternalLinkResult } from './static-checking/getBrokenExternalLinks.js';
5
5
  export { getFilesLinksDependOn } from './static-checking/resolveSnippetLinksFromRenderingPages.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { buildGraph, decorateGraphNodeFromPageContent, getBrokenInternalLinks, } from './static-checking/getBrokenInternalLinks.js';
2
- export { Node, PathType } from './graph.js';
2
+ export { MdxPath, Node, PathType } from './graph.js';
3
3
  export { getBrokenExternalLinks } from './static-checking/getBrokenExternalLinks.js';
4
4
  export { getFilesLinksDependOn } from './static-checking/resolveSnippetLinksFromRenderingPages.js';
5
5
  export { getBrokenRedirects } from './static-checking/getBrokenRedirects.js';
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { cleanHeadingId, COMPONENTS_WITH_CLEANED_ID, COMPONENTS_WITHOUT_ID, coreRemark, generateParamFieldId, isMintIgnored, preprocessCustomHeadingIds, preprocessMdxFragmentCode, remarkComponentIds, remarkExtractTableOfContents, } from '@mintlify/common';
10
+ import { cleanHeadingId, COMPONENTS_WITH_CLEANED_ID, COMPONENTS_WITHOUT_ID, coreRemark, customHeadingIdSourceLines, generateParamFieldId, isMintIgnored, preprocessCustomHeadingIds, preprocessMdxFragmentCode, remarkComponentIds, remarkExtractTableOfContents, } from '@mintlify/common';
11
11
  import { getMintIgnore } from '@mintlify/prebuild';
12
12
  import fs from 'fs-extra';
13
13
  import path from 'path';
@@ -84,30 +84,32 @@ export const decorateGraphNodeFromPageContent = (graphNode, content, options) =>
84
84
  referenced.add(node.identifier);
85
85
  });
86
86
  visit(tree, (node) => {
87
- var _a, _b;
87
+ var _a, _b, _c;
88
+ const parsedLine = (_a = node.position) === null || _a === void 0 ? void 0 : _a.start.line;
89
+ const line = parsedLine === undefined ? undefined : sourceLines[parsedLine - 1];
88
90
  if (node.type === 'link' || node.type === 'image') {
89
- graphNode.addPath(node.url, Wrapper.MD);
91
+ graphNode.addPath(node.url, Wrapper.MD, line);
90
92
  return;
91
93
  }
92
94
  if (node.type === 'definition') {
93
95
  if (referenced.delete(node.identifier))
94
- graphNode.addPath(node.url, Wrapper.MD);
96
+ graphNode.addPath(node.url, Wrapper.MD, line);
95
97
  return;
96
98
  }
97
99
  const mdxJsxFlowElement = node;
98
100
  if (mdxJsxFlowElement.name === 'img' || mdxJsxFlowElement.name === 'source') {
99
101
  const srcAttrIndex = mdxJsxFlowElement.attributes.findIndex((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'src');
100
- const nodeUrl = attributeString((_a = mdxJsxFlowElement.attributes[srcAttrIndex]) === null || _a === void 0 ? void 0 : _a.value);
102
+ const nodeUrl = attributeString((_b = mdxJsxFlowElement.attributes[srcAttrIndex]) === null || _b === void 0 ? void 0 : _b.value);
101
103
  if (typeof nodeUrl === 'string') {
102
- graphNode.addPath(nodeUrl, Wrapper.SRC);
104
+ graphNode.addPath(nodeUrl, Wrapper.SRC, line);
103
105
  return;
104
106
  }
105
107
  }
106
108
  else if (mdxJsxFlowElement.name === 'a' || mdxJsxFlowElement.name === 'Card') {
107
109
  const hrefAttrIndex = mdxJsxFlowElement.attributes.findIndex((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'href');
108
- const nodeUrl = attributeString((_b = mdxJsxFlowElement.attributes[hrefAttrIndex]) === null || _b === void 0 ? void 0 : _b.value);
110
+ const nodeUrl = attributeString((_c = mdxJsxFlowElement.attributes[hrefAttrIndex]) === null || _c === void 0 ? void 0 : _c.value);
109
111
  if (typeof nodeUrl === 'string') {
110
- graphNode.addPath(nodeUrl, Wrapper.HREF);
112
+ graphNode.addPath(nodeUrl, Wrapper.HREF, line);
111
113
  return;
112
114
  }
113
115
  }
@@ -117,7 +119,9 @@ export const decorateGraphNodeFromPageContent = (graphNode, content, options) =>
117
119
  };
118
120
  // Same pre-parse escaping as prebuild, so code fences inside `<MDX>` fragments
119
121
  // (`<project-root>`, `{id}`) aren't read as JSX and the page parses like it renders
120
- const preprocessed = preprocessCustomHeadingIds(preprocessMdxFragmentCode(content));
122
+ const fragmentEscaped = preprocessMdxFragmentCode(content);
123
+ const preprocessed = preprocessCustomHeadingIds(fragmentEscaped);
124
+ const sourceLines = customHeadingIdSourceLines(fragmentEscaped);
121
125
  const processor = coreRemark()
122
126
  .use(remarkSmartypants)
123
127
  .use(visitLinks)