@mintlify/cli 4.0.1812 → 4.1.1
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 +43 -36
- 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,245 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import fsSync from 'node:fs';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
|
|
6
|
-
import { applyFixes, checkSite, selectRules, UsageError } from '../src/validate/engine.js';
|
|
7
|
-
import { RULES } from '../src/validate/rules/index.js';
|
|
8
|
-
import {
|
|
9
|
-
GROUPS,
|
|
10
|
-
type Diagnostic,
|
|
11
|
-
type FileRule,
|
|
12
|
-
type Site,
|
|
13
|
-
type SiteRule,
|
|
14
|
-
} from '../src/validate/types.js';
|
|
15
|
-
|
|
16
|
-
const ids = (rules: { id: string }[]) => rules.map(({ id }) => id);
|
|
17
|
-
|
|
18
|
-
describe('selectRules', () => {
|
|
19
|
-
it('starts from every rule; --disable all empties the selection', () => {
|
|
20
|
-
expect(ids(selectRules({}))).toEqual(ids(RULES));
|
|
21
|
-
expect(ids(selectRules({ disable: ['all'] }))).toEqual([]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('turns on the rules of an enabled group', () => {
|
|
25
|
-
const content = ids(selectRules({ disable: ['all'], enable: ['content'] }));
|
|
26
|
-
|
|
27
|
-
expect(content).toEqual([
|
|
28
|
-
'void-tags',
|
|
29
|
-
'duplicate-h1',
|
|
30
|
-
'unknown-component',
|
|
31
|
-
'undefined-variable',
|
|
32
|
-
'missing-snippet',
|
|
33
|
-
'katex',
|
|
34
|
-
'foreign-syntax',
|
|
35
|
-
'missing-file',
|
|
36
|
-
'import-error',
|
|
37
|
-
]);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('applies --enable after --disable', () => {
|
|
41
|
-
expect(ids(selectRules({ disable: ['content'], enable: ['void-tags'] }))).toContain(
|
|
42
|
-
'void-tags'
|
|
43
|
-
);
|
|
44
|
-
expect(ids(selectRules({ disable: ['content'] }))).not.toContain('void-tags');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('rejects unknown names and naming parse-error', () => {
|
|
48
|
-
expect(() => selectRules({ enable: ['nope'] })).toThrow(UsageError);
|
|
49
|
-
expect(() => selectRules({ disable: ['parse-error'] })).toThrow(
|
|
50
|
-
"parse-error always runs and can't be disabled"
|
|
51
|
-
);
|
|
52
|
-
expect(() => selectRules({ enable: ['parse-error'] })).toThrow(
|
|
53
|
-
"parse-error always runs and can't be disabled"
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('gives every rule a known group, a severity and a description', () => {
|
|
58
|
-
for (const rule of RULES) {
|
|
59
|
-
expect(GROUPS).toContain(rule.group);
|
|
60
|
-
expect(['error', 'warning']).toContain(rule.severity);
|
|
61
|
-
expect(rule.description).not.toBe('');
|
|
62
|
-
expect(rule.id).not.toBe('parse-error');
|
|
63
|
-
expect(GROUPS as string[]).not.toContain(rule.id);
|
|
64
|
-
}
|
|
65
|
-
expect(new Set(ids(RULES)).size).toBe(RULES.length);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('applyFixes', () => {
|
|
70
|
-
let dir: string;
|
|
71
|
-
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'validate-engine-'));
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
afterEach(() => {
|
|
77
|
-
fs.removeSync(dir);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const site = () =>
|
|
81
|
-
({
|
|
82
|
-
baseDir: dir,
|
|
83
|
-
files: [],
|
|
84
|
-
read: (file: string) => fs.readFileSync(path.join(dir, file), 'utf-8'),
|
|
85
|
-
}) as unknown as Site;
|
|
86
|
-
|
|
87
|
-
const diagnostic = (fix: Diagnostic['fix'], rule = 'r'): Diagnostic => ({
|
|
88
|
-
rule,
|
|
89
|
-
group: 'content',
|
|
90
|
-
severity: 'error',
|
|
91
|
-
file: 'a.mdx',
|
|
92
|
-
message: 'm',
|
|
93
|
-
fix,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('applies fixes across files, skipping ones that overlap an applied fix', async () => {
|
|
97
|
-
fs.writeFileSync(path.join(dir, 'a.mdx'), 'one two three');
|
|
98
|
-
fs.writeFileSync(path.join(dir, 'b.json'), '{}');
|
|
99
|
-
|
|
100
|
-
const changes = await applyFixes(site(), [
|
|
101
|
-
diagnostic({ file: 'a.mdx', start: 0, end: 3, text: '1' }),
|
|
102
|
-
diagnostic({ file: 'a.mdx', start: 8, end: 13, text: '3' }),
|
|
103
|
-
diagnostic({ file: 'b.json', start: 1, end: 1, text: '"k":1' }),
|
|
104
|
-
// Overlaps the first fix, so it waits for the next pass
|
|
105
|
-
diagnostic({ file: 'a.mdx', start: 2, end: 5, text: 'x' }),
|
|
106
|
-
]);
|
|
107
|
-
|
|
108
|
-
expect(fs.readFileSync(path.join(dir, 'a.mdx'), 'utf-8')).toBe('1 two 3');
|
|
109
|
-
expect(fs.readFileSync(path.join(dir, 'b.json'), 'utf-8')).toBe('{"k":1}');
|
|
110
|
-
expect(changes.map(({ file, before, after }) => [file, before, after])).toEqual([
|
|
111
|
-
['a.mdx', 'one', '1'],
|
|
112
|
-
['a.mdx', 'three', '3'],
|
|
113
|
-
['b.json', '', '"k":1'],
|
|
114
|
-
]);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('applies two insertions at the same point', async () => {
|
|
118
|
-
fs.writeFileSync(path.join(dir, 'b.json'), '{}');
|
|
119
|
-
|
|
120
|
-
const changes = await applyFixes(site(), [
|
|
121
|
-
diagnostic({ file: 'b.json', start: 1, end: 1, text: ',"j":2' }),
|
|
122
|
-
diagnostic({ file: 'b.json', start: 1, end: 1, text: '"k":1' }),
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
expect(fs.readFileSync(path.join(dir, 'b.json'), 'utf-8')).toBe('{"k":1,"j":2}');
|
|
126
|
-
expect(changes).toHaveLength(2);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('applies a replacement and an insertion at its start', async () => {
|
|
130
|
-
fs.writeFileSync(path.join(dir, 'a.mdx'), 'a<br>b');
|
|
131
|
-
|
|
132
|
-
const changes = await applyFixes(site(), [
|
|
133
|
-
diagnostic({ file: 'a.mdx', start: 1, end: 5, text: '<br />' }),
|
|
134
|
-
diagnostic({ file: 'a.mdx', start: 1, end: 1, text: 'x' }),
|
|
135
|
-
]);
|
|
136
|
-
|
|
137
|
-
expect(fs.readFileSync(path.join(dir, 'a.mdx'), 'utf-8')).toBe('ax<br />b');
|
|
138
|
-
expect(changes.map(({ after }) => after)).toEqual(['<br />', 'x']);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('skips writing a Markdown file whose fixed content no longer parses', async () => {
|
|
142
|
-
fs.writeFileSync(path.join(dir, 'a.mdx'), 'hello world\n');
|
|
143
|
-
fs.writeFileSync(path.join(dir, 'b.mdx'), 'line<br>\n');
|
|
144
|
-
|
|
145
|
-
const changes = await applyFixes(site(), [
|
|
146
|
-
diagnostic({ file: 'a.mdx', start: 0, end: 5, text: '<Note>' }),
|
|
147
|
-
diagnostic({ file: 'b.mdx', start: 4, end: 8, text: '<br />' }),
|
|
148
|
-
]);
|
|
149
|
-
|
|
150
|
-
expect(fs.readFileSync(path.join(dir, 'a.mdx'), 'utf-8')).toBe('hello world\n');
|
|
151
|
-
expect(fs.readFileSync(path.join(dir, 'b.mdx'), 'utf-8')).toBe('line<br />\n');
|
|
152
|
-
expect(changes.map(({ file, after }) => [file, after])).toEqual([['b.mdx', '<br />']]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('fixes a page that only parses after the build preprocesses its <MDX> fragments', async () => {
|
|
156
|
-
const fragment = '{true ? <MDX>\n```bash\n<root>/{arch}/app.vpkg\n```\n</MDX> : null}\n';
|
|
157
|
-
fs.writeFileSync(path.join(dir, 'a.mdx'), `${fragment}\nline<br>\n`);
|
|
158
|
-
const start = fragment.length + 5;
|
|
159
|
-
|
|
160
|
-
const changes = await applyFixes(site(), [
|
|
161
|
-
diagnostic({ file: 'a.mdx', start, end: start + 4, text: '<br />' }),
|
|
162
|
-
]);
|
|
163
|
-
|
|
164
|
-
expect(fs.readFileSync(path.join(dir, 'a.mdx'), 'utf-8')).toBe(`${fragment}\nline<br />\n`);
|
|
165
|
-
expect(changes).toHaveLength(1);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('fixes an unparseable page even when another error keeps it unparseable', async () => {
|
|
169
|
-
fs.writeFileSync(path.join(dir, 'a.mdx'), 'line<br>\n');
|
|
170
|
-
fs.writeFileSync(path.join(dir, 'b.mdx'), 'line<br>\n\nText {broken\n');
|
|
171
|
-
|
|
172
|
-
const changes = await applyFixes(site(), [
|
|
173
|
-
diagnostic({ file: 'a.mdx', start: 4, end: 8, text: '<br />' }),
|
|
174
|
-
diagnostic({ file: 'b.mdx', start: 4, end: 8, text: '<br />' }),
|
|
175
|
-
]);
|
|
176
|
-
|
|
177
|
-
expect(fs.readFileSync(path.join(dir, 'a.mdx'), 'utf-8')).toBe('line<br />\n');
|
|
178
|
-
expect(fs.readFileSync(path.join(dir, 'b.mdx'), 'utf-8')).toBe('line<br />\n\nText {broken\n');
|
|
179
|
-
expect(changes).toHaveLength(2);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
describe('checkSite with fix', () => {
|
|
184
|
-
let dir: string;
|
|
185
|
-
|
|
186
|
-
beforeEach(() => {
|
|
187
|
-
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'validate-fix-passes-'));
|
|
188
|
-
fs.writeJSONSync(path.join(dir, 'docs.json'), {
|
|
189
|
-
name: 'Test',
|
|
190
|
-
navigation: { pages: ['index', 'other'] },
|
|
191
|
-
});
|
|
192
|
-
fs.writeFileSync(path.join(dir, 'index.mdx'), '---\ntitle: Home\n---\n\nText\n');
|
|
193
|
-
fs.writeFileSync(path.join(dir, 'other.mdx'), '---\ntitle: Other\n---\n\nText!!!\n');
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
afterEach(() => {
|
|
197
|
-
fs.removeSync(dir);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
/** Offers one "!" at a time until a page ends with `limit` of them, so each pass unlocks the next. */
|
|
201
|
-
const bang = (limit: number): FileRule => ({
|
|
202
|
-
id: 'bang',
|
|
203
|
-
group: 'content',
|
|
204
|
-
severity: 'warning',
|
|
205
|
-
scope: 'file',
|
|
206
|
-
raw: true,
|
|
207
|
-
description: 'test rule',
|
|
208
|
-
check: ({ content }) => {
|
|
209
|
-
const end = content.trimEnd().length;
|
|
210
|
-
return content.endsWith(`${'!'.repeat(limit)}\n`)
|
|
211
|
-
? []
|
|
212
|
-
: [{ message: 'needs a bang', edit: { start: end, end, text: '!' } }];
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const siteRule = (): SiteRule => ({
|
|
217
|
-
id: 'site',
|
|
218
|
-
group: 'config',
|
|
219
|
-
severity: 'warning',
|
|
220
|
-
scope: 'site',
|
|
221
|
-
description: 'test rule',
|
|
222
|
-
check: vi.fn(() => []),
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it('rechecks only changed files between passes and runs site rules once more at the end', async () => {
|
|
226
|
-
const site = siteRule();
|
|
227
|
-
const reads = vi.spyOn(fsSync, 'readFileSync');
|
|
228
|
-
|
|
229
|
-
const result = await checkSite(dir, [bang(3), site], { localSchema: false, fix: true });
|
|
230
|
-
|
|
231
|
-
const otherReads = reads.mock.calls.filter(([file]) => String(file).endsWith('other.mdx'));
|
|
232
|
-
reads.mockRestore();
|
|
233
|
-
expect(result.fixed.map(({ file }) => file)).toEqual(['index.mdx', 'index.mdx', 'index.mdx']);
|
|
234
|
-
expect(fs.readFileSync(path.join(dir, 'index.mdx'), 'utf-8')).toContain('Text!!!\n');
|
|
235
|
-
expect(result.diagnostics).toEqual([]);
|
|
236
|
-
expect(site.check).toHaveBeenCalledTimes(2);
|
|
237
|
-
expect(otherReads).toHaveLength(2);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('applies up to five passes of fixes', async () => {
|
|
241
|
-
const result = await checkSite(dir, [bang(10)], { localSchema: false, fix: true });
|
|
242
|
-
|
|
243
|
-
expect(result.fixed.filter(({ file }) => file === 'index.mdx')).toHaveLength(5);
|
|
244
|
-
});
|
|
245
|
-
});
|