@mintlify/previewing 4.0.1547 → 4.0.1549

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,10 +1,11 @@
1
- import { prebuild } from '@mintlify/prebuild';
1
+ import { getWarnings, prebuild } from '@mintlify/prebuild';
2
2
  import { isOnline } from '../local-preview/is-online.js';
3
- import { checkBuild } from '../local-preview/validate-build.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';
5
6
  vi.mock('@mintlify/prebuild', async (importOriginal) => {
6
7
  const mod = await importOriginal();
7
- return { ...mod, prebuild: vi.fn() };
8
+ return { ...mod, prebuild: vi.fn(), getWarnings: vi.fn(() => []) };
8
9
  });
9
10
  vi.mock('../local-preview/is-online.js', () => ({ isOnline: vi.fn() }));
10
11
  vi.mock('fs-extra', () => {
@@ -30,13 +31,22 @@ describe('checkBuild', () => {
30
31
  vi.mocked(isOnline).mockResolvedValue(true);
31
32
  vi.spyOn(process, 'chdir').mockImplementation(() => undefined);
32
33
  });
34
+ it('logs nothing', async () => {
35
+ vi.mocked(prebuild).mockRejectedValue(new Error('Build validation failed with 1 warning(s). See above for details.'));
36
+ const result = await checkBuild(argv);
37
+ expect(result).toMatchObject({
38
+ passed: false,
39
+ error: expect.stringContaining('Build validation failed'),
40
+ });
41
+ expect(addLog).not.toHaveBeenCalled();
42
+ });
33
43
  it('passes when prebuild succeeds', async () => {
34
44
  vi.mocked(prebuild).mockResolvedValue(undefined);
35
- expect(await checkBuild(argv)).toEqual({ passed: true });
45
+ expect(await checkBuild(argv)).toEqual({ passed: true, warnings: [] });
36
46
  });
37
47
  it('returns a build failure instead of exiting', async () => {
38
48
  vi.mocked(prebuild).mockRejectedValue(new Error('boom'));
39
- expect(await checkBuild(argv)).toEqual({ passed: false, error: 'boom' });
49
+ expect(await checkBuild(argv)).toEqual({ passed: false, error: 'boom', warnings: [] });
40
50
  });
41
51
  it.each([
42
52
  ['passes', () => vi.mocked(prebuild).mockResolvedValue(undefined)],
@@ -56,3 +66,19 @@ describe('checkBuild', () => {
56
66
  expect(prebuild).not.toHaveBeenCalled();
57
67
  });
58
68
  });
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
+ });
@@ -1,10 +1,17 @@
1
+ import { type Warning } from '@mintlify/prebuild';
1
2
  import { ArgumentsCamelCase } from 'yargs';
2
- export type BuildValidationResult = {
3
+ export type BuildValidationResult = ({
3
4
  passed: true;
4
5
  } | {
5
6
  passed: false;
6
7
  error: string;
8
+ }) & {
9
+ warnings: Warning[];
7
10
  };
11
+ /**
12
+ * Runs the strict prebuild and returns its result without logging: warnings are collected
13
+ * instead of printed.
14
+ */
8
15
  export declare const checkBuild: (argv: ArgumentsCamelCase) => Promise<BuildValidationResult>;
9
16
  declare const validateBuild: (argv: ArgumentsCamelCase, onSuccess?: () => Promise<void>) => Promise<never>;
10
17
  export default validateBuild;
@@ -1,12 +1,16 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { prebuild } from '@mintlify/prebuild';
2
+ import { getWarnings, prebuild, setWarningsSilent } from '@mintlify/prebuild';
3
3
  import fse, { pathExists } from 'fs-extra';
4
4
  import { CLIENT_PATH, CMD_EXEC_PATH, VERSION_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, PREVIEW_PATH, configureSharedPreviewPath, } from '../constants.js';
5
5
  import { addLog, clearLogs } from '../logging-state.js';
6
- import { ErrorLog, SpinnerLog, SuccessLog } from '../logs.js';
6
+ import { ErrorLog, SpinnerLog, SuccessLog, WarningLog } from '../logs.js';
7
7
  import { timeDev, timeDevSync } from './dev-timing.js';
8
8
  import { isOnline } from './is-online.js';
9
9
  import { silentUpdateClient } from './update.js';
10
+ /**
11
+ * Runs the strict prebuild and returns its result without logging: warnings are collected
12
+ * instead of printed.
13
+ */
10
14
  export const checkBuild = async (argv) => {
11
15
  configureSharedPreviewPath();
12
16
  const hasInternet = await timeDev('check internet', () => isOnline());
@@ -41,21 +45,24 @@ export const checkBuild = async (argv) => {
41
45
  timeDevSync('switch to local client directory', () => {
42
46
  process.chdir(CLIENT_PATH);
43
47
  });
48
+ const runPrebuild = () => timeDev('prebuild content', () => prebuild(CMD_EXEC_PATH, {
49
+ localSchema,
50
+ groups,
51
+ disableOpenApi,
52
+ strict: true,
53
+ skipStaticFiles: true,
54
+ }));
55
+ setWarningsSilent(true);
44
56
  try {
45
- await timeDev('prebuild content', () => prebuild(CMD_EXEC_PATH, {
46
- localSchema,
47
- groups,
48
- disableOpenApi,
49
- strict: true,
50
- skipStaticFiles: true,
51
- }));
52
- return { passed: true };
57
+ await runPrebuild();
58
+ return { passed: true, warnings: getWarnings() };
53
59
  }
54
60
  catch (err) {
55
61
  const errorText = err instanceof Error && err.message ? err.message : 'build validation failed';
56
- return { passed: false, error: errorText };
62
+ return { passed: false, error: errorText, warnings: getWarnings() };
57
63
  }
58
64
  finally {
65
+ setWarningsSilent(false);
59
66
  process.chdir(cwd);
60
67
  }
61
68
  };
@@ -65,6 +72,7 @@ const validateBuild = async (argv, onSuccess) => {
65
72
  try {
66
73
  const result = await checkBuild(argv);
67
74
  clearLogs();
75
+ result.warnings.forEach(({ message }) => addLog(_jsx(WarningLog, { message: message })));
68
76
  if (result.passed) {
69
77
  addLog(_jsx(SuccessLog, { message: "build validation passed" }));
70
78
  await onSuccess?.();