@mintlify/cli 4.0.1813 → 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.
Files changed (274) hide show
  1. package/dist/assets/export-scripts/README.classic.md +15 -0
  2. package/dist/assets/export-scripts/README.md +14 -0
  3. package/dist/assets/export-scripts/serve.js +114 -0
  4. package/dist/assets/export-scripts/start-docs.bat +10 -0
  5. package/dist/assets/export-scripts/start-docs.sh +9 -0
  6. package/dist/assets/og/Inter-Bold.ttf +0 -0
  7. package/dist/assets/og/Inter-Medium.ttf +0 -0
  8. package/dist/assets/og/Inter-Regular.ttf +0 -0
  9. package/dist/assets/og/Inter-SemiBold.ttf +0 -0
  10. package/dist/assets/og/PaperMono-Regular.ttf +0 -0
  11. package/dist/assets/og/index_bg.wasm +0 -0
  12. package/dist/assets/openChrome.applescript +94 -0
  13. package/dist/assets/socket.io/socket.io.esm.min.js +7 -0
  14. package/dist/assets/socket.io/socket.io.esm.min.js.map +1 -0
  15. package/dist/assets/socket.io/socket.io.js +4907 -0
  16. package/dist/assets/socket.io/socket.io.js.map +1 -0
  17. package/dist/assets/socket.io/socket.io.min.js +7 -0
  18. package/dist/assets/socket.io/socket.io.min.js.map +1 -0
  19. package/dist/assets/socket.io/socket.io.msgpack.min.js +7 -0
  20. package/dist/assets/socket.io/socket.io.msgpack.min.js.map +1 -0
  21. package/dist/assets/xdg-open +1066 -0
  22. package/dist/assets/yargs-locales/be.json +46 -0
  23. package/dist/assets/yargs-locales/cs.json +51 -0
  24. package/dist/assets/yargs-locales/de.json +46 -0
  25. package/dist/assets/yargs-locales/en.json +55 -0
  26. package/dist/assets/yargs-locales/es.json +46 -0
  27. package/dist/assets/yargs-locales/fi.json +49 -0
  28. package/dist/assets/yargs-locales/fr.json +53 -0
  29. package/dist/assets/yargs-locales/hi.json +49 -0
  30. package/dist/assets/yargs-locales/hu.json +46 -0
  31. package/dist/assets/yargs-locales/id.json +50 -0
  32. package/dist/assets/yargs-locales/it.json +46 -0
  33. package/dist/assets/yargs-locales/ja.json +51 -0
  34. package/dist/assets/yargs-locales/ko.json +49 -0
  35. package/dist/assets/yargs-locales/nb.json +44 -0
  36. package/dist/assets/yargs-locales/nl.json +49 -0
  37. package/dist/assets/yargs-locales/nn.json +44 -0
  38. package/dist/assets/yargs-locales/pirate.json +13 -0
  39. package/dist/assets/yargs-locales/pl.json +49 -0
  40. package/dist/assets/yargs-locales/pt.json +45 -0
  41. package/dist/assets/yargs-locales/pt_BR.json +48 -0
  42. package/dist/assets/yargs-locales/ru.json +51 -0
  43. package/dist/assets/yargs-locales/th.json +46 -0
  44. package/dist/assets/yargs-locales/tr.json +48 -0
  45. package/dist/assets/yargs-locales/uk_UA.json +51 -0
  46. package/dist/assets/yargs-locales/uz.json +52 -0
  47. package/dist/assets/yargs-locales/zh_CN.json +48 -0
  48. package/dist/assets/yargs-locales/zh_TW.json +51 -0
  49. package/dist/converter-d8O3xkdU.js +102 -0
  50. package/dist/devtools-CGNZQKFV.js +24 -0
  51. package/dist/index.js +8 -0
  52. package/dist/rolldown-runtime-CEAe2Uac.js +7 -0
  53. package/dist/schemas-CBsmCNpK.js +372 -0
  54. package/dist/start.js +2310 -0
  55. package/package.json +38 -31
  56. package/.oxlintrc.json +0 -5
  57. package/.prettierignore +0 -2
  58. package/.turbo/turbo-build.log +0 -1
  59. package/CONTRIBUTING.md +0 -45
  60. package/__test__/agent-auth.test.ts +0 -114
  61. package/__test__/agent-claim.test.ts +0 -164
  62. package/__test__/agent-credentials.test.ts +0 -149
  63. package/__test__/agent-deployment.test.ts +0 -106
  64. package/__test__/agent-setup-config.test.ts +0 -324
  65. package/__test__/agent-setup.test.ts +0 -207
  66. package/__test__/agent.test.ts +0 -64
  67. package/__test__/analytics/client.test.ts +0 -180
  68. package/__test__/analytics/dates.test.ts +0 -12
  69. package/__test__/analytics/filters.test.ts +0 -116
  70. package/__test__/analytics/format.test.ts +0 -137
  71. package/__test__/authenticatedFetch.test.ts +0 -182
  72. package/__test__/brokenLinks.test.ts +0 -283
  73. package/__test__/checkPort.test.ts +0 -92
  74. package/__test__/deploy-github-actions.test.ts +0 -202
  75. package/__test__/deploy-github-setup.test.ts +0 -240
  76. package/__test__/deploy-instructions.test.ts +0 -155
  77. package/__test__/deploy.test.ts +0 -202
  78. package/__test__/feedback.test.ts +0 -34
  79. package/__test__/foreignSyntax.test.ts +0 -73
  80. package/__test__/format.test.ts +0 -72
  81. package/__test__/helpers.test.ts +0 -52
  82. package/__test__/init.test.ts +0 -119
  83. package/__test__/instructions.test.ts +0 -53
  84. package/__test__/keyring.test.ts +0 -82
  85. package/__test__/mdxAccessibility.test.ts +0 -81
  86. package/__test__/migrate.test.ts +0 -186
  87. package/__test__/openApiCheck.test.ts +0 -185
  88. package/__test__/pathValidation.test.ts +0 -25
  89. package/__test__/resolveFiles.test.ts +0 -70
  90. package/__test__/sessionId.test.ts +0 -46
  91. package/__test__/signup.test.ts +0 -36
  92. package/__test__/update.test.ts +0 -117
  93. package/__test__/utils.ts +0 -25
  94. package/__test__/validateCommand.test.ts +0 -647
  95. package/__test__/validateEngine.test.ts +0 -245
  96. package/__test__/validateRules.test.ts +0 -1275
  97. package/__test__/welcome.test.ts +0 -15
  98. package/__test__/workflows/client.test.ts +0 -126
  99. package/bin/accessibility.js +0 -111
  100. package/bin/accessibilityCheck.js +0 -82
  101. package/bin/addDomain.js +0 -130
  102. package/bin/agent-auth.js +0 -104
  103. package/bin/agent-claim.js +0 -97
  104. package/bin/agent-credentials.js +0 -124
  105. package/bin/agent-deployment.js +0 -96
  106. package/bin/agent-http.js +0 -45
  107. package/bin/agent-setup-config.js +0 -141
  108. package/bin/agent-setup.js +0 -146
  109. package/bin/agent.js +0 -42
  110. package/bin/analytics/client.js +0 -60
  111. package/bin/analytics/dates.js +0 -6
  112. package/bin/analytics/filters.js +0 -27
  113. package/bin/analytics/format.js +0 -13
  114. package/bin/analytics/index.js +0 -496
  115. package/bin/analytics/output.js +0 -75
  116. package/bin/analytics/types.js +0 -1
  117. package/bin/authenticatedFetch.js +0 -46
  118. package/bin/brokenLinks.js +0 -122
  119. package/bin/callbackServer.js +0 -65
  120. package/bin/cli.js +0 -813
  121. package/bin/comingSoon.js +0 -26
  122. package/bin/config.js +0 -78
  123. package/bin/constants.js +0 -16
  124. package/bin/deploy-base.js +0 -20
  125. package/bin/deploy-github-actions.js +0 -102
  126. package/bin/deploy-github-setup.js +0 -165
  127. package/bin/deploy-instructions.js +0 -71
  128. package/bin/deploy.js +0 -123
  129. package/bin/feedback.js +0 -36
  130. package/bin/format.js +0 -121
  131. package/bin/helpers.js +0 -238
  132. package/bin/idToken.js +0 -14
  133. package/bin/index.js +0 -102
  134. package/bin/init.js +0 -182
  135. package/bin/instructions.js +0 -101
  136. package/bin/keyring.js +0 -78
  137. package/bin/login.js +0 -123
  138. package/bin/logout.js +0 -18
  139. package/bin/mdxAccessibility.js +0 -113
  140. package/bin/mdxLinter.js +0 -55
  141. package/bin/middlewares/subdomainMiddleware.js +0 -28
  142. package/bin/middlewares/telemetryMiddleware.js +0 -61
  143. package/bin/migrate.js +0 -54
  144. package/bin/og.js +0 -145
  145. package/bin/openApiCheck.js +0 -99
  146. package/bin/resolveFiles.js +0 -114
  147. package/bin/score/client.js +0 -40
  148. package/bin/score/index.js +0 -211
  149. package/bin/score/types.js +0 -1
  150. package/bin/signup.js +0 -118
  151. package/bin/start.js +0 -36
  152. package/bin/status.js +0 -106
  153. package/bin/telemetry/client.js +0 -53
  154. package/bin/telemetry/distinctId.js +0 -68
  155. package/bin/telemetry/sessionId.js +0 -36
  156. package/bin/telemetry/track.js +0 -149
  157. package/bin/templates.js +0 -127
  158. package/bin/tokenRefresh.js +0 -50
  159. package/bin/tsconfig.build.tsbuildinfo +0 -1
  160. package/bin/update.js +0 -65
  161. package/bin/validate/command.js +0 -127
  162. package/bin/validate/engine.js +0 -154
  163. package/bin/validate/files.js +0 -163
  164. package/bin/validate/mdx.js +0 -238
  165. package/bin/validate/output.js +0 -44
  166. package/bin/validate/report.js +0 -11
  167. package/bin/validate/rules/build.js +0 -102
  168. package/bin/validate/rules/content/duplicateH1.js +0 -57
  169. package/bin/validate/rules/content/foreignSyntax.js +0 -120
  170. package/bin/validate/rules/content/katex.js +0 -34
  171. package/bin/validate/rules/content/missingSnippet.js +0 -34
  172. package/bin/validate/rules/content/undefinedVariable.js +0 -13
  173. package/bin/validate/rules/content/unknownComponent.js +0 -121
  174. package/bin/validate/rules/content/voidTags.js +0 -38
  175. package/bin/validate/rules/index.js +0 -21
  176. package/bin/validate/rules/openapi.js +0 -50
  177. package/bin/validate/rules/parseError.js +0 -7
  178. package/bin/validate/site.js +0 -57
  179. package/bin/validate/types.js +0 -1
  180. package/bin/vendor/converter.js +0 -30882
  181. package/bin/welcome.js +0 -108
  182. package/bin/workflows/client.js +0 -34
  183. package/bin/workflows/index.js +0 -269
  184. package/bin/workflows/types.js +0 -11
  185. package/scripts/bundle-converter.mjs +0 -26
  186. package/scripts/generate-logo.mjs +0 -79
  187. package/src/accessibility.ts +0 -180
  188. package/src/accessibilityCheck.tsx +0 -150
  189. package/src/addDomain.tsx +0 -206
  190. package/src/agent-auth.ts +0 -119
  191. package/src/agent-claim.ts +0 -124
  192. package/src/agent-credentials.ts +0 -104
  193. package/src/agent-deployment.ts +0 -116
  194. package/src/agent-http.ts +0 -34
  195. package/src/agent-setup-config.ts +0 -144
  196. package/src/agent-setup.ts +0 -165
  197. package/src/agent.ts +0 -56
  198. package/src/analytics/client.ts +0 -153
  199. package/src/analytics/dates.ts +0 -6
  200. package/src/analytics/filters.ts +0 -50
  201. package/src/analytics/format.ts +0 -13
  202. package/src/analytics/index.tsx +0 -599
  203. package/src/analytics/output.ts +0 -99
  204. package/src/analytics/types.ts +0 -145
  205. package/src/authenticatedFetch.ts +0 -42
  206. package/src/brokenLinks.tsx +0 -152
  207. package/src/callbackServer.ts +0 -64
  208. package/src/cli.tsx +0 -1105
  209. package/src/comingSoon.tsx +0 -29
  210. package/src/config.ts +0 -75
  211. package/src/constants.ts +0 -28
  212. package/src/deploy-base.ts +0 -18
  213. package/src/deploy-github-actions.ts +0 -139
  214. package/src/deploy-github-setup.ts +0 -189
  215. package/src/deploy-instructions.ts +0 -76
  216. package/src/deploy.ts +0 -165
  217. package/src/feedback.tsx +0 -31
  218. package/src/format.tsx +0 -82
  219. package/src/helpers.tsx +0 -279
  220. package/src/idToken.ts +0 -17
  221. package/src/index.ts +0 -109
  222. package/src/init.tsx +0 -237
  223. package/src/instructions.ts +0 -99
  224. package/src/keyring.ts +0 -65
  225. package/src/login.tsx +0 -166
  226. package/src/logout.tsx +0 -8
  227. package/src/mdxAccessibility.ts +0 -134
  228. package/src/mdxLinter.tsx +0 -88
  229. package/src/middlewares/subdomainMiddleware.ts +0 -20
  230. package/src/middlewares/telemetryMiddleware.ts +0 -55
  231. package/src/migrate.ts +0 -76
  232. package/src/og.tsx +0 -185
  233. package/src/openApiCheck.tsx +0 -125
  234. package/src/resolveFiles.ts +0 -101
  235. package/src/score/client.ts +0 -36
  236. package/src/score/index.tsx +0 -205
  237. package/src/score/types.ts +0 -15
  238. package/src/signup.tsx +0 -172
  239. package/src/start.ts +0 -27
  240. package/src/status.tsx +0 -129
  241. package/src/telemetry/client.ts +0 -46
  242. package/src/telemetry/distinctId.ts +0 -70
  243. package/src/telemetry/sessionId.ts +0 -40
  244. package/src/telemetry/track.ts +0 -163
  245. package/src/templates.tsx +0 -143
  246. package/src/tokenRefresh.ts +0 -53
  247. package/src/update.tsx +0 -89
  248. package/src/validate/command.tsx +0 -135
  249. package/src/validate/engine.ts +0 -210
  250. package/src/validate/files.ts +0 -249
  251. package/src/validate/mdx.ts +0 -290
  252. package/src/validate/output.tsx +0 -76
  253. package/src/validate/report.ts +0 -40
  254. package/src/validate/rules/build.ts +0 -146
  255. package/src/validate/rules/content/duplicateH1.ts +0 -78
  256. package/src/validate/rules/content/foreignSyntax.ts +0 -144
  257. package/src/validate/rules/content/katex.ts +0 -33
  258. package/src/validate/rules/content/missingSnippet.ts +0 -36
  259. package/src/validate/rules/content/undefinedVariable.ts +0 -20
  260. package/src/validate/rules/content/unknownComponent.ts +0 -130
  261. package/src/validate/rules/content/voidTags.ts +0 -43
  262. package/src/validate/rules/index.ts +0 -23
  263. package/src/validate/rules/openapi.ts +0 -59
  264. package/src/validate/rules/parseError.ts +0 -9
  265. package/src/validate/site.ts +0 -53
  266. package/src/validate/types.ts +0 -102
  267. package/src/vendor/converter.ts +0 -1
  268. package/src/welcome.ts +0 -154
  269. package/src/workflows/client.ts +0 -39
  270. package/src/workflows/index.tsx +0 -287
  271. package/src/workflows/types.ts +0 -73
  272. package/tsconfig.build.json +0 -4
  273. package/tsconfig.json +0 -10
  274. 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
- });