@mintlify/previewing 4.0.1663 → 4.0.1665
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/__tests__/listener-batching.test.js +11 -13
- package/dist/__tests__/listener-graphql-packages.test.js +9 -11
- package/dist/__tests__/listener-package-manifest.test.js +9 -11
- package/dist/__tests__/page-metadata-cache.test.js +17 -1
- package/dist/__tests__/watcher-native.test.d.ts +1 -0
- package/dist/__tests__/watcher-native.test.js +61 -0
- package/dist/__tests__/watcher.test.d.ts +1 -0
- package/dist/__tests__/watcher.test.js +237 -0
- package/dist/local-preview/listener/index.js +7 -10
- package/dist/local-preview/listener/page-metadata-cache.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/watcher.d.ts +14 -0
- package/dist/watcher.js +267 -0
- package/package.json +7 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fse from 'fs-extra';
|
|
2
2
|
import { mkdir, rm, writeFile } from 'fs/promises';
|
|
3
|
-
import { join } from 'path';
|
|
3
|
+
import { join, normalize } from 'path';
|
|
4
4
|
import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH } from '../constants.js';
|
|
5
5
|
import listener, { initializeDocsConfigHashCache, initializeFrontmatterHashCache, } from '../local-preview/listener/index.js';
|
|
6
6
|
import { updateGeneratedNavFromPageMetadataCache } from '../local-preview/listener/update.js';
|
|
@@ -23,18 +23,16 @@ vi.mock('../constants.js', async (importOriginal) => {
|
|
|
23
23
|
NEXT_PUBLIC_PATH: join(root, 'client', 'public'),
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
|
-
vi.mock('
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
close: async () => { }
|
|
34
|
-
}
|
|
35
|
-
return instance;
|
|
26
|
+
vi.mock('../watcher.js', async () => {
|
|
27
|
+
const { join } = await import('path');
|
|
28
|
+
return {
|
|
29
|
+
watchTree: async (root, options) => {
|
|
30
|
+
for (const type of ['add', 'change', 'unlink']) {
|
|
31
|
+
watcher.handlers[type] = (filename) => options.onEvent(type, join(root, filename));
|
|
32
|
+
}
|
|
33
|
+
return { close: async () => { } };
|
|
34
|
+
},
|
|
36
35
|
};
|
|
37
|
-
return { default: { watch }, watch };
|
|
38
36
|
});
|
|
39
37
|
vi.mock('@mintlify/prebuild', async (importOriginal) => {
|
|
40
38
|
const actual = await importOriginal();
|
|
@@ -62,7 +60,7 @@ const startWatcher = async () => {
|
|
|
62
60
|
await vi.waitFor(() => expect(watcher.handlers.change).toBeDefined());
|
|
63
61
|
};
|
|
64
62
|
const emit = (event, filename) => watcher.handlers[event](filename);
|
|
65
|
-
const loggedFor = (filename) => addChangeLogSpy.mock.calls.filter(([log]) => log.props?.filename === filename);
|
|
63
|
+
const loggedFor = (filename) => addChangeLogSpy.mock.calls.filter(([log]) => log.props?.filename === normalize(filename));
|
|
66
64
|
const writeDocsFile = async (filename, content) => {
|
|
67
65
|
await mkdir(join(CMD_EXEC_PATH, filename, '..'), { recursive: true });
|
|
68
66
|
await writeFile(join(CMD_EXEC_PATH, filename), content);
|
|
@@ -21,18 +21,16 @@ vi.mock('../constants.js', async (importOriginal) => {
|
|
|
21
21
|
NEXT_PUBLIC_PATH: join(root, 'client', 'public'),
|
|
22
22
|
};
|
|
23
23
|
});
|
|
24
|
-
vi.mock('
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
close: async () => { }
|
|
32
|
-
}
|
|
33
|
-
return instance;
|
|
24
|
+
vi.mock('../watcher.js', async () => {
|
|
25
|
+
const { join } = await import('path');
|
|
26
|
+
return {
|
|
27
|
+
watchTree: async (root, options) => {
|
|
28
|
+
for (const type of ['add', 'change', 'unlink']) {
|
|
29
|
+
watcher.handlers[type] = (filename) => options.onEvent(type, join(root, filename));
|
|
30
|
+
}
|
|
31
|
+
return { close: async () => { } };
|
|
32
|
+
},
|
|
34
33
|
};
|
|
35
|
-
return { default: { watch }, watch };
|
|
36
34
|
});
|
|
37
35
|
vi.mock('@mintlify/prebuild', async (importOriginal) => {
|
|
38
36
|
const actual = await importOriginal();
|
|
@@ -23,18 +23,16 @@ vi.mock('../constants.js', async (importOriginal) => {
|
|
|
23
23
|
NEXT_PUBLIC_PATH: join(root, 'client', 'public'),
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
|
-
vi.mock('
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
close: async () => { }
|
|
34
|
-
}
|
|
35
|
-
return instance;
|
|
26
|
+
vi.mock('../watcher.js', async () => {
|
|
27
|
+
const { join } = await import('path');
|
|
28
|
+
return {
|
|
29
|
+
watchTree: async (root, options) => {
|
|
30
|
+
for (const type of ['add', 'change', 'unlink']) {
|
|
31
|
+
watcher.handlers[type] = (filename) => options.onEvent(type, join(root, filename));
|
|
32
|
+
}
|
|
33
|
+
return { close: async () => { } };
|
|
34
|
+
},
|
|
36
35
|
};
|
|
37
|
-
return { default: { watch }, watch };
|
|
38
36
|
});
|
|
39
37
|
vi.mock('@mintlify/common', async (importOriginal) => {
|
|
40
38
|
const actual = await importOriginal();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
-
import { clearPageMetadataCache, ensurePageMetadataCacheForDocsConfig, generateDocsNavFromPageMetadataCache, hydratePageMetadataCacheFromGeneratedNav, upsertPageMetadataCacheEntryForFile, } from '../local-preview/listener/page-metadata-cache.js';
|
|
2
|
+
import { clearPageMetadataCache, ensurePageMetadataCacheForDocsConfig, generateDocsNavFromPageMetadataCache, hydratePageMetadataCacheFromGeneratedNav, removePageMetadataCacheEntryForFile, upsertPageMetadataCacheEntryForFile, } from '../local-preview/listener/page-metadata-cache.js';
|
|
3
3
|
const createDocsConfig = (pages) => ({
|
|
4
4
|
$schema: 'https://mintlify.com/docs.json',
|
|
5
5
|
name: 'Mintlify',
|
|
@@ -28,6 +28,22 @@ describe('pageMetadataCache', () => {
|
|
|
28
28
|
],
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
|
+
it('writes a forward-slash href for a backslash filename', () => {
|
|
32
|
+
hydratePageMetadataCacheFromGeneratedNav({
|
|
33
|
+
pages: [{ title: 'Old', href: '/nav/a' }],
|
|
34
|
+
});
|
|
35
|
+
upsertPageMetadataCacheEntryForFile('nav\\a.mdx', '---\ntitle: New\n---\n');
|
|
36
|
+
expect(generateDocsNavFromPageMetadataCache(createDocsConfig(['nav/a']))).toMatchObject({
|
|
37
|
+
pages: [{ title: 'New', href: '/nav/a' }],
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
it('removes the entry for a backslash filename', () => {
|
|
41
|
+
upsertPageMetadataCacheEntryForFile('nav/a.mdx', '---\ntitle: New\n---\n');
|
|
42
|
+
removePageMetadataCacheEntryForFile('nav\\a.mdx');
|
|
43
|
+
expect(generateDocsNavFromPageMetadataCache(createDocsConfig(['nav/a']))).not.toMatchObject({
|
|
44
|
+
pages: [{ title: 'New' }],
|
|
45
|
+
});
|
|
46
|
+
});
|
|
31
47
|
it('reports when a page references an OpenAPI spec via frontmatter', () => {
|
|
32
48
|
expect(upsertPageMetadataCacheEntryForFile('plain.mdx', '---\ntitle: Plain\n---\n# Plain')).toBe(false);
|
|
33
49
|
expect(upsertPageMetadataCacheEntryForFile('endpoint.mdx', '---\nopenapi: GET /pets\n---')).toBe(true);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { watchTree } from '../watcher.js';
|
|
5
|
+
describe.runIf(['darwin', 'linux', 'win32'].includes(process.platform))('watchTree native watcher', () => {
|
|
6
|
+
let base;
|
|
7
|
+
let root;
|
|
8
|
+
let watcher;
|
|
9
|
+
let seen;
|
|
10
|
+
const onNativeUnavailable = vi.fn();
|
|
11
|
+
const expectSeen = (type, file) => vi.waitFor(() => expect(seen).toContainEqual([type, path.normalize(file)]), {
|
|
12
|
+
timeout: 5000,
|
|
13
|
+
});
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
base = await realpath(await mkdtemp(path.join(os.tmpdir(), 'mint-watcher-native-')));
|
|
16
|
+
root = path.join(base, 'root');
|
|
17
|
+
await mkdir(path.join(root, 'guide'), { recursive: true });
|
|
18
|
+
await mkdir(path.join(root, 'junk'));
|
|
19
|
+
await writeFile(path.join(root, 'a.mdx'), 'a');
|
|
20
|
+
await writeFile(path.join(root, 'guide', 'b.mdx'), 'b');
|
|
21
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
22
|
+
seen = [];
|
|
23
|
+
watcher = await watchTree(root, {
|
|
24
|
+
ignored: (file) => file.split(path.sep).includes('junk'),
|
|
25
|
+
onEvent: (type, file) => seen.push([type, path.relative(root, file)]),
|
|
26
|
+
onNativeUnavailable,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
afterEach(async () => {
|
|
30
|
+
await watcher?.close();
|
|
31
|
+
await rm(base, { recursive: true, force: true });
|
|
32
|
+
});
|
|
33
|
+
it('loads the native watcher', () => {
|
|
34
|
+
expect(onNativeUnavailable).not.toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
it('reports added, changed and removed files', async () => {
|
|
37
|
+
await writeFile(path.join(root, 'new.mdx'), 'new');
|
|
38
|
+
await expectSeen('add', 'new.mdx');
|
|
39
|
+
await writeFile(path.join(root, 'a.mdx'), 'changed');
|
|
40
|
+
await expectSeen('change', 'a.mdx');
|
|
41
|
+
await rm(path.join(root, 'a.mdx'));
|
|
42
|
+
await expectSeen('unlink', 'a.mdx');
|
|
43
|
+
});
|
|
44
|
+
it('reports an atomic save as a change', async () => {
|
|
45
|
+
await writeFile(path.join(base, 'staged'), 'saved');
|
|
46
|
+
await rename(path.join(base, 'staged'), path.join(root, 'a.mdx'));
|
|
47
|
+
await expectSeen('change', 'a.mdx');
|
|
48
|
+
expect(seen).not.toContainEqual(['add', 'a.mdx']);
|
|
49
|
+
});
|
|
50
|
+
it('reports files of a renamed directory', async () => {
|
|
51
|
+
await rename(path.join(root, 'guide'), path.join(root, 'guides'));
|
|
52
|
+
await expectSeen('unlink', 'guide/b.mdx');
|
|
53
|
+
await expectSeen('add', 'guides/b.mdx');
|
|
54
|
+
});
|
|
55
|
+
it('skips ignored paths', async () => {
|
|
56
|
+
await writeFile(path.join(root, 'junk', 'hidden.mdx'), 'hidden');
|
|
57
|
+
await writeFile(path.join(root, 'new.mdx'), 'new');
|
|
58
|
+
await expectSeen('add', 'new.mdx');
|
|
59
|
+
expect(seen).toEqual([['add', 'new.mdx']]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { watchTree } from '../watcher.js';
|
|
5
|
+
const native = vi.hoisted(() => ({
|
|
6
|
+
emit: undefined,
|
|
7
|
+
raise: undefined,
|
|
8
|
+
fail: false,
|
|
9
|
+
before: undefined,
|
|
10
|
+
ignore: [],
|
|
11
|
+
unsubscribe: vi.fn(async () => { }),
|
|
12
|
+
}));
|
|
13
|
+
vi.mock('@parcel/watcher', () => ({
|
|
14
|
+
default: {
|
|
15
|
+
subscribe: async (_root, callback, options) => {
|
|
16
|
+
if (native.fail)
|
|
17
|
+
throw new Error('No prebuild or local build of @parcel/watcher found.');
|
|
18
|
+
native.ignore.push(options.ignore);
|
|
19
|
+
await native.before?.();
|
|
20
|
+
native.emit = (events) => callback(null, events);
|
|
21
|
+
native.raise = (error) => callback(error, []);
|
|
22
|
+
return { unsubscribe: native.unsubscribe };
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}));
|
|
26
|
+
const platform = process.platform;
|
|
27
|
+
let base;
|
|
28
|
+
let root;
|
|
29
|
+
let watcher;
|
|
30
|
+
let seen;
|
|
31
|
+
const onNativeUnavailable = vi.fn();
|
|
32
|
+
const watch = async (options = {}) => {
|
|
33
|
+
const target = options.target ?? root;
|
|
34
|
+
watcher = await watchTree(target, {
|
|
35
|
+
followSymlinks: options.followSymlinks,
|
|
36
|
+
ignored: (file) => file.split(path.sep).includes('junk'),
|
|
37
|
+
onEvent: (type, file) => seen.push([type, path.relative(target, file)]),
|
|
38
|
+
onNativeUnavailable,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const emit = (...events) => native.emit?.(events.map(([type, file]) => ({ type, path: path.join(root, file) })));
|
|
42
|
+
const expectSeen = (expected) => vi.waitFor(() => expect([...seen].sort()).toEqual([...expected].sort()), { timeout: 5000 });
|
|
43
|
+
beforeAll(() => {
|
|
44
|
+
Object.defineProperty(process, 'platform', { value: 'darwin' });
|
|
45
|
+
});
|
|
46
|
+
afterAll(() => {
|
|
47
|
+
Object.defineProperty(process, 'platform', { value: platform });
|
|
48
|
+
});
|
|
49
|
+
beforeEach(async () => {
|
|
50
|
+
base = await realpath(await mkdtemp(path.join(os.tmpdir(), 'mint-watcher-')));
|
|
51
|
+
root = path.join(base, 'root');
|
|
52
|
+
await mkdir(path.join(root, 'junk'), { recursive: true });
|
|
53
|
+
await mkdir(path.join(base, 'outside', 'nested'), { recursive: true });
|
|
54
|
+
await writeFile(path.join(root, 'a.mdx'), 'a');
|
|
55
|
+
await writeFile(path.join(root, 'junk', 'hidden.mdx'), 'hidden');
|
|
56
|
+
await writeFile(path.join(base, 'outside', 'x.mdx'), 'x');
|
|
57
|
+
await writeFile(path.join(base, 'outside', 'nested', 'y.mdx'), 'y');
|
|
58
|
+
seen = [];
|
|
59
|
+
native.emit = undefined;
|
|
60
|
+
native.fail = false;
|
|
61
|
+
native.before = undefined;
|
|
62
|
+
native.ignore = [];
|
|
63
|
+
vi.clearAllMocks();
|
|
64
|
+
});
|
|
65
|
+
afterEach(async () => {
|
|
66
|
+
await watcher?.close();
|
|
67
|
+
watcher = undefined;
|
|
68
|
+
vi.unstubAllEnvs();
|
|
69
|
+
await rm(base, { recursive: true, force: true });
|
|
70
|
+
});
|
|
71
|
+
describe('watchTree native backend', () => {
|
|
72
|
+
it('reports new files as add and known files as change', async () => {
|
|
73
|
+
await watch();
|
|
74
|
+
await writeFile(path.join(root, 'b.mdx'), 'b');
|
|
75
|
+
emit(['create', 'b.mdx'], ['create', 'a.mdx']);
|
|
76
|
+
await expectSeen([
|
|
77
|
+
['add', 'b.mdx'],
|
|
78
|
+
['change', 'a.mdx'],
|
|
79
|
+
]);
|
|
80
|
+
seen = [];
|
|
81
|
+
emit(['update', 'b.mdx']);
|
|
82
|
+
await expectSeen([['change', 'b.mdx']]);
|
|
83
|
+
});
|
|
84
|
+
it('reports unlink for removed files and ignores unknown paths', async () => {
|
|
85
|
+
await watch();
|
|
86
|
+
await rm(path.join(root, 'a.mdx'));
|
|
87
|
+
emit(['delete', '.a.mdx.tmp'], ['delete', 'a.mdx']);
|
|
88
|
+
await expectSeen([['unlink', 'a.mdx']]);
|
|
89
|
+
});
|
|
90
|
+
it('reports a file removed and recreated in separate batches as a change', async () => {
|
|
91
|
+
await watch();
|
|
92
|
+
emit(['delete', 'a.mdx']);
|
|
93
|
+
emit(['create', 'a.mdx']);
|
|
94
|
+
await expectSeen([['change', 'a.mdx']]);
|
|
95
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
96
|
+
expect(seen).toEqual([['change', 'a.mdx']]);
|
|
97
|
+
});
|
|
98
|
+
it('reports every file of a directory moved in or out', async () => {
|
|
99
|
+
await watch();
|
|
100
|
+
await rename(path.join(base, 'outside'), path.join(root, 'moved'));
|
|
101
|
+
emit(['create', 'moved']);
|
|
102
|
+
const files = ['moved/x.mdx', 'moved/nested/y.mdx'].map((file) => path.normalize(file));
|
|
103
|
+
await expectSeen(files.map((file) => ['add', file]));
|
|
104
|
+
seen = [];
|
|
105
|
+
await rename(path.join(root, 'moved'), path.join(base, 'outside'));
|
|
106
|
+
emit(['delete', 'moved']);
|
|
107
|
+
await expectSeen(files.map((file) => ['unlink', file]));
|
|
108
|
+
});
|
|
109
|
+
it('reports a file once when its new directory is scanned in the same batch', async () => {
|
|
110
|
+
await watch();
|
|
111
|
+
await mkdir(path.join(root, 'fresh'));
|
|
112
|
+
await writeFile(path.join(root, 'fresh', 'f.mdx'), 'f');
|
|
113
|
+
emit(['create', 'fresh'], ['create', path.join('fresh', 'f.mdx')]);
|
|
114
|
+
await writeFile(path.join(root, 'last.mdx'), 'last');
|
|
115
|
+
emit(['create', 'last.mdx']);
|
|
116
|
+
await expectSeen([
|
|
117
|
+
['add', path.join('fresh', 'f.mdx')],
|
|
118
|
+
['add', 'last.mdx'],
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
it('skips ignored paths', async () => {
|
|
122
|
+
await watch();
|
|
123
|
+
await writeFile(path.join(root, 'junk', 'new.mdx'), 'new');
|
|
124
|
+
await writeFile(path.join(root, 'b.mdx'), 'b');
|
|
125
|
+
emit(['update', path.join('junk', 'hidden.mdx')], ['create', path.join('junk', 'new.mdx')], ['create', 'b.mdx']);
|
|
126
|
+
await expectSeen([['add', 'b.mdx']]);
|
|
127
|
+
});
|
|
128
|
+
it('reports paths under the watched root when it is a symlink', async () => {
|
|
129
|
+
const alias = path.join(base, 'alias');
|
|
130
|
+
await symlink(root, alias, 'dir');
|
|
131
|
+
await watch({ target: alias });
|
|
132
|
+
await writeFile(path.join(root, 'b.mdx'), 'b');
|
|
133
|
+
emit(['create', 'b.mdx']);
|
|
134
|
+
await expectSeen([['add', 'b.mdx']]);
|
|
135
|
+
});
|
|
136
|
+
it('skips symlinks when not following them', async () => {
|
|
137
|
+
await symlink(path.join(base, 'outside'), path.join(root, 'link'), 'dir');
|
|
138
|
+
await watch({ followSymlinks: false });
|
|
139
|
+
await writeFile(path.join(root, 'b.mdx'), 'b');
|
|
140
|
+
emit(['create', 'link'], ['create', 'b.mdx']);
|
|
141
|
+
await expectSeen([['add', 'b.mdx']]);
|
|
142
|
+
expect(native.unsubscribe).not.toHaveBeenCalled();
|
|
143
|
+
});
|
|
144
|
+
it('resubscribes when an ignored directory appears later', async () => {
|
|
145
|
+
await watch();
|
|
146
|
+
await mkdir(path.join(root, 'nested', 'junk'), { recursive: true });
|
|
147
|
+
emit(['create', 'nested']);
|
|
148
|
+
await vi.waitFor(() => expect(native.unsubscribe).toHaveBeenCalledTimes(1));
|
|
149
|
+
expect(native.ignore).toHaveLength(2);
|
|
150
|
+
expect(native.ignore[1]).toContain(path.join(root, 'nested', 'junk'));
|
|
151
|
+
await writeFile(path.join(root, 'b.mdx'), 'b');
|
|
152
|
+
emit(['create', 'b.mdx']);
|
|
153
|
+
await expectSeen([['add', 'b.mdx']]);
|
|
154
|
+
});
|
|
155
|
+
it('reports changes made between the scan and the subscription on Linux', async () => {
|
|
156
|
+
Object.defineProperty(process, 'platform', { value: 'linux' });
|
|
157
|
+
native.before = async () => {
|
|
158
|
+
await mkdir(path.join(root, 'late'));
|
|
159
|
+
await writeFile(path.join(root, 'late', 'l.mdx'), 'l');
|
|
160
|
+
await rm(path.join(root, 'a.mdx'));
|
|
161
|
+
};
|
|
162
|
+
try {
|
|
163
|
+
await watch();
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
Object.defineProperty(process, 'platform', { value: 'darwin' });
|
|
167
|
+
}
|
|
168
|
+
await expectSeen([
|
|
169
|
+
['add', path.join('late', 'l.mdx')],
|
|
170
|
+
['unlink', 'a.mdx'],
|
|
171
|
+
]);
|
|
172
|
+
seen = [];
|
|
173
|
+
await writeFile(path.join(root, 'late', 'm.mdx'), 'm');
|
|
174
|
+
emit(['create', path.join('late', 'm.mdx')]);
|
|
175
|
+
await expectSeen([['add', path.join('late', 'm.mdx')]]);
|
|
176
|
+
});
|
|
177
|
+
it('stops the native subscription on close', async () => {
|
|
178
|
+
await watch();
|
|
179
|
+
await watcher?.close();
|
|
180
|
+
expect(native.unsubscribe).toHaveBeenCalledTimes(1);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
describe('watchTree chokidar fallback', () => {
|
|
184
|
+
const expectChokidarEvent = async () => {
|
|
185
|
+
await writeFile(path.join(root, 'b.mdx'), 'b');
|
|
186
|
+
await vi.waitFor(() => expect(seen).toContainEqual(['add', 'b.mdx']), { timeout: 5000 });
|
|
187
|
+
};
|
|
188
|
+
it('is used when a followed symlink is present', async () => {
|
|
189
|
+
await symlink(path.join(base, 'outside'), path.join(root, 'link'), 'dir');
|
|
190
|
+
await watch();
|
|
191
|
+
expect(native.unsubscribe).toHaveBeenCalledTimes(1);
|
|
192
|
+
expect(onNativeUnavailable).not.toHaveBeenCalled();
|
|
193
|
+
await expectChokidarEvent();
|
|
194
|
+
});
|
|
195
|
+
it('takes over when a followed symlink appears later', async () => {
|
|
196
|
+
await watch();
|
|
197
|
+
await symlink(path.join(base, 'outside'), path.join(root, 'link'), 'dir');
|
|
198
|
+
emit(['create', 'link']);
|
|
199
|
+
await vi.waitFor(() => expect(native.unsubscribe).toHaveBeenCalledTimes(1));
|
|
200
|
+
await vi.waitFor(() => expect(seen).toEqual(expect.arrayContaining([
|
|
201
|
+
['add', path.join('link', 'x.mdx')],
|
|
202
|
+
['add', path.join('link', 'nested', 'y.mdx')],
|
|
203
|
+
])), { timeout: 5000 });
|
|
204
|
+
expect(seen).not.toContainEqual(['add', 'a.mdx']);
|
|
205
|
+
await expectChokidarEvent();
|
|
206
|
+
});
|
|
207
|
+
it('reports changes missed while switching', async () => {
|
|
208
|
+
await watch();
|
|
209
|
+
await writeFile(path.join(root, 'new.mdx'), 'new');
|
|
210
|
+
await rm(path.join(root, 'a.mdx'));
|
|
211
|
+
native.raise?.(new Error('Events were dropped.'));
|
|
212
|
+
await vi.waitFor(() => expect(seen).toEqual(expect.arrayContaining([
|
|
213
|
+
['add', 'new.mdx'],
|
|
214
|
+
['unlink', 'a.mdx'],
|
|
215
|
+
])), { timeout: 5000 });
|
|
216
|
+
});
|
|
217
|
+
it('is used and reported when the native watcher fails to start', async () => {
|
|
218
|
+
native.fail = true;
|
|
219
|
+
await watch();
|
|
220
|
+
expect(onNativeUnavailable).toHaveBeenCalledTimes(1);
|
|
221
|
+
await expectChokidarEvent();
|
|
222
|
+
});
|
|
223
|
+
it('takes over and is reported when the native watcher fails later', async () => {
|
|
224
|
+
await watch();
|
|
225
|
+
native.raise?.(new Error('Events were dropped.'));
|
|
226
|
+
await vi.waitFor(() => expect(native.unsubscribe).toHaveBeenCalledTimes(1));
|
|
227
|
+
expect(onNativeUnavailable).toHaveBeenCalledTimes(1);
|
|
228
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
229
|
+
await expectChokidarEvent();
|
|
230
|
+
});
|
|
231
|
+
it('is used when the native watcher is disabled', async () => {
|
|
232
|
+
vi.stubEnv('MINTLIFY_DISABLE_NATIVE_WATCHER', '1');
|
|
233
|
+
await watch();
|
|
234
|
+
expect(native.emit).toBeUndefined();
|
|
235
|
+
await expectChokidarEvent();
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -3,7 +3,6 @@ import { findAndRemoveImports, hasImports, getFileCategory, isPackageManifestPat
|
|
|
3
3
|
import { createPage, discoverOverlayFiles, getFileListSync, getMintIgnore, MintConfigUpdater, DocsConfigUpdater, preparseMdxTree, prebuild, } from '@mintlify/prebuild';
|
|
4
4
|
import { isOverlayDocument } from '@mintlify/validation';
|
|
5
5
|
import Chalk from 'chalk';
|
|
6
|
-
import chokidar from 'chokidar';
|
|
7
6
|
import { createHash } from 'crypto';
|
|
8
7
|
import { promises as _promises } from 'fs';
|
|
9
8
|
import fse from 'fs-extra';
|
|
@@ -13,6 +12,7 @@ import pathUtil from 'path';
|
|
|
13
12
|
import { CMD_EXEC_PATH, CONTENT_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH } from '../../constants.js';
|
|
14
13
|
import { addChangeLog, addErrorLog, clearErrorLogs, getCurrentErrorLogs, } from '../../logging-state.js';
|
|
15
14
|
import { AddedLog, DeletedLog, EditedLog, WarningLog, InfoLog, ErrorLog } from '../../logs.js';
|
|
15
|
+
import { watchTree } from '../../watcher.js';
|
|
16
16
|
import { reportPageCompileError, reportPageCompileSuccess } from '../on-demand-page.js';
|
|
17
17
|
import { notifyPackageInputChange, writePackageBuildProps } from '../packages/index.js';
|
|
18
18
|
import { clearDocsConfigCaches, getDocsConfigApiHash, getDocsConfigNavigationHash, getVariablesHash, hasDocsConfigApiChanged, hasDocsConfigNavigationChanged, hasNavigationApiReference, hadDocsConfigApiReference, hasDocsConfigVariablesChanged, updateDocsConfigHashCache, } from './docs-config-cache.js';
|
|
@@ -208,15 +208,12 @@ const startPreviewWatcher = (options) => {
|
|
|
208
208
|
await previous.close();
|
|
209
209
|
}
|
|
210
210
|
const isPreviewPathIgnored = createPreviewPathIgnored(CMD_EXEC_PATH, getMintIgnoreGlobs());
|
|
211
|
-
previewWatcher =
|
|
212
|
-
.watch(CMD_EXEC_PATH, {
|
|
213
|
-
ignoreInitial: true,
|
|
211
|
+
previewWatcher = await watchTree(CMD_EXEC_PATH, {
|
|
214
212
|
ignored: isPreviewPathIgnored,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
.on('unlink', (filename) => enqueueWatchEvent('unlink', filename));
|
|
213
|
+
onEvent: (type, file) => enqueueWatchEvent(type, pathUtil.relative(CMD_EXEC_PATH, file)),
|
|
214
|
+
onError: (error) => console.error(error.message),
|
|
215
|
+
onNativeUnavailable: (error) => addChangeLog(_jsx(WarningLog, { message: `native file watcher unavailable, using a slower fallback: ${error.message}` })),
|
|
216
|
+
});
|
|
220
217
|
});
|
|
221
218
|
return previewWatcherRestart;
|
|
222
219
|
};
|
|
@@ -224,7 +221,7 @@ const listener = (triggerRefresh, options = {}, gate) => {
|
|
|
224
221
|
watcherGate = gate;
|
|
225
222
|
activeTriggerRefresh = triggerRefresh;
|
|
226
223
|
const previewOptions = { ...options, allowSourceRefs: true };
|
|
227
|
-
|
|
224
|
+
startPreviewWatcher(previewOptions).catch((error) => console.error(error.message));
|
|
228
225
|
};
|
|
229
226
|
const processUpdateEvent = async (filename, triggerRefresh, options, log) => {
|
|
230
227
|
if (watcherGate) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAllPathsInDocsNav, getDecoratedNavPageAndSlug, optionallyRemoveLeadingSlash, optionallyRemoveTrailingSlash, } from '@mintlify/common';
|
|
1
|
+
import { getAllPathsInDocsNav, getDecoratedNavPageAndSlug, optionallyRemoveLeadingSlash, optionallyRemoveTrailingSlash, toPosixPath, } from '@mintlify/common';
|
|
2
2
|
import { generateDecoratedDocsNavigationFromPages } from '@mintlify/prebuild';
|
|
3
3
|
import { divisions } from '@mintlify/validation';
|
|
4
4
|
import fse from 'fs-extra';
|
|
@@ -64,7 +64,7 @@ export const removePageMetadataCacheEntry = (slug) => {
|
|
|
64
64
|
generatedPageMetadataSlugs.delete(slug);
|
|
65
65
|
};
|
|
66
66
|
export const removePageMetadataCacheEntryForFile = (filename) => {
|
|
67
|
-
removePageMetadataCacheEntry(filename.replace(/\.mdx?$/, ''));
|
|
67
|
+
removePageMetadataCacheEntry(toPosixPath(filename).replace(/\.mdx?$/, ''));
|
|
68
68
|
};
|
|
69
69
|
// Returns true when the page references an OpenAPI/AsyncAPI spec via frontmatter.
|
|
70
70
|
// Those titles are derived from the schema, which the cache (built without spec
|