@mintlify/previewing 4.0.1514 → 4.0.1516

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 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ import { prebuild } from '@mintlify/prebuild';
2
+ import isOnline from 'is-online';
3
+ import { checkBuild } from '../local-preview/validate-build.js';
4
+ import { addLog } from '../logging-state.js';
5
+ vi.mock('@mintlify/prebuild', async (importOriginal) => {
6
+ const mod = await importOriginal();
7
+ return { ...mod, prebuild: vi.fn() };
8
+ });
9
+ vi.mock('is-online', () => ({ default: vi.fn() }));
10
+ vi.mock('fs-extra', () => {
11
+ const mocks = {
12
+ ensureDir: vi.fn().mockResolvedValue(undefined),
13
+ pathExists: vi.fn().mockResolvedValue(true),
14
+ readFileSync: vi.fn().mockReturnValue('1.0.0'),
15
+ emptyDirSync: vi.fn(),
16
+ };
17
+ return { ...mocks, default: mocks };
18
+ });
19
+ vi.mock('../local-preview/update.js', () => ({
20
+ silentUpdateClient: vi.fn(async () => ({ needsUpdate: false, error: undefined })),
21
+ }));
22
+ vi.mock('../logging-state.js', async (importOriginal) => {
23
+ const mod = await importOriginal();
24
+ return { ...mod, addLog: vi.fn(), clearLogs: vi.fn() };
25
+ });
26
+ const argv = { _: [], $0: 'mint', packageName: 'mint' };
27
+ describe('checkBuild', () => {
28
+ beforeEach(() => {
29
+ vi.clearAllMocks();
30
+ vi.mocked(isOnline).mockResolvedValue(true);
31
+ vi.spyOn(process, 'chdir').mockImplementation(() => undefined);
32
+ });
33
+ it('passes when prebuild succeeds', async () => {
34
+ vi.mocked(prebuild).mockResolvedValue(undefined);
35
+ expect(await checkBuild(argv)).toEqual({ passed: true });
36
+ });
37
+ it('returns a build failure instead of exiting', async () => {
38
+ vi.mocked(prebuild).mockRejectedValue(new Error('boom'));
39
+ expect(await checkBuild(argv)).toEqual({ passed: false, error: 'boom' });
40
+ });
41
+ it.each([
42
+ ['passes', () => vi.mocked(prebuild).mockResolvedValue(undefined)],
43
+ ['fails', () => vi.mocked(prebuild).mockRejectedValue(new Error('boom'))],
44
+ ])('restores the working directory and logs nothing when the build %s', async (_label, mock) => {
45
+ mock();
46
+ const cwd = process.cwd();
47
+ await checkBuild(argv);
48
+ expect(process.chdir).toHaveBeenLastCalledWith(cwd);
49
+ expect(addLog).not.toHaveBeenCalled();
50
+ });
51
+ it('throws when offline with no client', async () => {
52
+ const fse = await import('fs-extra');
53
+ vi.mocked(fse.pathExists).mockResolvedValueOnce(false);
54
+ vi.mocked(isOnline).mockResolvedValue(false);
55
+ await expect(checkBuild(argv)).rejects.toThrow('requires an internet connection');
56
+ expect(prebuild).not.toHaveBeenCalled();
57
+ });
58
+ });
package/dist/index.d.ts CHANGED
@@ -2,9 +2,10 @@ import { LOCAL_LINKED_CLI_VERSION } from './constants.js';
2
2
  import { getLatestClientVersion, downloadTargetMint, getVersionMap } from './local-preview/client.js';
3
3
  import { exportSite } from './local-preview/export.js';
4
4
  import dev from './local-preview/index.js';
5
- import validateBuild from './local-preview/validate-build.js';
5
+ import validateBuild, { checkBuild } from './local-preview/validate-build.js';
6
+ export type { BuildValidationResult } from './local-preview/validate-build.js';
6
7
  import { getClientVersion } from './util.js';
7
8
  export * from './logs.js';
8
9
  export * from './logging-state.js';
9
10
  export * from './packages/index.js';
10
- export { dev, exportSite, validateBuild, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
11
+ export { dev, exportSite, validateBuild, checkBuild, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@ import { LOCAL_LINKED_CLI_VERSION } from './constants.js';
2
2
  import { getLatestClientVersion, downloadTargetMint, getVersionMap, } from './local-preview/client.js';
3
3
  import { exportSite } from './local-preview/export.js';
4
4
  import dev from './local-preview/index.js';
5
- import validateBuild from './local-preview/validate-build.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, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
10
+ export { dev, exportSite, validateBuild, checkBuild, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
@@ -1,3 +1,10 @@
1
1
  import { ArgumentsCamelCase } from 'yargs';
2
+ export type BuildValidationResult = {
3
+ passed: true;
4
+ } | {
5
+ passed: false;
6
+ error: string;
7
+ };
8
+ export declare const checkBuild: (argv: ArgumentsCamelCase) => Promise<BuildValidationResult>;
2
9
  declare const validateBuild: (argv: ArgumentsCamelCase, onSuccess?: () => Promise<void>) => Promise<never>;
3
10
  export default validateBuild;
@@ -7,7 +7,7 @@ import { addLog, clearLogs } from '../logging-state.js';
7
7
  import { ErrorLog, SpinnerLog, SuccessLog } from '../logs.js';
8
8
  import { timeDev, timeDevSync } from './dev-timing.js';
9
9
  import { silentUpdateClient } from './update.js';
10
- const validateBuild = async (argv, onSuccess) => {
10
+ export const checkBuild = async (argv) => {
11
11
  configureSharedPreviewPath();
12
12
  const hasInternet = await timeDev('check internet', () => isOnline());
13
13
  const localSchema = argv['local-schema'];
@@ -21,12 +21,8 @@ const validateBuild = async (argv, onSuccess) => {
21
21
  return (await pathExists(VERSION_PATH)) ? fse.readFileSync(VERSION_PATH, 'utf8') : null;
22
22
  });
23
23
  if (!versionString && !hasInternet) {
24
- clearLogs();
25
- addLog(_jsx(ErrorLog, { message: `running ${packageName} validate-build after updating requires an internet connection.` }));
26
- await new Promise((resolve) => setTimeout(resolve, 50));
27
- process.exit(1);
24
+ throw new Error(`running ${packageName} validate-build after updating requires an internet connection.`);
28
25
  }
29
- addLog(_jsx(SpinnerLog, { message: "validating build..." }));
30
26
  const { error } = await timeDev('update local client', () => silentUpdateClient({
31
27
  versionString,
32
28
  clientVersion,
@@ -34,16 +30,14 @@ const validateBuild = async (argv, onSuccess) => {
34
30
  localClientVersion: undefined,
35
31
  }));
36
32
  if (error) {
37
- clearLogs();
38
- addLog(_jsx(ErrorLog, { message: error }));
39
- await new Promise((resolve) => setTimeout(resolve, 50));
40
- process.exit(1);
33
+ throw new Error(error);
41
34
  }
42
35
  // clear preexisting prebuild files
43
36
  timeDevSync('clear prebuild output', () => {
44
37
  fse.emptyDirSync(NEXT_PUBLIC_PATH);
45
38
  fse.emptyDirSync(NEXT_PROPS_PATH);
46
39
  });
40
+ const cwd = process.cwd();
47
41
  timeDevSync('switch to local client directory', () => {
48
42
  process.chdir(CLIENT_PATH);
49
43
  });
@@ -55,18 +49,38 @@ const validateBuild = async (argv, onSuccess) => {
55
49
  strict: true,
56
50
  skipStaticFiles: true,
57
51
  }));
52
+ return { passed: true };
53
+ }
54
+ catch (err) {
55
+ const errorText = err instanceof Error && err.message ? err.message : 'build validation failed';
56
+ return { passed: false, error: errorText };
57
+ }
58
+ finally {
59
+ process.chdir(cwd);
60
+ }
61
+ };
62
+ const validateBuild = async (argv, onSuccess) => {
63
+ addLog(_jsx(SpinnerLog, { message: "validating build..." }));
64
+ let code;
65
+ try {
66
+ const result = await checkBuild(argv);
58
67
  clearLogs();
59
- addLog(_jsx(SuccessLog, { message: "build validation passed" }));
60
- await onSuccess?.();
61
- await new Promise((resolve) => setTimeout(resolve, 50));
62
- process.exit(0);
68
+ if (result.passed) {
69
+ addLog(_jsx(SuccessLog, { message: "build validation passed" }));
70
+ await onSuccess?.();
71
+ code = 0;
72
+ }
73
+ else {
74
+ addLog(_jsx(ErrorLog, { message: result.error }));
75
+ code = 1;
76
+ }
63
77
  }
64
78
  catch (err) {
65
79
  clearLogs();
66
- const errorText = err instanceof Error && err.message ? err.message : 'build validation failed';
67
- addLog(_jsx(ErrorLog, { message: errorText }));
68
- await new Promise((resolve) => setTimeout(resolve, 50));
69
- process.exit(1);
80
+ addLog(_jsx(ErrorLog, { message: err instanceof Error ? err.message : String(err) }));
81
+ code = 2;
70
82
  }
83
+ await new Promise((resolve) => setTimeout(resolve, 50));
84
+ process.exit(code);
71
85
  };
72
86
  export default validateBuild;