@mintlify/cli 4.0.1813 → 4.1.2
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/assets/export-scripts/README.classic.md +15 -0
- package/dist/assets/export-scripts/README.md +14 -0
- package/dist/assets/export-scripts/serve.js +114 -0
- package/dist/assets/export-scripts/start-docs.bat +10 -0
- package/dist/assets/export-scripts/start-docs.sh +9 -0
- package/dist/assets/og/Inter-Bold.ttf +0 -0
- package/dist/assets/og/Inter-Medium.ttf +0 -0
- package/dist/assets/og/Inter-Regular.ttf +0 -0
- package/dist/assets/og/Inter-SemiBold.ttf +0 -0
- package/dist/assets/og/PaperMono-Regular.ttf +0 -0
- package/dist/assets/og/index_bg.wasm +0 -0
- package/dist/assets/openChrome.applescript +94 -0
- package/dist/assets/socket.io/socket.io.esm.min.js +7 -0
- package/dist/assets/socket.io/socket.io.esm.min.js.map +1 -0
- package/dist/assets/socket.io/socket.io.js +4907 -0
- package/dist/assets/socket.io/socket.io.js.map +1 -0
- package/dist/assets/socket.io/socket.io.min.js +7 -0
- package/dist/assets/socket.io/socket.io.min.js.map +1 -0
- package/dist/assets/socket.io/socket.io.msgpack.min.js +7 -0
- package/dist/assets/socket.io/socket.io.msgpack.min.js.map +1 -0
- package/dist/assets/xdg-open +1066 -0
- package/dist/assets/yargs-locales/be.json +46 -0
- package/dist/assets/yargs-locales/cs.json +51 -0
- package/dist/assets/yargs-locales/de.json +46 -0
- package/dist/assets/yargs-locales/en.json +55 -0
- package/dist/assets/yargs-locales/es.json +46 -0
- package/dist/assets/yargs-locales/fi.json +49 -0
- package/dist/assets/yargs-locales/fr.json +53 -0
- package/dist/assets/yargs-locales/hi.json +49 -0
- package/dist/assets/yargs-locales/hu.json +46 -0
- package/dist/assets/yargs-locales/id.json +50 -0
- package/dist/assets/yargs-locales/it.json +46 -0
- package/dist/assets/yargs-locales/ja.json +51 -0
- package/dist/assets/yargs-locales/ko.json +49 -0
- package/dist/assets/yargs-locales/nb.json +44 -0
- package/dist/assets/yargs-locales/nl.json +49 -0
- package/dist/assets/yargs-locales/nn.json +44 -0
- package/dist/assets/yargs-locales/pirate.json +13 -0
- package/dist/assets/yargs-locales/pl.json +49 -0
- package/dist/assets/yargs-locales/pt.json +45 -0
- package/dist/assets/yargs-locales/pt_BR.json +48 -0
- package/dist/assets/yargs-locales/ru.json +51 -0
- package/dist/assets/yargs-locales/th.json +46 -0
- package/dist/assets/yargs-locales/tr.json +48 -0
- package/dist/assets/yargs-locales/uk_UA.json +51 -0
- package/dist/assets/yargs-locales/uz.json +52 -0
- package/dist/assets/yargs-locales/zh_CN.json +48 -0
- package/dist/assets/yargs-locales/zh_TW.json +51 -0
- package/dist/converter-d8O3xkdU.js +102 -0
- package/dist/devtools-CGNZQKFV.js +24 -0
- package/dist/index.js +8 -0
- package/dist/rolldown-runtime-CEAe2Uac.js +7 -0
- package/dist/schemas-CBsmCNpK.js +372 -0
- package/dist/start.js +2310 -0
- package/package.json +38 -31
- package/.oxlintrc.json +0 -5
- package/.prettierignore +0 -2
- package/.turbo/turbo-build.log +0 -1
- package/CONTRIBUTING.md +0 -45
- package/__test__/agent-auth.test.ts +0 -114
- package/__test__/agent-claim.test.ts +0 -164
- package/__test__/agent-credentials.test.ts +0 -149
- package/__test__/agent-deployment.test.ts +0 -106
- package/__test__/agent-setup-config.test.ts +0 -324
- package/__test__/agent-setup.test.ts +0 -207
- package/__test__/agent.test.ts +0 -64
- package/__test__/analytics/client.test.ts +0 -180
- package/__test__/analytics/dates.test.ts +0 -12
- package/__test__/analytics/filters.test.ts +0 -116
- package/__test__/analytics/format.test.ts +0 -137
- package/__test__/authenticatedFetch.test.ts +0 -182
- package/__test__/brokenLinks.test.ts +0 -283
- package/__test__/checkPort.test.ts +0 -92
- package/__test__/deploy-github-actions.test.ts +0 -202
- package/__test__/deploy-github-setup.test.ts +0 -240
- package/__test__/deploy-instructions.test.ts +0 -155
- package/__test__/deploy.test.ts +0 -202
- package/__test__/feedback.test.ts +0 -34
- package/__test__/foreignSyntax.test.ts +0 -73
- package/__test__/format.test.ts +0 -72
- package/__test__/helpers.test.ts +0 -52
- package/__test__/init.test.ts +0 -119
- package/__test__/instructions.test.ts +0 -53
- package/__test__/keyring.test.ts +0 -82
- package/__test__/mdxAccessibility.test.ts +0 -81
- package/__test__/migrate.test.ts +0 -186
- package/__test__/openApiCheck.test.ts +0 -185
- package/__test__/pathValidation.test.ts +0 -25
- package/__test__/resolveFiles.test.ts +0 -70
- package/__test__/sessionId.test.ts +0 -46
- package/__test__/signup.test.ts +0 -36
- package/__test__/update.test.ts +0 -117
- package/__test__/utils.ts +0 -25
- package/__test__/validateCommand.test.ts +0 -647
- package/__test__/validateEngine.test.ts +0 -245
- package/__test__/validateRules.test.ts +0 -1275
- package/__test__/welcome.test.ts +0 -15
- package/__test__/workflows/client.test.ts +0 -126
- package/bin/accessibility.js +0 -111
- package/bin/accessibilityCheck.js +0 -82
- package/bin/addDomain.js +0 -130
- package/bin/agent-auth.js +0 -104
- package/bin/agent-claim.js +0 -97
- package/bin/agent-credentials.js +0 -124
- package/bin/agent-deployment.js +0 -96
- package/bin/agent-http.js +0 -45
- package/bin/agent-setup-config.js +0 -141
- package/bin/agent-setup.js +0 -146
- package/bin/agent.js +0 -42
- package/bin/analytics/client.js +0 -60
- package/bin/analytics/dates.js +0 -6
- package/bin/analytics/filters.js +0 -27
- package/bin/analytics/format.js +0 -13
- package/bin/analytics/index.js +0 -496
- package/bin/analytics/output.js +0 -75
- package/bin/analytics/types.js +0 -1
- package/bin/authenticatedFetch.js +0 -46
- package/bin/brokenLinks.js +0 -122
- package/bin/callbackServer.js +0 -65
- package/bin/cli.js +0 -813
- package/bin/comingSoon.js +0 -26
- package/bin/config.js +0 -78
- package/bin/constants.js +0 -16
- package/bin/deploy-base.js +0 -20
- package/bin/deploy-github-actions.js +0 -102
- package/bin/deploy-github-setup.js +0 -165
- package/bin/deploy-instructions.js +0 -71
- package/bin/deploy.js +0 -123
- package/bin/feedback.js +0 -36
- package/bin/format.js +0 -121
- package/bin/helpers.js +0 -238
- package/bin/idToken.js +0 -14
- package/bin/index.js +0 -102
- package/bin/init.js +0 -182
- package/bin/instructions.js +0 -101
- package/bin/keyring.js +0 -78
- package/bin/login.js +0 -123
- package/bin/logout.js +0 -18
- package/bin/mdxAccessibility.js +0 -113
- package/bin/mdxLinter.js +0 -55
- package/bin/middlewares/subdomainMiddleware.js +0 -28
- package/bin/middlewares/telemetryMiddleware.js +0 -61
- package/bin/migrate.js +0 -54
- package/bin/og.js +0 -145
- package/bin/openApiCheck.js +0 -99
- package/bin/resolveFiles.js +0 -114
- package/bin/score/client.js +0 -40
- package/bin/score/index.js +0 -211
- package/bin/score/types.js +0 -1
- package/bin/signup.js +0 -118
- package/bin/start.js +0 -36
- package/bin/status.js +0 -106
- package/bin/telemetry/client.js +0 -53
- package/bin/telemetry/distinctId.js +0 -68
- package/bin/telemetry/sessionId.js +0 -36
- package/bin/telemetry/track.js +0 -149
- package/bin/templates.js +0 -127
- package/bin/tokenRefresh.js +0 -50
- package/bin/tsconfig.build.tsbuildinfo +0 -1
- package/bin/update.js +0 -65
- package/bin/validate/command.js +0 -127
- package/bin/validate/engine.js +0 -154
- package/bin/validate/files.js +0 -163
- package/bin/validate/mdx.js +0 -238
- package/bin/validate/output.js +0 -44
- package/bin/validate/report.js +0 -11
- package/bin/validate/rules/build.js +0 -102
- package/bin/validate/rules/content/duplicateH1.js +0 -57
- package/bin/validate/rules/content/foreignSyntax.js +0 -120
- package/bin/validate/rules/content/katex.js +0 -34
- package/bin/validate/rules/content/missingSnippet.js +0 -34
- package/bin/validate/rules/content/undefinedVariable.js +0 -13
- package/bin/validate/rules/content/unknownComponent.js +0 -121
- package/bin/validate/rules/content/voidTags.js +0 -38
- package/bin/validate/rules/index.js +0 -21
- package/bin/validate/rules/openapi.js +0 -50
- package/bin/validate/rules/parseError.js +0 -7
- package/bin/validate/site.js +0 -57
- package/bin/validate/types.js +0 -1
- package/bin/vendor/converter.js +0 -30882
- package/bin/welcome.js +0 -108
- package/bin/workflows/client.js +0 -34
- package/bin/workflows/index.js +0 -269
- package/bin/workflows/types.js +0 -11
- package/scripts/bundle-converter.mjs +0 -26
- package/scripts/generate-logo.mjs +0 -79
- package/src/accessibility.ts +0 -180
- package/src/accessibilityCheck.tsx +0 -150
- package/src/addDomain.tsx +0 -206
- package/src/agent-auth.ts +0 -119
- package/src/agent-claim.ts +0 -124
- package/src/agent-credentials.ts +0 -104
- package/src/agent-deployment.ts +0 -116
- package/src/agent-http.ts +0 -34
- package/src/agent-setup-config.ts +0 -144
- package/src/agent-setup.ts +0 -165
- package/src/agent.ts +0 -56
- package/src/analytics/client.ts +0 -153
- package/src/analytics/dates.ts +0 -6
- package/src/analytics/filters.ts +0 -50
- package/src/analytics/format.ts +0 -13
- package/src/analytics/index.tsx +0 -599
- package/src/analytics/output.ts +0 -99
- package/src/analytics/types.ts +0 -145
- package/src/authenticatedFetch.ts +0 -42
- package/src/brokenLinks.tsx +0 -152
- package/src/callbackServer.ts +0 -64
- package/src/cli.tsx +0 -1105
- package/src/comingSoon.tsx +0 -29
- package/src/config.ts +0 -75
- package/src/constants.ts +0 -28
- package/src/deploy-base.ts +0 -18
- package/src/deploy-github-actions.ts +0 -139
- package/src/deploy-github-setup.ts +0 -189
- package/src/deploy-instructions.ts +0 -76
- package/src/deploy.ts +0 -165
- package/src/feedback.tsx +0 -31
- package/src/format.tsx +0 -82
- package/src/helpers.tsx +0 -279
- package/src/idToken.ts +0 -17
- package/src/index.ts +0 -109
- package/src/init.tsx +0 -237
- package/src/instructions.ts +0 -99
- package/src/keyring.ts +0 -65
- package/src/login.tsx +0 -166
- package/src/logout.tsx +0 -8
- package/src/mdxAccessibility.ts +0 -134
- package/src/mdxLinter.tsx +0 -88
- package/src/middlewares/subdomainMiddleware.ts +0 -20
- package/src/middlewares/telemetryMiddleware.ts +0 -55
- package/src/migrate.ts +0 -76
- package/src/og.tsx +0 -185
- package/src/openApiCheck.tsx +0 -125
- package/src/resolveFiles.ts +0 -101
- package/src/score/client.ts +0 -36
- package/src/score/index.tsx +0 -205
- package/src/score/types.ts +0 -15
- package/src/signup.tsx +0 -172
- package/src/start.ts +0 -27
- package/src/status.tsx +0 -129
- package/src/telemetry/client.ts +0 -46
- package/src/telemetry/distinctId.ts +0 -70
- package/src/telemetry/sessionId.ts +0 -40
- package/src/telemetry/track.ts +0 -163
- package/src/templates.tsx +0 -143
- package/src/tokenRefresh.ts +0 -53
- package/src/update.tsx +0 -89
- package/src/validate/command.tsx +0 -135
- package/src/validate/engine.ts +0 -210
- package/src/validate/files.ts +0 -249
- package/src/validate/mdx.ts +0 -290
- package/src/validate/output.tsx +0 -76
- package/src/validate/report.ts +0 -40
- package/src/validate/rules/build.ts +0 -146
- package/src/validate/rules/content/duplicateH1.ts +0 -78
- package/src/validate/rules/content/foreignSyntax.ts +0 -144
- package/src/validate/rules/content/katex.ts +0 -33
- package/src/validate/rules/content/missingSnippet.ts +0 -36
- package/src/validate/rules/content/undefinedVariable.ts +0 -20
- package/src/validate/rules/content/unknownComponent.ts +0 -130
- package/src/validate/rules/content/voidTags.ts +0 -43
- package/src/validate/rules/index.ts +0 -23
- package/src/validate/rules/openapi.ts +0 -59
- package/src/validate/rules/parseError.ts +0 -9
- package/src/validate/site.ts +0 -53
- package/src/validate/types.ts +0 -102
- package/src/vendor/converter.ts +0 -1
- package/src/welcome.ts +0 -154
- package/src/workflows/client.ts +0 -39
- package/src/workflows/index.tsx +0 -287
- package/src/workflows/types.ts +0 -73
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -10
- package/vitest.config.ts +0 -9
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import { buildGraph, getBrokenExternalLinks } from '@mintlify/link-rot';
|
|
2
|
-
import { MdxPath } from '@mintlify/link-rot/dist/graph.js';
|
|
3
|
-
import { addLog, clearLogs } from '@mintlify/previewing';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { mockProcessExit } from 'vitest-mock-process';
|
|
6
|
-
|
|
7
|
-
import { checkForMintJson, CMD_EXEC_PATH, findDocsRoot } from '../src/helpers.js';
|
|
8
|
-
import { resolveExplicitFiles } from '../src/resolveFiles.js';
|
|
9
|
-
import { runCommand } from './utils.js';
|
|
10
|
-
|
|
11
|
-
vi.mock('@mintlify/previewing', async (importOriginal) => {
|
|
12
|
-
const mod = await importOriginal<typeof import('@mintlify/previewing')>();
|
|
13
|
-
return { ...mod, addLog: vi.fn(), clearLogs: vi.fn() };
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
vi.mock('../src/helpers.js', async (importOriginal) => {
|
|
17
|
-
const actual = await importOriginal<typeof import('../src/helpers.js')>();
|
|
18
|
-
return {
|
|
19
|
-
...actual,
|
|
20
|
-
checkForMintJson: vi.fn(),
|
|
21
|
-
findDocsRoot: vi.fn(),
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
vi.mock('../src/resolveFiles.js', () => ({
|
|
26
|
-
resolveExplicitFiles: vi.fn(),
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
const mockGraph = {
|
|
30
|
-
precomputeFileResolutions: vi.fn(),
|
|
31
|
-
getBrokenInternalLinks: vi.fn().mockReturnValue([]),
|
|
32
|
-
getExternalPathsByNode: vi.fn().mockReturnValue(new Map()),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
vi.mock('@mintlify/link-rot', async () => {
|
|
36
|
-
const actual = await import('@mintlify/link-rot');
|
|
37
|
-
return {
|
|
38
|
-
...actual,
|
|
39
|
-
buildGraph: vi.fn(),
|
|
40
|
-
getBrokenExternalLinks: vi.fn(),
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const addLogSpy = vi.mocked(addLog);
|
|
45
|
-
const clearLogsSpy = vi.mocked(clearLogs);
|
|
46
|
-
const processExitMock = mockProcessExit();
|
|
47
|
-
|
|
48
|
-
describe('brokenLinks', () => {
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
vi.clearAllMocks();
|
|
51
|
-
vi.mocked(buildGraph).mockResolvedValue(mockGraph as never);
|
|
52
|
-
vi.mocked(resolveExplicitFiles).mockResolvedValue([]);
|
|
53
|
-
vi.mocked(findDocsRoot).mockResolvedValue(CMD_EXEC_PATH);
|
|
54
|
-
mockGraph.getBrokenInternalLinks.mockReturnValue([]);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('success with no broken links', async () => {
|
|
58
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
59
|
-
|
|
60
|
-
await runCommand('broken-links');
|
|
61
|
-
|
|
62
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
63
|
-
expect.objectContaining({
|
|
64
|
-
props: { message: 'checking for broken links...' },
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
68
|
-
expect.objectContaining({
|
|
69
|
-
props: { message: 'no broken links found' },
|
|
70
|
-
})
|
|
71
|
-
);
|
|
72
|
-
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('fails with broken links', async () => {
|
|
76
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
77
|
-
mockGraph.getBrokenInternalLinks.mockReturnValue([
|
|
78
|
-
{
|
|
79
|
-
relativeDir: '.',
|
|
80
|
-
filename: 'introduction.mdx',
|
|
81
|
-
originalPath: '/api/invalid-path',
|
|
82
|
-
pathType: 'internal',
|
|
83
|
-
} as MdxPath,
|
|
84
|
-
]);
|
|
85
|
-
|
|
86
|
-
await runCommand('broken-links');
|
|
87
|
-
|
|
88
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
89
|
-
expect.objectContaining({
|
|
90
|
-
props: { message: 'checking for broken links...' },
|
|
91
|
-
})
|
|
92
|
-
);
|
|
93
|
-
expect(clearLogsSpy).toHaveBeenCalled();
|
|
94
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
95
|
-
expect.objectContaining({
|
|
96
|
-
props: {
|
|
97
|
-
brokenLinksByFile: {
|
|
98
|
-
'introduction.mdx': ['/api/invalid-path'],
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
})
|
|
102
|
-
);
|
|
103
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('checks only files matching the provided option', async () => {
|
|
107
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
108
|
-
vi.mocked(resolveExplicitFiles).mockResolvedValueOnce(['guides/selected.mdx']);
|
|
109
|
-
mockGraph.getBrokenInternalLinks.mockReturnValue([
|
|
110
|
-
{
|
|
111
|
-
relativeDir: 'guides',
|
|
112
|
-
filename: 'selected.mdx',
|
|
113
|
-
originalPath: '/api/selected-invalid',
|
|
114
|
-
pathType: 'internal',
|
|
115
|
-
} as MdxPath,
|
|
116
|
-
{
|
|
117
|
-
relativeDir: 'guides',
|
|
118
|
-
filename: 'other.mdx',
|
|
119
|
-
originalPath: '/api/other-invalid',
|
|
120
|
-
pathType: 'internal',
|
|
121
|
-
} as MdxPath,
|
|
122
|
-
]);
|
|
123
|
-
|
|
124
|
-
await runCommand('broken-links', '--files', 'guides/selected.mdx', 'guides/**/*.mdx');
|
|
125
|
-
|
|
126
|
-
expect(resolveExplicitFiles).toHaveBeenCalledWith(CMD_EXEC_PATH, [
|
|
127
|
-
'guides/selected.mdx',
|
|
128
|
-
'guides/**/*.mdx',
|
|
129
|
-
]);
|
|
130
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
131
|
-
expect.objectContaining({
|
|
132
|
-
props: {
|
|
133
|
-
brokenLinksByFile: {
|
|
134
|
-
[path.join('guides', 'selected.mdx')]: ['/api/selected-invalid'],
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
})
|
|
138
|
-
);
|
|
139
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('builds the graph from the docs root when run inside a content folder', async () => {
|
|
143
|
-
const docsRoot = path.resolve(CMD_EXEC_PATH, '..', '..');
|
|
144
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
145
|
-
vi.mocked(findDocsRoot).mockResolvedValue(docsRoot);
|
|
146
|
-
vi.mocked(resolveExplicitFiles).mockResolvedValueOnce(['apis.mdx']);
|
|
147
|
-
mockGraph.getBrokenInternalLinks.mockReturnValue([]);
|
|
148
|
-
|
|
149
|
-
await runCommand('broken-links', '--files', 'apis.mdx');
|
|
150
|
-
|
|
151
|
-
expect(buildGraph).toHaveBeenCalledWith(docsRoot, expect.anything());
|
|
152
|
-
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('rebases matched files onto the docs root so nested links still resolve', async () => {
|
|
156
|
-
const docsRoot = path.resolve(CMD_EXEC_PATH, '..', '..');
|
|
157
|
-
const nested = path.relative(docsRoot, path.join(CMD_EXEC_PATH, 'apis.mdx'));
|
|
158
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
159
|
-
vi.mocked(findDocsRoot).mockResolvedValue(docsRoot);
|
|
160
|
-
vi.mocked(resolveExplicitFiles).mockResolvedValueOnce(['apis.mdx']);
|
|
161
|
-
mockGraph.getBrokenInternalLinks.mockReturnValue([
|
|
162
|
-
{
|
|
163
|
-
relativeDir: path.dirname(nested),
|
|
164
|
-
filename: 'apis.mdx',
|
|
165
|
-
originalPath: '/docs/authenticate',
|
|
166
|
-
pathType: 'internal',
|
|
167
|
-
} as MdxPath,
|
|
168
|
-
]);
|
|
169
|
-
|
|
170
|
-
await runCommand('broken-links', '--files', 'apis.mdx');
|
|
171
|
-
|
|
172
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
173
|
-
expect.objectContaining({
|
|
174
|
-
props: { brokenLinksByFile: { [nested]: ['/docs/authenticate'] } },
|
|
175
|
-
})
|
|
176
|
-
);
|
|
177
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('fails when checking throws error', async () => {
|
|
181
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
182
|
-
vi.mocked(buildGraph).mockRejectedValueOnce(new Error('some error'));
|
|
183
|
-
|
|
184
|
-
await runCommand('broken-links');
|
|
185
|
-
|
|
186
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
187
|
-
expect.objectContaining({
|
|
188
|
-
props: { message: 'checking for broken links...' },
|
|
189
|
-
})
|
|
190
|
-
);
|
|
191
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
192
|
-
expect.objectContaining({
|
|
193
|
-
props: { message: 'some error' },
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
describe('brokenLinks --check-external', () => {
|
|
201
|
-
beforeEach(() => {
|
|
202
|
-
vi.clearAllMocks();
|
|
203
|
-
vi.mocked(buildGraph).mockResolvedValue(mockGraph as never);
|
|
204
|
-
vi.mocked(resolveExplicitFiles).mockResolvedValue([]);
|
|
205
|
-
vi.mocked(findDocsRoot).mockResolvedValue(CMD_EXEC_PATH);
|
|
206
|
-
mockGraph.getBrokenInternalLinks.mockReturnValue([]);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('success with no broken external links', async () => {
|
|
210
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
211
|
-
vi.mocked(getBrokenExternalLinks).mockResolvedValueOnce([]);
|
|
212
|
-
|
|
213
|
-
await runCommand('broken-links', '--check-external');
|
|
214
|
-
|
|
215
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
216
|
-
expect.objectContaining({
|
|
217
|
-
props: { message: 'no broken links found' },
|
|
218
|
-
})
|
|
219
|
-
);
|
|
220
|
-
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('fails with broken external links', async () => {
|
|
224
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
225
|
-
vi.mocked(getBrokenExternalLinks).mockResolvedValueOnce([
|
|
226
|
-
{
|
|
227
|
-
url: 'https://example.com/broken',
|
|
228
|
-
status: 404,
|
|
229
|
-
sources: [{ file: 'introduction.mdx', originalPath: 'https://example.com/broken' }],
|
|
230
|
-
},
|
|
231
|
-
]);
|
|
232
|
-
|
|
233
|
-
await runCommand('broken-links', '--check-external');
|
|
234
|
-
|
|
235
|
-
expect(clearLogsSpy).toHaveBeenCalled();
|
|
236
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
237
|
-
expect.objectContaining({
|
|
238
|
-
props: {
|
|
239
|
-
brokenLinksByFile: {
|
|
240
|
-
'introduction.mdx': ['https://example.com/broken (404)'],
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
})
|
|
244
|
-
);
|
|
245
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('checks external links only from matching files', async () => {
|
|
249
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
250
|
-
vi.mocked(resolveExplicitFiles).mockResolvedValueOnce(['selected.mdx']);
|
|
251
|
-
vi.mocked(getBrokenExternalLinks).mockResolvedValueOnce([]);
|
|
252
|
-
|
|
253
|
-
await runCommand('broken-links', '--files', 'selected.mdx', '--check-external');
|
|
254
|
-
|
|
255
|
-
expect(getBrokenExternalLinks).toHaveBeenCalledWith(mockGraph, {
|
|
256
|
-
sourceFiles: new Set(['selected.mdx']),
|
|
257
|
-
});
|
|
258
|
-
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('fails when external link checking throws error', async () => {
|
|
262
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
263
|
-
vi.mocked(getBrokenExternalLinks).mockRejectedValueOnce(new Error('network error'));
|
|
264
|
-
|
|
265
|
-
await runCommand('broken-links', '--check-external');
|
|
266
|
-
|
|
267
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
268
|
-
expect.objectContaining({
|
|
269
|
-
props: { message: 'network error' },
|
|
270
|
-
})
|
|
271
|
-
);
|
|
272
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('does not check external links without --check-external flag', async () => {
|
|
276
|
-
vi.mocked(checkForMintJson).mockResolvedValueOnce(true);
|
|
277
|
-
|
|
278
|
-
await runCommand('broken-links');
|
|
279
|
-
|
|
280
|
-
expect(getBrokenExternalLinks).not.toHaveBeenCalled();
|
|
281
|
-
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
282
|
-
});
|
|
283
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as previewing from '@mintlify/previewing';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import { mockProcessExit } from 'vitest-mock-process';
|
|
4
|
-
|
|
5
|
-
import { runCommand } from './utils.js';
|
|
6
|
-
|
|
7
|
-
vi.mock('@mintlify/previewing', async () => {
|
|
8
|
-
const originalModule =
|
|
9
|
-
await vi.importActual<typeof import('@mintlify/previewing')>('@mintlify/previewing');
|
|
10
|
-
return {
|
|
11
|
-
...originalModule,
|
|
12
|
-
dev: vi.fn(),
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
vi.mock('readline/promises', () => {
|
|
17
|
-
return {
|
|
18
|
-
createInterface: () => {
|
|
19
|
-
return {
|
|
20
|
-
close: () => undefined,
|
|
21
|
-
question: (question: string) => {
|
|
22
|
-
console.log(question);
|
|
23
|
-
return 'y';
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const allowedPorts = [3000, 5002];
|
|
31
|
-
|
|
32
|
-
vi.mock('detect-port', () => ({
|
|
33
|
-
default: (port: number) => (allowedPorts.includes(port) ? port : port + 1),
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
const devSpy = vi.spyOn(previewing, 'dev');
|
|
37
|
-
const addLogSpy = vi.spyOn(previewing, 'addLog');
|
|
38
|
-
const processExitMock = mockProcessExit();
|
|
39
|
-
|
|
40
|
-
describe('checkPort', () => {
|
|
41
|
-
let originalArgv: string[];
|
|
42
|
-
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
// Remove all cached modules, otherwise the same results are shown in subsequent tests.
|
|
45
|
-
vi.resetModules();
|
|
46
|
-
|
|
47
|
-
// mock inquirer prompt
|
|
48
|
-
vi.spyOn(inquirer, 'prompt').mockResolvedValue({ action: 'continue' });
|
|
49
|
-
|
|
50
|
-
// Keep track of original process arguments.
|
|
51
|
-
originalArgv = process.argv;
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
afterEach(() => {
|
|
55
|
-
vi.resetAllMocks();
|
|
56
|
-
|
|
57
|
-
// Set process arguments back to the original value.
|
|
58
|
-
process.argv = originalArgv;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should run dev command', async () => {
|
|
62
|
-
await runCommand('dev');
|
|
63
|
-
|
|
64
|
-
expect(devSpy).toHaveBeenCalledWith(expect.objectContaining({ port: 3000 }));
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('port 5000 and 5001 should be taken and 5002 should be accepted by the user and available.', async () => {
|
|
68
|
-
await runCommand('dev', '--port=5000');
|
|
69
|
-
|
|
70
|
-
expect(addLogSpy).toHaveBeenCalledTimes(2);
|
|
71
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
72
|
-
expect.objectContaining({
|
|
73
|
-
props: { message: 'port 5000 is already in use. trying 5001 instead' },
|
|
74
|
-
})
|
|
75
|
-
);
|
|
76
|
-
expect(addLogSpy).toHaveBeenCalledWith(
|
|
77
|
-
expect.objectContaining({
|
|
78
|
-
props: { message: 'port 5001 is already in use. trying 5002 instead' },
|
|
79
|
-
})
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('fails after the 10th used port', async () => {
|
|
84
|
-
await runCommand('dev', '--port=8000');
|
|
85
|
-
|
|
86
|
-
expect(addLogSpy).toHaveBeenCalledTimes(10);
|
|
87
|
-
expect(addLogSpy).toHaveBeenLastCalledWith(
|
|
88
|
-
expect.objectContaining({ props: { message: 'no available port found' } })
|
|
89
|
-
);
|
|
90
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { execFileSync, spawn } from 'node:child_process';
|
|
2
|
-
import { EventEmitter } from 'node:events';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
-
|
|
8
|
-
import { deployFromGithubActions } from '../src/deploy-github-actions.js';
|
|
9
|
-
|
|
10
|
-
const real = vi.hoisted(() => ({ spawn: undefined as unknown as typeof spawn }));
|
|
11
|
-
vi.mock('node:child_process', async (importOriginal) => {
|
|
12
|
-
const original = await importOriginal<typeof import('node:child_process')>();
|
|
13
|
-
real.spawn = original.spawn;
|
|
14
|
-
return { ...original, spawn: vi.fn() };
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const apiUrl = 'https://leaves.mintlify.com';
|
|
18
|
-
const env = {
|
|
19
|
-
PATH: process.env.PATH,
|
|
20
|
-
HOME: process.env.HOME,
|
|
21
|
-
GITHUB_ACTIONS: 'true',
|
|
22
|
-
GITHUB_REPOSITORY: 'acme/monorepo',
|
|
23
|
-
ACTIONS_ID_TOKEN_REQUEST_URL: 'https://token.actions.example.com/request?api-version=2.0',
|
|
24
|
-
ACTIONS_ID_TOKEN_REQUEST_TOKEN: 'request-token',
|
|
25
|
-
};
|
|
26
|
-
const write = {
|
|
27
|
-
remote: 'https://git.example.com/repo.git',
|
|
28
|
-
branch: 'main',
|
|
29
|
-
token: 'write-token',
|
|
30
|
-
tokenExpiresAt: '2026-12-01T00:00:00.000Z',
|
|
31
|
-
};
|
|
32
|
-
let repo: string;
|
|
33
|
-
|
|
34
|
-
const gitIn = (cwd: string, ...args: string[]) =>
|
|
35
|
-
execFileSync('git', args, { cwd, encoding: 'utf8' }).trim();
|
|
36
|
-
const response = (body: unknown, status = 200) => new Response(JSON.stringify(body), { status });
|
|
37
|
-
const pushCall = () => vi.mocked(spawn).mock.calls.find(([, args]) => args[0] === 'push');
|
|
38
|
-
const stubFetch = (...bodies: Response[]) => {
|
|
39
|
-
const request = vi.fn();
|
|
40
|
-
for (const body of bodies) request.mockResolvedValueOnce(body);
|
|
41
|
-
vi.stubGlobal('fetch', request);
|
|
42
|
-
return request;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
function pushExitsWith(code: number) {
|
|
46
|
-
vi.mocked(spawn).mockImplementation(((command: string, args: string[], options: object) => {
|
|
47
|
-
if (args[0] !== 'push') return real.spawn(command, args, options);
|
|
48
|
-
const child = new EventEmitter();
|
|
49
|
-
setImmediate(() => child.emit('close', code));
|
|
50
|
-
return child;
|
|
51
|
-
}) as typeof spawn);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
vi.resetAllMocks();
|
|
56
|
-
pushExitsWith(0);
|
|
57
|
-
repo = fs.mkdtempSync(path.join(os.tmpdir(), 'mint-gha-'));
|
|
58
|
-
fs.mkdirSync(path.join(repo, 'docs'));
|
|
59
|
-
fs.writeFileSync(path.join(repo, 'docs', 'docs.json'), '{}\n');
|
|
60
|
-
fs.writeFileSync(path.join(repo, 'app.ts'), 'export {};\n');
|
|
61
|
-
gitIn(repo, 'init', '-q', '-b', 'main');
|
|
62
|
-
gitIn(
|
|
63
|
-
repo,
|
|
64
|
-
'-c',
|
|
65
|
-
'user.name=Ada',
|
|
66
|
-
'-c',
|
|
67
|
-
'user.email=ada@acme.dev',
|
|
68
|
-
'commit',
|
|
69
|
-
'-q',
|
|
70
|
-
'--allow-empty',
|
|
71
|
-
'-m',
|
|
72
|
-
'root'
|
|
73
|
-
);
|
|
74
|
-
gitIn(repo, 'add', '-A');
|
|
75
|
-
gitIn(
|
|
76
|
-
repo,
|
|
77
|
-
'-c',
|
|
78
|
-
'user.name=Ada',
|
|
79
|
-
'-c',
|
|
80
|
-
'user.email=ada@acme.dev',
|
|
81
|
-
'commit',
|
|
82
|
-
'-q',
|
|
83
|
-
'-m',
|
|
84
|
-
'update docs'
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
afterEach(() => {
|
|
88
|
-
vi.unstubAllGlobals();
|
|
89
|
-
fs.rmSync(repo, { recursive: true, force: true });
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe('mint deploy in GitHub Actions', () => {
|
|
93
|
-
it('pushes only the docs directory as the site root', async () => {
|
|
94
|
-
const request = stubFetch(response({ value: 'oidc-jwt' }), response(write));
|
|
95
|
-
const directory = path.join(repo, 'docs');
|
|
96
|
-
|
|
97
|
-
await expect(
|
|
98
|
-
deployFromGithubActions({ apiUrl, directory, subdomain: 'my-docs' }, undefined, env)
|
|
99
|
-
).resolves.toBe('https://my-docs.mintlify.site/');
|
|
100
|
-
|
|
101
|
-
expect(request.mock.calls[0]?.[0]).toBe(
|
|
102
|
-
`${env.ACTIONS_ID_TOKEN_REQUEST_URL}&audience=${encodeURIComponent(apiUrl)}`
|
|
103
|
-
);
|
|
104
|
-
expect(request.mock.calls[1]?.[0]).toBe(`${apiUrl}/api/agent/deployments/github-actions/token`);
|
|
105
|
-
expect(request.mock.calls[1]?.[1].headers.Authorization).toBe('Bearer oidc-jwt');
|
|
106
|
-
|
|
107
|
-
const [, args, options] = pushCall() ?? [];
|
|
108
|
-
const commit = String(args?.[3]).replace(':refs/heads/main', '');
|
|
109
|
-
expect(args).toEqual(['push', '--force', write.remote, `${commit}:refs/heads/main`]);
|
|
110
|
-
expect(args?.join(' ')).not.toContain('write-token');
|
|
111
|
-
expect(gitIn(repo, 'rev-parse', `${commit}^{tree}`)).toBe(
|
|
112
|
-
gitIn(repo, 'rev-parse', 'HEAD:docs')
|
|
113
|
-
);
|
|
114
|
-
expect(gitIn(repo, 'log', '-1', '--format=%an <%ae>%n%s', commit)).toBe(
|
|
115
|
-
'Ada <ada@acme.dev>\nupdate docs'
|
|
116
|
-
);
|
|
117
|
-
expect(gitIn(repo, 'log', '-1', '--format=%b', commit)).toBe(
|
|
118
|
-
`Deployed from acme/monorepo@${gitIn(repo, 'rev-parse', 'HEAD')}`
|
|
119
|
-
);
|
|
120
|
-
expect(options?.env).toMatchObject({
|
|
121
|
-
GIT_CONFIG_COUNT: '1',
|
|
122
|
-
GIT_CONFIG_KEY_0: `http.${write.remote}.extraHeader`,
|
|
123
|
-
GIT_CONFIG_VALUE_0: `Authorization: Basic ${Buffer.from('x-access-token:write-token').toString('base64')}`,
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('pushes the whole tree from the repository root', async () => {
|
|
128
|
-
stubFetch(response({ value: 'oidc-jwt' }), response(write));
|
|
129
|
-
await deployFromGithubActions(
|
|
130
|
-
{ apiUrl, directory: repo, subdomain: 'my-docs' },
|
|
131
|
-
undefined,
|
|
132
|
-
env
|
|
133
|
-
);
|
|
134
|
-
const commit = String(pushCall()?.[1]?.[3]).replace(':refs/heads/main', '');
|
|
135
|
-
expect(gitIn(repo, 'rev-parse', `${commit}^{tree}`)).toBe(
|
|
136
|
-
gitIn(repo, 'rev-parse', 'HEAD^{tree}')
|
|
137
|
-
);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('appends to existing git config environment entries', async () => {
|
|
141
|
-
stubFetch(response({ value: 'oidc-jwt' }), response(write));
|
|
142
|
-
await deployFromGithubActions({ apiUrl, directory: repo, subdomain: 'my-docs' }, undefined, {
|
|
143
|
-
...env,
|
|
144
|
-
GIT_CONFIG_COUNT: '2',
|
|
145
|
-
GIT_CONFIG_KEY_0: 'core.quotepath',
|
|
146
|
-
GIT_CONFIG_VALUE_0: 'false',
|
|
147
|
-
GIT_CONFIG_KEY_1: 'color.ui',
|
|
148
|
-
GIT_CONFIG_VALUE_1: 'false',
|
|
149
|
-
});
|
|
150
|
-
expect(pushCall()?.[2]?.env).toMatchObject({
|
|
151
|
-
GIT_CONFIG_COUNT: '3',
|
|
152
|
-
GIT_CONFIG_KEY_2: `http.${write.remote}.extraHeader`,
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('asks for id-token: write when OIDC is unavailable', async () => {
|
|
157
|
-
const request = stubFetch();
|
|
158
|
-
await expect(
|
|
159
|
-
deployFromGithubActions({ apiUrl, directory: repo, subdomain: 'my-docs' }, undefined, {
|
|
160
|
-
...env,
|
|
161
|
-
ACTIONS_ID_TOKEN_REQUEST_URL: undefined,
|
|
162
|
-
})
|
|
163
|
-
).rejects.toThrow('permissions: id-token: write');
|
|
164
|
-
expect(request).not.toHaveBeenCalled();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('requires --subdomain', async () => {
|
|
168
|
-
await expect(
|
|
169
|
-
deployFromGithubActions({ apiUrl, directory: repo }, undefined, env)
|
|
170
|
-
).rejects.toThrow('--subdomain');
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('fails clearly when the directory is not in the checkout', async () => {
|
|
174
|
-
const request = stubFetch();
|
|
175
|
-
await expect(
|
|
176
|
-
deployFromGithubActions(
|
|
177
|
-
{ apiUrl, directory: os.tmpdir(), subdomain: 'my-docs' },
|
|
178
|
-
undefined,
|
|
179
|
-
env
|
|
180
|
-
)
|
|
181
|
-
).rejects.toThrow('Could not read');
|
|
182
|
-
expect(request).not.toHaveBeenCalled();
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('explains how to trust the repository on 403', async () => {
|
|
186
|
-
stubFetch(response({ value: 'oidc-jwt' }), response({ error: 'forbidden' }, 403));
|
|
187
|
-
await expect(
|
|
188
|
-
deployFromGithubActions({ apiUrl, directory: repo, subdomain: 'my-docs' }, undefined, env)
|
|
189
|
-
).rejects.toThrow(
|
|
190
|
-
"This repository/branch isn't trusted to deploy my-docs. Run `mint deploy --github` locally"
|
|
191
|
-
);
|
|
192
|
-
expect(pushCall()).toBeUndefined();
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('fails when git push fails', async () => {
|
|
196
|
-
pushExitsWith(1);
|
|
197
|
-
stubFetch(response({ value: 'oidc-jwt' }), response(write));
|
|
198
|
-
await expect(
|
|
199
|
-
deployFromGithubActions({ apiUrl, directory: repo, subdomain: 'my-docs' }, undefined, env)
|
|
200
|
-
).rejects.toThrow('git push to the site repository failed');
|
|
201
|
-
});
|
|
202
|
-
});
|