@mintlify/previewing 4.0.1553 → 4.0.1555

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.
@@ -1,11 +1,10 @@
1
- import { getWarnings, prebuild } from '@mintlify/prebuild';
1
+ import { prebuild, StrictModeError } from '@mintlify/prebuild';
2
+ import { checkBuild } from '../local-preview/check-build.js';
2
3
  import { isOnline } from '../local-preview/is-online.js';
3
- import validateBuild, { checkBuild } from '../local-preview/validate-build.js';
4
4
  import { addLog } from '../logging-state.js';
5
- import { WarningLog } from '../logs.js';
6
5
  vi.mock('@mintlify/prebuild', async (importOriginal) => {
7
6
  const mod = await importOriginal();
8
- return { ...mod, prebuild: vi.fn(), getWarnings: vi.fn(() => []) };
7
+ return { ...mod, prebuild: vi.fn() };
9
8
  });
10
9
  vi.mock('../local-preview/is-online.js', () => ({ isOnline: vi.fn() }));
11
10
  vi.mock('fs-extra', () => {
@@ -32,11 +31,12 @@ describe('checkBuild', () => {
32
31
  vi.spyOn(process, 'chdir').mockImplementation(() => undefined);
33
32
  });
34
33
  it('logs nothing', async () => {
35
- vi.mocked(prebuild).mockRejectedValue(new Error('Build validation failed with 1 warning(s). See above for details.'));
34
+ vi.mocked(prebuild).mockRejectedValue(new StrictModeError('Build validation failed with 1 warning(s). See above for details.'));
36
35
  const result = await checkBuild(argv);
37
36
  expect(result).toMatchObject({
38
37
  passed: false,
39
38
  error: expect.stringContaining('Build validation failed'),
39
+ strict: true,
40
40
  });
41
41
  expect(addLog).not.toHaveBeenCalled();
42
42
  });
@@ -46,7 +46,12 @@ describe('checkBuild', () => {
46
46
  });
47
47
  it('returns a build failure instead of exiting', async () => {
48
48
  vi.mocked(prebuild).mockRejectedValue(new Error('boom'));
49
- expect(await checkBuild(argv)).toEqual({ passed: false, error: 'boom', warnings: [] });
49
+ expect(await checkBuild(argv)).toEqual({
50
+ passed: false,
51
+ error: 'boom',
52
+ strict: false,
53
+ warnings: [],
54
+ });
50
55
  });
51
56
  it.each([
52
57
  ['passes', () => vi.mocked(prebuild).mockResolvedValue(undefined)],
@@ -66,19 +71,3 @@ describe('checkBuild', () => {
66
71
  expect(prebuild).not.toHaveBeenCalled();
67
72
  });
68
73
  });
69
- describe('validateBuild', () => {
70
- beforeEach(() => {
71
- vi.clearAllMocks();
72
- vi.mocked(isOnline).mockResolvedValue(true);
73
- vi.spyOn(process, 'chdir').mockImplementation(() => undefined);
74
- vi.spyOn(process, 'exit').mockImplementation(() => undefined);
75
- });
76
- it('prints the collected warnings before the failure', async () => {
77
- vi.mocked(prebuild).mockRejectedValue(new Error('Build validation failed with 1 warning(s).'));
78
- vi.mocked(getWarnings).mockReturnValue([{ type: 'missing-file', message: 'missing a.mdx' }]);
79
- await validateBuild(argv);
80
- const logged = vi.mocked(addLog).mock.calls.map(([node]) => node);
81
- expect(logged).toContainEqual(expect.objectContaining({ type: WarningLog, props: { message: 'missing a.mdx' } }));
82
- expect(process.exit).toHaveBeenCalledWith(1);
83
- });
84
- });
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { LOCAL_LINKED_CLI_VERSION } from './constants.js';
2
+ import { checkBuild } from './local-preview/check-build.js';
2
3
  import { getLatestClientVersion, downloadTargetMint, getVersionMap } from './local-preview/client.js';
3
4
  import { exportSite } from './local-preview/export.js';
4
5
  import dev from './local-preview/index.js';
5
- import validateBuild, { checkBuild } from './local-preview/validate-build.js';
6
- export type { BuildValidationResult } from './local-preview/validate-build.js';
6
+ export type { BuildValidationResult } from './local-preview/check-build.js';
7
7
  import { getClientVersion } from './util.js';
8
8
  export * from './logs.js';
9
9
  export * from './logging-state.js';
10
10
  export * from './packages/index.js';
11
- export { dev, exportSite, validateBuild, checkBuild, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
11
+ export { dev, exportSite, checkBuild, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { LOCAL_LINKED_CLI_VERSION } from './constants.js';
2
+ import { checkBuild } from './local-preview/check-build.js';
2
3
  import { getLatestClientVersion, downloadTargetMint, getVersionMap, } from './local-preview/client.js';
3
4
  import { exportSite } from './local-preview/export.js';
4
5
  import dev from './local-preview/index.js';
5
- import validateBuild, { checkBuild } from './local-preview/validate-build.js';
6
6
  import { getClientVersion } from './util.js';
7
7
  export * from './logs.js';
8
8
  export * from './logging-state.js';
9
9
  export * from './packages/index.js';
10
- export { dev, exportSite, validateBuild, checkBuild, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
10
+ export { dev, exportSite, checkBuild, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
@@ -5,6 +5,7 @@ export type BuildValidationResult = ({
5
5
  } | {
6
6
  passed: false;
7
7
  error: string;
8
+ strict: boolean;
8
9
  }) & {
9
10
  warnings: Warning[];
10
11
  };
@@ -13,5 +14,3 @@ export type BuildValidationResult = ({
13
14
  * instead of printed.
14
15
  */
15
16
  export declare const checkBuild: (argv: ArgumentsCamelCase) => Promise<BuildValidationResult>;
16
- declare const validateBuild: (argv: ArgumentsCamelCase, onSuccess?: () => Promise<void>) => Promise<never>;
17
- export default validateBuild;
@@ -1,9 +1,6 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { getWarnings, prebuild, setWarningsSilent } from '@mintlify/prebuild';
1
+ import { getWarnings, prebuild, setWarningsSilent, StrictModeError, } from '@mintlify/prebuild';
3
2
  import fse, { pathExists } from 'fs-extra';
4
3
  import { CLIENT_PATH, CMD_EXEC_PATH, VERSION_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, PREVIEW_PATH, configureSharedPreviewPath, } from '../constants.js';
5
- import { addLog, clearLogs } from '../logging-state.js';
6
- import { ErrorLog, SpinnerLog, SuccessLog, WarningLog } from '../logs.js';
7
4
  import { timeDev, timeDevSync } from './dev-timing.js';
8
5
  import { isOnline } from './is-online.js';
9
6
  import { silentUpdateClient } from './update.js';
@@ -59,36 +56,15 @@ export const checkBuild = async (argv) => {
59
56
  }
60
57
  catch (err) {
61
58
  const errorText = err instanceof Error && err.message ? err.message : 'build validation failed';
62
- return { passed: false, error: errorText, warnings: getWarnings() };
59
+ return {
60
+ passed: false,
61
+ error: errorText,
62
+ strict: err instanceof StrictModeError,
63
+ warnings: getWarnings(),
64
+ };
63
65
  }
64
66
  finally {
65
67
  setWarningsSilent(false);
66
68
  process.chdir(cwd);
67
69
  }
68
70
  };
69
- const validateBuild = async (argv, onSuccess) => {
70
- addLog(_jsx(SpinnerLog, { message: "validating build..." }));
71
- let code;
72
- try {
73
- const result = await checkBuild(argv);
74
- clearLogs();
75
- result.warnings.forEach(({ message }) => addLog(_jsx(WarningLog, { message: message })));
76
- if (result.passed) {
77
- addLog(_jsx(SuccessLog, { message: "build validation passed" }));
78
- await onSuccess?.();
79
- code = 0;
80
- }
81
- else {
82
- addLog(_jsx(ErrorLog, { message: result.error }));
83
- code = 1;
84
- }
85
- }
86
- catch (err) {
87
- clearLogs();
88
- addLog(_jsx(ErrorLog, { message: err instanceof Error ? err.message : String(err) }));
89
- code = 2;
90
- }
91
- await new Promise((resolve) => setTimeout(resolve, 50));
92
- process.exit(code);
93
- };
94
- export default validateBuild;
@@ -46,6 +46,8 @@ const decodePathname = (pathname) => {
46
46
  }
47
47
  };
48
48
  const MARKDOWN_PREFIX = '_markdown/';
49
+ const MARKDOWN_SUFFIX = /\.md$/;
50
+ const RSS_SUFFIX = /\/?rss\.xml$/;
49
51
  const OG_PREVIEW_PREFIX = '_mintlify/og/';
50
52
  const OG_PREVIEW_EXTENSION = '.png';
51
53
  const pageSlugFromOgPreview = (slug) => {
@@ -58,6 +60,7 @@ const slugFromPathname = (pathname) => {
58
60
  if (slug.startsWith(MARKDOWN_PREFIX)) {
59
61
  slug = slug.slice(MARKDOWN_PREFIX.length);
60
62
  }
63
+ slug = slug.replace(MARKDOWN_SUFFIX, '').replace(RSS_SUFFIX, '');
61
64
  slug = pageSlugFromOgPreview(slug) ?? slug;
62
65
  if (slug === '') {
63
66
  return 'index';
@@ -93,10 +93,10 @@ export const run = async (argv) => {
93
93
  res.status(502).json({ error: 'search proxy failed' });
94
94
  }
95
95
  });
96
- app.post('/_mintlify/api-public/assistant/:subdomain/message', express.json({ limit: ASSISTANT_MESSAGE_JSON_LIMIT }), async (req, res) => {
96
+ const assistantProxy = (message) => async (req, res) => {
97
97
  const targetSubdomain = subdomain ?? req.params.subdomain;
98
98
  try {
99
- const upstream = await fetch(`${apiUrl}/api/cli/${targetSubdomain}/assistant/message`, {
99
+ const upstream = await fetch(`${apiUrl}/api/cli/${targetSubdomain}/assistant/${message}`, {
100
100
  method: 'POST',
101
101
  headers: {
102
102
  'Content-Type': 'application/json',
@@ -131,7 +131,10 @@ export const run = async (argv) => {
131
131
  res.destroy();
132
132
  }
133
133
  }
134
- });
134
+ };
135
+ for (const message of ['message', 'v2/message']) {
136
+ app.post(`/_mintlify/api-public/assistant/:subdomain/${message}`, express.json({ limit: ASSISTANT_MESSAGE_JSON_LIMIT }), assistantProxy(message));
137
+ }
135
138
  app.all('*', (req, res) => requestHandler(req, res));
136
139
  const onChange = () => {
137
140
  io.emit('reload');