@mintlify/cli 4.0.1344 → 4.0.1346

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.
@@ -5,7 +5,7 @@ import path from 'node:path';
5
5
  import { mockProcessExit } from 'vitest-mock-process';
6
6
 
7
7
  import { resolveExplicitFiles } from '../src/deslop/resolveFiles.js';
8
- import { checkForMintJson, CMD_EXEC_PATH } from '../src/helpers.js';
8
+ import { checkForMintJson, CMD_EXEC_PATH, findDocsRoot } from '../src/helpers.js';
9
9
  import { runCommand } from './utils.js';
10
10
 
11
11
  vi.mock('@mintlify/previewing', async (importOriginal) => {
@@ -18,6 +18,7 @@ vi.mock('../src/helpers.js', async (importOriginal) => {
18
18
  return {
19
19
  ...actual,
20
20
  checkForMintJson: vi.fn(),
21
+ findDocsRoot: vi.fn(),
21
22
  };
22
23
  });
23
24
 
@@ -50,6 +51,7 @@ describe('brokenLinks', () => {
50
51
  vi.clearAllMocks();
51
52
  vi.mocked(buildGraph).mockResolvedValue(mockGraph as never);
52
53
  vi.mocked(resolveExplicitFiles).mockResolvedValue([]);
54
+ vi.mocked(findDocsRoot).mockResolvedValue(CMD_EXEC_PATH);
53
55
  mockGraph.getBrokenInternalLinks.mockReturnValue([]);
54
56
  });
55
57
 
@@ -138,6 +140,44 @@ describe('brokenLinks', () => {
138
140
  expect(processExitMock).toHaveBeenCalledWith(1);
139
141
  });
140
142
 
143
+ it('builds the graph from the docs root when run inside a content folder', async () => {
144
+ const docsRoot = path.resolve(CMD_EXEC_PATH, '..', '..');
145
+ vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
146
+ vi.mocked(findDocsRoot).mockResolvedValue(docsRoot);
147
+ vi.mocked(resolveExplicitFiles).mockResolvedValueOnce(['apis.mdx']);
148
+ mockGraph.getBrokenInternalLinks.mockReturnValue([]);
149
+
150
+ await runCommand('broken-links', '--files', 'apis.mdx');
151
+
152
+ expect(buildGraph).toHaveBeenCalledWith(docsRoot, expect.anything());
153
+ expect(processExitMock).toHaveBeenCalledWith(0);
154
+ });
155
+
156
+ it('rebases matched files onto the docs root so nested links still resolve', async () => {
157
+ const docsRoot = path.resolve(CMD_EXEC_PATH, '..', '..');
158
+ const nested = path.relative(docsRoot, path.join(CMD_EXEC_PATH, 'apis.mdx'));
159
+ vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
160
+ vi.mocked(findDocsRoot).mockResolvedValue(docsRoot);
161
+ vi.mocked(resolveExplicitFiles).mockResolvedValueOnce(['apis.mdx']);
162
+ mockGraph.getBrokenInternalLinks.mockReturnValue([
163
+ {
164
+ relativeDir: path.dirname(nested),
165
+ filename: 'apis.mdx',
166
+ originalPath: '/docs/authenticate',
167
+ pathType: 'internal',
168
+ } as MdxPath,
169
+ ]);
170
+
171
+ await runCommand('broken-links', '--files', 'apis.mdx');
172
+
173
+ expect(addLogSpy).toHaveBeenCalledWith(
174
+ expect.objectContaining({
175
+ props: { brokenLinksByFile: { [nested]: ['/docs/authenticate'] } },
176
+ })
177
+ );
178
+ expect(processExitMock).toHaveBeenCalledWith(1);
179
+ });
180
+
141
181
  it('fails when checking throws error', async () => {
142
182
  vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
143
183
  vi.mocked(buildGraph).mockRejectedValueOnce(new Error('some error'));
@@ -163,6 +203,7 @@ describe('brokenLinks --check-external', () => {
163
203
  vi.clearAllMocks();
164
204
  vi.mocked(buildGraph).mockResolvedValue(mockGraph as never);
165
205
  vi.mocked(resolveExplicitFiles).mockResolvedValue([]);
206
+ vi.mocked(findDocsRoot).mockResolvedValue(CMD_EXEC_PATH);
166
207
  mockGraph.getBrokenInternalLinks.mockReturnValue([]);
167
208
  });
168
209
 
package/bin/cli.js CHANGED
@@ -24,7 +24,7 @@ import { API_URL } from './constants.js';
24
24
  import { deslopHandler } from './deslop/index.js';
25
25
  import { resolveExplicitFiles } from './deslop/resolveFiles.js';
26
26
  import { formatHandler } from './format.js';
27
- import { CMD_EXEC_PATH, checkPort, checkNodeVersion, autoUpgradeIfNeeded, getVersions, isAI, suppressConsoleWarnings, terminate, } from './helpers.js';
27
+ import { CMD_EXEC_PATH, checkPort, checkNodeVersion, autoUpgradeIfNeeded, findDocsRoot, getVersions, isAI, suppressConsoleWarnings, terminate, } from './helpers.js';
28
28
  import { init } from './init.js';
29
29
  import { getAccessToken } from './keyring.js';
30
30
  import { login } from './login.js';
@@ -266,11 +266,12 @@ export const cli = ({ packageName = 'mint' }) => {
266
266
  yield autoUpgradeIfNeeded();
267
267
  addLog(_jsx(SpinnerLog, { message: "checking for broken links..." }));
268
268
  try {
269
+ const docsRoot = yield findDocsRoot(CMD_EXEC_PATH);
269
270
  const fileArgs = ((_a = argv.files) !== null && _a !== void 0 ? _a : []).map(String).filter(Boolean);
270
271
  const sourceFiles = fileArgs.length > 0
271
- ? new Set((yield resolveExplicitFiles(CMD_EXEC_PATH, fileArgs)).map((file) => path.normalize(file)))
272
+ ? new Set((yield resolveExplicitFiles(CMD_EXEC_PATH, fileArgs)).map((file) => path.relative(docsRoot, path.resolve(CMD_EXEC_PATH, file))))
272
273
  : undefined;
273
- const graph = yield buildGraph(undefined, {
274
+ const graph = yield buildGraph(docsRoot, {
274
275
  checkSnippets: argv['check-snippets'],
275
276
  });
276
277
  graph.precomputeFileResolutions();
@@ -311,7 +312,7 @@ export const cli = ({ packageName = 'mint' }) => {
311
312
  const brokenRedirects = graph.getBrokenRedirects();
312
313
  if (brokenRedirects.length > 0) {
313
314
  const configFilename = yield fs
314
- .access(path.join(CMD_EXEC_PATH, 'docs.json'))
315
+ .access(path.join(docsRoot, 'docs.json'))
315
316
  .then(() => 'docs.json')
316
317
  .catch(() => 'mint.json');
317
318
  const labels = brokenRedirects.map(({ source, destination }) => `${source} → ${destination}`);
package/bin/helpers.js CHANGED
@@ -55,6 +55,17 @@ export const checkNodeVersion = () => __awaiter(void 0, void 0, void 0, function
55
55
  export const checkForMintJson = () => __awaiter(void 0, void 0, void 0, function* () {
56
56
  return !!(yield getConfigPath(CMD_EXEC_PATH, 'mint'));
57
57
  });
58
+ export const findDocsRoot = (startDir) => __awaiter(void 0, void 0, void 0, function* () {
59
+ const start = path.resolve(startDir);
60
+ const { root } = path.parse(start);
61
+ let dir = start;
62
+ while (dir !== root) {
63
+ if ((yield getConfigPath(dir, 'docs')) || (yield getConfigPath(dir, 'mint')))
64
+ return dir;
65
+ dir = path.dirname(dir);
66
+ }
67
+ return start;
68
+ });
58
69
  export const checkForDocsJson = () => __awaiter(void 0, void 0, void 0, function* () {
59
70
  const docsJsonPath = path.join(CMD_EXEC_PATH, 'docs.json');
60
71
  if (!(yield fse.pathExists(docsJsonPath))) {