@mintlify/link-rot 3.0.4 → 3.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/link-rot",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "Static checking for broken internal links",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -27,6 +27,7 @@
27
27
  "registry": "https://registry.npmjs.org/"
28
28
  },
29
29
  "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
30
31
  "files": [
31
32
  "dist"
32
33
  ],
@@ -34,10 +35,12 @@
34
35
  "prepare": "npm run build",
35
36
  "build": "tsc",
36
37
  "watch": "tsc --watch",
37
- "lint": "eslint . --cache"
38
+ "lint": "eslint . --cache",
39
+ "format": "prettier \"./src/**/*.ts\" --write",
40
+ "format:check": "prettier \"./src/**/*.ts\" --check"
38
41
  },
39
42
  "dependencies": {
40
- "@mintlify/prebuild": "^1.0.0",
43
+ "@mintlify/prebuild": "1.0.9",
41
44
  "chalk": "^5.1.0",
42
45
  "fs-extra": "^11.1.0",
43
46
  "is-absolute-url": "^4.0.1",
@@ -50,7 +53,9 @@
50
53
  "devDependencies": {
51
54
  "@mintlify/eslint-config": "1.0.3",
52
55
  "@mintlify/eslint-config-typescript": "1.0.7",
56
+ "@mintlify/prettier-config": "1.0.1",
53
57
  "@mintlify/ts-config": "1.0.7",
58
+ "@trivago/prettier-plugin-sort-imports": "3.x",
54
59
  "@tsconfig/recommended": "1.x",
55
60
  "@types/fs-extra": "^9.0.13",
56
61
  "@types/mdast": "^3.0.10",
@@ -63,5 +68,6 @@
63
68
  "mdast-util-mdx-jsx": "^2.1.2",
64
69
  "prettier": "2.x",
65
70
  "typescript": "^4.8.2"
66
- }
71
+ },
72
+ "gitHead": "1d442e3c32d9fc7f38dbe40396e3574f10de0f2d"
67
73
  }
@@ -1,2 +0,0 @@
1
- import { renameFileAndUpdateLinksInContent } from "./renameFileAndUpdateLinksInContent.js";
2
- export default renameFileAndUpdateLinksInContent;
@@ -1,2 +0,0 @@
1
- import { renameFileAndUpdateLinksInContent } from "./renameFileAndUpdateLinksInContent.js";
2
- export default renameFileAndUpdateLinksInContent;
@@ -1,2 +0,0 @@
1
- declare const renameLinks: (filePath: string, existingLink: string, newLink: string) => Promise<number>;
2
- export default renameLinks;
@@ -1,47 +0,0 @@
1
- /**
2
- * @typedef {import('remark-mdx')}
3
- */
4
- import fs from "fs-extra";
5
- import { normalize } from "path";
6
- import { remark } from "remark";
7
- import remarkFrontmatter from "remark-frontmatter";
8
- import remarkGfm from "remark-gfm";
9
- import remarkMdx from "remark-mdx";
10
- import { visit } from "unist-util-visit";
11
- const getContentWithRenamedLinks = async (fileContent, existingLink, newLink) => {
12
- let numRenamedLinks = 0;
13
- const remarkMdxReplaceLinks = () => {
14
- return (tree) => {
15
- visit(tree, (node) => {
16
- // ![]() format
17
- if (node.type === "link" &&
18
- node.url &&
19
- normalize(node.url) === existingLink) {
20
- node.url = newLink;
21
- numRenamedLinks++;
22
- }
23
- return;
24
- });
25
- };
26
- };
27
- const file = await remark()
28
- .use(remarkMdx)
29
- .use(remarkGfm)
30
- .use(remarkFrontmatter, ["yaml", "toml"])
31
- .use(remarkMdxReplaceLinks)
32
- .process(fileContent);
33
- return {
34
- numRenamedLinks,
35
- newContent: String(file),
36
- };
37
- };
38
- const renameLinks = async (filePath, existingLink, newLink) => {
39
- const fileContent = fs.readFileSync(filePath).toString();
40
- const { numRenamedLinks, newContent } = await getContentWithRenamedLinks(fileContent, existingLink, newLink);
41
- fs.outputFileSync(filePath, newContent, {
42
- flag: "w",
43
- });
44
- return numRenamedLinks;
45
- };
46
- console.log(await getContentWithRenamedLinks("[](test)", "[](test)", "test2"));
47
- export default renameLinks;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export declare const getUsedInternalLinksInPage: (content: string) => Promise<string[]>;
2
- export declare const getUsedInternalLinksInSite: (dirName: string) => Promise<Record<string, string[]>>;
@@ -1,74 +0,0 @@
1
- import isAbsoluteUrl from "is-absolute-url";
2
- import fs from "fs-extra";
3
- import { remark } from "remark";
4
- import remarkFrontmatter from "remark-frontmatter";
5
- import remarkGfm from "remark-gfm";
6
- import remarkMdx from "remark-mdx";
7
- import { visit } from "unist-util-visit";
8
- import { getFullPath, getPagePaths, normalizeFilePaths, removeLeadingSlash, } from "../prebuild.js";
9
- import path from "path";
10
- const isDataString = (str) => str.startsWith("data:");
11
- export const getUsedInternalLinksInPage = async (content) => {
12
- const links = [];
13
- const visitLinks = () => {
14
- return (tree) => {
15
- visit(tree, (node) => {
16
- if (
17
- // ![]() format
18
- (node.type === "link" || node.type === "image") &&
19
- node.url &&
20
- !isAbsoluteUrl(node.url) &&
21
- !isDataString(node.url)) {
22
- links.push(node.url);
23
- return;
24
- }
25
- const mdxJsxFlowElement = node;
26
- if (mdxJsxFlowElement.name === "img" ||
27
- mdxJsxFlowElement.name === "source") {
28
- const srcAttrIndex = mdxJsxFlowElement.attributes.findIndex((attr) => attr.type === "mdxJsxAttribute" && attr.name === "src");
29
- const nodeUrl = mdxJsxFlowElement.attributes[srcAttrIndex].value;
30
- if (srcAttrIndex !== -1 &&
31
- typeof nodeUrl === "string" &&
32
- !isAbsoluteUrl(nodeUrl) &&
33
- !isDataString(nodeUrl)) {
34
- links.push(nodeUrl);
35
- }
36
- }
37
- else if (mdxJsxFlowElement.name === "a") {
38
- const hrefAttrIndex = mdxJsxFlowElement.attributes.findIndex((attr) => attr.type === "mdxJsxAttribute" && attr.name === "href");
39
- const nodeUrl = mdxJsxFlowElement.attributes[hrefAttrIndex].value;
40
- if (hrefAttrIndex !== -1 &&
41
- typeof nodeUrl === "string" &&
42
- !isAbsoluteUrl(nodeUrl) &&
43
- !isDataString(nodeUrl)) {
44
- links.push(nodeUrl);
45
- }
46
- }
47
- });
48
- return tree;
49
- };
50
- };
51
- await remark()
52
- .use(remarkMdx)
53
- .use(remarkGfm)
54
- .use(remarkFrontmatter, ["yaml", "toml"])
55
- .use(visitLinks)
56
- .process(content);
57
- return normalizeFilePaths(links).map(getFullPath).map(removeLeadingSlash);
58
- };
59
- export const getUsedInternalLinksInSite = async (dirName) => {
60
- const dirChildren = getPagePaths(dirName);
61
- const getLinksPromises = [];
62
- const usedLinksInSite = {};
63
- dirChildren.forEach((filePath) => {
64
- getLinksPromises.push((async () => {
65
- const fileContent = fs
66
- .readFileSync(path.join(dirName, filePath))
67
- .toString();
68
- const usedLinksInPage = await getUsedInternalLinksInPage(fileContent);
69
- usedLinksInSite[filePath] = usedLinksInPage;
70
- })());
71
- });
72
- await Promise.all(getLinksPromises);
73
- return usedLinksInSite;
74
- };
@@ -1 +0,0 @@
1
- export declare const getValidInternalLinks: (dirName: string) => Set<string>;
@@ -1,5 +0,0 @@
1
- import { getFileList } from "@mintlify/prebuild";
2
- import { filterLinks, removeFileExtension, removeLeadingSlash, } from "../prebuild.js";
3
- export const getValidInternalLinks = (dirName) => new Set(filterLinks(getFileList(dirName))
4
- .map(removeFileExtension)
5
- .map(removeLeadingSlash));
@@ -1,4 +0,0 @@
1
- export { getUsedInternalLinksInPage, getUsedInternalLinksInSite, } from "./getUsedInternalLinks";
2
- export { getValidInternalLinks } from "./getValidInternalLinks";
3
- import { getBrokenInternalLinks } from "./getBrokenInternalLinks";
4
- export default getBrokenInternalLinks;
@@ -1,4 +0,0 @@
1
- export { getUsedInternalLinksInPage, getUsedInternalLinksInSite, } from "./getUsedInternalLinks";
2
- export { getValidInternalLinks } from "./getValidInternalLinks";
3
- import { getBrokenInternalLinks } from "./getBrokenInternalLinks";
4
- export default getBrokenInternalLinks;