@mintlify/cli 4.0.627 → 4.0.629

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/bin/update.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { getTargetMintVersion, downloadTargetMint, SpinnerLog, SuccessLog, ErrorLog, addLog, clearLogs, } from '@mintlify/previewing';
12
- import { execAsync, getLatestCliVersion, getVersions } from './helpers.js';
12
+ import { execAsync, getLatestCliVersion, getVersions, detectPackageManager } from './helpers.js';
13
13
  export const update = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packageName, silent, }) {
14
14
  if (!silent) {
15
15
  addLog(_jsx(SpinnerLog, { message: "updating..." }));
@@ -35,10 +35,17 @@ export const update = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packa
35
35
  clearLogs();
36
36
  addLog(_jsx(SpinnerLog, { message: `updating ${packageName} package...` }));
37
37
  }
38
- yield execAsync(`npm install -g ${packageName}@latest --silent`);
38
+ const packageManager = yield detectPackageManager({ packageName });
39
+ if (packageManager === 'pnpm') {
40
+ yield execAsync(`pnpm install -g ${packageName}@latest --silent`);
41
+ }
42
+ else {
43
+ yield execAsync(`npm install -g ${packageName}@latest --silent`);
44
+ }
39
45
  }
40
46
  catch (err) {
41
47
  if (!silent) {
48
+ clearLogs();
42
49
  addLog(_jsx(ErrorLog, { message: `failed to update ${packageName}@latest` }));
43
50
  }
44
51
  return;
@@ -56,6 +63,7 @@ export const update = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packa
56
63
  }
57
64
  catch (err) {
58
65
  if (!silent) {
66
+ clearLogs();
59
67
  addLog(_jsx(ErrorLog, { message: `failed to update mintlify client to ${latestClientVersion}` }));
60
68
  }
61
69
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/cli",
3
- "version": "4.0.627",
3
+ "version": "4.0.629",
4
4
  "description": "The Mintlify CLI",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -73,5 +73,5 @@
73
73
  "vitest": "^2.0.4",
74
74
  "vitest-mock-process": "^1.0.4"
75
75
  },
76
- "gitHead": "04c0129b6fb7fcd56c65fd4efe3be1dba4594f72"
76
+ "gitHead": "1f5d91b3cda50efafeb9c460d8ce09b0f531ffbe"
77
77
  }
package/src/cli.tsx CHANGED
@@ -32,11 +32,12 @@ import {
32
32
  } from './helpers.js';
33
33
  import { update } from './update.js';
34
34
 
35
- export const cli = () => {
35
+ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
36
36
  render(<Logs />);
37
37
 
38
38
  return (
39
39
  yargs(hideBin(process.argv))
40
+ .scriptName(packageName)
40
41
  .middleware(checkNodeVersion)
41
42
  .middleware(suppressConsoleWarnings)
42
43
  .command(
@@ -71,7 +72,6 @@ export const cli = () => {
71
72
  .example('mintlify dev --no-open', 'run without opening in browser'),
72
73
  async (argv) => {
73
74
  const port = await checkPort(argv);
74
- const packageName = process.argv[1]?.split('/').pop() ?? 'mintlify';
75
75
  const cliVersion = getCliVersion();
76
76
  if (
77
77
  cliVersion &&
@@ -222,7 +222,6 @@ export const cli = () => {
222
222
  'update the CLI to the latest version',
223
223
  () => undefined,
224
224
  async () => {
225
- const packageName = process.argv[1]?.split('/').pop() ?? 'mintlify';
226
225
  await update({ packageName });
227
226
  await terminate(0);
228
227
  }
package/src/helpers.tsx CHANGED
@@ -174,3 +174,16 @@ export const terminate = async (code: number) => {
174
174
  };
175
175
 
176
176
  export const execAsync = promisify(exec);
177
+
178
+ export const detectPackageManager = async ({ packageName }: { packageName: string }) => {
179
+ try {
180
+ const { stdout: packagePath } = await execAsync(`which ${packageName}`);
181
+ if (packagePath.includes('pnpm')) {
182
+ return 'pnpm';
183
+ } else {
184
+ return 'npm';
185
+ }
186
+ } catch (error) {
187
+ return 'npm';
188
+ }
189
+ };
package/src/index.ts CHANGED
@@ -1,5 +1,109 @@
1
1
  #!/usr/bin/env node
2
- import { cli } from './cli.js';
2
+ import { spawn, type ChildProcess } from 'child_process';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ const packageName =
10
+ process.argv[1]?.split('/').pop() === 'index.js'
11
+ ? 'mint'
12
+ : process.argv[1]?.split('/').pop() ?? 'mint';
13
+
14
+ let cli: ChildProcess | null = null;
15
+ let isShuttingDown = false;
16
+ let hasExited = false;
17
+
18
+ const cleanup = async (): Promise<void> => {
19
+ if (isShuttingDown) return;
20
+ isShuttingDown = true;
21
+
22
+ if (cli && !cli.killed) {
23
+ try {
24
+ cli.kill('SIGTERM');
25
+
26
+ await new Promise<void>((resolve) => {
27
+ const timeout = setTimeout(() => {
28
+ if (cli && !cli.killed) {
29
+ cli.kill('SIGKILL');
30
+ }
31
+ resolve();
32
+ }, 5000);
33
+
34
+ cli!.once('exit', () => {
35
+ clearTimeout(timeout);
36
+ resolve();
37
+ });
38
+ });
39
+ } catch (error) {
40
+ // ignore
41
+ }
42
+ }
43
+ };
44
+
45
+ const exitProcess = (code: number) => {
46
+ if (hasExited) return;
47
+ hasExited = true;
48
+ process.exit(code);
49
+ };
50
+
51
+ const killSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP'];
52
+ killSignals.forEach((signal) => {
53
+ process.on(signal, async () => {
54
+ await cleanup();
55
+ exitProcess(0);
56
+ });
57
+ });
58
+
59
+ process.on('uncaughtException', async () => {
60
+ await cleanup();
61
+ exitProcess(1);
62
+ });
63
+
64
+ process.on('unhandledRejection', async () => {
65
+ await cleanup();
66
+ exitProcess(1);
67
+ });
68
+
69
+ try {
70
+ cli = spawn(
71
+ 'node',
72
+ ['--no-deprecation', path.join(__dirname, '../bin/start.js'), ...process.argv.slice(2)],
73
+ {
74
+ stdio: 'inherit',
75
+ env: {
76
+ ...process.env,
77
+ MINTLIFY_PACKAGE_NAME: packageName,
78
+ },
79
+ shell: process.platform === 'win32',
80
+ windowsHide: process.platform === 'win32',
81
+ detached: false,
82
+ }
83
+ );
84
+
85
+ cli.on('error', async (error) => {
86
+ console.error(`Failed to start ${packageName}: ${error.message}`);
87
+ await cleanup();
88
+ exitProcess(1);
89
+ });
90
+
91
+ cli.on('exit', (code) => {
92
+ exitProcess(code ?? 0);
93
+ });
94
+ } catch (error) {
95
+ console.error(`Failed to start ${packageName}: ${error}`);
96
+ exitProcess(1);
97
+ }
98
+
99
+ process.on('exit', () => {
100
+ if (cli && !cli.killed) {
101
+ try {
102
+ cli.kill('SIGKILL');
103
+ } catch (error) {
104
+ // ignore
105
+ }
106
+ }
107
+ });
3
108
 
4
109
  export { cli };
5
- void cli();
package/src/start.ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { cli } from './cli.js';
3
+
4
+ const packageName = process.env.MINTLIFY_PACKAGE_NAME ?? 'mint';
5
+
6
+ void cli({ packageName });
package/src/update.tsx CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  clearLogs,
9
9
  } from '@mintlify/previewing';
10
10
 
11
- import { execAsync, getLatestCliVersion, getVersions } from './helpers.js';
11
+ import { execAsync, getLatestCliVersion, getVersions, detectPackageManager } from './helpers.js';
12
12
 
13
13
  export const update = async ({
14
14
  packageName,
@@ -44,9 +44,15 @@ export const update = async ({
44
44
  clearLogs();
45
45
  addLog(<SpinnerLog message={`updating ${packageName} package...`} />);
46
46
  }
47
- await execAsync(`npm install -g ${packageName}@latest --silent`);
47
+ const packageManager = await detectPackageManager({ packageName });
48
+ if (packageManager === 'pnpm') {
49
+ await execAsync(`pnpm install -g ${packageName}@latest --silent`);
50
+ } else {
51
+ await execAsync(`npm install -g ${packageName}@latest --silent`);
52
+ }
48
53
  } catch (err) {
49
54
  if (!silent) {
55
+ clearLogs();
50
56
  addLog(<ErrorLog message={`failed to update ${packageName}@latest`} />);
51
57
  }
52
58
  return;
@@ -64,6 +70,7 @@ export const update = async ({
64
70
  });
65
71
  } catch (err) {
66
72
  if (!silent) {
73
+ clearLogs();
67
74
  addLog(<ErrorLog message={`failed to update mintlify client to ${latestClientVersion}`} />);
68
75
  }
69
76
  return;