@mintlify/cli 4.0.1142 → 4.0.1144

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.
@@ -15,16 +15,15 @@ describe('getCliVersion', () => {
15
15
 
16
16
  it('returns a test marker when CLI_TEST_MODE is enabled', () => {
17
17
  process.env.CLI_TEST_MODE = 'true';
18
- expect(getCliVersion()).toBe('test-cli');
18
+ expect(getCliVersion('mint')).toBe('test-cli');
19
19
  });
20
20
 
21
21
  it(
22
22
  'returns LOCAL_LINKED_CLI_VERSION when running from the monorepo source ' +
23
23
  '(not inside node_modules)',
24
24
  () => {
25
- // Source lives outside node_modules, mirroring `npm link` / `yarn dev`. See #7121.
26
25
  delete process.env.CLI_TEST_MODE;
27
- expect(getCliVersion()).toBe(LOCAL_LINKED_CLI_VERSION);
26
+ expect(getCliVersion('mint')).toBe(LOCAL_LINKED_CLI_VERSION);
28
27
  }
29
28
  );
30
29
  });
@@ -8,8 +8,9 @@ vi.mock('@mintlify/previewing', async () => {
8
8
  await vi.importActual<typeof import('@mintlify/previewing')>('@mintlify/previewing');
9
9
  return {
10
10
  ...originalModule,
11
- getClientVersion: vi.fn(),
12
- downloadTargetMint: vi.fn(),
11
+ getClientVersion: vi.fn().mockReturnValue('1.0.0'),
12
+ getLatestClientVersion: vi.fn().mockResolvedValue('2.0.0'),
13
+ downloadTargetMint: vi.fn().mockResolvedValue(undefined),
13
14
  };
14
15
  });
15
16
 
@@ -50,19 +51,16 @@ describe('update', () => {
50
51
 
51
52
  await update({ packageName: 'mintlify' });
52
53
 
53
- expect(addLogSpy).toHaveBeenCalledTimes(3);
54
- expect(addLogSpy).toHaveBeenCalledWith(
55
- expect.objectContaining({ props: { message: 'updating...' } })
56
- );
57
- expect(addLogSpy).toHaveBeenCalledWith(
58
- expect.objectContaining({ props: { message: 'updating mintlify package...' } })
59
- );
54
+ expect(execAsync).toHaveBeenCalledWith('npm install -g mintlify@latest --silent');
55
+ expect(previewing.downloadTargetMint).toHaveBeenCalledWith({
56
+ targetVersion: '2.0.0',
57
+ existingVersion: '1.0.0',
58
+ });
60
59
  expect(addLogSpy).toHaveBeenCalledWith(
61
60
  expect.objectContaining({
62
61
  props: { message: 'updated mintlify to the latest version: 2.0.0' },
63
62
  })
64
63
  );
65
- expect(execAsync).toHaveBeenCalledWith('npm install -g mintlify@latest --silent');
66
64
  });
67
65
 
68
66
  it('should return when already up to date', async () => {
@@ -71,18 +69,16 @@ describe('update', () => {
71
69
  client: '1.0.0',
72
70
  });
73
71
  vi.mocked(getLatestCliVersion).mockReturnValue('1.0.0');
74
- vi.mocked(execAsync).mockResolvedValue({ stdout: '', stderr: '' });
72
+ vi.mocked(previewing.getLatestClientVersion).mockResolvedValue('1.0.0');
73
+ vi.mocked(previewing.getClientVersion).mockReturnValue('1.0.0');
75
74
 
76
75
  await update({ packageName: 'mintlify' });
77
76
 
78
- expect(addLogSpy).toHaveBeenCalledTimes(2);
79
- expect(addLogSpy).toHaveBeenCalledWith(
80
- expect.objectContaining({ props: { message: 'updating...' } })
81
- );
77
+ expect(execAsync).not.toHaveBeenCalled();
78
+ expect(previewing.downloadTargetMint).not.toHaveBeenCalled();
82
79
  expect(addLogSpy).toHaveBeenCalledWith(
83
80
  expect.objectContaining({ props: { message: 'already up to date' } })
84
81
  );
85
- expect(execAsync).not.toHaveBeenCalled();
86
82
  });
87
83
 
88
84
  it('should handle cli update failure', async () => {
package/bin/cli.js CHANGED
@@ -92,7 +92,7 @@ export const cli = ({ packageName = 'mint' }) => {
92
92
  var _a;
93
93
  yield autoUpgradeIfNeeded();
94
94
  const port = yield checkPort(argv);
95
- const { cli: cliVersion } = getVersions();
95
+ const { cli: cliVersion } = getVersions(packageName);
96
96
  let accessToken;
97
97
  let subdomain;
98
98
  try {
@@ -150,7 +150,7 @@ export const cli = ({ packageName = 'mint' }) => {
150
150
  return;
151
151
  }
152
152
  }
153
- const { cli: cliVersion } = getVersions();
153
+ const { cli: cliVersion } = getVersions(packageName);
154
154
  yield validateBuild(Object.assign(Object.assign({}, argv), { packageName,
155
155
  cliVersion }));
156
156
  }))
@@ -176,7 +176,7 @@ export const cli = ({ packageName = 'mint' }) => {
176
176
  .usage('usage: mintlify export [options]')
177
177
  .example('mintlify export', 'export as export.zip')
178
178
  .example('mintlify export --output docs.zip', 'export to custom filename'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
179
- const { cli: cliVersion } = getVersions();
179
+ const { cli: cliVersion } = getVersions(packageName);
180
180
  yield exportSite(Object.assign(Object.assign({}, argv), { packageName,
181
181
  cliVersion }));
182
182
  yield terminate(0);
@@ -386,7 +386,7 @@ export const cli = ({ packageName = 'mint' }) => {
386
386
  yield terminate(accessibilityCheckTerminateCode || mdxLinterTerminateCode);
387
387
  }))
388
388
  .command(['version', 'v'], 'Display the current version of the CLI and client', () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
389
- const { cli, client } = getVersions();
389
+ const { cli, client } = getVersions(packageName);
390
390
  addLog(_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "green", children: "cli version" }), ' ', cli] }));
391
391
  addLog(_jsxs(Text, { children: [_jsx(Text, { bold: true, color: "green", children: "client version" }), ' ', client] }));
392
392
  }))
package/bin/helpers.js CHANGED
@@ -19,6 +19,7 @@ import yaml from 'js-yaml';
19
19
  import { exec, execSync } from 'node:child_process';
20
20
  import { readFileSync } from 'node:fs';
21
21
  import fs from 'node:fs/promises';
22
+ import { createRequire } from 'node:module';
22
23
  import { fileURLToPath } from 'node:url';
23
24
  import { promisify } from 'node:util';
24
25
  import path from 'path';
@@ -110,44 +111,41 @@ export const upgradeConfig = () => __awaiter(void 0, void 0, void 0, function* (
110
111
  addLog(_jsx(ErrorLog, { message: err instanceof Error ? err.message : 'an unknown error occurred' }));
111
112
  }
112
113
  });
113
- // Resolve the CLI's own package.json via `import.meta.url` so the version is
114
- // always the one shipped with this package, regardless of cwd. See #7121.
115
- const CLI_PACKAGE_JSON_PATH = (() => {
114
+ const require = createRequire(import.meta.url);
115
+ const isRunningFromLinkedBuild = () => {
116
116
  try {
117
- return fileURLToPath(new URL('../package.json', import.meta.url));
117
+ const thisFile = fileURLToPath(import.meta.url);
118
+ return !thisFile.split(path.sep).includes('node_modules');
118
119
  }
119
120
  catch (_a) {
120
- return undefined;
121
+ return false;
121
122
  }
122
- })();
123
- const readCliPackageVersion = () => {
124
- if (!CLI_PACKAGE_JSON_PATH)
125
- return undefined;
123
+ };
124
+ const readPackageVersion = (packageName) => {
126
125
  try {
127
- const pkg = JSON.parse(readFileSync(CLI_PACKAGE_JSON_PATH, 'utf8'));
126
+ const pkgPath = require.resolve(`${packageName}/package.json`);
127
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
128
128
  return typeof pkg.version === 'string' ? pkg.version : undefined;
129
129
  }
130
130
  catch (_a) {
131
131
  return undefined;
132
132
  }
133
133
  };
134
- // Outside `node_modules` means `yarn dev` or `npm link`: treat as linked. See #7121.
135
- const isRunningFromLinkedBuild = () => {
136
- if (!CLI_PACKAGE_JSON_PATH)
137
- return false;
138
- return !CLI_PACKAGE_JSON_PATH.split(path.sep).includes('node_modules');
139
- };
140
- export const getCliVersion = () => {
134
+ export const getCliVersion = (packageName) => {
135
+ var _a;
136
+ if (packageName === void 0) { packageName = (_a = process.env.MINTLIFY_PACKAGE_NAME) !== null && _a !== void 0 ? _a : 'mint'; }
141
137
  if (process.env.CLI_TEST_MODE === 'true') {
142
138
  return 'test-cli';
143
139
  }
144
140
  if (isRunningFromLinkedBuild()) {
145
141
  return LOCAL_LINKED_CLI_VERSION;
146
142
  }
147
- return readCliPackageVersion();
143
+ return readPackageVersion(packageName);
148
144
  };
149
- export const getVersions = () => {
150
- const cli = getCliVersion();
145
+ export const getVersions = (packageName) => {
146
+ var _a;
147
+ if (packageName === void 0) { packageName = (_a = process.env.MINTLIFY_PACKAGE_NAME) !== null && _a !== void 0 ? _a : 'mint'; }
148
+ const cli = getCliVersion(packageName);
151
149
  const client = getClientVersion().trim();
152
150
  return { cli, client };
153
151
  };