@mintlify/previewing 4.0.1664 → 4.0.1666
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__/export-archive.test.d.ts +1 -0
- package/dist/__tests__/export-archive.test.js +53 -0
- 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/export-archive.d.ts +9 -0
- package/dist/local-preview/export-archive.js +51 -0
- package/dist/local-preview/export.js +12 -5
- 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 +10 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import AdmZip from 'adm-zip';
|
|
2
|
+
import fse from 'fs-extra';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { writeZipArchive } from '../local-preview/export-archive.js';
|
|
6
|
+
describe('writeZipArchive', () => {
|
|
7
|
+
let workDir;
|
|
8
|
+
let sourceDir;
|
|
9
|
+
let outputPath;
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
workDir = await fse.mkdtemp(path.join(os.tmpdir(), 'export-archive-test-'));
|
|
12
|
+
sourceDir = path.join(workDir, 'site');
|
|
13
|
+
outputPath = path.join(workDir, 'export.zip');
|
|
14
|
+
await fse.ensureDir(sourceDir);
|
|
15
|
+
});
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
await fse.remove(workDir);
|
|
18
|
+
});
|
|
19
|
+
it('archives nested files with forward-slash entry names', async () => {
|
|
20
|
+
await fse.outputFile(path.join(sourceDir, 'index.html'), '<h1>Home</h1>');
|
|
21
|
+
await fse.outputFile(path.join(sourceDir, 'ja', 'soc', 'page', 'index.html'), '<h1>ページ</h1>');
|
|
22
|
+
await fse.outputFile(path.join(sourceDir, '_next', 'static', 'app.js'), 'console.log(1);');
|
|
23
|
+
await writeZipArchive(sourceDir, outputPath);
|
|
24
|
+
const zip = new AdmZip(outputPath);
|
|
25
|
+
const names = zip
|
|
26
|
+
.getEntries()
|
|
27
|
+
.map((entry) => entry.entryName)
|
|
28
|
+
.sort();
|
|
29
|
+
expect(names).toEqual(['_next/static/app.js', 'index.html', 'ja/soc/page/index.html']);
|
|
30
|
+
expect(zip.readAsText('ja/soc/page/index.html')).toBe('<h1>ページ</h1>');
|
|
31
|
+
expect(await fse.pathExists(`${outputPath}.partial`)).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
it.skipIf(process.platform === 'win32')('preserves the executable bit', async () => {
|
|
34
|
+
const script = path.join(sourceDir, 'Start Docs.command');
|
|
35
|
+
await fse.outputFile(script, '#!/bin/sh\n');
|
|
36
|
+
await fse.chmod(script, 0o755);
|
|
37
|
+
await writeZipArchive(sourceDir, outputPath);
|
|
38
|
+
const [entry] = new AdmZip(outputPath).getEntries();
|
|
39
|
+
expect((entry.header.attr >>> 16) & 0o777).toBe(0o755);
|
|
40
|
+
});
|
|
41
|
+
it('creates missing parent directories for the output path', async () => {
|
|
42
|
+
await fse.outputFile(path.join(sourceDir, 'index.html'), '<h1>Home</h1>');
|
|
43
|
+
const nestedOutput = path.join(workDir, 'dist', 'nested', 'docs.zip');
|
|
44
|
+
await writeZipArchive(sourceDir, nestedOutput);
|
|
45
|
+
expect(new AdmZip(nestedOutput).readAsText('index.html')).toBe('<h1>Home</h1>');
|
|
46
|
+
});
|
|
47
|
+
it('leaves an existing archive untouched when archiving fails', async () => {
|
|
48
|
+
await fse.outputFile(outputPath, 'previous export');
|
|
49
|
+
await expect(writeZipArchive(path.join(workDir, 'missing'), outputPath)).rejects.toThrow();
|
|
50
|
+
expect(await fse.readFile(outputPath, 'utf8')).toBe('previous export');
|
|
51
|
+
expect(await fse.pathExists(`${outputPath}.partial`)).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streams every file under `sourceDir` into a zip at `outputPath`.
|
|
3
|
+
*
|
|
4
|
+
* The archive is written to disk as it is built, so its size isn't bounded by memory or by
|
|
5
|
+
* Node's 2 GiB Buffer limit, and yazl switches to ZIP64 once the archive needs it. Output goes
|
|
6
|
+
* to a `.partial` file that is renamed into place on success, so a failed run never leaves a
|
|
7
|
+
* truncated archive at `outputPath` or clobbers an existing one.
|
|
8
|
+
*/
|
|
9
|
+
export declare function writeZipArchive(sourceDir: string, outputPath: string): Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fse from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { pipeline } from 'stream/promises';
|
|
4
|
+
import yazl from 'yazl';
|
|
5
|
+
async function collectEntries(sourceDir) {
|
|
6
|
+
const entries = [];
|
|
7
|
+
async function walk(dir) {
|
|
8
|
+
const dirents = await fse.readdir(dir, { withFileTypes: true });
|
|
9
|
+
for (const dirent of dirents) {
|
|
10
|
+
const filePath = path.join(dir, dirent.name);
|
|
11
|
+
if (dirent.isDirectory()) {
|
|
12
|
+
await walk(filePath);
|
|
13
|
+
}
|
|
14
|
+
else if (dirent.isFile()) {
|
|
15
|
+
const { mode, mtime } = await fse.stat(filePath);
|
|
16
|
+
const entryName = path.relative(sourceDir, filePath).split(path.sep).join('/');
|
|
17
|
+
entries.push({ filePath, entryName, mode, mtime });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
await walk(sourceDir);
|
|
22
|
+
return entries.sort((a, b) => a.entryName.localeCompare(b.entryName));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Streams every file under `sourceDir` into a zip at `outputPath`.
|
|
26
|
+
*
|
|
27
|
+
* The archive is written to disk as it is built, so its size isn't bounded by memory or by
|
|
28
|
+
* Node's 2 GiB Buffer limit, and yazl switches to ZIP64 once the archive needs it. Output goes
|
|
29
|
+
* to a `.partial` file that is renamed into place on success, so a failed run never leaves a
|
|
30
|
+
* truncated archive at `outputPath` or clobbers an existing one.
|
|
31
|
+
*/
|
|
32
|
+
export async function writeZipArchive(sourceDir, outputPath) {
|
|
33
|
+
const entries = await collectEntries(sourceDir);
|
|
34
|
+
const partialPath = `${outputPath}.partial`;
|
|
35
|
+
await fse.ensureDir(path.dirname(outputPath));
|
|
36
|
+
const zip = new yazl.ZipFile();
|
|
37
|
+
const zipError = new Promise((_, reject) => zip.once('error', reject));
|
|
38
|
+
const written = pipeline(zip.outputStream, fse.createWriteStream(partialPath));
|
|
39
|
+
try {
|
|
40
|
+
for (const { filePath, entryName, mode, mtime } of entries) {
|
|
41
|
+
zip.addFile(filePath, entryName, { mode, mtime });
|
|
42
|
+
}
|
|
43
|
+
zip.end();
|
|
44
|
+
await Promise.race([written, zipError]);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
await fse.remove(partialPath);
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
await fse.move(partialPath, outputPath, { overwrite: true });
|
|
51
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { getAllPathsInDecoratedNav, getAllPathsInDocsNav } from '@mintlify/common';
|
|
3
3
|
import { prebuild } from '@mintlify/prebuild';
|
|
4
|
-
import AdmZip from 'adm-zip';
|
|
5
4
|
import fse, { pathExists } from 'fs-extra';
|
|
6
5
|
import os from 'os';
|
|
7
6
|
import path from 'path';
|
|
@@ -9,6 +8,7 @@ import { fileURLToPath } from 'url';
|
|
|
9
8
|
import { CMD_EXEC_PATH, CONTENT_PATH, VERSION_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, PREVIEW_PATH, configureSharedPreviewPath, } from '../constants.js';
|
|
10
9
|
import { addLog, clearLogs } from '../logging-state.js';
|
|
11
10
|
import { ErrorLog, SpinnerLog, SuccessLog, WarningLog } from '../logs.js';
|
|
11
|
+
import { writeZipArchive } from './export-archive.js';
|
|
12
12
|
import { localizeAssets } from './export-assets.js';
|
|
13
13
|
import { findBasePathConflict, normalizeExportBasePath } from './export-base-path.js';
|
|
14
14
|
import { generateExportLlmsTxt } from './export-llms.js';
|
|
@@ -126,6 +126,7 @@ async function generateExportArchive(routes, outputPath, groups, basePath, vite)
|
|
|
126
126
|
const { routes: preparedRoutes, rootRoute } = prepareRoutesForExport(routes, groups);
|
|
127
127
|
const routesToGenerate = withIndexRouteAliases(preparedRoutes);
|
|
128
128
|
let tmpDir;
|
|
129
|
+
let keepExportDir = false;
|
|
129
130
|
try {
|
|
130
131
|
clearLogs();
|
|
131
132
|
addLog(_jsx(SpinnerLog, { message: `generating ${routesToGenerate.length} pages...` }));
|
|
@@ -153,9 +154,15 @@ async function generateExportArchive(routes, outputPath, groups, basePath, vite)
|
|
|
153
154
|
});
|
|
154
155
|
const failed = [...clientAssetFailures, ...assetFailures];
|
|
155
156
|
addLog(_jsx(SpinnerLog, { message: "creating zip archive..." }));
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
try {
|
|
158
|
+
await writeZipArchive(exportDir, outputPath);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
// Rendering a large site can take an hour, so keep the output rather than discard it.
|
|
162
|
+
keepExportDir = true;
|
|
163
|
+
const reason = err instanceof Error ? err.message : 'unknown error';
|
|
164
|
+
throw new Error(`failed to create zip archive: ${reason}. The rendered site was kept at ${exportDir}`);
|
|
165
|
+
}
|
|
159
166
|
clearLogs();
|
|
160
167
|
for (const url of failed) {
|
|
161
168
|
addLog(_jsx(WarningLog, { message: `could not bundle ${url}` }));
|
|
@@ -163,7 +170,7 @@ async function generateExportArchive(routes, outputPath, groups, basePath, vite)
|
|
|
163
170
|
addLog(_jsx(SuccessLog, { message: `exported to ${outputPath}` }));
|
|
164
171
|
}
|
|
165
172
|
finally {
|
|
166
|
-
if (tmpDir) {
|
|
173
|
+
if (tmpDir && !keepExportDir) {
|
|
167
174
|
await fse.remove(tmpDir);
|
|
168
175
|
}
|
|
169
176
|
await renderer.close();
|
|
@@ -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) {
|