@mintlify/cli 4.0.1479 → 4.0.1481

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.
@@ -0,0 +1,66 @@
1
+ import fs from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
+
6
+ import { formatHandler } from '../src/format.js';
7
+ import { terminate } from '../src/helpers.js';
8
+
9
+ const fixture = vi.hoisted(() => ({ directory: '' }));
10
+
11
+ vi.mock('../src/helpers.js', () => ({
12
+ get CMD_EXEC_PATH() {
13
+ return fixture.directory;
14
+ },
15
+ terminate: vi.fn(),
16
+ }));
17
+
18
+ vi.mock('@mintlify/prebuild', () => ({ getMintIgnore: vi.fn(async () => []) }));
19
+ vi.mock('@mintlify/previewing', () => ({
20
+ addLog: vi.fn(),
21
+ ErrorLog: () => null,
22
+ SuccessLog: () => null,
23
+ }));
24
+
25
+ beforeEach(async () => {
26
+ vi.clearAllMocks();
27
+ fixture.directory = await fs.mkdtemp(path.join(os.tmpdir(), 'mint-format-math-'));
28
+ });
29
+
30
+ afterEach(async () => {
31
+ vi.restoreAllMocks();
32
+ await fs.rm(fixture.directory, { recursive: true, force: true });
33
+ });
34
+
35
+ describe('formatHandler math and currency', () => {
36
+ it.each([
37
+ ['single-dollar math', 'The formula is $x$ in text', 'The formula is $$x$$ in text'],
38
+ [
39
+ 'paired currency dollars',
40
+ 'Savings are $1 today ($5 tomorrow).',
41
+ 'Savings are $$1 today ($$5 tomorrow).',
42
+ ],
43
+ ['literal currency', 'Savings are $1 today.', 'Savings are \\$1 today.'],
44
+ [
45
+ 'escaped currency',
46
+ 'Savings are \\$1 today (\\$5 tomorrow).',
47
+ 'Savings are \\$1 today (\\$5 tomorrow).',
48
+ ],
49
+ ['double-dollar math', 'The formula is $$x$$ in text', 'The formula is $$x$$ in text'],
50
+ ])('preserves %s and produces stable output', async (_label, source, expected) => {
51
+ const file = path.join(fixture.directory, 'page.mdx');
52
+ await fs.writeFile(file, source);
53
+ const writeFile = vi.spyOn(fs, 'writeFile');
54
+
55
+ await formatHandler();
56
+
57
+ expect(terminate).toHaveBeenLastCalledWith(0);
58
+ expect(await fs.readFile(file, 'utf8')).toBe(`${expected}\n`);
59
+ writeFile.mockClear();
60
+
61
+ await formatHandler();
62
+
63
+ expect(terminate).toHaveBeenLastCalledWith(0);
64
+ expect(writeFile).not.toHaveBeenCalled();
65
+ });
66
+ });
package/bin/format.js CHANGED
@@ -88,7 +88,7 @@ export const formatHandler = () => __awaiter(void 0, void 0, void 0, function* (
88
88
  let formatted = raw;
89
89
  let originalFrontmatterKeys = 0;
90
90
  for (let pass = 0; pass < 3; pass++) {
91
- const { doc, frontmatter } = mdxToPm(formatted, { singleDollarTextMath: false });
91
+ const { doc, frontmatter } = mdxToPm(formatted);
92
92
  if (pass === 0)
93
93
  originalFrontmatterKeys = Object.keys(frontmatter).length;
94
94
  const next = `${pmToMdx(doc, Object.assign({ frontmatter }, canonicalPmToMdxOptions))}\n`;