@mintlify/link-rot 3.0.1538 → 3.0.1540

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
@@ -1,6 +1,6 @@
1
1
  import { ParsedPath } from 'path';
2
2
  import type { SnippetReferences } from './static-checking/getSnippetReferences.js';
3
- declare enum PathType {
3
+ export declare enum PathType {
4
4
  INTERNAL = "internal",
5
5
  EXTERNAL = "external",
6
6
  DATA = "data"
@@ -121,4 +121,3 @@ export declare class Graph {
121
121
  getExternalPathsByNode(): Map<string, MdxPath[]>;
122
122
  getAllInternalPaths(): string[];
123
123
  }
124
- export {};
package/dist/graph.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { isMintIgnored, safeCleanHeadingId } from '@mintlify/common';
2
2
  import { getFileListWithDirectories } from '@mintlify/prebuild';
3
3
  import { existsSync } from 'fs';
4
- import { parse, join, resolve, relative, dirname, basename } from 'path';
4
+ import { parse, join, resolve, dirname, basename } from 'path';
5
5
  import { sep as WINDOWS_SEPARATOR } from 'path/win32';
6
6
  import { getLinkPaths, normalizePath, removeSelectors } from './prebuild.js';
7
- var PathType;
7
+ export var PathType;
8
8
  (function (PathType) {
9
9
  PathType["INTERNAL"] = "internal";
10
10
  PathType["EXTERNAL"] = "external";
@@ -61,27 +61,16 @@ export class MdxPath {
61
61
  let urlPath;
62
62
  let path;
63
63
  if (pathType === PathType.INTERNAL) {
64
- let normalizedPath = this.originalPath.replaceAll(WINDOWS_SEPARATOR, '/');
65
- if (normalizedPath.startsWith('.')) {
66
- // also include paths that start with "..", etc.
67
- normalizedPath = relative('.', resolve(this.relativeDir, normalizedPath));
68
- // TODO path starts with .. if path resolves to file system outside of mintlify project
69
- }
70
- // remove leading slash
71
- normalizedPath = normalizedPath.startsWith('/') ? normalizedPath.slice(1) : normalizedPath;
72
- // resolve relative path
73
- // add arbitrary protocol to parse as URL and isolate pathname
74
- urlPath = new URL(`mintlify:${normalizedPath}`);
75
- normalizedPath = decodeUrlComponent(urlPath.pathname);
64
+ const pageUrl = new URL('mintlify:/');
65
+ pageUrl.pathname = `/${this.relativeDir}/${this.filename}`.replaceAll(WINDOWS_SEPARATOR, '/');
66
+ urlPath = new URL(this.originalPath.replaceAll(WINDOWS_SEPARATOR, '/'), pageUrl);
67
+ let normalizedPath = decodeUrlComponent(urlPath.pathname).slice(1);
76
68
  // remove trailing slash
77
69
  if (normalizedPath.endsWith('/')) {
78
70
  normalizedPath = normalizedPath.slice(0, -1);
79
- urlPath.pathname = normalizedPath;
80
71
  }
81
- // if path is "", then path points to same page
82
72
  if (normalizedPath === '') {
83
- normalizedPath = join(this.relativeDir, this.filename);
84
- urlPath.pathname = normalizedPath;
73
+ normalizedPath = '.';
85
74
  }
86
75
  path = parse(normalizedPath);
87
76
  }
@@ -446,7 +435,9 @@ export class Graph {
446
435
  if (path.pathType === PathType.INTERNAL) {
447
436
  const pathString = path.toString();
448
437
  const resolvedFiles = this.fileResolutionMap.get(pathString);
449
- const hasExistingFile = (resolvedFiles && [...resolvedFiles].some((file) => nodeSet.has(file))) ||
438
+ const isSiteRoot = pathString === '.';
439
+ const hasExistingFile = isSiteRoot ||
440
+ (resolvedFiles && [...resolvedFiles].some((file) => nodeSet.has(file))) ||
450
441
  this.virtualNodes.has(pathString);
451
442
  if (!hasExistingFile && !this.reachesPage(pathString)) {
452
443
  brokenLinks.add(path);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { buildGraph, getBrokenInternalLinks } from './static-checking/getBrokenInternalLinks.js';
1
+ export { buildGraph, decorateGraphNodeFromPageContent, getBrokenInternalLinks, } from './static-checking/getBrokenInternalLinks.js';
2
+ export { Node, PathType } from './graph.js';
2
3
  export { getBrokenExternalLinks } from './static-checking/getBrokenExternalLinks.js';
3
4
  export type { ExternalLinkResult } from './static-checking/getBrokenExternalLinks.js';
4
5
  export { getFilesLinksDependOn } from './static-checking/resolveSnippetLinksFromRenderingPages.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export { buildGraph, getBrokenInternalLinks } from './static-checking/getBrokenInternalLinks.js';
1
+ export { buildGraph, decorateGraphNodeFromPageContent, getBrokenInternalLinks, } from './static-checking/getBrokenInternalLinks.js';
2
+ export { Node, PathType } from './graph.js';
2
3
  export { getBrokenExternalLinks } from './static-checking/getBrokenExternalLinks.js';
3
4
  export { getFilesLinksDependOn } from './static-checking/resolveSnippetLinksFromRenderingPages.js';
4
5
  export { getBrokenRedirects } from './static-checking/getBrokenRedirects.js';
@@ -60,20 +60,44 @@ export const extractComponentAnchorIds = (tree) => {
60
60
  });
61
61
  return ids;
62
62
  };
63
+ const attributeString = (value) => {
64
+ var _a, _b, _c, _d;
65
+ if (typeof value === 'string')
66
+ return value;
67
+ const statement = (_b = (_a = value === null || value === void 0 ? void 0 : value.data) === null || _a === void 0 ? void 0 : _a.estree) === null || _b === void 0 ? void 0 : _b.body[0];
68
+ const expression = (statement === null || statement === void 0 ? void 0 : statement.type) === 'ExpressionStatement' ? statement.expression : undefined;
69
+ if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'Literal' && typeof expression.value === 'string') {
70
+ return expression.value;
71
+ }
72
+ if ((expression === null || expression === void 0 ? void 0 : expression.type) === 'TemplateLiteral' && expression.expressions.length === 0) {
73
+ return (_d = (_c = expression.quasis[0]) === null || _c === void 0 ? void 0 : _c.value.cooked) !== null && _d !== void 0 ? _d : undefined;
74
+ }
75
+ return undefined;
76
+ };
63
77
  export const decorateGraphNodeFromPageContent = (graphNode, content, options) => __awaiter(void 0, void 0, void 0, function* () {
64
78
  const mdxExtracts = {};
65
79
  const visitLinks = () => {
66
80
  return (tree) => {
81
+ const referenced = new Set();
82
+ visit(tree, ['linkReference', 'imageReference'], (node) => {
83
+ if ('identifier' in node)
84
+ referenced.add(node.identifier);
85
+ });
67
86
  visit(tree, (node) => {
68
87
  var _a, _b;
69
88
  if (node.type === 'link' || node.type === 'image') {
70
89
  graphNode.addPath(node.url, Wrapper.MD);
71
90
  return;
72
91
  }
92
+ if (node.type === 'definition') {
93
+ if (referenced.delete(node.identifier))
94
+ graphNode.addPath(node.url, Wrapper.MD);
95
+ return;
96
+ }
73
97
  const mdxJsxFlowElement = node;
74
98
  if (mdxJsxFlowElement.name === 'img' || mdxJsxFlowElement.name === 'source') {
75
99
  const srcAttrIndex = mdxJsxFlowElement.attributes.findIndex((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'src');
76
- const nodeUrl = (_a = mdxJsxFlowElement.attributes[srcAttrIndex]) === null || _a === void 0 ? void 0 : _a.value;
100
+ const nodeUrl = attributeString((_a = mdxJsxFlowElement.attributes[srcAttrIndex]) === null || _a === void 0 ? void 0 : _a.value);
77
101
  if (typeof nodeUrl === 'string') {
78
102
  graphNode.addPath(nodeUrl, Wrapper.SRC);
79
103
  return;
@@ -81,7 +105,7 @@ export const decorateGraphNodeFromPageContent = (graphNode, content, options) =>
81
105
  }
82
106
  else if (mdxJsxFlowElement.name === 'a' || mdxJsxFlowElement.name === 'Card') {
83
107
  const hrefAttrIndex = mdxJsxFlowElement.attributes.findIndex((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'href');
84
- const nodeUrl = (_b = mdxJsxFlowElement.attributes[hrefAttrIndex]) === null || _b === void 0 ? void 0 : _b.value;
108
+ const nodeUrl = attributeString((_b = mdxJsxFlowElement.attributes[hrefAttrIndex]) === null || _b === void 0 ? void 0 : _b.value);
85
109
  if (typeof nodeUrl === 'string') {
86
110
  graphNode.addPath(nodeUrl, Wrapper.HREF);
87
111
  return;
@@ -1,10 +1,10 @@
1
1
  import { resolveImportPath } from '@mintlify/common';
2
2
  import { sep as WINDOWS_SEPARATOR } from 'path/win32';
3
- import { MdxPath, Wrapper } from '../graph.js';
3
+ import { MdxPath, PathType, Wrapper } from '../graph.js';
4
4
  import { removeLeadingSlash } from '../prebuild.js';
5
5
  const SNIPPET_DIRECTORIES = ['snippets/', '_snippets/'];
6
6
  const toKey = (file) => file.replaceAll(WINDOWS_SEPARATOR, '/');
7
- const isPageRelativeLink = ({ originalPath, wrapper }) => wrapper !== Wrapper.IMPORT && (originalPath.startsWith('.') || originalPath.startsWith('#'));
7
+ const isPageRelativeLink = ({ originalPath, pathType, wrapper }) => wrapper !== Wrapper.IMPORT && pathType === PathType.INTERNAL && !originalPath.startsWith('/');
8
8
  export const resolveSnippetLinksFromRenderingPages = (graph, snippetReferencesByFile) => {
9
9
  var _a, _b, _c;
10
10
  const fileByKey = new Map([...snippetReferencesByFile.keys()].map((file) => [toKey(file), file]));