@mintlify/cli 4.0.1629 → 4.0.1631

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/bin/cli.js CHANGED
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- import { buildGraph, getBrokenExternalLinks } from '@mintlify/link-rot';
11
+ import { buildGraph, getBrokenExternalLinks, getFilesLinksDependOn } from '@mintlify/link-rot';
12
12
  import { addLog, dev, exportSite, validateBuild, ErrorLog, SpinnerLog, SuccessLog, Logs, clearLogs, BrokenLinksLog, WarningLog, } from '@mintlify/previewing';
13
13
  import { thumbnailOverrideSchema } from '@mintlify/validation';
14
14
  import { render, Text } from 'ink';
@@ -307,10 +307,26 @@ export const cli = ({ packageName = 'mint' }) => {
307
307
  const sourceFiles = fileArgs.length > 0
308
308
  ? new Set((yield resolveExplicitFiles(CMD_EXEC_PATH, fileArgs)).map((file) => path.relative(docsRoot, path.resolve(CMD_EXEC_PATH, file))))
309
309
  : undefined;
310
+ // One unparseable page shouldn't hide every other result: report it and keep going
311
+ const parseErrorsByFile = new Map();
310
312
  const graph = yield buildGraph(docsRoot, {
311
313
  checkSnippets: argv['check-snippets'],
314
+ onParseError: (filePath, error) => parseErrorsByFile.set(filePath, error.message),
312
315
  });
313
316
  graph.precomputeFileResolutions();
317
+ // With --files, a failure elsewhere only matters when a selected link needs that
318
+ // file: an anchor pointing at it, or a snippet the selected page renders
319
+ const dependencies = sourceFiles
320
+ ? getFilesLinksDependOn(graph, sourceFiles, {
321
+ checkAnchors: argv['check-anchors'],
322
+ checkSnippets: argv['check-snippets'],
323
+ })
324
+ : undefined;
325
+ const parseErrors = [...parseErrorsByFile]
326
+ .filter(([filePath]) => !sourceFiles ||
327
+ sourceFiles.has(filePath) ||
328
+ (dependencies === null || dependencies === void 0 ? void 0 : dependencies.has(filePath.split(path.sep).join('/'))))
329
+ .map(([, message]) => message);
314
330
  const brokenInternalLinks = graph
315
331
  .getBrokenInternalLinks({
316
332
  checkAnchors: argv['check-anchors'],
@@ -361,13 +377,25 @@ export const cli = ({ packageName = 'mint' }) => {
361
377
  }
362
378
  }
363
379
  }
364
- if (Object.keys(brokenLinksByFile).length === 0) {
380
+ const hasBrokenLinks = Object.keys(brokenLinksByFile).length > 0;
381
+ if (!hasBrokenLinks && parseErrors.length === 0) {
365
382
  clearLogs();
366
383
  addLog(_jsx(SuccessLog, { message: "no broken links found" }));
367
384
  yield terminate(0);
368
385
  }
369
386
  clearLogs();
370
- addLog(_jsx(BrokenLinksLog, { brokenLinksByFile: brokenLinksByFile }));
387
+ if (hasBrokenLinks) {
388
+ addLog(_jsx(BrokenLinksLog, { brokenLinksByFile: brokenLinksByFile }));
389
+ }
390
+ else {
391
+ addLog(_jsx(SuccessLog, { message: "no broken links found in the files that parsed" }));
392
+ }
393
+ for (const message of parseErrors) {
394
+ addLog(_jsx(ErrorLog, { message: message }));
395
+ }
396
+ if (parseErrors.length > 0) {
397
+ addLog(_jsx(WarningLog, { message: `skipped ${parseErrors.length} file(s) that could not be parsed; links in them were not checked` }));
398
+ }
371
399
  }
372
400
  catch (err) {
373
401
  addLog(_jsx(ErrorLog, { message: err instanceof Error ? err.message : 'unknown error' }));